diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md new file mode 100644 index 000000000000..d3c2045c472a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/README.md @@ -0,0 +1,140 @@ + + +# gfill + +> Fill a one-dimensional ndarray with a specified scalar constant. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); +``` + +#### gfill( arrays ) + +Fills a one-dimensional ndarray with a specified scalar constant. + +```javascript +var vector = require( '@stdlib/ndarray/vector/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var x = vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ], 'generic' ); + +var alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' +}); + +var start = scalar2ndarray( 0, { + 'dtype': 'generic' +}); + +var end = scalar2ndarray( 3, { + 'dtype': 'generic' +}); + +gfill( [ x, alpha, start, end ] ); +// x => [ 5.0, 5.0, 5.0, -5.0, 4.0, -1.0 ] +``` + +The function has the following parameters: + +- **arrays**: array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the scalar constant. + - a zero-dimensional ndarray containing the starting index (inclusive). + - a zero-dimensional ndarray containing the ending index (exclusive). + +
+ + + +
+ +## Notes + +- The input ndarray is modified **in-place** (i.e., the input ndarray is **mutated**). +- If a specified `start` or `end` index is negative, the function resolves the respective index by counting backward from the last element (where `-1` refers to the last element). + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); + +var opts = { + 'dtype': 'generic' +}; + +var x = discreteUniform( [ 20 ], -100, 100, opts ); +console.log( ndarray2array( x ) ); + +var alpha = scalar2ndarray( 5, opts ); +console.log( 'Alpha: %d', ndarraylike2scalar( alpha ) ); + +var start = scalar2ndarray( 5, opts ); +console.log( 'Start Index: %d', ndarraylike2scalar( start ) ); + +var end = scalar2ndarray( 15, opts ); +console.log( 'End Index: %d', ndarraylike2scalar( end ) ); + +gfill( [ x, alpha, start, end ] ); +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js new file mode 100644 index 000000000000..3769609741b3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/benchmark/benchmark.js @@ -0,0 +1,114 @@ +/** +* @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/uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gfill = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var alpha; + var start; + var end; + var x; + + x = uniform( [ len ], -100.0, 100.0, options ); + alpha = [ + scalar2ndarray( 5.0, options ), + scalar2ndarray( 0.0, options ) + ]; + start = scalar2ndarray( 0, options ); + end = scalar2ndarray( len, options ); + 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 = gfill( [ x, alpha[ i%2 ], start, end ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + 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/ndarray/gfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt new file mode 100644 index 000000000000..df63ae3d87f3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/repl.txt @@ -0,0 +1,40 @@ + +{{alias}}( arrays ) + Fills a one-dimensional ndarray with a specified scalar constant. + + The input ndarray is modified *in-place* (i.e., the input ndarray is + *mutated*). + + If a specified `start` or `end` index is negative, the function resolves + the respective index by counting backward from the last element (where `-1` + refers to the last element). + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing the following ndarrays: + + - a one-dimensional input ndarray. + - a zero-dimensional ndarray containing the scalar constant. + - a zero-dimensional ndarray containing the starting index (inclusive). + - a zero-dimensional ndarray containing the ending index (exclusive). + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var buf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + > var x = {{alias:@stdlib/ndarray/vector/ctor}}( buf, 'generic' ); + > var opts = { 'dtype': 'generic' }; + > var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 5.0, opts ); + > var st = {{alias:@stdlib/ndarray/from-scalar}}( 0, opts ); + > var en = {{alias:@stdlib/ndarray/from-scalar}}( 3, opts ); + > {{alias}}( [ x, alpha, st, en ] ) + [ 5.0, 5.0, 5.0, -5.0, 4.0, -1.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts new file mode 100644 index 000000000000..ef6b220a67d2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/index.d.ts @@ -0,0 +1,66 @@ +/* +* @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 { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Fills a one-dimensional ndarray with a specified scalar constant. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the scalar constant. +* - a zero-dimensional ndarray containing the starting index (inclusive). +* - a zero-dimensional ndarray containing the ending index (exclusive). +* +* @param arrays - array-like object containing ndarrays +* @returns input ndarray +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ], 'generic' ); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var start = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var end = scalar2ndarray( 3, { +* 'dtype': 'generic' +* }); +* +* var out = gfill( [ x, alpha, start, end ] ); +* // returns [ 5.0, 5.0, 5.0, -5.0, 4.0, -1.0 ] +*/ +declare function gfill = typedndarray>( arrays: [ T, typedndarray, typedndarray, typedndarray ] ): T; + + +// EXPORTS // + +export = gfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts new file mode 100644 index 000000000000..faef810cb897 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/docs/types/test.ts @@ -0,0 +1,76 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import gfill = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + const start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + const end = scalar2ndarray( 10, { + 'dtype': 'generic' + }); + + gfill( [ x, alpha, start, end ] ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gfill( '10' ); // $ExpectError + gfill( 5 ); // $ExpectError + gfill( true ); // $ExpectError + gfill( false ); // $ExpectError + gfill( null ); // $ExpectError + gfill( undefined ); // $ExpectError + gfill( [] ); // $ExpectError + gfill( {} ); // $ExpectError + gfill( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + const start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + const end = scalar2ndarray( 10, { + 'dtype': 'generic' + }); + + gfill(); // $ExpectError + gfill( [ x, alpha, start, end ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js new file mode 100644 index 000000000000..eabbef7e922c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/examples/index.js @@ -0,0 +1,44 @@ +/** +* @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/discrete-uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' ); +var gfill = require( './../lib' ); + +var opts = { + 'dtype': 'generic' +}; + +var x = discreteUniform( [ 20 ], -100, 100, opts ); +console.log( ndarray2array( x ) ); + +var alpha = scalar2ndarray( 5, opts ); +console.log( 'Alpha: %d', ndarraylike2scalar( alpha ) ); + +var start = scalar2ndarray( 5, opts ); +console.log( 'Start Index: %d', ndarraylike2scalar( start ) ); + +var end = scalar2ndarray( 15, opts ); +console.log( 'End Index: %d', ndarraylike2scalar( end ) ); + +gfill( [ x, alpha, start, end ] ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js new file mode 100644 index 000000000000..0929cab95e0d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/index.js @@ -0,0 +1,56 @@ +/** +* @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 one-dimensional ndarray with a specified scalar constant. +* +* @module @stdlib/blas/ext/base/ndarray/gfill +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var gfill = require( '@stdlib/blas/ext/base/ndarray/gfill' ); +* +* var x = vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ], 'generic' ); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var start = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var end = scalar2ndarray( 3, { +* 'dtype': 'generic' +* }); +* +* var out = gfill( [ x, alpha, start, end ] ); +* // returns [ 5.0, 5.0, 5.0, -5.0, 4.0, -1.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js new file mode 100644 index 000000000000..583a72021f09 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/lib/main.js @@ -0,0 +1,98 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var clipIndex = require( '@stdlib/ndarray/base/clip-index' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var strided = require( '@stdlib/blas/ext/base/gfill' ).ndarray; + + +// MAIN // + +/** +* Fills a one-dimensional ndarray with a specified scalar constant. +* +* ## Notes +* +* - The function expects the following ndarrays: +* +* - a one-dimensional input ndarray. +* - a zero-dimensional ndarray containing the scalar constant. +* - a zero-dimensional ndarray containing the starting index (inclusive). +* - a zero-dimensional ndarray containing the ending index (exclusive). +* +* @param {ArrayLikeObject} arrays - array-like object containing ndarrays +* @returns {ndarray} input ndarray +* +* @example +* var vector = require( '@stdlib/ndarray/vector/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = vector( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ], 'generic' ); +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'generic' +* }); +* +* var start = scalar2ndarray( 0, { +* 'dtype': 'generic' +* }); +* +* var end = scalar2ndarray( 3, { +* 'dtype': 'generic' +* }); +* +* var out = gfill( [ x, alpha, start, end ] ); +* // returns [ 5.0, 5.0, 5.0, -5.0, 4.0, -1.0 ] +*/ +function gfill( arrays ) { + var stride; + var offset; + var alpha; + var start; + var end; + var N; + var x; + + x = arrays[ 0 ]; + alpha = ndarraylike2scalar( arrays[ 1 ] ); + + N = numelDimension( x, 0 ); + start = clipIndex( ndarraylike2scalar( arrays[ 2 ] ), N ); + end = clipIndex( ndarraylike2scalar( arrays[ 3 ] ), N ); + if ( start >= end ) { + return x; + } + stride = getStride( x, 0 ); + offset = getOffset( x ) + ( stride*start ); + + strided( end-start, alpha, getData( x ), stride, offset ); + return x; +} + + +// EXPORTS // + +module.exports = gfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/package.json new file mode 100644 index 000000000000..0c342ee8e6f8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gfill", + "version": "0.0.0", + "description": "Fill a one-dimensional ndarray with a specified scalar constant.", + "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", + "ext", + "fill", + "assign", + "set", + "copy", + "broadcast", + "constant", + "strided", + "array", + "ndarray", + "generic" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js new file mode 100644 index 000000000000..56747f1b3d66 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gfill/test/test.js @@ -0,0 +1,441 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gfill = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfill, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function fills a one-dimensional ndarray with a specified scalar constant', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + x = vector( xbuf, 6, 1, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 6, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-unit stride', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + x = vector( xbuf, 3, 2, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 1.0, 5.0, -5.0, 5.0, -1.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a negative stride', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + x = vector( xbuf, 3, -2, 4 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 1.0, 5.0, -5.0, 5.0, -1.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an input ndarray having a non-zero offset', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + x = vector( xbuf, 3, 1, 3 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ -2.0, 1.0, 3.0, 5.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a nonnegative starting index', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + x = vector( xbuf, 6, 1, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 6, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ -2.0, 1.0, 5.0, 5.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative starting index', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + x = vector( xbuf, 6, 1, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( -4, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 6, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ -2.0, 1.0, 5.0, 5.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a nonnegative ending index', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + x = vector( xbuf, 6, 1, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 5.0, 5.0, -5.0, 4.0, -1.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative ending index', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + x = vector( xbuf, 6, 1, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( -3, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 5.0, 5.0, -5.0, 4.0, -1.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function clamps out-of-bounds starting and ending indices', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0 ]; + x = vector( xbuf, 6, 1, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( -10, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 10, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if a resolved starting index is greater than or equal to a resolved ending index, the function returns the input ndarray unchanged', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0 ]; + x = vector( xbuf, 4, 1, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + expected = [ -2.0, 1.0, 3.0, -5.0 ]; + + start = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + start = scalar2ndarray( 3, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + start = scalar2ndarray( 5, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 4, { + 'dtype': 'generic' + }); + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( -10, { + 'dtype': 'generic' + }); + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying a fill range for an input ndarray having a non-unit stride', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = [ -2.0, 1.0, 3.0, -5.0 ]; + x = vector( xbuf, 2, 2, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 1, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 2, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = [ -2.0, 1.0, 5.0, -5.0 ]; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray unchanged when the input ndarray is empty', function test( t ) { + var expected; + var actual; + var alpha; + var start; + var xbuf; + var end; + var x; + + xbuf = []; + x = vector( xbuf, 0, 1, 0 ); + alpha = scalar2ndarray( 5.0, { + 'dtype': 'generic' + }); + start = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + end = scalar2ndarray( 0, { + 'dtype': 'generic' + }); + + actual = gfill( [ x, alpha, start, end ] ); + t.strictEqual( actual, x, 'returns expected value' ); + + expected = []; + t.deepEqual( xbuf, expected, 'returns expected value' ); + + t.end(); +});