|
| 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 | +# dvander |
| 22 | + |
| 23 | +> Generate a double-precision floating-point Vandermonde matrix. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +</section> |
| 28 | + |
| 29 | +<!-- /.intro --> |
| 30 | + |
| 31 | +<section class="usage"> |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +```javascript |
| 36 | +var dvander = require( '@stdlib/blas/ext/base/dvander' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### dvander( order, mode, M, N, x, strideX, out, ldo ) |
| 40 | + |
| 41 | +Generates a double-precision floating-point Vandermonde matrix. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 45 | + |
| 46 | +var x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); |
| 47 | +var out = new Float64Array( 9 ); |
| 48 | + |
| 49 | +dvander( 'row-major', -1, 3, 3, x, 1, out, 3 ); |
| 50 | +// out => <Float64Array>[ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ] |
| 51 | +``` |
| 52 | + |
| 53 | +The function has the following parameters: |
| 54 | + |
| 55 | +- **order**: row-major (C-style) or column-major (Fortran-style) order. |
| 56 | +- **mode**: mode. If `mode < 0`, the function generates decreasing powers. If `mode > 0`, the function generates increasing powers. |
| 57 | +- **M**: number of rows in `out`. |
| 58 | +- **N**: number of columns in `out`. |
| 59 | +- **x**: input [`Float64Array`][@stdlib/array/float64]. |
| 60 | +- **strideX**: stride length for `x`. |
| 61 | +- **out**: output matrix stored in linear memory as a [`Float64Array`][@stdlib/array/float64]. |
| 62 | +- **ldo**: stride between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of the matrix `out`). |
| 63 | + |
| 64 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 65 | + |
| 66 | +<!-- eslint-disable stdlib/capitalized-comments, max-len --> |
| 67 | + |
| 68 | +```javascript |
| 69 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 70 | + |
| 71 | +// Initial arrays: |
| 72 | +var x0 = new Float64Array( [ 999.0, 1.0, 2.0, 3.0 ] ); |
| 73 | +var out0 = new Float64Array( 10 ); |
| 74 | + |
| 75 | +// Create offset views: |
| 76 | +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 77 | +var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 78 | + |
| 79 | +dvander( 'row-major', 1, 3, 3, x1, 1, out1, 3 ); |
| 80 | +// out0 => <Float64Array>[ 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] |
| 81 | +``` |
| 82 | + |
| 83 | +When the mode is positive, the matrix is generated such that |
| 84 | + |
| 85 | +```text |
| 86 | +[ |
| 87 | + 1 x_0^1 x_0^2 ... x_0^(N-1) |
| 88 | + 1 x_1^1 x_1^2 ... x_1^(N-1) |
| 89 | + ... |
| 90 | +] |
| 91 | +``` |
| 92 | + |
| 93 | +with increasing powers along the rows. |
| 94 | + |
| 95 | +When the mode is negative, the matrix is generated such that |
| 96 | + |
| 97 | +```text |
| 98 | +[ |
| 99 | + x_0^(N-1) ... x_0^2 x_0^1 1 |
| 100 | + x_1^(N-1) ... x_1^2 x_1^1 1 |
| 101 | + ... |
| 102 | +] |
| 103 | +``` |
| 104 | + |
| 105 | +with decreasing powers along the rows. |
| 106 | + |
| 107 | +<!-- lint disable maximum-heading-length --> |
| 108 | + |
| 109 | +#### dvander.ndarray( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) |
| 110 | + |
| 111 | +<!-- lint enable maximum-heading-length --> |
| 112 | + |
| 113 | +Generates a double-precision floating-point Vandermonde matrix using alternative indexing semantics. |
| 114 | + |
| 115 | +```javascript |
| 116 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 117 | + |
| 118 | +var x = new Float64Array( [ 1.0, 2.0, 3.0 ] ); |
| 119 | +var out = new Float64Array( 9 ); |
| 120 | + |
| 121 | +dvander.ndarray( -1, 3, 3, x, 1, 0, out, 3, 1, 0 ); |
| 122 | +// out => <Float64Array>[ 1.0, 1.0, 1.0, 4.0, 2.0, 1.0, 9.0, 3.0, 1.0 ] |
| 123 | +``` |
| 124 | + |
| 125 | +The function has the following additional parameters: |
| 126 | + |
| 127 | +- **offsetX**: starting index for `x`. |
| 128 | +- **strideOut1**: stride length for the first dimension of `out`. |
| 129 | +- **strideOut2**: stride length for the second dimension of `out`. |
| 130 | +- **offsetOut**: starting index for `out`. |
| 131 | + |
| 132 | +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to use every other element from the input array starting from the second element: |
| 133 | + |
| 134 | +```javascript |
| 135 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 136 | + |
| 137 | +var x = new Float64Array( [ 0.0, 1.0, 0.0, 2.0, 0.0, 3.0 ] ); |
| 138 | +var out = new Float64Array( 9 ); |
| 139 | + |
| 140 | +dvander.ndarray( 1, 3, 3, x, 2, 1, out, 3, 1, 0 ); |
| 141 | +// out => <Float64Array>[ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] |
| 142 | +``` |
| 143 | + |
| 144 | +</section> |
| 145 | + |
| 146 | +<!-- /.usage --> |
| 147 | + |
| 148 | +<section class="notes"> |
| 149 | + |
| 150 | +## Notes |
| 151 | + |
| 152 | +- If `M <= 0` or `N <= 0`, both functions return the output matrix unchanged. |
| 153 | + |
| 154 | +</section> |
| 155 | + |
| 156 | +<!-- /.notes --> |
| 157 | + |
| 158 | +<section class="examples"> |
| 159 | + |
| 160 | +## Examples |
| 161 | + |
| 162 | +<!-- eslint no-undef: "error" --> |
| 163 | + |
| 164 | +```javascript |
| 165 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 166 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 167 | +var dvander = require( '@stdlib/blas/ext/base/dvander' ); |
| 168 | + |
| 169 | +var M = 3; |
| 170 | +var N = 4; |
| 171 | + |
| 172 | +var x = discreteUniform( M, 0, 10, { |
| 173 | + 'dtype': 'float64' |
| 174 | +}); |
| 175 | +var out = new Float64Array( M*N ); |
| 176 | + |
| 177 | +dvander( 'row-major', -1, M, N, x, 1, out, N ); |
| 178 | +console.log( out ); |
| 179 | +``` |
| 180 | + |
| 181 | +</section> |
| 182 | + |
| 183 | +<!-- /.examples --> |
| 184 | + |
| 185 | +<!-- C interface documentation. --> |
| 186 | + |
| 187 | +* * * |
| 188 | + |
| 189 | +<section class="c"> |
| 190 | + |
| 191 | +## C APIs |
| 192 | + |
| 193 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 194 | + |
| 195 | +<section class="intro"> |
| 196 | + |
| 197 | +</section> |
| 198 | + |
| 199 | +<!-- /.intro --> |
| 200 | + |
| 201 | +<!-- C usage documentation. --> |
| 202 | + |
| 203 | +<section class="usage"> |
| 204 | + |
| 205 | +### Usage |
| 206 | + |
| 207 | +```c |
| 208 | +#include "stdlib/blas/ext/base/dvander.h" |
| 209 | +``` |
| 210 | + |
| 211 | +#### stdlib_strided_dvander( order, mode, M, N, \*X, strideX, \*Out, LDO ) |
| 212 | + |
| 213 | +Generates a double-precision floating-point Vandermonde matrix. |
| 214 | + |
| 215 | +```c |
| 216 | +#include "stdlib/blas/base/shared.h" |
| 217 | + |
| 218 | +const double x[ 3 ] = { 1.0, 2.0, 3.0 }; |
| 219 | +double Out[ 3*3 ] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; |
| 220 | + |
| 221 | +stdlib_strided_dvander( CblasRowMajor, -1.0, 3, 3, x, 1, Out, 3 ); |
| 222 | +``` |
| 223 | +
|
| 224 | +The function accepts the following arguments: |
| 225 | +
|
| 226 | +- **order**: `[in] CBLAS_LAYOUT` storage layout. |
| 227 | +- **mode**: `[in] double` mode. If `mode < 0`, the function generates decreasing powers. If `mode > 0`, the function generates increasing powers. |
| 228 | +- **M**: `[in] CBLAS_INT` number of rows in `Out`. |
| 229 | +- **N**: `[in] CBLAS_INT` number of columns in `Out`. |
| 230 | +- **X**: `[in] double*` input array. |
| 231 | +- **strideX**: `[in] CBLAS_INT` stride length for `X`. |
| 232 | +- **Out**: `[out] double*` output matrix. |
| 233 | +- **LDO**: `[in] CBLAS_INT` stride between successive contiguous vectors of the matrix `Out` (a.k.a., leading dimension of the matrix `Out`). |
| 234 | +
|
| 235 | +```c |
| 236 | +void API_SUFFIX(stdlib_strided_dvander)( const CBLAS_LAYOUT order, const double mode, const CBLAS_INT M, const CBLAS_INT N, const double *X, const CBLAS_INT strideX, double *Out, const CBLAS_INT LDO ); |
| 237 | +``` |
| 238 | + |
| 239 | +<!-- lint disable maximum-heading-length --> |
| 240 | + |
| 241 | +#### stdlib_strided_dvander_ndarray( mode, M, N, \*X, strideX, offsetX, \*Out, strideOut1, strideOut2, offsetOut ) |
| 242 | + |
| 243 | +<!-- lint enable maximum-heading-length --> |
| 244 | + |
| 245 | +Generates a double-precision floating-point Vandermonde matrix using alternative indexing semantics. |
| 246 | + |
| 247 | +```c |
| 248 | +#include "stdlib/blas/base/shared.h" |
| 249 | + |
| 250 | +const double x[ 3 ] = { 1.0, 2.0, 3.0 }; |
| 251 | +double Out[ 3*3 ] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; |
| 252 | + |
| 253 | +stdlib_strided_dvander_ndarray( -1.0, 3, 3, x, 1, 0, Out, 3, 1, 0 ); |
| 254 | +``` |
| 255 | +
|
| 256 | +The function accepts the following arguments: |
| 257 | +
|
| 258 | +- **mode**: `[in] double` mode. If `mode < 0`, the function generates decreasing powers. If `mode > 0`, the function generates increasing powers. |
| 259 | +- **M**: `[in] CBLAS_INT` number of rows in `Out`. |
| 260 | +- **N**: `[in] CBLAS_INT` number of columns in `Out`. |
| 261 | +- **X**: `[in] double*` input array. |
| 262 | +- **strideX**: `[in] CBLAS_INT` stride length for `X`. |
| 263 | +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. |
| 264 | +- **Out**: `[out] double*` output matrix. |
| 265 | +- **strideOut1**: `[in] CBLAS_INT` stride length for the first dimension of `Out`. |
| 266 | +- **strideOut2**: `[in] CBLAS_INT` stride length for the second dimension of `Out`. |
| 267 | +- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`. |
| 268 | +
|
| 269 | +```c |
| 270 | +void API_SUFFIX(stdlib_strided_dvander_ndarray)( const double mode, const CBLAS_INT M, const CBLAS_INT N, 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 ); |
| 271 | +``` |
| 272 | + |
| 273 | +</section> |
| 274 | + |
| 275 | +<!-- /.usage --> |
| 276 | + |
| 277 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 278 | + |
| 279 | +<section class="notes"> |
| 280 | + |
| 281 | +</section> |
| 282 | + |
| 283 | +<!-- /.notes --> |
| 284 | + |
| 285 | +<!-- C API usage examples. --> |
| 286 | + |
| 287 | +<section class="examples"> |
| 288 | + |
| 289 | +### Examples |
| 290 | + |
| 291 | +```c |
| 292 | +#include "stdlib/blas/ext/base/dvander.h" |
| 293 | +#include "stdlib/blas/base/shared.h" |
| 294 | +#include <stdio.h> |
| 295 | + |
| 296 | +int main( void ) { |
| 297 | + // Define the input array: |
| 298 | + const double x[ 3 ] = { 1.0, 2.0, 3.0 }; |
| 299 | + |
| 300 | + // Define a 3x3 output array stored in row-major order: |
| 301 | + double Out[ 3*3 ] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; |
| 302 | + |
| 303 | + // Specify the number of rows and columns: |
| 304 | + const int M = 3; |
| 305 | + const int N = 3; |
| 306 | + |
| 307 | + // Perform operation: |
| 308 | + stdlib_strided_dvander( CblasRowMajor, -1.0, M, N, x, 1, Out, N ); |
| 309 | + |
| 310 | + // Print the result: |
| 311 | + for ( int i = 0; i < M; i++ ) { |
| 312 | + for ( int j = 0; j < N; j++ ) { |
| 313 | + printf( "Out[%i,%i] = %lf\n", i, j, Out[ (i*N)+j ] ); |
| 314 | + } |
| 315 | + } |
| 316 | +} |
| 317 | +``` |
| 318 | +
|
| 319 | +</section> |
| 320 | +
|
| 321 | +<!-- /.examples --> |
| 322 | +
|
| 323 | +</section> |
| 324 | +
|
| 325 | +<!-- /.c --> |
| 326 | +
|
| 327 | +<section class="references"> |
| 328 | +
|
| 329 | +</section> |
| 330 | +
|
| 331 | +<!-- /.references --> |
| 332 | +
|
| 333 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 334 | +
|
| 335 | +<section class="related"> |
| 336 | +
|
| 337 | +</section> |
| 338 | +
|
| 339 | +<!-- /.related --> |
| 340 | +
|
| 341 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 342 | +
|
| 343 | +<section class="links"> |
| 344 | +
|
| 345 | +[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64 |
| 346 | +
|
| 347 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 348 | +
|
| 349 | +</section> |
| 350 | +
|
| 351 | +<!-- /.links --> |
0 commit comments