This project has moved and is read-only. For the latest updates, please go here.

Missing Vector.ScalarMultiply(Vector), and more

Mar 21, 2014 at 9:13 PM
Edited Mar 24, 2014 at 1:02 PM
Here what's missing from Iridium and not sure what replacement to use:
Vector.ScalarMultiply (Vector)
Vector.ScalarProduct (Vector, Vector)
Vector.ScaleInplace (double)
Vector.AddInplace (Vector)
Mar 21, 2014 at 9:22 PM
Edited Mar 24, 2014 at 1:02 PM
Ok, I think that the * operator can be used for ScalarMultiply and ScalarProduct:
double value = v1.ScalarMultiply (v2) // .... now becomes
double value = v1 * v2;

double value = Vector.ScalarProduct (v1,v2)  // .... now becomes
double value = v1 * v2;
Not sure about the InPlace methods though... still digging.
Mar 22, 2014 at 11:55 AM
double value = ...;

//inplace scalar multiply
v1.Multiply(value, v1);

//inplace scalar add
v1.Add(value, v1);
v1.Add(v2, v1);
Everything is there, already.
Mar 24, 2014 at 1:01 PM
Edited Mar 24, 2014 at 1:01 PM
Vector.Multiply and Vector.Add do not modify the vector "in place", they return a copy.

In the end I did the following:
// Replaces Vector.ScaleInplace (double)
double scalar = 2;
v1.MapInPlace (value => value * scalar);

// Replaces Vector.AddInplace (Vector)
v1.MapIndexedInplace ((index, value) => value + v2[index]);
Mar 24, 2014 at 2:26 PM
Actually, yes, the void Vector.Multiply(scalar, result) and void Vector.Add(other, result) overloads accept the resulting vector as last argument and thus operate in-place if the input vector is passed in (as demonstrated with v1 in tibel's examples) - and they do not return anything (void).
Marked as answer by stecy on 3/24/2014 at 1:57 PM