Skip to content

feat: add c and fortran implementation for blas/base/zdscal #7086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions lib/node_modules/@stdlib/blas/base/zdscal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,151 @@ console.log( zx.toString() );

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/blas/base/zdscal.h"
```

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

Scales a double-precision complex floating-point vector by a double-precision floating-point constant.

```c
#include "stdlib/complex/float64/ctor.h"

stdlib_complex128_t x[] = {
stdlib_complex128( 1.0, 2.0 ),
stdlib_complex128( 3.0, 4.0 ),
stdlib_complex128( 5.0, 6.0 )
};

c_zdscal( 3, 2.0, x, 1 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **alpha**: `[in] double` constant.
- **x**: `[inout] stdlib_complex128_t*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `x`.

```c
void c_zdscal( const CBLAS_INT N, const double alpha, stdlib_complex128_t *X, const CBLAS_INT strideX );
```

#### c_zdscal_ndarray( N, alpha, \*X, strideX, offsetX )

Scales a double-precision complex floating-point vector by a double-precision floating-point constant using alternative indexing semantics.

```c
#include "stdlib/complex/float64/ctor.h"

stdlib_complex128_t x[] = {
stdlib_complex128( 1.0, 2.0 ),
stdlib_complex128( 3.0, 4.0 ),
stdlib_complex128( 5.0, 6.0 )
};

c_zdscal_ndarray( 3, 2.0, x, 1, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **alpha**: `[in] double` constant.
- **x**: `[inout] void*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `x`.
- **offsetX**: `[in] CBLAS_INT` starting index for `x`.

```c
void c_zdscal_ndarray( const CBLAS_INT N, const double alpha, stdlib_complex128_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/blas/base/zdscal.h"
#include "stdlib/complex/float64/ctor.h"
#include "stdlib/complex/float64/real.h"
#include "stdlib/complex/float64/imag.h"
#include <stdio.h>

int main( void ) {
// Create strided arrays:
stdlib_complex128_t x[] = {
stdlib_complex128( 1.0, 2.0 ),
stdlib_complex128( 3.0, 4.0 ),
stdlib_complex128( 5.0, 6.0 ),
stdlib_complex128( 7.0, 8.0 )
};

// Specify the number of elements:
const int N = 4;

// Specify stride lengths:
const int strideX = 1;

c_zdscal( N, 2.0, (void *)x, strideX );

// Print the result:
for ( int i = 0; i < N; i++ ) {
printf( "x[ %i ] = %lf + %lfj\n", i, stdlib_complex128_real( x[ i ] ), stdlib_complex128_imag( x[ i ] ) );
}

c_zdscal_ndarray( N, 2.0, (void *)x, strideX, 0 );

// Print the result:
for ( int i = 0; i < N; i++ ) {
printf( "x[ %i ] = %lf + %lfj\n", i, stdlib_complex128_real( x[ i ] ), stdlib_complex128_imag( x[ i ] ) );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Complex128Array = require( '@stdlib/array/complex128' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var zdscal = tryRequire( resolve( __dirname, './../lib/zdscal.native.js' ) );
var opts = {
'skip': ( zdscal instanceof Error )
};
var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var viewX;
var i;

viewX = reinterpret( x, 0 );
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
zdscal( x.length, 2.0, x, 1 );
if ( isnan( viewX[ i%(len*2) ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( viewX[ i%(len*2) ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+'::native:len='+len, opts, f );
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Complex128Array = require( '@stdlib/array/complex128' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var zdscal = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( zdscal instanceof Error )
};
var options = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x = new Complex128Array( uniform( len*2, -100.0, 100.0, options ) );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var viewX;
var i;

viewX = reinterpret( x, 0 );
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
zdscal( x.length, 2.0, x, 1, 0 );
if ( isnan( viewX[ i%(len*2) ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( viewX[ i%(len*2) ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+'::native:ndarray:len='+len, opts, f );
}
}

main();
Loading