@stdlib/blas-ext-base-srev 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/NOTICE +1 -1
- package/README.md +134 -18
- package/dist/index.js +7 -7
- package/dist/index.js.map +4 -4
- package/docs/types/index.d.ts +6 -6
- package/include/stdlib/blas/ext/base/srev.h +7 -5
- package/lib/ndarray.js +10 -10
- package/lib/ndarray.native.js +5 -12
- package/lib/srev.js +5 -68
- package/lib/srev.native.js +3 -3
- package/manifest.json +17 -15
- package/package.json +5 -6
- package/src/addon.c +22 -4
- package/src/{srev.c → main.c} +36 -24
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -53,9 +53,9 @@ npm install @stdlib/blas-ext-base-srev
|
|
|
53
53
|
var srev = require( '@stdlib/blas-ext-base-srev' );
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
#### srev( N, x,
|
|
56
|
+
#### srev( N, x, strideX )
|
|
57
57
|
|
|
58
|
-
Reverses a single-precision floating-point strided array
|
|
58
|
+
Reverses a single-precision floating-point strided array in-place.
|
|
59
59
|
|
|
60
60
|
```javascript
|
|
61
61
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
@@ -70,9 +70,9 @@ The function has the following parameters:
|
|
|
70
70
|
|
|
71
71
|
- **N**: number of indexed elements.
|
|
72
72
|
- **x**: input [`Float32Array`][@stdlib/array/float32].
|
|
73
|
-
- **
|
|
73
|
+
- **strideX**: stride length.
|
|
74
74
|
|
|
75
|
-
The `N` and
|
|
75
|
+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to reverse every other element:
|
|
76
76
|
|
|
77
77
|
```javascript
|
|
78
78
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
@@ -99,9 +99,9 @@ srev( 3, x1, 2 );
|
|
|
99
99
|
// x0 => <Float32Array>[ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ]
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
#### srev.ndarray( N, x,
|
|
102
|
+
#### srev.ndarray( N, x, strideX, offsetX )
|
|
103
103
|
|
|
104
|
-
Reverses a single-precision floating-point strided array
|
|
104
|
+
Reverses a single-precision floating-point strided array in-place using alternative indexing semantics.
|
|
105
105
|
|
|
106
106
|
```javascript
|
|
107
107
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
@@ -114,9 +114,9 @@ srev.ndarray( x.length, x, 1, 0 );
|
|
|
114
114
|
|
|
115
115
|
The function has the following additional parameters:
|
|
116
116
|
|
|
117
|
-
- **
|
|
117
|
+
- **offsetX**: starting index.
|
|
118
118
|
|
|
119
|
-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying
|
|
119
|
+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of the strided array:
|
|
120
120
|
|
|
121
121
|
```javascript
|
|
122
122
|
var Float32Array = require( '@stdlib/array-float32' );
|
|
@@ -149,13 +149,12 @@ srev.ndarray( 3, x, 1, x.length-3 );
|
|
|
149
149
|
<!-- eslint no-undef: "error" -->
|
|
150
150
|
|
|
151
151
|
```javascript
|
|
152
|
-
var discreteUniform = require( '@stdlib/random-
|
|
153
|
-
var filledarrayBy = require( '@stdlib/array-filled-by' );
|
|
152
|
+
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
|
|
154
153
|
var srev = require( '@stdlib/blas-ext-base-srev' );
|
|
155
154
|
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
var x = discreteUniform( 10, -100, 100, {
|
|
156
|
+
'dtype': 'float32'
|
|
157
|
+
});
|
|
159
158
|
console.log( x );
|
|
160
159
|
|
|
161
160
|
srev( x.length, x, 1 );
|
|
@@ -166,6 +165,123 @@ console.log( x );
|
|
|
166
165
|
|
|
167
166
|
<!-- /.examples -->
|
|
168
167
|
|
|
168
|
+
<!-- C interface documentation. -->
|
|
169
|
+
|
|
170
|
+
* * *
|
|
171
|
+
|
|
172
|
+
<section class="c">
|
|
173
|
+
|
|
174
|
+
## C APIs
|
|
175
|
+
|
|
176
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
177
|
+
|
|
178
|
+
<section class="intro">
|
|
179
|
+
|
|
180
|
+
</section>
|
|
181
|
+
|
|
182
|
+
<!-- /.intro -->
|
|
183
|
+
|
|
184
|
+
<!-- C usage documentation. -->
|
|
185
|
+
|
|
186
|
+
<section class="usage">
|
|
187
|
+
|
|
188
|
+
### Usage
|
|
189
|
+
|
|
190
|
+
```c
|
|
191
|
+
#include "stdlib/blas/ext/base/srev.h"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### stdlib_strided_srev( N, \*X, strideX )
|
|
195
|
+
|
|
196
|
+
Reverses a single-precision floating-point strided array in-place.
|
|
197
|
+
|
|
198
|
+
```c
|
|
199
|
+
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
|
|
200
|
+
|
|
201
|
+
stdlib_strided_srev( 4, x, 1 );
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The function accepts the following arguments:
|
|
205
|
+
|
|
206
|
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
|
|
207
|
+
- **X**: `[inout] float*` input array.
|
|
208
|
+
- **strideX**: `[in] CBLAS_INT` stride length.
|
|
209
|
+
|
|
210
|
+
```c
|
|
211
|
+
void stdlib_strided_srev( const CBLAS_INT N, float *X, const CBLAS_INT strideX );
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### stdlib_strided_srev_ndarray( N, \*X, strideX, offsetX )
|
|
215
|
+
|
|
216
|
+
Reverses a single-precision floating-point strided array in-place using alternative indexing semantics.
|
|
217
|
+
|
|
218
|
+
```c
|
|
219
|
+
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
|
|
220
|
+
|
|
221
|
+
stdlib_strided_srev_ndarray( 4, x, 1, 0 );
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
The function accepts the following arguments:
|
|
225
|
+
|
|
226
|
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
|
|
227
|
+
- **X**: `[inout] float*` input array.
|
|
228
|
+
- **strideX**: `[in] CBLAS_INT` stride length.
|
|
229
|
+
- **offsetX**: `[in] CBLAS_INT` starting index.
|
|
230
|
+
|
|
231
|
+
```c
|
|
232
|
+
void stdlib_strided_srev_ndarray( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
</section>
|
|
236
|
+
|
|
237
|
+
<!-- /.usage -->
|
|
238
|
+
|
|
239
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
240
|
+
|
|
241
|
+
<section class="notes">
|
|
242
|
+
|
|
243
|
+
</section>
|
|
244
|
+
|
|
245
|
+
<!-- /.notes -->
|
|
246
|
+
|
|
247
|
+
<!-- C API usage examples. -->
|
|
248
|
+
|
|
249
|
+
<section class="examples">
|
|
250
|
+
|
|
251
|
+
### Examples
|
|
252
|
+
|
|
253
|
+
```c
|
|
254
|
+
#include "stdlib/blas/ext/base/srev.h"
|
|
255
|
+
#include <stdio.h>
|
|
256
|
+
|
|
257
|
+
int main( void ) {
|
|
258
|
+
// Create a strided array:
|
|
259
|
+
float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f };
|
|
260
|
+
|
|
261
|
+
// Specify the number of elements:
|
|
262
|
+
const int N = 8;
|
|
263
|
+
|
|
264
|
+
// Specify a stride:
|
|
265
|
+
const int strideX = 1;
|
|
266
|
+
|
|
267
|
+
// Reverse the array:
|
|
268
|
+
stdlib_strided_srev( N, x, strideX );
|
|
269
|
+
|
|
270
|
+
// Print the result:
|
|
271
|
+
for ( int i = 0; i < 8; i++ ) {
|
|
272
|
+
printf( "x[ %i ] = %f\n", i, x[ i ] );
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
</section>
|
|
278
|
+
|
|
279
|
+
<!-- /.examples -->
|
|
280
|
+
|
|
281
|
+
</section>
|
|
282
|
+
|
|
283
|
+
<!-- /.c -->
|
|
284
|
+
|
|
169
285
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
170
286
|
|
|
171
287
|
<section class="related">
|
|
@@ -207,7 +323,7 @@ See [LICENSE][stdlib-license].
|
|
|
207
323
|
|
|
208
324
|
## Copyright
|
|
209
325
|
|
|
210
|
-
Copyright © 2016-
|
|
326
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
211
327
|
|
|
212
328
|
</section>
|
|
213
329
|
|
|
@@ -220,8 +336,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
220
336
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-srev.svg
|
|
221
337
|
[npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-srev
|
|
222
338
|
|
|
223
|
-
[test-image]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
224
|
-
[test-url]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml?query=branch:v0.
|
|
339
|
+
[test-image]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
340
|
+
[test-url]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml?query=branch:v0.3.0
|
|
225
341
|
|
|
226
342
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-srev/main.svg
|
|
227
343
|
[coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-srev?branch=main
|
|
@@ -233,8 +349,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
233
349
|
|
|
234
350
|
-->
|
|
235
351
|
|
|
236
|
-
[chat-image]: https://img.shields.io/
|
|
237
|
-
[chat-url]: https://
|
|
352
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
353
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
238
354
|
|
|
239
355
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
240
356
|
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
var
|
|
3
|
-
});var
|
|
4
|
-
var
|
|
5
|
-
});var
|
|
6
|
-
var
|
|
7
|
-
});var
|
|
1
|
+
"use strict";var f=function(v,r){return function(){return r||v((r={exports:{}}).exports,r),r.exports}};var q=f(function(D,p){
|
|
2
|
+
var M=require('@stdlib/math-base-special-floor/dist'),s=3;function O(v,r,u,E){var i,e,a,o,n,t;if(v<=0)return r;if(n=M(v/2),e=E,u===1){if(o=n%s,a=e+v-1,o>0)for(t=0;t<o;t++)i=r[e],r[e]=r[a],r[a]=i,e+=u,a-=u;if(n<s)return r;for(t=o;t<n;t+=s)i=r[e],r[e]=r[a],r[a]=i,i=r[e+1],r[e+1]=r[a-1],r[a-1]=i,i=r[e+2],r[e+2]=r[a-2],r[a-2]=i,e+=s,a-=s;return r}for(a=e+(v-1)*u,t=0;t<n;t++)i=r[e],r[e]=r[a],r[a]=i,e+=u,a-=u;return r}p.exports=O
|
|
3
|
+
});var m=f(function(F,y){
|
|
4
|
+
var b=require('@stdlib/strided-base-stride2offset/dist'),d=q();function g(v,r,u){return d(v,r,u,b(v,u))}y.exports=g
|
|
5
|
+
});var R=f(function(G,l){
|
|
6
|
+
var h=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),j=m(),k=q();h(j,"ndarray",k);l.exports=j
|
|
7
|
+
});var w=require("path").join,z=require('@stdlib/utils-try-require/dist'),A=require('@stdlib/assert-is-error/dist'),B=R(),c,_=z(w(__dirname,"./native.js"));A(_)?c=B:c=_;module.exports=c;
|
|
8
8
|
/** @license Apache-2.0 */
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../lib/
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// VARIABLES //\n\nvar M = 3;\n\n\n// MAIN //\n\n/**\n* Reverses a single-precision floating-point strided array in-place.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} stride - index
|
|
5
|
-
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAKnDC,EAAI,
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../lib/ndarray.js", "../lib/srev.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// VARIABLES //\n\nvar M = 3;\n\n\n// MAIN //\n\n/**\n* Reverses a single-precision floating-point strided array in-place.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} strideX - stride length\n* @param {NonNegativeInteger} offsetX - starting index\n* @returns {Float32Array} input array\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );\n*\n* srev( 3, x, 1, x.length-3 );\n* // x => <Float32Array>[ 1.0, -2.0, 3.0, -6.0, 5.0, -4.0 ]\n*/\nfunction srev( N, x, strideX, offsetX ) {\n\tvar tmp;\n\tvar ix;\n\tvar iy;\n\tvar m;\n\tvar n;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn x;\n\t}\n\tn = floor( N/2 );\n\tix = offsetX;\n\n\t// Use loop unrolling if the stride is equal to `1`...\n\tif ( strideX === 1 ) {\n\t\tm = n % M;\n\t\tiy = ix + N - 1;\n\n\t\t// If we have a remainder, run a clean-up loop...\n\t\tif ( m > 0 ) {\n\t\t\tfor ( i = 0; i < m; i++ ) {\n\t\t\t\ttmp = x[ ix ];\n\t\t\t\tx[ ix ] = x[ iy ];\n\t\t\t\tx[ iy ] = tmp;\n\t\t\t\tix += strideX;\n\t\t\t\tiy -= strideX;\n\t\t\t}\n\t\t}\n\t\tif ( n < M ) {\n\t\t\treturn x;\n\t\t}\n\t\tfor ( i = m; i < n; i += M ) {\n\t\t\ttmp = x[ ix ];\n\t\t\tx[ ix ] = x[ iy ];\n\t\t\tx[ iy ] = tmp;\n\n\t\t\ttmp = x[ ix+1 ];\n\t\t\tx[ ix+1 ] = x[ iy-1 ];\n\t\t\tx[ iy-1 ] = tmp;\n\n\t\t\ttmp = x[ ix+2 ];\n\t\t\tx[ ix+2 ] = x[ iy-2 ];\n\t\t\tx[ iy-2 ] = tmp;\n\n\t\t\tix += M;\n\t\t\tiy -= M;\n\t\t}\n\t\treturn x;\n\t}\n\tiy = ix + ( ( N-1 ) * strideX );\n\tfor ( i = 0; i < n; i++ ) {\n\t\ttmp = x[ ix ];\n\t\tx[ ix ] = x[ iy ];\n\t\tx[ iy ] = tmp;\n\t\tix += strideX;\n\t\tiy -= strideX;\n\t}\n\treturn x;\n}\n\n\n// EXPORTS //\n\nmodule.exports = srev;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar stride2offset = require( '@stdlib/strided-base-stride2offset' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\n/**\n* Reverses a single-precision floating-point strided array in-place.\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {Float32Array} x - input array\n* @param {integer} strideX - stride length\n* @returns {Float32Array} input array\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );\n*\n* srev( x.length, x, 1 );\n* // x => <Float32Array>[ -3.0, -1.0, 0.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]\n*/\nfunction srev( N, x, strideX ) {\n\treturn ndarray( N, x, strideX, stride2offset( N, strideX ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = srev;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar srev = require( './srev.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( srev, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = srev;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Reverse a single-precision floating-point strided array in-place.\n*\n* @module @stdlib/blas-ext-base-srev\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var srev = require( '@stdlib/blas-ext-base-srev' );\n*\n* var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );\n*\n* srev( x.length, x, 1 );\n* // x => <Float32Array>[ -3.0, -1.0, 0.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var srev = require( '@stdlib/blas-ext-base-srev' );\n*\n* var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );\n*\n* srev( x.length, x, 1, 0 );\n* // x => <Float32Array>[ -3.0, -1.0, 0.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar srev;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tsrev = main;\n} else {\n\tsrev = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = srev;\n\n// exports: { \"ndarray\": \"srev.ndarray\" }\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EAKnDC,EAAI,EAsBR,SAASC,EAAMC,EAAGC,EAAGC,EAASC,EAAU,CACvC,IAAIC,EACAC,EACAC,EACAC,EACA,EACAC,EAEJ,GAAKR,GAAK,EACT,OAAOC,EAMR,GAJA,EAAIJ,EAAOG,EAAE,CAAE,EACfK,EAAKF,EAGAD,IAAY,EAAI,CAKpB,GAJAK,EAAI,EAAIT,EACRQ,EAAKD,EAAKL,EAAI,EAGTO,EAAI,EACR,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IACnBJ,EAAMH,EAAGI,CAAG,EACZJ,EAAGI,CAAG,EAAIJ,EAAGK,CAAG,EAChBL,EAAGK,CAAG,EAAIF,EACVC,GAAMH,EACNI,GAAMJ,EAGR,GAAK,EAAIJ,EACR,OAAOG,EAER,IAAMO,EAAID,EAAGC,EAAI,EAAGA,GAAKV,EACxBM,EAAMH,EAAGI,CAAG,EACZJ,EAAGI,CAAG,EAAIJ,EAAGK,CAAG,EAChBL,EAAGK,CAAG,EAAIF,EAEVA,EAAMH,EAAGI,EAAG,CAAE,EACdJ,EAAGI,EAAG,CAAE,EAAIJ,EAAGK,EAAG,CAAE,EACpBL,EAAGK,EAAG,CAAE,EAAIF,EAEZA,EAAMH,EAAGI,EAAG,CAAE,EACdJ,EAAGI,EAAG,CAAE,EAAIJ,EAAGK,EAAG,CAAE,EACpBL,EAAGK,EAAG,CAAE,EAAIF,EAEZC,GAAMP,EACNQ,GAAMR,EAEP,OAAOG,CACR,CAEA,IADAK,EAAKD,GAASL,EAAE,GAAME,EAChBM,EAAI,EAAGA,EAAI,EAAGA,IACnBJ,EAAMH,EAAGI,CAAG,EACZJ,EAAGI,CAAG,EAAIJ,EAAGK,CAAG,EAChBL,EAAGK,CAAG,EAAIF,EACVC,GAAMH,EACNI,GAAMJ,EAEP,OAAOD,CACR,CAKAL,EAAO,QAAUG,ICjHjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,oCAAqC,EAC9DC,EAAU,IAqBd,SAASC,EAAMC,EAAGC,EAAGC,EAAU,CAC9B,OAAOJ,EAASE,EAAGC,EAAGC,EAASL,EAAeG,EAAGE,CAAQ,CAAE,CAC5D,CAKAN,EAAO,QAAUG,ICnDjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtCH,EAAO,QAAUE,ICYjB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAAOD,EAEPC,EAAOC,EAMR,OAAO,QAAUD",
|
|
6
|
+
"names": ["require_ndarray", "__commonJSMin", "exports", "module", "floor", "M", "srev", "N", "x", "strideX", "offsetX", "tmp", "ix", "iy", "m", "i", "require_srev", "__commonJSMin", "exports", "module", "stride2offset", "ndarray", "srev", "N", "x", "strideX", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "srev", "ndarray", "join", "tryRequire", "isError", "main", "srev", "tmp"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ interface Routine {
|
|
|
27
27
|
*
|
|
28
28
|
* @param N - number of indexed elements
|
|
29
29
|
* @param x - input array
|
|
30
|
-
* @param
|
|
30
|
+
* @param strideX - stride length
|
|
31
31
|
* @returns input array
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
@@ -38,15 +38,15 @@ interface Routine {
|
|
|
38
38
|
* srev( x.length, x, 1 );
|
|
39
39
|
* // x => <Float32Array>[ -3.0, -1.0, 0.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]
|
|
40
40
|
*/
|
|
41
|
-
( N: number, x: Float32Array,
|
|
41
|
+
( N: number, x: Float32Array, strideX: number ): Float32Array;
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Reverses a single-precision floating-point strided array in-place. using alternative indexing semantics.
|
|
45
45
|
*
|
|
46
46
|
* @param N - number of indexed elements
|
|
47
47
|
* @param x - input array
|
|
48
|
-
* @param
|
|
49
|
-
* @param
|
|
48
|
+
* @param strideX - stride length
|
|
49
|
+
* @param offsetX - starting index
|
|
50
50
|
* @returns input array
|
|
51
51
|
*
|
|
52
52
|
* @example
|
|
@@ -57,7 +57,7 @@ interface Routine {
|
|
|
57
57
|
* srev.ndarray( x.length, x, 1, 0 );
|
|
58
58
|
* // x => <Float32Array>[ -3.0, -1.0, 0.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]
|
|
59
59
|
*/
|
|
60
|
-
ndarray( N: number, x: Float32Array,
|
|
60
|
+
ndarray( N: number, x: Float32Array, strideX: number, offsetX: number ): Float32Array;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -65,7 +65,7 @@ interface Routine {
|
|
|
65
65
|
*
|
|
66
66
|
* @param N - number of indexed elements
|
|
67
67
|
* @param x - input array
|
|
68
|
-
* @param
|
|
68
|
+
* @param strideX - stride length
|
|
69
69
|
* @returns input array
|
|
70
70
|
*
|
|
71
71
|
* @example
|
|
@@ -16,13 +16,10 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Header file containing function declarations.
|
|
21
|
-
*/
|
|
22
19
|
#ifndef STDLIB_BLAS_EXT_BASE_SREV_H
|
|
23
20
|
#define STDLIB_BLAS_EXT_BASE_SREV_H
|
|
24
21
|
|
|
25
|
-
#include
|
|
22
|
+
#include "stdlib/blas/base/shared.h"
|
|
26
23
|
|
|
27
24
|
/*
|
|
28
25
|
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
@@ -34,7 +31,12 @@ extern "C" {
|
|
|
34
31
|
/**
|
|
35
32
|
* Reverses a single-precision floating-point strided array in-place.
|
|
36
33
|
*/
|
|
37
|
-
void
|
|
34
|
+
void API_SUFFIX(stdlib_strided_srev)( const CBLAS_INT N, float *X, const CBLAS_INT strideX );
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Reverses a single-precision floating-point strided array in-place using alternative indexing semantics.
|
|
38
|
+
*/
|
|
39
|
+
void API_SUFFIX(stdlib_strided_srev_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
|
|
38
40
|
|
|
39
41
|
#ifdef __cplusplus
|
|
40
42
|
}
|
package/lib/ndarray.js
CHANGED
|
@@ -35,8 +35,8 @@ var M = 3;
|
|
|
35
35
|
*
|
|
36
36
|
* @param {PositiveInteger} N - number of indexed elements
|
|
37
37
|
* @param {Float32Array} x - input array
|
|
38
|
-
* @param {integer}
|
|
39
|
-
* @param {NonNegativeInteger}
|
|
38
|
+
* @param {integer} strideX - stride length
|
|
39
|
+
* @param {NonNegativeInteger} offsetX - starting index
|
|
40
40
|
* @returns {Float32Array} input array
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
@@ -47,7 +47,7 @@ var M = 3;
|
|
|
47
47
|
* srev( 3, x, 1, x.length-3 );
|
|
48
48
|
* // x => <Float32Array>[ 1.0, -2.0, 3.0, -6.0, 5.0, -4.0 ]
|
|
49
49
|
*/
|
|
50
|
-
function srev( N, x,
|
|
50
|
+
function srev( N, x, strideX, offsetX ) {
|
|
51
51
|
var tmp;
|
|
52
52
|
var ix;
|
|
53
53
|
var iy;
|
|
@@ -59,10 +59,10 @@ function srev( N, x, stride, offset ) {
|
|
|
59
59
|
return x;
|
|
60
60
|
}
|
|
61
61
|
n = floor( N/2 );
|
|
62
|
-
ix =
|
|
62
|
+
ix = offsetX;
|
|
63
63
|
|
|
64
64
|
// Use loop unrolling if the stride is equal to `1`...
|
|
65
|
-
if (
|
|
65
|
+
if ( strideX === 1 ) {
|
|
66
66
|
m = n % M;
|
|
67
67
|
iy = ix + N - 1;
|
|
68
68
|
|
|
@@ -72,8 +72,8 @@ function srev( N, x, stride, offset ) {
|
|
|
72
72
|
tmp = x[ ix ];
|
|
73
73
|
x[ ix ] = x[ iy ];
|
|
74
74
|
x[ iy ] = tmp;
|
|
75
|
-
ix +=
|
|
76
|
-
iy -=
|
|
75
|
+
ix += strideX;
|
|
76
|
+
iy -= strideX;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
if ( n < M ) {
|
|
@@ -97,13 +97,13 @@ function srev( N, x, stride, offset ) {
|
|
|
97
97
|
}
|
|
98
98
|
return x;
|
|
99
99
|
}
|
|
100
|
-
iy = ix + ((N-1)*
|
|
100
|
+
iy = ix + ( ( N-1 ) * strideX );
|
|
101
101
|
for ( i = 0; i < n; i++ ) {
|
|
102
102
|
tmp = x[ ix ];
|
|
103
103
|
x[ ix ] = x[ iy ];
|
|
104
104
|
x[ iy ] = tmp;
|
|
105
|
-
ix +=
|
|
106
|
-
iy -=
|
|
105
|
+
ix += strideX;
|
|
106
|
+
iy -= strideX;
|
|
107
107
|
}
|
|
108
108
|
return x;
|
|
109
109
|
}
|
package/lib/ndarray.native.js
CHANGED
|
@@ -20,9 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
var offsetView = require( '@stdlib/strided-base-offset-view' );
|
|
25
|
-
var addon = require( './srev.native.js' );
|
|
23
|
+
var addon = require( './../src/addon.node' );
|
|
26
24
|
|
|
27
25
|
|
|
28
26
|
// MAIN //
|
|
@@ -32,8 +30,8 @@ var addon = require( './srev.native.js' );
|
|
|
32
30
|
*
|
|
33
31
|
* @param {PositiveInteger} N - number of indexed elements
|
|
34
32
|
* @param {Float32Array} x - input array
|
|
35
|
-
* @param {integer}
|
|
36
|
-
* @param {NonNegativeInteger}
|
|
33
|
+
* @param {integer} strideX - stride length
|
|
34
|
+
* @param {NonNegativeInteger} offsetX - starting index
|
|
37
35
|
* @returns {Float32Array} input array
|
|
38
36
|
*
|
|
39
37
|
* @example
|
|
@@ -44,13 +42,8 @@ var addon = require( './srev.native.js' );
|
|
|
44
42
|
* srev( 3, x, 1, x.length-3 );
|
|
45
43
|
* // x => <Float32Array>[ 1.0, -2.0, 3.0, -6.0, 5.0, -4.0 ]
|
|
46
44
|
*/
|
|
47
|
-
function srev( N, x,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
offset = minViewBufferIndex( N, stride, offset );
|
|
51
|
-
view = offsetView( x, offset );
|
|
52
|
-
|
|
53
|
-
addon( N, view, stride );
|
|
45
|
+
function srev( N, x, strideX, offsetX ) {
|
|
46
|
+
addon.ndarray( N, x, strideX, offsetX );
|
|
54
47
|
return x;
|
|
55
48
|
}
|
|
56
49
|
|
package/lib/srev.js
CHANGED
|
@@ -20,12 +20,8 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// VARIABLES //
|
|
27
|
-
|
|
28
|
-
var M = 3;
|
|
23
|
+
var stride2offset = require( '@stdlib/strided-base-stride2offset' );
|
|
24
|
+
var ndarray = require( './ndarray.js' );
|
|
29
25
|
|
|
30
26
|
|
|
31
27
|
// MAIN //
|
|
@@ -35,7 +31,7 @@ var M = 3;
|
|
|
35
31
|
*
|
|
36
32
|
* @param {PositiveInteger} N - number of indexed elements
|
|
37
33
|
* @param {Float32Array} x - input array
|
|
38
|
-
* @param {integer}
|
|
34
|
+
* @param {integer} strideX - stride length
|
|
39
35
|
* @returns {Float32Array} input array
|
|
40
36
|
*
|
|
41
37
|
* @example
|
|
@@ -46,67 +42,8 @@ var M = 3;
|
|
|
46
42
|
* srev( x.length, x, 1 );
|
|
47
43
|
* // x => <Float32Array>[ -3.0, -1.0, 0.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]
|
|
48
44
|
*/
|
|
49
|
-
function srev( N, x,
|
|
50
|
-
|
|
51
|
-
var ix;
|
|
52
|
-
var iy;
|
|
53
|
-
var m;
|
|
54
|
-
var n;
|
|
55
|
-
var i;
|
|
56
|
-
|
|
57
|
-
if ( N <= 0 ) {
|
|
58
|
-
return x;
|
|
59
|
-
}
|
|
60
|
-
n = floor( N/2 );
|
|
61
|
-
|
|
62
|
-
// Use loop unrolling if the stride is equal to `1`...
|
|
63
|
-
if ( stride === 1 ) {
|
|
64
|
-
m = n % M;
|
|
65
|
-
iy = N - 1;
|
|
66
|
-
|
|
67
|
-
// If we have a remainder, run a clean-up loop...
|
|
68
|
-
if ( m > 0 ) {
|
|
69
|
-
for ( ix = 0; ix < m; ix++ ) {
|
|
70
|
-
tmp = x[ ix ];
|
|
71
|
-
x[ ix ] = x[ iy ];
|
|
72
|
-
x[ iy ] = tmp;
|
|
73
|
-
iy -= 1;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if ( n < M ) {
|
|
77
|
-
return x;
|
|
78
|
-
}
|
|
79
|
-
for ( ix = m; ix < n; ix += M ) {
|
|
80
|
-
tmp = x[ ix ];
|
|
81
|
-
x[ ix ] = x[ iy ];
|
|
82
|
-
x[ iy ] = tmp;
|
|
83
|
-
|
|
84
|
-
tmp = x[ ix+1 ];
|
|
85
|
-
x[ ix+1 ] = x[ iy-1 ];
|
|
86
|
-
x[ iy-1 ] = tmp;
|
|
87
|
-
|
|
88
|
-
tmp = x[ ix+2 ];
|
|
89
|
-
x[ ix+2 ] = x[ iy-2 ];
|
|
90
|
-
x[ iy-2 ] = tmp;
|
|
91
|
-
|
|
92
|
-
iy -= M;
|
|
93
|
-
}
|
|
94
|
-
return x;
|
|
95
|
-
}
|
|
96
|
-
if ( stride < 0 ) {
|
|
97
|
-
ix = (1-N) * stride;
|
|
98
|
-
} else {
|
|
99
|
-
ix = 0;
|
|
100
|
-
}
|
|
101
|
-
iy = ix + ((N-1)*stride);
|
|
102
|
-
for ( i = 0; i < n; i++ ) {
|
|
103
|
-
tmp = x[ ix ];
|
|
104
|
-
x[ ix ] = x[ iy ];
|
|
105
|
-
x[ iy ] = tmp;
|
|
106
|
-
ix += stride;
|
|
107
|
-
iy -= stride;
|
|
108
|
-
}
|
|
109
|
-
return x;
|
|
45
|
+
function srev( N, x, strideX ) {
|
|
46
|
+
return ndarray( N, x, strideX, stride2offset( N, strideX ) );
|
|
110
47
|
}
|
|
111
48
|
|
|
112
49
|
|
package/lib/srev.native.js
CHANGED
|
@@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' );
|
|
|
30
30
|
*
|
|
31
31
|
* @param {PositiveInteger} N - number of indexed elements
|
|
32
32
|
* @param {Float32Array} x - input array
|
|
33
|
-
* @param {integer}
|
|
33
|
+
* @param {integer} strideX - stride length
|
|
34
34
|
* @returns {Float32Array} input array
|
|
35
35
|
*
|
|
36
36
|
* @example
|
|
@@ -41,8 +41,8 @@ var addon = require( './../src/addon.node' );
|
|
|
41
41
|
* srev( x.length, x, 1 );
|
|
42
42
|
* // x => <Float32Array>[ -3.0, -1.0, 0.0, 4.0, -5.0, 3.0, 1.0, -2.0 ]
|
|
43
43
|
*/
|
|
44
|
-
function srev( N, x,
|
|
45
|
-
addon( N, x,
|
|
44
|
+
function srev( N, x, strideX ) {
|
|
45
|
+
addon( N, x, strideX );
|
|
46
46
|
return x;
|
|
47
47
|
}
|
|
48
48
|
|
package/manifest.json
CHANGED
|
@@ -28,49 +28,51 @@
|
|
|
28
28
|
{
|
|
29
29
|
"task": "build",
|
|
30
30
|
"src": [
|
|
31
|
-
"./src/
|
|
31
|
+
"./src/main.c"
|
|
32
32
|
],
|
|
33
33
|
"include": [
|
|
34
34
|
"./include"
|
|
35
35
|
],
|
|
36
|
-
"libraries": [
|
|
37
|
-
"-lm"
|
|
38
|
-
],
|
|
36
|
+
"libraries": [],
|
|
39
37
|
"libpath": [],
|
|
40
38
|
"dependencies": [
|
|
41
39
|
"@stdlib/napi-export",
|
|
42
40
|
"@stdlib/napi-argv",
|
|
43
41
|
"@stdlib/napi-argv-int64",
|
|
44
|
-
"@stdlib/napi-argv-strided-float32array"
|
|
42
|
+
"@stdlib/napi-argv-strided-float32array",
|
|
43
|
+
"@stdlib/strided-base-stride2offset",
|
|
44
|
+
"@stdlib/blas-base-shared"
|
|
45
45
|
]
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
"task": "benchmark",
|
|
49
49
|
"src": [
|
|
50
|
-
"./src/
|
|
50
|
+
"./src/main.c"
|
|
51
51
|
],
|
|
52
52
|
"include": [
|
|
53
53
|
"./include"
|
|
54
54
|
],
|
|
55
|
-
"libraries": [
|
|
56
|
-
"-lm"
|
|
57
|
-
],
|
|
55
|
+
"libraries": [],
|
|
58
56
|
"libpath": [],
|
|
59
|
-
"dependencies": [
|
|
57
|
+
"dependencies": [
|
|
58
|
+
"@stdlib/strided-base-stride2offset",
|
|
59
|
+
"@stdlib/blas-base-shared"
|
|
60
|
+
]
|
|
60
61
|
},
|
|
61
62
|
{
|
|
62
63
|
"task": "examples",
|
|
63
64
|
"src": [
|
|
64
|
-
"./src/
|
|
65
|
+
"./src/main.c"
|
|
65
66
|
],
|
|
66
67
|
"include": [
|
|
67
68
|
"./include"
|
|
68
69
|
],
|
|
69
|
-
"libraries": [
|
|
70
|
-
"-lm"
|
|
71
|
-
],
|
|
70
|
+
"libraries": [],
|
|
72
71
|
"libpath": [],
|
|
73
|
-
"dependencies": [
|
|
72
|
+
"dependencies": [
|
|
73
|
+
"@stdlib/strided-base-stride2offset",
|
|
74
|
+
"@stdlib/blas-base-shared"
|
|
75
|
+
]
|
|
74
76
|
}
|
|
75
77
|
]
|
|
76
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/blas-ext-base-srev",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Reverse a single-precision floating-point strided array in-place.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -35,13 +35,15 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@stdlib/assert-is-error": "^0.2.2",
|
|
38
|
+
"@stdlib/blas-base-shared": "^0.1.0",
|
|
38
39
|
"@stdlib/math-base-special-floor": "^0.2.3",
|
|
39
40
|
"@stdlib/napi-argv": "^0.2.2",
|
|
40
41
|
"@stdlib/napi-argv-int64": "^0.2.2",
|
|
41
42
|
"@stdlib/napi-argv-strided-float32array": "^0.2.2",
|
|
42
|
-
"@stdlib/napi-export": "^0.
|
|
43
|
+
"@stdlib/napi-export": "^0.3.0",
|
|
44
|
+
"@stdlib/strided-base-stride2offset": "^0.1.0",
|
|
43
45
|
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
44
|
-
"@stdlib/utils-library-manifest": "^0.2.
|
|
46
|
+
"@stdlib/utils-library-manifest": "^0.2.3",
|
|
45
47
|
"@stdlib/utils-try-require": "^0.2.2"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {},
|
|
@@ -79,9 +81,6 @@
|
|
|
79
81
|
"single",
|
|
80
82
|
"float32array"
|
|
81
83
|
],
|
|
82
|
-
"__stdlib__": {
|
|
83
|
-
"wasm": false
|
|
84
|
-
},
|
|
85
84
|
"funding": {
|
|
86
85
|
"type": "opencollective",
|
|
87
86
|
"url": "https://opencollective.com/stdlib"
|
package/src/addon.c
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
#include "stdlib/blas/ext/base/srev.h"
|
|
20
|
+
#include "stdlib/blas/base/shared.h"
|
|
20
21
|
#include "stdlib/napi/export.h"
|
|
21
22
|
#include "stdlib/napi/argv.h"
|
|
22
23
|
#include "stdlib/napi/argv_int64.h"
|
|
@@ -33,10 +34,27 @@
|
|
|
33
34
|
static napi_value addon( napi_env env, napi_callback_info info ) {
|
|
34
35
|
STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
|
|
35
36
|
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
36
|
-
STDLIB_NAPI_ARGV_INT64( env,
|
|
37
|
-
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N,
|
|
38
|
-
|
|
37
|
+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
|
|
38
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
|
|
39
|
+
API_SUFFIX(stdlib_strided_srev)( N, X, strideX );
|
|
39
40
|
return NULL;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Receives JavaScript callback invocation data.
|
|
45
|
+
*
|
|
46
|
+
* @param env environment under which the function is invoked
|
|
47
|
+
* @param info callback data
|
|
48
|
+
* @return Node-API value
|
|
49
|
+
*/
|
|
50
|
+
static napi_value addon_method( napi_env env, napi_callback_info info ) {
|
|
51
|
+
STDLIB_NAPI_ARGV( env, info, argv, argc, 4 );
|
|
52
|
+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
53
|
+
STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 );
|
|
54
|
+
STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 );
|
|
55
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 );
|
|
56
|
+
API_SUFFIX(stdlib_strided_srev_ndarray)( N, X, strideX, offsetX );
|
|
57
|
+
return NULL;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method );
|
package/src/{srev.c → main.c}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license Apache-2.0
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
5
|
*
|
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
7
|
* you may not use this file except in compliance with the License.
|
|
@@ -17,46 +17,62 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
#include "stdlib/blas/ext/base/srev.h"
|
|
20
|
-
#include
|
|
20
|
+
#include "stdlib/blas/base/shared.h"
|
|
21
|
+
#include "stdlib/strided/base/stride2offset.h"
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Reverses a single-precision floating-point strided array in-place.
|
|
24
25
|
*
|
|
25
|
-
* @param N
|
|
26
|
-
* @param X
|
|
27
|
-
* @param stride
|
|
26
|
+
* @param N number of indexed elements
|
|
27
|
+
* @param X input array
|
|
28
|
+
* @param strideX stride length
|
|
28
29
|
*/
|
|
29
|
-
void
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
void API_SUFFIX(stdlib_strided_srev)( const CBLAS_INT N, float *X, const CBLAS_INT strideX ) {
|
|
31
|
+
const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
|
|
32
|
+
API_SUFFIX(stdlib_strided_srev_ndarray)( N, X, strideX, ox );
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Reverses a single-precision floating-point strided array in-place using alternative indexing semantics.
|
|
37
|
+
*
|
|
38
|
+
* @param N number of indexed elements
|
|
39
|
+
* @param X input array
|
|
40
|
+
* @param strideX stride length
|
|
41
|
+
* @param offsetX stride length
|
|
42
|
+
*/
|
|
43
|
+
void API_SUFFIX(stdlib_strided_srev_ndarray)( const CBLAS_INT N, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) {
|
|
44
|
+
CBLAS_INT ix;
|
|
45
|
+
CBLAS_INT iy;
|
|
46
|
+
CBLAS_INT m;
|
|
47
|
+
CBLAS_INT n;
|
|
48
|
+
CBLAS_INT i;
|
|
35
49
|
float tmp;
|
|
36
50
|
|
|
37
51
|
if ( N <= 0 ) {
|
|
38
52
|
return;
|
|
39
53
|
}
|
|
40
54
|
n = N / 2;
|
|
55
|
+
ix = offsetX;
|
|
41
56
|
|
|
42
57
|
// Use loop unrolling if the stride is equal to `1`...
|
|
43
|
-
if (
|
|
58
|
+
if ( strideX == 1 ) {
|
|
44
59
|
m = n % 3;
|
|
45
|
-
iy = N - 1;
|
|
60
|
+
iy = ix + N - 1;
|
|
46
61
|
|
|
47
62
|
// If we have a remainder, run a clean-up loop...
|
|
48
63
|
if ( m > 0 ) {
|
|
49
|
-
for (
|
|
64
|
+
for ( i = 0; i < m; i++ ) {
|
|
50
65
|
tmp = X[ ix ];
|
|
51
66
|
X[ ix ] = X[ iy ];
|
|
52
67
|
X[ iy ] = tmp;
|
|
53
|
-
|
|
68
|
+
ix += strideX;
|
|
69
|
+
iy -= strideX;
|
|
54
70
|
}
|
|
55
71
|
}
|
|
56
72
|
if ( n < 3 ) {
|
|
57
73
|
return;
|
|
58
74
|
}
|
|
59
|
-
for (
|
|
75
|
+
for ( i = m; i < n; i += 3 ) {
|
|
60
76
|
tmp = X[ ix ];
|
|
61
77
|
X[ ix ] = X[ iy ];
|
|
62
78
|
X[ iy ] = tmp;
|
|
@@ -69,22 +85,18 @@ void c_srev( const int64_t N, float *X, const int64_t stride ) {
|
|
|
69
85
|
X[ ix+2 ] = X[ iy-2 ];
|
|
70
86
|
X[ iy-2 ] = tmp;
|
|
71
87
|
|
|
88
|
+
ix += 3;
|
|
72
89
|
iy -= 3;
|
|
73
90
|
}
|
|
74
91
|
return;
|
|
75
92
|
}
|
|
76
|
-
|
|
77
|
-
ix = (1-N) * stride;
|
|
78
|
-
} else {
|
|
79
|
-
ix = 0;
|
|
80
|
-
}
|
|
81
|
-
iy = ix + ((N-1)*stride);
|
|
93
|
+
iy = ix + ( (N-1) * strideX );
|
|
82
94
|
for ( i = 0; i < n; i++ ) {
|
|
83
95
|
tmp = X[ ix ];
|
|
84
96
|
X[ ix ] = X[ iy ];
|
|
85
97
|
X[ iy ] = tmp;
|
|
86
|
-
ix +=
|
|
87
|
-
iy -=
|
|
98
|
+
ix += strideX;
|
|
99
|
+
iy -= strideX;
|
|
88
100
|
}
|
|
89
101
|
return;
|
|
90
102
|
}
|