Skip to content

Commit 8831e32

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

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

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

Lines changed: 5 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) 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.
@@ -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 //
@@ -139,6 +141,8 @@ function dispatch( addon, fallback ) {
139141
viewX = reinterpretComplex64( x, 0 );
140142
} else if ( dtypeX === COMPLEX128 ) {
141143
viewX = reinterpretComplex128( x, 0 );
144+
} else if ( dtypeX === BOOLEAN ) {
145+
viewX = reinterpretBoolean( x, 0 );
142146
} else {
143147
viewX = x;
144148
}

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

Lines changed: 5 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) 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 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 //
@@ -150,6 +152,8 @@ function dispatch( addon, fallback ) {
150152
viewX = reinterpretComplex64( x, offsetX );
151153
} else if ( dtypeX === COMPLEX128 ) {
152154
viewX = reinterpretComplex128( x, offsetX );
155+
} else if ( dtypeX === BOOLEAN ) {
156+
viewX = reinterpretBoolean( x, offsetX );
153157
} else {
154158
viewX = offsetView( x, offsetX );
155159
}

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

Lines changed: 28 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) 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.
@@ -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

@@ -123,6 +125,31 @@ tape( 'the function returns a function which dispatches to an addon function whe
123125
}
124126
});
125127

128+
tape( 'the function supports boolean arrays (bool)', function test( t ) {
129+
var f;
130+
var x;
131+
132+
f = dispatch( addon, fallback );
133+
134+
x = new BooleanArray( 2 );
135+
f( x.length, 'bool', x, 1 );
136+
137+
t.end();
138+
139+
function addon( N, dx, ax, sx ) {
140+
t.ok( true, 'called addon' );
141+
t.strictEqual( N, x.length, 'returns expected value' );
142+
t.strictEqual( dx, resolve( 'bool' ), 'returns expected value' );
143+
t.strictEqual( isUint8Array( ax ), true, 'returns expected value' );
144+
t.strictEqual( ax.buffer, x.buffer, 'returns expected value' );
145+
t.strictEqual( sx, 1, 'returns expected value' );
146+
}
147+
148+
function fallback() {
149+
t.ok( false, 'called fallback' );
150+
}
151+
});
152+
126153
tape( 'the function supports complex number typed arrays (complex64)', function test( t ) {
127154
var f;
128155
var x;

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

Lines changed: 28 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) 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.
@@ -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

@@ -159,6 +161,31 @@ tape( 'the function returns a function which dispatches to an addon function whe
159161
}
160162
});
161163

164+
tape( 'the function supports boolean arrays (bool)', function test( t ) {
165+
var f;
166+
var x;
167+
168+
f = dispatch( addon, fallback );
169+
170+
x = new BooleanArray( 2 );
171+
f( x.length, 'bool', x, 1, 0 );
172+
173+
t.end();
174+
175+
function addon( N, dx, ax, sx ) {
176+
t.ok( true, 'called addon' );
177+
t.strictEqual( N, x.length, 'returns expected value' );
178+
t.strictEqual( dx, resolve( 'bool' ), 'returns expected value' );
179+
t.strictEqual( isUint8Array( ax ), true, 'returns expected value' );
180+
t.strictEqual( ax.buffer, x.buffer, 'returns expected value' );
181+
t.strictEqual( sx, 1, 'returns expected value' );
182+
}
183+
184+
function fallback() {
185+
t.ok( false, 'called fallback' );
186+
}
187+
});
188+
162189
tape( 'the function supports complex number typed arrays (complex64)', function test( t ) {
163190
var f;
164191
var x;

0 commit comments

Comments
 (0)