Skip to content

Commit f5ee96c

Browse files
authored
feat: add boolean dtype support to strided/base/mskunary-addon-dispatch
PR-URL: #2523 Ref: #2500 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 867c4e2 commit f5ee96c

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 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 //
@@ -168,13 +170,17 @@ function dispatch( addon, fallback ) {
168170
viewX = reinterpretComplex64( x, 0 );
169171
} else if ( dtypeX === COMPLEX128 ) {
170172
viewX = reinterpretComplex128( x, 0 );
173+
} else if ( dtypeX === BOOLEAN ) {
174+
viewX = reinterpretBoolean( x, 0 );
171175
} else {
172176
viewX = x;
173177
}
174178
if ( dtypeY === COMPLEX64 ) {
175179
viewY = reinterpretComplex64( y, 0 );
176180
} else if ( dtypeY === COMPLEX128 ) {
177181
viewY = reinterpretComplex128( y, 0 );
182+
} else if ( dtypeY === BOOLEAN ) {
183+
viewY = reinterpretBoolean( y, 0 );
178184
} else {
179185
viewY = y;
180186
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 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 //
@@ -196,13 +198,17 @@ function dispatch( addon, fallback ) {
196198
viewX = reinterpretComplex64( x, offsetX );
197199
} else if ( dtypeX === COMPLEX128 ) {
198200
viewX = reinterpretComplex128( x, offsetX );
201+
} else if ( dtypeX === BOOLEAN ) {
202+
viewX = reinterpretBoolean( x, offsetX );
199203
} else {
200204
viewX = offsetView( x, offsetX );
201205
}
202206
if ( dtypeY === COMPLEX64 ) {
203207
viewY = reinterpretComplex64( y, offsetY );
204208
} else if ( dtypeY === COMPLEX128 ) {
205209
viewY = reinterpretComplex128( y, offsetY );
210+
} else if ( dtypeY === BOOLEAN ) {
211+
viewY = reinterpretBoolean( y, offsetY );
206212
} else {
207213
viewY = offsetView( y, offsetY );
208214
}

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

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 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.
@@ -26,6 +26,7 @@ var Float64Array = require( '@stdlib/array/float64' );
2626
var Uint8Array = require( '@stdlib/array/uint8' );
2727
var Complex64Array = require( '@stdlib/array/complex64' );
2828
var Complex128Array = require( '@stdlib/array/complex128' );
29+
var BooleanArray = require( '@stdlib/array/bool' );
2930
var isFloat32Array = require( '@stdlib/assert/is-float32array' );
3031
var isFloat64Array = require( '@stdlib/assert/is-float64array' );
3132
var isUint8Array = require( '@stdlib/assert/is-uint8array' );
@@ -136,6 +137,43 @@ tape( 'the function returns a function which dispatches to an addon function whe
136137
}
137138
});
138139

140+
tape( 'the function supports boolean arrays (bool)', function test( t ) {
141+
var f;
142+
var x;
143+
var y;
144+
var m;
145+
146+
f = dispatch( addon, fallback );
147+
148+
x = new BooleanArray( 2 );
149+
y = new BooleanArray( x.length );
150+
m = new Uint8Array( x.length );
151+
152+
f( x.length, 'bool', x, 1, 'uint8', m, 1, 'bool', y, 1 );
153+
154+
t.end();
155+
156+
function addon( N, dx, ax, sx, dm, am, sm, dy, ay, sy ) {
157+
t.ok( true, 'called addon' );
158+
t.strictEqual( N, x.length, 'returns expected value' );
159+
t.strictEqual( dx, resolve( 'bool' ), 'returns expected value' );
160+
t.strictEqual( isUint8Array( ax ), true, 'returns expected value' );
161+
t.strictEqual( ax.buffer, x.buffer, 'returns expected value' );
162+
t.strictEqual( sx, 1, 'returns expected value' );
163+
t.strictEqual( dm, resolve( 'uint8' ), 'returns expected value' );
164+
t.strictEqual( isUint8Array( am ), true, 'returns expected value' );
165+
t.strictEqual( sm, 1, 'returns expected value' );
166+
t.strictEqual( dy, resolve( 'bool' ), 'returns expected value' );
167+
t.strictEqual( isUint8Array( ay ), true, 'returns expected value' );
168+
t.strictEqual( ay.buffer, y.buffer, 'returns expected value' );
169+
t.strictEqual( sy, 1, 'returns expected value' );
170+
}
171+
172+
function fallback() {
173+
t.ok( false, 'called fallback' );
174+
}
175+
});
176+
139177
tape( 'the function supports complex number typed arrays (complex64)', function test( t ) {
140178
var f;
141179
var x;

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

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 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 Float64Array = require( '@stdlib/array/float64' );
2828
var Uint8Array = require( '@stdlib/array/uint8' );
2929
var Complex64Array = require( '@stdlib/array/complex64' );
3030
var Complex128Array = require( '@stdlib/array/complex128' );
31+
var BooleanArray = require( '@stdlib/array/bool' );
3132
var isFloat32Array = require( '@stdlib/assert/is-float32array' );
3233
var isFloat64Array = require( '@stdlib/assert/is-float64array' );
3334
var isUint8Array = require( '@stdlib/assert/is-uint8array' );
@@ -258,6 +259,44 @@ tape( 'the function returns a function which dispatches to an addon function whe
258259
}
259260
});
260261

262+
tape( 'the function supports boolean arrays (bool)', function test( t ) {
263+
var f;
264+
var x;
265+
var y;
266+
var m;
267+
268+
f = dispatch( addon, fallback );
269+
270+
x = new BooleanArray( 2 );
271+
y = new BooleanArray( x.length );
272+
m = new Uint8Array( x.length );
273+
274+
f( x.length, 'bool', x, 1, 0, 'uint8', m, 1, 0, 'bool', y, 1, 0 );
275+
276+
t.end();
277+
278+
function addon( N, dx, ax, sx, dm, am, sm, dy, ay, sy ) {
279+
t.ok( true, 'called addon' );
280+
t.strictEqual( N, x.length, 'returns expected value' );
281+
t.strictEqual( dx, resolve( 'bool' ), 'returns expected value' );
282+
t.strictEqual( isUint8Array( ax ), true, 'returns expected value' );
283+
t.strictEqual( ax.buffer, x.buffer, 'returns expected value' );
284+
t.strictEqual( sx, 1, 'returns expected value' );
285+
t.strictEqual( dm, resolve( 'uint8' ), 'returns expected value' );
286+
t.strictEqual( isUint8Array( am ), true, 'returns expected value' );
287+
t.strictEqual( am.buffer, m.buffer, 'returns expected value' );
288+
t.strictEqual( sm, 1, 'returns expected value' );
289+
t.strictEqual( dy, resolve( 'bool' ), 'returns expected value' );
290+
t.strictEqual( isUint8Array( ay ), true, 'returns expected value' );
291+
t.strictEqual( ay.buffer, y.buffer, 'returns expected value' );
292+
t.strictEqual( sy, 1, 'returns expected value' );
293+
}
294+
295+
function fallback() {
296+
t.ok( false, 'called fallback' );
297+
}
298+
});
299+
261300
tape( 'the function supports complex number typed arrays (complex64)', function test( t ) {
262301
var f;
263302
var x;

0 commit comments

Comments
 (0)