class Chem::Linalg::Matrix
- Chem::Linalg::Matrix
- Reference
- Object
Overview
A Matrix
is a rectangular array of numbers, arranged in rows and columns.
It behaves similar to an Array
, but items are accessed by two indexes: row and
column. Similar to Array
, array indexing starts at 0. A negative index is assumed
to be relative to the end of the row/column: -1 indicates the last element, -2 is
the second to last element, and so on.
There are several convenience methods to create a Matrix
(see below), but using
the #[]
short-hand method is the most common:
require "chem"
alias M = Chem::Linalg::Matrix # avoid repeating the full name
M[[0, 1, 2], [3, 4, 5]] # => Matrix[[0, 1, 2], [3, 4, 5]]
This partial implementation is heavily based on the original Matrix
code in the
standard library, which was then moved to a shard (currently available at
github.com/Exilor/matrix).
NOTE numbers are internally saved in double precision floating-point format. NOTE: The implementation of some methods may be too slow for big matrices. In such cases, it is suggested to use a specialized library that leverages low-level optimized linear algebra packages such as BLAS/LAPACK
Defined in:
chem/linalg/matrix.crConstructors
- .[](*rows : Indexable(Number)) : self
- .build(rows : Number, columns : Number, &block : Pointer(Float64) -> ) : self
- .column(*values : Number) : self
- .diagonal(size : Int, initial_value : Float64) : self
- .diagonal(size : Int, &block : Int32 -> Number::Primitive) : self
- .diagonal(*values : Number) : self
- .identity(size : Int) : self
- .new(rows : Int32, columns : Int32, initial_value : Float64 | Nil = nil)
- .new(rows : Int32, columns : Int32, &)
- .read(path : Path | String, rows : Number, columns : Number) : self
- .read(io, rows : Number, columns : Number) : self
- .square(size : Int, initial_value : Float64 | Nil = nil) : self
- .square(size : Int, &block : Int32, Int32 -> Number::Primitive) : self
Instance Method Summary
- #*(other : Number) : self
- #*(other : self) : self
- #+(other : Number) : self
- #+(other : self) : self
- #-(other : Number) : self
- #-(other : self) : self
- #/(other : Number) : self
-
#==(other : self) : Bool
Returns
true
if this reference is the same as other. - #[](i : Int, j : Int) : Float64
- #[]=(i : Int, j : Int, value : Float64) : Float64
- #[]?(i : Int, j : Int) : Float64 | Nil
- #columns : Int32
- #det : Float64
- #dim : Tuple(Int32, Int32)
-
#dup : self
Returns a shallow copy of this object.
- #each_with_index : Iterator(Tuple(Float64, Int32, Int32))
- #each_with_index(&block : Float64, Int32, Int32 -> )
- #inspect(io : ::IO)
- #inv : self
- #map(&block : Float64 -> Float64) : self
- #map_with_index(&block : Float64, Int32, Int32, Int32 -> Float64) : self
- #reshape(rows : Int, columns : Int) : self
- #reshape!(rows : Int, columns : Int) : self
- #resize(rows : Int, columns : Int, fill_value : Number = 0) : self
- #resize!(rows : Int, columns : Int, fill_value : Number = 0) : self
- #rows : Int32
- #singular? : Bool
- #size : Int32
- #square? : Bool
- #swap_rows(i1 : Int, i2 : Int) : self
- #to_a : Array(Array(Float64))
- #to_s(io : ::IO)
- #to_unsafe : Pointer(Float64)
- #to_vector : Spatial::Vector
- #unsafe_fetch(i : Int32, j : Int32) : Float64
- #unsafe_fetch(index : Int) : Float64
Constructor Detail
Instance Method Detail
Returns true
if this reference is the same as other. Invokes same?
.
Returns a shallow copy of this object.
This allocates a new object and copies the contents of
self
into it.