Skip to content

Commit 6689dff

Browse files
committed
Auto-generated commit
1 parent 9ce122f commit 6689dff

File tree

11 files changed

+1001
-1
lines changed

11 files changed

+1001
-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-10-30)
7+
## Unreleased (2025-11-01)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`4b8a736`](https://github.com/stdlib-js/stdlib/commit/4b8a736be3db63bd001c4b556bf69f60045a9df2) - add `ndarray/base/copy` [(#8329)](https://github.com/stdlib-js/stdlib/pull/8329)
1314
- [`9d84704`](https://github.com/stdlib-js/stdlib/commit/9d8470471bc66b3a98da174b72a3ab4f9302744f) - add `ndarray/flatten-from` [(#8153)](https://github.com/stdlib-js/stdlib/pull/8153)
1415
- [`cb7cf8c`](https://github.com/stdlib-js/stdlib/commit/cb7cf8ce407731354c5b2861ffa659c8adbc3149) - add `ndarray/reverse-dimension` [(#8186)](https://github.com/stdlib-js/stdlib/pull/8186)
1516
- [`92b9d26`](https://github.com/stdlib-js/stdlib/commit/92b9d26a38360ed2b4b7a8f1fe21b31efc9192c8) - add `ndarray/to-reversed` [(#8149)](https://github.com/stdlib-js/stdlib/pull/8149)
@@ -603,6 +604,7 @@ A total of 31 issues were closed in this release:
603604

604605
<details>
605606

607+
- [`4b8a736`](https://github.com/stdlib-js/stdlib/commit/4b8a736be3db63bd001c4b556bf69f60045a9df2) - **feat:** add `ndarray/base/copy` [(#8329)](https://github.com/stdlib-js/stdlib/pull/8329) _(by Muhammad Haris, Athan Reines)_
606608
- [`4b9391c`](https://github.com/stdlib-js/stdlib/commit/4b9391cd318c753562d9c670fe2946e012fb15cb) - **chore:** fix C lint errors [(#8309)](https://github.com/stdlib-js/stdlib/pull/8309) _(by Navyansh Kesarwani, Athan Reines)_
607609
- [`a0de0e6`](https://github.com/stdlib-js/stdlib/commit/a0de0e64cebbdca08b7625a8357902c08268e92e) - **chore:** fix JavaScript lint errors [(#8226)](https://github.com/stdlib-js/stdlib/pull/8226) _(by Bhupesh Kumar, Athan Reines)_
608610
- [`0ccda74`](https://github.com/stdlib-js/stdlib/commit/0ccda74155ae15d3258c06cef82cbd08f5f3a730) - **chore:** fix C lint errors [(#8199)](https://github.com/stdlib-js/stdlib/pull/8199) _(by Geo Daoyu, Athan Reines)_

base/copy/README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 to a new ndarray 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/base/copy' );
41+
```
42+
43+
#### copy( x )
44+
45+
Copies an input ndarray to a new ndarray 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/base/zeros' );
50+
51+
var x = zeros( 'float64', [ 2, 2 ], 'row-major' );
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+
</section>
62+
63+
<!-- /.usage -->
64+
65+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
66+
67+
<section class="notes">
68+
69+
## Notes
70+
71+
- The function performs a full copy in which an ndarray's underlying data is copied to a new underlying data buffer.
72+
- Along with data type, shape, and order, the function infers the "class" of the returned ndarray from the provided ndarray. For example, if provided a "base" [ndarray][@stdlib/ndarray/base/ctor], the function returns a base [ndarray][@stdlib/ndarray/base/ctor]. If provided a non-base [ndarray][@stdlib/ndarray/ctor], the function returns a non-base [ndarray][@stdlib/ndarray/ctor].
73+
74+
</section>
75+
76+
<!-- /.notes -->
77+
78+
<!-- Package usage examples. -->
79+
80+
<section class="examples">
81+
82+
## Examples
83+
84+
<!-- eslint no-undef: "error" -->
85+
86+
```javascript
87+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
88+
var array = require( '@stdlib/ndarray/array' );
89+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
90+
var copy = require( '@stdlib/ndarray/base/copy' );
91+
92+
var xbuf = bernoulli( 10, 0.9, {
93+
'dtype': 'generic'
94+
});
95+
var x = array({
96+
'dtype': 'generic',
97+
'data': xbuf,
98+
'shape': [ 5, 2 ],
99+
'strides': [ 2, 1 ],
100+
'offset': 0,
101+
'order': 'row-major'
102+
});
103+
console.log( ndarray2array( x ) );
104+
105+
var o = copy( x );
106+
console.log( ndarray2array( o ) );
107+
```
108+
109+
</section>
110+
111+
<!-- /.examples -->
112+
113+
<!-- 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. -->
114+
115+
<section class="references">
116+
117+
</section>
118+
119+
<!-- /.references -->
120+
121+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
122+
123+
<section class="related">
124+
125+
</section>
126+
127+
<!-- /.related -->
128+
129+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
130+
131+
<section class="links">
132+
133+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
134+
135+
[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray/tree/main/base/ctor
136+
137+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
138+
139+
</section>
140+
141+
<!-- /.links -->

base/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( './../../../base/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( 'float64', [ 10 ], 'row-major' ),
39+
zeros( 'float32', [ 5, 5 ], 'row-major' ),
40+
zeros( 'int32', [ 3, 3, 3 ], 'row-major' ),
41+
zeros( 'uint32', [ 2, 2, 2, 2 ], 'row-major' )
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+
});

base/copy/docs/repl.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
{{alias}}( x )
3+
Copies an input ndarray to a new ndarray having the same shape and data
4+
type.
5+
6+
The function performs a full copy in which an ndarray's underlying data is
7+
copied to a new underlying data buffer.
8+
9+
Along with data type, shape, and order, the function infers the "class" of
10+
the returned ndarray from the provided ndarray. For example, if provided a
11+
"base" ndarray, the function returns a base ndarray. If provided a non-base
12+
ndarray, the function returns a non-base ndarray.
13+
14+
Parameters
15+
----------
16+
x: ndarray
17+
Input array.
18+
19+
Returns
20+
-------
21+
out: ndarray
22+
Output array.
23+
24+
Examples
25+
--------
26+
> var x = {{alias:@stdlib/ndarray/base/zeros}}( 'float64', [ 2, 2 ], 'row-major' )
27+
<ndarray>
28+
> var sh = {{alias:@stdlib/ndarray/shape}}( x )
29+
[ 2, 2 ]
30+
> var y = {{alias}}( x )
31+
<ndarray>
32+
> sh = {{alias:@stdlib/ndarray/shape}}( y )
33+
[ 2, 2 ]
34+
35+
See Also
36+
--------

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

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+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Copies an input ndarray to a new ndarray having the same shape and data type.
27+
*
28+
* ## Notes
29+
*
30+
* - The function performs a full copy in which an ndarray's underlying data is copied to a new underlying data buffer.
31+
*
32+
* @param x - input array
33+
* @returns output array
34+
*
35+
* @example
36+
* var getShape = require( '@stdlib/ndarray/shape' );
37+
* var getDType = require( '@stdlib/ndarray/dtype' );
38+
* var zeros = require( '@stdlib/ndarray/base/zeros' );
39+
*
40+
* var x = zeros( 'float64', [ 2, 2 ], 'row-major' );
41+
* // returns <ndarray>
42+
*
43+
* var sh = getShape( x );
44+
* // returns [ 2, 2 ]
45+
*
46+
* var y = copy( x );
47+
* // returns <ndarray>
48+
*
49+
* sh = getShape( y );
50+
* // returns [ 2, 2 ]
51+
*/
52+
declare function copy<T extends ndarray = ndarray>( x: T ): T;
53+
54+
55+
// EXPORTS //
56+
57+
export = copy;

base/copy/docs/types/test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
import zeros = require( './../../../../base/zeros' );
20+
import empty = require( './../../../../base/empty' );
21+
import copy = require( './index' );
22+
23+
24+
// TESTS //
25+
26+
// The function returns an ndarray...
27+
{
28+
const sh = [ 2, 2 ];
29+
const ord = 'row-major';
30+
31+
copy( zeros( 'float64', sh, ord ) ); // $ExpectType float64ndarray
32+
copy( zeros( 'float32', sh, ord ) ); // $ExpectType float32ndarray
33+
copy( zeros( 'complex128', sh, ord ) ); // $ExpectType complex128ndarray
34+
copy( zeros( 'complex64', sh, ord ) ); // $ExpectType complex64ndarray
35+
copy( zeros( 'int32', sh, ord ) ); // $ExpectType int32ndarray
36+
copy( zeros( 'int16', sh, ord ) ); // $ExpectType int16ndarray
37+
copy( zeros( 'int8', sh, ord ) ); // $ExpectType int8ndarray
38+
copy( zeros( 'uint32', sh, ord ) ); // $ExpectType uint32ndarray
39+
copy( zeros( 'uint16', sh, ord ) ); // $ExpectType uint16ndarray
40+
copy( zeros( 'uint8', sh, ord ) ); // $ExpectType uint8ndarray
41+
copy( zeros( 'uint8c', sh, ord ) ); // $ExpectType uint8cndarray
42+
copy( empty( 'bool', sh, ord ) ); // $ExpectType boolndarray
43+
copy( zeros( 'generic', sh, ord ) ); // $ExpectType genericndarray<number>
44+
}
45+
46+
// The compiler throws an error if the function is provided a first argument is not an ndarray...
47+
{
48+
copy( '10' ); // $ExpectError
49+
copy( 10 ); // $ExpectError
50+
copy( false ); // $ExpectError
51+
copy( true ); // $ExpectError
52+
copy( null ); // $ExpectError
53+
copy( [] ); // $ExpectError
54+
copy( {} ); // $ExpectError
55+
copy( ( x: number ): number => x ); // $ExpectError
56+
}
57+
58+
// The compiler throws an error if the function is provided an unsupported number of arguments...
59+
{
60+
copy(); // $ExpectError
61+
copy( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectError
62+
}

0 commit comments

Comments
 (0)