class Apatite::Vector(T)

Overview

Represents a mathematical vector, and also constitutes a row or column of a Matrix

Included Modules

Defined in:

apatite/vector.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.[](*array) #

Creates a new vector from a list of elements.


[View source]
def self.basis(size, index) #

Returns a standard basis n-vector.


[View source]
def self.elements(array, copy = true) #

Creates a vector from an Array. The optional second argument specifies whether the array itself or a copy is used internally.


[View source]
def self.independent?(*vs) #

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

[View source]
def self.zero(size) #

Return a zero vector.


[View source]

Instance Method Detail

def *(x : Number) #

Multiplies the vector by x, where x is a number.


[View source]
def *(x : Vector) #

Multiplies the vector by x, where x is another vector.


[View source]
def *(x : Matrix) #

Multiplies the vector by x, where x is a matrix.


[View source]
def +(x : Number) #

Vector addition.


[View source]
def +(x : Vector) #

Vector addition.


[View source]
def +(x : Matrix) #

Vector addition.


[View source]
def -(x : Number) #

Vector subtraction.


[View source]
def -(x : Vector) #

Vector subtraction.


[View source]
def -(x : Matrix) #

Vector subtraction.


[View source]
def /(x : Number) #

Vector division.


[View source]
def /(x : Vector) #

Vector division.


[View source]
def /(x : Matrix) #

Vector division.


[View source]
def <=>(other : Vector | Indexable) #

Alien mothership


[View source]
def <=>(other) #

Take me to your leader


[View source]
def ==(other) #

Equality operator


[View source]
def angle_with(v) #

Returns an angle with another vector. Result is within the [0…Math::PI].


[View source]
def clone #

Returns a copy of the vector.


[View source]
def coerce(klass : Complex.class, imag : Number) #

Attempt to coerce the elements in a vector to Complex with imag as the imaginary number.


[View source]
def coerce(klass : BigInt.class, base = 10) #

Attempt to coerce the elements in a vector to BigInt with an optional base value.


[View source]
def coerce(klass : BigRational.class, denominator : Int) #

Attempt to coerce the elements in a vector to BigRational with the given denominator.


[View source]
def 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.


[View source]
def covector #

Creates a single-row matrix from this vector.


[View source]
def cross(v) #

ditto


[View source]
def cross_product(*vs) #

Returns the cross product of this vector with the others.


[View source]
def dot(v) #

ditto


[View source]
def each(*args, **options) #

[View source]
def each(v, &) #

Iterate over the elements of this vector and v in conjunction.


[View source]
def each(*args, **options, &) #

[View source]
def inner_product(v) #

Returns the inner product of this vector with the other.


[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 magnitude #

Returns the modulus (Pythagorean distance) of the vector.


[View source]
def 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


[View source]
def map(&block : T -> _) #

Maps over a vector, passing each element to the block


[View source]
def norm #

ditto


[View source]
def normalize #

Returns a new vector with the same direction but with norm 1


[View source]
def r #

ditto


[View source]
def round(ndigits = 0) #

Returns a vector with entries rounded to the given precision.


[View source]
def size #

Returns the number of elements in the vector.


[View source]
def size(*args, **options) #

[View source]
def size(*args, **options, &) #

[View source]
def to_a #

Returns the elements of the vector in an array.


[View source]
def to_matrix #

Return a single-column matrix from this vector.


[View source]
def to_s #
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 unsafe_fetch(index : Int) #
Description copied from module Indexable(T)

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 zero? #

Returns true if all elements are zero.


[View source]