@stdlib/ndarray-base-unary-reduce-strided1d 0.1.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.
Files changed (57) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +1 -0
  3. package/README.md +302 -0
  4. package/SECURITY.md +5 -0
  5. package/dist/index.js +101 -0
  6. package/dist/index.js.map +7 -0
  7. package/lib/0d.js +114 -0
  8. package/lib/0d_accessors.js +119 -0
  9. package/lib/10d.js +291 -0
  10. package/lib/10d_accessors.js +299 -0
  11. package/lib/10d_blocked.js +413 -0
  12. package/lib/10d_blocked_accessors.js +421 -0
  13. package/lib/1d.js +167 -0
  14. package/lib/1d_accessors.js +175 -0
  15. package/lib/2d.js +193 -0
  16. package/lib/2d_accessors.js +201 -0
  17. package/lib/2d_blocked.js +227 -0
  18. package/lib/2d_blocked_accessors.js +235 -0
  19. package/lib/3d.js +205 -0
  20. package/lib/3d_accessors.js +213 -0
  21. package/lib/3d_blocked.js +252 -0
  22. package/lib/3d_blocked_accessors.js +260 -0
  23. package/lib/4d.js +217 -0
  24. package/lib/4d_accessors.js +225 -0
  25. package/lib/4d_blocked.js +275 -0
  26. package/lib/4d_blocked_accessors.js +283 -0
  27. package/lib/5d.js +229 -0
  28. package/lib/5d_accessors.js +237 -0
  29. package/lib/5d_blocked.js +298 -0
  30. package/lib/5d_blocked_accessors.js +306 -0
  31. package/lib/6d.js +243 -0
  32. package/lib/6d_accessors.js +251 -0
  33. package/lib/6d_blocked.js +321 -0
  34. package/lib/6d_blocked_accessors.js +329 -0
  35. package/lib/7d.js +255 -0
  36. package/lib/7d_accessors.js +263 -0
  37. package/lib/7d_blocked.js +344 -0
  38. package/lib/7d_blocked_accessors.js +352 -0
  39. package/lib/8d.js +267 -0
  40. package/lib/8d_accessors.js +275 -0
  41. package/lib/8d_blocked.js +367 -0
  42. package/lib/8d_blocked_accessors.js +375 -0
  43. package/lib/9d.js +279 -0
  44. package/lib/9d_accessors.js +287 -0
  45. package/lib/9d_blocked.js +390 -0
  46. package/lib/9d_blocked_accessors.js +398 -0
  47. package/lib/factory.js +126 -0
  48. package/lib/increment_offsets.js +46 -0
  49. package/lib/index.js +161 -0
  50. package/lib/initialize_array_views.js +57 -0
  51. package/lib/main.js +498 -0
  52. package/lib/nd.js +177 -0
  53. package/lib/nd_accessors.js +185 -0
  54. package/lib/offsets.js +42 -0
  55. package/lib/reshape_strategy.js +260 -0
  56. package/lib/set_view_offsets.js +52 -0
  57. package/package.json +90 -0
package/lib/index.js ADDED
@@ -0,0 +1,161 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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
+ 'use strict';
20
+
21
+ /**
22
+ * Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function and assign results to a provided output ndarray.
23
+ *
24
+ * @module @stdlib/ndarray-base-unary-reduce-strided1d
25
+ *
26
+ * @example
27
+ * var Float64Array = require( '@stdlib/array-float64' );
28
+ * var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
29
+ * var getStride = require( '@stdlib/ndarray-base-stride' );
30
+ * var getOffset = require( '@stdlib/ndarray-base-offset' );
31
+ * var getData = require( '@stdlib/ndarray-base-data-buffer' );
32
+ * var numelDimension = require( '@stdlib/ndarray-base-numel-dimension' );
33
+ * var gsum = require( '@stdlib/blas-ext-base-gsum' ).ndarray;
34
+ * var unaryReduceStrided1d = require( '@stdlib/ndarray-base-unary-reduce-strided1d' );
35
+ *
36
+ * function wrapper( arrays ) {
37
+ * var x = arrays[ 0 ];
38
+ * return gsum( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) );
39
+ * }
40
+ *
41
+ * // Create data buffers:
42
+ * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
43
+ * var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] );
44
+ *
45
+ * // Define the array shapes:
46
+ * var xsh = [ 1, 3, 2, 2 ];
47
+ * var ysh = [ 1, 3 ];
48
+ *
49
+ * // Define the array strides:
50
+ * var sx = [ 12, 4, 2, 1 ];
51
+ * var sy = [ 3, 1 ];
52
+ *
53
+ * // Define the index offsets:
54
+ * var ox = 0;
55
+ * var oy = 0;
56
+ *
57
+ * // Create an input ndarray-like object:
58
+ * var x = {
59
+ * 'dtype': 'float64',
60
+ * 'data': xbuf,
61
+ * 'shape': xsh,
62
+ * 'strides': sx,
63
+ * 'offset': ox,
64
+ * 'order': 'row-major'
65
+ * };
66
+ *
67
+ * // Create an output ndarray-like object:
68
+ * var y = {
69
+ * 'dtype': 'float64',
70
+ * 'data': ybuf,
71
+ * 'shape': ysh,
72
+ * 'strides': sy,
73
+ * 'offset': oy,
74
+ * 'order': 'row-major'
75
+ * };
76
+ *
77
+ * // Perform a reduction:
78
+ * unaryReduceStrided1d( wrapper, [ x, y ], [ 2, 3 ] );
79
+ *
80
+ * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
81
+ * // returns [ [ 10.0, 26.0, 42.0 ] ]
82
+ *
83
+ * @example
84
+ * var Float64Array = require( '@stdlib/array-float64' );
85
+ * var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
86
+ * var getStride = require( '@stdlib/ndarray-base-stride' );
87
+ * var getOffset = require( '@stdlib/ndarray-base-offset' );
88
+ * var getData = require( '@stdlib/ndarray-base-data-buffer' );
89
+ * var numelDimension = require( '@stdlib/ndarray-base-numel-dimension' );
90
+ * var gsum = require( '@stdlib/blas-ext-base-gsum' ).ndarray;
91
+ * var unaryReduceStrided1d = require( '@stdlib/ndarray-base-unary-reduce-strided1d' );
92
+ *
93
+ * function wrapper( arrays ) {
94
+ * var x = arrays[ 0 ];
95
+ * return gsum( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) );
96
+ * }
97
+ *
98
+ * // Create data buffers:
99
+ * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
100
+ * var ybuf = new Float64Array( [ 0.0, 0.0, 0.0 ] );
101
+ *
102
+ * // Define the array shapes:
103
+ * var xsh = [ 1, 3, 2, 2 ];
104
+ * var ysh = [ 1, 3 ];
105
+ *
106
+ * // Define the array strides:
107
+ * var sx = [ 12, 4, 2, 1 ];
108
+ * var sy = [ 3, 1 ];
109
+ *
110
+ * // Define the index offsets:
111
+ * var ox = 0;
112
+ * var oy = 0;
113
+ *
114
+ * // Create an input ndarray-like object:
115
+ * var x = {
116
+ * 'dtype': 'float64',
117
+ * 'data': xbuf,
118
+ * 'shape': xsh,
119
+ * 'strides': sx,
120
+ * 'offset': ox,
121
+ * 'order': 'row-major'
122
+ * };
123
+ *
124
+ * // Create an output ndarray-like object:
125
+ * var y = {
126
+ * 'dtype': 'float64',
127
+ * 'data': ybuf,
128
+ * 'shape': ysh,
129
+ * 'strides': sy,
130
+ * 'offset': oy,
131
+ * 'order': 'row-major'
132
+ * };
133
+ *
134
+ * // Create a function for performing a reduction over subarrays:
135
+ * var sum = unaryReduceStrided1d.factory( wrapper );
136
+ * // returns <Function>
137
+ *
138
+ * // Perform a reduction:
139
+ * sum( [ x, y ], [ 2, 3 ] );
140
+ *
141
+ * var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
142
+ * // returns [ [ 10.0, 26.0, 42.0 ] ]
143
+ */
144
+
145
+ // MODULES //
146
+
147
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
148
+ var main = require( './main.js' );
149
+ var factory = require( './factory.js' );
150
+
151
+
152
+ // MAIN //
153
+
154
+ setReadOnly( main, 'factory', factory );
155
+
156
+
157
+ // EXPORTS //
158
+
159
+ module.exports = main;
160
+
161
+ // exports: { "factory": "main.factory" }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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
+ 'use strict';
20
+
21
+ // MAIN //
22
+
23
+ /**
24
+ * Initialize ndarray-like objects for representing zero-dimensional sub-array views of ancillary ndarray arguments.
25
+ *
26
+ * ## Notes
27
+ *
28
+ * - This function ignores the first two ndarray-like objects, which are assumed to be the input and output ndarray, respectively.
29
+ * - This function mutates the provided output array.
30
+ *
31
+ * @private
32
+ * @param {ArrayLikeObject<Object>} arrays - list of ndarray-like objects
33
+ * @param {Array<Object>} out - output array
34
+ * @returns {Array<Object>} output array
35
+ */
36
+ function initializeViews( arrays, out ) {
37
+ var v;
38
+ var i;
39
+
40
+ for ( i = 2; i < arrays.length; i++ ) {
41
+ v = arrays[ i ];
42
+ out.push({
43
+ 'dtype': v.dtype,
44
+ 'data': v.data,
45
+ 'shape': [],
46
+ 'strides': [ 0 ],
47
+ 'offset': v.offset,
48
+ 'order': v.order
49
+ });
50
+ }
51
+ return out;
52
+ }
53
+
54
+
55
+ // EXPORTS //
56
+
57
+ module.exports = initializeViews;