Skip to content

Commit 4e06982

Browse files
committed
Update tests
1 parent 1f9f558 commit 4e06982

File tree

2 files changed

+106
-57
lines changed

2 files changed

+106
-57
lines changed

lib/node_modules/@stdlib/blas/ddot/lib/main.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,14 @@ function ddot( x, y ) {
8282
}
8383
opts = {
8484
'dtype': 'float64',
85-
'casting': 'unsafe',
86-
'codegen': false
85+
'casting': 'unsafe'
8786
};
8887
x = array( x, opts );
8988
y = array( y, opts );
90-
if ( x.shape.length !== 1 ) {
89+
if ( x.ndims !== 1 ) {
9190
throw new TypeError( 'invalid argument. First argument must be either an array-like object or ndarray which can be cast to a 1-dimensional ndarray. Value: `' + x + '`.' );
9291
}
93-
if ( y.shape.length !== 1 ) {
92+
if ( y.ndims !== 1 ) {
9493
throw new TypeError( 'invalid argument. Second argument must be either an array-like object or ndarray which can be cast to a 1-dimensional ndarray. Value: `' + y + '`.' );
9594
}
9695
}

lib/node_modules/@stdlib/blas/ddot/test/test.js

Lines changed: 103 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ tape( 'the function has an arity of 2', function test( t ) {
4949
t.end();
5050
});
5151

52-
tape( 'the function throws an error if provided a first argument which is not a 1-dimensional ndarray', function test( t ) {
52+
tape( 'the function throws an error if provided a first argument which is not a 1-dimensional ndarray or array-like object', function test( t ) {
5353
var values;
5454
var i;
5555

@@ -60,7 +60,6 @@ tape( 'the function throws an error if provided a first argument which is not a
6060
false,
6161
null,
6262
void 0,
63-
[],
6463
{},
6564
function noop() {}
6665
];
@@ -79,30 +78,7 @@ tape( 'the function throws an error if provided a first argument which is not a
7978
}
8079
});
8180

82-
tape( 'the function throws an error if provided a first argument which is not a 1-dimensional ndarray containing double-precision floating-point numbers', function test( t ) {
83-
var values;
84-
var i;
85-
86-
values = [
87-
array( new Float32Array( 10 ) ),
88-
array( new Int32Array( 10 ) )
89-
];
90-
91-
for ( i = 0; i < values.length; i++ ) {
92-
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ].toString() );
93-
}
94-
t.end();
95-
96-
function badValue( value ) {
97-
var y = array( new Float64Array( 10 ) );
98-
99-
return function badValue() {
100-
ddot( value, y );
101-
};
102-
}
103-
});
104-
105-
tape( 'the function throws an error if provided a second argument which is not a 1-dimensional ndarray', function test( t ) {
81+
tape( 'the function throws an error if provided a second argument which is not a 1-dimensional ndarray or array-like object', function test( t ) {
10682
var values;
10783
var i;
10884

@@ -113,7 +89,6 @@ tape( 'the function throws an error if provided a second argument which is not a
11389
false,
11490
null,
11591
void 0,
116-
[],
11792
{},
11893
function noop() {}
11994
];
@@ -132,41 +107,54 @@ tape( 'the function throws an error if provided a second argument which is not a
132107
}
133108
});
134109

135-
tape( 'the function throws an error if provided a second argument which is not a 1-dimensional ndarray containing double-precision floating-point numbers', function test( t ) {
136-
var values;
137-
var i;
138-
139-
values = [
140-
array( new Float32Array( 10 ) ),
141-
array( new Int32Array( 10 ) )
142-
];
110+
tape( 'the function throws an error if provided unequal length vectors (ndarrays)', function test( t ) {
111+
t.throws( badValue, RangeError, 'throws an error' );
112+
t.end();
143113

144-
for ( i = 0; i < values.length; i++ ) {
145-
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ].toString() );
114+
function badValue() {
115+
var x = array( new Float64Array( 10 ) );
116+
var y = array( new Float64Array( 100 ) );
117+
ddot( x, y );
146118
}
119+
});
120+
121+
tape( 'the function throws an error if provided unequal length vectors (array-like objects)', function test( t ) {
122+
t.throws( badValue, RangeError, 'throws an error' );
147123
t.end();
148124

149-
function badValue( value ) {
150-
var x = array( new Float64Array( 10 ) );
125+
function badValue() {
126+
var x = [ 1, 2, 3 ];
127+
var y = [ 1, 2, 3, 4, 5 ];
128+
ddot( x, y );
129+
}
130+
});
151131

152-
return function badValue() {
153-
ddot( x, value );
132+
tape( 'the function throws an error if provided ndarrays which cannot be cast to 1-dimensional ndarrays (ndarrays)', function test( t ) {
133+
t.throws( badValue, TypeError, 'throws an error' );
134+
t.end();
135+
136+
function badValue() {
137+
var opts = {
138+
'shape': [ 5, 2 ]
154139
};
140+
var x = array( new Float64Array( 10 ), opts );
141+
var y = array( new Float64Array( 10 ), opts );
142+
ddot( x, y );
155143
}
156144
});
157145

158-
tape( 'the function throws an error if provided vectors which do not have the same length', function test( t ) {
159-
t.throws( badValue, RangeError, 'throws an error' );
146+
tape( 'the function throws an error if provided array-like objects which cannot be cast to 1-dimensional ndarrays (array-like objects)', function test( t ) {
147+
t.throws( badValue, TypeError, 'throws an error' );
160148
t.end();
161149

162150
function badValue() {
163-
var x = array( new Float64Array( 10 ) );
164-
var y = array( new Float64Array( 100 ) );
151+
var x = [ [ 1, 2 ], [ 3, 4 ] ];
152+
var y = [ [ 5, 6 ], [ 7, 8 ] ];
165153
ddot( x, y );
166154
}
167155
});
168156

169-
tape( 'the function calculates the dot product of vectors `x` and `y`', function test( t ) {
157+
tape( 'the function calculates the dot product of vectors `x` and `y` (ndarrays)', function test( t ) {
170158
var dot;
171159
var x;
172160
var y;
@@ -183,7 +171,55 @@ tape( 'the function calculates the dot product of vectors `x` and `y`', function
183171
t.end();
184172
});
185173

186-
tape( 'if provided empty vectors, the function returns `0`', function test( t ) {
174+
tape( 'the function calculates the dot product of vectors `x` and `y` (array-like objects)', function test( t ) {
175+
var dot;
176+
var x;
177+
var y;
178+
179+
x = [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ];
180+
y = [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ];
181+
182+
dot = ddot( x, y );
183+
t.strictEqual( dot, -17.0, 'returns expected value' );
184+
185+
t.end();
186+
});
187+
188+
tape( 'the function calculates the dot product of vectors `x` and `y` (mixed)', function test( t ) {
189+
var dot;
190+
var x;
191+
var y;
192+
193+
x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] );
194+
y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] );
195+
196+
dot = ddot( array( x ), y );
197+
t.strictEqual( dot, -17.0, 'returns expected value' );
198+
199+
dot = ddot( x, array( y ) );
200+
t.strictEqual( dot, -17.0, 'returns expected value' );
201+
202+
t.end();
203+
});
204+
205+
tape( 'the function supports providing ndarrays whose underlying data type is not `float64`', function test( t ) {
206+
var dot;
207+
var x;
208+
var y;
209+
210+
x = new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] );
211+
y = new Int32Array( [ 2, 6, -1, -4, 8, 8, 2, -3 ] );
212+
213+
x = array( x );
214+
y = array( y );
215+
216+
dot = ddot( x, y );
217+
t.strictEqual( dot, -17.0, 'returns expected value' );
218+
219+
t.end();
220+
});
221+
222+
tape( 'if provided empty vectors, the function returns `0` (ndarrays)', function test( t ) {
187223
var dot;
188224
var x;
189225
var y;
@@ -200,7 +236,21 @@ tape( 'if provided empty vectors, the function returns `0`', function test( t )
200236
t.end();
201237
});
202238

203-
tape( 'the function supports a strided vector for the first argument', function test( t ) {
239+
tape( 'if provided empty vectors, the function returns `0` (array-like objects)', function test( t ) {
240+
var dot;
241+
var x;
242+
var y;
243+
244+
x = [];
245+
y = [];
246+
247+
dot = ddot( x, y );
248+
t.strictEqual( dot, 0.0, 'returns expected value' );
249+
250+
t.end();
251+
});
252+
253+
tape( 'the function supports a strided vector for the first argument (ndarrays)', function test( t ) {
204254
var dot;
205255
var x;
206256
var y;
@@ -227,7 +277,7 @@ tape( 'the function supports a strided vector for the first argument', function
227277
t.end();
228278
});
229279

230-
tape( 'the function supports a strided vector for the second argument', function test( t ) {
280+
tape( 'the function supports a strided vector for the second argument (ndarrays)', function test( t ) {
231281
var dot;
232282
var x;
233283
var y;
@@ -255,7 +305,7 @@ tape( 'the function supports a strided vector for the second argument', function
255305
t.end();
256306
});
257307

258-
tape( 'the function support negative strides', function test( t ) {
308+
tape( 'the function support negative strides (ndarrays)', function test( t ) {
259309
var dot;
260310
var x;
261311
var y;
@@ -282,7 +332,7 @@ tape( 'the function support negative strides', function test( t ) {
282332
t.end();
283333
});
284334

285-
tape( 'the function supports complex access patterns', function test( t ) {
335+
tape( 'the function supports complex access patterns (ndarrays)', function test( t ) {
286336
var dot;
287337
var x;
288338
var y;
@@ -309,7 +359,7 @@ tape( 'the function supports complex access patterns', function test( t ) {
309359
t.end();
310360
});
311361

312-
tape( 'the function supports strided vectors having offsets', function test( t ) {
362+
tape( 'the function supports strided vectors having offsets (ndarrays)', function test( t ) {
313363
var dot;
314364
var x;
315365
var y;
@@ -339,7 +389,7 @@ tape( 'the function supports strided vectors having offsets', function test( t )
339389
t.end();
340390
});
341391

342-
tape( 'the function supports underlying data buffers with view offsets', function test( t ) {
392+
tape( 'the function supports underlying data buffers with view offsets (ndarrays)', function test( t ) {
343393
var dot;
344394
var x0;
345395
var y0;

0 commit comments

Comments
 (0)