Skip to content

Commit f446206

Browse files
headlessNodekgryte
andauthored
feat: add C ndarray API and refactor blas/ext/base/zfill
PR-URL: #2962 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Athan Reines <[email protected]>
1 parent 5774557 commit f446206

24 files changed

+416
-208
lines changed

lib/node_modules/@stdlib/blas/ext/base/cfill/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ console.log( x.get( 0 ).toString() );
287287

288288
#### stdlib_strided_cfill( N, alpha, \*X, strideX )
289289

290-
Fills a single-precision floating-point strided array `X` with a specified scalar constant `alpha`.
290+
Fills a single-precision complex floating-point strided array `X` with a specified scalar constant `alpha`.
291291

292292
```c
293293
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
@@ -321,13 +321,13 @@ stdlib_strided_cfill_ndarray( 4, alpha, (stdlib_complex64_t *x), 1, 0 );
321321
The function accepts the following arguments:
322322
323323
- **N**: `[in] CBLAS_INT` number of indexed elements.
324-
- **alpha**: `[in] stlib_complex64_t` scalar constant.
324+
- **alpha**: `[in] stdlib_complex64_t` scalar constant.
325325
- **X**: `[out] stdlib_complex64_t*` input array.
326326
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
327327
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
328328
329329
```c
330-
void stdlib_strided_cfill_ndarray( const CBLAS_INT N, const stdlib_complex64_t alpha, stdlib_complex_64_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
330+
void stdlib_strided_cfill_ndarray( const CBLAS_INT N, const stdlib_complex64_t alpha, stdlib_complex64_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
331331
```
332332

333333
</section>
@@ -367,7 +367,7 @@ int main( void ) {
367367
const int strideX = 1;
368368

369369
// Fill the array:
370-
stdlib_strided_cfill( N, alpha, (stdlib_complex_64_t *)x, strideX );
370+
stdlib_strided_cfill( N, alpha, (stdlib_complex64_t *)x, strideX );
371371

372372
// Print the result:
373373
for ( int i = 0; i < N; i++ ) {

lib/node_modules/@stdlib/blas/ext/base/cfill/lib/ndarray.js

+27-28
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ function cfill( N, alpha, x, strideX, offsetX ) {
7272
var ix;
7373
var m;
7474
var i;
75-
var j;
7675

7776
if ( N <= 0 ) {
7877
return x;
7978
}
80-
ix = offsetX;
8179

8280
// Decompose the constant into its real and imaginary components:
8381
re = realf( alpha );
@@ -86,48 +84,49 @@ function cfill( N, alpha, x, strideX, offsetX ) {
8684
// Reinterpret the complex input array as a real-valued array:
8785
view = reinterpret( x, 0 );
8886

89-
// Use loop unrolling if the stride is equal to `1`...
90-
if ( strideX === 1 ) {
87+
// Adjust the stride and offset according to real-valued array:
88+
ix = offsetX * 2;
89+
strideX *= 2;
90+
91+
// Use loop unrolling if the stride is equal to `2`...
92+
if ( strideX === 2 ) {
9193
m = N % M;
9294

9395
// If we have a remainder, run a clean-up loop...
9496
if ( m > 0 ) {
9597
for ( i = 0; i < m; i++ ) {
96-
j = ix * 2;
97-
view[ j ] = re;
98-
view[ j+1 ] = im;
98+
view[ ix ] = re;
99+
view[ ix+1 ] = im;
99100
ix += strideX;
100101
}
101102
}
102103
if ( N < M ) {
103104
return x;
104105
}
105106
for ( i = m; i < N; i += M ) {
106-
j = ix * 2;
107-
view[ j ] = re;
108-
view[ j+1 ] = im;
109-
view[ j+2 ] = re;
110-
view[ j+3 ] = im;
111-
view[ j+4 ] = re;
112-
view[ j+5 ] = im;
113-
view[ j+6 ] = re;
114-
view[ j+7 ] = im;
115-
view[ j+8 ] = re;
116-
view[ j+9 ] = im;
117-
view[ j+10 ] = re;
118-
view[ j+11 ] = im;
119-
view[ j+12 ] = re;
120-
view[ j+13 ] = im;
121-
view[ j+14 ] = re;
122-
view[ j+15 ] = im;
123-
ix += M;
107+
view[ ix ] = re;
108+
view[ ix+1 ] = im;
109+
view[ ix+2 ] = re;
110+
view[ ix+3 ] = im;
111+
view[ ix+4 ] = re;
112+
view[ ix+5 ] = im;
113+
view[ ix+6 ] = re;
114+
view[ ix+7 ] = im;
115+
view[ ix+8 ] = re;
116+
view[ ix+9 ] = im;
117+
view[ ix+10 ] = re;
118+
view[ ix+11 ] = im;
119+
view[ ix+12 ] = re;
120+
view[ ix+13 ] = im;
121+
view[ ix+14 ] = re;
122+
view[ ix+15 ] = im;
123+
ix += M * 2;
124124
}
125125
return x;
126126
}
127127
for ( i = 0; i < N; i++ ) {
128-
j = ix * 2;
129-
view[ j ] = re;
130-
view[ j+1 ] = im;
128+
view[ ix ] = re;
129+
view[ ix+1 ] = im;
131130
ix += strideX;
132131
}
133132
return x;

lib/node_modules/@stdlib/blas/ext/base/cfill/test/test.ndarray.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,23 @@ tape( 'the function supports an offset parameter', function test( t ) {
167167
-2.0,
168168
3.0, // 0
169169
-4.0, // 0
170-
6.0,
171-
-8.0,
172-
10.0, // 1
173-
-12.0 // 1
170+
6.0, // 1
171+
-8.0, // 1
172+
10.0,
173+
-12.0
174174
]);
175175
expected = new Complex64Array([
176176
1.0,
177177
-2.0,
178178
5.0, // 0
179179
-5.0, // 0
180-
6.0,
181-
-8.0,
182180
5.0, // 1
183-
-5.0 // 1
181+
-5.0, // 1
182+
10.0,
183+
-12.0
184184
]);
185185

186-
cfill( 2, new Complex64( 5.0, -5.0 ), x, 2, 1 );
186+
cfill( 2, new Complex64( 5.0, -5.0 ), x, 1, 1 );
187187
t.strictEqual( isSameComplex64Array( x, expected ), true, 'returns expected value' );
188188
t.end();
189189
});

lib/node_modules/@stdlib/blas/ext/base/cfill/test/test.ndarray.native.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,23 @@ tape( 'the function supports an offset parameter', opts, function test( t ) {
176176
-2.0,
177177
3.0, // 0
178178
-4.0, // 0
179-
6.0,
180-
-8.0,
181-
10.0, // 1
182-
-12.0 // 1
179+
6.0, // 1
180+
-8.0, // 1
181+
10.0,
182+
-12.0
183183
]);
184184
expected = new Complex64Array([
185185
1.0,
186186
-2.0,
187187
5.0, // 0
188188
-5.0, // 0
189-
6.0,
190-
-8.0,
191189
5.0, // 1
192-
-5.0 // 1
190+
-5.0, // 1
191+
10.0,
192+
-12.0
193193
]);
194194

195-
cfill( 2, new Complex64( 5.0, -5.0 ), x, 2, 1 );
195+
cfill( 2, new Complex64( 5.0, -5.0 ), x, 1, 1 );
196196
t.strictEqual( isSameComplex64Array( x, expected ), true, 'returns expected value' );
197197
t.end();
198198
});

lib/node_modules/@stdlib/blas/ext/base/dfill/test/test.ndarray.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,21 @@ tape( 'the function supports an offset parameter', function test( t ) {
157157
x = new Float64Array([
158158
1.0,
159159
2.0, // 0
160-
3.0,
161-
4.0, // 1
162-
5.0,
163-
6.0 // 2
160+
3.0, // 1
161+
4.0, // 2
162+
6.0,
163+
7.0
164164
]);
165165
expected = new Float64Array([
166166
1.0,
167167
5.0, // 0
168-
3.0,
169168
5.0, // 1
170-
5.0,
171-
5.0 // 2
169+
5.0, // 2
170+
6.0,
171+
7.0
172172
]);
173173

174-
dfill( 3, 5.0, x, 2, 1 );
174+
dfill( 3, 5.0, x, 1, 1 );
175175
t.deepEqual( x, expected, 'returns expected value' );
176176
t.end();
177177
});

lib/node_modules/@stdlib/blas/ext/base/dfill/test/test.ndarray.native.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,21 @@ tape( 'the function supports an offset parameter', opts, function test( t ) {
166166
x = new Float64Array([
167167
1.0,
168168
2.0, // 0
169-
3.0,
170-
4.0, // 1
171-
5.0,
172-
6.0 // 2
169+
3.0, // 1
170+
4.0, // 2
171+
6.0,
172+
7.0
173173
]);
174174
expected = new Float64Array([
175175
1.0,
176176
5.0, // 0
177-
3.0,
178177
5.0, // 1
179-
5.0,
180-
5.0 // 2
178+
5.0, // 2
179+
6.0,
180+
7.0
181181
]);
182182

183-
dfill( 3, 5.0, x, 2, 1 );
183+
dfill( 3, 5.0, x, 1, 1 );
184184
t.deepEqual( x, expected, 'returns expected value' );
185185
t.end();
186186
});

lib/node_modules/@stdlib/blas/ext/base/sfill/test/test.ndarray.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,21 @@ tape( 'the function supports an offset parameter', function test( t ) {
157157
x = new Float32Array([
158158
1.0,
159159
2.0, // 0
160-
3.0,
161-
4.0, // 1
162-
5.0,
163-
6.0 // 2
160+
3.0, // 1
161+
4.0, // 2
162+
6.0,
163+
7.0
164164
]);
165165
expected = new Float32Array([
166166
1.0,
167167
5.0, // 0
168-
3.0,
169168
5.0, // 1
170-
5.0,
171-
5.0 // 2
169+
5.0, // 2
170+
6.0,
171+
7.0
172172
]);
173173

174-
sfill( 3, 5.0, x, 2, 1 );
174+
sfill( 3, 5.0, x, 1, 1 );
175175
t.deepEqual( x, expected, 'returns expected value' );
176176
t.end();
177177
});

lib/node_modules/@stdlib/blas/ext/base/sfill/test/test.ndarray.native.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,21 @@ tape( 'the function supports an offset parameter', opts, function test( t ) {
166166
x = new Float32Array([
167167
1.0,
168168
2.0, // 0
169-
3.0,
170-
4.0, // 1
171-
5.0,
172-
6.0 // 2
169+
3.0, // 1
170+
4.0, // 2
171+
6.0,
172+
7.0
173173
]);
174174
expected = new Float32Array([
175175
1.0,
176176
5.0, // 0
177-
3.0,
178177
5.0, // 1
179-
5.0,
180-
5.0 // 2
178+
5.0, // 2
179+
6.0,
180+
7.0
181181
]);
182182

183-
sfill( 3, 5.0, x, 2, 1 );
183+
sfill( 3, 5.0, x, 1, 1 );
184184
t.deepEqual( x, expected, 'returns expected value' );
185185
t.end();
186186
});

0 commit comments

Comments
 (0)