Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c7e0f03
chore: initial scaffold setup
gunjjoshi Sep 24, 2025
32865ab
chore: initial scripts
gunjjoshi Sep 24, 2025
39bf63d
refactor: update scripts
gunjjoshi Sep 24, 2025
ef93d50
refactor: update script
gunjjoshi Sep 24, 2025
82c5939
refactor: update scripts and templates
gunjjoshi Sep 30, 2025
bc812da
refactor: remove unwanted files
gunjjoshi Sep 30, 2025
fe66127
chore: generate acosd
gunjjoshi Sep 30, 2025
d4db062
chore: generate acosd
gunjjoshi Sep 30, 2025
50ab32e
refactor: use correct scalar function name in C
gunjjoshi Sep 30, 2025
033dc3f
refactor: add handlebars for output policy phrases
gunjjoshi Oct 22, 2025
a6f8e92
Merge remote-tracking branch 'upstream/develop' into scaffolds
stdlib-bot Nov 5, 2025
af38a80
Apply suggestions from code review
kgryte Nov 5, 2025
e833eaa
Merge branch 'stdlib-js:develop' into scaffolds
gunjjoshi Nov 10, 2025
1d034ff
refactor: use input policy phrase in repl
gunjjoshi Nov 10, 2025
6f2e394
refactor: use stdlib packages
gunjjoshi Nov 10, 2025
a3e2f9f
refactor: use stdlib packages
gunjjoshi Nov 10, 2025
1f69a2f
refactor: use array/base/assert/contains
gunjjoshi Nov 10, 2025
05f9132
chore: remove scripts field
gunjjoshi Nov 10, 2025
1d9dedb
fix: lint error, check exit code directly
gunjjoshi Nov 10, 2025
8151f43
refactor: handle example results correctly
gunjjoshi Nov 10, 2025
6a6757f
feat: add more dtype mappings
gunjjoshi Nov 10, 2025
f2d00b4
docs: remove invalid dtypes from comments
gunjjoshi Nov 10, 2025
60ea576
feat: add support for OUTPUT_DTYPE_TS
gunjjoshi Nov 19, 2025
25fbc40
Merge branch 'stdlib-js:develop' into scaffolds
gunjjoshi Nov 19, 2025
9f3d03f
feat: add support to handle prefix aliases of different namespaces
gunjjoshi Nov 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
<!--

@license Apache-2.0

Copyright (c) {{YEAR}} {{COPYRIGHT}}.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# {{ALIAS}}

> {{README_PKG_DESC}}

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var {{ALIAS}} = require( '@{{PKG}}' );
```

#### {{ALIAS}}( x\[, options] )

{{README_MAIN_DESC}}

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );

var x = array( {{JS_EXAMPLE_VALUES_2X2}} );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little tricky, as it assumes that x is allowed to be a float64 array. I am not sure that will always be the case. E.g., we could have a ufunc which only accept integer arrays or complex number arrays, etc. I am not sure the most robust solution here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you confirm that, for all ufuncs in math special, we will support float64, float32, and generic?

Copy link
Member Author

@gunjjoshi gunjjoshi Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe all of them will support float64, float32 and generic. And for cpolar, which we discussed in the call, I found that we can implement polar, by keeping the phase angle as 0 or pi. MATLAB already supports both complex and real numbers for its angle() function. The documentation here states:

"When the elements of z are non-negative real numbers, angle returns 0. When the elements of z are negative real numbers, angle returns π."

var y = {{ALIAS}}( x );
// returns <ndarray>

var arr = ndarray2array( y );
// returns {{JS_EXAMPLE_RESULTS_2X2}}
```

The function accepts the following arguments:

- **x**: input [ndarray][@stdlib/ndarray/ctor].
- **options**: function options (_optional_).

The function accepts the following options:

- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a {{OUTPUT_POLICY_PHRASE}} [data type][@stdlib/ndarray/dtypes].
- **order**: output ndarray [order][@stdlib/ndarray/orders] (i.e., memory layout).

By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option.

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );
var getDType = require( '@stdlib/ndarray/dtype' );

var x = array( {{JS_EXAMPLE_VALUES_2X2}} );
var y = {{ALIAS}}( x, {
'dtype': 'generic'
});
// returns <ndarray>

var dt = getDType( y );
// returns 'generic'

var arr = ndarray2array( y );
// returns {{JS_EXAMPLE_RESULTS_2X2}}
```

By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having the same [order][@stdlib/ndarray/orders] as the input [ndarray][@stdlib/ndarray/ctor]. To return an [ndarray][@stdlib/ndarray/ctor] having a specific memory layout irrespective of the memory layout of the input [ndarray][@stdlib/ndarray/ctor], set the `order` option.

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );
var getOrder = require( '@stdlib/ndarray/order' );

var x = array( {{JS_EXAMPLE_VALUES_2X2}} );
var y = {{ALIAS}}( x, {
'order': 'column-major'
});
// returns <ndarray>

var ord = getOrder( y );
// returns 'column-major'

var arr = ndarray2array( y );
// returns {{JS_EXAMPLE_RESULTS_2X2}}
```

#### {{ALIAS}}.assign( x, y )

{{README_ASSIGN_DESC}}

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );

var x = array( {{JS_EXAMPLE_VALUES_2X2}} );
var y = array( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] );

var out = {{ALIAS}}.assign( x, y );
// returns <ndarray>

var bool = ( out === y );
// returns true

var arr = ndarray2array( out );
// returns {{JS_EXAMPLE_RESULTS_2X2}}
```

The function accepts the following arguments:

- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape of the output [ndarray][@stdlib/ndarray/ctor].
- **y**: output [ndarray][@stdlib/ndarray/ctor].

The function supports broadcasting an input [ndarray][@stdlib/ndarray/ctor] to the shape of the output [ndarray][@stdlib/ndarray/ctor] without performing a physical copy of the input [ndarray][@stdlib/ndarray/ctor]'s underlying data.

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var zeros = require( '@stdlib/ndarray/zeros' );
var array = require( '@stdlib/ndarray/array' );

// Create a 2x2 input ndarray:
var x = array( {{JS_EXAMPLE_VALUES_2X2}} );

// Create a 2x2x2 output ndarray:
var y = zeros( [ 2, 2, 2 ] );

var out = {{ALIAS}}.assign( x, y );
// returns <ndarray>

var arr = ndarray2array( out );
// returns [ {{JS_EXAMPLE_RESULTS_2X2}}, {{JS_EXAMPLE_RESULTS_2X2}} ]
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having a {{OUTPUT_POLICY_PHRASE}} [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes].

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var random = require( '@stdlib/random/{{BASE_PRNG}}' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var {{ALIAS}} = require( '@{{PKG}}' );

var x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}} );
console.log( ndarray2array( x ) );

var y = {{ALIAS}}( x );
console.log( ndarray2array( y ) );
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/math/base/special/{{ALIAS}}]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40{{PKG_LINK_SUFFIX}}

[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor

[@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders

[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes

[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies

[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* @license Apache-2.0
*
* Copyright (c) {{YEAR}} {{COPYRIGHT}}.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var random = require( '@stdlib/random/{{BASE_PRNG}}' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var getData = require( '@stdlib/ndarray/data-buffer' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var {{ALIAS}} = require( './../lib/main.js' );


// VARIABLES //

var DTYPES = [
'float64',
'float32',
'generic'
];


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} size - array size
* @param {string} dtype - data type
* @returns {Function} benchmark function
*/
function createBenchmark( size, dtype ) {
var x = random( [ size ], {{RAND_MIN}}, {{RAND_MAX}}, {
'dtype': dtype
});
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = {{ALIAS}}( x );
if ( typeof y !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( isnan( getData( y )[ i%size ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var size;
var min;
var max;
var dt;
var f;
var i;
var j;

min = 1; // 10^min
max = 6; // 10^max

for ( j = 0; j < DTYPES.length; j++ ) {
dt = DTYPES[ j ];
for ( i = min; i <= max; i++ ) {
size = pow( 10, i );
f = createBenchmark( size, dt );
bench( format( '%s:contiguous=true,ndims=1,dtype=%s,size=%d', pkg, dt, size ), f );
}
}
}

main();
Loading
Loading