You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by Andy Twigg <an...@gmail.com> on 2013/04/15 12:01:02 UTC

immutable vs mutable vectors

Hello all,

As far as I can tell, mahout.math vectors are generally immutable, i.e.

Vector x = foo
Vector y = bar
x=x.plus(y) // creates a new vector
x=x.normalize() // creates a new vector

This seems very inefficient. Is there an alternative, mutable strategy?

-Andy


-- 
Dr Andy Twigg
Junior Research Fellow, St Johns College, Oxford
Room 351, Department of Computer Science
http://www.cs.ox.ac.uk/people/andy.twigg/
andy.twigg@cs.ox.ac.uk | +447799647538

Re: immutable vs mutable vectors

Posted by Sebastian Schelter <ss...@apache.org>.
Yes, look at the assign() method which allows you to apply functions
directly to the vector.

/s

On 15.04.2013 12:01, Andy Twigg wrote:
> Hello all,
> 
> As far as I can tell, mahout.math vectors are generally immutable, i.e.
> 
> Vector x = foo
> Vector y = bar
> x=x.plus(y) // creates a new vector
> x=x.normalize() // creates a new vector
> 
> This seems very inefficient. Is there an alternative, mutable strategy?
> 
> -Andy
> 
> 


Re: immutable vs mutable vectors

Posted by Ted Dunning <te...@gmail.com>.
We update using a functional style.  As Sebastian pointed out, the key
entry point is assign(...) in various flavors.  Common mutations like
addition of sparse vectors are special cased.




On Mon, Apr 15, 2013 at 3:01 AM, Andy Twigg <an...@gmail.com> wrote:

> Hello all,
>
> As far as I can tell, mahout.math vectors are generally immutable, i.e.
>
> Vector x = foo
> Vector y = bar
> x=x.plus(y) // creates a new vector
> x=x.normalize() // creates a new vector
>
> This seems very inefficient. Is there an alternative, mutable strategy?
>
> -Andy
>
>
> --
> Dr Andy Twigg
> Junior Research Fellow, St Johns College, Oxford
> Room 351, Department of Computer Science
> http://www.cs.ox.ac.uk/people/andy.twigg/
> andy.twigg@cs.ox.ac.uk | +447799647538
>