void axpy (float[] x, const float[] y, const float a) {
x[] = a*x[] + y[];
}
void axpy1 (float[] x, const float[] y, const float a) {
x[] *= a;
x[] += y[];
}
void axpy2(float[] x, const float[] y, const float a) {
size_t index = 0;
for (;index < x.length; index++) {
x[index] = a * x[index] + y[index];
}
}
axpy1 and axpy2 compile fine, but axpy only compiles if I omit the const on the "y" parameter.
Error message is:
Error: invalid array operation cast(const(float)[])(a * x[]) + y[] (possible missing [])
Not clear to me why a*x[] is being cast to const or where the extra [] could be inserted. Seems like maybe underlying implementation doesn't support a binary operator between scalars and vectors, only an opAssign when one is const and the other isn't.
It appears the scalar multiply results in a const float[] and then
Comment #1 by robert.schadek — 2024-12-13T18:44:48Z