All files base.js

98.93% Statements 186/188
95.23% Branches 20/21
100% Functions 1/1
98.93% Lines 186/188

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 1893x 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 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x     31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 12x 12x 12x 42x 42x 42x 42x 42x 42x 42x 42x 42x 12x 12x 19x 31x 15x 15x 15x 4x 4x 4x 4x 4x 4x 4x 4x 4x 15x 13x 13x 13x 13x 13x 13x 13x 15x 2x 2x 2x 2x 2x 2x 2x 2x 31x 2x 2x 2x 2x 2x 2x 19x 31x 15x 15x 36x 36x 36x 36x 36x 36x 36x 36x 36x 15x 13x 13x 13x 13x 13x 13x 13x 13x 15x 19x 31x 17x 17x 6x 6x 6x 6x 6x 6x 6x 6x 6x 17x 19x 31x 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-params, max-len, max-statements */
 
'use strict';
 
// MODULES //
 
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
 
 
// MAIN //
 
/**
* Calculates the forward difference of a single-precision complex floating-point strided array.
*
* @private
* @param {PositiveInteger} N - number of indexed elements
* @param {Complex64Array} x - input array
* @param {integer} strideX - stride length for `x`
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {NonNegativeInteger} N1 - number of indexed elements to `prepend`
* @param {Complex64Array} prepend - prepend array
* @param {integer} strideP - stride length for `prepend`
* @param {NonNegativeInteger} offsetP - starting index for `prepend`
* @param {NonNegativeInteger} N2 - number of indexed elements to `append`
* @param {Complex64Array} append - append array
* @param {integer} strideA - stride length for `append`
* @param {NonNegativeInteger} offsetA - starting index for `append`
* @param {Complex64Array} out - output array
* @param {integer} strideOut - stride length for `out`
* @param {NonNegativeInteger} offsetOut - starting index for `out`
* @returns {Complex64Array} output array
*/
function base( N, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut ) {
	var total;
	var rprev;
	var iprev;
	var rcurr;
	var icurr;
	var xv;
	var pv;
	var av;
	var ov;
	var sx;
	var sp;
	var sa;
	var so;
	var ix;
	var ip;
	var ia;
	var io;
	var i;
 
	total = N + N1 + N2;
	if ( total <= 1 ) {
		return out;
	}
	// Reinterpret the complex arrays as real-valued arrays of interleaved real and imaginary components:
	xv = reinterpret( x, 0 );
	pv = reinterpret( prepend, 0 );
	av = reinterpret( append, 0 );
	ov = reinterpret( out, 0 );
 
	// Adjust the strides and offsets according to the real-valued arrays:
	sx = strideX * 2;
	sp = strideP * 2;
	sa = strideA * 2;
	so = strideOut * 2;
	ix = offsetX * 2;
	ip = offsetP * 2;
	ia = offsetA * 2;
	io = offsetOut * 2;
 
	// Compute forward differences:
	if ( N1 === 0 && N2 === 0 ) {
		rprev = xv[ ix ];
		iprev = xv[ ix+1 ];
		for ( i = 1; i < N; i++ ) {
			ix += sx;
			rcurr = xv[ ix ];
			icurr = xv[ ix+1 ];
			ov[ io ] = rcurr - rprev;
			ov[ io+1 ] = icurr - iprev;
			rprev = rcurr;
			iprev = icurr;
			io += so;
		}
		return out;
	}
	// Compute forward differences over the list of prepended values:
	if ( N1 > 0 ) {
		rprev = pv[ ip ];
		iprev = pv[ ip+1 ];
		for ( i = 1; i < N1; i++ ) {
			ip += sp;
			rcurr = pv[ ip ];
			icurr = pv[ ip+1 ];
			ov[ io ] = rcurr - rprev;
			ov[ io+1 ] = icurr - iprev;
			rprev = rcurr;
			iprev = icurr;
			io += so;
		}
		if ( N > 0 ) {
			rcurr = xv[ ix ];
			icurr = xv[ ix+1 ];
			ov[ io ] = rcurr - rprev;
			ov[ io+1 ] = icurr - iprev;
			rprev = rcurr;
			iprev = icurr;
			io += so;
		} else if ( N2 > 0 ) {
			rcurr = av[ ia ];
			icurr = av[ ia+1 ];
			ov[ io ] = rcurr - rprev;
			ov[ io+1 ] = icurr - iprev;
			rprev = rcurr;
			iprev = icurr;
			io += so;
		}
	} else if ( N > 0 ) {
		rprev = xv[ ix ];
		iprev = xv[ ix+1 ];
	} else {
		rprev = av[ ia ];
		iprev = av[ ia+1 ];
	}
	// Compute forward differences over the input array:
	if ( N > 0 ) {
		ix += sx;
		for ( i = 1; i < N; i++ ) {
			rcurr = xv[ ix ];
			icurr = xv[ ix+1 ];
			ov[ io ] = rcurr - rprev;
			ov[ io+1 ] = icurr - iprev;
			rprev = rcurr;
			iprev = icurr;
			io += so;
			ix += sx;
		}
		if ( N2 > 0 ) {
			rcurr = av[ ia ];
			icurr = av[ ia+1 ];
			ov[ io ] = rcurr - rprev;
			ov[ io+1 ] = icurr - iprev;
			rprev = rcurr;
			iprev = icurr;
			io += so;
		}
	}
	// Compute forward differences over the list of appended values:
	if ( N2 > 0 ) {
		ia += sa;
		for ( i = 1; i < N2; i++ ) {
			rcurr = av[ ia ];
			icurr = av[ ia+1 ];
			ov[ io ] = rcurr - rprev;
			ov[ io+1 ] = icurr - iprev;
			rprev = rcurr;
			iprev = icurr;
			io += so;
			ia += sa;
		}
	}
	return out;
}
 
 
// EXPORTS //
 
module.exports = base;