Skip to content
Open
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
139 changes: 139 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/zero-to/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<!--

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

-->

# zeroTo

> Fill an [ndarray][@stdlib/ndarray/ctor] with linearly spaced numeric elements which increment by `1` starting from zero.

<section class="usage">

## Usage

```javascript
var zeroTo = require( '@stdlib/blas/ext/zero-to' );
```

#### zeroTo( x\[, options] )

Fills an [ndarray][@stdlib/ndarray/ctor] with linearly spaced numeric elements which increment by `1` starting from zero.

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

var x = array( [ 0.0, 0.0, 0.0 ] );
// returns <ndarray>[ 0.0, 0.0, 0.0 ]

var y = zeroTo( x );
// returns <ndarray>[ 0.0, 1.0, 2.0 ]

var bool = ( x === y );
// returns true
```

The function has the following parameters:

- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a numeric or "generic" [data type][@stdlib/ndarray/dtypes].
- **options**: function options (_optional_).

The function accepts the following options:

- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor].

By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option.

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

var x = array( [ 0.0, 0.0, 0.0, 0.0 ], {
'shape': [ 2, 2 ],
'order': 'row-major'
});
// returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]

var y = zeroTo( x, {
'dims': [ 1 ]
});
// returns <ndarray>[ [ 0.0, 1.0 ], [ 0.0, 1.0 ] ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- The input [ndarray][@stdlib/ndarray/ctor] is filled **in-place** (i.e., the input [ndarray][@stdlib/ndarray/ctor] is **mutated**).
- The function iterates over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before performing the operation.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var zeros = require( '@stdlib/ndarray/zeros' );
var zeroTo = require( '@stdlib/blas/ext/zero-to' );

// Create a zeros-filled ndarray:
var x = zeros( [ 5, 5 ], {
'dtype': 'generic'
});
console.log( ndarray2array( x ) );

// Perform operation:
zeroTo( x, {
'dims': [ 1 ]
});

// Print the results:
console.log( ndarray2array( x ) );
```

</section>

<!-- /.examples -->

<!-- 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/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor

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

</section>

<!-- /.links -->
106 changes: 106 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/zero-to/benchmark/benchmark.js
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var zeros = require( '@stdlib/array/zeros' );
var ndarray = require( '@stdlib/ndarray/base/ctor' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var zeroTo = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x = zeros( len, options.dtype );
x = new ndarray( options.dtype, x, [ len ], [ 1 ], 0, 'row-major' );

return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
o = zeroTo( x );
if ( typeof o !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( isnan( o.get( i%len ) ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

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

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f );
}
}

main();
33 changes: 33 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/zero-to/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

{{alias}}( x[, options] )
Fills an ndarray with linearly spaced numeric elements which increment by
1 starting from zero.

The function fills an ndarray in-place and thus mutates the input ndarray.

Parameters
----------
x: ndarray
Input array. Must have a numeric or "generic" data type.

options: Object (optional)
Function options.

options.dims: Array<integer> (optional)
List of dimensions over which to perform operation. If not provided,
the function performs the operation over all elements in a provided
input ndarray.

Returns
-------
out: ndarray
Input array.

Examples
--------
> var x = {{alias:@stdlib/ndarray/array}}( [ 0.0, 0.0, 0.0 ] );
> var y = {{alias}}( x )
<ndarray>[ 0.0, 1.0, 2.0 ]

See Also
--------
88 changes: 88 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/zero-to/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* @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.
*/

// TypeScript Version: 4.1

/// <reference types="@stdlib/types"/>

import { ArrayLike } from '@stdlib/types/array';
import { typedndarray, genericndarray } from '@stdlib/types/ndarray';

/**
* Input array.
*/
type InputArray = typedndarray<number> | genericndarray<number>;

/**
* Interface defining options.
*/
interface Options {
/**
* List of dimensions over which to perform operation.
*/
dims?: ArrayLike<number>;
}

/**
* Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero.
*
* ## Notes
*
* - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**).
*
* @param x - input ndarray
* @param options - function options
* @returns output ndarray
*
* @example
* var array = require( '@stdlib/ndarray/array' );
*
* var x = array( [ 0.0, 0.0, 0.0 ] );
* // returns <ndarray>[ 0.0, 0.0, 0.0 ]
*
* var y = zeroTo( x );
* // returns <ndarray>[ 0.0, 1.0, 2.0 ]
*/
type ZeroTo = <T extends InputArray = InputArray>( x: T, options?: Options ) => T;

/**
* Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero.
*
* ## Notes
*
* - The input ndarray is filled **in-place** (i.e., the input ndarray is **mutated**).
*
* @param x - input ndarray
* @param options - function options
* @returns output ndarray
*
* @example
* var array = require( '@stdlib/ndarray/array' );
*
* var x = array( [ 0.0, 0.0, 0.0 ] );
* // returns <ndarray>[ 0.0, 0.0, 0.0 ]
*
* var y = zeroTo( x );
* // returns <ndarray>[ 0.0, 1.0, 2.0 ]
*/
declare const zeroTo: ZeroTo;


// EXPORTS //

export = zeroTo;
Loading