[RFC]: Improve zero-dimensional ndarray creation in tests and examples

Abierto
#16,654 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Vijay431 ya está trabajando en esto.

Desde el 16/11/2026.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
67/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
javascript, node.js

Línea de trabajo

Study the two example commits linked in the issue, then find one package with examples, benchmarks, or tests using @stdlib/ndarray/from-scalar for zero-dimensional arrays. Inspect that package’s README, examples, tests, and benchmarks individually, and update only that package where a typed constructor improves clarity. Done means the existing behavior is preserved and only zero-dimensional construction is changed.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Accepted difficulty: 1 Documentation Good First Issue JavaScript Modernization RFC Tracking Issue
Instructions
  1. Read the issue description below.
  2. Read the issue comment which follows the description.
  3. Search the code base for a package having an example, benchmark, and/or test which needs updating according to the description below.
  4. Follow any additional guidance specified in this issue.
Description

This RFC proposes updating zero-dimensional ndarray construction in package tests, benchmarks, and/or examples. This is best conveyed through an example.

Consider the following snippet:

var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );

var x = scalar2ndarray( 3.0, {
	'dtype': 'float64'
});
// <ndarray>[ 3.0 ]

Compare to the example after updating in commit https://github.com/stdlib-js/stdlib/commit/3757981ba9ac1c1debc571b5f0edaea47fb2a367

var Float64Tensor0D = require( '@stdlib/ndarray/tensor0d/float64' );

var x = new Float64Tensor0D( 3.0 );
// <ndarray>[ 3.0 ]

Notice how, in the updated example, we migrate from an imperative expression using scalar2ndarray to a declarative expression with new Float64Tensor0D.

Moving to using the dedicated float64 zero-dimensional ndarray constructor eliminates some of the common { 'dtype': '<dtype>' } boilerplate which is often found in scalar2ndarray usage. This becomes more obvious after considering the following example

var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );

var x = scalar2ndarray( new Complex64( 3.0, 4.0 ), {
	'dtype': 'complex64'
});
// <ndarray>[ <Complex64>[ 3.0, 4.0 ] ]

where the { 'dtype': 'complex64' } options object is not strictly necessary; however, we often include it to make explicit the output ndarray data type. Compare then to the example after updating in commit https://github.com/stdlib-js/stdlib/commit/37c95c00da3ceb98668c063fe0e6322a436b056a

var Complex64Tensor0D = require( '@stdlib/ndarray/tensor0d/complex64' );

var x = new Complex64Tensor0D( 3.0, 4.0 );
// <ndarray>[ <Complex64>[ 3.0, 4.0 ] ]

Notice how the options boilerplate is no longer present and that we can directly create a zero-dimensional ndarray from real and imaginary components without needing to create an intermediate Complex64 instance.

Accordingly, this RFC seeks to leverage recent improvements in zero-dimensional ndarray construction in order to more succinctly (and declaratively) create zero-dimensional ndarrays.

Steps

Given the relatively widespread practice of using @stdlib/ndarray/from-scalar to convert a scalar value to a zero-dimensional ndarray, this RFC aims to be an open call for any contributor wanting to contribute to the project to do the following:

  1. Study the changes made in commits https://github.com/stdlib-js/stdlib/commit/3757981ba9ac1c1debc571b5f0edaea47fb2a367 and https://github.com/stdlib-js/stdlib/commit/37c95c00da3ceb98668c063fe0e6322a436b056a, as these commits contain the sort of changes that we are looking for.

  2. Find a package containing documentation examples, benchmarks, and/or tests which use @stdlib/ndarray/from-scalar to create zero-dimensional ndarrays.

  3. Assess whether migrating away from @stdlib/ndarray/from-scalar would make a meaningful improvement to tests, benchmarks, and/or examples.

  4. Update the documentation (and possibly tests and benchmarks) for that package, and only that package, to migrate to using dedicated typed zero-dimensional ndarray constructors. Examples may be found in the following package files (note: not all files may require updating; you should inspect each file individually):

    • README.md
    • docs/index.d.ts
    • docs/test.ts
    • docs/repl.txt
    • examples/index.js
    • lib/* JSDoc examples
    • benchmark/* benchmarks
    • test/* unit tests
  5. Submit a PR updating the files for that package (and only that package).

  6. For the PR title, use the following template

    docs: use dedicated zero-dimensional tensor constructor in `<package_name>`
    

    where <package_name> is the name of the package you updated (e.g., blas/ext/base/ndarray/daxpby).

Please do NOT make extraneous changes to examples, tests, or benchmarks. We are not interested in changing examples, tests, and/or benchmarks wholesale. We are only interested in replacing zero-dimensional ndarray construction logic.

Related Issues

None.

Questions

No.

Other
  • If you are interested in working on this RFC, for each pull request, please only update the examples, tests, and/or benchmarks for a single package.
  • As mentioned above, please do NOT make extraneous changes to examples, tests, or benchmarks. We are not interested in changing examples, tests, or benchmarks wholesale. Nor are we interested in new "creative" changes. We are only interested in replacing zero-dimensional ndarray creation. Failure to match the behavior of the existing examples, tests, and benchmarks and to respect this guidance will result in your PRs being automatically closed without review.
  • As this is a "Good First Issue", you are strongly encouraged to avoid using AI when authoring your contribution. One of the primary intents of Good First Issues is to help introduce you to stdlib, its development environment, and the contribution process, as documented in the contributing guide. Most new contributors are unfamiliar with stdlib and its conventions, and thus fail to appropriately use LLMs and AI when authoring contributions, most often generating AI slop and leading to wasted time. Don't be one of those people. :) Take the time to manually author your first several PRs, and, once you are intimately familiar with project conventions, you can consider leveraging AI to augment your dev tasks.
Checklist
  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.
Lenguaje dominante
JavaScript
Estrellas
6k
Forks
1.3k
Merge medio
1 d 21 h
PR fusionados (30 d)
224

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de stdlib-js/stdlib

Todos los issues de stdlib-js/stdlib

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.