diff --git a/lib/node_modules/@stdlib/blas/scal/README.md b/lib/node_modules/@stdlib/blas/scal/README.md new file mode 100644 index 000000000000..ece019f419b8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/README.md @@ -0,0 +1,142 @@ + + +# scal + +> Multiply an input [ndarray][@stdlib/ndarray/ctor] by a scalar constant along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +
+ +## Usage + +```javascript +var scal = require( '@stdlib/blas/scal' ); +``` + +#### scal( x, alpha\[, options] ) + +Multiplies an input [ndarray][@stdlib/ndarray/ctor] by a scalar constant along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ] ); +// returns [ 1.0, 2.0, 3.0, 4.0 ] + +var y = scal( x, 5.0 ); +// returns [ 5.0, 10.0, 15.0, 20.0 ] + +var bool = ( x === y ); +// returns true +``` + +The function has the following parameters: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. +- **alpha**: scalar constant. May be either a numeric value or an [ndarray][@stdlib/ndarray/ctor] having a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. If provided a numeric value, the value is cast to the [data type][@stdlib/ndarray/dtypes] of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] for `alpha` must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] for `alpha` must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options (_optional_). + +The function accepts the following options: + +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. + +By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { + 'shape': [ 2, 2 ], + 'order': 'row-major' +}); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + +var y = scal( x, 5.0, { + 'dims': [ 1 ] +}); +// returns [ [ 5.0, 10.0 ], [ 15.0, 20.0 ] ] +``` + +
+ + + +
+ +## Notes + +- The input [ndarray][@stdlib/ndarray/ctor] is multiplied **in-place** (i.e., the input [ndarray][@stdlib/ndarray/ctor] is **mutated**). +- A provided scalar constant is cast to the [data type][@stdlib/ndarray/dtypes] of the input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scal = require( '@stdlib/blas/scal' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 5 ], -20, 20, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +scal( x, 5.0, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/scal/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/scal/benchmark/benchmark.js new file mode 100644 index 000000000000..0e73c225da43 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var uniform = require( '@stdlib/random/uniform' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var scal = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( [ len ], -50.0, 50.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var o; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = scal( x, 1.0 ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:dtype=%s,len=%d', pkg, options.dtype, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/scal/docs/repl.txt b/lib/node_modules/@stdlib/blas/scal/docs/repl.txt new file mode 100644 index 000000000000..4e5e79783c27 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/docs/repl.txt @@ -0,0 +1,48 @@ + +{{alias}}( x, alpha[, options] ) + Multiplies an input ndarray by a scalar constant along one or more ndarray + dimensions. + + The function multiplies an input ndarray in-place and thus mutates an + input ndarray. + + Parameters + ---------- + x: ndarray + Input array. Must have a numeric or "generic" data type. + + alpha: ndarray|number|Complex + Scalar constant. May be either a scalar value or an ndarray having a + numeric or "generic" data type. If provided a scalar value, the value + is cast to the data type of the input ndarray. If provided an ndarray, + the value must have a shape which is broadcast compatible with the + complement of the shape defined by `options.dims`. For example, given + the input shape `[2, 3, 4]` and `options.dims=[0]`, an ndarray for + `alpha` must have a shape which is broadcast compatible with the shape + `[3, 4]`. Similarly, when performing the operation over all elements in + a provided input ndarray, an ndarray for `alpha` must be a + zero-dimensional ndarray. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided input + ndarray. + + Returns + ------- + out: ndarray + Input array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var y = {{alias}}( x, 5.0 ); + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ 5.0, 10.0, 15.0, 20.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/scal/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/scal/docs/types/index.d.ts new file mode 100644 index 000000000000..6108d2881220 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/docs/types/index.d.ts @@ -0,0 +1,69 @@ +/* +* @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 { ArrayLike } from '@stdlib/types/array'; +import { typedndarray } from '@stdlib/types/ndarray'; +import { ComplexLike } from '@stdlib/types/complex'; + +/** +* Interface defining options. +*/ +interface Options { + /** + * List of dimensions over which to perform operation. + */ + dims?: ArrayLike; +} + +/** +* Multiplies an input ndarray by a scalar constant along one or more ndarray dimensions. +* +* ## Notes +* +* - The input ndarray is multiplied **in-place** (i.e., the input ndarray is **mutated**). +* - A provided scalar constant is cast to the data type of the input ndarray. +* +* @param x - input ndarray +* @param alpha - scalar constant +* @param options - function options +* @returns input ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { +* 'shape': [ 2, 2 ], +* 'order': 'row-major' +* }); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = scal( x, 5.0, { +* 'dims': [ 1 ] +* }); +* // returns [ [ 5.0, 10.0 ], [ 15.0, 20.0 ] ] +*/ +declare function scal>( x: T, alpha: typedndarray | number | ComplexLike, options?: Options ): T; + + +// EXPORTS // + +export = scal; diff --git a/lib/node_modules/@stdlib/blas/scal/docs/types/test.ts b/lib/node_modules/@stdlib/blas/scal/docs/types/test.ts new file mode 100644 index 000000000000..228fc00e602d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/docs/types/test.ts @@ -0,0 +1,132 @@ +/* +* @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 empty = require( '@stdlib/ndarray/empty' ); +import scal = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + scal( empty( [ 2, 2 ], { 'dtype': 'float64' } ), 5.0 ); // $ExpectType float64ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'float64' } ), 5.0, {} ); // $ExpectType float64ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'float32' } ), 5.0 ); // $ExpectType float32ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'float32' } ), 5.0, {} ); // $ExpectType float32ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'int32' } ), 5.0 ); // $ExpectType int32ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'int32' } ), 5.0, {} ); // $ExpectType int32ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'complex128' } ), 5.0 ); // $ExpectType complex128ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'complex128' } ), 5.0, {} ); // $ExpectType complex128ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'complex64' } ), 5.0 ); // $ExpectType complex64ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'complex64' } ), 5.0, {} ); // $ExpectType complex64ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'generic' } ), 5.0 ); // $ExpectType genericndarray + scal( empty( [ 2, 2 ], { 'dtype': 'generic' } ), 5.0, {} ); // $ExpectType genericndarray + + scal( empty( [ 2, 2 ], { 'dtype': 'float64' } ), empty( [], { 'dtype': 'float64' } ) ); // $ExpectType float64ndarray + scal( empty( [ 2, 2 ], { 'dtype': 'float64' } ), empty( [], { 'dtype': 'float64' } ), {} ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + scal( '5', 5.0 ); // $ExpectError + scal( 5, 5.0 ); // $ExpectError + scal( true, 5.0 ); // $ExpectError + scal( false, 5.0 ); // $ExpectError + scal( null, 5.0 ); // $ExpectError + scal( void 0, 5.0 ); // $ExpectError + scal( {}, 5.0 ); // $ExpectError + scal( ( x: number ): number => x, 5.0 ); // $ExpectError + + scal( '5', 5.0, {} ); // $ExpectError + scal( 5, 5.0, {} ); // $ExpectError + scal( true, 5.0, {} ); // $ExpectError + scal( false, 5.0, {} ); // $ExpectError + scal( null, 5.0, {} ); // $ExpectError + scal( void 0, 5.0, {} ); // $ExpectError + scal( {}, 5.0, {} ); // $ExpectError + scal( ( x: number ): number => x, 5.0, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an ndarray or a number... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + scal( x, true ); // $ExpectError + scal( x, false ); // $ExpectError + scal( x, '5' ); // $ExpectError + scal( x, null ); // $ExpectError + scal( x, void 0 ); // $ExpectError + scal( x, [] ); // $ExpectError + scal( x, {} ); // $ExpectError + scal( x, ( x: number ): number => x ); // $ExpectError + + scal( x, true, {} ); // $ExpectError + scal( x, false, {} ); // $ExpectError + scal( x, '5', {} ); // $ExpectError + scal( x, null, {} ); // $ExpectError + scal( x, void 0, {} ); // $ExpectError + scal( x, [], {} ); // $ExpectError + scal( x, {}, {} ); // $ExpectError + scal( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not an object... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + scal( x, 5.0, '5' ); // $ExpectError + scal( x, 5.0, true ); // $ExpectError + scal( x, 5.0, false ); // $ExpectError + scal( x, 5.0, null ); // $ExpectError + scal( x, 5.0, [] ); // $ExpectError + scal( x, 5.0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `dims` option... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + scal( x, 5.0, { 'dims': '5' } ); // $ExpectError + scal( x, 5.0, { 'dims': 5 } ); // $ExpectError + scal( x, 5.0, { 'dims': true } ); // $ExpectError + scal( x, 5.0, { 'dims': false } ); // $ExpectError + scal( x, 5.0, { 'dims': null } ); // $ExpectError + scal( x, 5.0, { 'dims': {} } ); // $ExpectError + scal( x, 5.0, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = empty( [ 2, 2 ], { + 'dtype': 'float64' + }); + + scal(); // $ExpectError + scal( x ); // $ExpectError + scal( x, 5.0, {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/scal/examples/index.js b/lib/node_modules/@stdlib/blas/scal/examples/index.js new file mode 100644 index 000000000000..81dcfdad00ba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scal = require( './../lib' ); + +// Generate an ndarray of random numbers: +var x = discreteUniform( [ 5, 5 ], -20, 20, { + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +// Perform operation: +scal( x, 5.0, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/blas/scal/lib/base.js b/lib/node_modules/@stdlib/blas/scal/lib/base.js new file mode 100644 index 000000000000..d61e86f2b838 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/lib/base.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 dtypes = require( '@stdlib/ndarray/dtypes' ); +var gscal = require( '@stdlib/blas/base/ndarray/gscal' ); +var dscal = require( '@stdlib/blas/base/ndarray/dscal' ); +var sscal = require( '@stdlib/blas/base/ndarray/sscal' ); +var zscal = require( '@stdlib/blas/base/ndarray/zscal' ); +var cscal = require( '@stdlib/blas/base/ndarray/cscal' ); +var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); + + +// VARIABLES // + +var idtypes0 = dtypes( 'numeric_and_generic' ); // input ndarray +var idtypes1 = dtypes( 'numeric_and_generic' ); // alpha ndarray +var odtypes = dtypes( 'numeric_and_generic' ); +var table = { + 'types': [ + 'float64', // input/output + 'float32', // input/output + 'complex128', // input/output + 'complex64' // input/output + + // NOTE: we cannot support dispatch to specialized kernels, such as `csscal` and `zdscal`, as dispatch is based solely on the data type of the input ndarray and `alpha` must be cast to the data type of the input ndarray + ], + 'fcns': [ + dscal, + sscal, + zscal, + cscal + ], + 'default': gscal +}; +var options = { + 'strictTraversalOrder': true +}; + + +// MAIN // + +/** +* Multiplies an input ndarray by a scalar constant along one or more ndarray dimensions. +* +* @private +* @name scal +* @type {Function} +* @param {ndarray} x - input ndarray +* @param {ndarray} alpha - ndarray containing the scalar constant +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be an ndarray-like object +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} input ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* // returns [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +* +* var alpha = scalar2ndarray( 5.0, { +* 'dtype': 'float64' +* }); +* +* var out = scal( x, alpha ); +* // returns [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ +var scal = factory( table, [ idtypes0, idtypes1 ], odtypes, options ); + + +// EXPORTS // + +module.exports = scal; diff --git a/lib/node_modules/@stdlib/blas/scal/lib/index.js b/lib/node_modules/@stdlib/blas/scal/lib/index.js new file mode 100644 index 000000000000..1ceb88f00b0c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/lib/index.js @@ -0,0 +1,51 @@ +/** +* @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'; + +/** +* Multiply an input ndarray by a scalar constant along one or more ndarray dimensions. +* +* @module @stdlib/blas/scal +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var scal = require( '@stdlib/blas/scal' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { +* 'shape': [ 2, 2 ], +* 'order': 'row-major' +* }); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var alpha = array( [ 2.0, 10.0 ] ); +* +* var y = scal( x, alpha, { +* 'dims': [ 1 ] +* }); +* // returns [ [ 2.0, 4.0 ], [ 30.0, 40.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/scal/lib/main.js b/lib/node_modules/@stdlib/blas/scal/lib/main.js new file mode 100644 index 000000000000..49ef419e0cd1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/lib/main.js @@ -0,0 +1,122 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isComplexLike = require( '@stdlib/assert/is-complex-like' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); +var maybeBroadcastArray = require( '@stdlib/ndarray/base/maybe-broadcast-array' ); +var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Multiplies an input ndarray by a scalar constant along one or more ndarray dimensions. +* +* @param {ndarrayLike} x - input ndarray +* @param {(ndarrayLike|number|ComplexLike)} alpha - scalar constant +* @param {Options} [options] - function options +* @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} second argument must be either an ndarray-like object or a numeric value +* @throws {TypeError} options argument must be an object +* @throws {RangeError} dimension indices must not exceed input ndarray bounds +* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions +* @throws {Error} must provide valid options +* @returns {ndarray} input ndarray +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ 1.0, 2.0, 3.0, 4.0 ], { +* 'shape': [ 2, 2 ], +* 'order': 'row-major' +* }); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = scal( x, 5.0, { +* 'dims': [ 1 ] +* }); +* // returns [ [ 5.0, 10.0 ], [ 15.0, 20.0 ] ] +*/ +function scal( x, alpha ) { + var nargs; + var opts; + var dt; + var sh; + var a; + + nargs = arguments.length; + + // Resolve the input ndarray data type: + dt = getDType( x ); + + // Case: scal( x, alpha ) + if ( nargs === 2 ) { + // Case: scal( x, alpha_scalar ) + if ( isNumber( alpha ) || isComplexLike( alpha ) ) { + return base( x, broadcastScalar( alpha, dt, [], getOrder( x ) ) ); + } + // Case: scal( x, alpha_ndarray ) + if ( isndarrayLike( alpha ) ) { + // As the operation is performed across all dimensions, `alpha` is assumed to be a zero-dimensional ndarray... + return base( x, alpha ); + } + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric value. Value: `%s`.', alpha ) ); + } + // Case: scal( x, alpha, opts ) + opts = arguments[ 2 ]; + + // Case: scal( x, alpha_scalar, opts ) + if ( isNumber( alpha ) || isComplexLike( alpha ) ) { + if ( hasOwnProp( opts, 'dims' ) ) { + sh = nonCoreShape( getShape( x ), opts.dims ); + } else { + sh = []; + } + a = broadcastScalar( alpha, dt, sh, getOrder( x ) ); + } + // Case: scal( x, alpha_ndarray, opts ) + else if ( isndarrayLike( alpha ) ) { + // When not provided `dims`, the operation is performed across all dimensions and `alpha` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `alpha` to match the shape of the non-core dimensions... + if ( hasOwnProp( opts, 'dims' ) ) { + a = maybeBroadcastArray( alpha, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len + } else { + a = alpha; + } + } else { + throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or a numeric value. Value: `%s`.', alpha ) ); + } + return base( x, a, opts ); +} + + +// EXPORTS // + +module.exports = scal; diff --git a/lib/node_modules/@stdlib/blas/scal/package.json b/lib/node_modules/@stdlib/blas/scal/package.json new file mode 100644 index 000000000000..29dfdb916542 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/blas/scal", + "version": "0.0.0", + "description": "Multiply an input ndarray by a scalar constant along one or more ndarray dimensions.", + "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", + "level 1", + "linear", + "algebra", + "subroutines", + "scal", + "scale", + "multiply", + "scalar", + "vector", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/scal/test/test.js b/lib/node_modules/@stdlib/blas/scal/test/test.js new file mode 100644 index 000000000000..1cd4ddf718fc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/scal/test/test.js @@ -0,0 +1,1312 @@ +/** +* @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 isSameArray = require( '@stdlib/assert/is-same-array' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var scal = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scal, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 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() { + scal( value, 5.0 ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (ndarray alpha)', function test( t ) { + var values; + var alpha; + var i; + + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + values = [ + '5', + 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() { + scal( value, alpha ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 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() { + scal( value, 5.0, {} ); + }; + } +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray-like object (ndarray alpha, options)', function test( t ) { + var values; + var alpha; + var i; + + alpha = scalar2ndarray( 5.0, { + 'dtype': 'float64' + }); + + values = [ + '5', + 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() { + scal( value, alpha, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an `alpha` argument which is not an ndarray-like object or a numeric value', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 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() { + scal( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided an `alpha` argument which is not an ndarray-like object or a numeric value (options)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 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() { + scal( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an `alpha` argument which is not broadcast-compatible', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + scal( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided an `alpha` argument which is not broadcast-compatible (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + zeros( [ 4 ], opts ), + zeros( [ 2, 2, 2 ], opts ), + zeros( [ 0 ], opts ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + scal( x, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (scalar alpha)', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 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() { + scal( x, 5.0, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object (ndarray alpha)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 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() { + scal( x, scalar2ndarray( 5.0, opts ), value ); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + scal( x, 5.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object of integers (ndarray alpha)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [ 'a' ], + {}, + 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() { + scal( x, scalar2ndarray( 5.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + 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() { + scal( x, 5.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains out-of-bounds indices (ndarray alpha)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ -10 ], + [ 0, 20 ], + [ 20 ] + ]; + 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() { + scal( x, scalar2ndarray( 5.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + 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() { + scal( x, 5.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains too many indices (ndarray alpha)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 1, 2 ], + [ 0, 1, 2, 3 ] + ]; + 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() { + scal( x, scalar2ndarray( 5.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + scal( x, 5.0, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which contains duplicate indices (ndarray alpha)', function test( t ) { + var values; + var opts; + var x; + var i; + + opts = { + 'dtype': 'float64' + }; + x = zeros( [ 2, 2 ], { + 'dtype': 'generic' + }); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, 1, 0 ], + [ 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + scal( x, scalar2ndarray( 5.0, opts ), { + 'dims': value + }); + }; + } +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (default, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, 5.0 ); + expected = [ 5.0, 10.0, 15.0, 20.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (default, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = scal( x, 5.0 ); + expected = [ 5.0, 10.0, 15.0, 20.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (all dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, 5.0, { + 'dims': [ 0, 1 ] + }); + expected = [ 5.0, 10.0, 15.0, 20.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (all dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = scal( x, 5.0, { + 'dims': [ 0, 1 ] + }); + expected = [ 5.0, 10.0, 15.0, 20.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (no dimensions, row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, 5.0, { + 'dims': [] + }); + expected = [ [ 5.0, 10.0 ], [ 15.0, 20.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (no dimensions, column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = scal( x, 5.0, { + 'dims': [] + }); + expected = [ [ 5.0, 15.0 ], [ 10.0, 20.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (row-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, 5.0, { + 'dims': [ 0 ] + }); + expected = [ [ 5.0, 10.0 ], [ 15.0, 20.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, 5.0, { + 'dims': [ 1 ] + }); + expected = [ [ 5.0, 10.0 ], [ 15.0, 20.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports specifying operation dimensions (column-major)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = scal( x, 5.0, { + 'dims': [ 0 ] + }); + expected = [ [ 5.0, 15.0 ], [ 10.0, 20.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = scal( x, 5.0, { + 'dims': [ 1 ] + }); + expected = [ [ 5.0, 15.0 ], [ 10.0, 20.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an `alpha` argument (scalar)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, 5.0 ); + expected = [ 5.0, 10.0, 15.0, 20.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, -2.0 ); + expected = [ -2.0, -4.0, -6.0, -8.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an `alpha` argument (scalar, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, 2.0, {} ); + expected = [ 2.0, 4.0, 6.0, 8.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, 1.0, {} ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an `alpha` argument (0d ndarray)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + opts = { + 'dtype': 'float64' + }; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, scalar2ndarray( 5.0, opts ) ); + expected = [ 5.0, 10.0, 15.0, 20.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, scalar2ndarray( -1.0, opts ) ); + expected = [ -1.0, -2.0, -3.0, -4.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, scalar2ndarray( 0.0, opts ) ); + expected = [ 0.0, 0.0, 0.0, 0.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an `alpha` argument (0d ndarray, options)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + opts = { + 'dtype': 'float64' + }; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, scalar2ndarray( 2.0, opts ), {} ); + expected = [ 2.0, 4.0, 6.0, 8.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, scalar2ndarray( -1.0, opts ), {} ); + expected = [ -1.0, -2.0, -3.0, -4.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, scalar2ndarray( 1.0, opts ), {} ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an `alpha` argument (scalar, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, 2.0, { + 'dims': [ 0 ] + }); + expected = [ [ 2.0, 4.0 ], [ 6.0, 8.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = scal( x, 3.0, { + 'dims': [ 0 ] + }); + expected = [ [ 3.0, 9.0 ], [ 6.0, 12.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = scal( x, 0.0, { + 'dims': [ 0 ] + }); + expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an `alpha` argument (0d ndarray, broadcasted)', function test( t ) { + var expected; + var actual; + var xbuf; + var opts; + var x; + + opts = { + 'dtype': 'float64' + }; + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + actual = scal( x, scalar2ndarray( 2.0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ 2.0, 4.0 ], [ 6.0, 8.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = scal( x, scalar2ndarray( 3.0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ 3.0, 9.0 ], [ 6.0, 12.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); + + actual = scal( x, scalar2ndarray( 0.0, opts ), { + 'dims': [ 0 ] + }); + expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an `alpha` argument (ndarray)', function test( t ) { + var expected; + var actual; + var alpha; + var xbuf; + var abuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + abuf = [ 2.0, 10.0 ]; + alpha = new ndarray( 'generic', abuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = scal( x, alpha, { + 'dims': [ 1 ] + }); + expected = [ [ 2.0, 4.0 ], [ 30.0, 40.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + x = new ndarray( 'generic', xbuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + abuf = [ 1.0, 2.0 ]; + alpha = new ndarray( 'generic', abuf, [ 2 ], [ 1 ], 0, 'row-major' ); + actual = scal( x, alpha, { + 'dims': [ 1 ] + }); + expected = [ [ 1.0, 2.0, 3.0 ], [ 8.0, 10.0, 12.0 ] ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( getOrder( actual ), getOrder( x ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies elements in a 1d ndarray', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + x = new ndarray( 'generic', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + + actual = scal( x, 5.0 ); + expected = [ 5.0, 10.0, 15.0, 20.0, 25.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'generic', 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0 ]; + x = new ndarray( 'generic', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + + actual = scal( x, -2.0 ); + expected = [ -2.0, -4.0, -6.0, -8.0, -10.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `alpha` argument equal to `1`, the function returns an input ndarray unchanged', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = [ 1.0, 2.0, 3.0, 4.0 ]; + x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + + actual = scal( x, 1.0 ); + expected = [ 1.0, 2.0, 3.0, 4.0 ]; + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( isSameArray( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (complex128, real-valued alpha)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'complex128', xbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + actual = scal( x, 2.0 ); + expected = new Complex128Array( [ 2.0, 4.0, 6.0, 8.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex128', 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (complex128, complex-valued alpha)', function test( t ) { + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'complex128', xbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + alpha = new Complex128( 0.0, 1.0 ); + + actual = scal( x, alpha ); + expected = new Complex128Array( [ -2.0, 1.0, -4.0, 3.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex128', 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (complex128, 0d ndarray alpha)', function test( t ) { + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'complex128', xbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + alpha = scalar2ndarray( new Complex128( 2.0, 0.0 ), { + 'dtype': 'complex128' + }); + + actual = scal( x, alpha ); + expected = new Complex128Array( [ 2.0, 4.0, 6.0, 8.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex128', 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (complex64, real-valued alpha)', function test( t ) { + var expected; + var actual; + var xbuf; + var x; + + xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'complex64', xbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + actual = scal( x, 2.0 ); + expected = new Complex64Array( [ 2.0, 4.0, 6.0, 8.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex64', 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (complex64, complex-valued alpha)', function test( t ) { + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'complex64', xbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + alpha = new Complex64( 0.0, 1.0 ); + + actual = scal( x, alpha ); + expected = new Complex64Array( [ -2.0, 1.0, -4.0, 3.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex64', 'returns expected value' ); + t.strictEqual( isSameComplex64Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function multiplies an input ndarray by a scalar constant (complex128, options)', function test( t ) { + var expected; + var actual; + var alpha; + var xbuf; + var x; + + xbuf = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = new ndarray( 'complex128', xbuf, [ 2 ], [ 1 ], 0, 'row-major' ); + + alpha = new Complex128( 2.0, 0.0 ); + + actual = scal( x, alpha, { + 'dims': [ 0 ] + }); + expected = new Complex128Array( [ 2.0, 4.0, 6.0, 8.0 ] ); + + t.strictEqual( actual, x, 'returns expected value' ); + t.strictEqual( String( getDType( actual ) ), 'complex128', 'returns expected value' ); + t.strictEqual( isSameComplex128Array( getData( actual ), expected ), true, 'returns expected value' ); + + t.end(); +});