@stdlib/blas-ext-base-srev 0.2.0 → 0.2.2
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/README.md +12 -30
- package/docs/types/index.d.ts +3 -3
- package/lib/ndarray.native.js +6 -5
- package/manifest.json +74 -38
- package/package.json +16 -30
- package/src/addon.c +42 -0
- package/include.gypi +0 -53
- package/src/addon.cpp +0 -115
package/README.md
CHANGED
|
@@ -72,16 +72,14 @@ The function has the following parameters:
|
|
|
72
72
|
- **x**: input [`Float32Array`][@stdlib/array/float32].
|
|
73
73
|
- **stride**: index increment.
|
|
74
74
|
|
|
75
|
-
The `N` and `stride` parameters determine which elements in
|
|
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(
|
|
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,17 +87,15 @@ 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(
|
|
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
|
|
|
@@ -120,7 +116,7 @@ The function has the following additional parameters:
|
|
|
120
116
|
|
|
121
117
|
- **offset**: 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
|
|
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
|
|
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,13 @@ srev.ndarray( 3, x, 1, x.length-3 );
|
|
|
153
149
|
<!-- eslint no-undef: "error" -->
|
|
154
150
|
|
|
155
151
|
```javascript
|
|
156
|
-
var
|
|
157
|
-
var
|
|
158
|
-
var Float32Array = require( '@stdlib/array-float32' );
|
|
152
|
+
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory;
|
|
153
|
+
var filledarrayBy = require( '@stdlib/array-filled-by' );
|
|
159
154
|
var srev = require( '@stdlib/blas-ext-base-srev' );
|
|
160
155
|
|
|
161
|
-
var rand;
|
|
162
|
-
|
|
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
|
-
}
|
|
156
|
+
var rand = discreteUniform( -100, 100 );
|
|
157
|
+
|
|
158
|
+
var x = filledarrayBy( 10, 'float32', rand );
|
|
177
159
|
console.log( x );
|
|
178
160
|
|
|
179
161
|
srev( x.length, x, 1 );
|
|
@@ -238,8 +220,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
238
220
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/blas-ext-base-srev.svg
|
|
239
221
|
[npm-url]: https://npmjs.org/package/@stdlib/blas-ext-base-srev
|
|
240
222
|
|
|
241
|
-
[test-image]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml/badge.svg?branch=v0.2.
|
|
242
|
-
[test-url]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml?query=branch:v0.2.
|
|
223
|
+
[test-image]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml/badge.svg?branch=v0.2.2
|
|
224
|
+
[test-url]: https://github.com/stdlib-js/blas-ext-base-srev/actions/workflows/test.yml?query=branch:v0.2.2
|
|
243
225
|
|
|
244
226
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/blas-ext-base-srev/main.svg
|
|
245
227
|
[coverage-url]: https://codecov.io/github/stdlib-js/blas-ext-base-srev?branch=main
|
package/docs/types/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ interface Routine {
|
|
|
28
28
|
* @param N - number of indexed elements
|
|
29
29
|
* @param x - input array
|
|
30
30
|
* @param stride - stride length
|
|
31
|
-
* @returns
|
|
31
|
+
* @returns input array
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
34
|
* var Float32Array = require( '@stdlib/array-float32' );
|
|
@@ -47,7 +47,7 @@ interface Routine {
|
|
|
47
47
|
* @param x - input array
|
|
48
48
|
* @param stride - stride length
|
|
49
49
|
* @param offset - starting index
|
|
50
|
-
* @returns
|
|
50
|
+
* @returns input array
|
|
51
51
|
*
|
|
52
52
|
* @example
|
|
53
53
|
* var Float32Array = require( '@stdlib/array-float32' );
|
|
@@ -66,7 +66,7 @@ interface Routine {
|
|
|
66
66
|
* @param N - number of indexed elements
|
|
67
67
|
* @param x - input array
|
|
68
68
|
* @param stride - stride length
|
|
69
|
-
* @returns
|
|
69
|
+
* @returns input array
|
|
70
70
|
*
|
|
71
71
|
* @example
|
|
72
72
|
* var Float32Array = require( '@stdlib/array-float32' );
|
package/lib/ndarray.native.js
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
|
|
21
21
|
// MODULES //
|
|
22
22
|
|
|
23
|
-
var
|
|
23
|
+
var minViewBufferIndex = require( '@stdlib/strided-base-min-view-buffer-index' );
|
|
24
|
+
var offsetView = require( '@stdlib/strided-base-offset-view' );
|
|
24
25
|
var addon = require( './srev.native.js' );
|
|
25
26
|
|
|
26
27
|
|
|
@@ -45,10 +46,10 @@ var addon = require( './srev.native.js' );
|
|
|
45
46
|
*/
|
|
46
47
|
function srev( N, x, stride, offset ) {
|
|
47
48
|
var view;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
|
|
50
|
+
offset = minViewBufferIndex( N, stride, offset );
|
|
51
|
+
view = offsetView( x, offset );
|
|
52
|
+
|
|
52
53
|
addon( N, view, stride );
|
|
53
54
|
return x;
|
|
54
55
|
}
|
package/manifest.json
CHANGED
|
@@ -1,40 +1,76 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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/srev.c"
|
|
32
|
+
],
|
|
33
|
+
"include": [
|
|
34
|
+
"./include"
|
|
35
|
+
],
|
|
36
|
+
"libraries": [
|
|
37
|
+
"-lm"
|
|
38
|
+
],
|
|
39
|
+
"libpath": [],
|
|
40
|
+
"dependencies": [
|
|
41
|
+
"@stdlib/napi-export",
|
|
42
|
+
"@stdlib/napi-argv",
|
|
43
|
+
"@stdlib/napi-argv-int64",
|
|
44
|
+
"@stdlib/napi-argv-strided-float32array"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"task": "benchmark",
|
|
49
|
+
"src": [
|
|
50
|
+
"./src/srev.c"
|
|
51
|
+
],
|
|
52
|
+
"include": [
|
|
53
|
+
"./include"
|
|
54
|
+
],
|
|
55
|
+
"libraries": [
|
|
56
|
+
"-lm"
|
|
57
|
+
],
|
|
58
|
+
"libpath": [],
|
|
59
|
+
"dependencies": []
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"task": "examples",
|
|
63
|
+
"src": [
|
|
64
|
+
"./src/srev.c"
|
|
65
|
+
],
|
|
66
|
+
"include": [
|
|
67
|
+
"./include"
|
|
68
|
+
],
|
|
69
|
+
"libraries": [
|
|
70
|
+
"-lm"
|
|
71
|
+
],
|
|
72
|
+
"libpath": [],
|
|
73
|
+
"dependencies": []
|
|
74
|
+
}
|
|
75
|
+
]
|
|
40
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/blas-ext-base-srev",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Reverse a single-precision floating-point strided array in-place.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -17,21 +17,14 @@
|
|
|
17
17
|
"browser": "./lib/main.js",
|
|
18
18
|
"gypfile": false,
|
|
19
19
|
"directories": {
|
|
20
|
-
"benchmark": "./benchmark",
|
|
21
20
|
"doc": "./docs",
|
|
22
|
-
"example": "./examples",
|
|
23
21
|
"include": "./include",
|
|
24
22
|
"lib": "./lib",
|
|
25
23
|
"src": "./src",
|
|
26
|
-
"
|
|
24
|
+
"dist": "./dist"
|
|
27
25
|
},
|
|
28
26
|
"types": "./docs/types",
|
|
29
|
-
"scripts": {
|
|
30
|
-
"test": "make test",
|
|
31
|
-
"test-cov": "make test-cov",
|
|
32
|
-
"examples": "make examples",
|
|
33
|
-
"benchmark": "make benchmark"
|
|
34
|
-
},
|
|
27
|
+
"scripts": {},
|
|
35
28
|
"homepage": "https://stdlib.io",
|
|
36
29
|
"repository": {
|
|
37
30
|
"type": "git",
|
|
@@ -41,26 +34,17 @@
|
|
|
41
34
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
42
35
|
},
|
|
43
36
|
"dependencies": {
|
|
44
|
-
"@stdlib/assert-is-error": "^0.2.
|
|
45
|
-
"@stdlib/math-base-special-floor": "^0.2.
|
|
46
|
-
"@stdlib/
|
|
47
|
-
"@stdlib/
|
|
48
|
-
"@stdlib/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"@stdlib/
|
|
52
|
-
"@stdlib/
|
|
53
|
-
"@stdlib/math-base-assert-is-nanf": "^0.1.1",
|
|
54
|
-
"@stdlib/math-base-special-pow": "^0.1.0",
|
|
55
|
-
"@stdlib/math-base-special-round": "^0.1.1",
|
|
56
|
-
"@stdlib/random-base-randu": "^0.1.0",
|
|
57
|
-
"proxyquire": "^2.0.0",
|
|
58
|
-
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
59
|
-
"istanbul": "^0.4.1",
|
|
60
|
-
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
61
|
-
"@stdlib/bench-harness": "^0.2.0",
|
|
62
|
-
"@stdlib/bench": "^0.3.1"
|
|
37
|
+
"@stdlib/assert-is-error": "^0.2.2",
|
|
38
|
+
"@stdlib/math-base-special-floor": "^0.2.3",
|
|
39
|
+
"@stdlib/napi-argv": "^0.2.2",
|
|
40
|
+
"@stdlib/napi-argv-int64": "^0.2.2",
|
|
41
|
+
"@stdlib/napi-argv-strided-float32array": "^0.2.2",
|
|
42
|
+
"@stdlib/napi-export": "^0.2.2",
|
|
43
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
44
|
+
"@stdlib/utils-library-manifest": "^0.2.2",
|
|
45
|
+
"@stdlib/utils-try-require": "^0.2.2"
|
|
63
46
|
},
|
|
47
|
+
"devDependencies": {},
|
|
64
48
|
"engines": {
|
|
65
49
|
"node": ">=0.10.0",
|
|
66
50
|
"npm": ">2.7.0"
|
|
@@ -95,7 +79,9 @@
|
|
|
95
79
|
"single",
|
|
96
80
|
"float32array"
|
|
97
81
|
],
|
|
98
|
-
"__stdlib__": {
|
|
82
|
+
"__stdlib__": {
|
|
83
|
+
"wasm": false
|
|
84
|
+
},
|
|
99
85
|
"funding": {
|
|
100
86
|
"type": "opencollective",
|
|
101
87
|
"url": "https://opencollective.com/stdlib"
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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/napi/export.h"
|
|
21
|
+
#include "stdlib/napi/argv.h"
|
|
22
|
+
#include "stdlib/napi/argv_int64.h"
|
|
23
|
+
#include "stdlib/napi/argv_strided_float32array.h"
|
|
24
|
+
#include <node_api.h>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Receives JavaScript callback invocation data.
|
|
28
|
+
*
|
|
29
|
+
* @param env environment under which the function is invoked
|
|
30
|
+
* @param info callback data
|
|
31
|
+
* @return Node-API value
|
|
32
|
+
*/
|
|
33
|
+
static napi_value addon( napi_env env, napi_callback_info info ) {
|
|
34
|
+
STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
|
|
35
|
+
STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
|
|
36
|
+
STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 );
|
|
37
|
+
STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 );
|
|
38
|
+
c_srev( N, X, stride );
|
|
39
|
+
return NULL;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
|
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
|