The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Math::DVector -- Fast, compact vectors using arrays of double.

DESCRIPTION

Math::DVector implements a very simple class of vectors (arrays of double). Indexing starts from zero.

The interface is somewhat arbitrary, I hope to remove some of the redundant functions later and have a better interface to this class.

Methods:

new(size)

Creates a new vector with initial size size

aslist

Returns a list with the elements of the vector.

setlist(list)

Sets the vector values to list. If list is different size than the vector, the surplus elements are ignored.

asstr

Returns a string with the elements of the vector separated by spaces, the whole string surrounded by brackets. (useful in print commands)

copy

Returns a new vector that is a copy of this vector

getelem(i)

Returns the ith element of the vector

putelem(i,el)

Set the ith element of the vector to el.

resize(n)

Resize the vector to contain exactly n elements. Existing elements are preserved. New elements have undefined values.

zero

Zero all elements of the vector.

getsize

Returns the size of the vector

add_vec(vec,s)

Add the values of vector vec multiplied by s to this vector. Vectors needn't be same size.

set_vec(vec,s)

Set this vector to the values of vector vec multiplied by s. No resizing.

add_step(vec,s)

Add the value of vec scaled so that its euclidean length is s to this vector. Result is undefined if |vec| is very small.

mul_dbl(s)

Multiply the vector by a scale.

randomize(min,max)

Set all the elements of this vector to evenly distributed random values between min and max.

BUGS

Very arbitrary interface

Currently, the only mode of operation is "safe", checking the indices on each element access, which is a pain in some operations. This should be an external pragma, so that there are two different DVector objects.

AUTHOR

Tuomas J. Lukka (Tuomas.Lukka@Helsinki.FI)