From 458483fd38b7bf8aa8a967cf07f8800f9fb3aecf Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 7 Aug 2025 08:01:08 +0000 Subject: [PATCH] feat: add ndarray/base/nullary-strided1d-dispatch-factory --- .../README.md | 238 +++++++++ .../benchmark/benchmark.assign.js | 122 +++++ .../benchmark/benchmark.js | 62 +++ .../docs/repl.txt | 105 ++++ .../docs/types/index.d.ts | 242 +++++++++ .../docs/types/test.ts | 473 ++++++++++++++++++ .../examples/index.js | 76 +++ .../lib/index.js | 70 +++ .../lib/main.js | 123 +++++ .../package.json | 67 +++ .../test/test.js | 35 ++ 11 files changed, 1613 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.assign.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/README.md b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/README.md new file mode 100644 index 000000000000..f4dc76548dfd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/README.md @@ -0,0 +1,238 @@ + + +# nullaryStrided1dDispatchFactory + +> Create a function for applying a strided function to an output ndarray. + +
+ +## Usage + + + +```javascript +var nullaryStrided1dDispatchFactory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); +``` + +#### nullaryStrided1dDispatchFactory( table, odtypes, policies\[, options] ) + +Returns a function for applying a strided function to an output ndarray. + + + +```javascript +var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); + +var table = { + 'default': base +}; + +var dtypes = [ 'float64', 'float32', 'generic' ]; +var policies = { + 'output': 'same' +}; + +var nullary = nullaryStrided1dDispatchFactory( table, [ dtypes ], policies ); +``` + +The function has the following parameters: + +- **table**: strided function dispatch table. Must have the following properties: + + - **default**: default strided function which should be invoked when provided ndarrays have data types which do not have a corresponding specialized implementation. + + A dispatch table may have the following additional properties: + + - **types**: one-dimensional list of ndarray data types describing specialized output ndarray argument signatures. Only the output ndarray argument data types should be specified. Additional ndarray argument data types should be omitted and are not considered during dispatch. The length of `types` must equal the number of strided functions specified by `fcns`. + - **fcns**: list of strided functions which are specific to specialized output ndarray argument signatures. + +- **odtypes**: list containing lists of supported output data types for each input ndarray argument. + +- **policies**: dispatch policies. Must have the following properties: + + - **output**: output data type [policy][@stdlib/ndarray/output-dtype-policies]. + +- **options**: function options (_optional_). + +The function supports the following options: + +- **strictTraversalOrder**: boolean specifying whether the order of element traversal must match the memory layout order of an input ndarray. Default: `false`. + +#### unary.assign( x\[, ...args]\[, options] ) + +Applies a strided function and assigns results to a provided output ndarray. + + + +```javascript +var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var odt = dtypes( 'real_and_generic' ); +var policies = { + 'output': 'same' +}; + +var table = { + 'default': base +}; +var nullary = nullaryStrided1dDispatchFactory( table, [ odt ], policies ); + +var xbuf = [ -1.0, 2.0, -3.0 ]; +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + +var o = scalar2ndarray( 1.0, { + 'dtype': 'generic' +}); + +var out = nullary.assign( x, o ); +// returns + +var arr = ndarray2array( out ); +// returns [ -3.0, -1.0, 2.0 ] + +var bool = ( out === x ); +// returns true +``` + +The method has the following parameters: + +- **x**: output ndarray. +- **args**: additional output ndarray arguments (_optional_). +- **options**: function options (_optional_). + +The method accepts the following options: + +- **dims**: list of dimensions over which to perform operation. + +
+ + + +
+ +## Notes + +- A strided function should have the following signature: + + ```text + f( arrays ) + ``` + + where + + - **arrays**: array containing an output ndarray, followed by any additional ndarray arguments. + +- The output data type policy only applies to the function returned by the main function. For the `assign` method, the output ndarray is allowed to have any supported output data type. + +
+ + + +
+ +## Examples + + + + + +```javascript +var dsorthp = require( '@stdlib/blas/ext/base/ndarray/dsorthp' ); +var ssorthp = require( '@stdlib/blas/ext/base/ndarray/ssorthp' ); +var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var nullaryStrided1dDispatchFactory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); + +// Define the supported output data types: +var odt = dtypes( 'all' ); + +// Define dispatch policies: +var policies = { + 'output': 'same' +}; + +// Define a dispatch table: +var table = { + 'types': [ + 'float64', + 'float32' + ], + 'fcns': [ + dsorthp, + ssorthp + ], + 'default': base +}; + +// Create an interface for performing an operation: +var sorthp = nullaryStrided1dDispatchFactory( table, [ odt ], policies ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, -10, 10, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var o = scalar2ndarray( 1.0, { + 'dtype': 'generic' +}); + +// Perform operation: +sorthp.assign( x, o, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( x ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..a295be37513f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.assign.js @@ -0,0 +1,122 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var dtypes = require( '@stdlib/array/dtypes' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gsorthp = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var policies; + var nullary; + var table; + var dt; + var x; + var o; + + table = { + 'default': gsorthp + }; + dt = dtypes( 'all' ); + policies = { + 'output': 'same' + }; + nullary = factory( table, [ dt ], policies ); + + x = uniform( len, -50.0, 50.0, { + 'dtype': 'float64' + }); + x = new ndarray( 'float64', x, [ len ], [ 1 ], 0, 'row-major' ); + o = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + + 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 = nullary.assign( x, o ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( isnan( o.get( i%len ) ) ) { + b.fail( 'should not return NaN' ); + } + 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( pkg+':assign:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.js new file mode 100644 index 000000000000..84a6df88a61e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/benchmark/benchmark.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 gsorthp = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var pkg = require( './../package.json' ).name; +var factory = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::factory', function benchmark( b ) { + var policies; + var dtypes; + var table; + var v; + var i; + + table = { + 'default': gsorthp + }; + dtypes = [ + 'float64', + 'float32' + ]; + policies = { + 'output': 'same' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = factory( table, [ dtypes ], policies ); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + } + b.toc(); + if ( typeof v !== 'function' ) { + b.fail( 'should return a function' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt new file mode 100644 index 000000000000..46a8428c02e3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/repl.txt @@ -0,0 +1,105 @@ + +{{alias}}( table, odtypes, policies[, options] ) + Returns function for applying a strided function to an output ndarray. + + Parameters + ---------- + table: Object + Dispatch table containing strided functions. The table object must have + the following property: + + - default: default strided function to invoke when provided ndarrays + have data types which do not have a corresponding specialized + implementation. + + The table may having the following additional properties: + + - types: one-dimensional list of ndarray data types describing + specialized output ndarray argument signatures. + - fcns: list of strided functions which are specific to specialized + output ndarray argument signatures. + + A strided function should have the following signature: + + f( arrays ) + + where + + - arrays: array containing an output ndarray, followed by any additional + ndarray arguments. + + odtypes: Array> + List containing lists of supported output array data types for each + output ndarray argument. + + policies: Object + Dispatch policies. Must have the following properties: + + - output: output data type policy. + + options: Object (optional) + Function options. + + options.strictTraversalOrder: boolean (optional) + Boolean specifying whether the order of element traversal must match the + memory layout order of an output ndarray. + + Returns + ------- + fcn: Function + Function for applying a strided function to ndarrays. + + Examples + -------- + > var dt = [ 'float64', 'float32', 'generic' ]; + > var p = { 'output': 'same' }; + > var t = { 'default': {{alias:@stdlib/blas/ext/base/ndarray/gsorthp}} }; + > var f = {{alias}}( t, [ dt ], p ); + +fcn.assign( x[, ...args][, options] ) + Applies a strided function and assign results to a provided output ndarray. + + Parameters + ---------- + x: ndarray + Input array. + + args: ...ndarray (optional) + Additional ndarray arguments. + + options: Object (optional) + Function options. + + options.dims: Array (optional) + List of dimensions over which to perform operation. If not provided, the + function performs the operation over all elements in a provided output + ndarray. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var dts = [ 'float64', 'float32', 'generic' ]; + > var p = { 'output': 'same' }; + > var t = { 'default': {{alias:@stdlib/blas/ext/base/ndarray/gsorthp}} }; + > var f = {{alias}}( t, [ dts ], p ); + > var buf = [ -1.0, 2.0, -3.0, -4.0 ]; + > var dt = 'generic'; + > var sh = [ buf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, buf, sh, sx, ox, ord ); + > var o = {{alias:@stdlib/ndarray/from-scalar}}( 1.0 ); + > var out = f.assign( x, o ) + + > var bool = ( out === x ) + true + > {{alias:@stdlib/ndarray/to-array}}( x ) + [ -4.0, -3.0, -1.0, 2.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts new file mode 100644 index 000000000000..6d1c72e61690 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/index.d.ts @@ -0,0 +1,242 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { OutputPolicy, DataType, typedndarray } from '@stdlib/types/ndarray'; + +/** +* Input array. +*/ +type InputArray = typedndarray; + +/** +* Output array. +*/ +type OutputArray = typedndarray; + +/** +* Interface defining "base" options. +*/ +interface BaseOptions { + /** + * List of dimensions over which to perform an operation. + */ + dims?: ArrayLike; +} + +/** +* Interface defining factory options. +*/ +interface FactoryOptions { + /** + * Boolean specifying whether the order of element traversal must match the memory layout of an input ndarray. + */ + strictTraversalOrder?: boolean; +} + +/** +* Strided function. +* +* @param arrays - output ndarrays +* @param options - function options +* @returns result +*/ +type Nullary = ( arrays: [ typedndarray ], options?: unknown ) => typedndarray; + +/** +* Strided function. +* +* @param arrays - output ndarrays +* @param options - function options +* @returns result +*/ +type NullaryWithAdditionalArrays = ( arrays: [ typedndarray, ...Array> ], options?: unknown ) => typedndarray; + +/** +* Base dispatch table. +*/ +interface BaseDispatchTable { + /** + * Default strided function. + */ + default: Nullary | NullaryWithAdditionalArrays; +} + +/** +* Dispatch table. +*/ +interface DispatchTable extends BaseDispatchTable { + /** + * One-dimensional list of ndarray data types describing specialized output ndarray argument signatures. + */ + types: ArrayLike; + + /** + * List of strided functions which are specific to specialized output ndarray argument signatures. + */ + fcns: ArrayLike | NullaryWithAdditionalArrays>; +} + +/** +* Dispatch policies. +*/ +interface Policies { + /** + * Output data type policy. + */ + output: OutputPolicy; +} + +/** +* Interface for applying an operation to an ndarray. +*/ +interface NullaryFunction { + /** + * Applies a strided function and assign results to a provided output ndarray. + * + * @param x - output ndarray + * @param options - function options + * @returns output ndarray + * + * @example + * var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); + * var dtypes = require( '@stdlib/ndarray/dtypes' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var ndarray = require( '@stdlib/ndarray/base/ctor' ); + * + * var odt = dtypes( 'all' ); + * var policies = { + * 'output': 'same' + * }; + * + * var table = { + * 'default': base + * }; + * var sorthp = factory( table, [ odt ], policy ); + * + * var xbuf = [ -1.0, 2.0, -3.0 ]; + * var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + * + * var out = sorthp.assign( x ); + * // returns + * + * var arr = ndarray2array( out ); + * // returns [ -3.0, -1.0, 2.0 ] + * + * var bool = ( out === x ); + * // returns true + */ + assign = OutputArray>( x: V, options?: BaseOptions ): V; + + /** + * Applies a strided function and assigns results to a provided output ndarray. + * + * @param x - input ndarray + * @param o - additional ndarray argument + * @param args - output ndarray, additional array arguments, and function options + * @returns output ndarray + * + * @example + * var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); + * var dtypes = require( '@stdlib/ndarray/dtypes' ); + * var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + * var ndarray2array = require( '@stdlib/ndarray/to-array' ); + * var ndarray = require( '@stdlib/ndarray/base/ctor' ); + * + * var odt = dtypes( 'all' ); + * var policies = { + * 'output': 'same' + * }; + * + * var table = { + * 'default': base + * }; + * var sorthp = factory( table, [ odt ], policy ); + * + * var xbuf = [ -1.0, 2.0, -3.0 ]; + * var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + * + * var o = scalar2ndarray( 1.0, { + * 'dtype': 'generic' + * }); + * + * var out = sorthp.assign( x, o ); + * // returns + * + * var arr = ndarray2array( out ); + * // returns [ -3.0, -1.0, 2.0 ] + * + * var bool = ( out === x ); + * // returns true + */ + assign = OutputArray>( x: T, ...args: Array ): V; +} + +/** +* Creates a function for applying a strided function to an output ndarray. +* +* @param table - dispatch table +* @param odtypes - list containing lists of supported output data types for each ndarray argument +* @param policies - dispatch policies +* @param options - function options +* @returns function for applying a unary function +* +* @example +* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +* var dtypes = require( '@stdlib/ndarray/dtypes' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var odt = dtypes( 'all' ); +* var policies = { +* 'output': 'same' +* }; +* +* var table = { +* 'default': base +* }; +* var sorthp = factory( table, [ odt ], policy ); +* +* var xbuf = [ -1.0, 2.0, -3.0 ]; +* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* +* var o = scalar2ndarray( 1.0, { +* 'dtype': 'generic' +* }); +* +* var out = sorthp.assign( x, o ); +* // returns +* +* var arr = ndarray2array( out ); +* // returns [ -3.0, -1.0, 2.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ +declare function factory( table: DispatchTable | BaseDispatchTable, odtypes: ArrayLike>, policies: Policies, options?: FactoryOptions ): NullaryFunction; + + +// EXPORTS // + +export = factory; diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/test.ts new file mode 100644 index 000000000000..a4f457115326 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/docs/types/test.ts @@ -0,0 +1,473 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions, space-in-parens */ + +/// + +import { DataType, OutputPolicy, InputCastingPolicy } from '@stdlib/types/ndarray'; +import cumax = require( '@stdlib/stats/base/ndarray/cumax' ); +import zeros = require( '@stdlib/ndarray/zeros' ); +import factory = require( './index' ); + + +// TESTS // + +// The function returns a function... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + + factory( table, [ dtypes ], dtypes, policies ); // $ExpectType UnaryFunction + factory( table, [ dtypes ], dtypes, policies, {} ); // $ExpectType UnaryFunction +} + +// The compiler throws an error if the function is provided a first argument which is not a dispatch table... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + + factory( '5', [ dtypes ], dtypes, policies ); // $ExpectError + factory( 5, [ dtypes ], dtypes, policies ); // $ExpectError + factory( true, [ dtypes ], dtypes, policies ); // $ExpectError + factory( false, [ dtypes ], dtypes, policies ); // $ExpectError + factory( null, [ dtypes ], dtypes, policies ); // $ExpectError + factory( void 0, [ dtypes ], dtypes, policies ); // $ExpectError + factory( 'abc', [ dtypes ], dtypes, policies ); // $ExpectError + factory( {}, [ dtypes ], dtypes, policies ); // $ExpectError + factory( ( x: number, y: number ): number => x + y, [ dtypes ], dtypes, policies ); // $ExpectError + + factory( '5', [ dtypes ], dtypes, policies, {} ); // $ExpectError + factory( 5, [ dtypes ], dtypes, policies, {} ); // $ExpectError + factory( true, [ dtypes ], dtypes, policies, {} ); // $ExpectError + factory( false, [ dtypes ], dtypes, policies, {} ); // $ExpectError + factory( null, [ dtypes ], dtypes, policies, {} ); // $ExpectError + factory( void 0, [ dtypes ], dtypes, policies, {} ); // $ExpectError + factory( 'abc', [ dtypes ], dtypes, policies, {} ); // $ExpectError + factory( {}, [ dtypes ], dtypes, policies, {} ); // $ExpectError + factory( ( x: number, y: number ): number => x + y, [ dtypes ], dtypes, policies, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a list of data type lists... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + + factory( table, '5', dtypes, policies ); // $ExpectError + factory( table, 5, dtypes, policies ); // $ExpectError + factory( table, true, dtypes, policies ); // $ExpectError + factory( table, false, dtypes, policies ); // $ExpectError + factory( table, null, dtypes, policies ); // $ExpectError + factory( table, void 0, dtypes, policies ); // $ExpectError + factory( table, 'abc', dtypes, policies ); // $ExpectError + factory( table, {}, dtypes, policies ); // $ExpectError + factory( table, ( x: number ): number => x, dtypes, policies ); // $ExpectError + + factory( table, '5', dtypes, policies, {} ); // $ExpectError + factory( table, 5, dtypes, policies, {} ); // $ExpectError + factory( table, true, dtypes, policies, {} ); // $ExpectError + factory( table, false, dtypes, policies, {} ); // $ExpectError + factory( table, null, dtypes, policies, {} ); // $ExpectError + factory( table, void 0, dtypes, policies, {} ); // $ExpectError + factory( table, 'abc', dtypes, policies, {} ); // $ExpectError + factory( table, {}, dtypes, policies, {} ); // $ExpectError + factory( table, ( x: number ): number => x, dtypes, policies, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a list of data types... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + + factory( table, [ dtypes ], '5', policies ); // $ExpectError + factory( table, [ dtypes ], 5, policies ); // $ExpectError + factory( table, [ dtypes ], true, policies ); // $ExpectError + factory( table, [ dtypes ], false, policies ); // $ExpectError + factory( table, [ dtypes ], null, policies ); // $ExpectError + factory( table, [ dtypes ], void 0, policies ); // $ExpectError + factory( table, [ dtypes ], 'abc', policies ); // $ExpectError + factory( table, [ dtypes ], {}, policies ); // $ExpectError + factory( table, [ dtypes ], ( x: number ): number => x, policies ); // $ExpectError + + factory( table, [ dtypes ], '5', policies, {} ); // $ExpectError + factory( table, [ dtypes ], 5, policies, {} ); // $ExpectError + factory( table, [ dtypes ], true, policies, {} ); // $ExpectError + factory( table, [ dtypes ], false, policies, {} ); // $ExpectError + factory( table, [ dtypes ], null, policies, {} ); // $ExpectError + factory( table, [ dtypes ], void 0, policies, {} ); // $ExpectError + factory( table, [ dtypes ], 'abc', policies, {} ); // $ExpectError + factory( table, [ dtypes ], {}, policies, {} ); // $ExpectError + factory( table, [ dtypes ], ( x: number ): number => x, policies, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a valid policy object... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + + factory( table, [ dtypes ], dtypes, '5' ); // $ExpectError + factory( table, [ dtypes ], dtypes, 5 ); // $ExpectError + factory( table, [ dtypes ], dtypes, true ); // $ExpectError + factory( table, [ dtypes ], dtypes, false ); // $ExpectError + factory( table, [ dtypes ], dtypes, null ); // $ExpectError + factory( table, [ dtypes ], dtypes, void 0 ); // $ExpectError + factory( table, [ dtypes ], dtypes, 'abc' ); // $ExpectError + factory( table, [ dtypes ], dtypes, {} ); // $ExpectError + factory( table, [ dtypes ], dtypes, ( x: number ): number => x ); // $ExpectError + + factory( table, [ dtypes ], dtypes, '5', {} ); // $ExpectError + factory( table, [ dtypes ], dtypes, 5, {} ); // $ExpectError + factory( table, [ dtypes ], dtypes, true, {} ); // $ExpectError + factory( table, [ dtypes ], dtypes, false, {} ); // $ExpectError + factory( table, [ dtypes ], dtypes, null, {} ); // $ExpectError + factory( table, [ dtypes ], dtypes, void 0, {} ); // $ExpectError + factory( table, [ dtypes ], dtypes, 'abc', {} ); // $ExpectError + factory( table, [ dtypes ], dtypes, {}, {} ); // $ExpectError + factory( table, [ dtypes ], dtypes, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not an object... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + + factory( table, [ dtypes ], dtypes, policies, '5' ); // $ExpectError + factory( table, [ dtypes ], dtypes, policies, 5 ); // $ExpectError + factory( table, [ dtypes ], dtypes, policies, true ); // $ExpectError + factory( table, [ dtypes ], dtypes, policies, false ); // $ExpectError + factory( table, [ dtypes ], dtypes, policies, null ); // $ExpectError + factory( table, [ dtypes ], dtypes, policies, 'abc' ); // $ExpectError + factory( table, [ dtypes ], dtypes, policies, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + + factory(); // $ExpectError + factory( abs ); // $ExpectError + factory( table, [ dtypes ] ); // $ExpectError + factory( table, [ dtypes ], dtypes, policies, {}, {} ); // $ExpectError +} + +// The function returns a function which returns an ndarray... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + const f = factory( table, [ dtypes ], dtypes, policies ); + f( x ); // $ExpectType OutputArray + f( x, {} ); // $ExpectType OutputArray +} + +// The compiler throws an error if the returned function is provided a first argument which is not an ndarray... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + + const f = factory( table, [ dtypes ], dtypes, policies ); + f( '5' ); // $ExpectError + f( 5 ); // $ExpectError + f( true ); // $ExpectError + f( false ); // $ExpectError + f( null ); // $ExpectError + f( void 0 ); // $ExpectError + f( {} ); // $ExpectError + f( ( x: number ): number => x ); // $ExpectError + + f( '5', {} ); // $ExpectError + f( 5, {} ); // $ExpectError + f( true, {} ); // $ExpectError + f( false, {} ); // $ExpectError + f( null, {} ); // $ExpectError + f( void 0, {} ); // $ExpectError + f( {}, {} ); // $ExpectError + f( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the returned function is provided an invalid second argument... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + const f = factory( table, [ dtypes ], dtypes, policies ); + f( x, '5' ); // $ExpectError + f( x, true ); // $ExpectError + f( x, false ); // $ExpectError + f( x, null ); // $ExpectError + f( x, [] ); // $ExpectError + f( x, ( x: number ): number => x ); // $ExpectError + + f( x, '5', {} ); // $ExpectError + f( x, true, {} ); // $ExpectError + f( x, false, {} ); // $ExpectError + f( x, null, {} ); // $ExpectError + f( x, [], {} ); // $ExpectError + f( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the returned function is provided an invalid `dtype` option... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + const f = factory( table, [ dtypes ], dtypes, policies ); + f( x, { 'dtype': '5' } ); // $ExpectError + f( x, { 'dtype': 5 } ); // $ExpectError + f( x, { 'dtype': true } ); // $ExpectError + f( x, { 'dtype': false } ); // $ExpectError + f( x, { 'dtype': null } ); // $ExpectError + f( x, { 'dtype': [] } ); // $ExpectError + f( x, { 'dtype': {} } ); // $ExpectError + f( x, { 'dtype': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the returned function is provided an invalid `dims` option... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + const f = factory( table, [ dtypes ], dtypes, policies ); + f( x, { 'dims': '5' } ); // $ExpectError + f( x, { 'dims': 5 } ); // $ExpectError + f( x, { 'dims': true } ); // $ExpectError + f( x, { 'dims': false } ); // $ExpectError + f( x, { 'dims': null } ); // $ExpectError + f( x, { 'dims': {} } ); // $ExpectError + f( x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the returned function is provided an unsupported number of arguments... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + + const f = factory( table, [ dtypes ], dtypes, policies ); + f(); // $ExpectError +} + +// The function returns a function having an `assign` method which returns an ndarray... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + const f = factory( table, [ dtypes ], dtypes, policies ); + f.assign( x, x ); // $ExpectType float64ndarray +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an ndarray... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + const f = factory( table, [ dtypes ], dtypes, policies ); + f.assign( '5', x ); // $ExpectError + f.assign( 5, x ); // $ExpectError + f.assign( true, x ); // $ExpectError + f.assign( false, x ); // $ExpectError + f.assign( null, x ); // $ExpectError + f.assign( void 0, x ); // $ExpectError + f.assign( {}, x ); // $ExpectError + f.assign( ( x: number ): number => x, x ); // $ExpectError + + f.assign( '5', x, {} ); // $ExpectError + f.assign( 5, x, {} ); // $ExpectError + f.assign( true, x, {} ); // $ExpectError + f.assign( false, x, {} ); // $ExpectError + f.assign( null, x, {} ); // $ExpectError + f.assign( void 0, x, {} ); // $ExpectError + f.assign( {}, x, {} ); // $ExpectError + f.assign( ( x: number ): number => x, x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an ndarray... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + const f = factory( table, [ dtypes ], dtypes, policies ); + f.assign( x, '5' ); // $ExpectError + f.assign( x, 5 ); // $ExpectError + f.assign( x, true ); // $ExpectError + f.assign( x, false ); // $ExpectError + f.assign( x, null ); // $ExpectError + f.assign( x, void 0 ); // $ExpectError + f.assign( x, ( x: number ): number => x ); // $ExpectError + + f.assign( x, '5', {} ); // $ExpectError + f.assign( x, 5, {} ); // $ExpectError + f.assign( x, true, {} ); // $ExpectError + f.assign( x, false, {} ); // $ExpectError + f.assign( x, null, {} ); // $ExpectError + f.assign( x, void 0, {} ); // $ExpectError + f.assign( x, ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an invalid `dims` option... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + const f = factory( table, [ dtypes ], dtypes, policies ); + f.assign( x, x, { 'dims': '5' } ); // $ExpectError + f.assign( x, x, { 'dims': 5 } ); // $ExpectError + f.assign( x, x, { 'dims': true } ); // $ExpectError + f.assign( x, x, { 'dims': false } ); // $ExpectError + f.assign( x, x, { 'dims': null } ); // $ExpectError + f.assign( x, x, { 'dims': {} } ); // $ExpectError + f.assign( x, x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const dtypes: Array = [ 'float64', 'float32' ]; + const table = { + 'default': cumax + }; + const policies = { + 'output': 'same' as OutputPolicy, + 'casting': 'none' as InputCastingPolicy + }; + const x = zeros( [ 2, 2 ], { + 'dtype': 'float64' + }); + + const f = factory( table, [ dtypes ], dtypes, policies ); + f.assign(); // $ExpectError + f.assign( x ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/examples/index.js new file mode 100644 index 000000000000..2ad078a4e649 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/examples/index.js @@ -0,0 +1,76 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable array-element-newline */ + +'use strict'; + +var dsorthp = require( '@stdlib/blas/ext/base/ndarray/dsorthp' ); +var ssorthp = require( '@stdlib/blas/ext/base/ndarray/ssorthp' ); +var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var factory = require( './../lib' ); + +// Define the supported output data types: +var odt = dtypes( 'all' ); + +// Define dispatch policies: +var policies = { + 'output': 'same' +}; + +// Define a dispatch table: +var table = { + 'types': [ + 'float64', + 'float32' + ], + 'fcns': [ + dsorthp, + ssorthp + ], + 'default': base +}; + +// Create an interface for performing an operation: +var sorthp = factory( table, [ odt ], policies ); + +// Generate an array of random numbers: +var xbuf = discreteUniform( 25, -10, 10, { + 'dtype': 'generic' +}); + +// Wrap in an ndarray: +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var o = scalar2ndarray( 1.0, { + 'dtype': 'generic' +}); + +// Perform operation: +sorthp.assign( x, o, { + 'dims': [ 0 ] +}); + +// Print the results: +console.log( ndarray2array( x ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/index.js new file mode 100644 index 000000000000..8f8e69ff6b0b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/index.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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'; + +/** +* Create a function for applying a strided function to an output ndarray. +* +* @module @stdlib/ndarray/base/nullary-strided1d-dispatch-factory +* +* @example +* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +* var dtypes = require( '@stdlib/ndarray/dtypes' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var factory = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch-factory' ); +* +* var odt = dtypes( 'all' ); +* var policies = { +* 'output': 'same' +* }; +* +* var table = { +* 'default': base +* }; +* var sorthp = factory( table, [ odt ], policies ); +* +* var xbuf = [ -1.0, 2.0, -3.0 ]; +* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* +* var o = scalar2ndarray( 1.0, { +* 'dtype': 'generic' +* }); +* +* var out = sorthp.assign( x, o ); +* // returns +* +* var arr = ndarray2array( x ); +* // returns [ -3.0, -1.0, 2.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "assign": "main.assign" } diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/main.js new file mode 100644 index 000000000000..1c175f17e28e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/lib/main.js @@ -0,0 +1,123 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var NullaryStrided1dDispatch = require( '@stdlib/ndarray/base/nullary-strided1d-dispatch' ); + + +// MAIN // + +/** +* Returns a function for applying a strided function to an output ndarray. +* +* @param {Object} table - dispatch table +* @param {Function} table.default - default strided function +* @param {StringArray} [table.types] - one-dimensional list of ndarray data types describing specialized output ndarray argument signatures +* @param {ArrayLikeObject} [table.fcns] - list of strided functions which are specific to specialized output ndarray argument signatures +* @param {ArrayLikeObject} odtypes - list containing lists of supported output data types for each ndarray argument +* @param {Object} policies - policies +* @param {string} policies.output - output data type policy +* @param {Options} [options] - function options +* @param {boolean} [options.strictTraversalOrder=false] - boolean specifying whether to require that element traversal match the memory layout of an output ndarray +* @throws {TypeError} first argument must be an object having valid properties +* @throws {Error} first argument must be an object having valid properties +* @throws {TypeError} second argument must be an array containing arrays of supported data types +* @throws {TypeError} third argument must be an object having supported policies +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {Function} function for applying a strided function an ndarray +* +* @example +* var base = require( '@stdlib/blas/ext/base/ndarray/gsorthp' ); +* var dtypes = require( '@stdlib/ndarray/dtypes' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var odt = dtypes( 'all' ); +* var policies = { +* 'output': 'same' +* }; +* +* var table = { +* 'default': base +* }; +* var sorthp = factory( table, [ odt ], policies ); +* +* var xbuf = [ -1.0, 2.0, -3.0 ]; +* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* +* var o = scalar2ndarray( 1.0, { +* 'dtype': 'generic' +* }); +* +* var out = sorthp( x, o ); +* // returns +* +* var arr = ndarray2array( x ); +* // returns [ -3.0, -1.0, 2.0 ] +* +* var bool = ( out === x ); +* // returns true +*/ +function factory( table, odtypes, policies, options ) { + var f; + if ( arguments.length > 3 ) { + f = new NullaryStrided1dDispatch( table, odtypes, policies, options ); // eslint-disable-line max-len + } else { + f = new NullaryStrided1dDispatch( table, odtypes, policies ); + } + setReadOnly( assign, 'assign', assign ); + return assign; + + /** + * Applies a strided function and assigns results to a provided output ndarray. + * + * @private + * @param {ndarrayLike} x - output ndarray + * @param {...ndarrayLike} [args] - additional ndarray arguments + * @param {Options} [options] - function options + * @param {IntegerArray} [options.dims] - list of dimensions over which to perform operation + * @throws {TypeError} first argument must be an ndarray + * @throws {TypeError} first argument must have a supported data type + * @throws {TypeError} options argument must be an object + * @throws {RangeError} dimension indices must not exceed input ndarray bounds + * @throws {RangeError} number of dimension indices must not exceed the number of output ndarray dimensions + * @throws {Error} must provide valid options + * @returns {ndarrayLike} output ndarray + */ + function assign() { + var args; + var i; + + args = []; + for ( i = 0; i < arguments.length; i++ ) { + args.push( arguments[ i ] ); + } + return f.assign.apply( f, args ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/package.json b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/package.json new file mode 100644 index 000000000000..755d48fc1e7c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ndarray/base/nullary-strided1d-dispatch-factory", + "version": "0.0.0", + "description": "Create a function for applying a strided function to an output ndarray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "factory", + "function", + "func", + "fcn", + "ndarray", + "strided", + "vector", + "array", + "apply", + "cumulative", + "aggregation", + "aggregate", + "accumulate" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/test/test.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/test/test.js new file mode 100644 index 000000000000..6a51e9ffda63 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch-factory/test/test.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 tape = require( 'tape' ); +var factory = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +// FIXME: add tests