All files base.js

100% Statements 155/155
100% Branches 21/21
100% Functions 1/1
100% Lines 155/155

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 1563x 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 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 57x 20x 20x 37x 37x 37x 37x 37x 57x 26x 26x 26x 26x 26x 26x 26x 14x 14x 14x 32x 32x 32x 56x 56x 56x 32x 32x 32x 14x 14x 12x 12x 12x 26x 28x 28x 28x 46x 46x 46x 28x 28x 28x 12x 12x 11x 11x 11x 11x 11x 57x 3x 3x 3x 3x 3x 5x 5x 14x 14x 14x 14x 5x 5x 3x 3x 8x 8x 57x 16x 16x 16x 36x 36x 36x 36x 16x 8x 57x 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 arraylike2object = require( '@stdlib/array/base/arraylike2object' );
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
var gfill = require( '@stdlib/blas/ext/base/gfill' ).ndarray;
var accessors = require( './accessors.js' );
 
 
// MAIN //
 
/**
* Generates a Vandermonde matrix using alternative indexing semantics.
*
* @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 {NumericArray} x - input array
* @param {integer} strideX - stride length for `x`
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {NumericArray} 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 {NumericArray} output matrix
*
* @example
* 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( 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 ]
*/
function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut ) {
	var isrm;
	var xobj;
	var oobj;
	var do0;
	var do1;
	var S0;
	var S1;
	var sx;
	var io;
	var ix;
	var i0;
	var i1;
 
	xobj = arraylike2object( x );
	oobj = arraylike2object( out );
	if ( xobj.accessorProtocol || oobj.accessorProtocol ) {
		return accessors( mode, M, N, xobj, strideX, offsetX, oobj, strideOut1, strideOut2, offsetOut );
	}
 
	// Note on variable naming convention: S#, do#, io, i# where # corresponds to the loop number, with `0` being the innermost loop...
	isrm = isRowMajor( [ strideOut1, strideOut2 ] );
	sx = strideX;
 
	if ( isrm ) {
		S0 = N;
		S1 = M;
		do0 = strideOut2;
		ix = offsetX;
 
		// Increasing: x^0, x^1, ..., x^(N-1)
		if ( mode > 0 ) {
			do1 = strideOut1 - ( S0*strideOut2 );
			io = offsetOut;
			for ( i1 = 0; i1 < S1; i1++ ) {
				out[ io ] = 1.0;
				io += do0;
				for ( i0 = 1; i0 < S0; i0++ ) {
					out[ io ] = out[ io-do0 ] * x[ ix ];
					io += do0;
				}
				ix += sx;
				io += do1;
			}
			return out;
		}
		// Decreasing: x^(N-1), x^(N-2), ..., x^0
		do1 = strideOut1 + ( S0*strideOut2 );
		io = offsetOut + ( ( S0-1 ) * strideOut2 );
		for ( i1 = 0; i1 < S1; i1++ ) {
			out[ io ] = 1.0;
			io -= do0;
			for ( i0 = 1; i0 < S0; i0++ ) {
				out[ io ] = out[ io+do0 ] * x[ ix ];
				io -= do0;
			}
			ix += sx;
			io += do1;
		}
		return out;
	}
	// Column-major...
	S0 = M;
	S1 = N;
	
	// Increasing: column j contains x^j
	if ( mode > 0 ) {
		gfill( S0, 1.0, out, strideOut1, offsetOut );
		do0 = strideOut1;
		do1 = strideOut2 - ( S0*strideOut1 );
		io = offsetOut + strideOut2;
		for ( i1 = 1; i1 < S1; i1++ ) {
			ix = offsetX;
			for ( i0 = 0; i0 < S0; i0++ ) {
				out[ io ] = out[ io-strideOut2 ] * x[ ix ];
				ix += sx;
				io += do0;
			}
			io += do1;
		}
		return out;
	}
	// Decreasing: column 0 contains x^(N-1), last column all ones
	gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) );
	for ( i1 = S1-2; i1 >= 0; i1-- ) {
		io = offsetOut + ( i1*strideOut2 );
		ix = offsetX;
		for ( i0 = 0; i0 < S0; i0++ ) {
			out[ io ] = out[ io+strideOut2 ] * x[ ix ];
			ix += sx;
			io += strideOut1;
		}
	}
	return out;
}
 
 
// EXPORTS //
 
module.exports = gvander;