GSL::Vector class

Contents:

  1. Class methods

  2. Notes

  3. Methods

    1. Accessing vector elements

    2. Initializing vector elements

    3. Iterators

    4. IO

    5. Copying vectors

    6. Vector views

    7. Vector operations

    8. Vector operations with size changes

    9. Finding maximum and minimum elements of vectors

    10. Vector properties

    11. Element-wise vector comparison

    12. Histogram

    13. Sorting

    14. BLAS methods

    15. Data type conversions

  4. NArray

  5. GNU graph interface

See also GSL::Vector::Complex.

Class methods








NArray Extension

If an NArray object is given, a newly allocated vector is created.

Ex:

na = NArray[1.0, 2, 3, 4, 5]
p na                <----- NArray.float(5):
                           [ 1.0, 2.0, 3.0, 4.0, 5.0]
v = GSL::Vector.alloc(na)
p v                 <----- [ 1 2 3 4 5 ]

See also here.

NOTE:

In Ruby/GSL, vector length is limited within the range of Fixnum. For 32-bit CPU, the maximum of vector length is 2^30 ~ 1e9.

Methods

Accessing vector elements



Initializing vector elements






Iterators





IO


Copying vectors


Vector views

The GSL::Vector::View class is defined to be used as “references” to vectors. Since the Vector::View class is a subclass of Vector, an instance of the View class created by slicing a Vector object can be used same as the original vector. A View object shares the data with the original vector, i.e. any changes in the elements of the View object affect to the original vector.




Vector operations














  1. Scale

    >> v = GSL::Vector[1, 2]
    [ 1 2 ]
    >> v*2
    [ 2 4 ]
  2. Element-by-element multiplication

    >> a = GSL::Vector[1, 2]; b = GSL::Vector[3, 4]
    [ 3 4 ]
    >> a*b
    [ 3 8 ]
  3. Inner product

    >> a = GSL::Vector[1, 2]; b = GSL::Vector[3, 4]
    [ 3
      4 ]
    >> a*b.col
    => 11.0
  4. GSL::Vector::Col*Vector -> GSL::Matrix

    >> a = GSL::Vector::Col[1, 2]; b = GSL::Vector[3, 4]
    [ 3 4 ]
    >> a*b
    [ 3 4
      6 8 ]
  5. GSL::Matrix*Vector::Col -> GSL::Vector::Col

    >> a = GSL::Vector[1, 2]; m = GSL::Matrix[[2, 3], [4, 5]]
    [ 2 3
      4 5 ]
    >> m*a          <--- Error
    TypeError: Operation with GSL::Vector is not defined (GSL::Vector::Col expected)
            from (irb):30:in `*'
            from (irb):30
    >> m*a.col
    [ 8
      14 ]

















Vector operations with size changes

The methods below change vector length of self. A Vector's length may not extend past its original allocation. Use of these methods is discouraged. Existing Views may still refer to elements beyond the end of the shortened Vector. These elements remain allocated, but are effectvely unmanaged.




Finding maximum and minimum elements of vectors







Vector Properties
















Element-wise vector comparison




Histogram


Sorting




BLAS Methods



Data type conversions







NArray conversions





Graphics


prev next

Reference index top