|
| 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 | +# gvander |
| 22 | + |
| 23 | +> Generate a 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 gvander = require( '@stdlib/blas/ext/base/gvander' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### gvander( order, mode, M, N, x, strideX, out, ldo ) |
| 40 | + |
| 41 | +Generates a Vandermonde matrix. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var x = [ 1.0, 2.0, 3.0 ]; |
| 45 | +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; |
| 46 | + |
| 47 | +gvander( 'row-major', 1, 3, 3, x, 1, out, 3 ); |
| 48 | +// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] |
| 49 | +``` |
| 50 | + |
| 51 | +The function has the following parameters: |
| 52 | + |
| 53 | +- **order**: row-major (C-style) or column-major (Fortran-style) order. |
| 54 | +- **mode**: mode. If `mode < 0`, the function generates decreasing powers. If `mode > 0`, the function generates increasing powers. |
| 55 | +- **M**: number of rows in `out` and number of indexed elements in `x`. |
| 56 | +- **N**: number of columns in `out`. |
| 57 | +- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. |
| 58 | +- **strideX**: stride length for `x`. |
| 59 | +- **out**: output matrix. |
| 60 | +- **ldo**: stride of the first dimension of `out` (a.k.a., leading dimension of the matrix `out`). |
| 61 | + |
| 62 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 63 | + |
| 64 | +<!-- eslint-disable stdlib/capitalized-comments, max-len --> |
| 65 | + |
| 66 | +```javascript |
| 67 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 68 | + |
| 69 | +// Initial arrays: |
| 70 | +var x0 = new Float64Array( [ 999.0, 1.0, 2.0, 3.0 ] ); |
| 71 | +var out0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 72 | + |
| 73 | +// Create offset views: |
| 74 | +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 75 | +var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 76 | + |
| 77 | +gvander( 'row-major', 1, 3, 3, x1, 1, out1, 3 ); |
| 78 | +// out0 => <Float64Array>[ 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] |
| 79 | +``` |
| 80 | + |
| 81 | +When the mode is positive, the matrix is generated such that |
| 82 | + |
| 83 | +```text |
| 84 | +[ |
| 85 | + 1 x_0^1 x_0^2 ... x_0^(N-1) |
| 86 | + 1 x_1^1 x_1^2 ... x_1^(N-1) |
| 87 | + ... |
| 88 | +] |
| 89 | +``` |
| 90 | + |
| 91 | +with increasing powers along the rows. |
| 92 | + |
| 93 | +When the mode is negative, the matrix is generated such that |
| 94 | + |
| 95 | +```text |
| 96 | +[ |
| 97 | + x_0^(N-1) ... x_0^2 x_0^1 1 |
| 98 | + x_1^(N-1) ... x_1^2 x_1^1 1 |
| 99 | + ... |
| 100 | +] |
| 101 | +``` |
| 102 | + |
| 103 | +with decreasing powers along the rows. |
| 104 | + |
| 105 | +<!-- lint disable maximum-heading-length --> |
| 106 | + |
| 107 | +#### gvander.ndarray( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) |
| 108 | + |
| 109 | +<!-- lint enable maximum-heading-length --> |
| 110 | + |
| 111 | +Generates a Vandermonde matrix using alternative indexing semantics. |
| 112 | + |
| 113 | +```javascript |
| 114 | +var x = [ 1.0, 2.0, 3.0 ]; |
| 115 | +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; |
| 116 | + |
| 117 | +gvander.ndarray( 1, 3, 3, x, 1, 0, out, 3, 1, 0 ); |
| 118 | +// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] |
| 119 | +``` |
| 120 | + |
| 121 | +The function has the following additional parameters: |
| 122 | + |
| 123 | +- **offsetX**: starting index for `x`. |
| 124 | +- **strideOut1**: stride length for the first dimension of `out`. |
| 125 | +- **strideOut2**: stride length for the second dimension of `out`. |
| 126 | +- **offsetOut**: starting index for `out`. |
| 127 | + |
| 128 | +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: |
| 129 | + |
| 130 | +```javascript |
| 131 | +var x = [ 0.0, 1.0, 0.0, 2.0, 0.0, 3.0 ]; |
| 132 | +var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; |
| 133 | + |
| 134 | +gvander.ndarray( 1, 3, 3, x, 2, 1, out, 3, 1, 0 ); |
| 135 | +// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ] |
| 136 | +``` |
| 137 | + |
| 138 | +</section> |
| 139 | + |
| 140 | +<!-- /.usage --> |
| 141 | + |
| 142 | +<section class="notes"> |
| 143 | + |
| 144 | +## Notes |
| 145 | + |
| 146 | +- If `M <= 0` or `N <= 0`, both functions return `out` unchanged. |
| 147 | +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). |
| 148 | +- Depending on the environment, the typed versions ([`dvander`][@stdlib/blas/ext/base/dvander], [`svander`][@stdlib/blas/ext/base/svander], etc.) are likely to be significantly more performant. |
| 149 | + |
| 150 | +</section> |
| 151 | + |
| 152 | +<!-- /.notes --> |
| 153 | + |
| 154 | +<section class="examples"> |
| 155 | + |
| 156 | +## Examples |
| 157 | + |
| 158 | +<!-- eslint no-undef: "error" --> |
| 159 | + |
| 160 | +```javascript |
| 161 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 162 | +var zeros = require( '@stdlib/array/zeros' ); |
| 163 | +var gvander = require( '@stdlib/blas/ext/base/gvander' ); |
| 164 | + |
| 165 | +var M = 3; |
| 166 | +var N = 4; |
| 167 | + |
| 168 | +var x = discreteUniform( M, 0, 10, { |
| 169 | + 'dtype': 'generic' |
| 170 | +}); |
| 171 | +var out = zeros( M*N, 'generic' ); |
| 172 | +console.log( x ); |
| 173 | + |
| 174 | +gvander( 'row-major', -1, M, N, x, 1, out, N ); |
| 175 | +console.log( out ); |
| 176 | +``` |
| 177 | + |
| 178 | +</section> |
| 179 | + |
| 180 | +<!-- /.examples --> |
| 181 | + |
| 182 | +<section class="references"> |
| 183 | + |
| 184 | +</section> |
| 185 | + |
| 186 | +<!-- /.references --> |
| 187 | + |
| 188 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 189 | + |
| 190 | +<section class="related"> |
| 191 | + |
| 192 | +</section> |
| 193 | + |
| 194 | +<!-- /.related --> |
| 195 | + |
| 196 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 197 | + |
| 198 | +<section class="links"> |
| 199 | + |
| 200 | +[mdn-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array |
| 201 | + |
| 202 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 203 | + |
| 204 | +[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor |
| 205 | + |
| 206 | +[@stdlib/blas/ext/base/dvander]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/dvander |
| 207 | + |
| 208 | +[@stdlib/blas/ext/base/svander]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/svander |
| 209 | + |
| 210 | +<!-- <related-links> --> |
| 211 | + |
| 212 | +<!-- </related-links> --> |
| 213 | + |
| 214 | +</section> |
| 215 | + |
| 216 | +<!-- /.links --> |
0 commit comments