diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md new file mode 100644 index 000000000000..b99b9e263381 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md @@ -0,0 +1,119 @@ + + +# cfill + +> Fill a complex single-precision floating-point ndarray with a specified scalar constant. + +
+ +## Usage + +```javascript +var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); +``` + +#### cfill( arrays ) + +Fills a complex single-precision floating-point ndarray `x` with a specified scalar constant `alpha`. + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); + +var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); + +var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' +}); + +var out = cfill( [ x, alpha ] ); +// returns + +var arr = ndarray2array( out ); +// returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant. + +
+ + + +
+ +## Examples + +```javascript +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); + +var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new ndarray( 'complex64', buffer, [ 3 ], [ 1 ], 0, 'row-major' ); + +var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' +}); + +cfill( [ x, alpha ] ); + +var v = x.get( 0 ); +console.log( 'x[0] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[0] = 10 + 10i' + +v = x.get( 1 ); +console.log( 'x[1] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[1] = 10 + 10i' + +v = x.get( 2 ); +console.log( 'x[2] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[2] = 10 + 10i' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js new file mode 100644 index 000000000000..0d8b6ab57a87 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/benchmark/benchmark.js @@ -0,0 +1,112 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var pkg = require( './../package.json' ).name; +var cfill = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'complex64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var alpha; + var xbuf; + var buf; + var x; + + buf = uniform( len*2, 0.0, 100.0, { + 'dtype': 'float32' + }); + xbuf = new Complex64Array( buf.buffer ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + alpha = scalar2ndarray( new Complex64( 5.0, 5.0 ), options ); + + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = cfill( [ x, alpha ] ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt new file mode 100644 index 000000000000..df7c923a41a9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt @@ -0,0 +1,28 @@ + +{{alias}}( arrays ) + Fills a complex single-precision floating-point ndarray with a specified + scalar constant. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a single one-dimensional input ndarray + and a zero-dimensional ndarray containing a scalar constant. + + Returns + ------- + out: ndarray + Input ndarray. + + Examples + -------- + > var buf = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var x = {{alias:@stdlib/ndarray/ctor}}( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ); + > var C64 = {{alias:@stdlib/complex/float32/ctor}}; + > var s2n = {{alias:@stdlib/ndarray/from-scalar}}; + > var alpha = s2n( new C64( 10.0, 10.0 ), { 'dtype': 'complex64' } ); + > {{alias}}( [ x, alpha ] ) + [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts new file mode 100644 index 000000000000..e9b135a0fd3a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/index.d.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 { complex64ndarray } from '@stdlib/types/ndarray'; + +/** +* Fills a complex single-precision floating-point ndarray with a specified scalar constant. +* +* @param arrays - array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant +* @returns input ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); +* +* var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { +* 'dtype': 'complex64' +* }); +* +* var out = cfill( [ x, alpha ] ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +*/ +declare function cfill( arrays: [ complex64ndarray, complex64ndarray ] ): complex64ndarray; + + +// EXPORTS // + +export = cfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts new file mode 100644 index 000000000000..b6907fe73a9d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeros = require( '@stdlib/ndarray/base/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import Complex64 = require( '@stdlib/complex/float32/ctor' ); +import cfill = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( 'complex64', [ 10 ], 'row-major' ); + const alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' + }); + cfill( [ x, alpha ] ); // $ExpectType complex64ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + cfill( 'abc' ); // $ExpectError + cfill( 5 ); // $ExpectError + cfill( true ); // $ExpectError + cfill( false ); // $ExpectError + cfill( null ); // $ExpectError + cfill( undefined ); // $ExpectError + cfill( {} ); // $ExpectError + cfill( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an insufficient number of arguments... +{ + cfill(); // $ExpectError +} + +// The compiler throws an error if the function is provided too many arguments... +{ + const x = zeros( 'complex64', [ 10 ], 'row-major' ); + const alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' + }); + cfill( [ x, alpha ], 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js new file mode 100644 index 000000000000..1152b71b9165 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/examples/index.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex64Array = require( '@stdlib/array/complex64' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var cfill = require( './../lib' ); + +var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var x = new ndarray( 'complex64', buffer, [ 3 ], [ 1 ], 0, 'row-major' ); + +var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' +}); + +cfill( [ x, alpha ] ); + +var v = x.get( 0 ); +console.log( 'x[0] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[0] = 10 + 10i' + +v = x.get( 1 ); +console.log( 'x[1] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[1] = 10 + 10i' + +v = x.get( 2 ); +console.log( 'x[2] = %d + %di', realf( v ), imagf( v ) ); +// => 'x[2] = 10 + 10i' diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js new file mode 100644 index 000000000000..069558c559d3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/index.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Fill a complex single-precision floating-point ndarray with a specified scalar constant. +* +* @module @stdlib/blas/ext/base/ndarray/cfill +* +* @example + * var Complex64Array = require( '@stdlib/array/complex64' ); + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * var ndarray = require( '@stdlib/ndarray/ctor' ); + * var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' ); + * + * var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + * var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); + * + * var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + * 'dtype': 'complex64' + * }); + * + * var out = cfill( [ x, alpha ] ); + * // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js new file mode 100644 index 000000000000..4b97021ce582 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/lib/main.js @@ -0,0 +1,85 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var strided = require( '@stdlib/blas/ext/base/cfill' ).ndarray; +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); + + +// MAIN // + +/** +* Fills a complex single-precision floating-point ndarray with a specified scalar constant. +* +* @param {ArrayLikeObject} arrays - array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant +* @returns {complex64ndarray} input ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); +* var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' ); +* +* var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { +* 'dtype': 'complex64' +* }); +* +* var out = cfill( [ x, alpha ] ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ] +*/ +function cfill( arrays ) { + var alpha; + var buf; + var sx; + var ox; + var x; + var N; + + x = arrays[ 0 ]; + alpha = ndarraylike2scalar( arrays[ 1 ] ); + + N = numelDimension( x, 0 ); + if ( N <= 0 ) { + return x; + } + buf = getData( x ); + sx = getStride( x, 0 ); + ox = getOffset( x ); + + strided( N, alpha, buf, sx, ox ); + return x; +} + + +// EXPORTS // + +module.exports = cfill; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json new file mode 100644 index 000000000000..5c36f2f3da78 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/cfill", + "version": "0.0.0", + "description": "Fill a one-dimensional complex single-precision floating-point ndarray with a specified scalar constant.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "ndarray", + "blas", + "extend", + "extended", + "extension", + "base", + "fill", + "array", + "typed", + "complex", + "complex64", + "float", + "float32", + "single" + ] +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js new file mode 100644 index 000000000000..fe6b25a2f288 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/test/test.js @@ -0,0 +1,167 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 Complex64Array = require( '@stdlib/array/complex64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var cfill = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cfill, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function fills an ndarray with a specified scalar constant', function test( t ) { + var alpha; + var raw; + var buf; + var x; + var v; + + raw = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ); + + alpha = scalar2ndarray( new Complex64( 5.0, -3.0 ), { + 'dtype': 'complex64' + }); + + cfill( [ x, alpha ] ); + + v = x.get( 0 ); + t.strictEqual( realf( v ), 5.0, 'returns expected real component for element 0' ); + t.strictEqual( imagf( v ), -3.0, 'returns expected imaginary component for element 0' ); + + v = x.get( 1 ); + t.strictEqual( realf( v ), 5.0, 'returns expected real component for element 1' ); + t.strictEqual( imagf( v ), -3.0, 'returns expected imaginary component for element 1' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray', function test( t ) { + var alpha; + var raw; + var buf; + var out; + var x; + + raw = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' ); + + alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), { + 'dtype': 'complex64' + }); + + out = cfill( [ x, alpha ] ); + + t.strictEqual( out, x, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var alpha; + var raw; + var buf; + var x; + var v; + + raw = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 2 ], [ -1 ], 1, 'row-major' ); + + alpha = scalar2ndarray( new Complex64( 7.0, 8.0 ), { + 'dtype': 'complex64' + }); + + cfill( [ x, alpha ] ); + + v = x.get( 0 ); + t.strictEqual( realf( v ), 7.0, 'returns expected real component for element 0' ); + t.strictEqual( imagf( v ), 8.0, 'returns expected imaginary component for element 0' ); + + v = x.get( 1 ); + t.strictEqual( realf( v ), 7.0, 'returns expected real component for element 1' ); + t.strictEqual( imagf( v ), 8.0, 'returns expected imaginary component for element 1' ); + + t.end(); +}); + +tape( 'the function supports an offset', function test( t ) { + var alpha; + var raw; + var buf; + var x; + var v; + + raw = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 2 ], [ 1 ], 1, 'row-major' ); + + alpha = scalar2ndarray( new Complex64( 9.0, -2.0 ), { + 'dtype': 'complex64' + }); + + cfill( [ x, alpha ] ); + + v = buf.get( 0 ); + t.strictEqual( realf( v ), 1.0, 'element 0 unchanged (real)' ); + t.strictEqual( imagf( v ), 2.0, 'element 0 unchanged (imag)' ); + + v = x.get( 0 ); + t.strictEqual( realf( v ), 9.0, 'returns expected real component for element at offset' ); + t.strictEqual( imagf( v ), -2.0, 'returns expected imaginary component for element at offset' ); + + t.end(); +}); + +tape( 'the function handles zero-length dimensions', function test( t ) { + var alpha; + var raw; + var buf; + var x; + + raw = new Float32Array( [ 1.0, 2.0 ] ); + buf = new Complex64Array( raw ); + x = new ndarray( 'complex64', buf, [ 0 ], [ 1 ], 0, 'row-major' ); + + alpha = scalar2ndarray( new Complex64( 5.0, 5.0 ), { + 'dtype': 'complex64' + }); + + cfill( [ x, alpha ] ); + + t.strictEqual( realf( buf.get( 0 ) ), 1.0, 'buffer unchanged' ); + t.strictEqual( imagf( buf.get( 0 ) ), 2.0, 'buffer unchanged' ); + + t.end(); +});