Skip to content

Commit 416bb2d

Browse files
authored
refactor: reduce assignment duplication
Signed-off-by: Athan <kgryte@gmail.com>
1 parent 4ff7d56 commit 416bb2d

1 file changed

Lines changed: 37 additions & 36 deletions

File tree

  • lib/node_modules/@stdlib/blas/ext/base/gvander/lib

lib/node_modules/@stdlib/blas/ext/base/gvander/lib/base.js

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -77,46 +77,49 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2,
7777
isrm = isRowMajor( [ strideOut1, strideOut2 ] );
7878
sx = strideX;
7979

80-
if ( isrm && mode > 0 ) {
81-
// Row-major, increasing: x^0, x^1, ..., x^(N-1)
80+
if ( isrm ) {
8281
S0 = N;
8382
S1 = M;
8483
do0 = strideOut2;
85-
do1 = strideOut1 - ( S0*strideOut2 );
86-
io = offsetOut;
8784
ix = offsetX;
88-
for ( i1 = 0; i1 < S1; i1++ ) {
89-
out[ io ] = 1.0;
90-
io += do0;
91-
for ( i0 = 1; i0 < S0; i0++ ) {
92-
out[ io ] = out[ io - do0 ] * x[ ix ];
85+
86+
// Increasing: x^0, x^1, ..., x^(N-1)
87+
if ( mode > 0 ) {
88+
do1 = strideOut1 - ( S0*strideOut2 );
89+
io = offsetOut;
90+
for ( i1 = 0; i1 < S1; i1++ ) {
91+
out[ io ] = 1.0;
9392
io += do0;
93+
for ( i0 = 1; i0 < S0; i0++ ) {
94+
out[ io ] = out[ io-do0 ] * x[ ix ];
95+
io += do0;
96+
}
97+
ix += sx;
98+
io += do1;
9499
}
95-
ix += sx;
96-
io += do1;
100+
return out;
97101
}
98-
} else if ( isrm ) {
99-
// Row-major, decreasing: x^(N-1), x^(N-2), ..., x^0
100-
S0 = N;
101-
S1 = M;
102-
do0 = strideOut2;
102+
// Decreasing: x^(N-1), x^(N-2), ..., x^0
103103
do1 = strideOut1 + ( S0*strideOut2 );
104104
io = offsetOut + ( ( S0-1 ) * do0 );
105-
ix = offsetX;
106105
for ( i1 = 0; i1 < S1; i1++ ) {
107106
out[ io ] = 1.0;
108107
io -= do0;
109108
for ( i0 = 1; i0 < S0; i0++ ) {
110-
out[ io ] = out[ io + do0 ] * x[ ix ];
109+
out[ io ] = out[ io+do0 ] * x[ ix ];
111110
io -= do0;
112111
}
113112
ix += sx;
114113
io += do1;
115114
}
116-
} else if ( mode > 0 ) {
117-
// Column-major, increasing: column j contains x^j
118-
S0 = M;
119-
S1 = N;
115+
return out;
116+
}
117+
// Column-major...
118+
S0 = M;
119+
S1 = N;
120+
121+
// Increasing: column j contains x^j
122+
if ( mode > 0 ) {
120123
do0 = strideOut1;
121124
do1 = strideOut2 - ( S0*strideOut1 );
122125
io = offsetOut;
@@ -125,25 +128,23 @@ function gvander( mode, M, N, x, strideX, offsetX, out, strideOut1, strideOut2,
125128
for ( i1 = 1; i1 < S1; i1++ ) {
126129
ix = offsetX;
127130
for ( i0 = 0; i0 < S0; i0++ ) {
128-
out[ io ] = out[ io - strideOut2 ] * x[ ix ];
131+
out[ io ] = out[ io-strideOut2 ] * x[ ix ];
129132
ix += sx;
130133
io += do0;
131134
}
132135
io += do1;
133136
}
134-
} else {
135-
// Column-major, decreasing: column 0 contains x^(N-1), last column all ones
136-
S0 = M;
137-
S1 = N;
138-
gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) );
139-
for ( i1 = S1 - 2; i1 >= 0; i1-- ) {
140-
io = offsetOut + ( i1 * strideOut2 );
141-
ix = offsetX;
142-
for ( i0 = 0; i0 < S0; i0++ ) {
143-
out[ io ] = out[ io + strideOut2 ] * x[ ix ];
144-
ix += sx;
145-
io += strideOut1;
146-
}
137+
return out;
138+
}
139+
// Decreasing: column 0 contains x^(N-1), last column all ones
140+
gfill( S0, 1.0, out, strideOut1, offsetOut + ( ( S1-1 ) * strideOut2 ) );
141+
for ( i1 = S1 - 2; i1 >= 0; i1-- ) {
142+
io = offsetOut + ( i1*strideOut2 );
143+
ix = offsetX;
144+
for ( i0 = 0; i0 < S0; i0++ ) {
145+
out[ io ] = out[ io+strideOut2 ] * x[ ix ];
146+
ix += sx;
147+
io += strideOut1;
147148
}
148149
}
149150
return out;

0 commit comments

Comments
 (0)