#
# = GSL::Vector class
#
# Contents:
# 1. {Class methods}[link:rdoc/vector_rdoc.html#label-Class+methods]
# 1. {Notes}[link:rdoc/vector_rdoc.html#label-NOTE%3A]
# 1. {Methods}[link:rdoc/vector_rdoc.html#label-Methods]
#    1. {Accessing vector elements}[link:rdoc/vector_rdoc.html#label-Accessing+vector+elements]
#    1. {Initializing vector elements}[link:rdoc/vector_rdoc.html#label-Initializing+vector+elements]
#    1. {Iterators}[link:rdoc/vector_rdoc.html#label-Iterators]
#    1. {IO}[link:rdoc/vector_rdoc.html#label-IO]
#    1. {Copying vectors}[link:rdoc/vector_rdoc.html#label-Copying+vectors]
#    1. {Vector views}[link:rdoc/vector_rdoc.html#label-Vector+views]
#    1. {Vector operations}[link:rdoc/vector_rdoc.html#label-Vector+operations]
#    1. {Vector operations with size changes}[link:rdoc/vector_rdoc.html#label-Vector+operations+with+size+changes]
#    1. {Finding maximum and minimum elements of vectors}[link:rdoc/vector_rdoc.html#label-Finding+maximum+and+minimum+elements+of+vectors]
#    1. {Vector properties}[link:rdoc/vector_rdoc.html#label-Vector+Properties]
#    1. {Element-wise vector comparison}[link:rdoc/vector_rdoc.html#label-Element-wise+vector+comparison]
#    1. {Histogram}[link:rdoc/vector_rdoc.html#label-Histogram]
#    1. {Sorting}[link:rdoc/vector_rdoc.html#label-Sorting]
#    1. {BLAS methods}[link:rdoc/vector_rdoc.html#label-BLAS+Methods]
#    1. {Data type conversions}[link:rdoc/vector_rdoc.html#label-Data+type+conversions]
# 1. {NArray}[link:rdoc/vector_rdoc.html#label-NArray+conversions]
# 1. {GNU graph interface}[link:rdoc/vector_rdoc.html#label-Graphics]
#
# See also {GSL::Vector::Complex}[link:rdoc/vector_complex_rdoc.html].
#
# == Class methods
#
# ---
# * GSL::Vector.alloc(ary)
# * GSL::Vector.alloc(ary)
# * GSL::Vector.alloc(range)
# * GSL::Vector.alloc(size)
# * GSL::Vector.alloc(elm0, elm1, ....)
# * GSL::Vector[elm0, elm1, ....]
#
#   Constructors.
#
#   Ex:
#      >> v1 = GSL::Vector.alloc(5)
#      => GSL::Vector: [ 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 ]
#      >> v2 = GSL::Vector.alloc(1, 3, 5, 2)
#      => GSL::Vector: [ 1.000e+00 3.000e+00 5.000e+00 2.000e+00 ]
#      >> v3 = GSL::Vector[1, 3, 5, 2]
#      => GSL::Vector: [ 1.000e+00 3.000e+00 5.000e+00 2.000e+00 ]
#      >> v4 = GSL::Vector.alloc([1, 3, 5, 2])
#      => GSL::Vector: [ 1.000e+00 3.000e+00 5.000e+00 2.000e+00 ]
#      >> v5 = GSL::Vector[1..6]
#      => GSL::Vector: [ 1.000e+00 2.000e+00 3.000e+00 4.000e+00 5.000e+00 6.000e+00 ]
#
# ---
# * GSL::Vector.calloc(size)
#
#   This method creates a vector object, and initializes all the elements to zero.
#
# ---
# * GSL::Vector.linspace(min, max, n = 10)
#
#   Creates an <tt>GSL::Vector</tt> with <tt>n</tt> linearly spaced elements
#   between <tt>min</tt> and <tt>max</tt>. If <tt>min</tt> is greater than <tt>max</tt>,
#   the elements are stored in decreasing order. This mimics the <tt>linspace</tt>
#   function of {GNU Octave}[https://gnu.org/software/octave/].
#
#   Ex:
#       >> x = GSL::Vector.linspace(0, 10, 5)
#       [ 0.000e+00 2.500e+00 5.000e+00 7.500e+00 1.000e+01 ]
#       >> y = GSL::Vector.linspace(10, 0, 5)
#       [ 1.000e+01 7.500e+00 5.000e+00 2.500e+00 0.000e+00 ]
#
# ---
# * GSL::Vector.logspace(min, max, n)
#
#   Similar to <tt>GSL::Vector#linspace</tt> except that the values are
#   logarithmically spaced from 10^<tt>min</tt> to 10^<tt>max</tt>.
#
#   Ex:
#       >> x = GSL::Vector.logspace(1, 3, 5)
#       [ 1.000e+01 3.162e+01 1.000e+02 3.162e+02 1.000e+03 ]
#       >> x = GSL::Vector.logspace(3, 1, 5)
#       [ 1.000e+03 3.162e+02 1.000e+02 3.162e+01 1.000e+01 ]
#
# ---
# * GSL::Vector.logspace2(min, max, n)
#
#   Similar to <tt>GSL::Vector#linspace</tt> except that the values are
#   logarithmically spaced from <tt>min</tt> to <tt>max</tt>.
#
#   Ex:
#       >> x = GSL::Vector.logspace2(10, 1000, 5)
#       [ 1.000e+01 3.162e+01 1.000e+02 3.162e+02 1.000e+03 ]
#       >> x = GSL::Vector.logspace2(1000, 10, 5)
#       [ 1.000e+03 3.162e+02 1.000e+02 3.162e+01 1.000e+01 ]
#
# ---
# * GSL::Vector.indgen(n, start=0, step=1)
#
#   This creates a vector of length <tt>n</tt> with elements from <tt>start</tt>
#   with interval <tt>step</tt> (mimics NArray#indgen).
#
#   Ex:
#       >> v = GSL::Vector::Int.indgen(5)
#       => GSL::Vector::Int:
#       [ 0 1 2 3 4 ]
#       >> v = GSL::Vector::Int.indgen(5, 3)
#       => GSL::Vector::Int:
#       [ 3 4 5 6 7 ]
#       >> v = GSL::Vector.indgen(4, 1.2, 0.3)
#       => GSL::Vector
#       [ 1.200e+00 1.500e+00 1.800e+00 2.100e+00 ]
#
# ---
# * GSL::Vector.filescan(filename)
#
#   Reads a formatted ascii file and returns an array of vectors.
#   For a data file <tt>a.dat</tt> as
#     1 5 6 5
#     3 5 6 7
#     5 6 7 9
#   then <tt>a, b, c, d = Vetor.filescan("a.dat")</tt> yields
#     a = [1, 3, 5]
#     b = [5, 5, 6]
#     c = [6, 6, 7]
#     d = [5, 7, 9]
#
# === NArray Extension
# If an <tt>NArray</tt> 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}[link:rdoc/vector_rdoc.html#label-NArray+conversions].
#
# == 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
# ---
# * GSL::Vector#get(args)
# * \GSL::Vector#[args]
#
#   Returns elements(s) of the vector <tt>self</tt> if <tt>args</tt> is a single
#   <tt>Fixnum</tt>, a single <tt>Array</tt> of <tt>Fixnums</tt>, or a single
#   <tt>GSL::Permutation</tt> (or <tt>GSL::Index</tt>).  For all other <tt>args</tt>,
#   the arguments are treated as with <tt>Vector#subvector</tt> and a
#   <tt>Vector::View</tt> is returned.
#
# ---
# * GSL::Vector#set(args, val)
# * \GSL::Vector#[args] = val
#
#   If <tt>args</tt> is empty, behaves as <tt>#set_all</tt> and <tt>val</tt> must be a
#   <tt>Numeric</tt>.
#
#   If <tt>args</tt> is a single <tt>Fixnum</tt>, <tt>i</tt>, sets the <tt>i</tt>-th
#   element of the vector <tt>self</tt> to <tt>val</tt>, which must be a
#   <tt>Numeric</tt>.
#
#   All other <tt>args</tt> specify a subvector (as with <tt>#subvector</tt>) whose
#   elements are assigned from <tt>val</tt>.  In this case, <tt>val</tt> can be an
#   <tt>Array</tt>, <tt>Range</tt>, <tt>GSL::Vector</tt>, or <tt>Numeric</tt>.
#
#   NOTE: GSL does not provide a vector copy function that properly copies data
#   across overlapping memory regions, so watch out if assigning to part of a
#   Vector from another part of itself (see example below).
#
#   Ex:
#       >> require 'gsl'
#       => true
#       >> v = GSL::Vector[0..5]
#       => GSL::Vector
#       [ 0.000e+00 1.000e+00 2.000e+00 3.000e+00 4.000e+00 5.000e+00 ]
#       >> v[2]
#       => 2.0
#       >> v[1,2,3]
#       => GSL::Vector::View
#       [ 1.000e+00 3.000e+00 5.000e+00 ]
#       >> v[[1,2,3]]
#       => GSL::Vector
#       [ 1.000e+00 2.000e+00 3.000e+00 ]
#       >> v[3] = 9
#       => 9
#       >> v[-1] = 123
#       => 123
#       >> v
#       => GSL::Vector
#       [ 0.000e+00 1.000e+00 2.000e+00 9.000e+00 4.000e+00 1.230e+02 ]
#       >> v[2,3] = 0
#       => 0
#       >> v
#       => GSL::Vector
#       [ 0.000e+00 1.000e+00 0.000e+00 0.000e+00 0.000e+00 1.230e+02 ]
#       >> v[2,3] = [4,5,6]
#       => [4, 5, 6]
#       >> v
#       => GSL::Vector
#       [ 0.000e+00 1.000e+00 4.000e+00 5.000e+00 6.000e+00 1.230e+02 ]
#       >> v[1,4] = v[0,4] # !!! Overlapping !!!
#       => GSL::Vector::View
#       [ 0.000e+00 0.000e+00 0.000e+00 0.000e+00 ]
#       >> v
#       => GSL::Vector
#       [ 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 1.230e+02 ]
#
#
# === Initializing vector elements
# ---
# * GSL::Vector#set_all(x)
#
#   This method sets all the elements of the vector to the value <tt>x</tt>.
#
# ---
# * GSL::Vector#set_zero
#
#   This method sets all the elements of the vector to zero.
#
# ---
# * GSL::Vector#set_basis!(i)
#
#   This method makes a basis vector by setting all the elements of the vector
#   to zero except for the <tt>i</tt>-th element, which is set to one.
#   For a vector <tt>v</tt> of size 10, the method
#     v.set_basis!(4)
#   sets the vector <tt>v</tt> to a basis vector <tt>[0, 0, 0, 0, 1, 0, 0, 0, 0, 0]</tt>.
#
# ---
# * GSL::Vector#set_basis(i)
#
#   This method returns a new basis vector by setting all the elements of the
#   vector to zero except for the i-th element which is set to one.
#   For a vector <tt>v</tt> of size 10, the method
#     vb = v.set_basis(4)
#   creates a new vector <tt>vb</tt> with elements <tt>[0, 0, 0, 0, 1, 0, 0, 0, 0, 0]</tt>.
#   The vector <tt>v</tt> is not changed.
#
# ---
# * GSL::Vector#indgen!(start=0, step=1)
# * GSL::Vector#indgen(start=0, step=1)
#
#   Mimics NArray#indgen!.
#
# === Iterators
# ---
# * GSL::Vector#each
# * GSL::Vector#reverse_each
#
#   An iterator for each of the vector elements, used as
#
#     v.each do |x|    # Show all the elements
#       p x
#     end
#
# ---
# * GSL::Vector#each_index
# * GSL::Vector#reverse_each_index
#
#   Iterators
#
# ---
# * GSL::Vector#collect { |item| .. }
# * GSL::Vector#map { |item| .. }
#
#   Creates a new vector by collecting the vector elements modified with some
#   operations.
#
#   Ex:
#     >> a = GSL::Vector::Int[0..5]
#     => GSL::Vector::Int
#     [ 0 1 2 3 4 5 ]
#     >> b = a.collect {|v| v*v}
#     => GSL::Vector::Int
#     [ 0 1 4 9 16 25 ]
#     >> a
#     => GSL::Vector::Int
#     [ 0 1 2 3 4 5 ]
#
# ---
# * GSL::Vector#collect! { |item| .. }
# * GSL::Vector#map! { |item| .. }
#
#   Ex:
#     >> a = GSL::Vector::Int[0..5]
#     => GSL::Vector::Int
#     [ 0 1 2 3 4 5 ]
#     >> a.collect! {|v| v*v}
#     => GSL::Vector::Int
#     [ 0 1 4 9 16 25 ]
#     >> a
#     => GSL::Vector::Int
#     [ 0 1 4 9 16 25 ]
#
# === IO
# ---
# * GSL::Vector#print
# * GSL::Vector#fprintf(io, format = "%e")
# * GSL::Vector#fprintf(filename, format = "%e")
# * GSL::Vector#fscanf(io)
# * GSL::Vector#fscanf(filename)
# * GSL::Vector#fwrite(io)
# * GSL::Vector#fwrite(filename)
# * GSL::Vector#fread(io)
# * GSL::Vector#fread(filename)
#
#   Methods for writing or reading the vector.
#   The first argument is an <tt>IO</tt> or a <tt>String</tt> object.
#
# === Copying vectors
# ---
# * GSL::Vector#clone
# * GSL::Vector#duplicate
#
#   Create a new vector of the same elements.
#
# === Vector views
# The <tt>GSL::Vector::View</tt> class is defined to be used as "references" to
# vectors. Since the <tt>Vector::View</tt> class is a subclass of <tt>Vector</tt>,
# an instance of the <tt>View</tt> class created by slicing a <tt>Vector</tt> object
# can be used same as the original vector. A
# <tt>View</tt> object shares the data with the original vector, i.e. any changes
# in the elements of the <tt>View</tt> object affect to the original vector.
#
# ---
# * GSL::Vector#subvector
# * GSL::Vector#subvector(n)
# * GSL::Vector#subvector(offset, n)
# * GSL::Vector#subvector(offset, stride, n)
# * GSL::Vector#subvector(range, stride=1)
#
#   Create a <tt>Vector::View</tt> object slicing <tt>n</tt> elements
#   of the vector <tt>self</tt> from the offset <tt>offset</tt>. If called with one
#   argument <tt>n</tt>, <tt>offset</tt> is set to 0. With no arguments, a view is
#   created with the same length of the original vector.  If called with a
#   <tt>range</tt> parameter (and optional <tt>stride</tt>), a view is created for
#   that range (and stride).  Note the <tt>n</tt>, if given, is the length of the
#   returned View.
#
#   * Example:
#      #!/usr/bin/env ruby
#      require("gsl")
#
#      v = GSL::Vector[1, 2, 3, 4, 5, 6]
#      view = v.subvector(1, 4)
#      p view.class         <----- GSL::Vector::View
#      view.print           <----- [ 2 3 4 5 ]
#
#      view[2] = 99
#      view.print           <----- [ 2 3 99 5 ]
#      v.print              <----- [ 1 2 3 99 5 6 ]
#
# ---
# * GSL::Vector#subvector_with_stride(stride)
# * GSL::Vector#subvector_with_stride(offset, stride)
# * GSL::Vector#subvector_with_stride(offset, stride, n)
#
#   Return a <tt>Vector::View</tt> object of a subvector of another vector
#   <tt>self</tt> with an additional stride argument. The subvector is formed in
#   the same way as for <tt>Vector#subvector</tt> but the new vector view has
#   <tt>n</tt> elements with a step-size of <tt>stride</tt> from one element to the
#   next in the original vector.  Note that <tt>n</tt>, if given, is the length of
#   the returned View.
#
# ---
# * GSL::Vector#matrix_view(n1, n2)
#
#   This creates a <tt>Matrix::View</tt> object from the vector <tt>self</tt>.
#   It enables to use the vector as a {Matrix}[link:rdoc/matrix_rdoc.html] object.
#
#   * Ex:
#
#       >> v = GSL::Vector::Int.alloc(1..9)
#       => GSL::Vector::Int:
#       [ 1 2 3 4 5 6 7 8 9 ]
#       >> m = v.matrix_view(3, 3)
#       => GSL::Matrix::Int::View:
#       [ 1 2 3
#         4 5 6
#         7 8 9 ]
#       >> m[1][2] = 99
#       => 99
#       >> v
#       => GSL::Vector::Int:
#       [ 1 2 3 4 5 99 7 8 9 ]
#
# === Vector operations
#
# ---
# * GSL::Vector#swap_elements(i, j)
#
#   This method exchanges the i-th and j-th elements of the vector <tt>in-place</tt>.
#
# ---
# * GSL::Vector#reverse
#
#   Reverses the order of the elements of the vector.
#
#     >> v = GSL::Vector::Int[1..5]
#     => GSL::Vector::Int:
#     [ 1 2 3 4 5 ]
#     >> v.reverse
#     => GSL::Vector::Int:
#     [ 5 4 3 2 1 ]
#
# ---
# * GSL::Vector#trans
# * GSL::Vector#transpose
# * GSL::Vector#col
# * GSL::Vector#row
#
#   Transpose the vector from a row vector into a column vector and vice versa.
#
#     >> v = GSL::Vector::Int[1..5]
#     => GSL::Vector::Int:
#     [ 1 2 3 4 5 ]
#     >> v.col
#     => GSL::Vector::Int::Col:
#     [ 1
#       2
#       3
#       4
#       5 ]
#
# ---
# * GSL::Vector#add(b)
#
#   Adds the elements of vector <tt>b</tt> to the elements
#   of the vector <tt>self</tt>. A new vector is created, and the vector
#   <tt>self</tt> is not changed.
#
# ---
# * GSL::Vector#sub(b)
#
#   Subtracts the element of vector <tt>b</tt> from the elements of <tt>self</tt>.
#   A new vector is created, and the vector <tt>self</tt> is not changed.
#
# ---
# * GSL::Vector#mul(b)
#
#   Multiplies the elements of vector <tt>self</tt> by the elements of vector <tt>b</tt>.
# ---
# * GSL::Vector#div(b)
#
#   Divides the elements of vector <tt>self</tt> by the elements of vector <tt>b</tt>.
#
# ---
# * GSL::Vector#scale(x)
# * GSL::Vector#scale!(x)
#
#   This method multiplies the elements of vector <tt>self</tt> by
#   the constant factor <tt>x</tt>.
#
# ---
# * GSL::Vector#add_constant(x)
# * GSL::Vector#add_constant!(x)
#
#   Adds the constant value <tt>x</tt> to the elements of the vector <tt>self</tt>.
#
# ---
# * GSL::Vector#+(b)
#
#   For <tt>b</tt>,
#     * a Number: ---> <tt>self.add_constanb(b)</tt>
#     * a Vector: ---> <tt>self.add(b)</tt>
# ---
# * GSL::Vector#-(b)
#
#   For <tt>b</tt>,
#     * a Number: ---> <tt>self.add_constanb(-b)</tt>
#     * a Vector: ---> <tt>self.sub(b)</tt>
# ---
# * GSL::Vector#/(b)
#
#   For <tt>b</tt>,
#     * a Number: ---> <tt>self.scale(1/b)</tt>
#     * a Vector: ---> <tt>self.div(b)</tt>
#
# ---
# * GSL::Vector#*(b)
#
#   Vector multiplication.
#
# 1. Scale
#         >> v = GSL::Vector[1, 2]
#         [ 1 2 ]
#         >> v*2
#         [ 2 4 ]
# 1. Element-by-element multiplication
#         >> a = GSL::Vector[1, 2]; b = GSL::Vector[3, 4]
#         [ 3 4 ]
#         >> a*b
#         [ 3 8 ]
# 1. Inner product
#         >> a = GSL::Vector[1, 2]; b = GSL::Vector[3, 4]
#         [ 3
#           4 ]
#         >> a*b.col
#         => 11.0
# 1. 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 ]
# 1. 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 ]
#
# ---
# * GSL::Vector#add!(b)
# * GSL::Vector#sub!(b)
# * GSL::Vector#mul!(b)
# * GSL::Vector#div!(b)
#
#   In-place operations with a vector <tt>b</tt>.
#
# ---
# * GSL::Vector#pow(p)
# * GSL::Vector#**(p)
# * GSL::Vector#pow!(p)
#
#   Element-wise calculation of power p.
#
#   Ex)
#      >> require("gsl")
#      >> v = GSL::Vector[1, 2, 3]
#      => GSL::Vector
#      [ 1.000e+00 2.000e+00 3.000e+00 ]
#      >> v.pow(2)
#      => GSL::Vector
#      [ 1.000e+00 4.000e+00 9.000e+00 ]
#      >> v**2
#      => GSL::Vector
#      [ 1.000e+00 4.000e+00 9.000e+00 ]
#      >> v
#      => GSL::Vector
#      [ 1.000e+00 2.000e+00 3.000e+00 ]
#      >> v.pow!(2)
#      => GSL::Vector
#      [ 1.000e+00 4.000e+00 9.000e+00 ]
#      >> v
#      => GSL::Vector
#      [ 1.000e+00 4.000e+00 9.000e+00 ]
#
# ---
# * GSL::Vector#swap_elements(i, j)
#
#   This exchanges the <tt>i</tt>-th and <tt>j</tt>-th elements of the vector <tt>self</tt> in-place.
# ---
# * GSL::Vector#clone
# * GSL::Vector#duplicate
#
#   These create a copy of the vector <tt>self</tt>.
#
# ---
# * GSL::Vector.connect(v1, v2, v3, ...)
# * GSL::Vector#connect(v2, v3, ...)
#
#   Creates a new vector by connecting all the elements of the given vectors.
#
#     >> v1 = GSL::Vector::Int[1, 3]
#     => GSL::Vector::Int:
#     [ 1 3 ]
#     >> v2 = GSL::Vector::Int[4, 3, 5]
#     => GSL::Vector::Int:
#     [ 4 3 5 ]
#     >> v1.connect(v2)
#     => GSL::Vector::Int:
#     [ 1 3 4 3 5 ]
#
# ---
# * GSL::Vector#sgn
# * GSL::Vector#signum
#
#   Creates a new vector, with elements +1 if <tt>x_i</tt> > 0, -1 if <tt>x_i</tt> <
#   0, otherwise 0.  Note that this definition gives the signum of NaN as 0
#   rather than NaN.
#
# ---
# * GSL::Vector#abs
# * GSL::Vector#fabs
#
#   Creates a new vector, with elements <tt>fabs(x_i)</tt>.
#
#     >> v = GSL::Vector::Int[-3, 2, -5, 4]
#     => GSL::Vector::Int:
#     [ -3 2 -5 4 ]
#     >> v.abs
#     => GSL::Vector::Int:
#     [ 3 2 5 4 ]
#
# ---
# * GSL::Vector#square
# * GSL::Vector#abs2
#
#   Create a new vector, with elements <tt>x_i*x_i</tt>.
#
#     >> v = GSL::Vector::Int[1..4]
#     => GSL::Vector::Int:
#     [ 1 2 3 4 ]
#     >> v.square
#     => GSL::Vector::Int:
#     [ 1 4 9 16 ]
#
# ---
# * GSL::Vector#sqrt
#
#   Creates a new vector, with elements <tt>sqrt</tt>(<tt>x_i</tt>).
#
# ---
# * GSL::Vector#floor
# * GSL::Vector#ceil
# * GSL::Vector#round
#
#
#   Ex:
#     >> v = GSL::Vector[1.1, 2.7, 3.5, 4.3]
#     => GSL::Vector
#     [ 1.100e+00 2.700e+00 3.500e+00 4.300e+00 ]
#     >> v.floor
#     => GSL::Vector::Int
#     [ 1 2 3 4 ]
#     >> v.ceil
#     => GSL::Vector::Int
#     [ 2 3 4 5 ]
#     >> v.round
#     => GSL::Vector::Int
#     [ 1 3 4 4 ]
#
# ---
# * GSL::Vector#normalize(nrm = 1.0)
#
#   Creates a new vector of norm <tt>nrm</tt>, by scaling the vector <tt>self</tt>.
# ---
# * GSL::Vector#normalize!(nrm = 1.0)
#
#   This normalizes the vector <tt>self</tt> in-place.
#
#   Ex:
#     tcsh> irb
#     >> require("gsl")
#     => true
#     >> a = GSL::Vector[-1, -2, -3, -4]
#     => GSL::Vector:
#     [ -1.000e+00 -2.000e+00 -3.000e+00 -4.000e+00 ]
#     >> b = a.abs
#     => GSL::Vector:
#     [ 1.000e+00 2.000e+00 3.000e+00 4.000e+00 ]
#     >> b.sqrt
#     => GSL::Vector:
#     [ 1.000e+00 1.414e+00 1.732e+00 2.000e+00 ]
#     >> b.square
#     => GSL::Vector:
#     [ 1.000e+00 4.000e+00 9.000e+00 1.600e+01 ]
#     >> c = b.normalize(2)
#     => GSL::Vector:
#     [ 2.582e-01 5.164e-01 7.746e-01 1.033e+00 ]
#     >> c.square.sum
#     => 2.0
#
# ---
# * GSL::Vector#decimate(n)
#
#   Creates a new vector by averaring every <tt>n</tt>
#   points of the vector <tt>self</tt> down to one point.
#
# ---
# * GSL::Vector#diff(k = 1)
#
#   Calculate <tt>k</tt>-th differences of a vector <tt>self</tt>.
#
#
# ---
# * GSL::Vector#join(sep = " ")
#
#   Converts the vector to a <tt>String</tt> by joining all the elements with a
#   separator <tt>sep</tt>.
#
# ---
# * GSL::Vector#zip(vec, ...)
# * GSL::Vector.zip(vec, ...)
#
#   Create an <tt>Array</tt> of vectors by merging the elements of <tt>self</tt>
#   with corresponding elements from each arguments.
#
#   Ex:
#     >> require("gsl")
#     >> a = GSL::Vector[4, 5, 6]
#     >> b = GSL::Vector[7, 8, 9]
#     >> GSL::Vector[1, 2, 3].zip(a, b)
#     [[ 1.000e+00 4.000e+00 7.000e+00 ],
#      [ 2.000e+00 5.000e+00 8.000e+00 ],
#      [ 3.000e+00 6.000e+00 9.000e+00 ]]
#     >> GSL::Vector[1, 2].zip(a, b)
#     [[ 1.000e+00 4.000e+00 7.000e+00 ],
#      [ 2.000e+00 5.000e+00 8.000e+00 ]]
#     >> a.zip(GSL::Vector[1, 2], GSL::Vector[8.0])
#     [[ 4.000e+00 1.000e+00 8.000e+00 ],
#      [ 5.000e+00 2.000e+00 0.000e+00 ],
#      [ 6.000e+00 0.000e+00 0.000e+00 ]]
#
# ---
# * GSL::Vector#concat(x)
#
#   Returns a new Vector that contains the concatenation <tt>self</tt> and
#   <tt>x</tt>, which must be an <tt>Array</tt>, <tt>Fixnum</tt>, <tt>Bignum</tt>,
#   <tt>Float</tt>, <tt>Range</tt>, or <tt>GSL::Vector</tt>.
#
# === Vector operations with size changes
# The methods below change vector length of <tt>self</tt>.  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.
#
# ---
# * GSL::Vector#delete(x)
#
#   Deletes items from <tt>self</tt> that are equal to <tt>x</tt>.  If the item is
#   not found, returns <tt>nil</tt>, otherwise returns <tt>x</tt>.
# ---
# * GSL::Vector#delete_at(i)
#
#   Deletes the element at the specified index <tt>i</tt>,
#   returning that  element, or <tt>nil</tt> if the index is out of range.
# ---
# * GSL::Vector#delete_if { |x| ... }
#
#   Deletes every element of <tt>self</tt> for which block evaluates to <tt>true</tt>
#   and returns <tt>self</tt>.
#
# === Finding maximum and minimum elements of vectors
#
# ---
# * GSL::Vector#max
#
#   This method returns the maximum value in the vector.
#
# ---
# * GSL::Vector#min
#
#   This method returns the minimum value in the vector.
#
# ---
# * GSL::Vector#minmax
#
#   This method returns an array of two elements, the minimum and the maximum values
#   in the vector <tt>self</tt>.
#
# ---
# * GSL::Vector#max_index
#
#   This method returns the index of the maximum value in the vector. When there are
#   several equal maximum elements then the lowest index is returned.
#
# ---
# * GSL::Vector#min_index
#
#   This method returns the index of the minimum value in the vector. When there are
#   several equal minimum elements then the lowest index is returned.
#
# ---
# * GSL::Vector#minmax_index
#
#   This method returns an array of two elements which has the indices
#   of the minimum and the maximum values in the vector <tt>self</tt>.
#
# === Vector Properties
# ---
# * GSL::Vector#size
# * GSL::Vector#len
# * GSL::Vector#length
#
#   Return the vector length.
#
# ---
# * GSL::Vector#stride
#
#   Return the vector stride.
#
# ---
# * GSL::Vector#sum
#
#   Returns the sum of the vector elements.
#
# ---
# * GSL::Vector#prod
#
#   Returns the product of the vector elements.
#
# ---
# * GSL::Vector#cumsum
#
#   Calculate the cumulative sum of elements of <tt>self</tt> and returns as a new vector.
#
# ---
# * GSL::Vector#cumprod
#
#   Calculate the cumulative product of elements of <tt>self</tt> and returns as a new vector.
#
# ---
# * GSL::Vector#isnull
#
#   Returns 1 if all the elements of the vector <tt>self</tt>
#   are zero, and 0 otherwise.
# ---
# * GSL::Vector#isnull?
#
#   Return <tt>true</tt> if all the elements of the vector <tt>self</tt>
#   are zero, and <tt>false</tt> otherwise.
# ---
# * GSL::Vector#ispos
# * GSL::Vector#ispos?
# * GSL::Vector#isneg
# * GSL::Vector#isneg?
#
#   (GSL-1.9 or later) Return 1 (true) if all the elements of the vector <tt>self</tt> are zero, strictly positive, strictly negative respectively, and 0 (false) otherwise.
#
# ---
# * GSL::Vector#isnonneg
# * GSL::Vector#isnonneg?
#
#   (GSL-1.10 or later) Return 1 (true) if all the elements of the vector <tt>self</tt> are non-negative , and 0 (false) otherwise.
#
# ---
# * GSL::Vector#all?
#
#   Returns <tt>true</tt> if all the vector elements are non-zero, and <tt>false</tt>
#   otherwise. If a block is given, the method returns <tt>true</tt> if the
#   tests are true for all the elements.
# ---
# * GSL::Vector#any?
#
#   Returns <tt>true</tt> if any the vector elements are non-zero, and <tt>false</tt>
#   otherwise. If a block is given, the method returns <tt>true</tt> if the
#   tests are true for any of the elements.
# ---
# * GSL::Vector#none?
#
#   Returns <tt>true</tt> if all the elements of the vector <tt>self</tt>
#   are zero, and <tt>false</tt> otherwise (just as <tt>GSL::Vector#isnull?</tt>).
#   If a block is given, the method returns <tt>true</tt> if the
#   tests are false for all the elements.
#
#   Ex:
#     >> a = GSL::Vector[1, 2, 3]
#     >> b = GSL::Vector[1, 2, 0]
#     >> c = GSL::Vector[0, 0, 0]
#     >> a.all?
#     => true
#     >> b.all?
#     => false
#     >> b.any?
#     => true
#     >> c.any?
#     => false
#     >> a.none?
#     => false
#     >> c.none?
#     => true
#
# ---
# * GSL::Vector#all
# * GSL::Vector#any
# * GSL::Vector#none
#
#   Returns 1 or 0.
#
# ---
# * GSL::Vector#equal?(other, eps = 1e-10)
# * GSL::Vector#==(other, eps = 1e-10)
#
#   Returns <tt>true</tt> if the vectors have same size and elements
#   equal to absolute accurary <tt>eps</tt> for all the indices,
#   and <tt>false</tt> otherwise.
#
# === Element-wise vector comparison
# ---
# * GSL::Vector#eq(other)
# * GSL::Vector#ne(other)
# * GSL::Vector#gt(other)
# * GSL::Vector#ge(other)
# * GSL::Vector#lt(other)
# * GSL::Vector#le(other)
#
#   Return a <tt>Block::Byte</tt> object with elements 0/1 by comparing the two vectors
#   <tt>self</tt> and <tt>other</tt>. Note that the values returned are 0/1,
#   not <tt>true/false</tt>, thus all of the elements are "true" in Ruby.
#
#   Ex:
#      >> a = GSL::Vector[1, 2, 3]
#      >> b = GSL::Vector[1, 2, 5]
#      >> a.eq(b)
#      [ 1 1 0 ]
#      >> a.ne(b)
#      [ 0 0 1 ]
#      >> a.gt(b)
#      [ 0 0 0 ]
#      >> a.ge(b)
#      [ 1 1 0 ]
#      >> a.eq(3)
#      [ 0 0 1 ]
#      >> a.ne(2)
#      [ 1 0 1 ]
#      >> a.ge(2)
#      [ 0 1 1 ]
#
# ---
# * GSL::Vector#and(other)
# * GSL::Vector#or(other)
# * GSL::Vector#xor(other)
# * GSL::Vector#not
#
#
#   Ex:
#     >> a = GSL::Vector[1, 0, 3, 0]
#     >> b = GSL::Vector[3, 4, 0, 0]
#     >> a.and(b)
#     [ 1 0 0 0 ]
#     >> a.or(b)
#     [ 1 1 1 0 ]
#     >> a.xor(b)
#     [ 0 1 1 0 ]
#     >> a.not
#     [ 0 1 0 1 ]
#     >> b.not
#     [ 0 0 1 1 ]
#
# ---
# * GSL::Vector#where
# * GSL::Vector#where { |elm| ... }
#
#   Returns the vector indices where the tests are true. If all the test failed
#   <tt>nil</tt> is returned.
#
#   Ex:
#     >> v = GSL::Vector::Int[0, 3, 0, -2, 3, 5, 0, 3]
#     >> v.where
#     [ 1 3 4 5 7 ]                   # where elements are non-zero
#     >> v.where { |elm| elm == -2 }
#     [ 3 ]
#     >> a = GSL::Vector[0, 0, 0]
#     >> a.where
#     => nil
#
# === Histogram
# ---
# * GSL::Vector#histogram(n)
# * GSL::Vector#histogram(ranges)
# * GSL::Vector#histogram(n, min, max)
# * GSL::Vector#histogram(n, [min, max])
#
#   Creates a histogram filling the vector <tt>self</tt>.
#
#   Example:
#      >> r = GSL::Rng.alloc           # Random number generator
#      => #<GSL::Rng:0x6d8594>
#      >> v = r.gaussian(1, 1000)    # Generate 1000 Gaussian random numbers
#      => GSL::Vector
#      [ 1.339e-01 -8.810e-02 1.674e+00 7.336e-01 9.975e-01 -1.278e+00 -2.397e+00 ... ]
#      >> h = v.histogram(50, [-4, 4])  # Creates a histogram of size 50, range [-4, 4)
#      => #<GSL::Histogram:0x6d28b0>
#      >> h.graph("-T X -C -g 3")    # Show the histogram
#      => true
#
#   This is equivalent to
#      h = Histogram.alloc(50, [-4, 4])
#      h.increment(v)
#
# === Sorting
#
# ---
# * GSL::Vector#sort
# * GSL::Vector#sort!
#
#   These methods sort the vector <tt>self</tt> in ascending numerical order.
#
# ---
# * GSL::Vector#sort_index
#
#   This method indirectly sorts the elements of the vector <tt>self</tt> into
#   ascending order, and returns the resulting permutation.
#   The elements of permutation give the index of the vector element which
#   would have been stored in that position if the vector had been sorted in place.
#   The first element of permutation gives the index of the least element in the
#   vector, and the last element of permutation gives the index of the greatest
#   vector element. The vector <tt>self</tt> is not changed.
#
# ---
# * GSL::Vector#sort_smallest(n)
# * GSL::Vector#sort_largest(n)
# * GSL::Vector#sort_smallest_index(n)
# * GSL::Vector#sort_largest_index(n)
#
#
#   Ex:
#       >> v = GSL::Vector::Int[8, 2, 3, 7, 9, 1, 4]
#       => GSL::Vector::Int:
#       [ 8 2 3 7 9 1 4 ]
#       >> v.sort
#       => GSL::Vector::Int:
#       [ 1 2 3 4 7 8 9 ]
#       >> v.sort_index
#       => GSL::Permutation:
#       [ 5 1 2 6 3 0 4 ]
#       >> v.sort_largest(3)
#       => GSL::Vector::Int:
#       [ 9 8 7 ]
#       >> v.sort_smallest(3)
#       => GSL::Vector::Int:
#       [ 1 2 3 ]
#
# === BLAS Methods
# ---
# * GSL::Vector#nrm2
# * GSL::Vector#dnrm2
#
#   Compute the Euclidean norm ||x||_2 = sqrt {sum x_i^2} of the vector.
#
# ---
# * GSL::Vector#asum
# * GSL::Vector#dasum
#
#   Compute the absolute sum \sum |x_i| of the elements of the vector.
#
# === Data type conversions
# ---
# * GSL::Vector#to_a
#
#   This method converts the vector into a Ruby array. A Ruby array also can be
#   converted into a GSL::Vector object with the <tt>to_gv</tt> method. For example,
#
#     v = GSL::Vector.alloc([1, 2, 3, 4, 5])
#     a = v.to_a   -> GSL::Vector to an array
#     p a          -> [1.0, 2.0, 3.0, 4.0, 5.0]
#     a[2] = 12.0
#     v2 = a.to_gv  -> a new GSL::Vector object
#     v2.print     -> 1.0000e+00 2.0000e+00 1.2000e+01 4.0000e+00 5.0000e+00
#
# ---
# * GSL::Vector#to_m(nrow, ncol)
#
#   Creates a <tt>GSL::Matrix</tt> object of <tt>nrow</tt> rows and <tt>ncol</tt> columns.
#
#     >> v = GSL::Vector::Int[1..5]
#     => GSL::Vector::Int:
#     [ 1 2 3 4 5 ]
#     >> v.to_m(2, 3)
#     => GSL::Matrix::Int:
#     [ 1 2 3
#       4 5 0 ]
#     >> v.to_m(2, 2)
#     => GSL::Matrix::Int:
#     [ 1 2
#       3 4 ]
#     >> v.to_m(3, 2)
#     => GSL::Matrix::Int:
#     [ 1 2
#       3 4
#       5 0 ]
#
# ---
# * GSL::Vector#to_m_diagonal
#
#   Converts the vector into a diagonal matrix.
#   See also {GSL::Matrix.diagonal(v)}[link:rdoc/matrix_rdoc.html].
#
#      >> v = GSL::Vector[1..4].to_i
#      => GSL::Vector::Int:
#      [ 1 2 3 4 ]
#      >> v.to_m_diagonal
#      => GSL::Matrix::Int:
#      [ 1 0 0 0
#        0 2 0 0
#        0 0 3 0
#        0 0 0 4 ]
#
# ---
# * GSL::Vector#to_m_circulant
#
#   Creates a circulant matrix.
#
#     >> v = GSL::Vector::Int[1..5]
#     => GSL::Vector::Int:
#     [ 1 2 3 4 5 ]
#     >> v.to_m_circulant
#     => GSL::Matrix::Int:
#     [ 5 1 2 3 4
#       4 5 1 2 3
#       3 4 5 1 2
#       2 3 4 5 1
#       1 2 3 4 5 ]
#
# ---
# * GSL::Vector#to_complex
# * GSL::Vector#to_complex2
#
#   Example:
#
#     >> v = GSL::Vector[1..4]
#     => GSL::Vector
#     [ 1.000e+00 2.000e+00 3.000e+00 4.000e+00 ]
#     >> v.to_complex
#     [ [1.000e+00 0.000e+00] [2.000e+00 0.000e+00] [3.000e+00 0.000e+00] [4.000e+00 0.000e+00] ]
#     => #<GSL::Vector::Complex:0x6d7d24>
#     >> v.to_complex2
#     [ [1.000e+00 2.000e+00] [3.000e+00 4.000e+00] ]
#     => #<GSL::Vector::Complex:0x6d6424>
#
# ---
# * GSL::Vector#to_tensor(rank, dimension)
#
#
# === NArray conversions
#
# ---
# * GSL::Vector#to_na
#
#   Converts a vector <tt>self</tt> into an <tt>NArray</tt> object.
#   The data are copied to newly allocated memory.
#
# ---
# * GSL::Vector#to_na2
# * GSL::Vector#to_na_ref
#
#   Create an <tt>NArray</tt> reference of the vector <tt>self</tt>.
#
#   Example:
#     >> v = GSL::Vector::Int[1, 2, 3, 4]
#     => GSL::Vector::Int
#     [ 1 2 3 4 ]
#     >> na = v.to_na
#     => NArray.int(4):
#     [ 1, 2, 3, 4 ]
#     >> na2 = v.to_na2
#     => NArray(ref).int(4):
#     [ 1, 2, 3, 4 ]
#     >> na[1] = 99
#     => 99
#     >> v              # na and v are independent
#     => GSL::Vector::Int
#     [ 1 2 3 4 ]
#     >> na2[1] = 99    # na2 points to the data of v
#     => 99
#     >> v
#     => GSL::Vector::Int
#     [ 1 99 3 4 ]
#
# ---
# * NArray#to_gv
# * NArray#to_gslv
#
#   Create <tt>GSL::Vector</tt> object from the <tt>NArray</tt> object <tt>self</tt>.
#
# ---
# * NArray#to_gv_view
# * NArray#to_gv2
# * NArray#to_gslv_view
#
#   A <tt>GSL::Vector::View</tt> object is created from the NArray object <tt>self</tt>.
#   This method does not allocate memory for the data: the data of <tt>self</tt>
#   are not copied, but shared with the <tt>View</tt> object created, thus
#   any modifications to the <tt>View</tt> object affect on the original NArray
#   object. In other words, the <tt>View</tt> object can be used as a <tt>reference</tt>
#   to the NArray object.
#
#   Ex:
#      tcsh> irb
#      >> require("gsl")
#      => true
#      >> na = NArray[1.0, 2, 3, 4, 5]
#      => NArray.float(5):
#      [ 1.0, 2.0, 3.0, 4.0, 5.0 ]
#      >> vv = na.to_gv_view   # Create a view sharing the memory
#      => GSL::Vector::View
#      [ 1.000e+00 2.000e+00 3.000e+00 4.000e+00 5.000e+00 ]
#      >> vv[3] = 9
#      => 9
#      >> na
#      => NArray.float(5):
#      [ 1.0, 2.0, 3.0, 9.0, 5.0 ]           # The data are changed
#      >> v = na.to_gv         # A vector with newly allocated memory
#      => GSL::Vector
#      [ 1.000e+00 2.000e+00 3.000e+00 9.000e+00 5.000e+00 ]
#      >> v[1] = 123
#      => 123
#      >> v
#      => GSL::Vector
#      [ 1.000e+00 1.230e+02 3.000e+00 9.000e+00 5.000e+00 ]
#      >> na
#      => NArray.float(5):
#      [ 1.0, 2.0, 3.0, 9.0, 5.0 ]           # v and na are independent
#      >> na = NArray[1.0, 2, 3, 4, 5, 6]
#      => NArray.float(6):
#      [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
#      >> m = na.to_gv_view.matrix_view(2, 3)
#      => GSL::Matrix::View
#      [  1.000e+00  2.000e+00  3.000e+00
#         4.000e+00  5.000e+00  6.000e+00 ]
#      >> m[1][2] = 9
#      => 9
#      >> na
#      => NArray.float(6):
#      [ 1.0, 2.0, 3.0, 4.0, 5.0, 9.0 ]
#
# === Graphics
# ---
# * GSL::Vector.graph(y)
# * GSL::Vector.graph(y, options)
# * GSL::Vector.graph(x, y)
# * GSL::Vector.graph(x, y, options)
# * GSL::Vector#graph(options)
# * GSL::Vector#graph(x, options)
#
#   These methods use the GNU plotutils <tt>graph</tt> application to plot
#   a vector <tt>self</tt>. The options of <tt>graph</tt> as "-T X -C" can be given by a String.
#
#   Example:
#     >> x = GSL::Vector.linspace(0, 2.0*M_PI, 20)
#     >> c = GSL::Sf::cos(x)
#     >> s = GSL::Sf::sin(x)
#     >> GSL::Vector.graph(x, c, s, "-T X -C -L 'cos(x), sin(x)'")
#
# {prev}[link:rdoc/sf_rdoc.html]
# {next}[link:rdoc/matrix_rdoc.html]
#
# {Reference index}[link:rdoc/ref_rdoc.html]
# {top}[link:index.html]
#
#
