Skip to content
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
356 changes: 356 additions & 0 deletions lib/node_modules/@stdlib/stats/strided/scurange/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,356 @@
<!--

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

-->

# scurange

> Compute the cumulative range of a single-precision floating-point strided array.

<section class="intro">

The **cumulative range** at index `i` is defined as the difference between the maximum and minimum values in the subarray `x[0..i]`.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var scurange = require( '@stdlib/stats/strided/scurange' );
```

#### scurange( N, x, strideX, y, strideY )

Computes the cumulative [range][range] of a single-precision floating-point strided array `x`.

```javascript
var Float32Array = require( '@stdlib/array/float32' );

var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
var y = new Float32Array( x.length );

scurange( x.length, x, 1, y, 1 );
// y => <Float32Array>[ 0.0, 3.0, 4.0 ]
```

The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Float32Array`][@stdlib/array/float32].
- **strideX**: index increment for `x`.
- **y**: output [`Float32Array`][@stdlib/array/float32].
- **strideY**: index increment for `y`.

The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the cumulative [range][range] of every other element in `x` and store the results in every other element of y,

```javascript
var Float32Array = require( '@stdlib/array/float32' );

var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
var y = new Float32Array( x.length );

scurange( 4, x, 2, y, 2 );
// y => <Float32Array>[ 0.0, 0.0, 1.0, 0.0, 4.0, 0.0, 6.0, 0.0 ]
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

<!-- eslint-disable stdlib/capitalized-comments -->

```javascript
var Float32Array = require( '@stdlib/array/float32' );

// Input array:
var x0 = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );

// Create a view of x0 starting at the 2nd element:
var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 );

// Create an output array:
var y0 = new Float32Array( x0.length );

// Create a view of y0 starting at the 2nd element:
var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 );

scurange( 3, x1, 2, y1, 2 );
// y0 => <Float32Array>[ 0.0, 0.0, 0.0, 2.0, 0.0, 4.0 ]
```

#### scurange.ndarray

```text
scurange.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )


Computes the cumulative [range][range] of a single-precision floating-point strided array using alternative indexing semantics.

```javascript
var Float32Array = require( '@stdlib/array/float32' );

var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
var y = new Float32Array( x.length );

scurange.ndarray( x.length, x, 1, 0, y, 1, 0 );
// y => <Float32Array>[ 0.0, 3.0, 4.0 ]
```

The function has the following additional parameters:

- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [range][range] for every other element in `x` starting from the second element and store the results in y starting from the first element:

```javascript
var Float32Array = require( '@stdlib/array/float32' );

var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
var y = new Float32Array( 4 );

scurange.ndarray( 4, x, 2, 1, y, 1, 0 );
// y => <Float32Array>[ 0.0, 3.0, 4.0, 6.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N <= 0`, both functions return the output array `y` unchanged.
- If an indexed input value is `NaN`, all subsequent output values are `NaN`.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Float32Array = require( '@stdlib/array/float32' );
var scurange = require( '@stdlib/stats/strided/scurange' );

var x = discreteUniform( 10, -50, 50, {
'dtype': 'float32'
});
var y = new Float32Array( x.length );

console.log( x );
console.log( y );

scurange( x.length, x, 1, y, 1 );

console.log( y );
```

</section>

<!-- /.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/stats/strided/scurange.h"
```

#### stdlib_strided_scurange( N, \*X, strideX, \*Y, strideY )

Computes the cumulative [range][range] of a single-precision floating-point strided array `x`.

```c
const float x[] = { 1.0, -2.0, 3.0, -4.0 };
float y[] = { 0.0, 0.0, 0.0, 0.0 };

stdlib_strided_scurange( 4, x, 1, y, 1 );
// y => <float>[ 0.0, 3.0, 4.0, 0.0 ]
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] float*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Y**: `[out] float*` output array.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.

```c
void stdlib_strided_scurange( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY );
```

#### stdlib_strided_scurange_ndarray

```c
void stdlib_strided_scurange_ndarray(
const CBLAS_INT N,
const float *X,
const CBLAS_INT strideX,
const CBLAS_INT offsetX,
float *Y,
const CBLAS_INT strideY,
const CBLAS_INT offsetY
);


Computes the cumulative [range][range] of a single-precision floating-point strided array using alternative indexing semantics.

```c
const float x[] = { 1.0, -2.0, 3.0, -4.0 };
float y[] = { 0.0, 0.0, 0.0, 0.0 };

stdlib_strided_scurange_ndarray( 4, x, 1, 0, y, 1, 0 );
// y => <float>[ 0.0, 3.0, 4.0, 0.0 ]
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] float*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[out] float*` output array.
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.

```c
void stdlib_strided_scurange_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
```

</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/stats/strided/scurange.h"
#include <stdio.h>

int main( void ) {
// Create a strided array:
const float x[] = { 1.0, -2.0, -3.0, 4.0, -5.0, -6.0, 7.0, 8.0 };

// Create an output array:
float y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

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

// Specify the stride lengths:
const int strideX = 2;
const int strideY = 1;

// Compute the cumulative range:
stdlib_strided_scurange( N, x, strideX, y, strideY );

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

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

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

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/stats/strided/scumax`][@stdlib/stats/strided/scumax]</span><span class="delimiter">: </span><span class="description">calculate the cumulative maximum value of a single-precision floating-point strided array.</span>
- <span class="package-name">[`@stdlib/stats/strided/scumin`][@stdlib/stats/strided/scumin]</span><span class="delimiter">: </span><span class="description">calculate the cumulative minimum value of a single-precision floating-point strided array.</span>
- <span class="package-name">[`@stdlib/stats/strided/srange`][@stdlib/stats/strided/srange]</span><span class="delimiter">: </span><span class="description">calculate the range of a single-precision floating-point strided array.</span>

</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">

[range]: https://en.wikipedia.org/wiki/Range_%28statistics%29

[@stdlib/array/float32]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float32

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

<!-- <related-links> -->

[@stdlib/stats/strided/scumax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/scumax

[@stdlib/stats/strided/scumin]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/scumin

[@stdlib/stats/strided/srange]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/srange

<!-- </related-links> -->

</section>

<!-- /.links -->
Loading