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

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

-->

# dcombinations

> Compute combinations of a specified length from double-precision floating-point strided array elements.

<section class="usage">

## Usage

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

<!-- lint disable maximum-heading-length -->

#### dcombinations( order, N, k, replacement, x, strideX, out, LDO, workspace, strideW )

<!-- lint enable maximum-heading-length -->

Computes combinations of a specified length from double-precision floating-point strided array elements.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var out = new Float64Array( 12 );
var workspace = new Int32Array( 2 );

dcombinations( 'row-major', x.length, 2, false, x, 1, out, 2, workspace, 1 );
// out => <Float64Array>[ 1.0, 2.0, 1.0, 3.0, 1.0, 4.0, 2.0, 3.0, 2.0, 4.0, 3.0, 4.0 ]
```

The function has the following parameters:

- **order**: storage layout. Must be either `'row-major'` or `'column-major'`.
- **N**: number of indexed elements.
- **k**: number of elements to combine.
- **replacement**: boolean indicating whether to allow duplication in combination.
- **x**: input [`Float64Array`][@stdlib/array/float64].
- **strideX**: stride length for `x`.
- **out**: output [`Float64Array`][@stdlib/array/float64].
- **LDO**: stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`).
- **workspace**: workspace [`Int32Array`][@stdlib/array/int32]. Must have at least `k` elements.
- **strideW**: stride length for `workspace`.

The `N`, `k`, and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to operate on every other element:

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );

var x = new Float64Array( [ 1.0, 0.0, 2.0, 0.0, 3.0 ] );
var out = new Float64Array( 6 );
var workspace = new Int32Array( 2 );

dcombinations( 'row-major', 3, 2, false, x, 2, out, 2, workspace, 1 );
// out => <Float64Array>[ 1.0, 2.0, 1.0, 3.0, 2.0, 3.0 ]
```

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );

// Initial array:
var x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] );

// Create an offset view:
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var out = new Float64Array( 6 );
var workspace = new Int32Array( 2 );

dcombinations( 'row-major', 3, 2, false, x1, 1, out, 2, workspace, 1 );
// out => <Float64Array>[ 1.0, 2.0, 1.0, 3.0, 2.0, 3.0 ]
```

<!-- lint disable maximum-heading-length -->

#### dcombinations.ndarray( N, k, replacement, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut, workspace, strideW, offsetW )

<!-- lint enable maximum-heading-length -->

Computes combinations of a specified length from double-precision floating-point strided array elements using alternative indexing semantics.

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var out = new Float64Array( 12 );
var workspace = new Int32Array( 2 );

dcombinations.ndarray( x.length, 2, false, x, 1, 0, out, 2, 1, 0, workspace, 1, 0 );
// out => <Float64Array>[ 1.0, 2.0, 1.0, 3.0, 1.0, 4.0, 2.0, 3.0, 2.0, 4.0, 3.0, 4.0 ]
```

The function has the following additional parameters:

- **offsetX**: starting index for `x`.
- **strideOut1**: stride length for the first dimension of `out`.
- **strideOut2**: stride length for the second dimension of `out`.
- **offsetOut**: starting index for `out`.
- **workspace**: workspace [`Int32Array`][@stdlib/array/int32]. Must have at least `k` elements.
- **strideW**: stride length for `workspace`.
- **offsetW**: starting index for `workspace`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on a starting index. For example, to access only the last three elements:

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );

var x = new Float64Array( [ 0.0, 0.0, 1.0, 2.0, 3.0 ] );
var out = new Float64Array( 6 );
var workspace = new Int32Array( 2 );

dcombinations.ndarray( 3, 2, false, x, 1, 2, out, 2, 1, 0, workspace, 1, 0 );
// out => <Float64Array>[ 1.0, 2.0, 1.0, 3.0, 2.0, 3.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N <= 0` or `k <= 0`, both functions return `out` unchanged.
- If `replacement` is `false` and `k > N`, both functions return `out` unchanged.
- For an input array `x` of length `N`, the output array `out` must contain at least `C(N, k) * k` elements if `replacement` is `false`, or `C(N+k-1, k) * k` elements if `replacement` is `true`.
- For row-major order, the `LDO` parameter must be greater than or equal to `k`. For column-major order, the `LDO` parameter must be greater than or equal to `max(1,C(N,k))` if `replacement` is `false`, or `max(1,C(N+k-1,k))` if `replacement` is `true`.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );
var dcombinations = require( '@stdlib/blas/ext/base/dcombinations' );

var N = 5;
var k = 2;
var x = discreteUniform( N, 1, 10, {
'dtype': 'float64'
});
console.log( x );

var out = new Float64Array( 20 );

var workspace = new Int32Array( k );

dcombinations( 'row-major', N, k, false, x, 1, out, 2, workspace, 1 );
console.log( out );
```

</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/blas/ext/base/dcombinations.h"
```

<!-- lint disable maximum-heading-length -->

#### stdlib_strided_dcombinations( order, N, k, replacement, \*X, strideX, \*Out, LDO, \*Workspace, strideW )

<!-- lint enable maximum-heading-length -->

Computes combinations of a specified length from double-precision floating-point strided array elements.

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

const double x[] = { 1.0, 2.0, 3.0, 4.0 };
double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
int32_t workspace[] = { 0, 0 };

stdlib_strided_dcombinations( CblasRowMajor, 4, 2, false, x, 1, out, 2, workspace, 1 );
```

The function accepts the following arguments:

- **order**: `[in] CBLAS_LAYOUT` storage layout.
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **k**: `[in] CBLAS_INT` number of elements to combine.
- **replacement**: `[in] bool` boolean indicating whether to allow duplication in combination.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Out**: `[out] double*` output array.
- **LDO**: `[in] CBLAS_INT` stride length between successive contiguous vectors of the matrix `Out` (a.k.a., leading dimension of `Out`). For row-major order, must be greater than or equal to `k`. For column-major order, must be greater than or equal to `max(1,C(N,k))` if `replacement` is `false`, or `max(1,C(N+k-1,k))` if `replacement` is `true`.
- **Workspace**: `[out] int32_t*` workspace array. Must have at least `k` elements.
- **strideW**: `[in] CBLAS_INT` stride length for `Workspace`.

```c
void stdlib_strided_dcombinations( const CBLAS_LAYOUT order, const CBLAS_INT N, const CBLAS_INT k, const bool replacement, const double *X, const CBLAS_INT strideX, double *Out, const CBLAS_INT LDO, int32_t *Workspace, const CBLAS_INT strideW );
```

<!-- lint disable maximum-heading-length -->

#### stdlib_strided_dcombinations_ndarray( N, k, replacement, \*X, strideX, offsetX, \*Out, strideOut1, strideOut2, offsetOut, \*Workspace, strideW, offsetW )

<!-- lint enable maximum-heading-length -->

Computes combinations of a specified length from double-precision floating-point strided array elements using alternative indexing semantics.

```c
const double x[] = { 1.0, 2.0, 3.0, 4.0 };
double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
int32_t workspace[] = { 0, 0 };

stdlib_strided_dcombinations_ndarray( 4, 2, false, x, 1, 0, out, 2, 1, 0, workspace, 1, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **k**: `[in] CBLAS_INT` number of elements to combine.
- **replacement**: `[in] bool` boolean indicating whether to allow duplication in combination.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Out**: `[out] double*` output array.
- **strideOut1**: `[in] CBLAS_INT` stride length for the first dimension of `Out`.
- **strideOut2**: `[in] CBLAS_INT` stride length for the second dimension of `Out`.
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.
- **Workspace**: `[out] int32_t*` workspace array. Must have at least `k` elements.
- **strideW**: `[in] CBLAS_INT` stride length for `Workspace`.
- **offsetW**: `[in] CBLAS_INT` starting index for `Workspace`.

```c
void stdlib_strided_dcombinations_ndarray( const CBLAS_INT N, const CBLAS_INT k, const bool replacement, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Out, const CBLAS_INT strideOut1, const CBLAS_INT strideOut2, const CBLAS_INT offsetOut, int32_t *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW );
```

</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/ext/base/dcombinations.h"
#include "stdlib/blas/base/shared.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

int main( void ) {
// Create a strided array:
const double x[] = { 1.0, 2.0, 3.0, 4.0 };

// Create an output array:
double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

// Create a workspace array:
int32_t workspace[] = { 0, 0 };

// Specify strides:
const int strideX = 1;
const int strideW = 1;
const int LDO = 2;

// Compute combinations:
stdlib_strided_dcombinations( CblasRowMajor, 4, 2, false, x, strideX, out, LDO, workspace, strideW );

// Print each combination:
for ( int i = 0; i < 6; i++ ) {
printf( " [ %lf, %lf ]\n", out[ i*2 ], out[ (i*2)+1 ] );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

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

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

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

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

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

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

</section>

<!-- /.links -->
Loading