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

オープン
#16,654 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Vijay431 がすでに取り組んでいます。

2026年11月16日 から。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
67/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript, node.js

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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:.
主要言語
JavaScript
スター
6k
フォーク
1.3k
平均マージ
1日 21時間
マージ済み PR(30日)
224

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

stdlib-js/stdlib のほかの issue

stdlib-js/stdlib の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。