@@ -69,9 +69,9 @@ var arr = ndarray2array( y );
69
69
The function accepts the following arguments:
70
70
71
71
- ** x** : input [ ndarray] [ @stdlib/ndarray/ctor ] .
72
- - ** options** : function options.
72
+ - ** options** : function options _ (optional) _ .
73
73
- ** fcn** : callback to apply.
74
- - ** thisArg** : callback execution context.
74
+ - ** thisArg** : callback execution context _ (optional) _ .
75
75
76
76
The function accepts the following options:
77
77
@@ -112,6 +112,41 @@ var arr = ndarray2array( y );
112
112
// returns [ [ 20.0, 30.0, 40.0 ], [ 80.0, 90.0, 100.0 ] ]
113
113
```
114
114
115
+ To set the callback function execution context, provide a ` thisArg ` .
116
+
117
+ <!-- eslint-disable no-invalid-this, max-len -->
118
+
119
+ ``` javascript
120
+ var Float64Array = require ( ' @stdlib/array/float64' );
121
+ var ndarray = require ( ' @stdlib/ndarray/ctor' );
122
+ var ndarray2array = require ( ' @stdlib/ndarray/to-array' );
123
+
124
+ function scale ( z ) {
125
+ this .count += 1 ;
126
+ return z * 10.0 ;
127
+ }
128
+
129
+ 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 ] );
130
+ var shape = [ 2 , 3 ];
131
+ var strides = [ 6 , 1 ];
132
+ var offset = 1 ;
133
+
134
+ var x = ndarray ( ' float64' , buffer, shape, strides, offset, ' row-major' );
135
+ // returns <ndarray>
136
+
137
+ var ctx = {
138
+ ' count' : 0
139
+ };
140
+ var y = map ( x, scale, ctx );
141
+ // returns <ndarray>
142
+
143
+ var arr = ndarray2array ( y );
144
+ // returns [ [ 20.0, 30.0, 40.0 ], [ 80.0, 90.0, 100.0 ] ]
145
+
146
+ var count = ctx .count ;
147
+ // returns 6
148
+ ```
149
+
115
150
The callback function is provided the following arguments:
116
151
117
152
- ** value** : current array element.
0 commit comments