Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 30x 30x 30x 30x 30x 30x 30x 14x 14x 14x 31x 31x 31x 31x 31x 31x 56x 56x 56x 56x 56x 56x 31x 31x 31x 14x 14x 16x 16x 16x 30x 36x 36x 36x 36x 36x 36x 62x 62x 62x 62x 62x 62x 36x 36x 36x 16x 16x 13x 13x 13x 13x 13x 13x 13x 13x 43x 4x 4x 4x 8x 8x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 8x 8x 4x 4x 9x 9x 9x 43x 17x 17x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 39x 17x 17x 9x 43x 3x 3x 3x 3x 3x | /**
* @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.
*/
/* eslint-disable max-len */
'use strict';
// MODULES //
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' );
var Complex128 = require( '@stdlib/complex/float64/ctor' );
var zfill = require( '@stdlib/blas/ext/base/zfill' ).ndarray;
// MAIN //
/**
* Generates a double-precision complex floating-point Vandermonde matrix.
*
* ## Notes
*
* - The implementation uses recursive multiplication to generate successive powers, which carries risk of additional accumulated floating-point error; however, for most use cases, such additional error should be negligible and not problematic.
*
* @private
* @param {integer} mode - mode indicating whether to generate increasing or decreasing powers
* @param {NonNegativeInteger} M - number of rows in `out`
* @param {NonNegativeInteger} N - number of columns in `out`
* @param {Complex128Array} x - input array
* @param {integer} strideX - stride length for `x`
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {Complex128Array} out - output matrix
* @param {integer} strideOut1 - stride length for the first dimension of `out`
* @param {integer} strideOut2 - stride length for the second dimension of `out`
* @param {NonNegativeInteger} offsetOut - starting index for `out`
* @returns {Complex128Array} output matrix
*
* @example
* var Complex128Array = require( '@stdlib/array/complex128' );
*
* var x = new Complex128Array( [ 1.0, 0.0, 2.0, 0.0 ] );
* var out = new Complex128Array( 6 );
*
* zvander( -1, 2, 3, x, 1, 0, out, 3, 1, 0 );
* // out => <Complex128Array>[ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 4.0, 0.0, 2.0, 0.0, 1.0, 0.0 ]
*/
function zvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) {
var prevIm;
var prevRe;
var xview;
var oview;
var do0;
var do1;
var xre;
var xim;
var S0;
var S1;
var io;
var ix;
var re;
var im;
var i0;
var i1;
var a;
xview = reinterpret( x, 0 );
oview = reinterpret( out, 0 );
// Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop...
if ( isRowMajor( [ strideOut1, strideOut2 ] ) ) {
S0 = N;
S1 = M;
do0 = strideOut2 * 2;
do1 = ( strideOut1 - ( S0*strideOut2 ) ) * 2;
// Increasing: x^0, x^1, ..., x^(N-1)
if ( mode > 0 ) {
io = offsetOut * 2;
ix = offsetX * 2;
for ( i1 = 0; i1 < S1; i1++ ) {
oview[ io ] = 1.0;
oview[ io+1 ] = 0.0;
io += do0;
xre = xview[ ix ];
xim = xview[ ix+1 ];
for ( i0 = 1; i0 < S0; i0++ ) {
prevRe = oview[ io-do0 ];
prevIm = oview[ io-do0+1 ];
oview[ io ] = ( prevRe*xre ) - ( prevIm*xim );
oview[ io+1 ] = ( prevRe*xim ) + ( prevIm*xre );
io += do0;
}
ix += strideX * 2;
io += do1;
}
return out;
}
// Decreasing: x^(N-1), x^(N-2), ..., x^0
io = ( offsetOut + ( ( S1-1 ) * strideOut1 ) + ( ( S0-1 ) * strideOut2 ) ) * 2;
ix = ( offsetX + ( ( S1-1 ) * strideX ) ) * 2;
for ( i1 = S1-1; i1 >= 0; i1-- ) {
oview[ io ] = 1.0;
oview[ io+1 ] = 0.0;
io -= do0;
xre = xview[ ix ];
xim = xview[ ix+1 ];
for ( i0 = 1; i0 < S0; i0++ ) {
prevRe = oview[ io+do0 ];
prevIm = oview[ io+do0+1 ];
oview[ io ] = ( prevRe*xre ) - ( prevIm*xim );
oview[ io+1 ] = ( prevRe*xim ) + ( prevIm*xre );
io -= do0;
}
ix -= strideX * 2;
io -= do1;
}
return out;
}
// Column-major...
S0 = M;
S1 = N;
do0 = strideOut1 * 2;
do1 = ( strideOut2 - ( S0*strideOut1 ) ) * 2;
a = new Complex128( 1.0, 0.0 );
// Increasing: column j contains x^j
if ( mode > 0 ) {
zfill( S0, a, out, strideOut1, offsetOut );
io = ( offsetOut + strideOut2 ) * 2;
for ( i1 = 1; i1 < S1; i1++ ) {
ix = offsetX * 2;
for ( i0 = 0; i0 < S0; i0++ ) {
prevRe = oview[ io - ( strideOut2*2 ) ];
prevIm = oview[ io - ( strideOut2*2 ) + 1 ];
xre = xview[ ix ];
xim = xview[ ix+1 ];
re = ( prevRe*xre ) - ( prevIm*xim );
im = ( prevRe*xim ) + ( prevIm*xre );
oview[ io ] = re;
oview[ io+1 ] = im;
ix += strideX * 2;
io += do0;
}
io += do1;
}
return out;
}
// Decreasing: column 0 contains x^(N-1), last column all ones
zfill( S0, a, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) );
io = ( offsetOut + ( ( S1-2 ) * strideOut2 ) + ( ( S0-1 ) * strideOut1 ) ) * 2;
for ( i1 = S1-2; i1 >= 0; i1-- ) {
ix = ( offsetX + ( ( S0-1 ) * strideX ) ) * 2;
for ( i0 = S0-1; i0 >= 0; i0-- ) {
prevRe = oview[ io + ( strideOut2*2 ) ];
prevIm = oview[ io + ( strideOut2*2 ) + 1 ];
xre = xview[ ix ];
xim = xview[ ix+1 ];
re = ( prevRe*xre ) - ( prevIm*xim );
im = ( prevRe*xim ) + ( prevIm*xre );
oview[ io ] = re;
oview[ io+1 ] = im;
ix -= strideX * 2;
io -= do0;
}
io -= do1;
}
return out;
}
// EXPORTS //
module.exports = zvander;
|