Skip to content
Merged
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
202 changes: 202 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/ndarray/clogspace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<!--

@license Apache-2.0

Copyright (c) 2026 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.

-->

# clogspace

> Fill a one-dimensional single-precision complex floating-point ndarray with logarithmically spaced values over a specified interval.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var clogspace = require( '@stdlib/blas/ext/base/ndarray/clogspace' );
```

#### clogspace( arrays )

Fills a one-dimensional single-precision complex floating-point ndarray with logarithmically spaced values over a specified interval.

<!-- eslint-disable max-len -->

```javascript
var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );

var x = new Complex64Vector( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

var base = scalar2ndarray( 10.0, {
'dtype': 'float32'
});

var strt = scalar2ndarray( new Complex64( 0.0, 0.0 ), {
'dtype': 'complex64'
});

var stp = scalar2ndarray( new Complex64( 3.0, 0.0 ), {
'dtype': 'complex64'
});

var endpoint = scalar2ndarray( true, {
'dtype': 'bool'
});

var out = clogspace( [ x, base, strt, stp, endpoint ] );
// returns <ndarray>[ <Complex64>[ 1.0, 0.0 ], <Complex64>[ 10.0, 0.0 ], <Complex64>[ 100.0, 0.0 ], <Complex64>[ 1000.0, 0.0 ] ]
```

The function has the following parameters:

- **arrays**: array-like object containing the following ndarrays:

- a one-dimensional input ndarray.
- a zero-dimensional ndarray specifying the base of the logarithmic scale.
- a zero-dimensional ndarray specifying the exponent of the starting value, where the starting value is given by `base^start`.
- a zero-dimensional ndarray specifying the exponent of the final value, where the final value is given by `base^stop`.
- a zero-dimensional ndarray specifying whether to include the `base^stop` value when writing values to the input ndarray. If `true`, the input ndarray is filled with logarithmically spaced values over the closed interval `[base^start, base^stop]`. If `false`, the input ndarray is filled with logarithmically spaced values over the half-open interval `[base^start, base^stop)`.

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Let `M` be the number of generated values (which is either `N` or `N+1` depending on whether `endpoint` is `true` or `false`, respectively). The complex increment between exponents is thus given by

```text
Δ = (stop-start)/(M-1)
```

and the generated values are equal to `base^(start+Δ*i)` for `i = 0, 1, ..., M-1`, where exponentiation is performed in the complex sense.

- When the number of generated values is greater than `1` and `endpoint` is `true`, the set of values written to a provided input ndarray is guaranteed to include the `base^start` and `base^stop` values. Beware, however, that values between `base^start` and `base^stop` are subject to floating-point rounding errors. Hence,

<!-- eslint-disable max-len -->

```javascript
var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );

var x = new Complex64Vector( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

var base = scalar2ndarray( 10.0, {
'dtype': 'float32'
});

var strt = scalar2ndarray( new Complex64( 0.0, 0.0 ), {
'dtype': 'complex64'
});

var stp = scalar2ndarray( new Complex64( 1.0, 0.0 ), {
'dtype': 'complex64'
});

var endpoint = scalar2ndarray( true, {
'dtype': 'bool'
});

clogspace( [ x, base, strt, stp, endpoint ] );

var v = x.get( 1 );
// returns <Complex64>[ ~3.162, 0.0 ]
```

where `arr[1]` is only guaranteed to be approximately equal to the square root of `10`.

- When `N = 1` and `endpoint` is `false`, only the `base^start` value is written to a provided input ndarray. When `N = 1` and `endpoint` is `true`, only the `base^stop` value is written to a provided input ndarray.

- Generated values follow a logarithmic spiral in the complex plane, where imaginary components of `start` and `stop` control phase rotation. If `Re(start) < Re(stop)`, the magnitudes of the generated values are in ascending order; otherwise, the magnitudes are in descending order.

- The input ndarray is **mutated**.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' );
var clogspace = require( '@stdlib/blas/ext/base/ndarray/clogspace' );

var x = new Complex64Vector( 10 );
console.log( ndarray2array( x ) );

var base = scalar2ndarray( 10.0, {
'dtype': 'float32'
});
console.log( 'Base: %d', ndarraylike2scalar( base ) );

var strt = scalar2ndarray( new Complex64( 0.0, 0.0 ), {
'dtype': 'complex64'
});
console.log( 'Start: %s', ndarraylike2scalar( strt ) );

var stp = scalar2ndarray( new Complex64( 9.0, 1.0 ), {
'dtype': 'complex64'
});
console.log( 'Stop: %s', ndarraylike2scalar( stp ) );

var endpoint = scalar2ndarray( true, {
'dtype': 'bool'
});
console.log( 'Endpoint: %s', ndarraylike2scalar( endpoint ) );

clogspace( [ x, base, strt, stp, endpoint ] );
console.log( ndarray2array( x ) );
```

</section>

<!-- /.examples -->

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

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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 bench = require( '@stdlib/bench' );
var pow = require( '@stdlib/math/base/special/pow' );
var format = require( '@stdlib/string/format' );
var Complex64Vector = require( '@stdlib/ndarray/vector/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var pkg = require( './../package.json' ).name;
var clogspace = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var endpoint;
var base;
var strt;
var stp;
var x;

x = new Complex64Vector( len );
base = scalar2ndarray( 10.0, {
'dtype': 'float32'
});
strt = scalar2ndarray( new Complex64( 0.0, 0.0 ), {
'dtype': 'complex64'
});
stp = [
scalar2ndarray( new Complex64( 9.0, 1.0 ), {
'dtype': 'complex64'
}),
scalar2ndarray( new Complex64( 5.0, 1.0 ), {
'dtype': 'complex64'
})
];
endpoint = scalar2ndarray( true, {
'dtype': 'bool'
});
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = clogspace( [ x, base, strt, stp[ i%2 ], endpoint ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( typeof out !== 'object' ) {
b.fail( 'should return an ndarray' );
}
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( format( '%s:len=%d', pkg, len ), f );
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

{{alias}}( arrays )
Fills a one-dimensional single-precision complex floating-point ndarray
with logarithmically spaced values over a specified interval.

Let `N` be the number of elements in the input ndarray. If `N = 1` and
`endpoint` is `true`, the set of values written to an input ndarray only
includes `base^stop`, but not `base^start`; otherwise, when `N = 1` and
`endpoint` is `false`, the set of values written to an input ndarray only
includes `base^start`, but not `base^stop`.

Generated values follow a logarithmic spiral in the complex plane, where
imaginary components of `start` and `stop` control phase rotation. If the
real part of `start` is less than that of `stop`, the magnitudes of the
generated values will be in ascending order; otherwise, the magnitudes will
be in descending order.

When `N >= 2` and `endpoint` is `true`, the set of values written to an
input ndarray is guaranteed to include the `base^start` and `base^stop`
values. Beware, however, that values between `base^start` and `base^stop`
are subject to floating-point rounding errors.

Parameters
----------
arrays: ArrayLikeObject<ndarray>
Array-like object containing the following ndarrays:

- a one-dimensional input ndarray.
- a zero-dimensional ndarray specifying the base of the logarithmic
scale.
- a zero-dimensional ndarray specifying the exponent of the starting
value.
- a zero-dimensional ndarray specifying the exponent of the final
value.
- a zero-dimensional ndarray specifying whether to include the
`base^stop` value when writing values to the input ndarray.

Returns
-------
out: ndarray
Input ndarray.

Examples
--------
// Create the input ndarray:
> var x = new {{alias:@stdlib/ndarray/vector/complex64}}( [ 0.0, 0.0, 0.0, 0.0 ] );

// Specify the base:
> var base = {{alias:@stdlib/ndarray/from-scalar}}( 10.0, { 'dtype': 'float32' } );

// Specify the exponent of the starting value:
> var s = new {{alias:@stdlib/complex/float32/ctor}}( 0.0, 0.0 );
> var strt = {{alias:@stdlib/ndarray/from-scalar}}( s, { 'dtype': 'complex64' } );

// Specify the exponent of the final value:
> s = new {{alias:@stdlib/complex/float32/ctor}}( 1.0, 0.0 );
> var stp = {{alias:@stdlib/ndarray/from-scalar}}( s, { 'dtype': 'complex64' } );

// Specify whether to include the endpoint:
> var endpoint = {{alias:@stdlib/ndarray/from-scalar}}( true, { 'dtype': 'bool' } );

// Fill the input ndarray:
> {{alias}}( [ x, base, strt, stp, endpoint ] )
<ndarray>[ <Complex64>[ 1.0, 0.0 ], <Complex64>[ 10.0, 0.0 ] ]

See Also
--------
Loading