[ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

9.24.3 Uvector numeric operations

Function: TAGvector-add vec val &optional clamp
Function: TAGvector-add! vec val &optional clamp
Function: TAGvector-sub vec val &optional clamp
Function: TAGvector-sub! vec val &optional clamp
Function: TAGvector-mul vec val &optional clamp
Function: TAGvector-mul! vec val &optional clamp
Element-wise arithmetic. Vec must be a TAGvector, and val must be either a TAGvector, a vector, or a list of the same length as vec, or a number (an exact integer for integer vectors, and a real number for f32- and f64-vectors).

If val is a TAGvector, its elements are added to, subtracted from, or multiplied by the corresponding elements of vec, respectively, and the results are gathered to a TAGvector and returned. The destructive version (those have bang `!' in the name) reuses vec to store the result. If the result of calculation goes out of the range of TAGvector's element, the behavior is specified by clamp optional argument. (For f32vector and f64vector, clamp argument is ignored and the result may contain infinity).

If val is a number, it is added to, subtracted from, or multiplied by each element of vec, respectively.

 ```(s8vector-add '#s8(1 2 3 4) '#s8(5 6 7 8)) => #s8(6 8 10 12) (u8vector-sub '#u8(1 2 3 4) '#u8(2 2 2 2)) => error (u8vector-sub '#u8(1 2 3 4) '#u8(2 2 2 2) 'both) => #u8(0 0 1 2) (f32vector-mul '#f32(3.0 2.0 1.0) 1.5) => #f32(4.5 3.0 1.5) ```

Function: TAGvector-div vec val
Function: TAGvector-div! vec val
Element-wise division of flonum vectors. These are only defined for f32vector and f64vector. val must be a TAGvector, a vector or a list of the same length as vec, or a real number.

 ```(f32vector-div '#f32(1.0 2.0 3.0) 2.0) => #f32(0.5 1.0 1.5) ```

Function: TAGvector-and vec val
Function: TAGvector-and! vec val
Function: TAGvector-ior vec val
Function: TAGvector-ior! vec val
Function: TAGvector-xor vec val
Function: TAGvector-xor! vec val
Element-wise logical (bitwise) operation. These procedures are only defined for integral vectors. val must be a TAGvector, a vector or a list of the same length as vec, or an exact integer. Bitwise and, inclusive or or exclusive or is calculated between each element in vec and the corresponding element of val (when val is a non-scalar value), or val itself (when val is an integer). The result is returned in a TAGvector. The destructive version reuses vec to store the result.

Function: TAGvector-dot vec0 vec1
Calculates the dot product of two TAGvectors. The length of vec0 and vec1 must be the same.

Function: TAGvector-range-check vec min max
Vec must be a TAGvector, and each of min and max must be either a TAGvector, a vector or a list of the same length as vec, or a number, or `#f`.

For each element in vec, this procedure checks if the value is between minval and maxval inclusive, where minval and maxval are the corresponding values of min and max (when min and/or max is/are non-scalar value) or min and max themselves (when min and/or max is/are a number). When min is `#f`, negative infinity is assumed. When max is `#f`, positive infinity is assumed.

If all the elements in vec are within the range, `#f` is returned. Otherwise, the index of the leftmost element of vec that is out of range is returned.

 ```(u8vector-range-check '#u8(3 1 0 2) 0 3) => #f (u8vector-range-check '#u8(3 1 0 2) 1 3) => 2 (u8vector-range-check '#u8(4 32 64 98) 0 '#u8(10 40 70 90)) => 3 ;; Range check in a program (cond ((u8vector-range-check u8v 1 31) => (lambda (i) (errorf "~sth vector element is out of range: ~s" i (u8vector-ref u8v i)))) (else (do-something u8v))) ```

Function: TAGvector-clamp vec min max
Function: TAGvector-clamp! vec min max
Vec must be a TAGvector, and each of min and max must be either a TAGvector, a vector or a list of the same length as vec, or a number, or `#f`.

Like TAGvector-range-check, these procedures check if each element of vec are within the range between minval and maxval inclusive, which are defived from min and max. If the value is less than minval, it is replaced by minval. If the value is grater than maxval, it is replaced by maxval.

TAGvector-clamp creates a copy of vec and do clamp operation on it, while TAGvector-clamp! modifies vec. Both return the clamped vector.

 ```(s8vector-clamp '#s8(8 14 -3 -22 0) -10 10) => #s8(8 10 -3 -10 0) ```

 [ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html