Skip to content

Commit 082d2e9

Browse files
authored
feat: add boolean dtype support to strided/base/binary-addon-dispatch
PR-URL: #2526 Ref: #2500 Reviewed-by: Athan Reines <[email protected]>
1 parent 599f5e4 commit 082d2e9

File tree

4 files changed

+100
-4
lines changed

4 files changed

+100
-4
lines changed

lib/node_modules/@stdlib/strided/base/binary-addon-dispatch/lib/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2021 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -27,13 +27,15 @@ var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' );
2727
var resolve = require( '@stdlib/strided/base/dtype-resolve-enum' );
2828
var reinterpretComplex64 = require( '@stdlib/strided/base/reinterpret-complex64' );
2929
var reinterpretComplex128 = require( '@stdlib/strided/base/reinterpret-complex128' );
30+
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
3031
var format = require( '@stdlib/string/format' );
3132

3233

3334
// VARIABLES //
3435

3536
var COMPLEX64 = resolve( 'complex64' );
3637
var COMPLEX128 = resolve( 'complex128' );
38+
var BOOLEAN = resolve( 'bool' );
3739

3840

3941
// MAIN //
@@ -173,20 +175,26 @@ function dispatch( addon, fallback ) {
173175
viewX = reinterpretComplex64( x, 0 );
174176
} else if ( dtypeX === COMPLEX128 ) {
175177
viewX = reinterpretComplex128( x, 0 );
178+
} else if ( dtypeX === BOOLEAN ) {
179+
viewX = reinterpretBoolean( x, 0 );
176180
} else {
177181
viewX = x;
178182
}
179183
if ( dtypeY === COMPLEX64 ) {
180184
viewY = reinterpretComplex64( y, 0 );
181185
} else if ( dtypeY === COMPLEX128 ) {
182186
viewY = reinterpretComplex128( y, 0 );
187+
} else if ( dtypeY === BOOLEAN ) {
188+
viewY = reinterpretBoolean( y, 0 );
183189
} else {
184190
viewY = y;
185191
}
186192
if ( dtypeZ === COMPLEX64 ) {
187193
viewZ = reinterpretComplex64( z, 0 );
188194
} else if ( dtypeZ === COMPLEX128 ) {
189195
viewZ = reinterpretComplex128( z, 0 );
196+
} else if ( dtypeZ === BOOLEAN ) {
197+
viewZ = reinterpretBoolean( z, 0 );
190198
} else {
191199
viewZ = z;
192200
}

lib/node_modules/@stdlib/strided/base/binary-addon-dispatch/lib/ndarray.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2021 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).is
2828
var resolve = require( '@stdlib/strided/base/dtype-resolve-enum' );
2929
var reinterpretComplex64 = require( '@stdlib/strided/base/reinterpret-complex64' );
3030
var reinterpretComplex128 = require( '@stdlib/strided/base/reinterpret-complex128' );
31+
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
3132
var offsetView = require( '@stdlib/strided/base/offset-view' );
3233
var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
3334
var format = require( '@stdlib/string/format' );
@@ -37,6 +38,7 @@ var format = require( '@stdlib/string/format' );
3738

3839
var COMPLEX64 = resolve( 'complex64' );
3940
var COMPLEX128 = resolve( 'complex128' );
41+
var BOOLEAN = resolve( 'bool' );
4042

4143

4244
// MAIN //
@@ -200,20 +202,26 @@ function dispatch( addon, fallback ) {
200202
viewX = reinterpretComplex64( x, offsetX );
201203
} else if ( dtypeX === COMPLEX128 ) {
202204
viewX = reinterpretComplex128( x, offsetX );
205+
} else if ( dtypeX === BOOLEAN ) {
206+
viewX = reinterpretBoolean( x, offsetX );
203207
} else {
204208
viewX = offsetView( x, offsetX );
205209
}
206210
if ( dtypeY === COMPLEX64 ) {
207211
viewY = reinterpretComplex64( y, offsetY );
208212
} else if ( dtypeY === COMPLEX128 ) {
209213
viewY = reinterpretComplex128( y, offsetY );
214+
} else if ( dtypeY === BOOLEAN ) {
215+
viewY = reinterpretBoolean( y, offsetY );
210216
} else {
211217
viewY = offsetView( y, offsetY );
212218
}
213219
if ( dtypeZ === COMPLEX64 ) {
214220
viewZ = reinterpretComplex64( z, offsetZ );
215221
} else if ( dtypeZ === COMPLEX128 ) {
216222
viewZ = reinterpretComplex128( z, offsetZ );
223+
} else if ( dtypeZ === BOOLEAN ) {
224+
viewZ = reinterpretBoolean( z, offsetZ );
217225
} else {
218226
viewZ = offsetView( z, offsetZ );
219227
}

lib/node_modules/@stdlib/strided/base/binary-addon-dispatch/test/test.main.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2021 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -25,8 +25,10 @@ var noop = require( '@stdlib/utils/noop' );
2525
var Float64Array = require( '@stdlib/array/float64' );
2626
var Complex64Array = require( '@stdlib/array/complex64' );
2727
var Complex128Array = require( '@stdlib/array/complex128' );
28+
var BooleanArray = require( '@stdlib/array/bool' );
2829
var isFloat32Array = require( '@stdlib/assert/is-float32array' );
2930
var isFloat64Array = require( '@stdlib/assert/is-float64array' );
31+
var isUint8Array = require( '@stdlib/assert/is-uint8array' );
3032
var resolve = require( '@stdlib/strided/base/dtype-resolve-enum' );
3133
var dispatch = require( './../lib' );
3234

@@ -134,6 +136,44 @@ tape( 'the function returns a function which dispatches to an addon function whe
134136
}
135137
});
136138

139+
tape( 'the function returns a function which dispatches to an addon function when provided typed arrays (bool)', function test( t ) {
140+
var f;
141+
var x;
142+
var y;
143+
var z;
144+
145+
f = dispatch( addon, fallback );
146+
147+
x = new BooleanArray( 2 );
148+
y = new BooleanArray( x.length );
149+
z = new BooleanArray( x.length );
150+
151+
f( x.length, 'bool', x, 1, 'bool', y, 1, 'bool', z, 1 );
152+
153+
t.end();
154+
155+
function addon( N, dx, ax, sx, dy, ay, sy, dz, az, sz ) {
156+
t.ok( true, 'called addon' );
157+
t.strictEqual( N, x.length, 'returns expected value' );
158+
t.strictEqual( dx, resolve( 'bool' ), 'returns expected value' );
159+
t.strictEqual( isUint8Array( ax ), true, 'returns expected value' );
160+
t.strictEqual( ax.buffer, x.buffer, 'returns expected value' );
161+
t.strictEqual( sx, 1, 'returns expected value' );
162+
t.strictEqual( dy, resolve( 'bool' ), 'returns expected value' );
163+
t.strictEqual( isUint8Array( ay ), true, 'returns expected value' );
164+
t.strictEqual( ay.buffer, y.buffer, 'returns expected value' );
165+
t.strictEqual( sy, 1, 'returns expected value' );
166+
t.strictEqual( dz, resolve( 'bool' ), 'returns expected value' );
167+
t.strictEqual( isUint8Array( az ), true, 'returns expected value' );
168+
t.strictEqual( az.buffer, z.buffer, 'returns expected value' );
169+
t.strictEqual( sz, 1, 'returns expected value' );
170+
}
171+
172+
function fallback() {
173+
t.ok( false, 'called fallback' );
174+
}
175+
});
176+
137177
tape( 'the function returns a function which dispatches to an addon function when provided typed arrays (complex64)', function test( t ) {
138178
var f;
139179
var x;

lib/node_modules/@stdlib/strided/base/binary-addon-dispatch/test/test.ndarray.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2021 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -27,8 +27,10 @@ var noop = require( '@stdlib/utils/noop' );
2727
var Float64Array = require( '@stdlib/array/float64' );
2828
var Complex64Array = require( '@stdlib/array/complex64' );
2929
var Complex128Array = require( '@stdlib/array/complex128' );
30+
var BooleanArray = require( '@stdlib/array/bool' );
3031
var isFloat32Array = require( '@stdlib/assert/is-float32array' );
3132
var isFloat64Array = require( '@stdlib/assert/is-float64array' );
33+
var isUint8Array = require( '@stdlib/assert/is-uint8array' );
3234
var resolve = require( '@stdlib/strided/base/dtype-resolve-enum' );
3335
var dispatch = require( './../lib/ndarray.js' );
3436

@@ -256,6 +258,44 @@ tape( 'the function returns a function which dispatches to an addon function whe
256258
}
257259
});
258260

261+
tape( 'the function returns a function which dispatches to an addon function when provided typed arrays (bool)', function test( t ) {
262+
var f;
263+
var x;
264+
var y;
265+
var z;
266+
267+
f = dispatch( addon, fallback );
268+
269+
x = new BooleanArray( 2 );
270+
y = new BooleanArray( x.length );
271+
z = new BooleanArray( x.length );
272+
273+
f( x.length, 'bool', x, 1, 0, 'bool', y, 1, 0, 'bool', z, 1, 0 );
274+
275+
t.end();
276+
277+
function addon( N, dx, ax, sx, dy, ay, sy, dz, az, sz ) {
278+
t.ok( true, 'called addon' );
279+
t.strictEqual( N, x.length, 'returns expected value' );
280+
t.strictEqual( dx, resolve( 'bool' ), 'returns expected value' );
281+
t.strictEqual( isUint8Array( ax ), true, 'returns expected value' );
282+
t.strictEqual( ax.buffer, x.buffer, 'returns expected value' );
283+
t.strictEqual( sx, 1, 'returns expected value' );
284+
t.strictEqual( dy, resolve( 'bool' ), 'returns expected value' );
285+
t.strictEqual( isUint8Array( ay ), true, 'returns expected value' );
286+
t.strictEqual( ay.buffer, y.buffer, 'returns expected value' );
287+
t.strictEqual( sy, 1, 'returns expected value' );
288+
t.strictEqual( dz, resolve( 'bool' ), 'returns expected value' );
289+
t.strictEqual( isUint8Array( az ), true, 'returns expected value' );
290+
t.strictEqual( az.buffer, z.buffer, 'returns expected value' );
291+
t.strictEqual( sz, 1, 'returns expected value' );
292+
}
293+
294+
function fallback() {
295+
t.ok( false, 'called fallback' );
296+
}
297+
});
298+
259299
tape( 'the function returns a function which dispatches to an addon function when provided typed arrays (complex64)', function test( t ) {
260300
var f;
261301
var x;

0 commit comments

Comments
 (0)