class Apatite::Vector(T)
- Apatite::Vector(T)
- Reference
- Object
Overview
Represents a mathematical vector, and also constitutes a row or column
of a Matrix
Included Modules
- Comparable(Apatite::Vector(T))
- Enumerable(T)
- Indexable(T)
Defined in:
apatite/vector.crClass Method Summary
-
.[](*array)
Creates a new vector from a list of elements.
-
.basis(size, index)
Returns a standard basis
n
-vector. -
.elements(array, copy = true)
Creates a vector from an Array.
-
.independent?(*vs)
Returns
true
if all of vectors are linearly independent. -
.zero(size)
Return a zero vector.
Instance Method Summary
-
#*(x : Number)
Multiplies the vector by x, where x is a number.
-
#*(x : Vector)
Multiplies the vector by x, where x is another vector.
-
#*(x : Matrix)
Multiplies the vector by x, where x is a matrix.
-
#+(x : Number)
Vector addition.
-
#+(x : Vector)
Vector addition.
-
#+(x : Matrix)
Vector addition.
-
#-(x : Number)
Vector subtraction.
-
#-(x : Vector)
Vector subtraction.
-
#-(x : Matrix)
Vector subtraction.
-
#/(x : Number)
Vector division.
-
#/(x : Vector)
Vector division.
-
#/(x : Matrix)
Vector division.
-
#<=>(other : Vector | Indexable)
Alien mothership
-
#<=>(other)
Take me to your leader
-
#==(other)
Equality operator
-
#angle_with(v)
Returns an angle with another vector.
-
#clone
Returns a copy of the vector.
-
#coerce(klass : Complex.class, imag : Number)
Attempt to coerce the elements in a vector to Complex with
imag
as the imaginary number. -
#coerce(klass : BigInt.class, base = 10)
Attempt to coerce the elements in a vector to BigInt with an optional
base
value. -
#coerce(klass : BigRational.class, denominator : Int)
Attempt to coerce the elements in a vector to BigRational with the given
denominator
. -
#coerce(klass : U.class) : Vector(U) forall U
The coerce method allows you to attempt to coerce the elements in the matrix to another type.
-
#covector
Creates a single-row matrix from this vector.
-
#cross(v)
ditto
-
#cross_product(*vs)
Returns the cross product of this vector with the others.
-
#dot(v)
ditto
- #each(*args, **options)
-
#each(v, &)
Iterate over the elements of this vector and
v
in conjunction. - #each(*args, **options, &)
-
#inner_product(v)
Returns the inner product of this vector with the other.
-
#inspect
Returns an unambiguous and information-rich string representation of this object, typically intended for developers.
-
#magnitude
Returns the modulus (Pythagorean distance) of the vector.
-
#map(v, &block : T, T -> _)
Maps over the current vector and
v
in conjunction, passing each element in each to the block and returning a new vector -
#map(&block : T -> _)
Maps over a vector, passing each element to the block
-
#norm
ditto
-
#normalize
Returns a new vector with the same direction but with norm 1
-
#r
ditto
-
#round(ndigits = 0)
Returns a vector with entries rounded to the given precision.
-
#size
Returns the number of elements in the vector.
- #size(*args, **options)
- #size(*args, **options, &)
-
#to_a
Returns the elements of the vector in an array.
-
#to_matrix
Return a single-column matrix from this vector.
-
#to_s
Returns a nicely readable and concise string representation of this object, typically intended for users.
-
#unsafe_fetch(index : Int)
Returns the element at the given index, without doing any bounds check.
-
#zero?
Returns
true
if all elements are zero.
Class Method Detail
Creates a vector from an Array. The optional second argument specifies whether the array itself or a copy is used internally.
Returns true
if all of vectors are linearly independent.
Vector.independent?(Vector[1, 0], Vector[0, 1])
# => true
Vector.independent?(Vector[1, 2], Vector[2, 4])
# => false
Instance Method Detail
Attempt to coerce the elements in a vector to Complex with
imag
as the imaginary number.
Attempt to coerce the elements in a vector to BigInt with
an optional base
value.
Attempt to coerce the elements in a vector to BigRational
with the given denominator
.
The coerce method allows you to attempt to coerce the elements in the matrix to another type.
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
.
Maps over the current vector and v
in conjunction, passing each
element in each to the block and returning a new vector
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
.
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.