Skip to content

Commit b72b73f

Browse files
committed
Auto-generated commit
1 parent 3ca4bc5 commit b72b73f

File tree

12 files changed

+1460
-0
lines changed

12 files changed

+1460
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`a12ba0a`](https://github.com/stdlib-js/stdlib/commit/a12ba0a26b7e11e99b04627e57a1dd2f21ca4ad0) - add `ndarray/base/tile` [(#11499)](https://github.com/stdlib-js/stdlib/pull/11499)
1314
- [`97fd5b7`](https://github.com/stdlib-js/stdlib/commit/97fd5b7de7e74e99e0ffb4ccd27c5ae555aa02cb) - add `toUnflattened` to namespace
1415
- [`737511b`](https://github.com/stdlib-js/stdlib/commit/737511bad0cbe580a8771094f13ef75fd8975f01) - add `ndarray/base/to-unflattened` [(#11493)](https://github.com/stdlib-js/stdlib/pull/11493)
1516
- [`886ad4c`](https://github.com/stdlib-js/stdlib/commit/886ad4c592bb63614a1aedc2f6db0895eb737a01) - add `fullBy` to namespace
@@ -844,6 +845,7 @@ A total of 49 issues were closed in this release:
844845

845846
<details>
846847

848+
- [`a12ba0a`](https://github.com/stdlib-js/stdlib/commit/a12ba0a26b7e11e99b04627e57a1dd2f21ca4ad0) - **feat:** add `ndarray/base/tile` [(#11499)](https://github.com/stdlib-js/stdlib/pull/11499) _(by Muhammad Haris, Athan Reines)_
847849
- [`2505815`](https://github.com/stdlib-js/stdlib/commit/25058156cf7b1138c5c33209a5143100c376b46d) - **docs:** update namespace table of contents [(#11520)](https://github.com/stdlib-js/stdlib/pull/11520) _(by stdlib-bot)_
848850
- [`3af178c`](https://github.com/stdlib-js/stdlib/commit/3af178cc07862b3070234245f015a4bdc8370acb) - **style:** use single quotes for require calls [(#11516)](https://github.com/stdlib-js/stdlib/pull/11516) _(by Philipp Burckhardt)_
849851
- [`5426e50`](https://github.com/stdlib-js/stdlib/commit/5426e503c7239b8672e8f2c9621ec0dfc9dcf391) - **docs:** improve doctests for ndarray instances in `ndarray/to-reversed` [(#11506)](https://github.com/stdlib-js/stdlib/pull/11506) _(by Uday Kakade, Athan Reines)_

base/tile/README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
# tile
22+
23+
> Return an [ndarray][@stdlib/ndarray/base/ctor] created by repeating the elements of an input [ndarray][@stdlib/ndarray/base/ctor] a specified number of times along each dimension.
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 tile = require( '@stdlib/ndarray/base/tile' );
41+
```
42+
43+
#### tile( x, reps )
44+
45+
Returns an [ndarray][@stdlib/ndarray/base/ctor] created by repeating the elements of an input [ndarray][@stdlib/ndarray/base/ctor] a specified number of times along each dimension.
46+
47+
```javascript
48+
var array = require( '@stdlib/ndarray/array' );
49+
50+
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
51+
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
52+
53+
var y = tile( x, [ 2, 2 ] );
54+
// returns <ndarray>[ [ 1, 2, 1, 2 ], [ 3, 4, 3, 4 ], [ 1, 2, 1, 2 ], [ 3, 4, 3, 4 ] ]
55+
```
56+
57+
The function accepts the following arguments:
58+
59+
- **x**: input [ndarray][@stdlib/ndarray/base/ctor].
60+
- **reps**: list specifying the number of times to repeat elements of an input [ndarray][@stdlib/ndarray/base/ctor] along each dimension.
61+
62+
</section>
63+
64+
<!-- /.usage -->
65+
66+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
67+
68+
<section class="notes">
69+
70+
## Notes
71+
72+
- The number of repetitions must have at least as many elements as the number of input dimensions. When the number of repetitions exceeds the number of input dimensions, the input [ndarray][@stdlib/ndarray/base/ctor] is treated as if singleton dimensions were prepended.
73+
- The function always copies data to a new [ndarray][@stdlib/ndarray/base/ctor].
74+
75+
</section>
76+
77+
<!-- /.notes -->
78+
79+
<!-- Package usage examples. -->
80+
81+
<section class="examples">
82+
83+
## Examples
84+
85+
<!-- eslint no-undef: "error" -->
86+
87+
```javascript
88+
var array = require( '@stdlib/ndarray/array' );
89+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
90+
var tile = require( '@stdlib/ndarray/base/tile' );
91+
92+
// Create a 2x2 array:
93+
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
94+
console.log( ndarray2array( x ) );
95+
96+
// Tile the array to 4x4:
97+
var out = tile( x, [ 2, 2 ] );
98+
console.log( ndarray2array( out ) );
99+
```
100+
101+
</section>
102+
103+
<!-- /.examples -->
104+
105+
<!-- 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. -->
106+
107+
<section class="references">
108+
109+
</section>
110+
111+
<!-- /.references -->
112+
113+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
114+
115+
<section class="related">
116+
117+
</section>
118+
119+
<!-- /.related -->
120+
121+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
122+
123+
<section class="links">
124+
125+
[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray/tree/main/base/ctor
126+
127+
</section>
128+
129+
<!-- /.links -->

base/tile/benchmark/benchmark.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 Float64Array = require( '@stdlib/array/float64' );
25+
var ndarrayBase = require( './../../../base/ctor' );
26+
var ndarray = require( './../../../ctor' );
27+
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
28+
var format = require( '@stdlib/string/format' );
29+
var pkg = require( './../package.json' ).name;
30+
var tile = require( './../lib' );
31+
32+
33+
// MAIN //
34+
35+
bench( format( '%s::ctor=base,ndims=2,order=row-major', pkg ), function benchmark( b ) {
36+
var strides;
37+
var values;
38+
var buffer;
39+
var offset;
40+
var dtype;
41+
var shape;
42+
var order;
43+
var out;
44+
var i;
45+
46+
dtype = 'float64';
47+
buffer = new Float64Array( 4 );
48+
shape = [ 2, 2 ];
49+
strides = [ 2, 1 ];
50+
offset = 0;
51+
order = 'row-major';
52+
53+
values = [
54+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
55+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
56+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
57+
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
58+
ndarrayBase( dtype, buffer, shape, strides, offset, order )
59+
];
60+
61+
b.tic();
62+
for ( i = 0; i < b.iterations; i++ ) {
63+
out = tile( values[ i%values.length ], [ 2, 2 ] );
64+
if ( typeof out !== 'object' ) {
65+
b.fail( 'should return an object' );
66+
}
67+
}
68+
b.toc();
69+
if ( !isndarrayLike( out ) ) {
70+
b.fail( 'should return an ndarray' );
71+
}
72+
b.pass( 'benchmark finished' );
73+
b.end();
74+
});
75+
76+
bench( format( '%s::ctor=non-base,ndims=2,order=row-major', pkg ), function benchmark( b ) {
77+
var strides;
78+
var values;
79+
var buffer;
80+
var offset;
81+
var dtype;
82+
var shape;
83+
var order;
84+
var out;
85+
var i;
86+
87+
dtype = 'float64';
88+
buffer = new Float64Array( 4 );
89+
shape = [ 2, 2 ];
90+
strides = [ 2, 1 ];
91+
offset = 0;
92+
order = 'row-major';
93+
94+
values = [
95+
ndarray( dtype, buffer, shape, strides, offset, order ),
96+
ndarray( dtype, buffer, shape, strides, offset, order ),
97+
ndarray( dtype, buffer, shape, strides, offset, order ),
98+
ndarray( dtype, buffer, shape, strides, offset, order ),
99+
ndarray( dtype, buffer, shape, strides, offset, order )
100+
];
101+
102+
b.tic();
103+
for ( i = 0; i < b.iterations; i++ ) {
104+
out = tile( values[ i%values.length ], [ 2, 2 ] );
105+
if ( typeof out !== 'object' ) {
106+
b.fail( 'should return an object' );
107+
}
108+
}
109+
b.toc();
110+
if ( !isndarrayLike( out ) ) {
111+
b.fail( 'should return an ndarray' );
112+
}
113+
b.pass( 'benchmark finished' );
114+
b.end();
115+
});
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 array = require( './../../../array' );
25+
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
26+
var format = require( '@stdlib/string/format' );
27+
var pkg = require( './../package.json' ).name;
28+
var tile = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} ndims - number of output dimensions
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( ndims ) {
41+
var reps;
42+
var x;
43+
var i;
44+
45+
x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
46+
47+
reps = [];
48+
for ( i = 0; i < ndims; i++ ) {
49+
reps.push( 1 );
50+
}
51+
reps[ ndims-1 ] = 2;
52+
if ( ndims >= 2 ) {
53+
reps[ ndims-2 ] = 2;
54+
}
55+
return benchmark;
56+
57+
/**
58+
* Benchmark function.
59+
*
60+
* @private
61+
* @param {Benchmark} b - benchmark instance
62+
*/
63+
function benchmark( b ) {
64+
var out;
65+
var i;
66+
67+
b.tic();
68+
for ( i = 0; i < b.iterations; i++ ) {
69+
out = tile( x, reps );
70+
if ( typeof out !== 'object' ) {
71+
b.fail( 'should return an object' );
72+
}
73+
}
74+
b.toc();
75+
if ( !isndarrayLike( out ) ) {
76+
b.fail( 'should return an ndarray' );
77+
}
78+
b.pass( 'benchmark finished' );
79+
b.end();
80+
}
81+
}
82+
83+
84+
// MAIN //
85+
86+
/**
87+
* Main execution sequence.
88+
*
89+
* @private
90+
*/
91+
function main() {
92+
var min;
93+
var max;
94+
var f;
95+
var i;
96+
97+
min = 2;
98+
max = 10;
99+
100+
for ( i = min; i <= max; i++ ) {
101+
f = createBenchmark( i );
102+
bench( format( '%s::ctor=non-base,ndims=%d,order=row-major', pkg, i ), f );
103+
}
104+
}
105+
106+
main();

0 commit comments

Comments
 (0)