diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/benchmark/benchmark.js new file mode 100644 index 000000000000..bcc14c914b21 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/benchmark/benchmark.js @@ -0,0 +1,123 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gfillRows = require( './../lib' ); + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {PositiveInteger} M - number of elements along each row +* @param {PositiveInteger} N - number of elements along each column +* @returns {Function} benchmark function +*/ +function createBenchmark( order, M, N ) { + var alpha; + var ldx; + var X; + + if ( order === 'column-major' ) { + ldx = M; + } else { + ldx = N; + } + + alpha = zeros( M, 'generic' ); + X = zeros( M*N, 'generic' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = gfillRows( order, M, N, alpha, X, ldx ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var shapes = [ + [ 10, 100000 ], + [ 100, 10000 ], + [ 1000, 1000 ], + [ 10000, 100 ], + [ 100000, 10 ] + ]; + var shape; + var ord; + var f; + var i; + var k; + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = 0; i < shapes.length; i++ ) { + shape = shapes[ i ]; + f = createBenchmark( ord, shape[ 0 ], shape[ 1 ] ); + bench( format( '%s::matrix:ndarray:order=%s:M=%d:N=%d:size=%d', pkg, ord, shape[ 0 ], shape[ 1 ], shape[ 0 ] * shape[ 1 ] ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..d84529815a9b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/benchmark/benchmark.ndarray.js @@ -0,0 +1,127 @@ +/** +* @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 zeros = require( '@stdlib/array/zeros' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gfillRows = require( './../lib' ).ndarray; + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {PositiveInteger} M - number of elements along each row +* @param {PositiveInteger} N - number of elements along each column +* @returns {Function} benchmark function +*/ +function createBenchmark( order, M, N ) { + var alpha; + var sx1; + var sx2; + var X; + + alpha = zeros( M, 'generic' ); + X = zeros( M*N, 'generic' ); + + if ( isColumnMajor( order ) ) { + sx1 = 1; + sx2 = M; + } else { // order === 'row-major' + sx1 = N; + sx2 = 1; + } + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var z; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = gfillRows( M, N, alpha, 1, 0, X, sx1, sx2, 0 ); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( z[ i%z.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var shapes = [ + [ 10, 100000 ], + [ 100, 10000 ], + [ 1000, 1000 ], + [ 10000, 100 ], + [ 100000, 10 ] + ]; + var shape; + var ord; + var f; + var i; + var k; + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = 0; i < shapes.length; i++ ) { + shape = shapes[ i ]; + f = createBenchmark( ord, shape[ 0 ], shape[ 1 ] ); + bench( format( '%s::matrix:ndarray:order=%s:M=%d:N=%d:size=%d', pkg, ord, shape[ 0 ], shape[ 1 ], shape[ 0 ] * shape[ 1 ] ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/docs/types/index.d.ts new file mode 100644 index 000000000000..f873fae20fb6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/docs/types/index.d.ts @@ -0,0 +1,110 @@ +/* +* @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'; +import { Layout } from '@stdlib/types/blas'; + +/** +* Input array. +*/ +type InputArray = AccessorArrayLike | Collection; + +/** +* Output array. +*/ +type OutputArray = AccessorArrayLike | Collection; + +/** +* Interface describing `gfillRows`. +*/ +interface Routine { + /** + * Fills the rows of a matrix from a vector of fill values. + * + * @param order - storage layout + * @param M - number of rows in `X` + * @param N - number of columns in `X` + * @param alpha - vector of fill values + * @param X - input matrix + * @param LDX - stride of the first dimension of `X` + * @returns `X` + * + * @example + * var alpha = [ 10.0, 20.0 ]; + * var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * + * gfillRows( 'row-major', 2, 3, alpha, X, 3 ); + * // X => [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0 ] + */ + ( order: Layout, M: number, N: number, alpha: InputArray, X: InputArray, LDX: number ): OutputArray; + + /** + * Fills the rows of a matrix from a vector of fill values using alternative indexing semantics. + * + * @param order - storage layout + * @param M - number of rows in `X` + * @param N - number of columns in `X` + * @param alpha - vector of fill values + * @param strideAlpha - stride length of `alpha` + * @param offsetAlpha - starting index of `alpha` + * @param X - input matrix + * @param strideX1 - stride length for the first dimension of `X` + * @param strideX2 - stride length for the second dimension of `X` + * @param offsetX - starting offset of `X` + * @returns `X` + * + * @example + * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); + * + * var alpha = [ 10, 20 ]; + * var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + * + * gfillRows.ndarray( 2, 3, toAccessorArray( alpha ), 1, 0, toAccessorArray( X ), 1, 2, 0 ); + * // X => [ 10.0, 20.0, 10.0, 20.0, 10.0, 20.0 ] + */ + ndarray( M: number, N: number, alpha: InputArray, strideAlpha: number, offsetAlpha: number, X: InputArray, strideX1: number, strideX2: number, offsetX: number ): OutputArray; +} + +/** +* Fills the rows of a matrix from a vector of fill values. +* +* @param order - storage layout +* @param M - number of rows in `X` +* @param N - number of columns in `X` +* @param alpha - vector of fill values +* @param X - input matrix +* @param LDX - stride of the first dimension of `X` +* @returns `X` +* +* @example +* var alpha = [ 10.0, 20.0 ]; +* var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gfillRows( 'row-major', 2, 3, alpha, X, 3 ); +* // X => [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0 ] +*/ +declare var gfillRows: Routine; + + +// EXPORTS // + +export = gfillRows; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/docs/types/test.ts new file mode 100644 index 000000000000..b3198cb0c664 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/docs/types/test.ts @@ -0,0 +1,243 @@ +/* +* @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 AccessorArray = require( '@stdlib/array/base/accessor' ); +import gfillRows = require( './index' ); + + +// TESTS // + +// The function returns a collection... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows( 'row-major', 2, 3, alpha, X, 3 ); // $ExpectType OutputArray +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows( 10, 2, 3, alpha, X, 3 ); // $ExpectError + gfillRows( true, 2, 3, alpha, X, 3 ); // $ExpectError + gfillRows( null, 2, 3, alpha, X, 3 ); // $ExpectError + gfillRows( undefined, 2, 3, alpha, X, 3 ); // $ExpectError + gfillRows( [], 2, 3, alpha, X, 3 ); // $ExpectError + gfillRows( {}, 2, 3, alpha, X, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows( 'row-major', '2', 3, alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', true, 3, alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', null, 3, alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', undefined, 3, alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', [], 3, alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', {}, 3, alpha, X, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows( 'row-major', 2, '3', alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', 2, true, alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', 2, null, alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', 2, undefined, alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', 2, [], alpha, X, 3 ); // $ExpectError + gfillRows( 'row-major', 2, {}, alpha, X, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a collection... +{ + const X = new Float64Array( 6 ); + + gfillRows( 'row-major', 2, 3, 10, X, 3 ); // $ExpectError + gfillRows( 'row-major', 2, 3, true, X, 3 ); // $ExpectError + gfillRows( 'row-major', 2, 3, null, X, 3 ); // $ExpectError + gfillRows( 'row-major', 2, 3, undefined, X, 3 ); // $ExpectError + gfillRows( 'row-major', 2, 3, {}, X, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a collection... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + + gfillRows( 'row-major', 2, 3, alpha, 10, 3 ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, true, 3 ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, null, 3 ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, undefined, 3 ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, {}, 3 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows( 'row-major', 2, 3, alpha, X, '3' ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, X, true ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, X, null ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, X, undefined ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, X, [] ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, X, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows(); // $ExpectError + gfillRows( 'row-major' ); // $ExpectError + gfillRows( 'row-major', 2 ); // $ExpectError + gfillRows( 'row-major', 2, 3 ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, X ); // $ExpectError + gfillRows( 'row-major', 2, 3, alpha, X, 3, 0 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a collection... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectType OutputArray + gfillRows.ndarray( 2, 3, alpha, 1, 0, new AccessorArray( X ), 3, 1, 0 ); // $ExpectType OutputArray +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows.ndarray( '2', 3, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( true, 3, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( null, 3, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( undefined, 3, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( [], 3, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( {}, 3, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows.ndarray( 2, '3', alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, true, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, null, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, undefined, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, [], alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, {}, alpha, 1, 0, X, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + const X = new Float64Array( 6 ); + + gfillRows.ndarray( 2, 3, 10, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, true, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, null, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, undefined, 1, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, {}, 1, 0, X, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + gfillRows.ndarray( 2, 3, alpha, '0', 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, true, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, null, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, undefined, 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, [], 0, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, {}, 0, X, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + gfillRows.ndarray( 2, 3, alpha, 1, '0', X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, true, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, null, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, undefined, X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, [], X, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, {}, X, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a collection... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + + gfillRows.ndarray( 2, 3, alpha, 1, 0, 10, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, true, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, null, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, undefined, 3, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, {}, 3, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, '1', 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, true, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, null, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, undefined, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, [], 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, {}, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, 1, '0' ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, 1, true ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, 1, null ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, 1, undefined ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, 1, [] ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, 1, {} ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const alpha = new Float64Array( [ 10.0, 20.0 ] ); + const X = new Float64Array( 6 ); + + gfillRows.ndarray(); // $ExpectError + gfillRows.ndarray( 2 ); // $ExpectError + gfillRows.ndarray( 2, 3 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, 1 ); // $ExpectError + gfillRows.ndarray( 2, 3, alpha, 1, 0, X, 3, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/examples/index.js new file mode 100644 index 000000000000..4d81a53b83ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/examples/index.js @@ -0,0 +1,31 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var gfillRows = require( './../lib' ); + +var alpha = [ 10.0, 20.0 ]; +var A = uniform( 6, -100, 100, { + 'dtype': 'float64' +}); +console.log( A ); + +gfillRows( 'row-major', 2, 3, alpha, A, 3 ); +console.log( A ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/accessors.js new file mode 100644 index 000000000000..5b8e71a25876 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/accessors.js @@ -0,0 +1,181 @@ +/** +* @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 the rows of a matrix from a vector of fill values. +* +* @param {integer} M - number of rows in `X` +* @param {integer} N - number of columns in `X` +* @param {Object} alpha - object of fill values +* @param {Collection} alpha.data - fill value array data +* @param {Array} alpha.accessors - array element accessors +* @param {integer} strideAlpha - stride length of `alpha` +* @param {NonNegativeInteger} offsetAlpha - starting index for `alpha` +* @param {Object} X - input matrix object +* @param {Collection} X.data - input matrix data +* @param {Array} X.accessors - array element accessors +* @param {integer} strideX1 - stride length for the first dimension of `X` +* @param {integer} strideX2 - stride length for the second dimension of `X` +* @param {NonNegativeInteger} offsetX - starting index for `X` +* @returns {Collection} input matrix +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var alpha = arraylike2object( toAccessorArray( [ 10.0, 20.0 ] ) ); +* var X = arraylike2object( toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); +* +* gfillRows( 2, 3, alpha, 1, 0, X, 1, 2, 0 ); +* // X.data => [ 10.0, 20.0, 10.0, 20.0, 10.0, 20.0 ] +*/ +function gfillRows( M, N, alpha, strideAlpha, offsetAlpha, X, strideX1, strideX2, offsetX ) { + var value; + var abuf; + var aget; + var xbuf; + var xset; + var ix; + var ia; + var i; + var j; + + // Column-major + if ( strideX1 === 1 ) { + if ( alpha.accessorProtocol && X.accessorProtocol ) { + // Cache references to array data, accessors + abuf = alpha.data; + aget = alpha.accessors[ 0 ]; + + xbuf = X.data; + xset = X.accessors[ 1 ]; + + for ( j = 0; j < N; j++ ) { + ix = offsetX + (j * strideX2); + ia = offsetAlpha; + for ( i = 0; i < M; i++ ) { + xset( xbuf, ix, aget( abuf, ia ) ); + ix += strideX1; + ia += strideAlpha; + } + } + } + + else if ( alpha.accessorProtocol ) { + // Cache references to array data, accessors + abuf = alpha.data; + aget = alpha.accessors[ 0 ]; + + for ( j = 0; j < N; j++ ) { + ix = offsetX + (j * strideX2); + ia = offsetAlpha; + for ( i = 0; i < M; i++ ) { + X[ ix ] = aget( abuf, ia ); + ix += strideX1; + ia += strideAlpha; + } + } + } + + else if ( X.accessorProtocol ) { + // Cache references to array data, accessors + xbuf = X.data; + xset = X.accessors[ 1 ]; + + for ( j = 0; j < N; j++ ) { + ix = offsetX + (j * strideX2); + ia = offsetAlpha; + for ( i = 0; i < M; i++ ) { + xset( xbuf, ix, alpha[ ia ] ); + ix += strideX1; + ia += strideAlpha; + } + } + } + + return X; + } + + // Row-major + if ( alpha.accessorProtocol && X.accessorProtocol ) { + // Cache references to array data, accessors + abuf = alpha.data; + aget = alpha.accessors[ 0 ]; + + xbuf = X.data; + xset = X.accessors[ 1 ]; + + for ( i = 0; i < M; i++ ) { + ix = offsetX + (i * strideX1); + ia = offsetAlpha + (i * strideAlpha); + + // Cache current rows fill value + value = aget( abuf, ia ); + for ( j = 0; j < N; j++ ) { + xset( xbuf, ix, value ); + ix += strideX2; + } + } + } + + else if ( alpha.accessorProtocol ) { + // Cache references to array data, accessors + abuf = alpha.data; + aget = alpha.accessors[ 0 ]; + + for ( i = 0; i < M; i++ ) { + ix = offsetX + (i * strideX1); + ia = offsetAlpha + (i * strideAlpha); + + // Cache current rows fill value + value = aget( abuf, ia ); + for ( j = 0; j < N; j++ ) { + X[ ix ] = value; + ix += strideX2; + } + } + } + + else if ( X.accessorProtocol ) { + // Cache references to array data, accessors + xbuf = X.data; + xset = X.accessors[ 1 ]; + + for ( i = 0; i < M; i++ ) { + ix = offsetX + (i * strideX1); + ia = offsetAlpha + (i * strideAlpha); + + value = alpha[ ia ]; + for ( j = 0; j < N; j++ ) { + xset( xbuf, ix, value ); + ix += strideX2; + } + } + } + + return X; +} + + +// EXPORTS // + +module.exports = gfillRows; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/index.js new file mode 100644 index 000000000000..d33eb6728bf2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/index.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'; + +/** +* Fill the rows of a matrix from a vector of fill values. +* +* @module @stdlib/blas/ext/base/gfill-rows +* +* @example +* var gfillRows = require( '@stdlib/blas/ext/base/gfill-rows' ); +* +* var alpha = [ 10.0, 20.0 ]; +* var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gfillRows( 'row-major', 2, 3, alpha, X, 3 ); +* // X => [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.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/gfill-rows/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/main.js new file mode 100644 index 000000000000..9f112a4a700b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/main.js @@ -0,0 +1,80 @@ +/** +* @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 isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var format = require( '@stdlib/string/format' ); +var max = require( '@stdlib/math/base/special/fast/max' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Fills the rows of a matrix from a vector of fill values. +* +* @param {string} order - storage layout +* @param {integer} M - number of rows in `X` +* @param {integer} N - number of columns in `X` +* @param {Collection} alpha - vector containing fill values +* @param {Collection} X - input matrix +* @param {integer} LDX - stride of the first dimension of `X` (a.k.a., leading dimension of the matrix `X`) +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} sixth argument must be greater than or equal to max(1,M) for column-major or max(1,N) for row-major +* @returns {Collection} input matrix +* +* @example +* var alpha = [ 10.0, 20.0 ]; +* var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gfillRows( 'row-major', 2, 3, alpha, X, 3 ); +* // X => [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0 ] +*/ +function gfillRows( order, M, N, alpha, X, LDX ) { + var strideX1; + var strideX2; + var s; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + + if ( isColumnMajor( order ) ) { + s = M; + strideX1 = 1; + strideX2 = LDX; + } else { // order === 'row-major' + s = N; + strideX1 = LDX; + strideX2 = 1; + } + if ( LDX < max( 1, s ) ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be greater than or equal to max(1,%d). Value: `%d`.', s, LDX ) ); + } + + return ndarray( M, N, alpha, 1, 0, X, strideX1, strideX2, 0 ); +} + + +// EXPORTS // + +module.exports = gfillRows; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/ndarray.js new file mode 100644 index 000000000000..05ac5c85b7bf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/lib/ndarray.js @@ -0,0 +1,100 @@ +/** +* @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 gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray; +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Fills the rows of a matrix from a vector of fill values. +* +* @param {integer} M - number of rows in `X` +* @param {integer} N - number of columns in `X` +* @param {Collection} alpha - vector of fill values +* @param {integer} strideAlpha - stride length of `alpha` +* @param {NonNegativeInteger} offsetAlpha - starting index for `alpha` +* @param {Collection} X - input matrix +* @param {integer} strideX1 - stride length for the first dimension of `X` +* @param {integer} strideX2 - stride length for the second dimension of `X` +* @param {NonNegativeInteger} offsetX - starting index for `X` +* @returns {Collection} input matrix +* +* @example +* var alpha = [ 10.0, 20.0 ]; +* var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* gfillRows( 2, 3, alpha, 1, 0, X, 3, 1, 0 ); +* // X => [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0 ] +*/ +function gfillRows( M, N, alpha, strideAlpha, offsetAlpha, X, strideX1, strideX2, offsetX ) { + var ia; + var ix; + var oa; + var ox; + var i; + var j; + + if ( M <= 0 || N <= 0 ) { + return X; + } + + oa = arraylike2object( alpha ); + ox = arraylike2object( X ); + + if ( oa.accessorProtocol || ox.accessorProtocol ) { + return accessors( M, N, oa, strideAlpha, offsetAlpha, ox, strideX1, strideX2, offsetX ); + } + + // Column-major + if ( strideX1 === 1 ) { + ia = offsetAlpha; + for ( j = 0; j < N; j++ ) { + ix = offsetX + (j * strideX2); + ia = offsetAlpha; + for ( i = 0; i < M; i++ ) { + X[ ix ] = alpha[ ia ]; + ix += strideX1; + ia += strideAlpha; + } + } + + return X; + } + + // Row-major + ia = offsetAlpha; + for ( i = 0; i < M; i++ ) { + ix = offsetX + (i * strideX1); + gfill( N, alpha[ ia ], X, strideX2, ix); + ia += strideAlpha; + } + + return X; +} + + +// EXPORTS // + +module.exports = gfillRows; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/package.json b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/package.json new file mode 100644 index 000000000000..3dfb3801124b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/gfill-rows", + "version": "0.0.0", + "description": "Fill the rows of a matrix from a vector of fill values.", + "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", + "row", + "assign", + "set", + "matrix", + "constant", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/test/test.js new file mode 100644 index 000000000000..eddf1dcf39b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/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 gfillRows = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfillRows, '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 gfillRows.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/test/test.main.js new file mode 100644 index 000000000000..84f4671617ae --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/test/test.main.js @@ -0,0 +1,203 @@ +/** +* @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 gfillRows = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfillRows, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( gfillRows.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var i; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var alpha = [ 1.0, 2.0 ]; + var X = [ 0.0, 0.0, 0.0, 0.0 ]; + gfillRows( value, 2, 2, alpha, X, 2 ); + }; + } +}); + +tape( 'the function throws an error if provided a sixth argument which is not a valid LDX value (row-major)', function test( t ) { + var values; + var i; + + values = [ 0, 1 ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var alpha = [ 1.0, 2.0 ]; + var X = [ 0.0, 0.0, 0.0, 0.0 ]; + gfillRows( 'row-major', 2, 2, alpha, X, value ); + }; + } +}); + +tape( 'the function throws an error if provided a sixth argument which is not a valid LDX value (column-major)', function test( t ) { + var values; + var i; + + values = [ 0, 1 ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var alpha = [ 1.0, 2.0 ]; + var X = [ 0.0, 0.0, 0.0, 0.0 ]; + gfillRows( 'row-major', 2, 2, alpha, X, value ); + }; + } +}); + +tape( 'the function fills rows of `X` with fill values from `alpha` (row-major)', function test( t ) { + var expected; + var alpha; + var out; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gfillRows( 'row-major', 3, 3, alpha, X, 3 ); + + expected = [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0, 30.0, 30.0, 30.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function fills rows of `X` with fill values from `alpha` (row-major, accessors)', function test( t ) { + var expected; + var alpha; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gfillRows( 'row-major', 3, 3, toAccessorArray( alpha ), toAccessorArray( X ), 3 ); + + expected = [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0, 30.0, 30.0, 30.0 ]; + t.deepEqual( X, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function fills rows of `X` with fill values from `alpha` (column-major)', function test( t ) { + var expected; + var alpha; + var out; + var X; + + alpha = [ 10.0, 20.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gfillRows( 'column-major', 2, 3, alpha, X, 2 ); + + expected = [ 10.0, 20.0, 10.0, 20.0, 10.0, 20.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function fills rows of `X` with fill values from `alpha` (column-major, accessors)', function test( t ) { + var expected; + var alpha; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gfillRows( 'column-major', 2, 3, toAccessorArray( alpha ), toAccessorArray( X ), 2 ); + + expected = [ 10.0, 20.0, 10.0, 20.0, 10.0, 20.0 ]; + t.deepEqual( X, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function leaves `X` unchanged when `M` or `N` is equal to zero', function test( t ) { + var expected; + var alpha; + var out; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gfillRows( 'column-major', 0, 0, alpha, X, 3 ); + + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function leaves `X` unchanged when `M` or `N` is equal to zero (accessors)', function test( t ) { + var expected; + var alpha; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gfillRows( 'column-major', 0, 0, toAccessorArray( alpha ), toAccessorArray( X ), 3 ); + + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + t.deepEqual( X, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/test/test.ndarray.js new file mode 100644 index 000000000000..2ca3fff52546 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-rows/test/test.ndarray.js @@ -0,0 +1,159 @@ +/** +* @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 gfillRows = require( './../lib' ).ndarray; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gfillRows, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function fills rows of `X` with fill values from `alpha` (row-major)', function test( t ) { + var expected; + var alpha; + var out; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gfillRows( 3, 3, alpha, 1, 0, X, 3, 1, 0 ); + + expected = [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0, 30.0, 30.0, 30.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function fills rows of `X` with fill values from `alpha` (row-major, accessors)', function test( t ) { + var expected; + var alpha; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gfillRows( 3, 3, toAccessorArray( alpha ), 1, 0, toAccessorArray( X ), 3, 1, 0 ); + + expected = [ 10.0, 10.0, 10.0, 20.0, 20.0, 20.0, 30.0, 30.0, 30.0 ]; + t.deepEqual( X, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function fills rows of `X` with fill values from `alpha` (column-major)', function test( t ) { + var expected; + var alpha; + var out; + var X; + + alpha = [ 10.0, 20.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gfillRows( 2, 3, alpha, 1, 0, X, 1, 2, 0 ); + + expected = [ 10.0, 20.0, 10.0, 20.0, 10.0, 20.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function fills rows of `X` with fill values from `alpha` (column-major, accessors)', function test( t ) { + var expected; + var alpha; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gfillRows( 2, 3, toAccessorArray( alpha ), 1, 0, toAccessorArray( X ), 1, 2, 0 ); + + expected = [ 10.0, 20.0, 10.0, 20.0, 10.0, 20.0 ]; + t.deepEqual( X, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function leaves `X` unchanged when `M` or `N` is equal to zero', function test( t ) { + var expected; + var alpha; + var out; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gfillRows( 0, 0, alpha, 1, 0, X, 3, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function leaves `X` unchanged when `M` or `N` is equal to zero (accessors)', function test( t ) { + var expected; + var alpha; + var X; + + alpha = [ 10.0, 20.0, 30.0 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + gfillRows( 0, 0, toAccessorArray( alpha ), 1, 0, toAccessorArray( X ), 3, 1, 0 ); + + expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + t.deepEqual( X, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `alpha` offset', function test( t ) { + var expected; + var alpha; + var out; + var X; + + alpha = [ 10.0, 20.0, 30 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gfillRows( 2, 3, alpha, 1, 1, X, 1, 2, 0 ); + + expected = [ 20.0, 30.0, 20.0, 30.0, 20.0, 30.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports an `X` offset', function test( t ) { + var expected; + var alpha; + var out; + var X; + + alpha = [ 10.0, 20.0, 30 ]; + X = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + + out = gfillRows( 2, 3, alpha, 1, 1, X, 1, 2, 1 ); + + expected = [ 0.0, 20.0, 30.0, 20.0, 30.0, 20.0, 30.0 ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.end(); +});