diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/README.md b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/README.md index 7a68dbefb463..e6421ec8ec64 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/README.md @@ -40,7 +40,7 @@ limitations under the License. var expandDimensions = require( '@stdlib/ndarray/base/expand-dimensions' ); ``` -#### expandDimensions( x, axis ) +#### expandDimensions( x, axis, writable ) Expands the shape of an array `x` by inserting a new dimension of size one at a specified `axis`. @@ -53,27 +53,33 @@ var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); // returns [ [ 1, 2 ], [ 3, 4 ] ] // Prepend a singleton dimension: -var y = expandDimensions( x, 0 ); +var y = expandDimensions( x, 0, false ); // returns [ [ [ 1, 2 ], [ 3, 4 ] ] ] var sh = getShape( y ); // returns [ 1, 2, 2 ] // Append a singleton dimension: -y = expandDimensions( x, 2 ); +y = expandDimensions( x, 2, false ); // returns [ [ [ 1 ], [ 2 ] ], [ [ 3 ], [ 4 ] ] ] sh = getShape( y ); // returns [ 2, 2, 1 ] // Insert a singleton dimension: -y = expandDimensions( x, 1 ); +y = expandDimensions( x, 1, false ); // returns [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ] sh = getShape( y ); // returns [ 2, 1, 2 ] ``` +The function accepts the following arguments: + +- **x**: input ndarray. +- **axis**: axis at which to insert a singleton dimension +- **writable**: boolean indicating whether a returned ndarray should be writable. + @@ -85,6 +91,7 @@ sh = getShape( y ); ## Notes - A provided axis must reside on the interval `[-N-1, N]`, where `N` is the rank (i.e., number of dimensions) of the provided input array. If provided a negative `axis`, the axis position at which to insert a singleton dimension is computed as `N + axis + 1`. Hence, if provided `-1`, the resolved axis position is `N` (i.e., a singleton dimension is appended to the input array). +- The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. @@ -99,32 +106,15 @@ sh = getShape( y ); ```javascript -var array = require( '@stdlib/ndarray/array' ); -var numel = require( '@stdlib/ndarray/base/numel' ); -var ind2sub = require( '@stdlib/ndarray/ind2sub' ); -var getShape = require( '@stdlib/ndarray/shape' ); +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var expandDimensions = require( '@stdlib/ndarray/base/expand-dimensions' ); -// Create a 2-dimensional array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns - -// Insert a singleton dimension: -var y = expandDimensions( x, 1 ); -// returns - -// Retrieve the shape: -var sh = getShape( y ); -// returns [ 2, 1, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} +var y = expandDimensions( x, 1, false ); +console.log( ndarray2array( y ) ); ``` diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/benchmark/benchmark.js index 690a6a4ea643..326405f76c47 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/benchmark/benchmark.js @@ -59,7 +59,7 @@ bench( pkg+'::base_ndarray,2d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = expandDimensions( values[ i%values.length ], 1 ); + out = expandDimensions( values[ i%values.length ], 1, false ); if ( typeof out !== 'object' ) { b.fail( 'should return an object' ); } @@ -100,7 +100,7 @@ bench( pkg+'::ndarray,2d', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = expandDimensions( values[ i%values.length ], 1 ); + out = expandDimensions( values[ i%values.length ], 1, false ); if ( typeof out !== 'object' ) { b.fail( 'should return an object' ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/benchmark/benchmark.ndims.js b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/benchmark/benchmark.ndims.js index 22f6cd1db66f..46e65bee5654 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/benchmark/benchmark.ndims.js +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/benchmark/benchmark.ndims.js @@ -54,7 +54,7 @@ function createBenchmark( ndims ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = expandDimensions( x, i%(ndims-1) ); + out = expandDimensions( x, i%(ndims-1), false ); if ( typeof out !== 'object' ) { b.fail( 'should return an object' ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/repl.txt index 7c6fd17d7773..dd658ab2c203 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( x, axis ) +{{alias}}( x, axis, writable ) Expands the shape of an array by inserting a new dimension of size one at a specified axis. @@ -11,6 +11,9 @@ the resolved axis position is `N` (i.e., a singleton dimension is appended to the input array). + The `writable` parameter only applies to ndarray constructors supporting + read-only instances. + Parameters ---------- x: ndarray @@ -19,6 +22,9 @@ axis: integer Axis at which to insert a singleton dimension. + writable: boolean + Boolean indicating whether the returned ndarray should be writable. + Returns ------- out: ndarray @@ -28,12 +34,8 @@ -------- > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) [ [ 1, 2 ], [ 3, 4 ] ] - > var sh = {{alias:@stdlib/ndarray/shape}}( x ) - [ 2, 2 ] - > var y = {{alias}}( x, 1 ) + > var y = {{alias}}( x, 1, false ) [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ] - > sh = {{alias:@stdlib/ndarray/shape}}( y ) - [ 2, 1, 2 ] See Also -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/types/index.d.ts index 74cf7a19db9a..b1a39c8055ba 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/types/index.d.ts @@ -31,25 +31,19 @@ import { typedndarray } from '@stdlib/types/ndarray'; * * @param x - input array * @param axis - axis at which to insert a singleton dimension +* @param writable - boolean indicating whether the returned ndarray should be writable * @returns output array * * @example -* var getShape = require( '@stdlib/ndarray/shape' ); * var array = require( '@stdlib/ndarray/array' ); * * var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); * // returns [ [ 1, 2 ], [ 3, 4 ] ] * -* var shx = getShape( x ); -* // returns [ 2, 2 ] -* -* var y = expandDimensions( x, 1 ); +* var y = expandDimensions( x, 1, false ); * // returns [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ] -* -* var shy = getShape( y ); -* // returns [ 2, 1, 2 ] */ -declare function expandDimensions( x: typedndarray, axis: number ): typedndarray; +declare function expandDimensions( x: typedndarray, axis: number, writable: boolean ): typedndarray; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/types/test.ts index a1cdc598ad2f..6866ac33667e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/docs/types/test.ts @@ -26,32 +26,47 @@ import expandDimensions = require( './index' ); { const x = zeros( [ 2, 2 ] ); - expandDimensions( x, 1 ); // $ExpectType typedndarray + expandDimensions( x, 1, false ); // $ExpectType typedndarray } // The compiler throws an error if the function is not provided a first argument which is an ndarray... { - expandDimensions( '5', 1 ); // $ExpectError - expandDimensions( 5, 1 ); // $ExpectError - expandDimensions( true, 1 ); // $ExpectError - expandDimensions( false, 1 ); // $ExpectError - expandDimensions( null, 1 ); // $ExpectError - expandDimensions( {}, 1 ); // $ExpectError - expandDimensions( [ '5' ], 1 ); // $ExpectError - expandDimensions( ( x: number ): number => x, 1 ); // $ExpectError + expandDimensions( '5', 1, false ); // $ExpectError + expandDimensions( 5, 1, false ); // $ExpectError + expandDimensions( true, 1, false ); // $ExpectError + expandDimensions( false, 1, false ); // $ExpectError + expandDimensions( void 0, 1, false ); // $ExpectError + expandDimensions( null, 1, false ); // $ExpectError + expandDimensions( {}, 1, false ); // $ExpectError + expandDimensions( [ '5' ], 1, false ); // $ExpectError + expandDimensions( ( x: number ): number => x, 1, false ); // $ExpectError } // The compiler throws an error if the function is not provided a second argument which is a number... { const x = zeros( [ 2, 2 ] ); - expandDimensions( x, '5' ); // $ExpectError - expandDimensions( x, true ); // $ExpectError - expandDimensions( x, false ); // $ExpectError - expandDimensions( x, null ); // $ExpectError - expandDimensions( x, {} ); // $ExpectError - expandDimensions( x, [ '5' ] ); // $ExpectError - expandDimensions( x, ( x: number ): number => x ); // $ExpectError + expandDimensions( x, '5', false ); // $ExpectError + expandDimensions( x, true, false ); // $ExpectError + expandDimensions( x, false, false ); // $ExpectError + expandDimensions( x, void 0, false ); // $ExpectError + expandDimensions( x, null, false ); // $ExpectError + expandDimensions( x, {}, false ); // $ExpectError + expandDimensions( x, [ '5' ], false ); // $ExpectError + expandDimensions( x, ( x: number ): number => x, false ); // $ExpectError +} + +// The compiler throws an error if the function is not provided a third argument which is a boolean... +{ + const x = zeros( [ 2, 2 ] ); + + expandDimensions( x, 1, '5' ); // $ExpectError + expandDimensions( x, 1, 5 ); // $ExpectError + expandDimensions( x, 1, void 0 ); // $ExpectError + expandDimensions( x, 1, null ); // $ExpectError + expandDimensions( x, 1, {} ); // $ExpectError + expandDimensions( x, 1, [ '5' ] ); // $ExpectError + expandDimensions( x, 1, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... @@ -60,5 +75,6 @@ import expandDimensions = require( './index' ); expandDimensions(); // $ExpectError expandDimensions( x ); // $ExpectError - expandDimensions( x, 1, [ 1, 2, 3 ], [ 2, 3 ] ); // $ExpectError + expandDimensions( x, 1 ); // $ExpectError + expandDimensions( x, 1, false, [ 1, 2, 3 ] ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/examples/index.js index df9c5a6765b2..5fe50abe6856 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/examples/index.js @@ -18,29 +18,12 @@ 'use strict'; -var array = require( '@stdlib/ndarray/array' ); -var numel = require( '@stdlib/ndarray/base/numel' ); -var ind2sub = require( '@stdlib/ndarray/ind2sub' ); -var getShape = require( '@stdlib/ndarray/shape' ); +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); var expandDimensions = require( './../lib' ); -// Create a 2-dimensional array: -var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -// returns +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); -// Insert a singleton dimension: -var y = expandDimensions( x, 1 ); -// returns - -// Retrieve the shape: -var sh = getShape( y ); -// returns [ 2, 1, 2 ] - -// Retrieve the number of elements: -var N = numel( sh ); - -// Loop through the array elements... -var i; -for ( i = 0; i < N; i++ ) { - console.log( 'Y[%s] = %d', ind2sub( sh, i ).join( ', ' ), y.iget( i ) ); -} +var y = expandDimensions( x, 1, false ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/lib/index.js index f4d711771a41..551cb8633be4 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/lib/index.js @@ -24,21 +24,14 @@ * @module @stdlib/ndarray/base/expand-dimensions * * @example -* var getShape = require( '@stdlib/ndarray/shape' ); * var array = require( '@stdlib/ndarray/array' ); * var expandDimensions = require( '@stdlib/ndarray/base/expand-dimensions' ); * * var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); * // returns [ [ 1, 2 ], [ 3, 4 ] ] * -* var shx = getShape( x ); -* // returns [ 2, 2 ] -* -* var y = expandDimensions( x, 1 ); +* var y = expandDimensions( x, 1, false ); * // returns [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ] -* -* var shy = getShape( y ); -* // returns [ 2, 1, 2 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/lib/main.js index da6c661bd9fd..bd1caaad24a3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/lib/main.js @@ -21,7 +21,6 @@ // MODULES // var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' ); -var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' ); var getDType = require( '@stdlib/ndarray/base/dtype' ); var getShape = require( '@stdlib/ndarray/base/shape' ); @@ -43,26 +42,20 @@ var format = require( '@stdlib/string/format' ); * * @param {ndarray} x - input array * @param {integer} axis - axis at which to insert a singleton dimension +* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable * @throws {RangeError} must provide a valid axis * @returns {ndarray} output array * * @example -* var getShape = require( '@stdlib/ndarray/shape' ); * var array = require( '@stdlib/ndarray/array' ); * * var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); * // returns [ [ 1, 2 ], [ 3, 4 ] ] * -* var shx = getShape( x ); -* // returns [ 2, 2 ] -* -* var y = expandDimensions( x, 1 ); +* var y = expandDimensions( x, 1, false ); * // returns [ [ [ 1, 2 ] ], [ [ 3, 4 ] ] ] -* -* var shy = getShape( y ); -* // returns [ 2, 1, 2 ] */ -function expandDimensions( x, axis ) { +function expandDimensions( x, axis, writable ) { var strides; var shape; var isrm; @@ -132,13 +125,9 @@ function expandDimensions( x, axis ) { } } } - if ( isReadOnly( x ) ) { - // If provided a read-only view, the returned array should also be read-only... - return new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), ord, { // eslint-disable-line max-len - 'readonly': true - }); - } - return new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), ord ); // eslint-disable-line max-len + return new x.constructor( getDType( x ), getData( x ), shape, strides, getOffset( x ), ord, { // eslint-disable-line max-len + 'readonly': !writable + }); } diff --git a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/test/test.js b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/test/test.js index acc450933030..54f02cc65e35 100644 --- a/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/expand-dimensions/test/test.js @@ -21,13 +21,13 @@ // MODULES // var tape = require( 'tape' ); -var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); var array = require( '@stdlib/ndarray/array' ); var getShape = require( '@stdlib/ndarray/shape' ); var getData = require( '@stdlib/ndarray/data-buffer' ); var getStrides = require( '@stdlib/ndarray/strides' ); var ndims = require( '@stdlib/ndarray/ndims' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); var expandDimensions = require( './../lib' ); @@ -59,7 +59,7 @@ tape( 'the function throws an error if provided an invalid `axis` argument', fun function badValue( value ) { return function badValue() { - expandDimensions( x, value ); + expandDimensions( x, value, false ); }; } }); @@ -70,11 +70,19 @@ tape( 'the function prepends singleton dimensions', function test( t ) { x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = expandDimensions( x, 0 ); + y = expandDimensions( x, 0, false ); + + t.notEqual( y, x, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 1, 2, 2 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); + + y = expandDimensions( x, 0, true ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 1, 2, 2 ], 'returns expected value' ); t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); @@ -85,11 +93,19 @@ tape( 'the function prepends singleton dimensions (negative axis)', function tes x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = expandDimensions( x, -ndims( x )-1 ); + y = expandDimensions( x, -ndims( x )-1, false ); + + t.notEqual( y, x, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 1, 2, 2 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); + + y = expandDimensions( x, -ndims( x )-1, true ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 1, 2, 2 ], 'returns expected value' ); t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); @@ -100,11 +116,19 @@ tape( 'the function appends singleton dimensions', function test( t ) { x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = expandDimensions( x, ndims( x ) ); + y = expandDimensions( x, ndims( x ), false ); + + t.notEqual( y, x, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2, 1 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); + + y = expandDimensions( x, ndims( x ), true ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 2, 1 ], 'returns expected value' ); t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); @@ -115,11 +139,19 @@ tape( 'the function appends singleton dimensions (negative axis)', function test x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = expandDimensions( x, -1 ); + y = expandDimensions( x, -1, false ); + + t.notEqual( y, x, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 2, 1 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); + + y = expandDimensions( x, ndims( x ), true ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 2, 1 ], 'returns expected value' ); t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); @@ -130,11 +162,19 @@ tape( 'the function inserts singleton dimensions', function test( t ) { x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = expandDimensions( x, 1 ); + y = expandDimensions( x, 1, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 1, 2 ], 'returns expected value' ); t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); + + y = expandDimensions( x, 1, true ); + + t.notEqual( y, x, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 1, 2 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); @@ -145,11 +185,19 @@ tape( 'the function inserts singleton dimensions (negative axis)', function test x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); - y = expandDimensions( x, -2 ); + y = expandDimensions( x, -2, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 1, 2 ], 'returns expected value' ); t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); + + y = expandDimensions( x, -2, true ); + + t.notEqual( y, x, 'returns expected value' ); + t.deepEqual( getShape( y ), [ 2, 1, 2 ], 'returns expected value' ); + t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); + t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); t.end(); }); @@ -159,7 +207,7 @@ tape( 'the function prepends singleton dimensions (base; row-major)', function t var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = expandDimensions( x, 0 ); + y = expandDimensions( x, 0, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 1, 2, 2 ], 'returns expected value' ); @@ -174,7 +222,7 @@ tape( 'the function prepends singleton dimensions (base; row-major; negative axi var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = expandDimensions( x, -ndims( x )-1 ); + y = expandDimensions( x, -ndims( x )-1, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 1, 2, 2 ], 'returns expected value' ); @@ -189,7 +237,7 @@ tape( 'the function prepends singleton dimensions (base; column-major)', functio var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - y = expandDimensions( x, 0 ); + y = expandDimensions( x, 0, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 1, 2, 2 ], 'returns expected value' ); @@ -204,7 +252,7 @@ tape( 'the function prepends singleton dimensions (base; column-major; negative var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - y = expandDimensions( x, -ndims( x )-1 ); + y = expandDimensions( x, -ndims( x )-1, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 1, 2, 2 ], 'returns expected value' ); @@ -219,7 +267,7 @@ tape( 'the function appends singleton dimensions (base; row-major)', function te var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = expandDimensions( x, ndims( x ) ); + y = expandDimensions( x, ndims( x ), false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 2, 1 ], 'returns expected value' ); @@ -234,7 +282,7 @@ tape( 'the function appends singleton dimensions (base; row-major; negative axis var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = expandDimensions( x, -1 ); + y = expandDimensions( x, -1, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 2, 1 ], 'returns expected value' ); @@ -249,7 +297,7 @@ tape( 'the function appends singleton dimensions (base; column-major)', function var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - y = expandDimensions( x, ndims( x ) ); + y = expandDimensions( x, ndims( x ), false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 2, 1 ], 'returns expected value' ); @@ -264,7 +312,7 @@ tape( 'the function appends singleton dimensions (base; column-major; negative i var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - y = expandDimensions( x, -1 ); + y = expandDimensions( x, -1, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 2, 1 ], 'returns expected value' ); @@ -279,7 +327,7 @@ tape( 'the function inserts singleton dimensions (base; row-major)', function te var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = expandDimensions( x, 1 ); + y = expandDimensions( x, 1, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 1, 2 ], 'returns expected value' ); @@ -294,7 +342,7 @@ tape( 'the function inserts singleton dimensions (base; row-major; negative axis var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - y = expandDimensions( x, -2 ); + y = expandDimensions( x, -2, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 1, 2 ], 'returns expected value' ); @@ -309,7 +357,7 @@ tape( 'the function inserts singleton dimensions (base; column-major)', function var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - y = expandDimensions( x, 1 ); + y = expandDimensions( x, 1, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 1, 2 ], 'returns expected value' ); @@ -324,7 +372,7 @@ tape( 'the function inserts singleton dimensions (base; column-major; negative i var y; x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 1, 2 ], 0, 'column-major' ); - y = expandDimensions( x, -2 ); + y = expandDimensions( x, -2, false ); t.notEqual( y, x, 'returns expected value' ); t.deepEqual( getShape( y ), [ 2, 1, 2 ], 'returns expected value' ); @@ -333,56 +381,3 @@ tape( 'the function inserts singleton dimensions (base; column-major; negative i t.end(); }); - -tape( 'if provided a read-only array, the function returns a read-only array', function test( t ) { - var x; - var y; - - x = array( [ 1, 2, 3, 4 ], { - 'shape': [ 2, 1, 2 ], - 'readonly': true - }); - - y = expandDimensions( x, 2 ); - - t.notEqual( y, x, 'returns expected value' ); - t.deepEqual( getShape( y ), [ 2, 1, 1, 2 ], 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - t.strictEqual( isReadOnly( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a writable array, the function returns a writable array', function test( t ) { - var x; - var y; - - x = array( [ 1, 2, 3, 4 ], { - 'shape': [ 2, 1, 2 ], - 'readonly': false - }); - - y = expandDimensions( x, 1 ); - - t.notEqual( y, x, 'returns expected value' ); - t.deepEqual( getShape( y ), [ 2, 1, 1, 2 ], 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided a writable array, the function returns a writable array (base)', function test( t ) { - var x; - var y; - - x = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 1, 2 ], [ 2, 2, 1 ], 0, 'row-major' ); - y = expandDimensions( x, 0 ); - - t.notEqual( y, x, 'returns expected value' ); - t.deepEqual( getShape( y ), [ 1, 2, 1, 2 ], 'returns expected value' ); - t.strictEqual( getData( y ), getData( x ), 'returns expected value' ); - t.strictEqual( isReadOnly( y ), false, 'returns expected value' ); - - t.end(); -});