Skip to content

Commit 04c9cdf

Browse files
committed
feat: add ndarray/base/any
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 8da4e68 commit 04c9cdf

File tree

77 files changed

+6914
-4314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+6914
-4314
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# any
22+
23+
> Test whether at least one element in an ndarray is truthy.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var any = require( '@stdlib/ndarray/base/any' );
37+
```
38+
39+
#### any( arrays )
40+
41+
Tests whether at least one element in an ndarray is truthy.
42+
43+
<!-- eslint-disable max-len -->
44+
45+
```javascript
46+
var Float64Array = require( '@stdlib/array/float64' );
47+
48+
// Create a data buffer:
49+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
50+
51+
// Define the shape of the input array:
52+
var shape = [ 3, 1, 2 ];
53+
54+
// Define the array strides:
55+
var sx = [ 4, 4, 1 ];
56+
57+
// Define the index offset:
58+
var ox = 0;
59+
60+
// Create the input ndarray-like object:
61+
var x = {
62+
'dtype': 'float64',
63+
'data': xbuf,
64+
'shape': shape,
65+
'strides': sx,
66+
'offset': ox,
67+
'order': 'row-major'
68+
};
69+
70+
// Test elements:
71+
var out = any( [ x ] );
72+
// returns true
73+
```
74+
75+
The function accepts the following arguments:
76+
77+
- **arrays**: array-like object containing an input ndarray.
78+
79+
The provided ndarray should be an `object` with the following properties:
80+
81+
- **dtype**: data type.
82+
- **data**: data buffer.
83+
- **shape**: dimensions.
84+
- **strides**: stride lengths.
85+
- **offset**: index offset.
86+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
87+
88+
</section>
89+
90+
<!-- /.usage -->
91+
92+
<section class="notes">
93+
94+
## Notes
95+
96+
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing the operation in order to achieve better performance.
97+
- If provided an empty ndarray, the function returns `false`.
98+
99+
</section>
100+
101+
<!-- /.notes -->
102+
103+
<section class="examples">
104+
105+
## Examples
106+
107+
<!-- eslint no-undef: "error" -->
108+
109+
```javascript
110+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
111+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
112+
var any = require( '@stdlib/ndarray/base/any' );
113+
114+
var x = {
115+
'dtype': 'generic',
116+
'data': bernoulli( 10, 0.9, {
117+
'dtype': 'generic'
118+
}),
119+
'shape': [ 5, 2 ],
120+
'strides': [ 2, 1 ],
121+
'offset': 0,
122+
'order': 'row-major'
123+
};
124+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
125+
126+
var out = any( [ x ] );
127+
console.log( out );
128+
```
129+
130+
</section>
131+
132+
<!-- /.examples -->
133+
134+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
135+
136+
<section class="related">
137+
138+
</section>
139+
140+
<!-- /.related -->
141+
142+
<section class="links">
143+
144+
</section>
145+
146+
<!-- /.links -->

lib/node_modules/@stdlib/ndarray/base/every/benchmark/benchmark.1d_rowmajor.js renamed to lib/node_modules/@stdlib/ndarray/base/any/benchmark/benchmark.1d_rowmajor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
var bench = require( '@stdlib/bench' );
2424
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
26-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
26+
var zeros = require( '@stdlib/array/zeros' );
2727
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
2828
var pkg = require( './../package.json' ).name;
29-
var every = require( './../lib' );
29+
var any = require( './../lib' );
3030

3131

3232
// VARIABLES //
@@ -49,7 +49,7 @@ var order = 'row-major';
4949
function createBenchmark( len, shape, xtype ) {
5050
var x;
5151

52-
x = discreteUniform( len, 1, 100 );
52+
x = zeros( len, xtype );
5353
x = {
5454
'dtype': xtype,
5555
'data': x,
@@ -72,7 +72,7 @@ function createBenchmark( len, shape, xtype ) {
7272

7373
b.tic();
7474
for ( i = 0; i < b.iterations; i++ ) {
75-
out = every( [ x ] );
75+
out = any( [ x ] );
7676
if ( typeof out !== 'boolean' ) {
7777
b.fail( 'should return a boolean' );
7878
}

lib/node_modules/@stdlib/ndarray/base/every/benchmark/benchmark.2d_blocked_columnmajor.js renamed to lib/node_modules/@stdlib/ndarray/base/any/benchmark/benchmark.2d_blocked_columnmajor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
2626
var sqrt = require( '@stdlib/math/base/special/sqrt' );
2727
var floor = require( '@stdlib/math/base/special/floor' );
28-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var zeros = require( '@stdlib/array/zeros' );
2929
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3030
var pkg = require( './../package.json' ).name;
31-
var every = require( './../lib/2d_blocked.js' );
31+
var any = require( './../lib/2d_blocked.js' );
3232

3333

3434
// VARIABLES //
@@ -51,7 +51,7 @@ var order = 'column-major';
5151
function createBenchmark( len, shape, xtype ) {
5252
var x;
5353

54-
x = discreteUniform( len, 1, 100 );
54+
x = zeros( len, xtype );
5555
x = {
5656
'dtype': xtype,
5757
'data': x,
@@ -74,7 +74,7 @@ function createBenchmark( len, shape, xtype ) {
7474

7575
b.tic();
7676
for ( i = 0; i < b.iterations; i++ ) {
77-
out = every( x );
77+
out = any( x );
7878
if ( typeof out !== 'boolean' ) {
7979
b.fail( 'should return a boolean' );
8080
}

lib/node_modules/@stdlib/ndarray/base/every/benchmark/benchmark.2d_blocked_rowmajor.js renamed to lib/node_modules/@stdlib/ndarray/base/any/benchmark/benchmark.2d_blocked_rowmajor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
2626
var sqrt = require( '@stdlib/math/base/special/sqrt' );
2727
var floor = require( '@stdlib/math/base/special/floor' );
28-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var zeros = require( '@stdlib/array/zeros' );
2929
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3030
var pkg = require( './../package.json' ).name;
31-
var every = require( './../lib/2d_blocked.js' );
31+
var any = require( './../lib/2d_blocked.js' );
3232

3333

3434
// VARIABLES //
@@ -51,7 +51,7 @@ var order = 'row-major';
5151
function createBenchmark( len, shape, xtype ) {
5252
var x;
5353

54-
x = discreteUniform( len, 1, 100 );
54+
x = zeros( len, xtype );
5555
x = {
5656
'dtype': xtype,
5757
'data': x,
@@ -74,7 +74,7 @@ function createBenchmark( len, shape, xtype ) {
7474

7575
b.tic();
7676
for ( i = 0; i < b.iterations; i++ ) {
77-
out = every( x );
77+
out = any( x );
7878
if ( typeof out !== 'boolean' ) {
7979
b.fail( 'should return a boolean' );
8080
}

lib/node_modules/@stdlib/ndarray/base/every/benchmark/benchmark.2d_columnmajor.js renamed to lib/node_modules/@stdlib/ndarray/base/any/benchmark/benchmark.2d_columnmajor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
2626
var sqrt = require( '@stdlib/math/base/special/sqrt' );
2727
var floor = require( '@stdlib/math/base/special/floor' );
28-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var zeros = require( '@stdlib/array/zeros' );
2929
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3030
var pkg = require( './../package.json' ).name;
31-
var every = require( './../lib/2d.js' );
31+
var any = require( './../lib/2d.js' );
3232

3333

3434
// VARIABLES //
@@ -51,7 +51,7 @@ var order = 'column-major';
5151
function createBenchmark( len, shape, xtype ) {
5252
var x;
5353

54-
x = discreteUniform( len, 1, 100 );
54+
x = zeros( len, xtype );
5555
x = {
5656
'dtype': xtype,
5757
'data': x,
@@ -74,7 +74,7 @@ function createBenchmark( len, shape, xtype ) {
7474

7575
b.tic();
7676
for ( i = 0; i < b.iterations; i++ ) {
77-
out = every( x );
77+
out = any( x );
7878
if ( typeof out !== 'boolean' ) {
7979
b.fail( 'should return a boolean' );
8080
}

lib/node_modules/@stdlib/ndarray/base/every/benchmark/benchmark.2d_rowmajor.js renamed to lib/node_modules/@stdlib/ndarray/base/any/benchmark/benchmark.2d_rowmajor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
2626
var sqrt = require( '@stdlib/math/base/special/sqrt' );
2727
var floor = require( '@stdlib/math/base/special/floor' );
28-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var zeros = require( '@stdlib/array/zeros' );
2929
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3030
var pkg = require( './../package.json' ).name;
31-
var every = require( './../lib/2d.js' );
31+
var any = require( './../lib/2d.js' );
3232

3333

3434
// VARIABLES //
@@ -51,7 +51,7 @@ var order = 'row-major';
5151
function createBenchmark( len, shape, xtype ) {
5252
var x;
5353

54-
x = discreteUniform( len, 1, 100 );
54+
x = zeros( len, xtype );
5555
x = {
5656
'dtype': xtype,
5757
'data': x,
@@ -74,7 +74,7 @@ function createBenchmark( len, shape, xtype ) {
7474

7575
b.tic();
7676
for ( i = 0; i < b.iterations; i++ ) {
77-
out = every( x );
77+
out = any( x );
7878
if ( typeof out !== 'boolean' ) {
7979
b.fail( 'should return a boolean' );
8080
}

lib/node_modules/@stdlib/ndarray/base/every/benchmark/benchmark.2d_rowmajor_accessors.js renamed to lib/node_modules/@stdlib/ndarray/base/any/benchmark/benchmark.2d_rowmajor_accessors.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
2626
var sqrt = require( '@stdlib/math/base/special/sqrt' );
2727
var floor = require( '@stdlib/math/base/special/floor' );
28-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var zeros = require( '@stdlib/array/zeros' );
2929
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3030
var pkg = require( './../package.json' ).name;
31-
var every = require( './../lib/2d_accessors.js' );
31+
var any = require( './../lib/2d_accessors.js' );
3232

3333

3434
// VARIABLES //
@@ -75,7 +75,7 @@ function set( buf, idx, value ) {
7575
function createBenchmark( len, shape, xtype ) {
7676
var x;
7777

78-
x = discreteUniform( len, 1, 100 );
78+
x = zeros( len, xtype );
7979
x = {
8080
'dtype': xtype,
8181
'data': x,
@@ -100,7 +100,7 @@ function createBenchmark( len, shape, xtype ) {
100100

101101
b.tic();
102102
for ( i = 0; i < b.iterations; i++ ) {
103-
out = every( x );
103+
out = any( x );
104104
if ( typeof out !== 'boolean' ) {
105105
b.fail( 'should return a boolean' );
106106
}

lib/node_modules/@stdlib/ndarray/base/every/benchmark/benchmark.3d_blocked_columnmajor.js renamed to lib/node_modules/@stdlib/ndarray/base/any/benchmark/benchmark.3d_blocked_columnmajor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
2626
var cbrt = require( '@stdlib/math/base/special/cbrt' );
2727
var floor = require( '@stdlib/math/base/special/floor' );
28-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var zeros = require( '@stdlib/array/zeros' );
2929
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3030
var pkg = require( './../package.json' ).name;
31-
var every = require( './../lib/3d_blocked.js' );
31+
var any = require( './../lib/3d_blocked.js' );
3232

3333

3434
// VARIABLES //
@@ -51,7 +51,7 @@ var order = 'column-major';
5151
function createBenchmark( len, shape, xtype ) {
5252
var x;
5353

54-
x = discreteUniform( len, 1, 100 );
54+
x = zeros( len, xtype );
5555
x = {
5656
'dtype': xtype,
5757
'data': x,
@@ -74,7 +74,7 @@ function createBenchmark( len, shape, xtype ) {
7474

7575
b.tic();
7676
for ( i = 0; i < b.iterations; i++ ) {
77-
out = every( x );
77+
out = any( x );
7878
if ( typeof out !== 'boolean' ) {
7979
b.fail( 'should return a boolean' );
8080
}

lib/node_modules/@stdlib/ndarray/base/every/benchmark/benchmark.3d_blocked_rowmajor.js renamed to lib/node_modules/@stdlib/ndarray/base/any/benchmark/benchmark.3d_blocked_rowmajor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2525
var pow = require( '@stdlib/math/base/special/pow' );
2626
var cbrt = require( '@stdlib/math/base/special/cbrt' );
2727
var floor = require( '@stdlib/math/base/special/floor' );
28-
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var zeros = require( '@stdlib/array/zeros' );
2929
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
3030
var pkg = require( './../package.json' ).name;
31-
var every = require( './../lib/3d_blocked.js' );
31+
var any = require( './../lib/3d_blocked.js' );
3232

3333

3434
// VARIABLES //
@@ -51,7 +51,7 @@ var order = 'row-major';
5151
function createBenchmark( len, shape, xtype ) {
5252
var x;
5353

54-
x = discreteUniform( len, 1, 100 );
54+
x = zeros( len, xtype );
5555
x = {
5656
'dtype': xtype,
5757
'data': x,
@@ -74,7 +74,7 @@ function createBenchmark( len, shape, xtype ) {
7474

7575
b.tic();
7676
for ( i = 0; i < b.iterations; i++ ) {
77-
out = every( x );
77+
out = any( x );
7878
if ( typeof out !== 'boolean' ) {
7979
b.fail( 'should return a boolean' );
8080
}

0 commit comments

Comments
 (0)