Skip to content

Commit b401bfe

Browse files
committed
feat: add blas/ext/base/ndarray/zunitspace
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 78898df commit b401bfe

10 files changed

Lines changed: 951 additions & 0 deletions

File tree

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# zunitspace
22+
23+
> Fill a one-dimensional double-precision complex floating-point ndarray with linearly spaced numeric elements which increment by `1` starting from a specified value.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var zunitspace = require( '@stdlib/blas/ext/base/ndarray/zunitspace' );
37+
```
38+
39+
#### zunitspace( arrays )
40+
41+
Fills a one-dimensional double-precision complex floating-point ndarray with linearly spaced numeric elements which increment by `1` starting from a specified value.
42+
43+
<!-- eslint-disable max-len -->
44+
45+
```javascript
46+
var Complex128Array = require( '@stdlib/array/complex128' );
47+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
48+
var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' );
49+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
50+
51+
var xbuf = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
52+
var x = new ndarray( 'complex128', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
53+
54+
var start = scalar2ndarray( new Complex128( 3.0, 0.0 ), 'complex128', 'row-major' );
55+
56+
var out = zunitspace( [ x, start ] );
57+
// returns <ndarray>[ <Complex128>[ 3.0, 0.0 ], <Complex128>[ 4.0, 0.0 ], <Complex128>[ 5.0, 0.0 ], <Complex128>[ 6.0, 0.0 ] ]
58+
```
59+
60+
The function has the following parameters:
61+
62+
- **arrays**: array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray containing a starting value.
63+
64+
</section>
65+
66+
<!-- /.usage -->
67+
68+
<section class="notes">
69+
70+
## Notes
71+
72+
- The input ndarray is modified **in-place** (i.e., the input ndarray is **mutated**).
73+
74+
</section>
75+
76+
<!-- /.notes -->
77+
78+
<section class="examples">
79+
80+
## Examples
81+
82+
<!-- eslint no-undef: "error" -->
83+
84+
```javascript
85+
var zeros = require( '@stdlib/array/zeros' );
86+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
87+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
88+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
89+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
90+
var zunitspace = require( '@stdlib/blas/ext/base/ndarray/zunitspace' );
91+
92+
var xbuf = zeros( 10, 'complex128' );
93+
var x = new ndarray( 'complex128', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
94+
var start = scalar2ndarray( new Complex128( 3.0, 0.0 ), {
95+
'dtype': 'complex128'
96+
});
97+
98+
console.log( ndarray2array( x ) );
99+
100+
zunitspace( [ x, start ] );
101+
console.log( ndarray2array( x ) );
102+
```
103+
104+
</section>
105+
106+
<!-- /.examples -->
107+
108+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
109+
110+
<section class="related">
111+
112+
</section>
113+
114+
<!-- /.related -->
115+
116+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
117+
118+
<section class="links">
119+
120+
</section>
121+
122+
<!-- /.links -->
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var zeros = require( '@stdlib/array/zeros' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var format = require( '@stdlib/string/format' );
27+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
28+
var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' );
29+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
30+
var pkg = require( './../package.json' ).name;
31+
var zunitspace = require( './../lib' );
32+
33+
34+
// VARIABLES //
35+
36+
var options = {
37+
'dtype': 'complex128'
38+
};
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} len - array length
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( len ) {
51+
var start;
52+
var xbuf;
53+
var x;
54+
55+
xbuf = zeros( len, options.dtype );
56+
x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' );
57+
start = scalar2ndarray( new Complex128( 3.0, 0.0 ), options.dtype, 'row-major' );
58+
59+
return benchmark;
60+
61+
/**
62+
* Benchmark function.
63+
*
64+
* @private
65+
* @param {Benchmark} b - benchmark instance
66+
*/
67+
function benchmark( b ) {
68+
var out;
69+
var i;
70+
71+
b.tic();
72+
for ( i = 0; i < b.iterations; i++ ) {
73+
out = zunitspace( [ x, start ] );
74+
if ( typeof out !== 'object' ) {
75+
b.fail( 'should return an ndarray' );
76+
}
77+
}
78+
b.toc();
79+
if ( typeof out !== 'object' ) {
80+
b.fail( 'should return an ndarray' );
81+
}
82+
b.pass( 'benchmark finished' );
83+
b.end();
84+
}
85+
}
86+
87+
88+
// MAIN //
89+
90+
/**
91+
* Main execution sequence.
92+
*
93+
* @private
94+
*/
95+
function main() {
96+
var len;
97+
var min;
98+
var max;
99+
var f;
100+
var i;
101+
102+
min = 1; // 10^min
103+
max = 6; // 10^max
104+
105+
for ( i = min; i <= max; i++ ) {
106+
len = pow( 10, i );
107+
f = createBenchmark( len );
108+
bench( format( '%s:len=%d', pkg, len ), f );
109+
}
110+
}
111+
112+
main();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
{{alias}}( arrays )
3+
Fills a one-dimensional double-precision complex floating-point ndarray with
4+
linearly spaced numeric elements which increment by `1` starting from a
5+
specified value.
6+
7+
The input ndarray is modified *in-place* (i.e., the input ndarray is
8+
*mutated*).
9+
10+
Parameters
11+
----------
12+
arrays: ArrayLikeObject<ndarray>
13+
Array-like object containing a one-dimensional input ndarray and a
14+
zero-dimensional ndarray containing a starting value.
15+
16+
Returns
17+
-------
18+
out: ndarray
19+
Input ndarray.
20+
21+
Examples
22+
--------
23+
> var xbuf = new {{alias:@stdlib/array/complex128}}( [ 0.0, 0.0, 0.0, 0.0 ] );
24+
> var dt = 'complex128';
25+
> var sh = [ 2 ];
26+
> var sx = [ 1 ];
27+
> var ox = 0;
28+
> var ord = 'row-major';
29+
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord );
30+
> var s = new {{alias:@stdlib/complex/float64/ctor}}( 3.0, 0.0 );
31+
> var start = {{alias:@stdlib/ndarray/base/from-scalar}}( s, dt, ord );
32+
> {{alias}}( [ x, start ] )
33+
<ndarray>[ <Complex128>[ 3.0, 0.0 ], <Complex128>[ 4.0, 0.0 ] ]
34+
35+
See Also
36+
--------
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { complex128ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Fills a one-dimensional double-precision complex floating-point ndarray with linearly spaced numeric elements which increment by `1` starting from a specified value.
27+
*
28+
* @param arrays - array-like object containing a one-dimensional input ndarray and a zero-dimensional ndarray containing a starting value
29+
* @returns input ndarray
30+
*
31+
* @example
32+
* var Complex128Array = require( '@stdlib/array/complex128' );
33+
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
34+
* var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' );
35+
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
36+
*
37+
* var xbuf = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
38+
* var x = new ndarray( 'complex128', xbuf, [ 4 ], [ 1 ], 0, 'row-major' );
39+
*
40+
* var start = scalar2ndarray( new Complex128( 3.0, 0.0 ), 'complex128', 'row-major' );
41+
*
42+
* var out = zunitspace( [ x, start ] );
43+
* // returns <ndarray>[ <Complex128>[ 3.0, 0.0 ], <Complex128>[ 4.0, 0.0 ], <Complex128>[ 5.0, 0.0 ], <Complex128>[ 6.0, 0.0 ] ]
44+
*/
45+
declare function zunitspace( arrays: [ complex128ndarray, complex128ndarray ] ): complex128ndarray;
46+
47+
48+
// EXPORTS //
49+
50+
export = zunitspace;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/* eslint-disable space-in-parens */
20+
21+
import zeros = require( '@stdlib/ndarray/zeros' );
22+
import zunitspace = require( './index' );
23+
24+
25+
// TESTS //
26+
27+
// The function returns an ndarray...
28+
{
29+
const x = zeros( [ 10 ], {
30+
'dtype': 'complex128'
31+
});
32+
const start = zeros( [], {
33+
'dtype': 'complex128'
34+
});
35+
36+
zunitspace( [ x, start ] ); // $ExpectType complex128ndarray
37+
}
38+
39+
// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays...
40+
{
41+
zunitspace( '10' ); // $ExpectError
42+
zunitspace( 10 ); // $ExpectError
43+
zunitspace( true ); // $ExpectError
44+
zunitspace( false ); // $ExpectError
45+
zunitspace( null ); // $ExpectError
46+
zunitspace( undefined ); // $ExpectError
47+
zunitspace( [] ); // $ExpectError
48+
zunitspace( {} ); // $ExpectError
49+
zunitspace( ( x: number ): number => x ); // $ExpectError
50+
}
51+
52+
// The compiler throws an error if the function is provided an unsupported number of arguments...
53+
{
54+
const x = zeros( [ 10 ], {
55+
'dtype': 'complex128'
56+
});
57+
const start = zeros( [], {
58+
'dtype': 'complex128'
59+
});
60+
61+
zunitspace(); // $ExpectError
62+
zunitspace( [ x, start ], {} ); // $ExpectError
63+
}

0 commit comments

Comments
 (0)