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

@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.

-->

# dlogspace

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

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### dlogspace( arrays )

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

```javascript
var Float64Vector = require( '@stdlib/ndarray/vector/float64' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );

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

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

var strt = scalar2ndarray( 0.0, {
'dtype': 'float64'
});

var stp = scalar2ndarray( 3.0, {
'dtype': 'float64'
});

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

var out = dlogspace( [ x, base, strt, stp, endpoint ] );
// returns <ndarray>[ 1.0, 10.0, 100.0, 1000.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 spacing between the 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`.

- 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 Float64Vector = require( '@stdlib/ndarray/vector/float64' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );

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

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

var strt = scalar2ndarray( 0.0, {
'dtype': 'float64'
});

var stp = scalar2ndarray( 1.0, {
'dtype': 'float64'
});

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

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

var arr = ndarray2array( x );
// returns [ 1.0, ~3.16, 10.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.

- If `start < stop`, the exponents are written to a provided input ndarray in ascending order; otherwise, they are written in descending order.

- The input ndarray is **mutated**.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var discreteUniform = require( '@stdlib/random/discrete-uniform' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var ndarraylike2scalar = require( '@stdlib/ndarray/ndarraylike2scalar' );
var dlogspace = require( '@stdlib/blas/ext/base/ndarray/dlogspace' );

var opts = {
'dtype': 'float64'
};

var x = discreteUniform( [ 10 ], -100, 100, opts );
console.log( ndarray2array( x ) );

var base = scalar2ndarray( 10.0, opts );
console.log( 'Base: %d', ndarraylike2scalar( base ) );

var strt = scalar2ndarray( 0.0, opts );
console.log( 'Start: %d', ndarraylike2scalar( strt ) );

var stp = scalar2ndarray( 9.0, opts );
console.log( 'Stop: %d', ndarraylike2scalar( stp ) );

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

dlogspace( [ 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,119 @@
/**
* @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 uniform = require( '@stdlib/random/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var dlogspace = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'float64'
};


// 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 = uniform( [ len ], 0.0, 100.0, options );
base = scalar2ndarray( 10.0, options );
strt = scalar2ndarray( 0.0, options );
stp = [
scalar2ndarray( 9.0, options ),
scalar2ndarray( 5.0, options )
];
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 = dlogspace( [ x, base, strt, stp[ i%2 ], endpoint ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( isnan( out.get( i%len ) ) ) {
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( format( '%s:len=%d', pkg, len ), f );
}
}

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

{{alias}}( arrays )
Fills a one-dimensional double-precision 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`.

If `start` is less than `stop`, the set of values written to an input
ndarray will be written in ascending order, and, if `start` is greater than
`stop`, the set of written values 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 opts = { 'dtype': 'float64' };
> var x = new {{alias:@stdlib/ndarray/vector/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] );

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

// Specify the exponent of the starting value:
> var strt = {{alias:@stdlib/ndarray/from-scalar}}( 0.0, opts );

// Specify the exponent of the final value:
> var stp = {{alias:@stdlib/ndarray/from-scalar}}( 3.0, opts );

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

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

See Also
--------
Loading