You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/ndarray/find/lib/assign.js
+45-70Lines changed: 45 additions & 70 deletions
Original file line number
Diff line number
Diff line change
@@ -45,14 +45,14 @@ var getSentinelValue = require( './sentinel.js' );
45
45
* Finds the first elements which pass a test implemented by a predicate function along one or more ndarray dimensions and assigns results to a provided output ndarray.
46
46
*
47
47
* @param {ndarray} x - input ndarray
48
-
* @param {ndarray} y - output ndarray
49
-
* @param {*|ndarray} [sentinelValue] - sentinel value
48
+
* @param {(*|ndarray)} [sentinelValue] - sentinel value
49
+
* @param {ndarray} out - output ndarray
50
50
* @param {Options} [options] - function options
51
51
* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction
52
52
* @param {Function} predicate - predicate function
53
53
* @param {*} [thisArg] - predicate function execution context
54
54
* @throws {TypeError} first argument must be an ndarray-like object
55
-
* @throws {TypeError} second argument must be an ndarray-like object
55
+
* @throws {TypeError} third argument must be an ndarray-like object
56
56
* @throws {TypeError} options argument must be an object
57
57
* @throws {TypeError} callback argument must be a function
58
58
* @throws {Error} must provide valid options
@@ -68,101 +68,81 @@ var getSentinelValue = require( './sentinel.js' );
68
68
* // returns <ndarray>
69
69
*
70
70
* // Create an output ndarray:
71
-
* var y = empty( [], {
71
+
* var out = empty( [], {
72
72
* 'dtype': x.dtype
73
73
* });
74
74
*
75
75
* // Perform reduction:
76
-
* var out = assign( x, y, isEven );
76
+
* var result = assign( x, -1, out, isEven );
77
77
* // returns <ndarray>
78
78
*
79
79
* var v = out.get();
80
80
* // returns 2.0
81
81
*/
82
-
functionassign(x,y){
82
+
functionassign(x){
83
83
varsentinelValue;
84
84
varpredicate;
85
85
varthisArg;
86
86
varoptions;
87
87
varnargs;
88
88
varopts;
89
89
varerr;
90
+
varout;
90
91
varsv;
92
+
varpi;
91
93
varN;
94
+
vari;
92
95
93
96
nargs=arguments.length;
94
97
if(!isndarrayLike(x)){
95
98
thrownewTypeError(format('invalid argument. First argument must be an ndarray-like object. Value: `%s`.',x));
96
99
}
97
-
if(!isndarrayLike(y)){
98
-
thrownewTypeError(format('invalid argument. Second argument must be an ndarray-like object. Value: `%s`.',y));
100
+
pi=-1;
101
+
for(i=1;i<nargs;i++){
102
+
if(isFunction(arguments[i])){
103
+
pi=i;
104
+
break;
105
+
}
99
106
}
100
-
101
-
if(nargs===3){
102
-
// assign( x, y, predicate )
107
+
if(pi===-1){
108
+
thrownewTypeError('invalid arguments. Must provide a predicate function. Value: `%s`.',arguments[i]);
// Check whether we need to reinsert singleton dimensions which can be useful for broadcasting the returned output array to the shape of the original input array...
0 commit comments