Skip to content

Commit

Permalink
feat: add C ndarray API and refactor blas/ext/base/zfill
Browse files Browse the repository at this point in the history
PR-URL: #2962
Co-authored-by: Athan Reines <[email protected]>
Reviewed-by: Athan Reines <[email protected]> 
Signed-off-by: Athan Reines <[email protected]>
  • Loading branch information
headlessNode and kgryte authored Oct 1, 2024
1 parent 5774557 commit f446206
Show file tree
Hide file tree
Showing 24 changed files with 416 additions and 208 deletions.
8 changes: 4 additions & 4 deletions lib/node_modules/@stdlib/blas/ext/base/cfill/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ console.log( x.get( 0 ).toString() );

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

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

```c
float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
Expand Down Expand Up @@ -321,13 +321,13 @@ stdlib_strided_cfill_ndarray( 4, alpha, (stdlib_complex64_t *x), 1, 0 );
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **alpha**: `[in] stlib_complex64_t` scalar constant.
- **alpha**: `[in] stdlib_complex64_t` scalar constant.
- **X**: `[out] stdlib_complex64_t*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
```c
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 );
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 );
```

</section>
Expand Down Expand Up @@ -367,7 +367,7 @@ int main( void ) {
const int strideX = 1;

// Fill the array:
stdlib_strided_cfill( N, alpha, (stdlib_complex_64_t *)x, strideX );
stdlib_strided_cfill( N, alpha, (stdlib_complex64_t *)x, strideX );

// Print the result:
for ( int i = 0; i < N; i++ ) {
Expand Down
55 changes: 27 additions & 28 deletions lib/node_modules/@stdlib/blas/ext/base/cfill/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ function cfill( N, alpha, x, strideX, offsetX ) {
var ix;
var m;
var i;
var j;

if ( N <= 0 ) {
return x;
}
ix = offsetX;

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

// Use loop unrolling if the stride is equal to `1`...
if ( strideX === 1 ) {
// Adjust the stride and offset according to real-valued array:
ix = offsetX * 2;
strideX *= 2;

// Use loop unrolling if the stride is equal to `2`...
if ( strideX === 2 ) {
m = N % M;

// If we have a remainder, run a clean-up loop...
if ( m > 0 ) {
for ( i = 0; i < m; i++ ) {
j = ix * 2;
view[ j ] = re;
view[ j+1 ] = im;
view[ ix ] = re;
view[ ix+1 ] = im;
ix += strideX;
}
}
if ( N < M ) {
return x;
}
for ( i = m; i < N; i += M ) {
j = ix * 2;
view[ j ] = re;
view[ j+1 ] = im;
view[ j+2 ] = re;
view[ j+3 ] = im;
view[ j+4 ] = re;
view[ j+5 ] = im;
view[ j+6 ] = re;
view[ j+7 ] = im;
view[ j+8 ] = re;
view[ j+9 ] = im;
view[ j+10 ] = re;
view[ j+11 ] = im;
view[ j+12 ] = re;
view[ j+13 ] = im;
view[ j+14 ] = re;
view[ j+15 ] = im;
ix += M;
view[ ix ] = re;
view[ ix+1 ] = im;
view[ ix+2 ] = re;
view[ ix+3 ] = im;
view[ ix+4 ] = re;
view[ ix+5 ] = im;
view[ ix+6 ] = re;
view[ ix+7 ] = im;
view[ ix+8 ] = re;
view[ ix+9 ] = im;
view[ ix+10 ] = re;
view[ ix+11 ] = im;
view[ ix+12 ] = re;
view[ ix+13 ] = im;
view[ ix+14 ] = re;
view[ ix+15 ] = im;
ix += M * 2;
}
return x;
}
for ( i = 0; i < N; i++ ) {
j = ix * 2;
view[ j ] = re;
view[ j+1 ] = im;
view[ ix ] = re;
view[ ix+1 ] = im;
ix += strideX;
}
return x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,23 @@ tape( 'the function supports an offset parameter', function test( t ) {
-2.0,
3.0, // 0
-4.0, // 0
6.0,
-8.0,
10.0, // 1
-12.0 // 1
6.0, // 1
-8.0, // 1
10.0,
-12.0
]);
expected = new Complex64Array([
1.0,
-2.0,
5.0, // 0
-5.0, // 0
6.0,
-8.0,
5.0, // 1
-5.0 // 1
-5.0, // 1
10.0,
-12.0
]);

cfill( 2, new Complex64( 5.0, -5.0 ), x, 2, 1 );
cfill( 2, new Complex64( 5.0, -5.0 ), x, 1, 1 );
t.strictEqual( isSameComplex64Array( x, expected ), true, 'returns expected value' );
t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,23 @@ tape( 'the function supports an offset parameter', opts, function test( t ) {
-2.0,
3.0, // 0
-4.0, // 0
6.0,
-8.0,
10.0, // 1
-12.0 // 1
6.0, // 1
-8.0, // 1
10.0,
-12.0
]);
expected = new Complex64Array([
1.0,
-2.0,
5.0, // 0
-5.0, // 0
6.0,
-8.0,
5.0, // 1
-5.0 // 1
-5.0, // 1
10.0,
-12.0
]);

cfill( 2, new Complex64( 5.0, -5.0 ), x, 2, 1 );
cfill( 2, new Complex64( 5.0, -5.0 ), x, 1, 1 );
t.strictEqual( isSameComplex64Array( x, expected ), true, 'returns expected value' );
t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,21 @@ tape( 'the function supports an offset parameter', function test( t ) {
x = new Float64Array([
1.0,
2.0, // 0
3.0,
4.0, // 1
5.0,
6.0 // 2
3.0, // 1
4.0, // 2
6.0,
7.0
]);
expected = new Float64Array([
1.0,
5.0, // 0
3.0,
5.0, // 1
5.0,
5.0 // 2
5.0, // 2
6.0,
7.0
]);

dfill( 3, 5.0, x, 2, 1 );
dfill( 3, 5.0, x, 1, 1 );
t.deepEqual( x, expected, 'returns expected value' );
t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,21 @@ tape( 'the function supports an offset parameter', opts, function test( t ) {
x = new Float64Array([
1.0,
2.0, // 0
3.0,
4.0, // 1
5.0,
6.0 // 2
3.0, // 1
4.0, // 2
6.0,
7.0
]);
expected = new Float64Array([
1.0,
5.0, // 0
3.0,
5.0, // 1
5.0,
5.0 // 2
5.0, // 2
6.0,
7.0
]);

dfill( 3, 5.0, x, 2, 1 );
dfill( 3, 5.0, x, 1, 1 );
t.deepEqual( x, expected, 'returns expected value' );
t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,21 @@ tape( 'the function supports an offset parameter', function test( t ) {
x = new Float32Array([
1.0,
2.0, // 0
3.0,
4.0, // 1
5.0,
6.0 // 2
3.0, // 1
4.0, // 2
6.0,
7.0
]);
expected = new Float32Array([
1.0,
5.0, // 0
3.0,
5.0, // 1
5.0,
5.0 // 2
5.0, // 2
6.0,
7.0
]);

sfill( 3, 5.0, x, 2, 1 );
sfill( 3, 5.0, x, 1, 1 );
t.deepEqual( x, expected, 'returns expected value' );
t.end();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,21 @@ tape( 'the function supports an offset parameter', opts, function test( t ) {
x = new Float32Array([
1.0,
2.0, // 0
3.0,
4.0, // 1
5.0,
6.0 // 2
3.0, // 1
4.0, // 2
6.0,
7.0
]);
expected = new Float32Array([
1.0,
5.0, // 0
3.0,
5.0, // 1
5.0,
5.0 // 2
5.0, // 2
6.0,
7.0
]);

sfill( 3, 5.0, x, 2, 1 );
sfill( 3, 5.0, x, 1, 1 );
t.deepEqual( x, expected, 'returns expected value' );
t.end();
});
Expand Down
Loading

1 comment on commit f446206

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
blas/ext/base/cfill $\color{green}491/491$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}491/491$
$\color{green}+100.00\%$
blas/ext/base/dfill $\color{green}391/391$
$\color{green}+100.00\%$
$\color{green}26/26$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}391/391$
$\color{green}+100.00\%$
blas/ext/base/sfill $\color{green}391/391$
$\color{green}+100.00\%$
$\color{green}26/26$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}391/391$
$\color{green}+100.00\%$
blas/ext/base/zfill $\color{green}491/491$
$\color{green}+100.00\%$
$\color{green}25/25$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}491/491$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.