Skip to content

Commit f21f5a2

Browse files
committed
Auto-generated commit
1 parent 027e140 commit f21f5a2

2 files changed

Lines changed: 134 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ A total of 15 issues were closed in this release:
369369

370370
<details>
371371

372+
- [`48d8be1`](https://github.com/stdlib-js/stdlib/commit/48d8be17cb1fb81b2e30a0ce976391fcf622b4c3) - **test:** add tests _(by Athan Reines)_
373+
- [`5bb21e7`](https://github.com/stdlib-js/stdlib/commit/5bb21e71dd19df4153a9e4e10640fa74f1fb9a0a) - **test:** add tests for when strides are transposed _(by Athan Reines)_
372374
- [`ccb3f8e`](https://github.com/stdlib-js/stdlib/commit/ccb3f8e33a29e6a09074d8bc7e54f0a6fa88a022) - **refactor:** use base assertion utility _(by Athan Reines)_
373375
- [`53de942`](https://github.com/stdlib-js/stdlib/commit/53de94256d47d502f47da4af97c0dfeb6ceb086e) - **refactor:** use base assertion utility _(by Athan Reines)_
374376
- [`b1ed7bc`](https://github.com/stdlib-js/stdlib/commit/b1ed7bc33de9d21119087820e0002a8803d97203) - **refactor:** use base assertion utility _(by Athan Reines)_

base/vind2bind/test/test.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,138 @@ tape( 'the function converts a view linear index to a linear index in an underly
248248
t.end();
249249
});
250250

251+
tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major, transposed)', function test( t ) {
252+
var strides;
253+
var offset;
254+
var order;
255+
var shape;
256+
var idx;
257+
258+
shape = [ 2, 2 ];
259+
order = 'row-major';
260+
strides = [ 1, 2 ];
261+
offset = 0;
262+
263+
idx = vind2bind( shape, strides, offset, order, 0, 'throw' );
264+
t.strictEqual( idx, 0, 'returns expected value' );
265+
266+
idx = vind2bind( shape, strides, offset, order, 1, 'throw' );
267+
t.strictEqual( idx, 2, 'returns expected value' );
268+
269+
idx = vind2bind( shape, strides, offset, order, 2, 'throw' );
270+
t.strictEqual( idx, 1, 'returns expected value' );
271+
272+
idx = vind2bind( shape, strides, offset, order, 3, 'throw' );
273+
t.strictEqual( idx, 3, 'returns expected value' );
274+
275+
t.end();
276+
});
277+
278+
tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major, transposed)', function test( t ) {
279+
var strides;
280+
var offset;
281+
var order;
282+
var shape;
283+
var idx;
284+
285+
shape = [ 2, 2 ];
286+
order = 'column-major';
287+
strides = [ 2, 1 ];
288+
offset = 0;
289+
290+
idx = vind2bind( shape, strides, offset, order, 0, 'throw' );
291+
t.strictEqual( idx, 0, 'returns expected value' );
292+
293+
idx = vind2bind( shape, strides, offset, order, 1, 'throw' );
294+
t.strictEqual( idx, 2, 'returns expected value' );
295+
296+
idx = vind2bind( shape, strides, offset, order, 2, 'throw' );
297+
t.strictEqual( idx, 1, 'returns expected value' );
298+
299+
idx = vind2bind( shape, strides, offset, order, 3, 'throw' );
300+
t.strictEqual( idx, 3, 'returns expected value' );
301+
302+
t.end();
303+
});
304+
305+
tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=row-major, permuted)', function test( t ) {
306+
var strides;
307+
var offset;
308+
var order;
309+
var shape;
310+
var idx;
311+
312+
shape = [ 2, 2, 2 ];
313+
order = 'row-major';
314+
strides = [ 1, 4, 2 ]; // normal: [ 4, 2, 1 ]
315+
offset = 0;
316+
317+
idx = vind2bind( shape, strides, offset, order, 0, 'throw' );
318+
t.strictEqual( idx, 0, 'returns expected value' );
319+
320+
idx = vind2bind( shape, strides, offset, order, 1, 'throw' );
321+
t.strictEqual( idx, 2, 'returns expected value' );
322+
323+
idx = vind2bind( shape, strides, offset, order, 2, 'throw' );
324+
t.strictEqual( idx, 4, 'returns expected value' );
325+
326+
idx = vind2bind( shape, strides, offset, order, 3, 'throw' );
327+
t.strictEqual( idx, 6, 'returns expected value' );
328+
329+
idx = vind2bind( shape, strides, offset, order, 4, 'throw' );
330+
t.strictEqual( idx, 1, 'returns expected value' );
331+
332+
idx = vind2bind( shape, strides, offset, order, 5, 'throw' );
333+
t.strictEqual( idx, 3, 'returns expected value' );
334+
335+
idx = vind2bind( shape, strides, offset, order, 6, 'throw' );
336+
t.strictEqual( idx, 5, 'returns expected value' );
337+
338+
idx = vind2bind( shape, strides, offset, order, 7, 'throw' );
339+
t.strictEqual( idx, 7, 'returns expected value' );
340+
341+
t.end();
342+
});
343+
344+
tape( 'the function converts a view linear index to a linear index in an underlying data buffer (order=column-major, permuted)', function test( t ) {
345+
var strides;
346+
var offset;
347+
var order;
348+
var shape;
349+
var idx;
350+
351+
shape = [ 2, 2, 2 ];
352+
order = 'column-major';
353+
strides = [ 2, 4, 1 ]; // normal: [ 1, 2, 4 ]
354+
offset = 0;
355+
356+
idx = vind2bind( shape, strides, offset, order, 0, 'throw' );
357+
t.strictEqual( idx, 0, 'returns expected value' );
358+
359+
idx = vind2bind( shape, strides, offset, order, 1, 'throw' );
360+
t.strictEqual( idx, 2, 'returns expected value' );
361+
362+
idx = vind2bind( shape, strides, offset, order, 2, 'throw' );
363+
t.strictEqual( idx, 4, 'returns expected value' );
364+
365+
idx = vind2bind( shape, strides, offset, order, 3, 'throw' );
366+
t.strictEqual( idx, 6, 'returns expected value' );
367+
368+
idx = vind2bind( shape, strides, offset, order, 4, 'throw' );
369+
t.strictEqual( idx, 1, 'returns expected value' );
370+
371+
idx = vind2bind( shape, strides, offset, order, 5, 'throw' );
372+
t.strictEqual( idx, 3, 'returns expected value' );
373+
374+
idx = vind2bind( shape, strides, offset, order, 6, 'throw' );
375+
t.strictEqual( idx, 5, 'returns expected value' );
376+
377+
idx = vind2bind( shape, strides, offset, order, 7, 'throw' );
378+
t.strictEqual( idx, 7, 'returns expected value' );
379+
380+
t.end();
381+
});
382+
251383
tape( 'if the `mode` is `throw`, the function throws if provided a linear index which exceeds array dimensions (order=row-major)', function test( t ) {
252384
var strides;
253385
var offset;

0 commit comments

Comments
 (0)