diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/README.md b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/README.md new file mode 100644 index 000000000000..e03acbcac61d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/README.md @@ -0,0 +1,152 @@ + + +# fillDiagonal + +> Fill a specified diagonal of a matrix (or stack of matrices) with a scalar value. + +
+ +For an `M`-by-`N` matrix `A`, the `k`-th diagonal is defined as + + + +```math +D_k = \{\, A_{i,j} : j - i = k \,\} +``` + + + + + +where `k = 0` corresponds to the main diagonal, `k > 0` corresponds to the super-diagonals (above the main diagonal), and `k < 0` corresponds to the sub-diagonals (below the main diagonal). + +
+ + + +
+ +## Usage + +```javascript +var fillDiagonal = require( '@stdlib/ndarray/base/fill-diagonal' ); +``` + +#### fillDiagonal( x, value, dims, k ) + +Fills a specified diagonal of a matrix (or stack of matrices) with a scalar value. + +```javascript +var zeros = require( '@stdlib/ndarray/zeros' ); + +var x = zeros( [ 3, 3 ] ); +// returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] + +var out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); +// returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] + +var bool = ( out === x ); +// returns true +``` + +The function accepts the following arguments: + +- **x**: input ndarray. +- **value**: scalar value. +- **dims**: dimension indices defining the plane in which to fill the diagonal. +- **k**: diagonal offset. + +
+ + + +
+ +## Notes + +- The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. +- Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. +- The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function fills the main diagonal; when `k > 0`, the function fills the diagonal above the main diagonal; and when `k < 0`, the function fills the diagonal below the main diagonal. +- If `value` is a number and `x` has a complex [data type][@stdlib/ndarray/dtypes], the function fills an input ndarray with a complex number whose real component equals the provided scalar `value` and whose imaginary component is zero. +- A `value` must be able to safely cast to the input ndarray [data type][@stdlib/ndarray/dtypes]. Scalar values having floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., a scalar double-precision floating-point number can be used to fill a `'float32'` input ndarray). +- The function **mutates** the input ndarray in-place. + +
+ + + +
+ +## Examples + + + +```javascript +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var fillDiagonal = require( '@stdlib/ndarray/base/fill-diagonal' ); + +// Create a stack of matrices: +var x = zeros( [ 2, 3, 3 ] ); + +// Fill main diagonals: +fillDiagonal( x, 1.0, [ 1, 2 ], 0 ); +console.log( ndarray2array( x ) ); + +// Fill super-diagonals: +fillDiagonal( x, 2.0, [ 1, 2 ], 1 ); +console.log( ndarray2array( x ) ); + +// Fill sub-diagonals: +fillDiagonal( x, 3.0, [ 1, 2 ], -1 ); +console.log( ndarray2array( x ) ); +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/benchmark/benchmark.js new file mode 100644 index 000000000000..7d78f86f2244 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/benchmark/benchmark.js @@ -0,0 +1,272 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var baseEmpty = require( '@stdlib/ndarray/base/empty' ); +var empty = require( '@stdlib/ndarray/empty' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var fillDiagonal = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:ndims=2,ctor=base', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = fillDiagonal( values[ i%values.length ], 1.0, [ 0, 1 ], 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:ndims=2,ctor=non-base', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = fillDiagonal( values[ i%values.length ], 1.0, [ 0, 1 ], 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:ndims=3,ctor=base', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = fillDiagonal( values[ i%values.length ], 1.0, [ 1, 2 ], 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:ndims=3,ctor=non-base', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = fillDiagonal( values[ i%values.length ], 1.0, [ 1, 2 ], 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:ndims=4,ctor=base', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = fillDiagonal( values[ i%values.length ], 1.0, [ 2, 3 ], 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:ndims=4,ctor=non-base', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = fillDiagonal( values[ i%values.length ], 1.0, [ 2, 3 ], 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:ndims=5,ctor=base', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = fillDiagonal( values[ i%values.length ], 1.0, [ 3, 4 ], 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:ndims=5,ctor=non-base', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = fillDiagonal( values[ i%values.length ], 1.0, [ 3, 4 ], 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/docs/repl.txt new file mode 100644 index 000000000000..39a3b54f18a2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/docs/repl.txt @@ -0,0 +1,53 @@ + +{{alias}}( x, value, dims, k ) + Fills a specified diagonal of a matrix (or stack of matrices) with a + scalar value. + + The order of the dimension indices contained in `dims` matters. The first + element specifies the row-like dimension. The second element specifies the + column-like dimension. + + Each provided dimension index must reside on the interval [-ndims, ndims-1]. + + The diagonal offset `k` is interpreted as `column - row`. Accordingly, when + `k = 0`, the function fills the main diagonal; when `k > 0`, the function + fills a diagonal above the main diagonal; and when `k < 0`, the function + fills a diagonal below the main diagonal. + + The function mutates the input ndarray in-place. + + Parameters + ---------- + x: ndarray + Input array. + + value: any + Scalar value. Must be able to safely cast to the input ndarray data + type. Scalar values having floating-point data types (both real and + complex) are allowed to downcast to a lower precision data type of the + same kind (e.g., a scalar double-precision floating-point number can be + used to fill a 'float32' input ndarray). + + dims: ArrayLikeObject + Dimension indices defining the plane in which to fill the diagonal. + + k: integer + Diagonal offset. + + Returns + ------- + out: ndarray + Input array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/zeros}}( [ 3, 3 ] ) + + > var out = {{alias}}( x, 1.0, [ 0, 1 ], 0 ) + [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] + > var bool = ( out === x ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/docs/types/index.d.ts new file mode 100644 index 000000000000..4a952d53c0f3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/docs/types/index.d.ts @@ -0,0 +1,59 @@ +/* +* @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 } from '@stdlib/types/array'; +import { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Fills a specified diagonal of a matrix (or stack of matrices) with a scalar value. +* +* ## Notes +* +* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. +* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. +* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function fills the main diagonal; when `k > 0`, the function fills the diagonal above the main diagonal; and when `k < 0`, the function fills the diagonal below the main diagonal. +* - The function mutates the input ndarray in-place. +* +* @param x - input array +* @param value - scalar value +* @param dims - dimension indices defining the plane in which to fill the diagonal +* @param k - diagonal offset +* @returns input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = zeros( [ 3, 3 ] ); +* // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] +* +* var out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); +* // returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] +* +* var bool = ( out === x ); +* // returns true +*/ +declare function fillDiagonal = typedndarray>( x: U, value: T, dims: Collection, k: number ): U; + + +// EXPORTS // + +export = fillDiagonal; diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/docs/types/test.ts new file mode 100644 index 000000000000..82c5d4eaf271 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/docs/types/test.ts @@ -0,0 +1,82 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import fillDiagonal = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 2, 2 ] ); + + fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the function is not provided a first argument which is an ndarray... +{ + fillDiagonal( '5', 1.0, [ 0, 1 ], 0 ); // $ExpectError + fillDiagonal( 5, 1.0, [ 0, 1 ], 0 ); // $ExpectError + fillDiagonal( true, 1.0, [ 0, 1 ], 0 ); // $ExpectError + fillDiagonal( false, 1.0, [ 0, 1 ], 0 ); // $ExpectError + fillDiagonal( null, 1.0, [ 0, 1 ], 0 ); // $ExpectError + fillDiagonal( {}, 1.0, [ 0, 1 ], 0 ); // $ExpectError + fillDiagonal( [ '5' ], 1.0, [ 0, 1 ], 0 ); // $ExpectError + fillDiagonal( ( x: number ): number => x, 1.0, [ 0, 1 ], 0 ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a third argument which is an array-like object containing numbers... +{ + const x = zeros( [ 2, 2 ] ); + + fillDiagonal( x, 1.0, '5', 0 ); // $ExpectError + fillDiagonal( x, 1.0, 5, 0 ); // $ExpectError + fillDiagonal( x, 1.0, true, 0 ); // $ExpectError + fillDiagonal( x, 1.0, false, 0 ); // $ExpectError + fillDiagonal( x, 1.0, null, 0 ); // $ExpectError + fillDiagonal( x, 1.0, {}, 0 ); // $ExpectError + fillDiagonal( x, 1.0, [ '5' ], 0 ); // $ExpectError + fillDiagonal( x, 1.0, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a fourth argument which is a number... +{ + const x = zeros( [ 2, 2 ] ); + + fillDiagonal( x, 1.0, [ 0, 1 ], '5' ); // $ExpectError + fillDiagonal( x, 1.0, [ 0, 1 ], true ); // $ExpectError + fillDiagonal( x, 1.0, [ 0, 1 ], false ); // $ExpectError + fillDiagonal( x, 1.0, [ 0, 1 ], null ); // $ExpectError + fillDiagonal( x, 1.0, [ 0, 1 ], {} ); // $ExpectError + fillDiagonal( x, 1.0, [ 0, 1 ], [] ); // $ExpectError + fillDiagonal( x, 1.0, [ 0, 1 ], ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 2, 2 ] ); + + fillDiagonal(); // $ExpectError + fillDiagonal( x ); // $ExpectError + fillDiagonal( x, 1.0 ); // $ExpectError + fillDiagonal( x, 1.0, [ 0, 1 ] ); // $ExpectError + fillDiagonal( x, 1.0, [ 0, 1 ], 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/examples/index.js new file mode 100644 index 000000000000..9fc692ce9590 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/examples/index.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'; + +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var fillDiagonal = require( './../lib' ); + +// Create a stack of matrices: +var x = zeros( [ 2, 3, 3 ] ); + +// Fill main diagonals: +fillDiagonal( x, 1.0, [ 1, 2 ], 0 ); +console.log( ndarray2array( x ) ); + +// Fill super-diagonals: +fillDiagonal( x, 2.0, [ 1, 2 ], 1 ); +console.log( ndarray2array( x ) ); + +// Fill sub-diagonals: +fillDiagonal( x, 3.0, [ 1, 2 ], -1 ); +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/lib/index.js new file mode 100644 index 000000000000..4bdbef3d2f30 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/lib/index.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Fill a specified diagonal of a matrix (or stack of matrices) with a scalar value. +* +* @module @stdlib/ndarray/base/fill-diagonal +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* var fillDiagonal = require( '@stdlib/ndarray/base/fill-diagonal' ); +* +* var x = zeros( [ 3, 3 ] ); +* // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] +* +* var out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); +* // returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] +* +* var bool = ( out === x ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/lib/main.js new file mode 100644 index 000000000000..571a2628bde8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/lib/main.js @@ -0,0 +1,70 @@ +/** +* @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 diagonal = require( '@stdlib/ndarray/base/diagonal' ); +var fill = require( '@stdlib/ndarray/base/fill' ); + + +// MAIN // + +/** +* Fills a specified diagonal of a matrix (or stack of matrices) with a scalar value. +* +* ## Notes +* +* - The order of the dimension indices contained in `dims` matters. The first element specifies the row-like dimension. The second element specifies the column-like dimension. +* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. +* - The diagonal offset `k` is interpreted as `column - row`. Accordingly, when `k = 0`, the function fills the main diagonal; when `k > 0`, the function fills the diagonal above the main diagonal; and when `k < 0`, the function fills the diagonal below the main diagonal. +* - The function mutates the input ndarray in-place. +* +* @param {ndarray} x - input array +* @param {*} value - scalar value +* @param {IntegerArray} dims - dimension indices defining the plane in which to fill the diagonal +* @param {integer} k - diagonal offset +* @throws {RangeError} must provide exactly two dimension indices +* @throws {RangeError} input ndarray must have at least two dimensions +* @throws {RangeError} must provide valid dimension indices +* @throws {Error} must provide unique dimension indices +* @throws {TypeError} second argument cannot be safely cast to the input array data type +* @returns {ndarray} input ndarray +* +* @example +* var zeros = require( '@stdlib/ndarray/zeros' ); +* +* var x = zeros( [ 3, 3 ] ); +* // returns [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] +* +* var out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); +* // returns [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ] +* +* var bool = ( out === x ); +* // returns true +*/ +function fillDiagonal( x, value, dims, k ) { + fill( diagonal( x, dims, k, true ), value ); + return x; +} + + +// EXPORTS // + +module.exports = fillDiagonal; diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/package.json b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/package.json new file mode 100644 index 000000000000..59cf523e7875 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/fill-diagonal", + "version": "0.0.0", + "description": "Fill a specified diagonal of a matrix (or stack of matrices) with a scalar value.", + "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", + "base", + "data", + "structure", + "ndarray", + "diagonal", + "fill", + "matrix", + "stack" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/test/test.js b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/test/test.js new file mode 100644 index 000000000000..1225add25b0e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/fill-diagonal/test/test.js @@ -0,0 +1,496 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeros = require( '@stdlib/ndarray/base/zeros' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var fillDiagonal = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof fillDiagonal, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided exactly two dimension indices', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + [], + [ 0 ], + [ 0, 1, 0 ], + [ 0, 1, 0, 1 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ].length + ' dimension indices' ); + } + t.end(); + + function badValue( dims ) { + return function badValue() { + fillDiagonal( x, 1.0, dims, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided an input ndarray with fewer than two dimensions', function test( t ) { + var values; + var i; + + values = [ + new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ), + new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an input ndarray with '+values[ i ].ndims+' dimensions' ); + } + t.end(); + + function badValue( x ) { + return function badValue() { + fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); + }; + } +}); + +tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + [ 0, 2 ], + [ 2, 0 ], + [ -3, 0 ], + [ 0, -3 ], + [ 10, 0 ], + [ 0, 10 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices ['+values[ i ]+']' ); + } + t.end(); + + function badValue( dims ) { + return function badValue() { + fillDiagonal( x, 1.0, dims, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ), [ 2, 2, 2 ], [ 4, 2, 1 ], 0, 'row-major' ); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 2, 2 ], + [ 0, -3 ], + [ -2, 1 ], + [ -1, 2 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); + } + t.end(); + + function badValue( dims ) { + return function badValue() { + fillDiagonal( x, 1.0, dims, 0 ); + }; + } +}); + +tape( 'the function throws an error if provided a value which cannot be safely cast to the input array data type', function test( t ) { + var x; + + x = zeros( 'int32', [ 3, 3 ], 'row-major' ); + + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + fillDiagonal( x, 3.14, [ 0, 1 ], 0 ); + } +}); + +tape( 'the function fills the main diagonal of a square matrix', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); + + expected = [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.strictEqual( out, x, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills the super-diagonal of a square matrix', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 0, 1 ], 1 ); + + expected = [ [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ], [ 0.0, 0.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ 0, 1 ], 2 ); + + expected = [ [ 0.0, 0.0, 1.0 ], [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills the sub-diagonal of a square matrix', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 0, 1 ], -1 ); + + expected = [ [ 0.0, 0.0, 0.0 ], [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ 0, 1 ], -2 ); + + expected = [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ], [ 1.0, 0.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills the diagonal of a non-square matrix (M < N)', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 2, 4 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); + + expected = [ [ 1.0, 0.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 2, 4 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ 0, 1 ], 2 ); + + expected = [ [ 0.0, 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 0.0, 1.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 2, 4 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ 0, 1 ], -1 ); + + expected = [ [ 0.0, 0.0, 0.0, 0.0 ], [ 1.0, 0.0, 0.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills the diagonal of a non-square matrix (M > N)', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 4, 2 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); + + expected = [ [ 1.0, 0.0 ], [ 0.0, 1.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 4, 2 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ 0, 1 ], -2 ); + + expected = [ [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 1.0, 0.0 ], [ 0.0, 1.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 4, 2 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ 0, 1 ], 1 ); + + expected = [ [ 0.0, 1.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input ndarray unchanged when the diagonal offset is out-of-bounds', function test( t ) { + var expected; + var out; + var x; + + x = array( [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ] ); + + out = fillDiagonal( x, -1.0, [ 0, 1 ], 3 ); + + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ], [ 7.0, 8.0, 9.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + out = fillDiagonal( x, -1.0, [ 0, 1 ], -3 ); + + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + out = fillDiagonal( x, -1.0, [ 0, 1 ], 100 ); + + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function swaps the row-like and column-like dimensions when `dims` is reversed', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 1, 0 ], 1 ); + + expected = [ [ 0.0, 0.0, 0.0 ], [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ 1, 0 ], -1 ); + + expected = [ [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ], [ 0.0, 0.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills the diagonals of a stack of matrices', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 2, 2, 2 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 1, 2 ], 0 ); + + expected = [ + [ [ 1.0, 0.0 ], [ 0.0, 1.0 ] ], + [ [ 1.0, 0.0 ], [ 0.0, 1.0 ] ] + ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 2, 2, 2 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ 1, 2 ], 1 ); + + expected = [ + [ [ 0.0, 1.0 ], [ 0.0, 0.0 ] ], + [ [ 0.0, 1.0 ], [ 0.0, 0.0 ] ] + ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 2, 2, 2 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ 1, 2 ], -1 ); + + expected = [ + [ [ 0.0, 0.0 ], [ 1.0, 0.0 ] ], + [ [ 0.0, 0.0 ], [ 1.0, 0.0 ] ] + ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills the diagonal when `dims` selects non-adjacent dimensions', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 2, 2, 3 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 0, 2 ], 0 ); + + expected = [ + [ [ 1.0, 0.0, 0.0 ], [ 1.0, 0.0, 0.0 ] ], + [ [ 0.0, 1.0, 0.0 ], [ 0.0, 1.0, 0.0 ] ] + ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input ndarrays having a non-zero buffer offset', function test( t ) { + var expected; + var buf; + var out; + var x; + + buf = [ -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; + x = new ndarray( 'generic', buf, [ 3, 3 ], [ 3, 1 ], 1, 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); + + expected = [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.strictEqual( buf[ 0 ], -1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function normalizes negative dimension indices', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ -2, -1 ], 0 ); + + expected = [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports column-major input ndarrays', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 3, 3 ], 'column-major' ); + + out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); + + expected = [ [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills non-trailing dimensions of higher-dimensional ndarrays', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 2, 3, 2 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ 0, 1 ], 0 ); + + expected = [ + [ + [ 1.0, 1.0 ], + [ 0.0, 0.0 ], + [ 0.0, 0.0 ] + ], + [ + [ 0.0, 0.0 ], + [ 1.0, 1.0 ], + [ 0.0, 0.0 ] + ] + ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative dimension indices combined with a non-zero `k`', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + + out = fillDiagonal( x, 1.0, [ -2, -1 ], 1 ); + + expected = [ [ 0.0, 1.0, 0.0 ], [ 0.0, 0.0, 1.0 ], [ 0.0, 0.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + x = zeros( 'float64', [ 3, 3 ], 'row-major' ); + out = fillDiagonal( x, 1.0, [ -2, -1 ], -1 ); + + expected = [ [ 0.0, 0.0, 0.0 ], [ 1.0, 0.0, 0.0 ], [ 0.0, 1.0, 0.0 ] ]; + t.deepEqual( ndarray2array( out ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function fills the diagonal of a complex128 ndarray', function test( t ) { + var expected; + var out; + var x; + + x = zeros( 'complex128', [ 3, 3 ], 'row-major' ); + + out = fillDiagonal( x, new Complex128( 1.0, 2.0 ), [ 0, 1 ], 0 ); + + expected = new Complex128Array([ + 1.0, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 2.0 + ]); + t.strictEqual( isSameComplex128Array( getData( out ), expected ), true, 'returns expected value' ); + t.strictEqual( out, x, 'returns expected value' ); + + t.end(); +});