Skip to content
Merged
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
120 changes: 119 additions & 1 deletion lib/node_modules/@stdlib/ndarray/filter-map/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/* eslint-disable max-lines */

import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray';
import { typedndarray, DataType, Order, float64ndarray, float32ndarray, float16ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray';
import { Complex64, Complex128, ComplexLike } from '@stdlib/types/complex';

/**
Expand Down Expand Up @@ -139,6 +139,20 @@ interface Float32Options extends Options {
dtype?: 'float32';
}

/**
* Interface describing function options.
*/
interface Float16Options extends Options {
/**
* Output ndarray data type.
*
* ## Notes
*
* - This option overrides using the input ndarray's inferred data type.
*/
dtype?: 'float16';
}

/**
* Interface describing function options.
*/
Expand Down Expand Up @@ -355,6 +369,37 @@ declare function filterMap<V = unknown>( x: float64ndarray, fcn: Callback<number
*/
declare function filterMap<V = unknown>( x: float32ndarray, fcn: Callback<number, number, V>, thisArg?: ThisParameterType<Callback<number, number, V>> ): float32ndarray;

/**
* Filters and maps elements in an input ndarray to elements in a new output ndarray according to a callback function.
*
* @param x - input ndarray
* @param fcn - callback function
* @param thisArg - callback function execution context
* @returns output ndarray
*
* @example
* var Float16Array = require( '@stdlib/array/float16' );
* var ndarray = require( '@stdlib/ndarray/ctor' );
*
* function scale( z ) {
* if ( z > 5.0 ) {
* return z * 10.0;
* }
* }
*
* var buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
* var shape = [ 2, 3 ];
* var strides = [ 6, 1 ];
* var offset = 1;
*
* var x = ndarray( 'float16', buffer, shape, strides, offset, 'row-major' );
* // returns <ndarray>
*
* var y = filterMap( x, scale );
* // returns <ndarray>[ 80.0, 90.0, 100.0 ]
*/
declare function filterMap<V = unknown>( x: float16ndarray, fcn: Callback<number, number, V>, thisArg?: ThisParameterType<Callback<number, number, V>> ): float16ndarray;

/**
* Filters and maps elements in an input ndarray to elements in a new output ndarray according to a callback function.
*
Expand Down Expand Up @@ -767,6 +812,42 @@ declare function filterMap<V = unknown>( x: float64ndarray, options: OrderOption
*/
declare function filterMap<V = unknown>( x: float32ndarray, options: OrderOptions, fcn: Callback<number, number, V>, thisArg?: ThisParameterType<Callback<number, number, V>> ): float32ndarray;

/**
* Filters and maps elements in an input ndarray to elements in a new output ndarray according to a callback function.
*
* @param x - input ndarray
* @param options - function options
* @param options.order - iteration order
* @param fcn - callback function
* @param thisArg - callback function execution context
* @returns output ndarray
*
* @example
* var Float16Array = require( '@stdlib/array/float16' );
* var ndarray = require( '@stdlib/ndarray/ctor' );
*
* function scale( z ) {
* if ( z > 5.0 ) {
* return z * 10.0;
* }
* }
*
* var buffer = new Float16Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
* var shape = [ 2, 3 ];
* var strides = [ 6, 1 ];
* var offset = 1;
*
* var x = ndarray( 'float16', buffer, shape, strides, offset, 'row-major' );
* // returns <ndarray>
*
* var opts = {
* 'order': 'row-major'
* };
* var y = filterMap( x, opts, scale );
* // returns <ndarray>[ 80.0, 90.0, 100.0 ]
*/
declare function filterMap<V = unknown>( x: float16ndarray, options: OrderOptions, fcn: Callback<number, number, V>, thisArg?: ThisParameterType<Callback<number, number, V>> ): float16ndarray;

/**
* Filters and maps elements in an input ndarray to elements in a new output ndarray according to a callback function.
*
Expand Down Expand Up @@ -1236,6 +1317,43 @@ declare function filterMap<T = unknown, U = unknown, V = unknown>( x: typedndarr
*/
declare function filterMap<T = unknown, U = unknown, V = unknown>( x: typedndarray<T>, options: Float32Options, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): float32ndarray;

/**
* Filters and maps elements in an input ndarray to elements in a new output ndarray according to a callback function.
*
* @param x - input ndarray
* @param options - options
* @param options.dtype - output ndarray data type
* @param options.order - iteration order
* @param fcn - callback function
* @param thisArg - callback function execution context
* @returns output ndarray
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var ndarray = require( '@stdlib/ndarray/ctor' );
*
* function scale( z ) {
* if ( z > 5.0 ) {
* return z * 10.0;
* }
* }
*
* var buffer = 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 ] );
* var shape = [ 2, 3 ];
* var strides = [ 6, 1 ];
* var offset = 1;
*
* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );
* // returns <ndarray>
*
* var opts = {
* 'dtype': 'float16'
* };
* var y = filterMap( x, opts, scale );
* // returns <ndarray>[ 80.0, 90.0, 100.0 ]
*/
declare function filterMap<T = unknown, U = unknown, V = unknown>( x: typedndarray<T>, options: Float16Options, fcn: Callback<T, U, V>, thisArg?: ThisParameterType<Callback<T, U, V>> ): float16ndarray;

/**
* Filters and maps elements in an input ndarray to elements in a new output ndarray according to a callback function.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @param x - input value
* @returns result
*/
function fcn( x: any ): any {

Check warning on line 32 in lib/node_modules/@stdlib/ndarray/filter-map/docs/types/test.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type

Check warning on line 32 in lib/node_modules/@stdlib/ndarray/filter-map/docs/types/test.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type
return x;
}

Expand Down Expand Up @@ -72,6 +72,8 @@
filterMap( zeros( 'float64', sh, ord ), identity1, {} ); // $ExpectType float64ndarray
filterMap( zeros( 'float32', sh, ord ), identity1 ); // $ExpectType float32ndarray
filterMap( zeros( 'float32', sh, ord ), identity1, {} ); // $ExpectType float32ndarray
filterMap( zeros( 'float16', sh, ord ), identity1 ); // $ExpectType float16ndarray
filterMap( zeros( 'float16', sh, ord ), identity1, {} ); // $ExpectType float16ndarray
filterMap( zeros( 'complex64', sh, ord ), identity3 ); // $ExpectType complex64ndarray
filterMap( zeros( 'complex64', sh, ord ), identity3, {} ); // $ExpectType complex64ndarray
filterMap( zeros( 'complex128', sh, ord ), identity3 ); // $ExpectType complex128ndarray
Expand Down Expand Up @@ -100,6 +102,8 @@
filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, fcn, {} ); // $ExpectType float64ndarray
filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, fcn ); // $ExpectType float32ndarray
filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, fcn, {} ); // $ExpectType float32ndarray
filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'float16' }, fcn ); // $ExpectType float16ndarray
filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'float16' }, fcn, {} ); // $ExpectType float16ndarray
filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, fcn ); // $ExpectType complex64ndarray
filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, fcn, {} ); // $ExpectType complex64ndarray
filterMap( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, fcn ); // $ExpectType complex128ndarray
Expand Down Expand Up @@ -128,6 +132,8 @@
filterMap( zeros( 'float64', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType float64ndarray
filterMap( zeros( 'float32', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType float32ndarray
filterMap( zeros( 'float32', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType float32ndarray
filterMap( zeros( 'float16', sh, ord ), { 'order': ord }, identity1 ); // $ExpectType float16ndarray
filterMap( zeros( 'float16', sh, ord ), { 'order': ord }, identity1, {} ); // $ExpectType float16ndarray
filterMap( zeros( 'complex64', sh, ord ), { 'order': ord }, identity3 ); // $ExpectType complex64ndarray
filterMap( zeros( 'complex64', sh, ord ), { 'order': ord }, identity3, {} ); // $ExpectType complex64ndarray
filterMap( zeros( 'complex128', sh, ord ), { 'order': ord }, identity3 ); // $ExpectType complex128ndarray
Expand Down
24 changes: 24 additions & 0 deletions lib/node_modules/@stdlib/ndarray/filter-map/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
var strides2offset = require( '@stdlib/ndarray/base/strides2offset' );
var Float64Array = require( '@stdlib/array/float64' );
var Float32Array = require( '@stdlib/array/float32' );
var Float16Array = require( '@stdlib/array/float16' );
var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' );
var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' );
var isSameFloat16Array = require( '@stdlib/assert/is-same-float16array' );
var filterMap = require( './../lib' );


Expand Down Expand Up @@ -369,6 +371,17 @@ tape( 'the function filters and maps an array according to a callback function (
]);
t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' );

opts = {
'dtype': 'float16'
};
y = filterMap( x, opts, fcn );

expected = new Float16Array([
10.0,
30.0
]);
t.strictEqual( isSameFloat16Array( y.data, expected ), true, 'returns expected value' );

t.end();

function fcn( z ) {
Expand Down Expand Up @@ -418,6 +431,17 @@ tape( 'the function filters and maps an array according to a callback function (
]);
t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' );

opts = {
'dtype': 'float16'
};
y = filterMap( x, opts, fcn );

expected = new Float16Array([
10.0,
30.0
]);
t.strictEqual( isSameFloat16Array( y.data, expected ), true, 'returns expected value' );

t.end();

function fcn( z ) {
Expand Down