struct GSL::Vector

Included Modules

Defined in:

gsl/base/vector.cr
gsl/maths/basic/vector.cr
gsl/maths/statistics/vector.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(size : Int32) #

[View source]
def self.new(a : Array(Float64)) #

[View source]
def self.new(*, unsafe_from) #

[View source]

Instance Method Detail

def *(n : Int32 | Float64) #

[View source]
def *(n : GSL::Vector) #

[View source]
def +(n : Int32 | Float64) #

[View source]
def +(n : GSL::Vector) #

[View source]
def -(n : Int32 | Float64) #

[View source]
def -(n : GSL::Vector) #

[View source]
def /(n : Int32 | Float64) #

[View source]
def /(n : GSL::Vector) #

[View source]
def <<(n : Float64 | Int32) : Vector #

alias of push methods


[View source]
def ==(n : GSL::Vector) : Bool #

[View source]
def clone #

[View source]
def concat(n : GSL::Vector) : Vector #

concatinate two different vector and return a new vector

a = [1,2,3].to_vector
b = [2,3,4].to_vector
a.concat b => GSL::Vector: [1.0,2.0,3.0,2.0,3.0,4.0]

[View source]
def copy #

[View source]
def dot(n : GSL::Vector) #

[View source]
def empty? : Bool #

return true if current vector's elements are all 0

a = [0,0,0].to_vector
b = [1,0,0].to_vector
a.empty? => true
b.empty? => false

[View source]
def freqs #

alias for frequencies


[View source]
def frequencies #

[View source]
def has_neg? : Bool #

return true if current vector has negtive element in it.

a = [-1,-1,1].to_vector
b = [1,0,0].to_vector
a.empty? => true
b.empty? => false

[View source]
def head : Vector #

return the first five elements in vector of current vector

a = [1,2,3,4,5,6,7,8]to_vector
a.head => GSL::Vector: [1.0,2.0,3.0,4.0,5.0]

[View source]
def inner_product(n : GSL::Vector) #

same as dot function


[View source]
def inspect #
Description copied from class Object

Returns an unambiguous and information-rich string representation of this object, typically intended for developers.

This method should usually not be overridden. It delegates to #inspect(IO) which can be overridden for custom implementations.

Also see #to_s.


[View source]
def max_index : UInt64 #

return the index of maximum value of current vector note: if there are multiple same maximum value then only return the first one.

a = [1,2,3].to_vector
a.max_index => 2

[View source]
def mean : Float64 #

calculate the mean of the vector's elements

a = [0.0, -5.0, 7.3].to_vector.mean
a => 0.76666666666666661

[View source]
def min_index : UInt64 #

return the index of minimum value of current vector note: if there are multiple same minimum value then only return the first one.

a = [1,2,3].to_vector
a.min_index => 0

[View source]
def minmax_index : Array(UInt64) #

return the index of minimum and maximum value of current vector

a = [1, 2, 3].to_vector
min, max = a.minmax_index
min = 0
max = 2

[View source]
def mode #

[View source]
def neg? : Bool #

return true if current vector's elements are all negtive

a = [-1,-1,-1].to_vector
b = [-1,0,0].to_vector
a.empty? => true
b.empty? => false

[View source]
def pointer #

[View source]
def pos? : Bool #

return true if current vector's elements are all positive

a = [1,1,1].to_vector
b = [-1,0,0].to_vector
a.empty? => true
b.empty? => false

[View source]
def proportion(n : Float64 | Int32) #

[View source]
def push(n : Float64 | Int32) : Vector #

Add element to the button of vector

a = [1,2,3].to_vector
a.push 4 => GSL::Vector: [1.0,2.0,3.0,4.0]

[View source]
def ranked #

[View source]
def raw : LibGSL::Gsl_vector #

[View source]
def replace(n : GSL::Vector) : Vector #

replace current vector with input vector note that two vector should have the same length

a = [1,2,3].to_vector
b = [2,3,4].to_vector
c = [2,3,4,5].to_vector
a.replace b
a => GSL::Vector: [2.0,3.0,4.0]
a.replace c => length error

[View source]
def reverse #

return a new vector with reversed elements of current vector

a = [1,2,3].to_vector
a.reverse => GSL::Vector: [3.0,2.0,1.0]
a => GSL::Vector [1.0,2.0,3.0]

[View source]
def reverse! : Vector #

reverse elements of current vector

a = [1,2,3].to_vector
a.reverse! => GSL::Vector: [3.0,2.0,1.0]
a => GSL::Vector: [3.0,2.0,1.0]

[View source]
def set_all(n : Int32 | Float64) : Vector #

return a new value with the same length as current vector's and all elements are set to input value

a = [-1,-1,1].to_vector
a.set_all! 2 => GSL::Vector: [2.0,2.0,2.0]
a => GSL::Vector: [-1.0,-1.0,1.0]

[View source]
def set_all!(n : Int32 | Float64) : Vector #

set current vector's elements to input value

a = [-1,-1,1].to_vector
a.set_all! 2 => GSL::Vector: [2.0,2.0,2.0]
a => GSL::Vector: [2.0,2.0,2.0]

[View source]
def set_basis(n : Int32) : Vector #

return a new vector with the same length of current vector but all values are zero except the input index

a = [-1,-1,1].to_vector
a.set_basis 2 => GSL::Vector: [0.0,0.0,1.0]
a => GSL::Vector: [-1.0,-1.0,1.0]

[View source]
def set_basis!(n : Int32) : Vector #

set current vector's elements to zero except the input index

a = [-1,-1,1].to_vector
a.set_basis! 2 => GSL::Vector: [0.0,0.0,1.0]
a => GSL::Vector: [0.0,0.0,1.0]

[View source]
def set_zero : Vector #

return a new vector with a length same as current vector but elements are set to zero

a = [-1,-1,1].to_vector
a.set_zero => GSL::Vector: [0.0,0.0,0.0]
a => GSL::Vector: [-1.0,-1.0,1.0]

[View source]
def set_zero! : Vector #

set current vector's elements to zero

a = [-1,-1,1].to_vector
a.set_zero => GSL::Vector: [0.0,0.0,0.0]
a => GSL::Vector: [0.0,0.0,0.0]

[View source]
def size : Int32 #
Description copied from module Indexable(Float64)

Returns the number of elements in this container.


[View source]
def sort : Vector #

return a new vector in ascending order

a = [2,5,3,7,1].to_vector
a.sort => GSL::Vector: [1.0,2.0,3.0,5.0,7.0]
a => GSL::Vector: [2.0,5.0,3.0,7.0,1.0]

[View source]
def sort! : Vector #

change current vector in ascending order

a = [2,5,3,7,1].to_vector
a.sort! => GSL::Vector: [1.0,2.0,3.0,5.0,7.0]
a => GSL::Vector: [1.0,2.0,3.0,5.0,7.0]

[View source]
def sum #
Description copied from module Enumerable(Float64)

Adds all the elements in the collection together.

Expects all element types to respond to #+ method.

[1, 2, 3, 4, 5, 6].sum # => 21

This method calls .additive_identity on the yielded type to determine the type of the sum value.

If the collection is empty, returns additive_identity.

([] of Int32).sum # => 0

[View source]
def tail : Vector #

return the last five elements in vector of current vector

a = [1,2,3,4,5,6,7,8]to_vector
a.tail => GSL::Vector: [2.0,3.0,4.0,5.0,6.0]

[View source]
def to_array : Array(Float64) #

alias to to_a


[View source]
def to_s : String #
Description copied from class Object

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.


[View source]
def to_slice #

[View source]
def to_unsafe #

[View source]
def unsafe_fetch(index : Int) #
Description copied from module Indexable(Float64)

Returns the element at the given index, without doing any bounds check.

Indexable makes sure to invoke this method with index in 0...size, so converting negative indices to positive ones is not needed here.

Clients never invoke this method directly. Instead, they access elements with #[](index) and #[]?(index).

This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.


[View source]
def unsafe_put(index : Int, value : T) #
Description copied from module Indexable::Mutable(Float64)

Sets the element at the given index to value, without doing any bounds check.

Indexable::Mutable makes sure to invoke this method with index in 0...size, so converting negative indices to positive ones is not needed here.

Clients never invoke this method directly. Instead, they modify elements with #[]=(index, value).

This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.


[View source]