Skip to content

Commit 60ca1ff

Browse files
committed
Auto-generated commit
1 parent 84cc466 commit 60ca1ff

File tree

12 files changed

+784
-0
lines changed

12 files changed

+784
-0
lines changed

CHANGELOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,28 @@ This release closes the following issue:
904904

905905
<!-- /.package -->
906906

907+
<section class="package" id="array-base-linspace2d-unreleased">
908+
909+
#### [@stdlib/array/base/linspace2d](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/linspace2d)
910+
911+
<details>
912+
913+
<section class="features">
914+
915+
##### Features
916+
917+
- [`b0da3de`](https://github.com/stdlib-js/stdlib/commit/b0da3de9a0fa3d1e657ee5a05dcca053fe74e515) - `add array/base/linspace2d` [(#5464)](https://github.com/stdlib-js/stdlib/pull/5464)
918+
919+
</section>
920+
921+
<!-- /.features -->
922+
923+
</details>
924+
925+
</section>
926+
927+
<!-- /.package -->
928+
907929
<section class="package" id="array-base-map-unreleased">
908930

909931
#### [@stdlib/array/base/map](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/map)
@@ -1649,6 +1671,7 @@ A total of 14 people contributed to this release. Thank you to the following con
16491671

16501672
<details>
16511673

1674+
- [`b0da3de`](https://github.com/stdlib-js/stdlib/commit/b0da3de9a0fa3d1e657ee5a05dcca053fe74e515) - **feat:** `add array/base/linspace2d` [(#5464)](https://github.com/stdlib-js/stdlib/pull/5464) _(by Muhammad Haris, Athan Reines, stdlib-bot)_
16521675
- [`40de89d`](https://github.com/stdlib-js/stdlib/commit/40de89d0b84ab345f198d6a90696c0762efde887) - **feat:** add `array/base/reshape` [(#5639)](https://github.com/stdlib-js/stdlib/pull/5639) _(by Muhammad Haris, Athan Reines)_
16531676
- [`54534dd`](https://github.com/stdlib-js/stdlib/commit/54534ddb74b35d0b99915f8017ed9d9e692a7502) - **chore:** address commit comments [(#5978)](https://github.com/stdlib-js/stdlib/pull/5978) _(by Jay Soni, Athan Reines, stdlib-bot)_
16541677
- [`e28064f`](https://github.com/stdlib-js/stdlib/commit/e28064f9d93a232d82297842a9a4bd2895952a55) - **docs:** update namespace TypeScript declarations [(#6478)](https://github.com/stdlib-js/stdlib/pull/6478) _(by stdlib-bot)_

base/linspace2d/README.md

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# linspace2d
22+
23+
> Generate a linearly spaced two-dimensional nested numeric array.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var linspace2d = require( '@stdlib/array/base/linspace2d' );
31+
```
32+
33+
#### linspace2d( start, stop, shape, colexicographic )
34+
35+
Generates a linearly spaced two-dimensional nested numeric array.
36+
37+
```javascript
38+
var x = linspace2d( 0, 100, [ 2, 3 ], false );
39+
// returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
40+
41+
x = linspace2d( 0, 100, [ 2, 3 ], true );
42+
// returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
43+
```
44+
45+
The function accepts the following arguments:
46+
47+
- **start**: first array value.
48+
- **stop**: last array value.
49+
- **shape**: array shape.
50+
- **colexicographic**: specifies whether generated array values should be stored in colexicographic order.
51+
52+
</section>
53+
54+
<!-- /.usage -->
55+
56+
<section class="notes">
57+
58+
## Notes
59+
60+
- The output array is guaranteed to include the `start` and `stop` values. Beware, however, that values between `start` and `stop` are subject to floating-point rounding errors. Hence,
61+
62+
```javascript
63+
var arr = linspace2d( 0, 1, [ 1, 3 ], false );
64+
// returns [ [ 0, ~0.5, 1 ] ]
65+
```
66+
67+
where `arr[0][1]` is only guaranteed to be approximately equal to `0.5`. If you desire more control over element precision, consider using [`roundn`][@stdlib/math/base/special/roundn]:
68+
69+
```javascript
70+
var roundn = require( '@stdlib/math/base/special/roundn' );
71+
var map2d = require( '@stdlib/array/base/map2d' );
72+
73+
var arr = linspace2d( 0, 1, [ 1, 3 ], false );
74+
// returns [ [ 0, ~0.5, 1 ] ]
75+
76+
// Round each value to the nearest tenth:
77+
var out = map2d( arr, [ 1, 3 ], clbk );
78+
// returns [ [ 0, 0.5, 1 ] ]
79+
80+
function clbk( v ) {
81+
return roundn( v, -1 );
82+
}
83+
```
84+
85+
</section>
86+
87+
<!-- /.notes -->
88+
89+
<section class="examples">
90+
91+
## Examples
92+
93+
<!-- eslint no-undef: "error" -->
94+
95+
```javascript
96+
var linspace2d = require( '@stdlib/array/base/linspace2d' );
97+
98+
var out = linspace2d( 0, 10, [ 2, 5 ], false );
99+
console.log( out );
100+
101+
out = linspace2d( 0, 10, [ 2, 3 ], true );
102+
console.log( out );
103+
104+
out = linspace2d( 0, 10, [ 4, 2 ], true );
105+
console.log( out );
106+
107+
// Create an array of arrays with decremented values:
108+
out = linspace2d( 10, 0, [ 2, 5 ], false );
109+
console.log( out );
110+
```
111+
112+
</section>
113+
114+
<!-- /.examples -->
115+
116+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
117+
118+
<section class="related">
119+
120+
</section>
121+
122+
<!-- /.related -->
123+
124+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
125+
126+
<section class="links">
127+
128+
[@stdlib/math/base/special/roundn]: https://github.com/stdlib-js/math-base-special-roundn
129+
130+
</section>
131+
132+
<!-- /.links -->
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isArrayArray = require( '@stdlib/assert/is-array-array' );
25+
var pkg = require( './../package.json' ).name;
26+
var linspace2d = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var i;
33+
var v;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
v = linspace2d( 0.0, 100.0, [ 2, 3 ], false );
38+
if ( typeof v !== 'object' ) {
39+
b.fail( 'should return an array of arrays' );
40+
}
41+
}
42+
b.toc();
43+
if ( !isArrayArray( v ) ) {
44+
b.fail( 'should return an array of arrays' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 pow = require( '@stdlib/math/base/special/pow' );
25+
var floor = require( '@stdlib/math/base/special/floor' );
26+
var sqrt = require( '@stdlib/math/base/special/sqrt' );
27+
var isArrayArray = require( '@stdlib/assert/is-array-array' );
28+
var pkg = require( './../package.json' ).name;
29+
var linspace2d = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} N - array lengths
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( N ) {
42+
return benchmark;
43+
44+
/**
45+
* Benchmark function.
46+
*
47+
* @private
48+
* @param {Benchmark} b - benchmark instance
49+
*/
50+
function benchmark( b ) {
51+
var v;
52+
var i;
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
v = linspace2d( 0.0, 100.0, [ N, N ], false );
57+
if ( typeof v !== 'object' ) {
58+
b.fail( 'should return an array of arrays' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isArrayArray( v ) ) {
63+
b.fail( 'should return an array of arrays' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var min;
80+
var max;
81+
var N;
82+
var f;
83+
var i;
84+
85+
min = 1; // 10^min
86+
max = 6; // 10^max
87+
88+
for ( i = min; i <= max; i++ ) {
89+
N = floor( sqrt( pow( 10, i ) ) );
90+
f = createBenchmark( N );
91+
bench( pkg+'::square_matrix:size='+(N*N), f );
92+
}
93+
}
94+
95+
main();

base/linspace2d/docs/repl.txt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
{{alias}}( start, stop, shape, colexicographic )
3+
Generates a linearly spaced two-dimensional nested numeric array.
4+
5+
The output array is guaranteed to include the `start` and `stop` values.
6+
7+
Parameters
8+
----------
9+
start: number
10+
First array value.
11+
12+
stop: number
13+
Last array value.
14+
15+
shape: Array<integer>
16+
Array shape.
17+
18+
colexicographic: boolean
19+
Specifies whether generated array values should be stored in
20+
colexicographic order.
21+
22+
Returns
23+
-------
24+
out: Array
25+
Linearly spaced two-dimensional nested numeric array.
26+
27+
Examples
28+
--------
29+
> var arr = {{alias}}( 0, 10, [ 2, 3 ], false )
30+
[ [ 0, 2, 4 ], [ 6, 8, 10 ] ]
31+
32+
See Also
33+
--------

base/linspace2d/docs/types/index.d.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
import { Shape2D } from '@stdlib/types/ndarray';
22+
23+
/**
24+
* Two-dimensional nested array.
25+
*/
26+
type Array2D<T> = Array<Array<T>>;
27+
28+
/**
29+
* Generates a linearly spaced two-dimensional nested numeric array.
30+
*
31+
* @param start - first array value
32+
* @param stop - last array value
33+
* @param shape - array shape
34+
* @param colexicographic - specifies whether generated array values should be stored in colexicographic order
35+
* @returns linearly spaced two-dimensional nested numeric array
36+
*
37+
* @example
38+
* var x = linspace2d( 0, 100, [ 2, 3 ], false );
39+
* // returns [ [ 0, 20, 40 ], [ 60, 80, 100 ] ]
40+
*
41+
* x = linspace2d( 0, 100, [ 2, 3 ], true );
42+
* // returns [ [ 0, 40, 80 ], [ 20, 60, 100 ] ]
43+
*/
44+
declare function linspace2d( start: number, stop: number, shape: Shape2D, colexicographic: boolean ): Array2D<number>;
45+
46+
47+
// EXPORTS //
48+
49+
export = linspace2d;

0 commit comments

Comments
 (0)