Description
Description
This RFC proposes improving doctests for complex number typed arrays in documentation examples. This is best conveyed through an example.
Consider the following JSDoc example in blas/base/ccopy
:
/**
* ...
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
* var realf = require( '@stdlib/complex/float32/real' );
* var imagf = require( '@stdlib/complex/float32/imag' );
*
* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
* var y = new Complex64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
*
* ccopy( x.length, x, 1, y, 1 );
*
* var z = y.get( 0 );
* // returns <Complex64>
*
* var re = realf( z );
* // returns 1.0
*
* var im = imagf( z );
* // returns 2.0
*/
Compare to a similar example from blas/base/dcopy
.
/**
* ...
*
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
* var y = new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] );
*
* dcopy( x.length, x, 1, y, 1 );
* // y => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
*/
Notice how, for dcopy
, we use the doctest return annotation // y => <Float64Array>[ ... ]
; however, for ccopy
, we need to retrieve an individual element and then decompose into real and imaginary components.
As may be observed, the dcopy
doctest is much more compact and conveys much more clearly the expected behavior. For the complex number typed array case, in order to show the expected behavior for the entire typed array, we'd need to extract and decompose each individual element. This is both more tedious when authoring documentation and less effective as a means of conveying expected behavior.
Accordingly, this RFC seeks to leverage recent improvements in our doctest framework which now supports typed array instance notation for complex number typed arrays (e.g., <Complex64Array>[ 1.0, 2.0, 3.0, 4.0 ]
), where previously it did not; hence, the more verbose decomposition logic.
Revisiting ccopy
above to use typed array instance notation would yield
/**
* ...
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
*
* var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
* var y = new Complex64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
*
* ccopy( x.length, x, 1, y, 1 );
* // y => <Complex64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
*/
Notice the removal of realf
and imagf
imports and element decomposition and the insertion of // y => <Complex64Array>[ ... ]
.
Given the relatively widespread practice of decomposing a complex number typed array into individual components, this RFC aims to be an open call for any contributor wanting to contributor to the project to do the following:
- Find a package containing documentation examples which performs element decomposition into real and imaginary components in order to show expected values.
- Update the examples for that package, and only that package, to migrate to using typed array instance notation (e.g.,
<Complex64Array>[ ... ]
,<Complex128Array>[ ... ]
, etc). Examples may be found in the package- README
- TypeScript declarations
- REPL text
- examples/index.js
- lib/* JSDoc examples
- Submit a PR updating the documentation for that package (and only that package).
Please do NOT make extraneous changes to examples. We are not interested in changing examples wholesale. We are only interested in replacing decomposition logic with typed array instance notation.
Related Issues
None.
Questions
No.
Other
- If you are interested in working on this RFC, for each pull request, please only update the examples for a single package.
- As mentioned above, please do NOT make extraneous changes to examples. We are not interested in changing examples wholesale. Nor are we interested in new "creative" changes. We are only interested in replacing decomposition logic with typed array instance notation. Failure to match the behavior of the existing examples and to respect this guidance will result in your PRs being automatically closed without review.
Checklist
- I have read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
- The issue name begins with
RFC:
.