Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/cunone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# cunone

> Cumulatively test whether every element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions is falsy.

<section class="usage">

## Usage

```javascript
var cunone = require( '@stdlib/blas/ext/cunone' );
```

#### cunone( x\[, options] )

Cumulatively tests whether every element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions is falsy.

```javascript
var array = require( '@stdlib/ndarray/array' );

var x = array( [ 0.0, 0.0, 1.0, 0.0 ] );

var y = cunone( x );
// returns <ndarray>[ true, true, false, false ]
```

The function has the following parameters:

- **x**: input [ndarray][@stdlib/ndarray/ctor].
- **options**: function options (_optional_).

The function accepts the following options:

- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor].
- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a boolean or "generic" [data type][@stdlib/ndarray/dtypes].

By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option.

```javascript
var array = require( '@stdlib/ndarray/array' );

var x = array( [ 0.0, 0.0, 1.0, 0.0 ], {
'shape': [ 2, 2 ],
'order': 'row-major'
});

var y = cunone( x, {
'dims': [ 0 ]
});
// returns <ndarray>[ [ true, true ], [ false, true ] ]

y = cunone( x, {
'dims': [ 1 ]
});
// returns <ndarray>[ [ true, true ], [ false, false ] ]

y = cunone( x, {
'dims': [ 0, 1 ]
});
// returns <ndarray>[ [ true, true ], [ false, false ] ]
```

By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option.

```javascript
var getDType = require( '@stdlib/ndarray/dtype' );
var array = require( '@stdlib/ndarray/array' );

var x = array( [ 0.0, 0.0, 1.0, 0.0 ] );

var y = cunone( x, {
'dtype': 'generic'
});
// returns <ndarray>

var dt = String( getDType( y ) );
// returns 'generic'
```

#### cunone.assign( x, out\[, options] )

Cumulatively tests whether every element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions is falsy and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor].

```javascript
var array = require( '@stdlib/ndarray/array' );
var falses = require( '@stdlib/ndarray/falses' );

var x = array( [ 0.0, 0.0, 1.0, 0.0 ] );
var y = falses( [ 4 ] );

var out = cunone.assign( x, y );
// returns <ndarray>[ true, true, false, false ]

var bool = ( out === y );
// returns true
```

The method has the following parameters:

- **x**: input [ndarray][@stdlib/ndarray/ctor].
- **out**: output [ndarray][@stdlib/ndarray/ctor].
- **options**: function options (_optional_).

The method accepts the following options:

- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor].

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Both functions iterate over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before performing the operation.
- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having a boolean or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes].
- Both functions explicitly treat `NaN` values as falsy.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var bernoulli = require( '@stdlib/random/bernoulli' );
var getDType = require( '@stdlib/ndarray/dtype' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var cunone = require( '@stdlib/blas/ext/cunone' );

// Generate an ndarray of random numbers:
var x = bernoulli( [ 5, 5 ], 0.3, {
'dtype': 'generic'
});
console.log( ndarray2array( x ) );

// Perform operation:
var y = cunone( x, {
'dims': [ 0 ]
});

// Resolve the output array data type:
var dt = getDType( y );
console.log( dt );

// Print the results:
console.log( ndarray2array( y ) );
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor

[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes

[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies

</section>

<!-- /.links -->
111 changes: 111 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/cunone/benchmark/benchmark.assign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pow = require( '@stdlib/math/base/special/pow' );
var falsesLike = require( '@stdlib/ndarray/falses-like' );
var zeros = require( '@stdlib/ndarray/zeros' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var cunone = require( './../lib' );

Check warning on line 30 in lib/node_modules/@stdlib/blas/ext/cunone/benchmark/benchmark.assign.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

only the `assign` property of the required module is used; require the property directly


// VARIABLES //

var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var out;
var x;

x = zeros( [ len ], options );
out = falsesLike( x, {
'dtype': 'bool'
});

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var o;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
o = cunone.assign( x, out );
if ( typeof o !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( !isBoolean( o.get( i%len ) ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s:assign:dtype=%s,len=%d', pkg, options.dtype, len ), f );
}
}

main();
Loading