Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/tile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# tile

> 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.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var tile = require( '@stdlib/ndarray/base/tile' );
```

#### tile( x, reps )

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.

```javascript
var array = require( '@stdlib/ndarray/array' );

var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]

var y = tile( x, [ 2, 2 ] );
// returns <ndarray>[ [ 1, 2, 1, 2 ], [ 3, 4, 3, 4 ], [ 1, 2, 1, 2 ], [ 3, 4, 3, 4 ] ]
```

The function accepts the following arguments:

- **x**: input [ndarray][@stdlib/ndarray/base/ctor].
- **reps**: list specifying the number of times to repeat elements of an input [ndarray][@stdlib/ndarray/base/ctor] along each dimension.

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- 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.
- The function always copies data to a new [ndarray][@stdlib/ndarray/base/ctor].

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var array = require( '@stdlib/ndarray/array' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var tile = require( '@stdlib/ndarray/base/tile' );

// Create a 2x2 array:
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
console.log( ndarray2array( x ) );

// Tile the array to 4x4:
var out = tile( x, [ 2, 2 ] );
console.log( ndarray2array( out ) );
```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/ctor

</section>

<!-- /.links -->
115 changes: 115 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/tile/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var ndarrayBase = require( '@stdlib/ndarray/base/ctor' );
var ndarray = require( '@stdlib/ndarray/ctor' );
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var tile = require( './../lib' );


// MAIN //

bench( format( '%s::ctor=base,ndims=2,order=row-major', pkg ), function benchmark( b ) {
var strides;
var values;
var buffer;
var offset;
var dtype;
var shape;
var order;
var out;
var i;

dtype = 'float64';
buffer = new Float64Array( 4 );
shape = [ 2, 2 ];
strides = [ 2, 1 ];
offset = 0;
order = 'row-major';

values = [
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
ndarrayBase( dtype, buffer, shape, strides, offset, order ),
ndarrayBase( dtype, buffer, shape, strides, offset, order )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = tile( values[ i%values.length ], [ 2, 2 ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isndarrayLike( out ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::ctor=non-base,ndims=2,order=row-major', pkg ), function benchmark( b ) {
var strides;
var values;
var buffer;
var offset;
var dtype;
var shape;
var order;
var out;
var i;

dtype = 'float64';
buffer = new Float64Array( 4 );
shape = [ 2, 2 ];
strides = [ 2, 1 ];
offset = 0;
order = 'row-major';

values = [
ndarray( dtype, buffer, shape, strides, offset, order ),
ndarray( dtype, buffer, shape, strides, offset, order ),
ndarray( dtype, buffer, shape, strides, offset, order ),
ndarray( dtype, buffer, shape, strides, offset, order ),
ndarray( dtype, buffer, shape, strides, offset, order )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = tile( values[ i%values.length ], [ 2, 2 ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isndarrayLike( out ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var array = require( '@stdlib/ndarray/array' );
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var tile = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} ndims - number of output dimensions
* @returns {Function} benchmark function
*/
function createBenchmark( ndims ) {
var reps;
var x;
var i;

x = array( [ [ 1, 2 ], [ 3, 4 ] ] );

reps = [];
for ( i = 0; i < ndims; i++ ) {
reps.push( 1 );
}
reps[ ndims-1 ] = 2;
if ( ndims >= 2 ) {
reps[ ndims-2 ] = 2;
}
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = tile( x, reps );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isndarrayLike( out ) ) {
b.fail( 'should return an ndarray' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var min;
var max;
var f;
var i;

min = 2;
max = 10;

for ( i = min; i <= max; i++ ) {
f = createBenchmark( i );
bench( format( '%s::ctor=non-base,ndims=%d,order=row-major', pkg, i ), f );
}
}

main();
35 changes: 35 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/tile/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

{{alias}}( x, reps )
Returns an ndarray created by repeating the elements of an input ndarray
a specified number of times along each dimension.

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 array is treated as if singleton dimensions
were prepended.

The function always copies data to a new ndarray.

Parameters
----------
x: ndarray
Input array.

reps: ArrayLikeObject
Number of repetitions along each dimension.

Returns
-------
out: ndarray
Output array.

Examples
--------
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] )
<ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
> var o = {{alias}}( x, [ 2, 2 ] )
<ndarray>[ [ 1, 2, 1, 2 ], [ 3, 4, 3, 4 ], [ 1, 2, 1, 2 ], [ 3, 4, 3, 4 ] ]

See Also
--------

Loading