This project has moved. For the latest updates, please go here.

Vector.PointwiseMultiply/Subtract/Multiply/...

Coordinator
Jul 13, 2010 at 7:34 AM

Hi Guys,

Another API suggestion I want to make; all our Vector methods like PointwiseMultiply,Subtract,Multiply come in two flavors: e.g.

void Subtract(Vector v)

void Subtract(Vector v, Vector result)

In other words, if you want to do an in-place subtract, you can either call Subtract(v) or Subtract(v,v). My suggestion would be that we turn the "void Subtract(v)" into a "Vector Subtract(v)" which is immutable but returns a newly created vector that is the subtraction of "this" and "v". First, if you want to do inplace stuff, calling Subtract(v,v) is not really any overhead at all wheras if you want a new vector, you'd have to write

var wcopy = w.Clone()

w.Subtract(v, wcopy)

which is a bit of a hassle (I find) and completely breaks the flow of functional programs in F#.

In other words, my suggestion would be to make sure our API has both mutable and immutable methods.

Any thoughts,

Jurgen

Jul 13, 2010 at 7:46 AM

Hi Jurgen,

I think we should keep the inplace methods on both the vector and matrix classes. It reduces overhead and memory requirements when dealing with large amounts of data. We could rename them to InplaceXXX(...) and then and Vector/Matrix XXX(...). Would that work?

Regards,

Marcus

Coordinator
Jul 19, 2010 at 8:40 PM
Hi Marcus, I agree that we should keep the inplace methods for efficiency reasons. However, at the moment you can write w.Subtract(v, w) to make sure you overwrite the current vector (we can internally optimize this call to do the same InplaceXxx. This is a bit shorter than writing w.InplaceSubtract(v) Any toughts? Cheers, J
Jul 20, 2010 at 12:19 AM

Hi Jurgen,

Duh! Right, we can optimize w.Subtract(v, w) to not do the unnecessary copy - so lets not add the InplaceXXX methods.

Regards,

Marcus

Coordinator
Jul 20, 2010 at 9:07 PM
OK brilliant; I'll go through the code and make the changes. Essentially all Vector methods which take a Vector result as a parameter I will leave as is, their equivalents without that parameter I will change the return parameter from void to Vector. Cheers, J