Skip to content

Commit b9709d8

Browse files
committed
test: use accessors to resolve ndarray meta data
--- 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: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - 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 24fe5a1 commit b9709d8

File tree

8 files changed

+64
-69
lines changed

8 files changed

+64
-69
lines changed

lib/node_modules/@stdlib/ndarray/base/ndarraylike2ndarray/README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var array = require( '@stdlib/ndarray/array' );
4949

5050
var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] );
5151
var out = ndarraylike2ndarray( arr );
52-
// returns <ndarray>
52+
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
5353
```
5454

5555
</section>
@@ -73,24 +73,32 @@ var out = ndarraylike2ndarray( arr );
7373
<!-- eslint no-undef: "error" -->
7474

7575
```javascript
76+
var getDType = require( '@stdlib/ndarray/dtype' );
77+
var getShape = require( '@stdlib/ndarray/shape' );
78+
var getStrides = require( '@stdlib/ndarray/strides' );
79+
var getOffset = require( '@stdlib/ndarray/offset' );
80+
var getOrder = require( '@stdlib/ndarray/order' );
7681
var array = require( '@stdlib/ndarray/array' );
82+
var numel = require( '@stdlib/ndarray/numel' );
83+
var ndims = require( '@stdlib/ndarray/ndims' );
84+
var join = require( '@stdlib/array/base/join' );
7785
var ndarraylike2ndarray = require( '@stdlib/ndarray/base/ndarraylike2ndarray' );
7886

7987
// Create an ndarray:
8088
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
8189

8290
// Convert to a "base" ndarray:
8391
var out = ndarraylike2ndarray( x );
84-
// returns <ndarray>
92+
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
8593

8694
// Print various properties:
87-
console.log( 'dtype: %s', out.dtype );
88-
console.log( 'ndims: %d', out.shape.length );
89-
console.log( 'length: %d', out.length );
90-
console.log( 'shape: [ %s ]', out.shape.join( ', ' ) );
91-
console.log( 'strides: [ %s ]', out.strides.join( ', ' ) );
92-
console.log( 'offset: %d', out.offset );
93-
console.log( 'order: %s', out.order );
95+
console.log( 'dtype: %s', getDType( out ) );
96+
console.log( 'ndims: %d', ndims( out ) );
97+
console.log( 'length: %d', numel( out ) );
98+
console.log( 'shape: [ %s ]', join( getShape( out ), ', ' ) );
99+
console.log( 'strides: [ %s ]', join( getStrides( out ), ', ' ) );
100+
console.log( 'offset: %d', getOffset( out ) );
101+
console.log( 'order: %s', getOrder( out ) );
94102
```
95103

96104
</section>

lib/node_modules/@stdlib/ndarray/base/ndarraylike2ndarray/benchmark/benchmark.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var Float64Array = require( '@stdlib/array/float64' );
2525
var ndarrayBase = require( '@stdlib/ndarray/base/ctor' );
2626
var ndarray = require( '@stdlib/ndarray/ctor' );
2727
var isCollection = require( '@stdlib/assert/is-collection' );
28+
var getData = require( '@stdlib/ndarray/data-buffer' );
2829
var format = require( '@stdlib/string/format' );
2930
var pkg = require( './../package.json' ).name;
3031
var ndarraylike2ndarray = require( './../lib' );
@@ -66,7 +67,7 @@ bench( format( '%s::base_ndarray', pkg ), function benchmark( b ) {
6667
}
6768
}
6869
b.toc();
69-
if ( !isCollection( out.data ) ) {
70+
if ( !isCollection( getData( out ) ) ) {
7071
b.fail( 'should return a collection' );
7172
}
7273
b.pass( 'benchmark finished' );
@@ -107,7 +108,7 @@ bench( format( '%s::ndarray', pkg ), function benchmark( b ) {
107108
}
108109
}
109110
b.toc();
110-
if ( !isCollection( out.data ) ) {
111+
if ( !isCollection( getData( out ) ) ) {
111112
b.fail( 'should return a collection' );
112113
}
113114
b.pass( 'benchmark finished' );
@@ -154,7 +155,7 @@ bench( format( '%s::ndarray_like', pkg ), function benchmark( b ) {
154155
}
155156
}
156157
b.toc();
157-
if ( !isCollection( out.data ) ) {
158+
if ( !isCollection( getData( out ) ) ) {
158159
b.fail( 'should return a collection' );
159160
}
160161
b.pass( 'benchmark finished' );

lib/node_modules/@stdlib/ndarray/base/ndarraylike2ndarray/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
--------
1717
> var arr = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] );
1818
> var out = {{alias}}( arr )
19-
<ndarray>
19+
<ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
2020

2121
See Also
2222
--------

lib/node_modules/@stdlib/ndarray/base/ndarraylike2ndarray/docs/types/test.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,15 @@
1616
* limitations under the License.
1717
*/
1818

19-
/// <reference types="@stdlib/types"/>
20-
21-
import { typedndarray } from '@stdlib/types/ndarray';
19+
import zeros = require( '@stdlib/ndarray/zeros' );
2220
import ndarraylike2ndarray = require( './index' );
2321

24-
/**
25-
* Mock function to create an ndarray-like object.
26-
*
27-
* @returns ndarray-like object
28-
*/
29-
function array(): typedndarray<number> {
30-
const obj: typedndarray<number> = {
31-
'byteLength': 80,
32-
'BYTES_PER_ELEMENT': 8,
33-
'data': new Float64Array( 10 ),
34-
'dtype': 'float64',
35-
'flags': {
36-
'ROW_MAJOR_CONTIGUOUS': true,
37-
'COLUMN_MAJOR_CONTIGUOUS': false
38-
},
39-
'length': 10,
40-
'ndims': 1,
41-
'offset': 0,
42-
'order': 'row-major',
43-
'shape': [ 10 ],
44-
'strides': [ 1 ],
45-
'get': (): number => 0,
46-
'set': (): typedndarray<number> => obj
47-
};
48-
return obj;
49-
}
50-
5122

5223
// TESTS //
5324

5425
// The function returns an ndarray...
5526
{
56-
const x = array();
27+
const x = zeros( [ 2, 2 ] );
5728
ndarraylike2ndarray( x ); // $ExpectType typedndarray<number>
5829
}
5930

@@ -71,7 +42,7 @@ function array(): typedndarray<number> {
7142

7243
// The compiler throws an error if the function is provided an unsupported number of arguments...
7344
{
74-
const x = array();
45+
const x = zeros( [ 2, 2 ] );
7546
ndarraylike2ndarray(); // $ExpectError
7647
ndarraylike2ndarray( x, 5 ); // $ExpectError
7748
}

lib/node_modules/@stdlib/ndarray/base/ndarraylike2ndarray/examples/index.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,29 @@
1818

1919
'use strict';
2020

21+
var getDType = require( '@stdlib/ndarray/dtype' );
22+
var getShape = require( '@stdlib/ndarray/shape' );
23+
var getStrides = require( '@stdlib/ndarray/strides' );
24+
var getOffset = require( '@stdlib/ndarray/offset' );
25+
var getOrder = require( '@stdlib/ndarray/order' );
2126
var array = require( '@stdlib/ndarray/array' );
27+
var numel = require( '@stdlib/ndarray/numel' );
28+
var ndims = require( '@stdlib/ndarray/ndims' );
29+
var join = require( '@stdlib/array/base/join' );
2230
var ndarraylike2ndarray = require( './../lib' );
2331

2432
// Create an ndarray:
2533
var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
2634

2735
// Convert to a "base" ndarray:
2836
var out = ndarraylike2ndarray( x );
29-
// returns <ndarray>
37+
// returns <ndarray>[ [ 1, 2 ], [ 3, 4 ] ]
3038

3139
// Print various properties:
32-
console.log( 'dtype: %s', out.dtype );
33-
console.log( 'ndims: %d', out.shape.length );
34-
console.log( 'length: %d', out.length );
35-
console.log( 'shape: [ %s ]', out.shape.join( ', ' ) );
36-
console.log( 'strides: [ %s ]', out.strides.join( ', ' ) );
37-
console.log( 'offset: %d', out.offset );
38-
console.log( 'order: %s', out.order );
40+
console.log( 'dtype: %s', getDType( out ) );
41+
console.log( 'ndims: %d', ndims( out ) );
42+
console.log( 'length: %d', numel( out ) );
43+
console.log( 'shape: [ %s ]', join( getShape( out ), ', ' ) );
44+
console.log( 'strides: [ %s ]', join( getStrides( out ), ', ' ) );
45+
console.log( 'offset: %d', getOffset( out ) );
46+
console.log( 'order: %s', getOrder( out ) );

lib/node_modules/@stdlib/ndarray/base/ndarraylike2ndarray/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
3131
*
3232
* var out = ndarraylike2ndarray( x );
33-
* // returns <ndarray>
33+
* // returns <ndarray>[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
3434
*/
3535

3636
// MODULES //

lib/node_modules/@stdlib/ndarray/base/ndarraylike2ndarray/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var DEFAULT_ORDER = defaults( 'order' );
5555
* var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
5656
*
5757
* var out = ndarraylike2ndarray( x );
58-
* // returns <ndarray>
58+
* // returns <ndarray>[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
5959
*/
6060
function ndarraylike2ndarray( x ) {
6161
return new ndarray( getDType( x ), getData( x ), getShape( x ), getStrides( x ), getOffset( x ), getOrder( x ) || DEFAULT_ORDER ); // eslint-disable-line max-len

lib/node_modules/@stdlib/ndarray/base/ndarraylike2ndarray/test/test.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ var tape = require( 'tape' );
2424
var Float64Array = require( '@stdlib/array/float64' );
2525
var array = require( '@stdlib/ndarray/array' );
2626
var ndarray = require( '@stdlib/ndarray/base/ctor' );
27+
var getData = require( '@stdlib/ndarray/data-buffer' );
28+
var getDType = require( '@stdlib/ndarray/dtype' );
29+
var getShape = require( '@stdlib/ndarray/shape' );
30+
var getStrides = require( '@stdlib/ndarray/strides' );
31+
var getOffset = require( '@stdlib/ndarray/offset' );
32+
var getOrder = require( '@stdlib/ndarray/order' );
33+
var numel = require( '@stdlib/ndarray/numel' );
2734
var ndarraylike2ndarray = require( './../lib' );
2835

2936

@@ -56,13 +63,13 @@ tape( 'the function converts an ndarray-like object to an ndarray (ndarray)', fu
5663
actual = ndarraylike2ndarray( x );
5764

5865
t.strictEqual( actual instanceof ndarray, true, 'returns expected value' );
59-
t.strictEqual( actual.data, expected.data, 'returns expected value' );
60-
t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' );
61-
t.strictEqual( actual.length, expected.length, 'returns expected value' );
62-
t.deepEqual( actual.shape, expected.shape, 'returns expected value' );
63-
t.deepEqual( actual.strides, expected.strides, 'returns expected value' );
64-
t.strictEqual( actual.offset, expected.offset, 'returns expected value' );
65-
t.strictEqual( actual.order, expected.order, 'returns expected value' );
66+
t.strictEqual( getData( actual ), expected.data, 'returns expected value' );
67+
t.strictEqual( String( getDType( actual ) ), expected.dtype, 'returns expected value' );
68+
t.strictEqual( numel( actual ), expected.length, 'returns expected value' );
69+
t.deepEqual( getShape( actual ), expected.shape, 'returns expected value' );
70+
t.deepEqual( getStrides( actual ), expected.strides, 'returns expected value' );
71+
t.strictEqual( getOffset( actual ), expected.offset, 'returns expected value' );
72+
t.strictEqual( getOrder( actual ), expected.order, 'returns expected value' );
6673

6774
t.end();
6875
});
@@ -96,13 +103,13 @@ tape( 'the function converts an ndarray-like object to an ndarray (ndarray-like)
96103
actual = ndarraylike2ndarray( x );
97104

98105
t.strictEqual( actual instanceof ndarray, true, 'returns expected value' );
99-
t.strictEqual( actual.data, expected.data, 'returns expected value' );
100-
t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' );
101-
t.strictEqual( actual.length, expected.length, 'returns expected value' );
102-
t.deepEqual( actual.shape, expected.shape, 'returns expected value' );
103-
t.deepEqual( actual.strides, expected.strides, 'returns expected value' );
104-
t.strictEqual( actual.offset, expected.offset, 'returns expected value' );
105-
t.strictEqual( actual.order, expected.order, 'returns expected value' );
106+
t.strictEqual( getData( actual ), expected.data, 'returns expected value' );
107+
t.strictEqual( String( getDType( actual ) ), expected.dtype, 'returns expected value' );
108+
t.strictEqual( numel( actual ), expected.length, 'returns expected value' );
109+
t.deepEqual( getShape( actual ), expected.shape, 'returns expected value' );
110+
t.deepEqual( getStrides( actual ), expected.strides, 'returns expected value' );
111+
t.strictEqual( getOffset( actual ), expected.offset, 'returns expected value' );
112+
t.strictEqual( getOrder( actual ), expected.order, 'returns expected value' );
106113

107114
t.end();
108115
});

0 commit comments

Comments
 (0)