diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/README.md b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/README.md new file mode 100644 index 000000000000..3581d502167f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/README.md @@ -0,0 +1,160 @@ + + +# gzeroTo + +> Fill a strided array with linearly spaced numeric elements which increment by `1` starting from zero. + +
+ +## Usage + +```javascript +var gzeroTo = require( '@stdlib/blas/ext/base/gzero-to' ); +``` + +#### gzeroTo( N, x, strideX ) + +Fills a strided array with linearly spaced numeric elements which increment by `1` starting from zero. + +```javascript +var x = [ 0.0, 0.0, 0.0, 0.0 ]; + +gzeroTo( x.length, x, 1 ); +// x => [ 0.0, 1.0, 2.0, 3.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input array. +- **strideX**: stride length. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to fill every other element: + +```javascript +var x = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gzeroTo( 3, x, 2 ); +// x => [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array... +var x0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// Create an offset view... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Fill every other element... +gzeroTo( 3, x1, 2 ); +// x0 => [ 0.0, 0.0, 0.0, 1.0, 0.0, 2.0 ] +``` + +#### gzeroTo.ndarray( N, x, strideX, offsetX ) + +Fills a strided array with linearly spaced numeric elements which increment by `1` starting from zero using alternative indexing semantics. + +```javascript +var x = [ 0.0, 0.0, 0.0, 0.0 ]; + +gzeroTo.ndarray( x.length, x, 1, 0 ); +// x => [ 0.0, 1.0, 2.0, 3.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: + +```javascript +var x = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + +gzeroTo.ndarray( 3, x, 1, x.length-3 ); +// x => [ 0.0, 0.0, 0.0, 0.0, 1.0, 2.0 ] +``` + +
+ + + +
+ +## Notes + +- If `N <= 0`, both functions return `x` unchanged. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/complex64`][@stdlib/array/complex64]). +- Depending on the environment, the typed versions ([`dzeroTo`][@stdlib/blas/ext/base/dzero-to], [`szeroTo`][@stdlib/blas/ext/base/szero-to], etc.) are likely to be significantly more performant. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gzeroTo = require( '@stdlib/blas/ext/base/gzero-to' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +gzeroTo( x.length, x, 1 ); +console.log( x ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/benchmark/benchmark.js new file mode 100644 index 000000000000..ecfbee933f74 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gzeroTo = require( './../lib/main.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100, 100, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gzeroTo( x.length, x, 1 ); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%x.length ] ) ) { + 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:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..6c0ea9249289 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/benchmark/benchmark.ndarray.js @@ -0,0 +1,103 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gzeroTo = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Create a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100, 100, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = gzeroTo( x.length, x, 1, 0 ); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%x.length ] ) ) { + 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:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/docs/repl.txt new file mode 100644 index 000000000000..a995d1a8cf21 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/docs/repl.txt @@ -0,0 +1,91 @@ + +{{alias}}( N, x, strideX ) + Fills a strided array with linearly spaced numeric elements which increment + by `1` starting from zero. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0`, the function returns `x` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length. + + Returns + ------- + x: ArrayLikeObject + Input array. + + Examples + -------- + // Standard Usage: + > var x = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( x.length, x, 1 ) + [ 0.0, 1.0, 2.0, 3.0 ] + + // Using `N` and stride parameters: + > x = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}( 3, x, 2 ) + [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, x1, 2 ) + [ 0.0, 0.0, 1.0, 0.0, 2.0 ] + > x0 + [ 0.0, 0.0, 0.0, 1.0, 0.0, 2.0 ] + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Fills a strided array with linearly spaced numeric elements which increment + by `1` starting from zero using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: ArrayLikeObject + Input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + x: ArrayLikeObject + Input array. + + Examples + -------- + // Standard Usage: + > var x = [ 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( x.length, x, 1, 0 ) + [ 0.0, 1.0, 2.0, 3.0 ] + + // Using an index offset: + > x = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + > {{alias}}.ndarray( 3, x, 2, 1 ) + [ 0.0, 0.0, 0.0, 1.0, 0.0, 2.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/docs/types/index.d.ts new file mode 100644 index 000000000000..87074c547e84 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/docs/types/index.d.ts @@ -0,0 +1,93 @@ +/* +* @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 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gzeroTo`. +*/ +interface Routine { + /** + * Fills a strided array with linearly spaced numeric elements which increment by `1` starting from zero. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @returns input array + * + * @example + * var x = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * gzeroTo( x.length, x, 1 ); + * // x => [ 0.0, 1.0, 2.0, 3.0 ] + */ + = InputArray>( N: number, x: U, strideX: number ): U; + + /** + * Fills a strided array with linearly spaced numeric elements which increment by `1` starting from zero using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns input array + * + * @example + * var x = [ 0.0, 0.0, 0.0, 0.0 ]; + * + * gzeroTo.ndarray( x.length, x, 1, 0 ); + * // x => [ 0.0, 1.0, 2.0, 3.0 ] + */ + ndarray = InputArray>( N: number, x: U, strideX: number, offsetX: number ): U; +} + +/** +* Fills a strided array with linearly spaced numeric elements which increment by `1` starting from zero. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - stride length +* @returns input array +* +* @example +* var x = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gzeroTo( x.length, x, 1 ); +* // x => [ 0.0, 1.0, 2.0, 3.0 ] +* +* @example +* var x = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gzeroTo.ndarray( x.length, x, 1, 0 ); +* // x => [ 0.0, 1.0, 2.0, 3.0 ] +*/ +declare var gzeroTo: Routine; + + +// EXPORTS // + +export = gzeroTo; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/docs/types/test.ts new file mode 100644 index 000000000000..9babe741d287 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/docs/types/test.ts @@ -0,0 +1,151 @@ +/* +* @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. +*/ + +import gzeroTo = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const x = new Float64Array( 10 ); + + gzeroTo( x.length, x, 1 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gzeroTo( '10', x, 1 ); // $ExpectError + gzeroTo( true, x, 1 ); // $ExpectError + gzeroTo( false, x, 1 ); // $ExpectError + gzeroTo( null, x, 1 ); // $ExpectError + gzeroTo( undefined, x, 1 ); // $ExpectError + gzeroTo( [], x, 1 ); // $ExpectError + gzeroTo( {}, x, 1 ); // $ExpectError + gzeroTo( ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gzeroTo( x.length, 10, 1 ); // $ExpectError + gzeroTo( x.length, true, 1 ); // $ExpectError + gzeroTo( x.length, false, 1 ); // $ExpectError + gzeroTo( x.length, null, 1 ); // $ExpectError + gzeroTo( x.length, undefined, 1 ); // $ExpectError + gzeroTo( x.length, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gzeroTo( x.length, x, '10' ); // $ExpectError + gzeroTo( x.length, x, true ); // $ExpectError + gzeroTo( x.length, x, false ); // $ExpectError + gzeroTo( x.length, x, null ); // $ExpectError + gzeroTo( x.length, x, undefined ); // $ExpectError + gzeroTo( x.length, x, [] ); // $ExpectError + gzeroTo( x.length, x, {} ); // $ExpectError + gzeroTo( x.length, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + gzeroTo(); // $ExpectError + gzeroTo( x.length ); // $ExpectError + gzeroTo( x.length, x ); // $ExpectError + gzeroTo( x.length, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a collection... +{ + const x = new Float64Array( 10 ); + + gzeroTo.ndarray( x.length, x, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gzeroTo.ndarray( '10', x, 1, 0 ); // $ExpectError + gzeroTo.ndarray( true, x, 1, 0 ); // $ExpectError + gzeroTo.ndarray( false, x, 1, 0 ); // $ExpectError + gzeroTo.ndarray( null, x, 1, 0 ); // $ExpectError + gzeroTo.ndarray( undefined, x, 1, 0 ); // $ExpectError + gzeroTo.ndarray( [], x, 1, 0 ); // $ExpectError + gzeroTo.ndarray( {}, x, 1, 0 ); // $ExpectError + gzeroTo.ndarray( ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a collection... +{ + const x = new Float64Array( 10 ); + + gzeroTo.ndarray( x.length, 10, 1, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, true, 1, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, false, 1, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, null, 1, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, undefined, 1, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gzeroTo.ndarray( x.length, x, '10', 0 ); // $ExpectError + gzeroTo.ndarray( x.length, x, true, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, x, false, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, x, null, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, x, undefined, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, x, [], 0 ); // $ExpectError + gzeroTo.ndarray( x.length, x, {}, 0 ); // $ExpectError + gzeroTo.ndarray( x.length, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + gzeroTo.ndarray( x.length, x, 1, '10' ); // $ExpectError + gzeroTo.ndarray( x.length, x, 1, true ); // $ExpectError + gzeroTo.ndarray( x.length, x, 1, false ); // $ExpectError + gzeroTo.ndarray( x.length, x, 1, null ); // $ExpectError + gzeroTo.ndarray( x.length, x, 1, undefined ); // $ExpectError + gzeroTo.ndarray( x.length, x, 1, [] ); // $ExpectError + gzeroTo.ndarray( x.length, x, 1, {} ); // $ExpectError + gzeroTo.ndarray( x.length, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + gzeroTo.ndarray(); // $ExpectError + gzeroTo.ndarray( x.length ); // $ExpectError + gzeroTo.ndarray( x.length, x ); // $ExpectError + gzeroTo.ndarray( x.length, x, 1 ); // $ExpectError + gzeroTo.ndarray( x.length, x, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/examples/index.js new file mode 100644 index 000000000000..9cdcf138790e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/examples/index.js @@ -0,0 +1,30 @@ +/** +* @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'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gzeroTo = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +gzeroTo( x.length, x, 1 ); +console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/accessors.js new file mode 100644 index 000000000000..9faca458346d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/accessors.js @@ -0,0 +1,72 @@ +/** +* @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'; + +// MAIN // + +/** +* Fills a strided array with linearly spaced numeric elements which increment by `1` starting from zero. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {Object} input array object +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0 ] ); +* +* gzeroTo( 4, arraylike2object( x ), 1, 0 ); +* +* var v = x.get( 0 ); +* // returns 0.0 +* +* v = x.get( 1 ); +* // returns 1.0 +*/ +function gzeroTo( N, x, strideX, offsetX ) { + var xbuf; + var set; + var ix; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + set = x.accessors[ 1 ]; + + ix = offsetX; + for ( i = 0; i < N; i++ ) { + set( xbuf, ix, i ); + ix += strideX; + } + return x; +} + + +// EXPORTS // + +module.exports = gzeroTo; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/index.js new file mode 100644 index 000000000000..fe6553849317 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/index.js @@ -0,0 +1,57 @@ +/** +* @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'; + +/** +* Fill a strided array with linearly spaced numeric elements which increment by `1` starting from zero. +* +* @module @stdlib/blas/ext/base/gzero-to +* +* @example +* var gzeroTo = require( '@stdlib/blas/ext/base/gzero-to' ); +* +* var x = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gzeroTo( x.length, x, 1 ); +* // x => [ 0.0, 1.0, 2.0, 3.0 ] +* +* @example +* var gzeroTo = require( '@stdlib/blas/ext/base/gzero-to' ); +* +* var x = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gzeroTo.ndarray( x.length, x, 1, 0 ); +* // x => [ 0.0, 1.0, 2.0, 3.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/main.js new file mode 100644 index 000000000000..12e4dd4b3f1a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/main.js @@ -0,0 +1,50 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Fills a strided array with linearly spaced numeric elements which increment by `1` starting from zero. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @returns {Collection} input array +* +* @example +* var x = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gzeroTo( x.length, x, 1 ); +* // x => [ 0.0, 1.0, 2.0, 3.0 ] +*/ +function gzeroTo( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = gzeroTo; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/ndarray.js new file mode 100644 index 000000000000..cac3bf34cf1b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/lib/ndarray.js @@ -0,0 +1,68 @@ +/** +* @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 arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Fills a strided array with linearly spaced numeric elements which increment by `1` starting from zero. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {Collection} input array +* +* @example +* var x = [ 0.0, 0.0, 0.0, 0.0 ]; +* +* gzeroTo( x.length, x, 1, 0 ); +* // x => [ 0.0, 1.0, 2.0, 3.0 ] +*/ +function gzeroTo( N, x, strideX, offsetX ) { + var ix; + var o; + var i; + + if ( N <= 0 ) { + return x; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + accessors( N, o, strideX, offsetX ); + return x; + } + ix = offsetX; + for ( i = 0; i < N; i++ ) { + x[ ix ] = i; + ix += strideX; + } + return x; +} + + +// EXPORTS // + +module.exports = gzeroTo; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/package.json b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/package.json new file mode 100644 index 000000000000..90e5925439d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/blas/ext/base/gzero-to", + "version": "0.0.0", + "description": "Fill a strided array with linearly spaced numeric elements which increment by `1` starting from zero.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "fill", + "assign", + "set", + "zero-to", + "zeroto", + "sequence", + "seq", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/test/test.js new file mode 100644 index 000000000000..45163f25cefc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/test/test.js @@ -0,0 +1,38 @@ +/** +* @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 tape = require( 'tape' ); +var gzeroTo = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gzeroTo, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gzeroTo.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/test/test.main.js new file mode 100644 index 000000000000..a032e56ab9f7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/test/test.main.js @@ -0,0 +1,253 @@ +/** +* @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 tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gzeroTo = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gzeroTo, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( gzeroTo.length, 3, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = gzeroTo( x.length, x, 1 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'the function returns a reference to the input array (accessors)', function test( t ) { + var out; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + out = gzeroTo( x.length, x, 1 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0 ]; + expected = [ 3.0, -4.0, 1.0 ]; + + gzeroTo( 0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gzeroTo( -4, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills a strided array', function test( t ) { + var expected; + var x; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + expected = [ + 0.0, + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0 + ]; + + gzeroTo( x.length, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills a strided array (accessors)', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = [ 4.0, 2.0, -3.0, 5.0 ]; + x = toAccessorArray( xbuf ); + expected = [ 0.0, 1.0, 2.0, 3.0 ]; + + gzeroTo( x.length, x, 1 ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + expected = [ + 0.0, // 0 + -3.0, + 1.0, // 1 + 7.0, + 2.0 // 2 + ]; + + gzeroTo( 3, x, 2 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (accessors)', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + x = toAccessorArray( xbuf ); + expected = [ + 0.0, // 0 + -3.0, + 1.0, // 1 + 7.0, + 2.0 // 2 + ]; + + gzeroTo( 3, x, 2 ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + expected = [ + 2.0, // 2 + -3.0, + 1.0, // 1 + 7.0, + 0.0 // 0 + ]; + + gzeroTo( 3, x, -2 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (accessors)', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + x = toAccessorArray( xbuf ); + expected = [ + 2.0, // 2 + -3.0, + 1.0, // 1 + 7.0, + 0.0 // 0 + ]; + + gzeroTo( 3, x, -2 ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var expected; + var x0; + var x1; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + expected = new Float64Array([ + 1.0, + 0.0, // 0 + 3.0, + 1.0, // 1 + 5.0, + 2.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + gzeroTo( 3, x1, 2 ); + t.deepEqual( x0, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gzero-to/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/test/test.ndarray.js new file mode 100644 index 000000000000..3f48069b748f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gzero-to/test/test.ndarray.js @@ -0,0 +1,277 @@ +/** +* @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 tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gzeroTo = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gzeroTo, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( gzeroTo.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns a reference to the input array', function test( t ) { + var out; + var x; + + x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + out = gzeroTo( x.length, x, 1, 0 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'the function returns a reference to the input array (accessors)', function test( t ) { + var out; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + out = gzeroTo( x.length, x, 1, 0 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { + var expected; + var x; + + x = [ 3.0, -4.0, 1.0 ]; + expected = [ 3.0, -4.0, 1.0 ]; + + gzeroTo( 0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + gzeroTo( -4, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills a strided array', function test( t ) { + var expected; + var x; + + x = [ + 4.0, + 2.0, + -3.0, + 5.0, + -1.0, + 2.0, + -5.0, + 6.0 + ]; + expected = [ + 0.0, + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + 6.0, + 7.0 + ]; + + gzeroTo( x.length, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills a strided array (accessors)', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = [ 4.0, 2.0, -3.0, 5.0 ]; + x = toAccessorArray( xbuf ); + expected = [ 0.0, 1.0, 2.0, 3.0 ]; + + gzeroTo( x.length, x, 1, 0 ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a stride', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + expected = [ + 0.0, // 0 + -3.0, + 1.0, // 1 + 7.0, + 2.0 // 2 + ]; + + gzeroTo( 3, x, 2, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a stride (accessors)', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = [ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]; + x = toAccessorArray( xbuf ); + expected = [ + 0.0, // 0 + -3.0, + 1.0, // 1 + 7.0, + 2.0 // 2 + ]; + + gzeroTo( 3, x, 2, 0 ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride', function test( t ) { + var expected; + var x; + + x = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + expected = [ + 2.0, // 2 + -3.0, + 1.0, // 1 + 7.0, + 0.0 // 0 + ]; + + gzeroTo( 3, x, -2, x.length-1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports specifying a negative stride (accessors)', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = [ + 2.0, // 2 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 0 + ]; + x = toAccessorArray( xbuf ); + expected = [ + 2.0, // 2 + -3.0, + 1.0, // 1 + 7.0, + 0.0 // 0 + ]; + + gzeroTo( 3, x, -2, x.length-1 ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an offset parameter', function test( t ) { + var expected; + var x; + + x = [ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 6.0, + 7.0 + ]; + expected = [ + 1.0, + 0.0, // 0 + 1.0, // 1 + 2.0, // 2 + 6.0, + 7.0 + ]; + + gzeroTo( 3, x, 1, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an offset parameter (accessors)', function test( t ) { + var expected; + var xbuf; + var x; + + xbuf = [ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 6.0, + 7.0 + ]; + x = toAccessorArray( xbuf ); + expected = [ + 1.0, + 0.0, // 0 + 1.0, // 1 + 2.0, // 2 + 6.0, + 7.0 + ]; + + gzeroTo( 3, x, 1, 1 ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + t.end(); +});