<<<<<<<<<<<<<<<<<

vector(lymb) LYMB vector(lymb)

NAME

vector

DESCRIPTION

The vector class is used in LYMB to represent one- dimensional arrays of numbers. Any numeric argument can be a floating point number or a string. If a string is given, it must parse as a floating point number using C floating point syntax.

Arithmetic operations can be performed on each component of a vector. If the argument is a scalar or a single number, that number is applied to each component of the vector. If the argument is a vector or list of numbers, vector arithmetic is performed. If the argument has fewer elements than the vector, the argument is reused cyclically. If the stride of the vector is greater than 1, only every stride'th element (between from and to) will be affected.

Note: When creating instances of the vector class, particularly in scripts, it is safest to enclose the names in quotes. Vectors return their components when an instance is referenced, not the name of the instance.

SUPERCLASS

object

INSTANCE VARIABLES

dimension is the number of elements, or components, in a vector.

from is the starting index in a vector used for assignment and arithmetic operations.

to is the ending index in a vector used for assignment and arithmetic operations.

stride is the increment between successive elements of the vector when performing most operations. The default is 1.

components are components of a vector.

MESSAGES

dimension= argument Set the dimension of a vector. If not set, the vector will resize dynamically to fit the data given.

dimension? Return the dimension of the vector.

end_of_message Reset "from" and "to" of the instance, i.e., set from=1 and to=dimension. End_of_message cannot be sent from a LYMB script. The parser normally sends this when it sees a ";". C programmers who manipulate vectors should be aware of this behavior.

= arguments Set the values of components. If more arguments than the current dimeniosn are given, the vector is resized dynamically. If the number of arguments is less than (to - from + 1), they are reused in a circular fashion. The same applies to messages "+", "-", and "components=". Affected by the stride value.

* arguments Multiply components of an instance by the list of arguments on a component-by-component basis. If the argument list is shorter that the number of members between from and to, it is reused cyclically. For instance, executing "vector new: v = (1,2,3) * 2;" would result in v' component values being (2,4,6), not (2,2,3). Affected by the stride value.

/ arguments Divide components of an instance by the list of arguments on a component-by-component basis. If the argument list is shorter that the number of members between from and to, it is reused cyclically. Affected by the stride value.

- arguments Subtract elements of the argument list from the instance members on a component-by-component basis. If the argument list is shorter that the number of members between from and to, it is reused cyclically. Affected by the stride value.

+ arguments Add elements of the argument list to the instance members on a component-by-component basis. If the argument list is shorter that the number of members between from and to, it is reused cyclically. Affected by the stride value.

^ arguments Raise each member by the exponent in the list on a component-by-component basis. If the argument list is shorter that the number of members between from and to, it is reused cyclically. Affected by the stride value.

? Return components of an instance, synonym to

"components?". Affected by the stride value.

components= arguments Set components of an instance (synonym to "="). Affected by the stride value.

components? Return components of an instance. Affected by the stride value.

@ argument Set "from" and "to" to the argument, valid until the next "end_of_message".

from: argument Set "from" index to the argument, valid until the next "end_of_message".

from? Return "from" index.

to: argument Set "to" index to the argument, valid until the next "end_of_message".

to? Return "to" index.

length? Return the euclidean norm of the vector. (The dimension? message returns the number of elements in the vector.) Affected by the stride value.

sum? Return the sum of the components. Affected by the stride value.

trace? Return the sum of the components. Alias for "sum?" Affected by the stride value.

max? Return the maximum element of the components. Affected by the stride value.

min? Return the minimum element of the components. Affected by the stride value.

swap! Reverse the order of components referenced by the "from" and "to" indices.

pointer=(ptr) Set the vector's value based upon an input float pointer.

pointer? Return a pointer to the vector instance's value.

first_set? Returns the index of first non-zero element of the vector. From and to bound the search. Affected by the stride value.

last_set? Returns the index of last non-zero element of the vector. From and to bound the search. Affected by the stride value.

stride= Sets the stride for the vector. It defaults to 1, and can't be set below 1, or to greater than the dimension of the vector. The stride is always reset to 1 when an end_of_message message is received.

stride? Returns the vector's stride.

EXAMPLE

vector new: v1 dimension=10; -- print only four components v1 from:4 to: 7 = (1,2,3,4) print:components; v1 print: components; -- will print all 10 components

-- zero out the z components of the points of -- a display_data object. vector new: `v' = [dd points?] stride= 3 from= 3 = 0 ; dd points= v;

SEE ALSO

scalar, string, s_vector, expr


Please send comments and suggestions to
consult@rpi.edu