Skip to content

Commit 867c4e2

Browse files
authored
feat: add boolean dtype support to strided/base/unary-addon-dispatch
PR-URL: #2522 Ref: #2500 Reviewed-by: Athan Reines <[email protected]>
1 parent 8831e32 commit 867c4e2

File tree

4 files changed

+84
-4
lines changed

4 files changed

+84
-4
lines changed

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

Lines changed: 7 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,13 +25,15 @@ var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' );
2525
var resolve = require( '@stdlib/strided/base/dtype-resolve-enum' );
2626
var reinterpretComplex64 = require( '@stdlib/strided/base/reinterpret-complex64' );
2727
var reinterpretComplex128 = require( '@stdlib/strided/base/reinterpret-complex128' );
28+
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
2829
var format = require( '@stdlib/string/format' );
2930

3031

3132
// VARIABLES //
3233

3334
var COMPLEX64 = resolve( 'complex64' );
3435
var COMPLEX128 = resolve( 'complex128' );
36+
var BOOLEAN = resolve( 'bool' );
3537

3638

3739
// MAIN //
@@ -153,13 +155,17 @@ function dispatch( addon, fallback ) {
153155
viewX = reinterpretComplex64( x, 0 );
154156
} else if ( dtypeX === COMPLEX128 ) {
155157
viewX = reinterpretComplex128( x, 0 );
158+
} else if ( dtypeX === BOOLEAN ) {
159+
viewX = reinterpretBoolean( x, 0 );
156160
} else {
157161
viewX = x;
158162
}
159163
if ( dtypeY === COMPLEX64 ) {
160164
viewY = reinterpretComplex64( y, 0 );
161165
} else if ( dtypeY === COMPLEX128 ) {
162166
viewY = reinterpretComplex128( y, 0 );
167+
} else if ( dtypeY === BOOLEAN ) {
168+
viewY = reinterpretBoolean( y, 0 );
163169
} else {
164170
viewY = y;
165171
}

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

Lines changed: 7 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.
@@ -26,6 +26,7 @@ var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).is
2626
var resolve = require( '@stdlib/strided/base/dtype-resolve-enum' );
2727
var reinterpretComplex64 = require( '@stdlib/strided/base/reinterpret-complex64' );
2828
var reinterpretComplex128 = require( '@stdlib/strided/base/reinterpret-complex128' );
29+
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
2930
var offsetView = require( '@stdlib/strided/base/offset-view' );
3031
var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
3132
var format = require( '@stdlib/string/format' );
@@ -35,6 +36,7 @@ var format = require( '@stdlib/string/format' );
3536

3637
var COMPLEX64 = resolve( 'complex64' );
3738
var COMPLEX128 = resolve( 'complex128' );
39+
var BOOLEAN = resolve( 'bool' );
3840

3941

4042
// MAIN //
@@ -172,13 +174,17 @@ function dispatch( addon, fallback ) {
172174
viewX = reinterpretComplex64( x, offsetX );
173175
} else if ( dtypeX === COMPLEX128 ) {
174176
viewX = reinterpretComplex128( x, offsetX );
177+
} else if ( dtypeX === BOOLEAN ) {
178+
viewX = reinterpretBoolean( x, offsetX );
175179
} else {
176180
viewX = offsetView( x, offsetX );
177181
}
178182
if ( dtypeY === COMPLEX64 ) {
179183
viewY = reinterpretComplex64( y, offsetY );
180184
} else if ( dtypeY === COMPLEX128 ) {
181185
viewY = reinterpretComplex128( y, offsetY );
186+
} else if ( dtypeY === BOOLEAN ) {
187+
viewY = reinterpretBoolean( y, offsetY );
182188
} else {
183189
viewY = offsetView( y, offsetY );
184190
}

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

Lines changed: 35 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

@@ -129,6 +131,38 @@ tape( 'the function returns a function which dispatches to an addon function whe
129131
}
130132
});
131133

134+
tape( 'the function supports boolean arrays (bool)', function test( t ) {
135+
var f;
136+
var x;
137+
var y;
138+
139+
f = dispatch( addon, fallback );
140+
141+
x = new BooleanArray( 2 );
142+
y = new BooleanArray( x.length );
143+
144+
f( x.length, 'bool', x, 1, 'bool', y, 1 );
145+
146+
t.end();
147+
148+
function addon( N, dx, ax, sx, dy, ay, sy ) {
149+
t.ok( true, 'called addon' );
150+
t.strictEqual( N, x.length, 'returns expected value' );
151+
t.strictEqual( dx, resolve( 'bool' ), 'returns expected value' );
152+
t.strictEqual( isUint8Array( ax ), true, 'returns expected value' );
153+
t.strictEqual( ax.buffer, x.buffer, 'returns expected value' );
154+
t.strictEqual( sx, 1, 'returns expected value' );
155+
t.strictEqual( dy, resolve( 'bool' ), 'returns expected value' );
156+
t.strictEqual( isUint8Array( ay ), true, 'returns expected value' );
157+
t.strictEqual( ay.buffer, y.buffer, 'returns expected value' );
158+
t.strictEqual( sy, 1, 'returns expected value' );
159+
}
160+
161+
function fallback() {
162+
t.ok( false, 'called fallback' );
163+
}
164+
});
165+
132166
tape( 'the function supports complex number typed arrays (complex64)', function test( t ) {
133167
var f;
134168
var x;

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

Lines changed: 35 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/ndarray.js' );
3234

@@ -205,6 +207,38 @@ tape( 'the function returns a function which dispatches to an addon function whe
205207
}
206208
});
207209

210+
tape( 'the function supports boolean arrays (bool)', function test( t ) {
211+
var f;
212+
var x;
213+
var y;
214+
215+
f = dispatch( addon, fallback );
216+
217+
x = new BooleanArray( 2 );
218+
y = new BooleanArray( x.length );
219+
220+
f( x.length, 'bool', x, 1, 0, 'bool', y, 1, 0 );
221+
222+
t.end();
223+
224+
function addon( N, dx, ax, sx, dy, ay, sy ) {
225+
t.ok( true, 'called addon' );
226+
t.strictEqual( N, x.length, 'returns expected value' );
227+
t.strictEqual( dx, resolve( 'bool' ), 'returns expected value' );
228+
t.strictEqual( isUint8Array( ax ), true, 'returns expected value' );
229+
t.strictEqual( ax.buffer, x.buffer, 'returns expected value' );
230+
t.strictEqual( sx, 1, 'returns expected value' );
231+
t.strictEqual( dy, resolve( 'bool' ), 'returns expected value' );
232+
t.strictEqual( isUint8Array( ay ), true, 'returns expected value' );
233+
t.strictEqual( ay.buffer, y.buffer, 'returns expected value' );
234+
t.strictEqual( sy, 1, 'returns expected value' );
235+
}
236+
237+
function fallback() {
238+
t.ok( false, 'called fallback' );
239+
}
240+
});
241+
208242
tape( 'the function supports complex number typed arrays (complex64)', function test( t ) {
209243
var f;
210244
var x;

0 commit comments

Comments
 (0)