Generate a Vandermonde matrix.
var gvander = require( '@stdlib/blas/ext/base/gvander' );Generates a Vandermonde matrix.
var x = [ 1.0, 2.0, 3.0 ];
var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
gvander( 'row-major', 1, 3, 3, x, 1, out, 3 );
// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]The function has the following parameters:
- order: row-major (C-style) or column-major (Fortran-style) order.
- mode: mode. If
mode < 0, the function generates decreasing powers. Ifmode > 0, the function generates increasing powers. - M: number of rows in
outand number of indexed elements inx. - N: number of columns in
out. - x: input
Arrayortyped array. - strideX: stride length for
x. - out: output matrix.
- ldo: stride of the first dimension of
out(a.k.a., leading dimension of the matrixout).
Generates a Vandermonde matrix using alternative indexing semantics.
var x = [ 1.0, 2.0, 3.0 ];
var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
gvander.ndarray( 1, 3, 3, x, 1, 0, out, 3, 1, 0 );
// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.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.
While 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:
var x = [ 0.0, 1.0, 0.0, 2.0, 0.0, 3.0 ];
var out = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
gvander.ndarray( 1, 3, 3, x, 2, 1, out, 3, 1, 0 );
// out => [ 1.0, 1.0, 1.0, 1.0, 2.0, 4.0, 1.0, 3.0, 9.0 ]- If
M <= 0orN <= 0, both functions returnoutunchanged. - Both functions support array-like objects having getter and setter accessors for array element access (e.g.,
@stdlib/array/base/accessor). - Depending on the environment, the typed versions (
dvander,svander, etc.) are likely to be significantly more performant.
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var zeros = require( '@stdlib/array/zeros' );
var gvander = require( '@stdlib/blas/ext/base/gvander' );
var M = 3;
var N = 4;
var x = discreteUniform( M, 0, 10, {
'dtype': 'generic'
});
var out = zeros( M*N, 'generic' );
console.log( x );
gvander( 'row-major', -1, M, N, x, 1, out, N );
console.log( out );