|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# dcartesianPower |
| 22 | + |
| 23 | +> Compute the Cartesian power for a double-precision floating-point strided array. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +</section> |
| 28 | + |
| 29 | +<!-- /.intro --> |
| 30 | + |
| 31 | +<section class="usage"> |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +```javascript |
| 36 | +var dcartesianPower = require( '@stdlib/blas/ext/base/dcartesian-power' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### dcartesianPower( N, k, x, strideX, out, strideOut1, strideOut2 ) |
| 40 | + |
| 41 | +Computes the Cartesian power for a double-precision floating-point strided array. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 45 | + |
| 46 | +var x = new Float64Array( [ 1.0, 2.0 ] ); |
| 47 | +var out = new Float64Array( 8 ); |
| 48 | + |
| 49 | +dcartesianPower( x.length, 2, x, 1, out, 2, 1 ); |
| 50 | +// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] |
| 51 | +``` |
| 52 | + |
| 53 | +The function has the following parameters: |
| 54 | + |
| 55 | +- **N**: number of indexed elements. |
| 56 | +- **k**: power. |
| 57 | +- **x**: input [`Float64Array`][@stdlib/array/float64]. |
| 58 | +- **strideX**: stride length. |
| 59 | +- **out**: output [`Float64Array`][@stdlib/array/float64]. |
| 60 | +- **strideOut1**: stride length between consecutive output pairs. |
| 61 | +- **strideOut2**: stride length between elements within each output pair. |
| 62 | + |
| 63 | +The `N`, `k`, and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the Cartesian power of every other element: |
| 64 | + |
| 65 | +```javascript |
| 66 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 67 | + |
| 68 | +var x = new Float64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); |
| 69 | +var out = new Float64Array( 8 ); |
| 70 | + |
| 71 | +dcartesianPower( 2, 2, x, 2, out, 2, 1 ); |
| 72 | +// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] |
| 73 | +``` |
| 74 | + |
| 75 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 76 | + |
| 77 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 78 | + |
| 79 | +```javascript |
| 80 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 81 | + |
| 82 | +// Initial arrays... |
| 83 | +var x0 = new Float64Array( [ 0.0, 1.0, 2.0 ] ); |
| 84 | +var out0 = new Float64Array( 8 ); |
| 85 | + |
| 86 | +// Create offset views... |
| 87 | +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 88 | + |
| 89 | +dcartesianPower( 2, 2, x1, 1, out0, 2, 1 ); |
| 90 | +// out0 => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] |
| 91 | +``` |
| 92 | + |
| 93 | +<!--lint disable maximum-heading-length--> |
| 94 | + |
| 95 | +#### dcartesianPower.ndarray( N, k, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) |
| 96 | + |
| 97 | +<!--lint enable maximum-heading-length--> |
| 98 | + |
| 99 | +Computes the Cartesian power for a double-precision floating-point strided array using alternative indexing semantics. |
| 100 | + |
| 101 | +```javascript |
| 102 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 103 | + |
| 104 | +var x = new Float64Array( [ 1.0, 2.0 ] ); |
| 105 | +var out = new Float64Array( 8 ); |
| 106 | + |
| 107 | +dcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0 ); |
| 108 | +// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] |
| 109 | +``` |
| 110 | + |
| 111 | +The function has the following additional parameters: |
| 112 | + |
| 113 | +- **offsetX**: starting index. |
| 114 | +- **offsetOut**: starting index. |
| 115 | + |
| 116 | +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to compute the Cartesian power of every other value in the strided input array starting from the second value: |
| 117 | + |
| 118 | +```javascript |
| 119 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 120 | + |
| 121 | +var x = new Float64Array( [ 0.0, 1.0, 2.0 ] ); |
| 122 | +var out = new Float64Array( 8 ); |
| 123 | + |
| 124 | +dcartesianPower.ndarray( 2, 2, x, 1, 1, out, 2, 1, 0 ); |
| 125 | +// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ] |
| 126 | +``` |
| 127 | + |
| 128 | +</section> |
| 129 | + |
| 130 | +<!-- /.usage --> |
| 131 | + |
| 132 | +<section class="notes"> |
| 133 | + |
| 134 | +## Notes |
| 135 | + |
| 136 | +- If `N <= 0` or `k <= 0`, both functions return `out` unchanged. |
| 137 | +- The output array must contain at least `N^k` elements. |
| 138 | + |
| 139 | +</section> |
| 140 | + |
| 141 | +<!-- /.notes --> |
| 142 | + |
| 143 | +<section class="examples"> |
| 144 | + |
| 145 | +## Examples |
| 146 | + |
| 147 | +<!-- eslint no-undef: "error" --> |
| 148 | + |
| 149 | +```javascript |
| 150 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 151 | +var dcartesianPower = require( '@stdlib/blas/ext/base/dcartesian-power' ); |
| 152 | + |
| 153 | +var x = new Float64Array( [ 1.0, 2.0 ] ); |
| 154 | +console.log( x ); |
| 155 | + |
| 156 | +var out = new Float64Array( 24 ); |
| 157 | + |
| 158 | +dcartesianPower( x.length, 3, x, 1, out, 3, 1 ); |
| 159 | +console.log( out ); |
| 160 | +``` |
| 161 | + |
| 162 | +</section> |
| 163 | + |
| 164 | +<!-- /.examples --> |
| 165 | + |
| 166 | +<!-- C interface documentation. --> |
| 167 | + |
| 168 | +* * * |
| 169 | + |
| 170 | +<section class="c"> |
| 171 | + |
| 172 | +## C APIs |
| 173 | + |
| 174 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 175 | + |
| 176 | +<section class="intro"> |
| 177 | + |
| 178 | +</section> |
| 179 | + |
| 180 | +<!-- /.intro --> |
| 181 | + |
| 182 | +<!-- C usage documentation. --> |
| 183 | + |
| 184 | +<section class="usage"> |
| 185 | + |
| 186 | +### Usage |
| 187 | + |
| 188 | +```c |
| 189 | +#include "stdlib/blas/ext/base/dcartesianpower.h" |
| 190 | +``` |
| 191 | + |
| 192 | +<!--lint disable maximum-heading-length--> |
| 193 | + |
| 194 | +#### stdlib_strided_dcartesian_power( N, k, \*X, strideX, \*Out, strideOut1, strideOut2 ) |
| 195 | + |
| 196 | +<!--lint enable maximum-heading-length--> |
| 197 | + |
| 198 | +Computes the Cartesian power for a double-precision floating-point strided array. |
| 199 | + |
| 200 | +```c |
| 201 | +const double X[] = { 1.0, 2.0 }; |
| 202 | +double Out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; |
| 203 | + |
| 204 | +stdlib_strided_dcartesian_power( 2, 2, X, 1, Out, 2, 1 ); |
| 205 | +``` |
| 206 | +
|
| 207 | +The function accepts the following arguments: |
| 208 | +
|
| 209 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 210 | +- **k**: `[in] CBLAS_INT` power. |
| 211 | +- **X**: `[in] double*` input array. |
| 212 | +- **strideX**: `[in] CBLAS_INT` stride length. |
| 213 | +- **Out**: `[out] double*` output array. |
| 214 | +- **strideOut1**: `[in] CBLAS_INT` stride length between consecutive output pairs. |
| 215 | +- **strideOut2**: `[in] CBLAS_INT` stride length between elements within each output pair. |
| 216 | +
|
| 217 | +```c |
| 218 | +void stdlib_strided_dcartesian_power( const CBLAS_INT N, const CBLAS_INT k, const double *X, const CBLAS_INT strideX, double *Out, const CBLAS_INT strideOut1, const CBLAS_INT strideOut2 ); |
| 219 | +``` |
| 220 | + |
| 221 | +<!--lint disable maximum-heading-length--> |
| 222 | + |
| 223 | +#### stdlib_strided_dcartesian_power_ndarray( N, k, \*X, strideX, offsetX, \*Out, strideOut1, strideOut2, offsetOut ) |
| 224 | + |
| 225 | +<!--lint enable maximum-heading-length--> |
| 226 | + |
| 227 | +Computes the Cartesian power for a double-precision floating-point strided array using alternative indexing semantics. |
| 228 | + |
| 229 | +```c |
| 230 | +const double X[] = { 1.0, 2.0 }; |
| 231 | +double Out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; |
| 232 | + |
| 233 | +stdlib_strided_dcartesian_power_ndarray( 2, 2, X, 1, 0, Out, 2, 1, 0 ); |
| 234 | +``` |
| 235 | +
|
| 236 | +The function accepts the following arguments: |
| 237 | +
|
| 238 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 239 | +- **k**: `[in] CBLAS_INT` power. |
| 240 | +- **X**: `[in] double*` input array. |
| 241 | +- **strideX**: `[in] CBLAS_INT` stride length. |
| 242 | +- **offsetX**: `[in] CBLAS_INT` starting index. |
| 243 | +- **Out**: `[out] double*` output array. |
| 244 | +- **strideOut1**: `[in] CBLAS_INT` stride length between consecutive output pairs. |
| 245 | +- **strideOut2**: `[in] CBLAS_INT` stride length between elements within each output pair. |
| 246 | +- **offsetOut**: `[in] CBLAS_INT` starting index. |
| 247 | +
|
| 248 | +```c |
| 249 | +void stdlib_strided_dcartesian_power_ndarray( const CBLAS_INT N, const CBLAS_INT k, 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 ); |
| 250 | +``` |
| 251 | + |
| 252 | +</section> |
| 253 | + |
| 254 | +<!-- /.usage --> |
| 255 | + |
| 256 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 257 | + |
| 258 | +<section class="notes"> |
| 259 | + |
| 260 | +</section> |
| 261 | + |
| 262 | +<!-- /.notes --> |
| 263 | + |
| 264 | +<!-- C API usage examples. --> |
| 265 | + |
| 266 | +<section class="examples"> |
| 267 | + |
| 268 | +### Examples |
| 269 | + |
| 270 | +```c |
| 271 | +#include "stdlib/blas/ext/base/dcartesianpower.h" |
| 272 | +#include <stdio.h> |
| 273 | + |
| 274 | +int main( void ) { |
| 275 | + // Create a strided input array: |
| 276 | + const double X[] = { 1.0, 2.0 }; |
| 277 | + |
| 278 | + // Specify the number of indexed elements and power: |
| 279 | + const int N = 2; |
| 280 | + const int k = 2; |
| 281 | + |
| 282 | + // Create an output array: |
| 283 | + double out[ 8 ] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; |
| 284 | + |
| 285 | + // Specify strides: |
| 286 | + const int strideX = 1; |
| 287 | + const int strideOut1 = 2; |
| 288 | + const int strideOut2 = 1; |
| 289 | + |
| 290 | + // Compute the Cartesian power: |
| 291 | + stdlib_strided_dcartesian_power( N, k, X, strideX, out, strideOut1, strideOut2 ); |
| 292 | + |
| 293 | + // Print the result: |
| 294 | + for ( int i = 0; i < N*N; i++ ) { |
| 295 | + printf( "out[ %i ] = ( %lf, %lf )\n", i, out[ i*2 ], out[ i*2+1 ] ); |
| 296 | + } |
| 297 | +} |
| 298 | +``` |
| 299 | +
|
| 300 | +</section> |
| 301 | +
|
| 302 | +<!-- /.examples --> |
| 303 | +
|
| 304 | +</section> |
| 305 | +
|
| 306 | +<!-- /.c --> |
| 307 | +
|
| 308 | +<section class="references"> |
| 309 | +
|
| 310 | +</section> |
| 311 | +
|
| 312 | +<!-- /.references --> |
| 313 | +
|
| 314 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 315 | +
|
| 316 | +<section class="related"> |
| 317 | +
|
| 318 | +</section> |
| 319 | +
|
| 320 | +<!-- /.related --> |
| 321 | +
|
| 322 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 323 | +
|
| 324 | +<section class="links"> |
| 325 | +
|
| 326 | +[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64 |
| 327 | +
|
| 328 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 329 | +
|
| 330 | +</section> |
| 331 | +
|
| 332 | +<!-- /.links --> |
0 commit comments