@stdlib/blas-ext-base-srev 0.2.1 → 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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
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, stride )
56
+ #### srev( N, x, strideX )
57
57
 
58
- Reverses a single-precision floating-point strided array `x` in-place.
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,18 +70,16 @@ The function has the following parameters:
70
70
 
71
71
  - **N**: number of indexed elements.
72
72
  - **x**: input [`Float32Array`][@stdlib/array/float32].
73
- - **stride**: index increment.
73
+ - **strideX**: stride length.
74
74
 
75
- The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to reverse every other element
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' );
79
- var floor = require( '@stdlib/math-base-special-floor' );
80
79
 
81
80
  var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] );
82
- var N = floor( x.length / 2 );
83
81
 
84
- srev( N, x, 2 );
82
+ srev( 4, x, 2 );
85
83
  // x => <Float32Array>[ -1.0, 1.0, 4.0, -5.0, 3.0, 0.0, -2.0, -3.0 ]
86
84
  ```
87
85
 
@@ -89,23 +87,21 @@ Note that indexing is relative to the first index. To introduce an offset, use [
89
87
 
90
88
  ```javascript
91
89
  var Float32Array = require( '@stdlib/array-float32' );
92
- var floor = require( '@stdlib/math-base-special-floor' );
93
90
 
94
91
  // Initial array...
95
92
  var x0 = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
96
93
 
97
94
  // Create an offset view...
98
95
  var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
99
- var N = floor( x0.length/2 );
100
96
 
101
97
  // Reverse every other element...
102
- srev( N, x1, 2 );
98
+ srev( 3, x1, 2 );
103
99
  // x0 => <Float32Array>[ 1.0, -6.0, 3.0, -4.0, 5.0, -2.0 ]
104
100
  ```
105
101
 
106
- #### srev.ndarray( N, x, stride, offset )
102
+ #### srev.ndarray( N, x, strideX, offsetX )
107
103
 
108
- Reverses a single-precision floating-point strided array `x` in-place using alternative indexing semantics.
104
+ Reverses a single-precision floating-point strided array in-place using alternative indexing semantics.
109
105
 
110
106
  ```javascript
111
107
  var Float32Array = require( '@stdlib/array-float32' );
@@ -118,9 +114,9 @@ srev.ndarray( x.length, x, 1, 0 );
118
114
 
119
115
  The function has the following additional parameters:
120
116
 
121
- - **offset**: starting index.
117
+ - **offsetX**: starting index.
122
118
 
123
- 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 `x`
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:
124
120
 
125
121
  ```javascript
126
122
  var Float32Array = require( '@stdlib/array-float32' );
@@ -139,7 +135,7 @@ srev.ndarray( 3, x, 1, x.length-3 );
139
135
 
140
136
  ## Notes
141
137
 
142
- - If `N <= 0`, both functions return `x` unchanged.
138
+ - If `N <= 0`, both functions return the strided array unchanged.
143
139
  - Where possible, one should "reverse" a strided array by negating its stride, which is an `O(1)` operation, in contrast to performing an in-place reversal, which is `O(N)`. However, in certain circumstances, this is not tenable, particularly when interfacing with libraries which assume and/or expect a specific memory layout (e.g., strided array elements arranged in memory in ascending order). In general, when working with strided arrays, only perform an in-place reversal when strictly necessary.
144
140
 
145
141
  </section>
@@ -153,27 +149,12 @@ srev.ndarray( 3, x, 1, x.length-3 );
153
149
  <!-- eslint no-undef: "error" -->
154
150
 
155
151
  ```javascript
156
- var round = require( '@stdlib/math-base-special-round' );
157
- var randu = require( '@stdlib/random-base-randu' );
158
- var Float32Array = require( '@stdlib/array-float32' );
152
+ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
159
153
  var srev = require( '@stdlib/blas-ext-base-srev' );
160
154
 
161
- var rand;
162
- var sign;
163
- var x;
164
- var i;
165
-
166
- x = new Float32Array( 10 );
167
- for ( i = 0; i < x.length; i++ ) {
168
- rand = round( randu()*100.0 );
169
- sign = randu();
170
- if ( sign < 0.5 ) {
171
- sign = -1.0;
172
- } else {
173
- sign = 1.0;
174
- }
175
- x[ i ] = sign * rand;
176
- }
155
+ var x = discreteUniform( 10, -100, 100, {
156
+ 'dtype': 'float32'
157
+ });
177
158
  console.log( x );
178
159
 
179
160
  srev( x.length, x, 1 );
@@ -184,6 +165,123 @@ console.log( x );
184
165
 
185
166
  <!-- /.examples -->
186
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
+
187
285
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
188
286
 
189
287
  <section class="related">
@@ -225,7 +323,7 @@ See [LICENSE][stdlib-license].
225
323
 
226
324
  ## Copyright
227
325
 
228
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
326
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
229
327
 
230
328
  </section>
231
329
 
@@ -238,8 +336,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
238
336
  [npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-srev.svg
239
337
  [npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-srev
240
338
 
241
- [test-image]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml/badge.svg?branch=v0.2.1
242
- [test-url]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml?query=branch:v0.2.1
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
243
341
 
244
342
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-srev/main.svg
245
343
  [coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-srev?branch=main
@@ -251,8 +349,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
251
349
 
252
350
  -->
253
351
 
254
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
255
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
352
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
353
+ [chat-url]: https://stdlib.zulipchat.com
256
354
 
257
355
  [stdlib]: https://github.com/stdlib-js/stdlib
258
356
 
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";var m=function(u,r){return function(){return r||u((r={exports:{}}).exports,r),r.exports}};var y=m(function(F,c){
2
- var O=require('@stdlib/math-base-special-floor/dist'),q=3;function b(u,r,i){var n,a,e,v,f,o;if(u<=0)return r;if(f=O(u/2),i===1){if(v=f%q,e=u-1,v>0)for(a=0;a<v;a++)n=r[a],r[a]=r[e],r[e]=n,e-=1;if(f<q)return r;for(a=v;a<f;a+=q)n=r[a],r[a]=r[e],r[e]=n,n=r[a+1],r[a+1]=r[e-1],r[e-1]=n,n=r[a+2],r[a+2]=r[e-2],r[e-2]=n,e-=q;return r}for(i<0?a=(1-u)*i:a=0,e=a+(u-1)*i,o=0;o<f;o++)n=r[a],r[a]=r[e],r[e]=n,a+=i,e-=i;return r}c.exports=b
3
- });var j=m(function(G,l){
4
- var g=require('@stdlib/math-base-special-floor/dist'),s=3;function h(u,r,i,n){var a,e,v,f,o,t;if(u<=0)return r;if(o=g(u/2),e=n,i===1){if(f=o%s,v=e+u-1,f>0)for(t=0;t<f;t++)a=r[e],r[e]=r[v],r[v]=a,e+=i,v-=i;if(o<s)return r;for(t=f;t<o;t+=s)a=r[e],r[e]=r[v],r[v]=a,a=r[e+1],r[e+1]=r[v-1],r[v-1]=a,a=r[e+2],r[e+2]=r[v-2],r[v-2]=a,e+=s,v-=s;return r}for(v=e+(u-1)*i,t=0;t<o;t++)a=r[e],r[e]=r[v],r[v]=a,e+=i,v-=i;return r}l.exports=h
5
- });var _=m(function(H,R){
6
- var k=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),M=y(),w=j();k(M,"ndarray",w);R.exports=M
7
- });var z=require("path").join,A=require('@stdlib/utils-try-require/dist'),B=require('@stdlib/assert-is-error/dist'),C=_(),p,E=A(z(__dirname,"./native.js"));B(E)?p=C:p=E;module.exports=p;
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/srev.js", "../lib/ndarray.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} stride - index increment\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, stride ) {\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\n\t// Use loop unrolling if the stride is equal to `1`...\n\tif ( stride === 1 ) {\n\t\tm = n % M;\n\t\tiy = 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 ( ix = 0; ix < m; ix++ ) {\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\tiy -= 1;\n\t\t\t}\n\t\t}\n\t\tif ( n < M ) {\n\t\t\treturn x;\n\t\t}\n\t\tfor ( ix = m; ix < n; ix += 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\tiy -= M;\n\t\t}\n\t\treturn x;\n\t}\n\tif ( stride < 0 ) {\n\t\tix = (1-N) * stride;\n\t} else {\n\t\tix = 0;\n\t}\n\tiy = ix + ((N-1)*stride);\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 += stride;\n\t\tiy -= stride;\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 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 increment\n* @param {NonNegativeInteger} offset - 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, stride, offset ) {\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 = offset;\n\n\t// Use loop unrolling if the stride is equal to `1`...\n\tif ( stride === 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 += stride;\n\t\t\t\tiy -= stride;\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)*stride);\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 += stride;\n\t\tiy -= stride;\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 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": "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",
6
- "names": ["require_srev", "__commonJSMin", "exports", "module", "floor", "M", "srev", "N", "x", "stride", "tmp", "ix", "iy", "m", "n", "i", "require_ndarray", "__commonJSMin", "exports", "module", "floor", "M", "srev", "N", "x", "stride", "offset", "tmp", "ix", "iy", "m", "n", "i", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "srev", "ndarray", "join", "tryRequire", "isError", "main", "srev", "tmp"]
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
  }
@@ -27,8 +27,8 @@ interface Routine {
27
27
  *
28
28
  * @param N - number of indexed elements
29
29
  * @param x - input array
30
- * @param stride - stride length
31
- * @returns `x`
30
+ * @param strideX - stride length
31
+ * @returns input array
32
32
  *
33
33
  * @example
34
34
  * var Float32Array = require( '@stdlib/array-float32' );
@@ -38,16 +38,16 @@ 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, stride: number ): 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 stride - stride length
49
- * @param offset - starting index
50
- * @returns `x`
48
+ * @param strideX - stride length
49
+ * @param offsetX - starting index
50
+ * @returns input array
51
51
  *
52
52
  * @example
53
53
  * var Float32Array = require( '@stdlib/array-float32' );
@@ -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, stride: number, offset: number ): Float32Array;
60
+ ndarray( N: number, x: Float32Array, strideX: number, offsetX: number ): Float32Array;
61
61
  }
62
62
 
63
63
  /**
@@ -65,8 +65,8 @@ interface Routine {
65
65
  *
66
66
  * @param N - number of indexed elements
67
67
  * @param x - input array
68
- * @param stride - stride length
69
- * @returns `x`
68
+ * @param strideX - stride length
69
+ * @returns input array
70
70
  *
71
71
  * @example
72
72
  * var Float32Array = require( '@stdlib/array-float32' );
@@ -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 <stdint.h>
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 c_srev( const int64_t N, float *X, const int64_t stride );
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} stride - index increment
39
- * @param {NonNegativeInteger} offset - starting index
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, stride, offset ) {
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 = offset;
62
+ ix = offsetX;
63
63
 
64
64
  // Use loop unrolling if the stride is equal to `1`...
65
- if ( stride === 1 ) {
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 += stride;
76
- iy -= stride;
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)*stride);
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 += stride;
106
- iy -= stride;
105
+ ix += strideX;
106
+ iy -= strideX;
107
107
  }
108
108
  return x;
109
109
  }
@@ -20,8 +20,7 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var Float32Array = require( '@stdlib/array-float32' );
24
- var addon = require( './srev.native.js' );
23
+ var addon = require( './../src/addon.node' );
25
24
 
26
25
 
27
26
  // MAIN //
@@ -31,8 +30,8 @@ var addon = require( './srev.native.js' );
31
30
  *
32
31
  * @param {PositiveInteger} N - number of indexed elements
33
32
  * @param {Float32Array} x - input array
34
- * @param {integer} stride - index increment
35
- * @param {NonNegativeInteger} offset - starting index
33
+ * @param {integer} strideX - stride length
34
+ * @param {NonNegativeInteger} offsetX - starting index
36
35
  * @returns {Float32Array} input array
37
36
  *
38
37
  * @example
@@ -43,13 +42,8 @@ var addon = require( './srev.native.js' );
43
42
  * srev( 3, x, 1, x.length-3 );
44
43
  * // x => <Float32Array>[ 1.0, -2.0, 3.0, -6.0, 5.0, -4.0 ]
45
44
  */
46
- function srev( N, x, stride, offset ) {
47
- var view;
48
- if ( stride < 0 ) {
49
- offset += (N-1) * stride;
50
- }
51
- view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len
52
- addon( N, view, stride );
45
+ function srev( N, x, strideX, offsetX ) {
46
+ addon.ndarray( N, x, strideX, offsetX );
53
47
  return x;
54
48
  }
55
49
 
package/lib/srev.js CHANGED
@@ -20,12 +20,8 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
- var floor = require( '@stdlib/math-base-special-floor' );
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} stride - index increment
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, stride ) {
50
- var tmp;
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
 
@@ -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} stride - index increment
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, stride ) {
45
- addon( N, x, stride );
44
+ function srev( N, x, strideX ) {
45
+ addon( N, x, strideX );
46
46
  return x;
47
47
  }
48
48
 
package/manifest.json CHANGED
@@ -1,40 +1,78 @@
1
1
  {
2
- "options": {},
3
- "fields": [
4
- {
5
- "field": "src",
6
- "resolve": true,
7
- "relative": true
8
- },
9
- {
10
- "field": "include",
11
- "resolve": true,
12
- "relative": true
13
- },
14
- {
15
- "field": "libraries",
16
- "resolve": false,
17
- "relative": false
18
- },
19
- {
20
- "field": "libpath",
21
- "resolve": true,
22
- "relative": false
23
- }
24
- ],
25
- "confs": [
26
- {
27
- "src": [
28
- "./src/srev.c"
29
- ],
30
- "include": [
31
- "./include"
32
- ],
33
- "libraries": [
34
- "-lm"
35
- ],
36
- "libpath": [],
37
- "dependencies": []
38
- }
39
- ]
2
+ "options": {
3
+ "task": "build"
4
+ },
5
+ "fields": [
6
+ {
7
+ "field": "src",
8
+ "resolve": true,
9
+ "relative": true
10
+ },
11
+ {
12
+ "field": "include",
13
+ "resolve": true,
14
+ "relative": true
15
+ },
16
+ {
17
+ "field": "libraries",
18
+ "resolve": false,
19
+ "relative": false
20
+ },
21
+ {
22
+ "field": "libpath",
23
+ "resolve": true,
24
+ "relative": false
25
+ }
26
+ ],
27
+ "confs": [
28
+ {
29
+ "task": "build",
30
+ "src": [
31
+ "./src/main.c"
32
+ ],
33
+ "include": [
34
+ "./include"
35
+ ],
36
+ "libraries": [],
37
+ "libpath": [],
38
+ "dependencies": [
39
+ "@stdlib/napi-export",
40
+ "@stdlib/napi-argv",
41
+ "@stdlib/napi-argv-int64",
42
+ "@stdlib/napi-argv-strided-float32array",
43
+ "@stdlib/strided-base-stride2offset",
44
+ "@stdlib/blas-base-shared"
45
+ ]
46
+ },
47
+ {
48
+ "task": "benchmark",
49
+ "src": [
50
+ "./src/main.c"
51
+ ],
52
+ "include": [
53
+ "./include"
54
+ ],
55
+ "libraries": [],
56
+ "libpath": [],
57
+ "dependencies": [
58
+ "@stdlib/strided-base-stride2offset",
59
+ "@stdlib/blas-base-shared"
60
+ ]
61
+ },
62
+ {
63
+ "task": "examples",
64
+ "src": [
65
+ "./src/main.c"
66
+ ],
67
+ "include": [
68
+ "./include"
69
+ ],
70
+ "libraries": [],
71
+ "libpath": [],
72
+ "dependencies": [
73
+ "@stdlib/strided-base-stride2offset",
74
+ "@stdlib/blas-base-shared"
75
+ ]
76
+ }
77
+ ]
40
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/blas-ext-base-srev",
3
- "version": "0.2.1",
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": {
@@ -34,11 +34,17 @@
34
34
  "url": "https://github.com/stdlib-js/stdlib/issues"
35
35
  },
36
36
  "dependencies": {
37
- "@stdlib/assert-is-error": "^0.2.1",
38
- "@stdlib/math-base-special-floor": "^0.2.1",
39
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1",
40
- "@stdlib/utils-library-manifest": "^0.2.1",
41
- "@stdlib/utils-try-require": "^0.2.1"
37
+ "@stdlib/assert-is-error": "^0.2.2",
38
+ "@stdlib/blas-base-shared": "^0.1.0",
39
+ "@stdlib/math-base-special-floor": "^0.2.3",
40
+ "@stdlib/napi-argv": "^0.2.2",
41
+ "@stdlib/napi-argv-int64": "^0.2.2",
42
+ "@stdlib/napi-argv-strided-float32array": "^0.2.2",
43
+ "@stdlib/napi-export": "^0.3.0",
44
+ "@stdlib/strided-base-stride2offset": "^0.1.0",
45
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
46
+ "@stdlib/utils-library-manifest": "^0.2.3",
47
+ "@stdlib/utils-try-require": "^0.2.2"
42
48
  },
43
49
  "devDependencies": {},
44
50
  "engines": {
@@ -75,7 +81,6 @@
75
81
  "single",
76
82
  "float32array"
77
83
  ],
78
- "__stdlib__": {},
79
84
  "funding": {
80
85
  "type": "opencollective",
81
86
  "url": "https://opencollective.com/stdlib"
package/src/addon.c ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ #include "stdlib/blas/ext/base/srev.h"
20
+ #include "stdlib/blas/base/shared.h"
21
+ #include "stdlib/napi/export.h"
22
+ #include "stdlib/napi/argv.h"
23
+ #include "stdlib/napi/argv_int64.h"
24
+ #include "stdlib/napi/argv_strided_float32array.h"
25
+ #include <node_api.h>
26
+
27
+ /**
28
+ * Receives JavaScript callback invocation data.
29
+ *
30
+ * @param env environment under which the function is invoked
31
+ * @param info callback data
32
+ * @return Node-API value
33
+ */
34
+ static napi_value addon( napi_env env, napi_callback_info info ) {
35
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
36
+ STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
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 );
40
+ return NULL;
41
+ }
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 );
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @license Apache-2.0
3
3
  *
4
- * Copyright (c) 2020 The Stdlib Authors.
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 <stdint.h>
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 number of indexed elements
26
- * @param X input array
27
- * @param stride index increment
26
+ * @param N number of indexed elements
27
+ * @param X input array
28
+ * @param strideX stride length
28
29
  */
29
- void c_srev( const int64_t N, float *X, const int64_t stride ) {
30
- int64_t ix;
31
- int64_t iy;
32
- int64_t m;
33
- int64_t n;
34
- int64_t i;
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 ( stride == 1 ) {
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 ( ix = 0; ix < m; ix++ ) {
64
+ for ( i = 0; i < m; i++ ) {
50
65
  tmp = X[ ix ];
51
66
  X[ ix ] = X[ iy ];
52
67
  X[ iy ] = tmp;
53
- iy -= 1;
68
+ ix += strideX;
69
+ iy -= strideX;
54
70
  }
55
71
  }
56
72
  if ( n < 3 ) {
57
73
  return;
58
74
  }
59
- for ( ix = m; ix < n; ix += 3 ) {
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
- if ( stride < 0 ) {
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 += stride;
87
- iy -= stride;
98
+ ix += strideX;
99
+ iy -= strideX;
88
100
  }
89
101
  return;
90
102
  }
package/include.gypi DELETED
@@ -1,53 +0,0 @@
1
- # @license Apache-2.0
2
- #
3
- # Copyright (c) 2020 The Stdlib Authors.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- # A GYP include file for building a Node.js native add-on.
18
- #
19
- # Main documentation:
20
- #
21
- # [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
22
- # [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
23
- {
24
- # Define variables to be used throughout the configuration for all targets:
25
- 'variables': {
26
- # Source directory:
27
- 'src_dir': './src',
28
-
29
- # Include directories:
30
- 'include_dirs': [
31
- '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).include; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
32
- ],
33
-
34
- # Add-on destination directory:
35
- 'addon_output_dir': './src',
36
-
37
- # Source files:
38
- 'src_files': [
39
- '<(src_dir)/addon.cpp',
40
- '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
41
- ],
42
-
43
- # Library dependencies:
44
- 'libraries': [
45
- '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libraries; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
46
- ],
47
-
48
- # Library directories:
49
- 'library_dirs': [
50
- '<!@(node -e "var arr = require(\'@stdlib/utils-library-manifest\')(\'./manifest.json\',{},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).libpath; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
51
- ],
52
- }, # end variables
53
- }
package/src/addon.cpp DELETED
@@ -1,115 +0,0 @@
1
- /**
2
- * @license Apache-2.0
3
- *
4
- * Copyright (c) 2020 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
- #include "stdlib/blas/ext/base/srev.h"
20
- #include <node_api.h>
21
- #include <stdint.h>
22
- #include <stdlib.h>
23
- #include <stdbool.h>
24
- #include <assert.h>
25
-
26
- /**
27
- * Add-on namespace.
28
- */
29
- namespace stdlib_blas_ext_base_srev {
30
-
31
- /**
32
- * Reverses a single-precision floating-point strided array in-place.
33
- *
34
- * ## Notes
35
- *
36
- * - When called from JavaScript, the function expects three arguments:
37
- *
38
- * - `N`: number of indexed elements
39
- * - `X`: input array
40
- * - `strideX`: `X` stride length
41
- */
42
- napi_value node_srev( napi_env env, napi_callback_info info ) {
43
- napi_status status;
44
-
45
- size_t argc = 3;
46
- napi_value argv[ 3 ];
47
- status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr );
48
- assert( status == napi_ok );
49
-
50
- if ( argc < 3 ) {
51
- napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." );
52
- return nullptr;
53
- }
54
-
55
- napi_valuetype vtype0;
56
- status = napi_typeof( env, argv[ 0 ], &vtype0 );
57
- assert( status == napi_ok );
58
- if ( vtype0 != napi_number ) {
59
- napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." );
60
- return nullptr;
61
- }
62
-
63
- bool res1;
64
- status = napi_is_typedarray( env, argv[ 1 ], &res1 );
65
- assert( status == napi_ok );
66
- if ( res1 == false ) {
67
- napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." );
68
- return nullptr;
69
- }
70
-
71
- napi_valuetype vtype2;
72
- status = napi_typeof( env, argv[ 2 ], &vtype2 );
73
- assert( status == napi_ok );
74
- if ( vtype2 != napi_number ) {
75
- napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." );
76
- return nullptr;
77
- }
78
-
79
- int64_t N;
80
- status = napi_get_value_int64( env, argv[ 0 ], &N );
81
- assert( status == napi_ok );
82
-
83
- int64_t strideX;
84
- status = napi_get_value_int64( env, argv[ 2 ], &strideX );
85
- assert( status == napi_ok );
86
-
87
- napi_typedarray_type vtype1;
88
- size_t xlen;
89
- void *X;
90
- status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr );
91
- assert( status == napi_ok );
92
- if ( vtype1 != napi_float32_array ) {
93
- napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." );
94
- return nullptr;
95
- }
96
- if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) {
97
- napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." );
98
- return nullptr;
99
- }
100
-
101
- c_srev( N, (float *)X, strideX );
102
-
103
- return nullptr;
104
- }
105
-
106
- napi_value Init( napi_env env, napi_value exports ) {
107
- napi_status status;
108
- napi_value fcn;
109
- status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_srev, NULL, &fcn );
110
- assert( status == napi_ok );
111
- return fcn;
112
- }
113
-
114
- NAPI_MODULE( NODE_GYP_MODULE_NAME, Init )
115
- } // end namespace stdlib_blas_ext_base_srev