Skip to content

Commit 984870a

Browse files
committed
Auto-generated commit
1 parent aa18a35 commit 984870a

File tree

12 files changed

+1834
-1
lines changed

12 files changed

+1834
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-11-11)
7+
## Unreleased (2025-11-12)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`e23e0c4`](https://github.com/stdlib-js/stdlib/commit/e23e0c4afb1a711ddc091197ea4dac8888aca03f) - add `ndarray/copy` [(#8490)](https://github.com/stdlib-js/stdlib/pull/8490)
1314
- [`cad6845`](https://github.com/stdlib-js/stdlib/commit/cad68452e8d2a52ebe1ebfd74117d98197a4a568) - add `isComplexFloatingPointDataTypeChar` to namespace
1415
- [`b8c50f8`](https://github.com/stdlib-js/stdlib/commit/b8c50f8cb3942eeb670d144cb4089ff30ed7370b) - add `ndarray/base/assert/is-complex-floating-point-data-type-char`
1516
- [`a07dba7`](https://github.com/stdlib-js/stdlib/commit/a07dba7671e5c34b32277a26e8f2aa014f0868b4) - add `nullaryStrided1dDispatchFactory` to namespace
@@ -624,6 +625,7 @@ A total of 32 issues were closed in this release:
624625

625626
<details>
626627

628+
- [`e23e0c4`](https://github.com/stdlib-js/stdlib/commit/e23e0c4afb1a711ddc091197ea4dac8888aca03f) - **feat:** add `ndarray/copy` [(#8490)](https://github.com/stdlib-js/stdlib/pull/8490) _(by Muhammad Haris, Athan Reines)_
627629
- [`9e78d0f`](https://github.com/stdlib-js/stdlib/commit/9e78d0f090816b652f837318212b91117f5cbd9a) - **docs:** fix typo _(by Philipp Burckhardt)_
628630
- [`12eb3ae`](https://github.com/stdlib-js/stdlib/commit/12eb3aee1baf1aa53cea76e8149c59d8c702b0b2) - **test:** add missing parentheses to descriptions _(by Philipp Burckhardt)_
629631
- [`ce97f8e`](https://github.com/stdlib-js/stdlib/commit/ce97f8e6b4c85870b9b983d930820c98de7b3c2b) - **chore:** fix C lint errors [(#8486)](https://github.com/stdlib-js/stdlib/pull/8486) _(by Geo Daoyu, Athan Reines)_

copy/README.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
# copy
22+
23+
> Copy an input [ndarray][@stdlib/ndarray/ctor] to a new [ndarray][@stdlib/ndarray/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var copy = require( '@stdlib/ndarray/copy' );
41+
```
42+
43+
#### copy( x\[, options] )
44+
45+
Copies an input [ndarray][@stdlib/ndarray/ctor] to a new [ndarray][@stdlib/ndarray/ctor] having the same shape and [data type][@stdlib/ndarray/dtypes].
46+
47+
```javascript
48+
var getShape = require( '@stdlib/ndarray/shape' );
49+
var zeros = require( '@stdlib/ndarray/zeros' );
50+
51+
var x = zeros( [ 2, 2 ] );
52+
// returns <ndarray>
53+
54+
var y = copy( x );
55+
// returns <ndarray>
56+
57+
var sh = getShape( y );
58+
// returns [ 2, 2 ]
59+
```
60+
61+
The function supports the following `options`:
62+
63+
- **dtype**: output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes]. Overrides the input ndarray's inferred [data type][@stdlib/ndarray/dtypes].
64+
- **order**: specifies whether the output [ndarray][@stdlib/ndarray/ctor] should be `'row-major'` (C-style) or `'column-major'` (Fortran-style). Overrides the input ndarray's inferred order.
65+
- **mode**: specifies how to handle indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`.
66+
- **submode**: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). If provided fewer modes than dimensions, the constructor recycles modes using modulo arithmetic. Default: `[ options.mode ]`.
67+
68+
To override either the `dtype` or `order`, specify the corresponding option. For example, to override the inferred [data type][@stdlib/ndarray/dtypes],
69+
70+
```javascript
71+
var getShape = require( '@stdlib/ndarray/shape' );
72+
var getDtype = require( '@stdlib/ndarray/dtype' );
73+
var zeros = require( '@stdlib/ndarray/zeros' );
74+
75+
var x = zeros( [ 2, 2 ] );
76+
// returns <ndarray>
77+
78+
var dt = String( getDtype( x ) );
79+
// returns 'float64'
80+
81+
var y = copy( x, {
82+
'dtype': 'float32'
83+
});
84+
// returns <ndarray>
85+
86+
var sh = getShape( y );
87+
// returns [ 2, 2 ]
88+
89+
dt = String( getDtype( y ) );
90+
// returns 'float32'
91+
```
92+
93+
</section>
94+
95+
<!-- /.usage -->
96+
97+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
98+
99+
<section class="notes">
100+
101+
## Notes
102+
103+
- The function performs a full copy in which an ndarray's underlying data is copied to a new underlying data buffer.
104+
105+
</section>
106+
107+
<!-- /.notes -->
108+
109+
<!-- Package usage examples. -->
110+
111+
<section class="examples">
112+
113+
## Examples
114+
115+
<!-- eslint no-undef: "error" -->
116+
117+
```javascript
118+
var uniform = require( '@stdlib/random/uniform' );
119+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
120+
var copy = require( '@stdlib/ndarray/copy' );
121+
122+
var x = uniform( [ 5, 2 ], -10.0, 10.0, {
123+
'dtype': 'generic'
124+
});
125+
console.log( ndarray2array( x ) );
126+
127+
var y = copy( x );
128+
console.log( ndarray2array( y ) );
129+
```
130+
131+
</section>
132+
133+
<!-- /.examples -->
134+
135+
<!-- 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. -->
136+
137+
<section class="references">
138+
139+
</section>
140+
141+
<!-- /.references -->
142+
143+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
144+
145+
<section class="related">
146+
147+
</section>
148+
149+
<!-- /.related -->
150+
151+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
152+
153+
<section class="links">
154+
155+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
156+
157+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
158+
159+
<!-- <related-links> -->
160+
161+
<!-- </related-links> -->
162+
163+
</section>
164+
165+
<!-- /.links -->

copy/benchmark/benchmark.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 isndarray = require( '@stdlib/assert/is-ndarray-like' );
25+
var zeros = require( './../../zeros' );
26+
var pkg = require( './../package.json' ).name;
27+
var copy = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var values;
34+
var out;
35+
var i;
36+
37+
values = [
38+
zeros( [ 25 ] ),
39+
zeros( [ 5, 5 ] ),
40+
zeros( [ 3, 3, 3 ] ),
41+
zeros( [ 2, 2, 2, 3 ] )
42+
];
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
out = copy( values[ i%values.length ] );
47+
if ( typeof out !== 'object' ) {
48+
b.fail( 'should return an ndarray' );
49+
}
50+
}
51+
b.toc();
52+
if ( !isndarray( out ) ) {
53+
b.fail( 'should return an ndarray' );
54+
}
55+
b.pass( 'benchmark finished' );
56+
b.end();
57+
});

copy/benchmark/benchmark.size.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
26+
var zeros = require( './../../zeros' );
27+
var pkg = require( './../package.json' ).name;
28+
var copy = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var DTYPES = [
34+
'float64',
35+
'float32',
36+
'generic',
37+
'int32',
38+
'uint32',
39+
'uint8',
40+
'complex128',
41+
'complex64'
42+
];
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {PositiveInteger} len - array length
52+
* @param {*} dtype - data type
53+
* @returns {Function} benchmark function
54+
*/
55+
function createBenchmark( len, dtype ) {
56+
var x = zeros( [ len ], {
57+
'dtype': dtype
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 arr;
69+
var i;
70+
71+
b.tic();
72+
for ( i = 0; i < b.iterations; i++ ) {
73+
arr = copy( x );
74+
if ( arr.length !== len ) {
75+
b.fail( 'unexpected length' );
76+
}
77+
}
78+
b.toc();
79+
if ( !isndarrayLike( arr ) ) {
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 dt;
100+
var f;
101+
var i;
102+
var j;
103+
104+
min = 1; // 10^min
105+
max = 6; // 10^max
106+
107+
for ( j = 0; j < DTYPES.length; j++ ) {
108+
dt = DTYPES[ j ];
109+
for ( i = min; i <= max; i++ ) {
110+
len = pow( 10, i );
111+
f = createBenchmark( len, dt );
112+
bench( pkg+':dtype='+String( dt )+',size='+len, f );
113+
}
114+
}
115+
}
116+
117+
main();

0 commit comments

Comments
 (0)