Skip to content

Commit 29648e3

Browse files
committed
refactor: improve type specificity
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent b9709d8 commit 29648e3

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

lib/node_modules/@stdlib/ndarray/base/prepend-singleton-dimensions/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { ndarray } from '@stdlib/types/ndarray';
3939
* var y = prependSingletonDimensions( x, 3, false );
4040
* // returns <ndarray>[ [ [ [ [ 1, 2 ], [ 3, 4 ] ] ] ] ]
4141
*/
42-
declare function prependSingletonDimensions( x: ndarray, n: number, writable: boolean ): ndarray;
42+
declare function prependSingletonDimensions<T extends ndarray>( x: T, n: number, writable: boolean ): T;
4343

4444

4545
// EXPORTS //

lib/node_modules/@stdlib/ndarray/base/prepend-singleton-dimensions/docs/types/test.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616
* limitations under the License.
1717
*/
1818

19-
import array = require( '@stdlib/ndarray/array' );
19+
/* eslint-disable space-in-parens */
20+
21+
import zeros = require( '@stdlib/ndarray/zeros' );
2022
import prependSingletonDimensions = require( './index' );
2123

2224

2325
// TESTS //
2426

2527
// The function returns an ndarray...
2628
{
27-
const x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
29+
const x = zeros( [ 2, 2 ], {
30+
'dtype': 'float64'
31+
});
2832

29-
prependSingletonDimensions( x, 3, false ); // $ExpectType ndarray
33+
prependSingletonDimensions( x, 3, false ); // $ExpectType float64ndarray
3034
}
3135

3236
// The compiler throws an error if the function is not provided a first argument which is an ndarray...
@@ -43,7 +47,9 @@ import prependSingletonDimensions = require( './index' );
4347

4448
// The compiler throws an error if the function is not provided a second argument which is a number...
4549
{
46-
const x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
50+
const x = zeros( [ 2, 2 ], {
51+
'dtype': 'float64'
52+
});
4753

4854
prependSingletonDimensions( x, '5', false ); // $ExpectError
4955
prependSingletonDimensions( x, true, false ); // $ExpectError
@@ -56,7 +62,9 @@ import prependSingletonDimensions = require( './index' );
5662

5763
// The compiler throws an error if the function is not provided a third argument which is a boolean...
5864
{
59-
const x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
65+
const x = zeros( [ 2, 2 ], {
66+
'dtype': 'float64'
67+
});
6068

6169
prependSingletonDimensions( x, 3, '5' ); // $ExpectError
6270
prependSingletonDimensions( x, 3, 5 ); // $ExpectError
@@ -68,7 +76,9 @@ import prependSingletonDimensions = require( './index' );
6876

6977
// The compiler throws an error if the function is provided an unsupported number of arguments...
7078
{
71-
const x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
79+
const x = zeros( [ 2, 2 ], {
80+
'dtype': 'float64'
81+
});
7282

7383
prependSingletonDimensions(); // $ExpectError
7484
prependSingletonDimensions( x ); // $ExpectError

lib/node_modules/@stdlib/ndarray/base/prepend-singleton-dimensions/test/test.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
var tape = require( 'tape' );
2424
var array = require( '@stdlib/ndarray/array' );
2525
var ndarray = require( '@stdlib/ndarray/base/ctor' );
26+
var getShape = require( '@stdlib/ndarray/shape' );
27+
var getData = require( '@stdlib/ndarray/data-buffer' );
28+
var getStrides = require( '@stdlib/ndarray/strides' );
2629
var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' );
2730
var prependSingletonDimensions = require( './../lib' ); // eslint-disable-line id-length
2831

@@ -44,15 +47,15 @@ tape( 'the function prepends singleton dimensions', function test( t ) {
4447
y = prependSingletonDimensions( x, 3, false );
4548

4649
t.notEqual( y, x, 'returns expected value' );
47-
t.deepEqual( y.shape, [ 1, 1, 1, 2, 2 ], 'returns expected value' );
48-
t.strictEqual( y.data, x.data, 'returns expected value' );
50+
t.deepEqual( getShape( y ), [ 1, 1, 1, 2, 2 ], 'returns expected value' );
51+
t.strictEqual( getData( y ), getData( x ), 'returns expected value' );
4952
t.strictEqual( isReadOnly( y ), true, 'returns expected value' );
5053

5154
y = prependSingletonDimensions( x, 3, true );
5255

5356
t.notEqual( y, x, 'returns expected value' );
54-
t.deepEqual( y.shape, [ 1, 1, 1, 2, 2 ], 'returns expected value' );
55-
t.strictEqual( y.data, x.data, 'returns expected value' );
57+
t.deepEqual( getShape( y ), [ 1, 1, 1, 2, 2 ], 'returns expected value' );
58+
t.strictEqual( getData( y ), x.data, 'returns expected value' );
5659
t.strictEqual( isReadOnly( y ), false, 'returns expected value' );
5760

5861
t.end();
@@ -66,9 +69,9 @@ tape( 'the function prepends singleton dimensions (base; row-major)', function t
6669
y = prependSingletonDimensions( x, 3, false );
6770

6871
t.notEqual( y, x, 'returns expected value' );
69-
t.deepEqual( y.shape, [ 1, 1, 1, 2, 1, 2 ], 'returns expected value' );
70-
t.deepEqual( y.strides, [ 2, 2, 2, 2, 2, 1 ], 'returns expected value' );
71-
t.strictEqual( y.data, x.data, 'returns expected value' );
72+
t.deepEqual( getShape( y ), [ 1, 1, 1, 2, 1, 2 ], 'returns expected value' );
73+
t.deepEqual( getStrides( y ), [ 2, 2, 2, 2, 2, 1 ], 'returns expected value' );
74+
t.strictEqual( getData( y ), getData( x ), 'returns expected value' );
7275

7376
t.end();
7477
});
@@ -81,9 +84,9 @@ tape( 'the function prepends singleton dimensions (base; column-major)', functio
8184
y = prependSingletonDimensions( x, 3, false );
8285

8386
t.notEqual( y, x, 'returns expected value' );
84-
t.deepEqual( y.shape, [ 1, 1, 1, 2, 1, 2 ], 'returns expected value' );
85-
t.deepEqual( y.strides, [ 1, 1, 1, 1, 2, 2 ], 'returns expected value' );
86-
t.strictEqual( y.data, x.data, 'returns expected value' );
87+
t.deepEqual( getShape( y ), [ 1, 1, 1, 2, 1, 2 ], 'returns expected value' );
88+
t.deepEqual( getStrides( y ), [ 1, 1, 1, 1, 2, 2 ], 'returns expected value' );
89+
t.strictEqual( getData( y ), getData( x ), 'returns expected value' );
8790

8891
t.end();
8992
});

0 commit comments

Comments
 (0)