The GSL-VECTOR module ************************* .. current-library:: dylan-gsl .. current-module:: gsl-vector The type ===================== .. class:: :superclasses: :description: A vector of double precision floating point numbers. :slots: .. method:: gsl-vector-stride :specializer: :signature: gsl-vector-stride (vector) => (stride) :parameter vector: An instance of ``. :value stride: An instance of ``. :description: Return the stride of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); let stride = v.gsl-vector-stride; .. method:: gsl-vector-stride-setter :specializer: :signature: gsl-vector-stride-setter (stride vector) => (stride) :parameter stride: An instance of ``. :parameter vector: An instance of ``. :value stride: An instance of ``. :description: Set the stride of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); v.gsl-vector-stride := 2; Allocation functions ==================== .. method:: make :specializer: :signature: make ( #key size fill stride) => (vector) :parameter #key size: An instance of ``. :parameter #key fill: An instance of ``. :parameter #key stride: An instance of ``. :value vector: An instance of ``. :description: Allocate an array of size elements in a block of memory. :examples: .. code-block:: dylan make(, size: 10, fill: 1.0d0); .. method:: size :specializer: :signature: size (vector) => (size) :parameter vector: An instance of ``. :value size: An instance of ``. :description: Return the size of the vector. Copying vectors =============== .. function:: copy-gsl-vector :signature: copy-gsl-vector (vector) => (copy) :parameter vector: An instance of ``. :value copy: An instance of ``. :description: Return a copy of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); let w = copy-gsl-vector(v); Accessing elements ================== .. method:: element :specializer: :signature: element (vector index) => (element) :parameter vector: An instance of ``. :parameter index: An instance of ``. :value element: An instance of ``. :description: Return the element at the given index. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); element(v, 0); .. method:: element-setter :specializer: :signature: element-setter (value vector index) => (value) :parameter value: An instance of ``. :parameter vector: An instance of ``. :parameter index: An instance of ``. :value value: An instance of ``. :description: Set the element at the given index to the given value. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); element-setter(v, 0, 2.0d0); Initializing vector elements ============================ .. function:: set-all! :signature: set-all! (vector value) => (vector) :parameter vector: An instance of ``. :parameter value: An instance of ``. :value vector: An instance of ``. :description: Set all elements of the vector to the given value. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); set-all!(v, 2.0d0); .. function:: set-zero! :signature: set-zero! (vector) => (vector) :parameter vector: An instance of ``. :value vector: An instance of ``. :description: Set all elements of the vector to zero. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); set-zero!(v); .. function:: set-basis! :signature: set-basis! (vector index) => (vector) :parameter vector: An instance of ``. :parameter index: An instance of ``. :value vector: An instance of ``. :description: Set all elements of the vector to zero except for the element at the given index. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); set-basis!(v, 0); Exchanging elements =================== .. function:: swap! :signature: swap! (vector index) => (vector) :parameter vector: An instance of ``. :parameter index: An instance of ``. :value vector: An instance of ``. :description: Swap the elements at the given index with the element at the given index. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); swap!(v, 0, 1); .. method:: reverse :specializer: :signature: reverse (vector) => (reversed) :parameter vector: An instance of ``. :value reversed: An instance of ``. :description: Return a reversed copy of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); let reversed = reverse(v); .. method:: reverse! :specializer: :signature: reverse! (vector) => (vector) :parameter vector: An instance of ``. :value vector: An instance of ``. :description: Reverse the vector in place. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); reverse!(v); Vector operations ================= .. function:: sum :signature: sum (vector) => (sum) :parameter vector: An instance of ``. :value sum: An instance of ``. :description: Return the sum of the elements of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); sum(v); .. method:: + :specializer: , :signature: \+ (v w) => (sum) :parameter v: An instance of ``. :parameter w: An instance of `` :value sum: An instance of ``. :description: Return the sum of the elements of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); let w = make(, size: 10, fill: 2.0d0); let z = v + w; .. method:: - :specializer: , :signature: \- (v w) => (difference) :parameter v: An instance of ``. :parameter w: An instance of `` :value difference: An instance of ``. :description: Return the sum of the elements of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); let w = make(, size: 10, fill: 2.0d0); let z = v - w; .. method:: * :specializer: , :signature: \* (v w) => (product) :parameter v: An instance of ``. :parameter w: An instance of `` :value product: An instance of ``. :description: Return the sum of the elements of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); let w = make(, size: 10, fill: 2.0d0); let z = v * w; .. method:: / :specializer: , :signature: \/ (v w) => (division) :parameter v: An instance of ``. :parameter w: An instance of ``. :value division: An instance of ``. :description: Return the division of the elements of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 10.0d0); let w = make(, size: 10, fill: 2.0d0); let q = v / w; .. method:: * :specializer: , :signature: \* (vector value) => (scaled) :parameter vector: An instance of ``. :parameter value: An instance of ``. :value scaled: An instance of ``. :description: Return the scaled version of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); let scaled = v * 2.0d0; .. method:: * :specializer: , :signature: \* (value vector) => (scaled) :parameter value: An instance of ``. :parameter vector: An instance of ``. :value scaled: An instance of ``. :description: Return the scaled version of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); let scaled = 2.0d0 * v; .. method:: + :specializer: , :signature: \+ (vector addend) => (sum) :parameter vector: An instance of ``. :parameter addend: An instance of ``. :value sum: An instance of ``. :description: Adds a constant value to the elements of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); let sum = v + 2.0d0; .. function:: sum :signature: sum (vector) => (sum) :parameter vector: An instance of ``. :value sum: An instance of ``. :description: Return the sum of the elements of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); sum(v); .. function:: axpby :signature: axpby (alpha x beta y) => (v) :parameter alpha: An instance of ``. :parameter x: An instance of ``. :parameter beta: An instance of ``. :parameter y: An instance of ``. :value v: An instance of ``. :description: Return the result of the operation alpha * x + beta * y. :examples: .. code-block:: dylan let alpha = 1.0d0; let beta = 2.0d0; let v = make(, size: 10, fill: 1.0d0); let w = make(, size: 10, fill: 2.0d0); let v = axpby(alpha, v, beta, w); .. function:: axpby! :signature: axpby! (alpha x beta y) => (v) :parameter alpha: An instance of ``. :parameter x: An instance of ``. :parameter beta: An instance of ``. :parameter y: An instance of ``. :value v: An instance of ``. :description: Return the result of the operation alpha * x + beta * y in place. :examples: .. code-block:: dylan let alpha = 1.0d0; let beta = 2.0d0; let v = make(, size: 10, fill: 1.0d0); let w = make(, size: 10, fill: 2.0d0); axpby!(alpha, v, beta, w); Finding maximum and minimum elements of vectors =============================================== .. function:: gsl-max :signature: gsl-max (vector) => (max) :parameter vector: An instance of ``. :value max: An instance of ``. :description: Return the maximum element of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); gsl-max(v); .. function:: gsl-min :signature: gsl-min (vector) => (min) :parameter vector: An instance of ``. :value min: An instance of ``. :description: Return the minimum element of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); gsl-min(v); .. function:: max-index :signature: max-index (vector) => (max-index) :parameter vector: An instance of ``. :value max-index: An instance of ``. :description: Return the index of the maximum element of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); max-index(v); .. function:: min-index :signature: min-index (vector) => (min-index) :parameter vector: An instance of ``. :value min-index: An instance of ``. :description: Return the index of the minimum element of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); min-index(v); .. function:: min-max :signature: min-max (vector) => (min max) :parameter vector: An instance of ``. :value min: An instance of ``. :value max: An instance of ``. :description: Return the minimum and maximum elements of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); min-max(v); .. function:: min-max-index :signature: min-max-index (vector) => (min-index max-index) :parameter vector: An instance of ``. :value min-index: An instance of ``. :value max-index: An instance of ``. :description: Return the indices of the minimum and maximum elements of the vector. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); min-max-index(v); Vector properties ================= .. function:: null? :signature: null? (vector) => (null?) :parameter vector: An instance of ``. :value null?: An instance of ``. :description: Return true if the vector is null. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); null?(v); .. method:: zero? :specializer: :signature: zero? (vector) => (zero?) :parameter vector: An instance of ``. :value zero?: An instance of ``. :description: Return true if the vector is zero. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); v.zero?; .. method:: positive? :specializer: :signature: positive? (vector) => (positive?) :parameter vector: An instance of ``. :value positive?: An instance of ``. :description: Return true if the vector is positive. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); v.positive?; .. method:: negative :specializer: :signature: negative (vector) => (vector) :parameter vector: An instance of ``. :value vector: An instance of ``. :description: Return the negative of the vector. :examples: .. code-block:: dylan let v = make(, size: 3, fill: 1.0d0); let r = v + (-v); r.zero? // #t .. method:: negative? :specializer: :signature: negative? (vector) => (negative?) :parameter vector: An instance of ``. :value negative?: An instance of ``. :description: Return true if the vector is negative. :examples: .. code-block:: dylan let v = make(, size: 10, fill: -1.0d0); v.negative?; .. function:: non-negative? :signature: non-negative? (vector) => (non-negative?) :parameter vector: An instance of ``. :value non-negative?: An instance of ``. :description: Return true if the vector is non-negative. :examples: .. code-block:: dylan let v = make(, size: 10, fill: 1.0d0); v.non-negative?; .. method:: f= :specializer: :signature: f= (vector vector #key epsilon) => (boolean) :parameter vector: An instance of ``. :value boolean: An instance of ``. :description: Return true if the vectors are equal. :examples: .. code-block:: dylan let a = make(, size: 10, fill: 1.0d0); let b = make(, size: 10, fill: 1.0d0); f=(a, b, epsilon: 0.00001d0);