@stdlib/math-tools-unary 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/main.js CHANGED
@@ -21,47 +21,52 @@
21
21
  // MODULES //
22
22
 
23
23
  var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
24
- var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;
25
- var isComplexLike = require( '@stdlib/assert-is-complex-like' );
26
24
  var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );
25
+ var isFunction = require( '@stdlib/assert-is-function' );
26
+ var isObject = require( '@stdlib/assert-is-object' );
27
27
  var isCollection = require( '@stdlib/assert-is-collection' );
28
- var dtype = require( '@stdlib/ndarray-base-buffer-dtype' );
29
- var buffer = require( '@stdlib/ndarray-base-buffer' );
30
- var broadcast = require( '@stdlib/ndarray-base-broadcast-array' );
28
+ var isOutputDataTypePolicy = require( '@stdlib/ndarray-base-assert-is-output-data-type-policy' );
29
+ var isInputCastingPolicy = require( '@stdlib/ndarray-base-assert-is-input-casting-policy' );
30
+ var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' );
31
+ var contains = require( '@stdlib/array-base-assert-contains' );
32
+ var unaryOutputDataType = require( '@stdlib/ndarray-base-unary-output-dtype' );
33
+ var unaryInputCastingDataType = require( '@stdlib/ndarray-base-unary-input-casting-dtype' );
34
+ var baseAssign = require( '@stdlib/ndarray-base-assign' );
35
+ var baseEmpty = require( '@stdlib/ndarray-base-empty' );
36
+ var maybeBroadcastArray = require( '@stdlib/ndarray-maybe-broadcast-array' );
37
+ var getShape = require( '@stdlib/ndarray-shape' );
38
+ var getOrder = require( '@stdlib/ndarray-order' );
39
+ var getDType = require( '@stdlib/ndarray-dtype' );
40
+ var empty = require( '@stdlib/ndarray-empty' );
41
+ var everyBy = require( '@stdlib/array-base-every-by' );
42
+ var join = require( '@stdlib/array-base-join' );
31
43
  var format = require( '@stdlib/string-format' );
32
- var ndarrayfcn = require( './ndarray.js' );
33
- var odtype = require( './resolve_output_dtype.js' );
34
- var defaults = require( './defaults.json' );
35
- var validateTable = require( './validate_table.js' );
36
- var validateOptions = require( './validate_options.js' );
37
44
  var validate = require( './validate.js' );
38
45
 
39
46
 
40
47
  // MAIN //
41
48
 
42
49
  /**
43
- * Returns a function which dispatches to specified functions based on input argument types.
50
+ * Returns a function which performs element-wise computation.
44
51
  *
45
- * @param {Object} table - resolution table object
46
- * @param {(Function|null)} [table.number] - function to invoke upon receiving a number
47
- * @param {(Function|null)} [table.complex] - function to invoke upon receiving a complex number
48
- * @param {(Function|null)} [table.array] - function to invoke upon receiving an array-like object
49
- * @param {(Function|null)} [table.ndarray] - function to invoke upon receiving an ndarray-like object
50
- * @param {Options} [options] - options
51
- * @param {string} [options.output_dtype_policy='floating-point'] - policy for determining the output array data type
52
- * @throws {TypeError} first argument must be an object
53
- * @throws {TypeError} first argument must have valid table fields
54
- * @throws {Error} each table field value must be either a function or `null`
55
- * @throws {TypeError} options argument must be an object
56
- * @throws {TypeError} must provide valid options
57
- * @returns {Function} dispatch function
52
+ * @param {Function} fcn - function which applies a unary function to each element in an ndarray
53
+ * @param {ArrayLikeObject<StringArray>} idtypes - list containing lists of supported input data types for each ndarray argument
54
+ * @param {StringArray} odtypes - list of supported output data types
55
+ * @param {Object} policies - dispatch policies
56
+ * @param {string} policies.output - output data type policy
57
+ * @param {string} policies.casting - input ndarray casting policy
58
+ * @throws {TypeError} first argument must be a function
59
+ * @throws {TypeError} second argument must be an array containing arrays of supported data types
60
+ * @throws {TypeError} third argument must be an array of supported data types
61
+ * @throws {TypeError} fourth argument must be an object having supported policies
62
+ * @returns {Function} function which performs element-wise computation
58
63
  *
59
64
  * @example
60
65
  * var base = require( '@stdlib/math-base-special-abs' );
61
- * var strided = require( '@stdlib/math-strided-special-abs' );
62
- * var dispatcher = require( '@stdlib/ndarray-dispatch' );
66
+ * var dispatch = require( '@stdlib/ndarray-dispatch' );
63
67
  * var unary = require( '@stdlib/ndarray-base-unary' );
64
- * var Float64Array = require( '@stdlib/array-float64' );
68
+ * var ndarray2array = require( '@stdlib/ndarray-to-array' );
69
+ * var array = require( '@stdlib/ndarray-array' );
65
70
  *
66
71
  * var types = [
67
72
  * 'float64', 'float64',
@@ -73,173 +78,172 @@ var validate = require( './validate.js' );
73
78
  * base,
74
79
  * base
75
80
  * ];
76
- * var nd = dispatcher( unary, types, data, 2, 1, 1 );
81
+ * var dispatcher = dispatch( unary, types, data, 2, 1, 1 );
77
82
  *
78
- * var table = {
79
- * 'number': base,
80
- * 'complex': null,
81
- * 'array': strided,
82
- * 'ndarray': nd
83
- * };
83
+ * var idt = [ 'float64', 'float32', 'generic' ];
84
+ * var odt = idt;
84
85
  *
85
- * var abs = dispatch( table, {
86
- * 'output_dtype_policy': 'same'
87
- * });
86
+ * var policies = {
87
+ * 'output': 'real_and_generic',
88
+ * 'casting': 'none'
89
+ * };
90
+ * var abs = factory( dispatcher, [ idt ], odt, policies );
88
91
  *
89
- * var x = new Float64Array( [ -1.0, -2.0, -3.0 ] );
92
+ * var x = array( [ [ -1.0, -2.0 ], [ -3.0, -4.0 ] ] );
93
+ * // returns <ndarray>
90
94
  *
91
95
  * var y = abs( x );
92
- * // returns <Float64Array>[ 1.0, 2.0, 3.0 ]
96
+ * // returns <ndarray>
97
+ *
98
+ * var arr = ndarray2array( y );
99
+ * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
93
100
  */
94
- function dispatch( table, options ) {
95
- var OPTS;
96
- var err;
97
- var fcn;
98
- var t;
99
-
100
- t = {
101
- 'number': null,
102
- 'complex': null,
103
- 'array': null,
104
- 'ndarray': null
105
- };
106
- err = validateTable( t, table );
107
- if ( err ) {
108
- throw err;
101
+ function factory( fcn, idtypes, odtypes, policies ) {
102
+ var POLICIES;
103
+ var dt;
104
+ var i;
105
+ if ( !isFunction( fcn ) ) {
106
+ throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', fcn ) );
109
107
  }
110
- OPTS = {
111
- 'policy': defaults.output_dtype_policy
112
- };
113
- if ( arguments.length > 1 ) {
114
- err = validateOptions( OPTS, options );
115
- if ( err ) {
116
- throw err;
108
+ if ( !isCollection( idtypes ) ) {
109
+ throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', idtypes ) );
110
+ }
111
+ for ( i = 0; i < idtypes.length; i++ ) {
112
+ dt = idtypes[ i ];
113
+ if (
114
+ !isCollection( dt ) ||
115
+ dt.length < 1 ||
116
+ !everyBy( dt, isDataType )
117
+ ) {
118
+ throw new TypeError( format( 'invalid argument. Second argument must contain arrays of data types. Value: `%s`.', idtypes ) );
117
119
  }
118
120
  }
119
- fcn = dispatcher;
120
- setReadOnly( fcn, 'assign', assign );
121
- return fcn;
121
+ if (
122
+ !isCollection( odtypes ) ||
123
+ odtypes.length < 1 ||
124
+ !everyBy( odtypes, isDataType )
125
+ ) {
126
+ throw new TypeError( format( 'invalid argument. Third argument must be an array of data types. Value: `%s`.', odtypes ) );
127
+ }
128
+ if ( !isObject( policies ) ) {
129
+ throw new TypeError( format( 'invalid argument. Fourth argument must be an object. Value: `%s`.', policies ) );
130
+ }
131
+ if ( !isOutputDataTypePolicy( policies.output ) ) {
132
+ throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported output data type policy. Value: `%s`.', policies.output ) );
133
+ }
134
+ if ( !isInputCastingPolicy( policies.casting ) ) {
135
+ throw new TypeError( format( 'invalid argument. Fourth argument must be an object having a supported casting policy. Value: `%s`.', policies.casting ) );
136
+ }
137
+ POLICIES = {
138
+ 'output': policies.output,
139
+ 'casting': policies.casting
140
+ };
141
+ setReadOnly( unary, 'assign', assign );
142
+ return unary;
122
143
 
123
144
  /**
124
- * Function interface which performs dispatch.
145
+ * Performs element-wise computation.
125
146
  *
126
147
  * @private
127
- * @param {(ndarray|Collection|number|Complex)} x - input value
148
+ * @param {ndarray} x - input array
128
149
  * @param {Options} [options] - options
129
- * @param {string} [options.dtype] - output array data type
130
- * @param {string} [options.order] - output array order (row-major or column-major)
131
- * @throws {TypeError} first argument must be a supported data type
150
+ * @param {*} [options.dtype] - output array data type
151
+ * @param {string} [options.order] - output array order
152
+ * @throws {TypeError} first argument must be an ndarray
153
+ * @throws {TypeError} first argument must have a supported data type
132
154
  * @throws {TypeError} options argument must be an object
133
155
  * @throws {TypeError} must provide valid options
134
- * @returns {(ndarray|Collection|number|Complex)} results
156
+ * @returns {ndarray} output array
135
157
  */
136
- function dispatcher( x ) {
137
- var xdtype;
138
- var ydtype;
158
+ function unary( x ) {
139
159
  var opts;
140
160
  var err;
161
+ var xsh;
162
+ var ord;
163
+ var xdt;
164
+ var ydt;
165
+ var tmp;
166
+ var dt;
141
167
  var y;
142
- if ( isNumber( x ) ) {
143
- if ( t.number ) {
144
- return t.number( x );
145
- }
146
- throw new TypeError( 'invalid argument. Providing a number is not supported.' );
168
+
169
+ if ( !isndarrayLike( x ) ) {
170
+ throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );
147
171
  }
148
- if ( isComplexLike( x ) ) {
149
- if ( t.complex ) {
150
- return t.complex( x );
151
- }
152
- throw new TypeError( 'invalid argument. Providing a complex number is not supported.' );
172
+ xdt = getDType( x );
173
+ if ( !contains( idtypes[ 0 ], xdt ) ) {
174
+ throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Data type: `%s`.', join( idtypes[ 0 ], '", "' ), xdt ) );
153
175
  }
154
176
  opts = {};
155
177
  if ( arguments.length > 1 ) {
156
- err = validate( opts, arguments[ 1 ] );
178
+ err = validate( opts, odtypes, arguments[ 1 ] );
157
179
  if ( err ) {
158
180
  throw err;
159
181
  }
160
182
  }
161
- if ( isndarrayLike( x ) ) {
162
- if ( t.ndarray === null ) {
163
- throw new TypeError( 'invalid argument. Providing an ndarray is not supported.' );
164
- }
165
- ydtype = opts.dtype || odtype( x.dtype, OPTS.policy );
166
- return ndarrayfcn( t.ndarray, x, ydtype, opts.order || x.order );
167
- }
168
- if ( isCollection( x ) ) {
169
- if ( t.array === null ) {
170
- throw new TypeError( 'invalid argument. Providing an array-like object is not supported.' );
171
- }
172
- xdtype = dtype( x ) || 'generic';
173
- ydtype = opts.dtype || odtype( xdtype, OPTS.policy );
174
- y = buffer( ydtype, x.length );
175
- t.array( x.length, xdtype, x, 1, ydtype, y, 1 );
176
- return y;
183
+ xsh = getShape( x );
184
+ ord = getOrder( x );
185
+
186
+ // Initialize an output array:
187
+ ydt = opts.dtype || unaryOutputDataType( xdt, POLICIES.output );
188
+ y = empty( xsh, {
189
+ 'dtype': ydt,
190
+ 'order': opts.order || ord
191
+ });
192
+
193
+ // Determine whether we need to cast the input ndarray...
194
+ dt = unaryInputCastingDataType( xdt, ydt, POLICIES.casting );
195
+ if ( xdt !== dt ) {
196
+ // TODO: replace the following logic with a call to `ndarray/base/(?maybe-)(cast|convert|copy)` or similar utility
197
+ tmp = baseEmpty( dt, xsh, ord );
198
+ baseAssign( [ x, tmp ] );
199
+ x = tmp;
177
200
  }
178
- throw new TypeError( format( 'invalid argument. Must provide an argument having a supported data type. Value: `%s`.', x ) );
201
+ fcn( x, y );
202
+ return y;
179
203
  }
180
204
 
181
205
  /**
182
- * Function interface which performs dispatch and assigns results to a provided output array.
206
+ * Performs element-wise computation and assigns results to a provided output ndarray.
183
207
  *
184
208
  * @private
185
- * @param {(ndarray|Collection)} x - input array
186
- * @param {(ndarray|Collection)} y - output array
187
- * @throws {TypeError} first argument must be a supported data type
188
- * @throws {TypeError} second argument must be a supported data type
189
- * @throws {TypeError} first and second argument must be the same "kind" (i.e., either both ndarrays or both collections)
190
- * @throws {RangeError} output array must have sufficient elements
209
+ * @param {ndarray} x - input array
210
+ * @param {ndarray} y - output array
211
+ * @throws {TypeError} first argument must be an ndarray
212
+ * @throws {TypeError} first argument must have a supported data type
213
+ * @throws {TypeError} second argument must be an ndarray
191
214
  * @throws {Error} unable to broadcast the input array against the output array
192
- * @returns {(ndarray|Collection)} output array
215
+ * @returns {ndarray} output array
193
216
  */
194
217
  function assign( x, y ) {
195
- var xsh;
196
- var ysh;
197
- var i;
198
- if ( isndarrayLike( x ) ) {
199
- if ( isndarrayLike( y ) ) {
200
- xsh = x.shape;
201
- ysh = y.shape;
218
+ var xdt;
219
+ var tmp;
220
+ var dt;
202
221
 
203
- // Check whether we need to broadcast `x`...
204
- if ( xsh.length === ysh.length ) {
205
- for ( i = 0; i < xsh.length; i++ ) {
206
- // Check whether dimensions match...
207
- if ( xsh[ i ] !== ysh[ i ] ) {
208
- // We found a mismatched dimension; delegate to `broadcast` to ensure that `x` is broadcast compatible with the output array shape...
209
- x = broadcast( x, ysh );
210
- break;
211
- }
212
- }
213
- } else {
214
- // If we are provided arrays with different ranks (i.e., number of dimensions), assume we need to broadcast, delegating to `broadcast` to ensure that `x` is broadcast compatible with the output array shape...
215
- x = broadcast( x, ysh );
216
- }
217
- t.ndarray( x, y );
218
- return y;
219
- }
220
- throw new TypeError( 'invalid argument. If the first argument is an ndarray, the second argument must be an ndarray.' );
222
+ if ( !isndarrayLike( x ) ) {
223
+ throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );
221
224
  }
222
- if ( isCollection( x ) ) {
223
- if ( isCollection( y ) ) {
224
- if ( y.length !== x.length ) {
225
- throw new RangeError( 'invalid argument. Output array must have the same number of elements (i.e., length) as the input array.' );
226
- }
227
- t.array( x.length, dtype( x ) || 'generic', x, 1, dtype( y ) || 'generic', y, 1 );
228
- return y;
229
- }
230
- throw new TypeError( 'invalid argument. If the first argument is an array-like object, the second argument must be an array-like object.' );
225
+ if ( !isndarrayLike( y ) ) {
226
+ throw new TypeError( format( 'invalid argument. Second argument must be an ndarray. Value: `%s`.', y ) );
231
227
  }
232
- if ( isNumber( x ) ) {
233
- throw new TypeError( 'invalid argument. Providing a number is not supported. Consider providing a zero-dimensional ndarray containing the numeric value.' );
228
+ // Validate the input ndarray data type in order to maintain similar behavior to above...
229
+ xdt = getDType( x );
230
+ if ( !contains( idtypes[ 0 ], xdt ) ) {
231
+ throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Data type: `%s`.', join( idtypes[ 0 ], '", "' ), xdt ) );
234
232
  }
235
- if ( isComplexLike( x ) ) {
236
- throw new TypeError( 'invalid argument. Providing a complex number is not supported. Consider providing a zero-dimensional ndarray containing the complex number value.' );
233
+ // Determine whether we need to cast the input ndarray...
234
+ dt = unaryInputCastingDataType( xdt, getDType( y ), POLICIES.casting );
235
+ if ( xdt !== dt ) {
236
+ // TODO: replace the following logic with a call to `ndarray/base/(?maybe-)(cast|convert|copy)` or similar utility
237
+ tmp = baseEmpty( dt, getShape( x ), getOrder( x ) );
238
+ baseAssign( [ x, tmp ] );
239
+ x = tmp;
237
240
  }
238
- throw new TypeError( format( 'invalid argument. Must provide an argument having a supported data type. Value: `%s`.', x ) );
241
+ fcn( maybeBroadcastArray( x, getShape( y ) ), y );
242
+ return y;
239
243
  }
240
244
  }
241
245
 
242
246
 
243
247
  // EXPORTS //
244
248
 
245
- module.exports = dispatch;
249
+ module.exports = factory;
package/lib/validate.js CHANGED
@@ -22,18 +22,13 @@
22
22
 
23
23
  var isPlainObject = require( '@stdlib/assert-is-plain-object' );
24
24
  var hasOwnProp = require( '@stdlib/assert-has-own-property' );
25
- var contains = require( '@stdlib/assert-contains' );
25
+ var isOrder = require( '@stdlib/ndarray-base-assert-is-order' );
26
+ var contains = require( '@stdlib/array-base-assert-contains' );
26
27
  var orders = require( '@stdlib/ndarray-orders' );
27
- var dtypes = require( '@stdlib/ndarray-dtypes' );
28
+ var join = require( '@stdlib/array-base-join' );
28
29
  var format = require( '@stdlib/string-format' );
29
30
 
30
31
 
31
- // VARIABLES //
32
-
33
- var ORDERS = orders();
34
- var DTYPES = dtypes();
35
-
36
-
37
32
  // MAIN //
38
33
 
39
34
  /**
@@ -41,35 +36,38 @@ var DTYPES = dtypes();
41
36
  *
42
37
  * @private
43
38
  * @param {Object} opts - destination object
39
+ * @param {Array} dtypes - list of supported output data types
44
40
  * @param {Object} options - options
45
- * @param {string} [options.dtype] - output array data type
41
+ * @param {*} [options.dtype] - output array data type
46
42
  * @param {string} [options.order] - output array order
47
43
  * @returns {(Error|null)} null or an error object
48
44
  *
49
45
  * @example
46
+ * var dtypes = [ 'float64', 'float32', 'generic' ];
47
+ *
50
48
  * var opts = {};
51
49
  * var options = {
52
50
  * 'order': 'row-major'
53
51
  * };
54
- * var err = validate( opts, options );
52
+ * var err = validate( opts, dtypes, options );
55
53
  * if ( err ) {
56
54
  * throw err;
57
55
  * }
58
56
  */
59
- function validate( opts, options ) {
57
+ function validate( opts, dtypes, options ) {
60
58
  if ( !isPlainObject( options ) ) {
61
59
  return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
62
60
  }
63
61
  if ( hasOwnProp( options, 'dtype' ) ) {
64
62
  opts.dtype = options.dtype;
65
- if ( !contains( DTYPES, opts.dtype ) ) {
66
- return new TypeError( format( 'invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.', 'dtype', opts.dtype ) );
63
+ if ( !contains( dtypes, String( opts.dtype ) ) ) {
64
+ return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'dtype', join( dtypes, '", "' ), opts.dtype ) );
67
65
  }
68
66
  }
69
67
  if ( hasOwnProp( options, 'order' ) ) {
70
68
  opts.order = options.order;
71
- if ( !contains( ORDERS, opts.order ) ) {
72
- return new TypeError( format( 'invalid option. `%s` option must be a recognized/supported data type. Option: `%s`.', 'order', opts.order ) );
69
+ if ( !isOrder( opts.order ) ) {
70
+ return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'order', join( orders(), '", "' ), opts.order ) );
73
71
  }
74
72
  }
75
73
  return null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stdlib/math-tools-unary",
3
- "version": "0.2.2",
4
- "description": "Multiple dispatch for unary mathematical functions.",
3
+ "version": "0.3.0",
4
+ "description": "Create a function which performs element-wise computation by applying a unary function to each element in an input ndarray.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
7
7
  "name": "The Stdlib Authors",
@@ -30,27 +30,31 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@stdlib/array-base-copy-indexed": "^0.2.2",
34
- "@stdlib/assert-contains": "^0.2.2",
33
+ "@stdlib/array-base-assert-contains": "^0.2.2",
34
+ "@stdlib/array-base-every-by": "^0.2.2",
35
+ "@stdlib/array-base-join": "^0.1.1",
35
36
  "@stdlib/assert-has-own-property": "^0.2.2",
36
37
  "@stdlib/assert-is-collection": "^0.2.2",
37
- "@stdlib/assert-is-complex-like": "^0.2.2",
38
38
  "@stdlib/assert-is-function": "^0.2.2",
39
39
  "@stdlib/assert-is-ndarray-like": "^0.2.2",
40
- "@stdlib/assert-is-null": "^0.2.2",
41
- "@stdlib/assert-is-number": "^0.2.2",
40
+ "@stdlib/assert-is-object": "^0.2.2",
42
41
  "@stdlib/assert-is-plain-object": "^0.2.2",
43
- "@stdlib/ndarray-base-broadcast-array": "^0.2.2",
44
- "@stdlib/ndarray-base-buffer": "^0.2.1",
45
- "@stdlib/ndarray-base-buffer-dtype": "^0.2.1",
46
- "@stdlib/ndarray-base-numel": "^0.2.2",
47
- "@stdlib/ndarray-base-shape2strides": "^0.2.2",
48
- "@stdlib/ndarray-ctor": "^0.2.1",
49
- "@stdlib/ndarray-dtypes": "^0.3.0",
42
+ "@stdlib/ndarray-base-assert-is-data-type": "^0.3.0",
43
+ "@stdlib/ndarray-base-assert-is-input-casting-policy": "^0.1.0",
44
+ "@stdlib/ndarray-base-assert-is-order": "^0.2.2",
45
+ "@stdlib/ndarray-base-assert-is-output-data-type-policy": "^0.1.0",
46
+ "@stdlib/ndarray-base-assign": "^0.1.1",
47
+ "@stdlib/ndarray-base-empty": "^0.3.0",
48
+ "@stdlib/ndarray-base-unary-input-casting-dtype": "^0.1.0",
49
+ "@stdlib/ndarray-base-unary-output-dtype": "^0.3.0",
50
+ "@stdlib/ndarray-dtype": "^0.2.2",
51
+ "@stdlib/ndarray-empty": "^0.3.0",
52
+ "@stdlib/ndarray-maybe-broadcast-array": "^0.2.2",
53
+ "@stdlib/ndarray-order": "^0.2.2",
50
54
  "@stdlib/ndarray-orders": "^0.2.2",
55
+ "@stdlib/ndarray-shape": "^0.2.2",
51
56
  "@stdlib/string-format": "^0.2.2",
52
57
  "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
53
- "@stdlib/utils-keys": "^0.2.2",
54
58
  "@stdlib/error-tools-fmtprodmsg": "^0.2.2"
55
59
  },
56
60
  "devDependencies": {},
@@ -80,9 +84,9 @@
80
84
  "dispatch",
81
85
  "multimethod",
82
86
  "multimethods",
83
- "ndarray"
87
+ "ndarray",
88
+ "ufunc"
84
89
  ],
85
- "__stdlib__": {},
86
90
  "funding": {
87
91
  "type": "opencollective",
88
92
  "url": "https://opencollective.com/stdlib"
package/lib/defaults.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "output_dtype_policy": "floating-point"
3
- }
package/lib/ndarray.js DELETED
@@ -1,63 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2021 The Stdlib Authors.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
- 'use strict';
20
-
21
- // MODULES //
22
-
23
- var ndarray = require( '@stdlib/ndarray-ctor' );
24
- var buffer = require( '@stdlib/ndarray-base-buffer' );
25
- var shape2strides = require( '@stdlib/ndarray-base-shape2strides' );
26
- var numel = require( '@stdlib/ndarray-base-numel' );
27
- var copy = require( '@stdlib/array-base-copy-indexed' );
28
-
29
-
30
- // MAIN //
31
-
32
- /**
33
- * Applies a function to an ndarray.
34
- *
35
- * @private
36
- * @param {Function} fcn - function to apply
37
- * @param {ndarray} x - input array
38
- * @param {string} ydtype - output array data type
39
- * @param {string} yorder - output array order
40
- * @returns {ndarray} output array
41
- */
42
- function ndarrayfcn( fcn, x, ydtype, yorder ) {
43
- var shape;
44
- var buf;
45
- var y;
46
-
47
- // Check if we were provided a zero-dimensional array...
48
- shape = copy( x.shape ); // Note: we need to copy the shape to avoid a shared shape object between `x` and `y` which could lead to unintended mutations (e.g., if either `x` or `y` is reshaped)
49
- if ( shape.length === 0 ) {
50
- buf = buffer( ydtype, 1 );
51
- y = ndarray( ydtype, buf, [], [ 0 ], 0, yorder );
52
- } else {
53
- buf = buffer( ydtype, x.length || numel( shape ) ); // WARNING: `x.length` is a property found on ndarray instances, but not strictly necessary to describe an ndarray; accordingly, used here to avoid unnecessary computation, but a potential source of bugs if provided an ndarray-like object having a `length` property which is not equal to the product of the dimensions.
54
- y = ndarray( ydtype, buf, shape, shape2strides( shape, yorder ), 0, yorder ); // eslint-disable-line max-len
55
- }
56
- fcn( x, y );
57
- return y;
58
- }
59
-
60
-
61
- // EXPORTS //
62
-
63
- module.exports = ndarrayfcn;
package/lib/policies.json DELETED
@@ -1,6 +0,0 @@
1
- [
2
- "same",
3
- "floating-point",
4
- "real floating-point",
5
- "complex floating-point"
6
- ]