diff --git a/README.md b/README.md index 4fc5e86..aa6648d 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Check out the [documentation](https://watzon.github.io/apatite/) for usage examp - [ ] Linear Algebra - [x] Vector - - [ ] Matrix (_in progress_) + - [x] Matrix - [ ] NDArray - [ ] Line - [ ] Plane diff --git a/docs/Apatite.html b/docs/Apatite.html index 8fad5ba..6149fef 100644 --- a/docs/Apatite.html +++ b/docs/Apatite.html @@ -171,28 +171,28 @@ of Crystal.
Creates a single-column matrix where the values of that column are as given in #column
.
Creates a single-column matrix where the values of that column are as given in #column
.
Creates a matrix where the diagonal elements are composed of values
.
Returns element (i
, j
) of the matrix.
Returns row i
of the matrix as an Array.
Returns row i
of the matrix as an Array.
Returns element (i
, j
) of the matrix.
Returns element (i
, j
) of the matrix.
Returns row i
of the matrix as an Array.
Returns row i
of the matrix as an Array.
Returns element (i
, j
) of the matrix.
Returns a block which yields every item in column j
of the Matrix.
Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns a block which yields every item in column j
of the Matrix.
Returns an array of the column vectors of the matrix.
Returns a section of the Matrix.
Returns a section of the Matrix.
Returns an array of the row vectors of the matrix.
Returns an array of arrays that describe the rows of the matrix.
Convert the matrix to a json array
Creates a single-column matrix where the values of that column are as given
-in #column
.
#column
.
Matrix.column_vector([4,5,6])
# => [ 4,
@@ -969,7 +987,7 @@ in View source]
+ [View source]
View source]
+ [View source]
@@ -1014,7 +1032,7 @@ y = Matrix[[1
- [View source]
+ [View source]
@@ -1037,7 +1055,7 @@ y = Matrix[[1
- [View source]
+ [View source]
@@ -1050,10 +1068,17 @@ y = Matrix[[1#
+ Creates a matrix where the diagonal elements are composed of values
.
+
+Matrix.diagonal(9, 5, -3)
+# => [ 9, 0, 0,
+# 0, 5, 0,
+# 0, 0, -3 ]
+
- [View source]
+ [View source]
@@ -1079,7 +1104,7 @@ m * n
- [View source]
+ [View source]
@@ -1102,7 +1127,7 @@ y = Matrix[[5
- [View source]
+ [View source]
@@ -1124,7 +1149,7 @@ y = Matrix[[5
- [View source]
+ [View source]
@@ -1146,7 +1171,7 @@ y = Matrix[[5
- [View source]
+ [View source]
@@ -1170,7 +1195,7 @@ arrays as the internal structure of the matrix without copying.
- [View source]
+ [View source]
@@ -1193,7 +1218,7 @@ arrays as the internal structure of the matrix without copying.
- [View source]
+ [View source]
@@ -1215,7 +1240,7 @@ arrays as the internal structure of the matrix without copying.
- [View source]
+ [View source]
@@ -1238,7 +1263,7 @@ y = Matrix[[5
- [View source]
+ [View source]
@@ -1260,7 +1285,7 @@ y = Matrix[[5
- [View source]
+ [View source]
@@ -1287,7 +1312,7 @@ y = Matrix[[5
- [View source]
+ [View source]
@@ -1312,7 +1337,7 @@ Non integer exponents will be handled by diagonalizing the matrix.
- [View source]
+ [View source]
@@ -1334,7 +1359,7 @@ Non integer exponents will be handled by diagonalizing the matrix.
- [View source]
+ [View source]
@@ -1356,7 +1381,7 @@ Non integer exponents will be handled by diagonalizing the matrix.
- [View source]
+ [View source]
@@ -1378,7 +1403,7 @@ Non integer exponents will be handled by diagonalizing the matrix.
- [View source]
+ [View source]
@@ -1396,26 +1421,7 @@ Non integer exponents will be handled by diagonalizing the matrix.
- [View source]
-
-
-
-
-
-
-
- def [](i, j)
-
- #
-
-
- Returns element (i
, j
) of the matrix. That is: row i
, column j
.
-Raises if either index is not found.
-
-
-
-
- [View source]
+ [View source]
@@ -1434,7 +1440,26 @@ index is not found.
- [View source]
+ [View source]
+
+
+
+
+
+
+
+ def [](i, j)
+
+ #
+
+
+ Returns element (i
, j
) of the matrix. That is: row i
, column j
.
+Raises if either index is not found.
+
+
+
+
+ [View source]
@@ -1452,26 +1477,7 @@ index is not found.
- [View source]
-
-
-
-
-
-
-
- def []?(i, j)
-
- #
-
-
- Returns element (i
, j
) of the matrix. That is: row i
, column j
.
-Returns nil if either index is not found.
-
-
-
-
- [View source]
+ [View source]
@@ -1490,7 +1496,26 @@ index is not found.
- [View source]
+ [View source]
+
+
+
+
+
+
+
+ def []?(i, j)
+
+ #
+
+
+ Returns element (i
, j
) of the matrix. That is: row i
, column j
.
+Returns nil if either index is not found.
+
+
+
+
+ [View source]
@@ -1516,7 +1541,7 @@ index is not found.
- [View source]
+ [View source]
@@ -1537,7 +1562,7 @@ identical objects.
- [View source]
+ [View source]
@@ -1555,7 +1580,7 @@ identical objects.
- [View source]
+ [View source]
@@ -1577,25 +1602,7 @@ the first minor by (-1)**(row + column).
- [View source]
-
-
-
-
-
-
-
- def column(j, &block : T -> )
-
- #
-
-
- Returns a block which yields every item in column j
of the Matrix.
-
-
-
-
- [View source]
+ [View source]
@@ -1614,7 +1621,25 @@ Raises if the column doesn't exist.
- [View source]
+ [View source]
+
+
+
+
+
+
+
+ def column(j, &block : T -> )
+
+ #
+
+
+ Returns a block which yields every item in column j
of the Matrix.
+
+
+
+
+ [View source]
@@ -1633,7 +1658,7 @@ Returns nil if the column doesn't exist.
- [View source]
+ [View source]
@@ -1651,7 +1676,25 @@ Returns nil if the column doesn't exist.
- [View source]
+ [View source]
+
+
+
+
+
+
+
+ def column_vectors
+
+ #
+
+
+ Returns an array of the column vectors of the matrix. See Vector
.
+
+
+
+
+ [View source]
@@ -1674,7 +1717,7 @@ y = Matrix[[1
- [View source]
+ [View source]
@@ -1699,7 +1742,7 @@ y = Matrix[[1
- [View source]
+ [View source]
@@ -1724,7 +1767,7 @@ Consider using exact types like Rational or BigDecimal instead.
- [View source]
+ [View source]
@@ -1742,7 +1785,7 @@ Consider using exact types like Rational or BigDecimal instead.
- [View source]
+ [View source]
@@ -1768,7 +1811,7 @@ Elements can be restricted by passing an argument:
- [View source]
+ [View source]
@@ -1795,7 +1838,7 @@ puts "#{e}
- [View source]
+ [View source]
@@ -1822,7 +1865,7 @@ v.inv == v_inv # => true
- [View source]
+ [View source]
@@ -1840,7 +1883,7 @@ v.inv == v_inv # => true
- [View source]
+ [View source]
@@ -1863,7 +1906,7 @@ v.inv == v_inv # => true
- [View source]
+ [View source]
@@ -1885,7 +1928,7 @@ v.inv == v_inv # => true
- [View source]
+ [View source]
@@ -1903,7 +1946,7 @@ v.inv == v_inv # => true
- [View source]
+ [View source]
@@ -1926,7 +1969,7 @@ x.hstack(y) # => Matrix[[1, 2, 5, 6], [3, 4, 7, 8]]
- [View source]
+ [View source]
@@ -1951,7 +1994,7 @@ x.hstack(y) # => Matrix[[1, 2, 5, 6], [3, 4, 7, 8]]
- [View source]
+ [View source]
@@ -1973,7 +2016,7 @@ It also accepts an optional selector
argument, see View source]
+ [View source]
@@ -1996,7 +2039,7 @@ result. It also accepts an optional selector
argument, see
- [View source]
+ [View source]
@@ -2021,7 +2064,7 @@ back into an Int
, use View source]
+ [View source]
@@ -2045,7 +2088,7 @@ back into an Int
, use View source]
+ [View source]
@@ -2063,7 +2106,7 @@ back into an Int
, use View source]
+ [View source]
@@ -2092,7 +2135,7 @@ a.lup.solve([2, 5]) View source]
+ [View source]
@@ -2111,29 +2154,7 @@ over all elements in the matrix.
- [View source]
-
-
-
-
-
-
-
- def minor(row_range : Range, col_range : Range)
-
- #
-
-
- Returns a section of the Matrix.
-
-Matrix.diagonal(9, 5, -3).minor(0..1, 0..2)
-# => [ 9, 0, 0,
-# 0, 5, 0 ]
-
-
-
-
- [View source]
+ [View source]
@@ -2155,7 +2176,29 @@ over all elements in the matrix.
- [View source]
+ [View source]
+
+
+
+
+
+
+
+ def minor(row_range : Range, col_range : Range)
+
+ #
+
+
+ Returns a section of the Matrix.
+
+Matrix.diagonal(9, 5, -3).minor(0..1, 0..2)
+# => [ 9, 0, 0,
+# 0, 5, 0 ]
+
+
+
+
+ [View source]
@@ -2176,7 +2219,7 @@ over all elements in the matrix.
- [View source]
+ [View source]
@@ -2197,7 +2240,7 @@ over all elements in the matrix.
- [View source]
+ [View source]
@@ -2218,7 +2261,7 @@ over all elements in the matrix.
- [View source]
+ [View source]
@@ -2234,7 +2277,7 @@ over all elements in the matrix.
- [View source]
+ [View source]
@@ -2259,7 +2302,7 @@ Consider using exact types like Rational or BigDecimal instead.
- [View source]
+ [View source]
@@ -2284,7 +2327,7 @@ Consider using exact types like Rational or BigDecimal instead.
- [View source]
+ [View source]
@@ -2307,7 +2350,7 @@ i.e. not Complex
.
- [View source]
+ [View source]
@@ -2329,7 +2372,7 @@ parts of the matrix
- [View source]
+ [View source]
@@ -2347,7 +2390,7 @@ parts of the matrix
- [View source]
+ [View source]
@@ -2366,7 +2409,7 @@ parts of the matrix
- [View source]
+ [View source]
@@ -2384,7 +2427,7 @@ parts of the matrix
- [View source]
+ [View source]
@@ -2403,7 +2446,7 @@ at 0 like a good boy). Raises if the row doesn't exist.
- [View source]
+ [View source]
@@ -2422,7 +2465,7 @@ at 0 like a good boy). Returns nil if the row doesn't exist.
- [View source]
+ [View source]
@@ -2440,7 +2483,25 @@ at 0 like a good boy). Returns nil if the row doesn't exist.
- [View source]
+ [View source]
+
+
+
+
+
+
+
+ def row_vectors
+
+ #
+
+
+ Returns an array of the row vectors of the matrix. See Vector
.
+
+
+
+
+ [View source]
@@ -2458,7 +2519,7 @@ at 0 like a good boy). Returns nil if the row doesn't exist.
- [View source]
+ [View source]
@@ -2476,7 +2537,7 @@ at 0 like a good boy). Returns nil if the row doesn't exist.
- [View source]
+ [View source]
@@ -2494,7 +2555,7 @@ at 0 like a good boy). Returns nil if the row doesn't exist.
- [View source]
+ [View source]
@@ -2512,7 +2573,7 @@ at 0 like a good boy). Returns nil if the row doesn't exist.
- [View source]
+ [View source]
@@ -2531,7 +2592,7 @@ Raises an error if matrix is not square.
- [View source]
+ [View source]
@@ -2557,7 +2618,7 @@ Raises an error if matrix is not square.
- [View source]
+ [View source]
@@ -2570,12 +2631,12 @@ Raises an error if matrix is not square.
#
-
+ Returns an array of arrays that describe the rows of the matrix.
- [View source]
+ [View source]
@@ -2588,10 +2649,12 @@ Raises an error if matrix is not square.
#
+ Convert the matrix to a json array
+
- [View source]
+ [View source]
@@ -2607,7 +2670,7 @@ Raises an error if matrix is not square.
- [View source]
+ [View source]
@@ -2628,7 +2691,7 @@ Raises an error if matrix is not square.
- [View source]
+ [View source]
@@ -2649,7 +2712,7 @@ Raises an error if matrix is not square.
- [View source]
+ [View source]
@@ -2675,7 +2738,7 @@ Raises an error if matrix is not square.
- [View source]
+ [View source]
@@ -2693,7 +2756,7 @@ Raises an error if matrix is not square.
- [View source]
+ [View source]
@@ -2709,7 +2772,7 @@ Raises an error if matrix is not square.
- [View source]
+ [View source]
@@ -2727,7 +2790,7 @@ Raises an error if matrix is not square.
- [View source]
+ [View source]
@@ -2751,7 +2814,7 @@ x.vstack(y)
- [View source]
+ [View source]
@@ -2769,7 +2832,7 @@ x.vstack(y)
- [View source]
+ [View source]
diff --git a/docs/Apatite/LinearAlgebra/Matrix/EigenvalueDecomposition.html b/docs/Apatite/LinearAlgebra/Matrix/EigenvalueDecomposition.html
index bcf158b..2ab0f88 100644
--- a/docs/Apatite/LinearAlgebra/Matrix/EigenvalueDecomposition.html
+++ b/docs/Apatite/LinearAlgebra/Matrix/EigenvalueDecomposition.html
@@ -163,7 +163,7 @@ equal to the eigenvalues and V is formed by the eigenvectors.
Defined in:
-
+
apatite/linear_algebra/matrix/eigenvalue_decomposition.cr
@@ -230,7 +230,7 @@ equal to the eigenvalues and V is formed by the eigenvectors.
- [View source]
+ [View source]
diff --git a/docs/Apatite/LinearAlgebra/Matrix/LupDecomposition.html b/docs/Apatite/LinearAlgebra/Matrix/LupDecomposition.html
index efba0ca..7002e18 100644
--- a/docs/Apatite/LinearAlgebra/Matrix/LupDecomposition.html
+++ b/docs/Apatite/LinearAlgebra/Matrix/LupDecomposition.html
@@ -163,7 +163,7 @@ linear equations. This will fail if singular? returns true.
Defined in:
-
+
apatite/linear_algebra/matrix/lup_decomposition.cr
@@ -230,7 +230,7 @@ linear equations. This will fail if singular? returns true.
- [View source]
+ [View source]
diff --git a/docs/Apatite/LinearAlgebra/NDArray.html b/docs/Apatite/LinearAlgebra/NDArray.html
index 673d6c5..2276436 100644
--- a/docs/Apatite/LinearAlgebra/NDArray.html
+++ b/docs/Apatite/LinearAlgebra/NDArray.html
@@ -162,7 +162,7 @@
Defined in:
-
+
apatite/linear_algebra/ndarray.cr
@@ -363,7 +363,7 @@
- [View source]
+ [View source]
@@ -386,7 +386,7 @@
- [View source]
+ [View source]
@@ -402,7 +402,7 @@
- [View source]
+ [View source]
@@ -418,7 +418,7 @@
- [View source]
+ [View source]
@@ -434,7 +434,7 @@
- [View source]
+ [View source]
@@ -450,7 +450,7 @@
- [View source]
+ [View source]
@@ -468,7 +468,7 @@
- [View source]
+ [View source]
@@ -486,7 +486,7 @@
- [View source]
+ [View source]
@@ -502,7 +502,7 @@
- [View source]
+ [View source]
@@ -518,7 +518,7 @@
- [View source]
+ [View source]
@@ -534,7 +534,7 @@
- [View source]
+ [View source]
@@ -550,7 +550,7 @@
- [View source]
+ [View source]
@@ -566,7 +566,7 @@
- [View source]
+ [View source]
@@ -582,7 +582,7 @@
- [View source]
+ [View source]
@@ -598,7 +598,7 @@
- [View source]
+ [View source]
@@ -614,7 +614,7 @@
- [View source]
+ [View source]
diff --git a/docs/Apatite/LinearAlgebra/Vector.html b/docs/Apatite/LinearAlgebra/Vector.html
index 23c1336..c077ce8 100644
--- a/docs/Apatite/LinearAlgebra/Vector.html
+++ b/docs/Apatite/LinearAlgebra/Vector.html
@@ -167,7 +167,7 @@ of a Matrix
Defined in:
-
+
apatite/linear_algebra/vector.cr
@@ -505,7 +505,7 @@ of a Matrix
- [View source]
+ [View source]
@@ -523,7 +523,7 @@ of a Matrix
- [View source]
+ [View source]
@@ -542,7 +542,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -560,7 +560,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -583,7 +583,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -601,7 +601,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -619,7 +619,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -637,7 +637,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -655,7 +655,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -673,7 +673,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -691,7 +691,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -709,7 +709,7 @@ whether the array itself or a copy is used internally.
- [View source]
+ [View source]
@@ -728,7 +728,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -746,7 +746,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -764,7 +764,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -782,7 +782,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -798,7 +798,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -814,7 +814,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -832,7 +832,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -850,7 +850,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -866,7 +866,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -884,7 +884,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -900,7 +900,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -916,7 +916,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -934,7 +934,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -952,7 +952,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -970,7 +970,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -988,7 +988,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -1006,7 +1006,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -1024,7 +1024,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -1040,7 +1040,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -1056,7 +1056,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
@@ -1074,7 +1074,7 @@ in the matrix to another type. The type
- [View source]
+ [View source]
diff --git a/docs/Apatite/LinearAlgebra/ZeroVectorError.html b/docs/Apatite/LinearAlgebra/ZeroVectorError.html
index dbf9267..50e4ec0 100644
--- a/docs/Apatite/LinearAlgebra/ZeroVectorError.html
+++ b/docs/Apatite/LinearAlgebra/ZeroVectorError.html
@@ -151,7 +151,7 @@
Defined in:
-
+
apatite/linear_algebra/error.cr
diff --git a/docs/Array.html b/docs/Array.html
index 785d0f7..10bf84f 100644
--- a/docs/Array.html
+++ b/docs/Array.html
@@ -200,7 +200,7 @@ set << 3
Defined in:
-
+
apatite/core_ext/array.cr
@@ -334,7 +334,7 @@ set << 3
- [View source]
+ [View source]
@@ -352,7 +352,7 @@ set << 3
- [View source]
+ [View source]
@@ -370,7 +370,7 @@ set << 3
- [View source]
+ [View source]
@@ -386,7 +386,7 @@ set << 3
Apatite is a fundimental package for scientific computing in Crystal.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","path":"Apatite/LinearAlgebra.html","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"},{"filename":"apatite/linear_algebra/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr"},{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr"},{"filename":"apatite/linear_algebra.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra.cr"},{"filename":"apatite/linear_algebra/ndarray.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"}],"subclasses":[],"including_types":[{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"}],"namespace":{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"sigmoid(input:Number)-instance-method","html_id":"sigmoid(input:Number)-instance-method","name":"sigmoid","doc":"Calculates the sigmoid curve for a numeric input.\n\n`f(x) = 1/(1 + e^-x)`\n\nSee also: [Sigmoid function (WikiWand)](https://www.wikiwand.com/en/Sigmoid_function)","summary":"Calculates the sigmoid curve for a numeric input.
","abstract":false,"args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"args_string":"(input : Number)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra.cr#L15","def":{"name":"sigmoid","args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = input.to_f64\n1 / (1 + (Math.exp(-num)))\n"}},{"id":"sigmoid_d(input:Number)-instance-method","html_id":"sigmoid_d(input:Number)-instance-method","name":"sigmoid_d","doc":"Calculates the derivative sigmoid curve for a numeric input.\n\n`f'(x) = f(x)(1 - f(x)),`","summary":"Calculates the derivative sigmoid curve for a numeric input.
","abstract":false,"args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"args_string":"(input : Number)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra.cr#L23","def":{"name":"sigmoid_d","args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = input.to_f64\nnum * (1 - num)\n"}}],"macros":[],"types":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrDimensionMismatch","path":"Apatite/LinearAlgebra/ErrDimensionMismatch.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrDimensionMismatch","name":"ErrDimensionMismatch","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrNotRegular","path":"Apatite/LinearAlgebra/ErrNotRegular.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrNotRegular","name":"ErrNotRegular","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrOperationNotDefined","path":"Apatite/LinearAlgebra/ErrOperationNotDefined.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrOperationNotDefined","name":"ErrOperationNotDefined","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":8,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(method,this,other)-class-method","html_id":"new(method,this,other)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"method","doc":null,"default_value":"","external_name":"method","restriction":""},{"name":"this","doc":null,"default_value":"","external_name":"this","restriction":""},{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(method, this, other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr#L9","def":{"name":"new","args":[{"name":"method","doc":null,"default_value":"","external_name":"method","restriction":""},{"name":"this","doc":null,"default_value":"","external_name":"this","restriction":""},{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(method, this, other)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","path":"Apatite/LinearAlgebra/Error.html","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":3,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrDimensionMismatch","kind":"class","full_name":"Apatite::LinearAlgebra::ErrDimensionMismatch","name":"ErrDimensionMismatch"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrNotRegular","kind":"class","full_name":"Apatite::LinearAlgebra::ErrNotRegular","name":"ErrNotRegular"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrOperationNotDefined","kind":"class","full_name":"Apatite::LinearAlgebra::ErrOperationNotDefined","name":"ErrOperationNotDefined"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ZeroVectorError","kind":"class","full_name":"Apatite::LinearAlgebra::ZeroVectorError","name":"ZeroVectorError"}],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix","path":"Apatite/LinearAlgebra/Matrix.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix(T)","name":"Matrix","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"SELECTORS","name":"SELECTORS","value":"{all: true, diagonal: true, off_diagonal: true, lower: true, strict_lower: true, strict_upper: true, upper: true}","doc":null,"summary":null}],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[{"id":"[](*rows)-class-method","html_id":"[](*rows)-class-method","name":"[]","doc":"Creates a matrix where each argument is a row.\n\n```\nMatrix[[25, 93], [-1, 66]]\n# => [ 25, 93,\n# -1, 66 ]\n```","summary":"Creates a matrix where each argument is a row.
","abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"args_string":"(*rows)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L21","def":{"name":"[]","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows(rows, false)"}},{"id":"build(row_count,column_count=row_count,&block:Int32,Int32->T)-class-method","html_id":"build(row_count,column_count=row_count,&block:Int32,Int32->T)-class-method","name":"build","doc":"Creates a matrix of size +row_count+ x +column_count+.\nIt fills the values by calling the given block,\npassing the current row and column.\nReturns an enumerator if no block is given.\n\n```\nm = Matrix.build(2, 4) { |row, col| col - row }\n# => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]\nm = Matrix.build(3) { rand }\n# => a 3x3 matrix with random elements\n```","summary":"Creates a matrix of size +row_count+ x +column_count+.
","abstract":false,"args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"args_string":"(row_count, column_count = row_count, &block : Int32, Int32 -> T)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L70","def":{"name":"build","args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"double_splat":null,"splat_index":null,"yields":2,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(Int32, Int32 -> T)"},"return_type":"","visibility":"Public","body":"row_count = row_count.to_i\ncolumn_count = column_count.to_i\nif row_count < 0 || column_count < 0\n raise(ArgumentError.new)\nend\nrows = Array(T).new(row_count) do |i|\n Array(T).new(column_count) do |j|\n yield i, j\n end\nend\nnew(rows, column_count)\n"}},{"id":"column_vector(column)-class-method","html_id":"column_vector(column)-class-method","name":"column_vector","doc":"Creates a single-column matrix where the values of that column are as given\nin `column`.\n\n```\nMatrix.column_vector([4,5,6])\n# => [ 4,\n# 5,\n# 6 ]\n```","summary":"Creates a single-column matrix where the values of that column are as given in #column
.
Creates a matrix using +columns+ as an array of column vectors.
","abstract":false,"args":[{"name":"columns","doc":null,"default_value":"","external_name":"columns","restriction":""}],"args_string":"(columns)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L55","def":{"name":"columns","args":[{"name":"columns","doc":null,"default_value":"","external_name":"columns","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(rows(columns, false)).transpose"}},{"id":"combine(*matrices,&block)-class-method","html_id":"combine(*matrices,&block)-class-method","name":"combine","doc":"Create a matrix by combining matrices entrywise, using the given block\n\n```\nx = Matrix[[6, 6], [4, 4]]\ny = Matrix[[1, 2], [3, 4]]\nMatrix.combine(x, y) {|a, b| a - b}\n# => Matrix[[5, 4], [1, 0]]\n```","summary":"Create a matrix by combining matrices entrywise, using the given block
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L245","def":{"name":"combine","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"if matrices.empty?\n return Matrix.empty\nend\nmatrices = matrices.map do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\nend\nx = matrices.first\nmatrices.each do |m|\n if (x.row_count == m.row_count) && (x.column_count == m.column_count)\n else\n raise(ErrDimensionMismatch.new)\n end\nend\nrows = Array(T).new(x.row_count) do |i|\n Array(T).new(x.column_count) do |j|\n yield matrices.map do |m|\n m[i, j]\n end\n end\nend\nnew(rows, x.column_count)\n"}},{"id":"diagonal(values:Indexable(T),dummy=nil)-class-method","html_id":"diagonal(values:Indexable(T),dummy=nil)-class-method","name":"diagonal","doc":"Creates a matrix where the diagonal elements are composed of `values`.\n\n```\nMatrix.diagonal(9, 5, -3)\n# => [ 9, 0, 0,\n# 0, 5, 0,\n# 0, 0, -3 ]\n```","summary":"Creates a matrix where the diagonal elements are composed of values
.
Creates a empty matrix of #row_count
x #column_count
.
Create a matrix by stacking matrices horizontally
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(x, *matrices)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L217","def":{"name":"hstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"result = x.rows\ntotal_column_count = x.column_count\nmatrices.each do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\n if m.row_count != x.row_count\n raise(ErrDimensionMismatch.new(\"The given matrices must have #{x.row_count} rows, but one has #{m.row_count}\"))\n end\n result.each_with_index do |row, i|\n row.concat(m.rows[i])\n end\n total_column_count = total_column_count + m.column_count\nend\nnew(result, total_column_count)\n"}},{"id":"identity(n)-class-method","html_id":"identity(n)-class-method","name":"identity","doc":"Creates an `n` by `n` identity matrix.\n\n```\nMatrix.identity(2)\n# => [ 1, 0,\n# 0, 1 ]\n```","summary":"Creates an n
by n
identity matrix.
Creates a single-row matrix where the values of that row are as given in #row
.
Creates a matrix where +rows+ is an array of arrays, each of which is a row of the matrix.
","abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Array(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(rows : Indexable(Array(T)), copy = true)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L34","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Array(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if copy\n rows = rows.dup\nend\nrows = rows.to_a\nrows.map! do |row|\n if row\n row = row.dup\n end\n row.to_a\nend\nsize = (rows[0] || ([] of T)).size\nrows.each_with_index do |row, i|\n if row.size == size\n else\n raise(ErrDimensionMismatch.new(\"row size differs (row at index `#{i}` should contain #{size} elements, instead has #{row.size})\"))\n end\nend\nnew(rows, size)\n"}},{"id":"scalar(n,value:T)-class-method","html_id":"scalar(n,value:T)-class-method","name":"scalar","doc":"Creates an +n+ by +n+ diagonal matrix where each diagonal element is\n`value`.\n\n```\nMatrix.scalar(2, 5)\n# => [ 5, 0,\n# 0, 5 ]\n```","summary":"Creates an +n+ by +n+ diagonal matrix where each diagonal element is value
.
Creates an n
by n
identity matrix.
Create a matrix by stacking matrices vertically
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(x, *matrices)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L197","def":{"name":"vstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"result = x.rows\nmatrices.each do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\n if m.column_count != x.column_count\n raise(ErrDimensionMismatch.new(\"The given matrices must have #{x.column_count} columns, but one has #{m.column_count}\"))\n end\n result.concat(m.rows)\nend\nnew(result, x.column_count)\n"}},{"id":"zero(row_count,column_count=row_count)-class-method","html_id":"zero(row_count,column_count=row_count)-class-method","name":"zero","doc":"Creates a zero matrix.\n\n```\nMatrix.zero(2)\n# => [ 0, 0,\n# 0, 0 ]\n```","summary":"Creates a zero matrix.
","abstract":false,"args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"args_string":"(row_count, column_count = row_count)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L140","def":{"name":"zero","args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = Array(T).new(row_count) do\n Array(T).new(column_count, T.new(0))\nend\nnew(rows, column_count)\n"}}],"constructors":[],"instance_methods":[{"id":"*(other)-instance-method","html_id":"*(other)-instance-method","name":"*","doc":"Matrix multiplication\n\n```\nMatrix[[2,4], [6,8]] * Matrix.identity(2)\n# => [ 2, 4,\n# 6, 8 ]\n```","summary":"Matrix multiplication
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L891","def":{"name":"*","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Number\n rows = @rows.map do |row|\n row.map do |e|\n (e * other).as(T)\n end\n end\n Matrix.new(rows, column_count)\nwhen Vector\n m = Matrix.column_vector(other)\n r = self * m\n r.column(0)\nwhen Matrix\n if column_count != other.column_count\n raise(ErrDimensionMismatch.new)\n end\n rows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (0...column_count).reduce(0) do |vij, k|\n vij + (self[i, k] * other[k, j])\n end\n end\n end\n Matrix.new(rows, column_count)\nelse\n self * (Matrix.rows(other))\nend"}},{"id":"**(other)-instance-method","html_id":"**(other)-instance-method","name":"**","doc":"Matrix exponentiation.\n\nEquivalent to multiplying the matrix by itself N times.\nNon integer exponents will be handled by diagonalizing the matrix.\n\n```\nMatrix[[7,6], [3,9]] ** 2\n# => [ 67, 96,\n# 48, 99 ]\n```","summary":"Matrix exponentiation.
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1061","def":{"name":"**","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"+(other:Matrix|Indexable)-instance-method","html_id":"+(other:Matrix|Indexable)-instance-method","name":"+","doc":"Matrix addition\n\n```\nMatrix.scalar(2,5) + Matrix[[1,0], [-4,7]]\n# => [ 6, 0,\n# -4, 1 ]\n```","summary":"Matrix addition
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"args_string":"(other : Matrix | Indexable)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L924","def":{"name":"+","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n other = Matrix.column_vector(other)\nwhen Matrix\nelse\n other = Matrix.rows(other)\nend\nif (row_count == other.row_count) && (column_count == other.column_count)\nelse\n raise(ErrDimensionMismatch.new)\nend\nrows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (self[i, j] + other[i, j]).as(T)\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"-(other:Matrix|Indexable)-instance-method","html_id":"-(other:Matrix|Indexable)-instance-method","name":"-","doc":"Matrix subtraction\n\n```\nMatrix[[1,5], [4,2]] - Matrix[[9,3], [-4,1]]\n# => [-8, 2,\n# 8, 1 ]\n```","summary":"Matrix subtraction
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"args_string":"(other : Matrix | Indexable)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L951","def":{"name":"-","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n other = Matrix.column_vector(other)\nwhen Matrix\nelse\n other = Matrix.rows(other)\nend\nif (row_count == other.row_count) && (column_count == other.column_count)\nelse\n raise(ErrDimensionMismatch.new)\nend\nrows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (self[i, j] - other[i, j]).as(T)\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"/(other)-instance-method","html_id":"/(other)-instance-method","name":"/","doc":"Matrix division (multiplication by the inverse).\n\n```\nMatrix[[7,6], [3,9]] / Matrix[[2,9], [3,1]]\n# => [ -7, 1,\n# -3, -6 ]\n```","summary":"Matrix division (multiplication by the inverse).
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L978","def":{"name":"/","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Number\n rows = @rows.map do |row|\n row.map do |e|\n (e / other).as(T)\n end\n end\n return Matrix.new(rows, column_count)\nwhen Matrix\n return self * other.inverse\nelse\n self / (Matrix.rows(other))\nend"}},{"id":"==(other:Matrix)-instance-method","html_id":"==(other:Matrix)-instance-method","name":"==","doc":"Equality operator","summary":"Equality operator
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix"}],"args_string":"(other : Matrix)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L868","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(rows == other.rows) && (column_count == other.column_count)"}},{"id":"[](i,j)-instance-method","html_id":"[](i,j)-instance-method","name":"[]","doc":"Returns element (`i`, `j`) of the matrix. That is: row `i`, column `j`.\nRaises if either index is not found.","summary":"Returns element (i
, j
) of the matrix.
Returns row i
of the matrix as an Array.
Set the value at index (i
, j
).
Returns element (i
, j
) of the matrix.
Returns row i
of the matrix as an Array.
Returns the adjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L626","def":{"name":"adjugate","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nMatrix.build(row_count, column_count) do |row, column|\n cofactor(column, row)\nend\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":"Returns a clone of the matrix, so that the contents of each do not reference\nidentical objects.\n\nThere should be no good reason to do this since Matrices are immutable.","summary":"Returns a clone of the matrix, so that the contents of each do not reference identical objects.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L876","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.new(@rows.map(&.dup), column_count)"}},{"id":"coerce(klass)-instance-method","html_id":"coerce(klass)-instance-method","name":"coerce","doc":"Attempt to coerce the elements in the matrix to another type.","summary":"Attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""}],"args_string":"(klass)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1365","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rws = @rows.map do |r|\n r.map do |i|\n klass.new(i)\n end\nend\nMatrix.rows(rws)\n"}},{"id":"cofactor(row,column)-instance-method","html_id":"cofactor(row,column)-instance-method","name":"cofactor","doc":"Returns the (row, column) cofactor which is obtained by multiplying\nthe first minor by (-1)**(row + column).\n\n```\nMatrix.diagonal(9, 5, -3, 4).cofactor(1, 1)\n# => -108\n```","summary":"Returns the (row, column) cofactor which is obtained by multiplying the first minor by (-1)**(row + column).
","abstract":false,"args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(row, column)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L612","def":{"name":"cofactor","args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n raise(\"cofactor of empty matrix is not defined\")\nend\nif square?\nelse\n raise(ErrDimensionMismatch.new)\nend\ndet_of_minor = (first_minor(row, column)).determinant\ndet_of_minor * ((-1) ** (row + column))\n"}},{"id":"column(j,&block:T->)-instance-method","html_id":"column(j,&block:T->)-instance-method","name":"column","doc":"Returns a block which yields every item in column `j` of the Matrix.","summary":"Returns a block which yields every item in column j
of the Matrix.
Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns the number of columns.
","abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L314","def":{"name":"column_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@column_count"}},{"id":"combine(*matrices,&block)-instance-method","html_id":"combine(*matrices,&block)-instance-method","name":"combine","doc":"Create a matrix by combining matrices entrywise, using the given block\n\n```\nx = Matrix[[6, 6], [4, 4]]\ny = Matrix[[1, 2], [3, 4]]\nMatrix.combine(x, y) {|a, b| a - b}\n# => Matrix[[5, 4], [1, 0]]\n```","summary":"Create a matrix by combining matrices entrywise, using the given block
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L264","def":{"name":"combine","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"return_type":"","visibility":"Public","body":"Matrix.combine(self, *matrices, &block)"}},{"id":"conj-instance-method","html_id":"conj-instance-method","name":"conj","doc":"Returns the conjugate of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => 1+2i i 0\n# 1 2 3\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].conj\n# => 1-2i -i 0\n# 1 2 3\n```","summary":"Returns the conjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1313","def":{"name":"conj","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#conj only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.conj)\n"}},{"id":"determinant-instance-method","html_id":"determinant-instance-method","name":"determinant","doc":"Returns the determinant of the matrix.\n\nBeware that using Float values can yield erroneous results\nbecause of their lack of precision.\nConsider using exact types like Rational or BigDecimal instead.\n\n```\nMatrix[[7,6], [3,9]].determinant\n# => 45\n```","summary":"Returns the determinant of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1079","def":{"name":"determinant","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nm = rows\ncase row_count\nwhen 0\n +1\nwhen 1\n +m[0][0]\nwhen 2\n ((+m[0][0]) * m[1][1]) - (m[0][1] * m[1][0])\nwhen 3\n m0, m1, m2 = m\n (((((((+m0[0]) * m1[1]) * m2[2]) - ((m0[0] * m1[2]) * m2[1])) - ((m0[1] * m1[0]) * m2[2])) + ((m0[1] * m1[2]) * m2[0])) + ((m0[2] * m1[0]) * m2[1])) - ((m0[2] * m1[1]) * m2[0])\nwhen 4\n m0, m1, m2, m3 = m\n ((((((((((((((((((((((((((+m0[0]) * m1[1]) * m2[2]) * m3[3]) - (((m0[0] * m1[1]) * m2[3]) * m3[2])) - (((m0[0] * m1[2]) * m2[1]) * m3[3])) + (((m0[0] * m1[2]) * m2[3]) * m3[1])) + (((m0[0] * m1[3]) * m2[1]) * m3[2])) - (((m0[0] * m1[3]) * m2[2]) * m3[1])) - (((m0[1] * m1[0]) * m2[2]) * m3[3])) + (((m0[1] * m1[0]) * m2[3]) * m3[2])) + (((m0[1] * m1[2]) * m2[0]) * m3[3])) - (((m0[1] * m1[2]) * m2[3]) * m3[0])) - (((m0[1] * m1[3]) * m2[0]) * m3[2])) + (((m0[1] * m1[3]) * m2[2]) * m3[0])) + (((m0[2] * m1[0]) * m2[1]) * m3[3])) - (((m0[2] * m1[0]) * m2[3]) * m3[1])) - (((m0[2] * m1[1]) * m2[0]) * m3[3])) + (((m0[2] * m1[1]) * m2[3]) * m3[0])) + (((m0[2] * m1[3]) * m2[0]) * m3[1])) - (((m0[2] * m1[3]) * m2[1]) * m3[0])) - (((m0[3] * m1[0]) * m2[1]) * m3[2])) + (((m0[3] * m1[0]) * m2[2]) * m3[1])) + (((m0[3] * m1[1]) * m2[0]) * m3[2])) - (((m0[3] * m1[1]) * m2[2]) * m3[0])) - (((m0[3] * m1[2]) * m2[0]) * m3[1])) + (((m0[3] * m1[2]) * m2[1]) * m3[0])\nelse\n determinant_bareiss\nend\n"}},{"id":"diagonal?-instance-method","html_id":"diagonal?-instance-method","name":"diagonal?","doc":"Returns `true` if this is a diagonal matrix.\n","summary":"Returns true
if this is a diagonal matrix.
Yields all elements of the matrix, starting with those of the first row, or returns an Enumerator if no block given.
","abstract":false,"args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"args_string":"(which = :all, &block : T -> )","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L380","def":{"name":"each","args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> )"},"return_type":"","visibility":"Public","body":"last = column_count\ncase which.to_s\nwhen \"all\"\n @rows.each do |row|\n row.each(&block)\n end\nwhen \"diagonal\"\n @rows.each_with_index do |row, row_index|\n yield row.fetch(row_index) do\n return self\n end\n end\nwhen \"off_diagonal\"\n @rows.each_with_index do |row, row_index|\n column_count.times do |col_index|\n if row_index == col_index\n else\n yield row[col_index]\n end\n end\n end\nwhen \"lower\"\n @rows.each_with_index do |row, row_index|\n 0.upto([row_index, last].min) do |col_index|\n yield row[col_index]\n end\n end\nwhen \"strict_lower\"\n @rows.each_with_index do |row, row_index|\n [row_index, column_count].min.times do |col_index|\n yield row[col_index]\n end\n end\nwhen \"strict_upper\"\n @rows.each_with_index do |row, row_index|\n (row_index + 1).upto(last - 1) do |col_index|\n yield row[col_index]\n end\n end\nwhen \"upper\"\n @rows.each_with_index do |row, row_index|\n row_index.upto(last - 1) do |col_index|\n yield row[col_index]\n end\n end\nelse\n raise(ArgumentError.new(\"expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper\"))\nend\n"}},{"id":"each_with_index(which=:all,&block:T,Int32,Int32->)-instance-method","html_id":"each_with_index(which=:all,&block:T,Int32,Int32->)-instance-method","name":"each_with_index","doc":"Same as #each, but the row index and column index in addition to the element\n\n```\nMatrix[ [1,2], [3,4] ].each_with_index do |e, row, col|\nputs \"#{e} at #{row}, #{col}\"\nend\n# => Prints:\n# 1 at 0, 0\n# 2 at 0, 1\n# 3 at 1, 0\n# 4 at 1, 1\n```","summary":"Same as #each, but the row index and column index in addition to the element
","abstract":false,"args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"args_string":"(which = :all, &block : T, Int32, Int32 -> )","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L438","def":{"name":"each_with_index","args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"double_splat":null,"splat_index":null,"yields":3,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T, Int32, Int32 -> )"},"return_type":"","visibility":"Public","body":"last = column_count\ncase which.to_s\nwhen \"all\"\n @rows.each_with_index do |row, row_index|\n row.each_with_index do |e, col_index|\n block.call(e, row_index, col_index)\n end\n end\nwhen \"diagonal\"\n @rows.each_with_index do |row, row_index|\n block.call(row.fetch(row_index) do\n return self\n end, row_index, row_index)\n end\nwhen \"off_diagonal\"\n @rows.each_with_index do |row, row_index|\n column_count.times do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"lower\"\n @rows.each_with_index do |row, row_index|\n 0.upto([row_index, last].min) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"strict_lower\"\n @rows.each_with_index do |row, row_index|\n [row_index, column_count].min.times do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"strict_upper\"\n @rows.each_with_index do |row, row_index|\n (row_index + 1).upto(last - 1) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"upper\"\n @rows.each_with_index do |row, row_index|\n row_index.upto(last - 1) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nelse\n raise(ArgumentError.new(\"expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper\"))\nend\n"}},{"id":"eigensystem-instance-method","html_id":"eigensystem-instance-method","name":"eigensystem","doc":"Returns the Eigensystem of the matrix\nSee `EigenvalueDecomposition`.\n\nNOTE: Not working yet\n\n```\nm = Matrix[[1, 2], [3, 4]]\nv, d, v_inv = m.eigensystem\nd.diagonal? # => true\nv.inv == v_inv # => true\n(v * d * v_inv).round(5) == m # => true\n```","summary":"Returns the Eigensystem of the matrix See EigenvalueDecomposition
.
Returns true if this matrix is empty.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L705","def":{"name":"empty?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(column_count == 0) || (row_count == 0)"}},{"id":"first_minor(row,column)-instance-method","html_id":"first_minor(row,column)-instance-method","name":"first_minor","doc":"Returns the submatrix obtained by deleting the specified row and column.\n\n```\nMatrix.diagonal(9, 5, -3, 4).first_minor(1, 2)\n# => [ 9, 0, 0,\n# 0, 0, 0,\n# 0, 0, 4 ]\n```","summary":"Returns the submatrix obtained by deleting the specified row and column.
","abstract":false,"args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(row, column)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L585","def":{"name":"first_minor","args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n raise(\"first_minor of empty matrix is not defined\")\nend\nif 0 <= row && row < row_count\nelse\n raise(ArgumentError.new(\"invalid row (#{row.inspect} for 0..#{row_count - 1})\"))\nend\nif 0 <= column && column < column_count\nelse\n raise(ArgumentError.new(\"invalid column (#{column.inspect} for 0..#{column_count - 1})\"))\nend\narrays = to_a\narrays.delete_at(row)\narrays.each do |array|\n array.delete_at(column)\nend\nMatrix.new(arrays, column_count - 1)\n"}},{"id":"hadamard_product(m)-instance-method","html_id":"hadamard_product(m)-instance-method","name":"hadamard_product","doc":"Hadamard product\n\n```\nMatrix[[1,2], [3,4]].hadamard_product Matrix[[1,2], [3,2]]\n# => [ 1, 4,\n# 9, 8 ]\n```","summary":"Hadamard product
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":""}],"args_string":"(m)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L999","def":{"name":"hadamard_product","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"combine(m) do |a, b|\n a * b\nend"}},{"id":"hermitian?-instance-method","html_id":"hermitian?-instance-method","name":"hermitian?","doc":"Returns `true` if this is an hermitian matrix.","summary":"Returns true
if this is an hermitian matrix.
Returns a new matrix resulting by stacking horizontally the receiver with the given matrices
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1161","def":{"name":"hstack","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.hstack(self, *matrices)"}},{"id":"imag-instance-method","html_id":"imag-instance-method","name":"imag","doc":"Returns the imaginary part of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => [ 1+2i, i, 0,\n# 1, 2, 3 ]\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].imag\n# => [ 2i, i, 0,\n# 0, 0, 0 ]\n```","summary":"Returns the imaginary part of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1328","def":{"name":"imag","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#imag only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.imag)\n"}},{"id":"index(i,selector=:all)-instance-method","html_id":"index(i,selector=:all)-instance-method","name":"index","doc":"The index method is specialized to return the index as {row, column}\nIt also accepts an optional `selector` argument, see `#each` for details.\n\n```\nMatrix[ [1,1], [1,1] ].index(1, :strict_lower)\n# => {1, 0}\n```","summary":"The index method is specialized to return the index as {row, column} It also accepts an optional selector
argument, see #each
for details.
Returns the index as {row, column}, using &block
to filter the result.
Returns the inverse of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1013","def":{"name":"inverse","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nlast = row_count - 1\na = self.coerce(Float64)\nm = Matrix(Float64).identity(row_count)\n0.upto(last) do |k|\n i = k\n akk = a[k, k].abs\n (k + 1).upto(last) do |j|\n v = a[j, k].abs\n if v > akk\n i = j\n akk = v\n end\n end\n if akk == 0\n raise(ErrNotRegular.new)\n end\n if i != k\n a.swap_rows(i, k)\n m.swap_rows(i, k)\n end\n akk = a[k, k]\n 0.upto(last) do |ii|\n if ii == k\n next\n end\n q = a[ii, k] / akk\n a[ii, k] = 0.0\n (k + 1).upto(last) do |j|\n __temp_24 = ii\n __temp_25 = j\n a[__temp_24, __temp_25] = a[__temp_24, __temp_25] - (a[k, j] * q)\n end\n 0.upto(last) do |j|\n __temp_27 = ii\n __temp_28 = j\n m[__temp_27, __temp_28] = m[__temp_27, __temp_28] - (m[k, j] * q)\n end\n end\n (k + 1).upto(last) do |j|\n a[k, j] = a[k, j] / akk\n end\n 0.upto(last) do |j|\n m[k, j] = m[k, j] / akk\n end\nend\nm\n"}},{"id":"laplace_expansion(*,row=nil,column=nil)-instance-method","html_id":"laplace_expansion(*,row=nil,column=nil)-instance-method","name":"laplace_expansion","doc":"Returns the Laplace expansion along given row or column.\n\n```\nMatrix[[7,6], [3,9]].laplace_expansion(column: 1)\n# => 45\n\nMatrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0)\n# => Vector[3, -2]\n```","summary":"Returns the Laplace expansion along given row or column.
","abstract":false,"args":[{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"row","doc":null,"default_value":"nil","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"nil","external_name":"column","restriction":""}],"args_string":"(*, row = nil, column = nil)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L642","def":{"name":"laplace_expansion","args":[{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"row","doc":null,"default_value":"nil","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"nil","external_name":"column","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = row || column\nif (!num) || (row && column)\n raise(ArgumentError.new(\"exactly one the row or column arguments must be specified\"))\nend\nif square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nif empty?\n raise(\"laplace_expansion of empty matrix is not defined\")\nend\nif 0 <= num && num < row_count\nelse\n raise(ArgumentError, \"invalid num (#{num.inspect} for 0..#{row_count - 1})\")\nend\nif row\n (row(num)).map_with_index do |e, k|\n e * (cofactor(num, k))\n end.reduce(&.+)\nelse\n (col(num)).map_with_index do |e, k|\n e * (cofactor(k, num))\n end.reduce(&.+)\nend\n"}},{"id":"lower_triangular?-instance-method","html_id":"lower_triangular?-instance-method","name":"lower_triangular?","doc":"Returns true if this matrix is a lower triangular matrix.","summary":"Returns true if this matrix is a lower triangular matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L720","def":{"name":"lower_triangular?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = [] of T\neach(:strict_upper) do |e|\n els << e\nend\nels.all?(&.zero?)\n"}},{"id":"lup-instance-method","html_id":"lup-instance-method","name":"lup","doc":"Returns the LUP decomposition of the matrix\nSee +LUPDecomposition+.\n\nNOTE: Not working yet\n\n```\na = Matrix[[1, 2], [3, 4]]\nl, u, p = a.lup\nl.lower_triangular? # => true\nu.upper_triangular? # => true\np.permutation? # => true\nl * u == p * a # => true\na.lup.solve([2, 5]) # => Vector[(1/1), (1/2)]\n```","summary":"Returns the LUP decomposition of the matrix See +LUPDecomposition+.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1295","def":{"name":"lup","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"LUPDecomposition.new(self)"}},{"id":"map(&block:T->T)-instance-method","html_id":"map(&block:T->T)-instance-method","name":"map","doc":"Returns a Matrix that is the result of iteration of the given block\nover all elements in the matrix.","summary":"Returns a Matrix that is the result of iteration of the given block over all elements in the matrix.
","abstract":false,"args":[],"args_string":"(&block : T -> T)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L359","def":{"name":"map","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> T)"},"return_type":"","visibility":"Public","body":"rows = @rows.map do |row|\n row.map(&block)\nend\nMatrix.new(rows, column_count)\n"}},{"id":"minor(row_range:Range,col_range:Range)-instance-method","html_id":"minor(row_range:Range,col_range:Range)-instance-method","name":"minor","doc":"Returns a section of the Matrix.\n\n```\nMatrix.diagonal(9, 5, -3).minor(0..1, 0..2)\n# => [ 9, 0, 0,\n# 0, 5, 0 ]\n```","summary":"Returns a section of the Matrix.
","abstract":false,"args":[{"name":"row_range","doc":null,"default_value":"","external_name":"row_range","restriction":"Range"},{"name":"col_range","doc":null,"default_value":"","external_name":"col_range","restriction":"Range"}],"args_string":"(row_range : Range, col_range : Range)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L532","def":{"name":"minor","args":[{"name":"row_range","doc":null,"default_value":"","external_name":"row_range","restriction":"Range"},{"name":"col_range","doc":null,"default_value":"","external_name":"col_range","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"from_row = row_range.first\nif from_row < 0\n from_row = from_row + row_count\nend\nto_row = row_range.end\nif to_row < 0\n to_row = to_row + row_count\nend\nif row_range.excludes_end?\nelse\n to_row = to_row + 1\nend\nsize_row = to_row - from_row\nfrom_col = col_range.first\nif from_col < 0\n from_col = from_col + column_count\nend\nto_col = col_range.end\nif to_col < 0\n to_col = to_col + column_count\nend\nif col_range.excludes_end?\nelse\n to_col = to_col + 1\nend\nsize_col = to_col - from_col\nif ((from_row > row_count || from_col > column_count) || from_row < 0) || from_col < 0\n return nil\nend\nrows = @rows[from_row, size_row].map do |row|\n row[from_col, size_col]\nend\nMatrix.new(rows, [column_count - from_col, size_col].min)\n"}},{"id":"minor(from_row:Int,nrows:Int,from_col:Int,ncols:Int)-instance-method","html_id":"minor(from_row:Int,nrows:Int,from_col:Int,ncols:Int)-instance-method","name":"minor","doc":"Returns a section of the Matrix.\n\n```\nMatrix.diagonal(9, 5, -3).minor(0, 2, 0, 3)\n# => [ 9, 0, 0,\n# 0, 5, 0 ]\n```","summary":"Returns a section of the Matrix.
","abstract":false,"args":[{"name":"from_row","doc":null,"default_value":"","external_name":"from_row","restriction":"Int"},{"name":"nrows","doc":null,"default_value":"","external_name":"nrows","restriction":"Int"},{"name":"from_col","doc":null,"default_value":"","external_name":"from_col","restriction":"Int"},{"name":"ncols","doc":null,"default_value":"","external_name":"ncols","restriction":"Int"}],"args_string":"(from_row : Int, nrows : Int, from_col : Int, ncols : Int)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L563","def":{"name":"minor","args":[{"name":"from_row","doc":null,"default_value":"","external_name":"from_row","restriction":"Int"},{"name":"nrows","doc":null,"default_value":"","external_name":"nrows","restriction":"Int"},{"name":"from_col","doc":null,"default_value":"","external_name":"from_col","restriction":"Int"},{"name":"ncols","doc":null,"default_value":"","external_name":"ncols","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if nrows < 0 || ncols < 0\n return nil\nend\nif from_row < 0\n from_row = from_row + row_count\nend\nif from_col < 0\n from_col = from_col + column_count\nend\nif ((from_row > row_count || from_col > column_count) || from_row < 0) || from_col < 0\n return nil\nend\nrows = @rows[from_row, nrows].map do |row|\n row[from_col, ncols]\nend\nMatrix.new(rows, [column_count - from_col, ncols].min)\n"}},{"id":"normal?-instance-method","html_id":"normal?-instance-method","name":"normal?","doc":"Returns `true` if this is a normal matrix.\n\n```\nMatrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].normal?\n# => true\n```","summary":"Returns true
if this is a normal matrix.
Returns true
if this is an orthogonal matrix
Returns true
if this is a permutation matrix
Returns the rank of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1175","def":{"name":"rank","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"a = to_a\nlast_column = column_count - 1\nlast_row = row_count - 1\npivot_row = 0\nprevious_pivot = 1\n0.upto(last_column) do |k|\n switch_row = (pivot_row..last_row).find do |row|\n a[row][k] != 0\n end\n if switch_row\n if pivot_row == switch_row\n else\n a[switch_row], a[pivot_row] = a[pivot_row], a[switch_row]\n end\n pivot = a[pivot_row][k]\n (pivot_row + 1).upto(last_row) do |i|\n ai = a[i]\n (k + 1).upto(last_column) do |j|\n ai[j] = ((pivot * ai[j]) - (ai[k] * a[pivot_row][j])) / previous_pivot\n end\n end\n pivot_row = pivot_row + 1\n previous_pivot = pivot\n end\nend\npivot_row\n"}},{"id":"real-instance-method","html_id":"real-instance-method","name":"real","doc":"Returns the real part of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => [ 1+2i, i, 0,\n# 1, 2, 3 ]\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real\n# => [ 1, 0, 0,\n# 1, 2, 3 ]\n```","summary":"Returns the real part of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1343","def":{"name":"real","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#real only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.real)\n"}},{"id":"real?-instance-method","html_id":"real?-instance-method","name":"real?","doc":"Returns `true` if this matrix contains real numbers,\ni.e. not `Complex`.\n\n```\nrequire \"complex\"\nMatrix[[Complex.new(1, 0)], [Complex.new(0, 1)]].real?\n# => false\n```","summary":"Returns true
if this matrix contains real numbers, i.e.
Returns an array containing matrices corresponding to the real and imaginary parts of the matrix
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1355","def":{"name":"rect","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#real only works with real matrices (i.e. Matrix(Complex))\"))\nend\n[real, imag]\n"}},{"id":"regular?-instance-method","html_id":"regular?-instance-method","name":"regular?","doc":"Returns `true` if this is a regular (i.e. non-singular) matrix.","summary":"Returns true
if this is a regular (i.e.
Returns a matrix with entries rounded to the given precision (see Float#round
)
Returns a block which yields every Vector in the row (starting at 0).
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i, &block : Vector -> )","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L322","def":{"name":"row","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(Vector -> )"},"return_type":"","visibility":"Public","body":"(row(i)).each(&block)"}},{"id":"row(i)-instance-method","html_id":"row(i)-instance-method","name":"row","doc":"Returns row vector number `i` of the Matrix as a Vector (starting\nat 0 like a good boy). Raises if the row doesn't exist.","summary":"Returns row vector number i
of the Matrix as a Vector (starting at 0 like a good boy).
Returns row vector number i
of the Matrix as a Vector (starting at 0 like a good boy).
Returns the number of rows.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L307","def":{"name":"row_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rows.size"}},{"id":"singular?-instance-method","html_id":"singular?-instance-method","name":"singular?","doc":"Returns `true` if this is a singular matrix.","summary":"Returns true
if this is a singular matrix.
Returns true
if this is a square matrix.
Swaps col1
and col2
Swaps row1
and row2
Returns +true+ if this is a symmetric matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L820","def":{"name":"symmetric?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n return false\nend\nresult = true\neach_with_index(:strict_upper) do |e, row, col|\n if e != rows[col][row]\n result = false\n end\nend\nresult\n"}},{"id":"t-instance-method","html_id":"t-instance-method","name":"t","doc":"Returns the transpose of the matrix.\n\n```\nMatrix[[1,2], [3,4], [5,6]]\n# => [ 1, 2,\n# 3, 4,\n# 5, 6 ]\nMatrix[[1,2], [3,4], [5,6]].transpose\n# => [ 1, 3, 5,\n# 2, 4, 6 ]\n```","summary":"Returns the transpose of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1244","def":{"name":"t","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"transpose"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Returns this matrix as an `Array(Array(T))`","summary":"Returns this matrix as an Array(Array(T))
Returns the trace (sum of diagonal elements) of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1223","def":{"name":"tr","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"trace"}},{"id":"trace-instance-method","html_id":"trace-instance-method","name":"trace","doc":"Returns the trace (sum of diagonal elements) of the matrix.\n\n```\nMatrix[[7,6], [3,9]].trace\n# => 16\n```","summary":"Returns the trace (sum of diagonal elements) of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1215","def":{"name":"trace","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\n(0...column_count).reduce(0) do |tr, i|\n tr + @rows[i][i]\nend\n"}},{"id":"transpose-instance-method","html_id":"transpose-instance-method","name":"transpose","doc":"Returns the transpose of the matrix.\n\n```\nMatrix[[1,2], [3,4], [5,6]]\n# => [ 1, 2,\n# 3, 4,\n# 5, 6 ]\nMatrix[[1,2], [3,4], [5,6]].transpose\n# => [ 1, 3, 5,\n# 2, 4, 6 ]\n```","summary":"Returns the transpose of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1238","def":{"name":"transpose","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if row_count.zero?\n return self.class.empty(column_count, 0)\nend\nMatrix.new(@rows.transpose, row_count)\n"}},{"id":"unitary?-instance-method","html_id":"unitary?-instance-method","name":"unitary?","doc":"Returns `true` if this is a unitary matrix","summary":"Returns true
if this is a unitary matrix
Returns true if this matrix is a upper triangular matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L852","def":{"name":"upper_triangular?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = [] of T\neach(:strict_lower) do |e|\n els << e\nend\nels.all?(&.zero?)\n"}},{"id":"vstack(*matrices)-instance-method","html_id":"vstack(*matrices)-instance-method","name":"vstack","doc":"Returns a new matrix resulting by stacking vertically\nthe receiver with the given matrices\n\n```\nx = Matrix[[1, 2], [3, 4]]\ny = Matrix[[5, 6], [7, 8]]\nx.vstack(y)\n# => Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]\n```","summary":"Returns a new matrix resulting by stacking vertically the receiver with the given matrices
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1257","def":{"name":"vstack","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.vstack(self, *matrices)"}},{"id":"zero?-instance-method","html_id":"zero?-instance-method","name":"zero?","doc":"Returns `true` if this is a matrix with only zero elements","summary":"Returns true
if this is a matrix with only zero elements
Eigenvalues and eigenvectors of a real matrix.
","class_methods":[],"constructors":[{"id":"new(matrix)-class-method","html_id":"new(matrix)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"args_string":"(matrix)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr#L13","def":{"name":"new","args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(matrix)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix/LupDecomposition","path":"Apatite/LinearAlgebra/Matrix/LupDecomposition.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix::LupDecomposition","name":"LupDecomposition","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":12,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/lup_decomposition.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix(T)","name":"Matrix"},"doc":"For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n\nunit lower triangular matrix L, an n-by-n upper triangular matrix U,\nand a m-by-m permutation matrix P so that L*U = P*A.\nIf m < n, then L is m-by-m and U is m-by-n.\n\nThe LUP decomposition with pivoting always exists, even if the matrix is\nsingular, so the constructor will never fail. The primary use of the\nLU decomposition is in the solution of square systems of simultaneous\nlinear equations. This will fail if singular? returns true.","summary":"For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a m-by-m permutation matrix P so that LU = PA.
","class_methods":[],"constructors":[{"id":"new(matrix)-class-method","html_id":"new(matrix)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"args_string":"(matrix)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/lup_decomposition.cr#L13","def":{"name":"new","args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(matrix)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/NDArray","path":"Apatite/LinearAlgebra/NDArray.html","kind":"class","full_name":"Apatite::LinearAlgebra::NDArray","name":"NDArray","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/ndarray.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(data:Array(Number),shape:Array(Int32)?=nil)-class-method","html_id":"new(data:Array(Number),shape:Array(Int32)?=nil)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array(Number)"},{"name":"shape","doc":null,"default_value":"nil","external_name":"shape","restriction":"Array(Int32) | ::Nil"}],"args_string":"(data : Array(Number), shape : Array(Int32)? = nil)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L18","def":{"name":"new","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array(Number)"},{"name":"shape","doc":null,"default_value":"nil","external_name":"shape","restriction":"Array(Int32) | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(data, shape)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"[](*args,**options)-instance-method","html_id":"[](*args,**options)-instance-method","name":"[]","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"[]","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]"}},{"id":"[](*args,**options,&block)-instance-method","html_id":"[](*args,**options,&block)-instance-method","name":"[]","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"[]","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options] do |*yield_args|\n yield *yield_args\nend"}},{"id":"[]=(*args,**options)-instance-method","html_id":"[]=(*args,**options)-instance-method","name":"[]=","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L13","def":{"name":"[]=","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args] = **options"}},{"id":"[]?(*args,**options)-instance-method","html_id":"[]?(*args,**options)-instance-method","name":"[]?","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L12","def":{"name":"[]?","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]?"}},{"id":"[]?(*args,**options,&block)-instance-method","html_id":"[]?(*args,**options,&block)-instance-method","name":"[]?","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L12","def":{"name":"[]?","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]? do |*yield_args|\n yield *yield_args\nend"}},{"id":"abs-instance-method","html_id":"abs-instance-method","name":"abs","doc":"Returns the absolute value of every item in the array","summary":"Returns the absolute value of every item in the array
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L24","def":{"name":"abs","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |e|\n e.abs\nend"}},{"id":"acos-instance-method","html_id":"acos-instance-method","name":"acos","doc":"Returns the arccosine of each element in the current array.","summary":"Returns the arccosine of each element in the current array.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L29","def":{"name":"acos","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"data:Array(Float64)-instance-method","html_id":"data:Array(Float64)-instance-method","name":"data","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Array(Float64)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L9","def":{"name":"data","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(Float64)","visibility":"Public","body":"@data"}},{"id":"shape:Array(Int32)-instance-method","html_id":"shape:Array(Int32)-instance-method","name":"shape","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Array(Int32)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"shape","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(Int32)","visibility":"Public","body":"@shape"}},{"id":"size(*args,**options)-instance-method","html_id":"size(*args,**options)-instance-method","name":"size","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L16","def":{"name":"size","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.size(*args, **options)"}},{"id":"size(*args,**options,&block)-instance-method","html_id":"size(*args,**options,&block)-instance-method","name":"size","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L16","def":{"name":"size","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.size(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"to_unsafe(*args,**options)-instance-method","html_id":"to_unsafe(*args,**options)-instance-method","name":"to_unsafe","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L15","def":{"name":"to_unsafe","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.to_unsafe(*args, **options)"}},{"id":"to_unsafe(*args,**options,&block)-instance-method","html_id":"to_unsafe(*args,**options,&block)-instance-method","name":"to_unsafe","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L15","def":{"name":"to_unsafe","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.to_unsafe(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"unsafe_fetch(*args,**options)-instance-method","html_id":"unsafe_fetch(*args,**options)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L14","def":{"name":"unsafe_fetch","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.unsafe_fetch(*args, **options)"}},{"id":"unsafe_fetch(*args,**options,&block)-instance-method","html_id":"unsafe_fetch(*args,**options,&block)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L14","def":{"name":"unsafe_fetch","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.unsafe_fetch(*args, **options) do |*yield_args|\n yield *yield_args\nend"}}],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Vector","path":"Apatite/LinearAlgebra/Vector.html","kind":"class","full_name":"Apatite::LinearAlgebra::Vector(T)","name":"Vector","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/vector.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":"Represents a mathematical vector, and also constitutes a row or column\nof a `Matrix`","summary":"Represents a mathematical vector, and also constitutes a row or column of a Matrix
Creates a new vector from a list of elements.
","abstract":false,"args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""}],"args_string":"(*array)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L22","def":{"name":"[]","args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new(array)"}},{"id":"basis(size,index)-class-method","html_id":"basis(size,index)-class-method","name":"basis","doc":"Returns a standard basis `n`-vector.","summary":"Returns a standard basis n
-vector.
Creates a vector from an Array.
","abstract":false,"args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(array, copy = true)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L28","def":{"name":"elements","args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if copy\n array = array.clone\nend\nnew(array)\n"}},{"id":"zero(size)-class-method","html_id":"zero(size)-class-method","name":"zero","doc":"Return a zero vector.","summary":"Return a zero vector.
","abstract":false,"args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""}],"args_string":"(size)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L53","def":{"name":"zero","args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size < 0\n raise(ArgumentError.new(\"invalid size (#{size} for 0..)\"))\nend\narray = Array.new(size, 0)\nnew(array)\n"}}],"constructors":[],"instance_methods":[{"id":"*(x)-instance-method","html_id":"*(x)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is a number or a matrix.","summary":"Multiplies the vector by x, where x is a number or a matrix.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L60","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e * x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg0|\n x = __arg0[0]\n y = __arg0[1]\n x * y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"+(x)-instance-method","html_id":"+(x)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L75","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e + x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg1|\n x = __arg1[0]\n y = __arg1[1]\n x + y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"-(x)-instance-method","html_id":"-(x)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L90","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e - x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg2|\n x = __arg2[0]\n y = __arg2[1]\n x - y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"/(x)-instance-method","html_id":"/(x)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L105","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e / x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg3|\n x = __arg3[0]\n y = __arg3[1]\n x / y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"-instance-method","html_id":"-instance-method","name":"<=>","doc":"Take me to your leader","summary":"Take me to your leader
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L129","def":{"name":"<=>","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if other.is_a?(Vector)\n @elements <=> other.elements\nelse\n @elements <=> other\nend"}},{"id":"==(other)-instance-method","html_id":"==(other)-instance-method","name":"==","doc":"Equality operator","summary":"Equality operator
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L120","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if other.is_a?(Vector)\n @elements == other.elements\nelse\n @elements == other\nend"}},{"id":"angle_with(v)-instance-method","html_id":"angle_with(v)-instance-method","name":"angle_with","doc":"Returns an angle with another vector. Result is within the [0…Math::PI].","summary":"Returns an angle with another vector.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L138","def":{"name":"angle_with","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\nprod = magnitude * v.magnitude\nif prod == 0\n raise(ZeroVectorError.new(\"Can't get angle of zero vector\"))\nend\nMath.acos((inner_product(v)) / prod)\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":"Returns a copy of the vector.","summary":"Returns a copy of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L147","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.elements(@elements)"}},{"id":"coerce(klass,*args)-instance-method","html_id":"coerce(klass,*args)-instance-method","name":"coerce","doc":"The coerce method allows you to attempt to coerce the elements\nin the matrix to another type. The type","summary":"The coerce method allows you to attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(klass, *args)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L249","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case klass.to_s\nwhen \"Complex\"\n if args[0]?\n else\n raise(\"coercing to a Complex requires a second argument\")\n end\n els = @elements.map do |e|\n Complex.new(e, args[0].as(Int32))\n end\nwhen \"BigInt\"\n base = args[0]? || 10\n els = @elements.map do |e|\n klass.new(e, base)\n end\nwhen \"BigRational\"\n if args[0]?\n else\n raise(\"coercing to a BigRational requires a second argument to use as a denominator\")\n end\n els = @elements.map do |e|\n klass.new(e, args[0])\n end\nelse\n els = @elements.map do |e|\n klass.new(e)\n end\nend\nVector.elements(els)\n"}},{"id":"cross(v)-instance-method","html_id":"cross(v)-instance-method","name":"cross","doc":"Returns the cross product of this vector with the others.","summary":"Returns the cross product of this vector with the others.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L193","def":{"name":"cross","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"cross_product(v)"}},{"id":"cross_product(*vs)-instance-method","html_id":"cross_product(*vs)-instance-method","name":"cross_product","doc":"Returns the cross product of this vector with the others.","summary":"Returns the cross product of this vector with the others.
","abstract":false,"args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"args_string":"(*vs)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L170","def":{"name":"cross_product","args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size >= 2\nelse\n raise(ErrOperationNotDefined.new(\"cross product is not defined on vectors of dimension #{size}\"))\nend\nif vs.size == (size - 2)\nelse\n raise(ArgumentError.new(\"wrong number of arguments (#{vs.size} for #{size - 2})\"))\nend\nvs.each do |v|\n if v.size == size\n else\n raise(ErrDimensionMismatch.new)\n end\nend\ncase size\nwhen 2\n Vector[-@elements[1], @elements[0]]\nwhen 3\n v = vs[0]\n Vector[(v[2] * @elements[1]) - (v[1] * @elements[2]), (v[0] * @elements[2]) - (v[2] * @elements[0]), (v[1] * @elements[0]) - (v[0] * @elements[1])]\nelse\n rows = (self + vs) + (Array.new(size) do |i|\n Vector.basis(size, i)\n end)\n (Matrix.rows(rows)).laplace_expansion(row: size - 1)\nend\n"}},{"id":"dot(v)-instance-method","html_id":"dot(v)-instance-method","name":"dot","doc":"Returns the inner product of this vector with the other.","summary":"Returns the inner product of this vector with the other.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L207","def":{"name":"dot","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"inner_product(v)"}},{"id":"each(*args,**options)-instance-method","html_id":"each(*args,**options)-instance-method","name":"each","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L14","def":{"name":"each","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.each(*args, **options)"}},{"id":"each(*args,**options,&block)-instance-method","html_id":"each(*args,**options,&block)-instance-method","name":"each","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L14","def":{"name":"each","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.each(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"each2(v,&block)-instance-method","html_id":"each2(v,&block)-instance-method","name":"each2","doc":"Iterate over the elements of this vector and `v` in conjunction.","summary":"Iterate over the elements of this vector and v
in conjunction.
Returns the inner product of this vector with the other.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L198","def":{"name":"inner_product","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\np = 0\neach2(v) do |v1, v2|\n p = p + (v1 * v2)\nend\np\n"}},{"id":"inspect-instance-method","html_id":"inspect-instance-method","name":"inspect","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L286","def":{"name":"inspect","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"<#Vector(#{T}) [#{@elements.join(\", \")}]>\""}},{"id":"magnitude-instance-method","html_id":"magnitude-instance-method","name":"magnitude","doc":"Returns the modulus (Pythagorean distance) of the vector.","summary":"Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L221","def":{"name":"magnitude","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Math.sqrt(@elements.reduce(0) do |v, e|\n v + e.abs2\nend)"}},{"id":"map(&block:T->UNDERSCORE)-instance-method","html_id":"map(&block:T->UNDERSCORE)-instance-method","name":"map","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"(&block : T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L151","def":{"name":"map","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> _)"},"return_type":"","visibility":"Public","body":"els = @elements.map(&block)\nself.class.elements(els, false)\n"}},{"id":"map2(v,&block:T,T->UNDERSCORE)-instance-method","html_id":"map2(v,&block:T,T->UNDERSCORE)-instance-method","name":"map2","doc":null,"summary":null,"abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v, &block : T, T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L156","def":{"name":"map2","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":2,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T, T -> _)"},"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\narr = Array.new(size) do |i|\n yield @elements[i], v[i]\nend\nself.class.elements(arr, false)\n"}},{"id":"norm-instance-method","html_id":"norm-instance-method","name":"norm","doc":"Returns the modulus (Pythagorean distance) of the vector.","summary":"Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L226","def":{"name":"norm","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"magnitude"}},{"id":"normalize-instance-method","html_id":"normalize-instance-method","name":"normalize","doc":"Returns a new vector with the same direction but with norm 1","summary":"Returns a new vector with the same direction but with norm 1
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L231","def":{"name":"normalize","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"n = magnitude\nif n == 0\n raise(ZeroVectorError.new(\"Zero vectors can not be normalized\"))\nend\nself / n\n"}},{"id":"r-instance-method","html_id":"r-instance-method","name":"r","doc":"Returns a new vector with the same direction but with norm 1","summary":"Returns a new vector with the same direction but with norm 1
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L238","def":{"name":"r","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"magnitude"}},{"id":"round(ndigits=0)-instance-method","html_id":"round(ndigits=0)-instance-method","name":"round","doc":"Returns a vector with entries rounded to the given precision.","summary":"Returns a vector with entries rounded to the given precision.
","abstract":false,"args":[{"name":"ndigits","doc":null,"default_value":"0","external_name":"ndigits","restriction":""}],"args_string":"(ndigits = 0)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L243","def":{"name":"round","args":[{"name":"ndigits","doc":null,"default_value":"0","external_name":"ndigits","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |e|\n e.round(ndigits)\nend"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Returns the elements of the vector in an array.","summary":"Returns the elements of the vector in an array.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L268","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.dup"}},{"id":"to_matrix-instance-method","html_id":"to_matrix-instance-method","name":"to_matrix","doc":"Return a single-column matrix from this vector.","summary":"Return a single-column matrix from this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L273","def":{"name":"to_matrix","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.column_vector(self)"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L277","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(\"Vector{\" + (@elements.join(\", \"))) + \"}\""}},{"id":"unsafe_fetch(i)-instance-method","html_id":"unsafe_fetch(i)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L290","def":{"name":"unsafe_fetch","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.unsafe_fetch(i)"}},{"id":"zero?-instance-method","html_id":"zero?-instance-method","name":"zero?","doc":"Returns `true` if all elements are zero.","summary":"Returns true
if all elements are zero.
An Array
is an ordered, integer-indexed collection of objects of type T.
Tests whether all elements evaluate to true
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/core_ext/array.cr#L3","def":{"name":"all?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"each do |i|\n if (!(!i)) == false\n return false\n end\nend\ntrue\n"}},{"id":"any?-instance-method","html_id":"any?-instance-method","name":"any?","doc":"Tests whether any of the elements evaluate to true","summary":"Tests whether any of the elements evaluate to true
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/core_ext/array.cr#L11","def":{"name":"any?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"each do |i|\n if (!(!i)) == true\n return true\n end\nend\nfalse\n"}},{"id":"shape-instance-method","html_id":"shape-instance-method","name":"shape","doc":"Get the array's dimensions","summary":"Get the array's dimensions
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/core_ext/array.cr#L19","def":{"name":"shape","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"max = max_by do |i|\n i.is_a?(Array) ? i.size : i\nend\nmax.is_a?(Array) ? [size, max.size] : [max]\n"}},{"id":"to_vec-instance-method","html_id":"to_vec-instance-method","name":"to_vec","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/core_ext/array.cr#L24","def":{"name":"to_vec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite::Vector.create(self)"}}],"macros":[],"types":[]}]}} \ No newline at end of file +{"repository_name":"github.com/watzon/apatite","body":"# Apatite\n\nApatite is meant to be a collecion of mathmatical and scientific computing algorithms for the Crystal programming language. I don't expect it to ever reach the level of completeness as numpy, but hopefully it can save some people the trouble of implementing these methods on their own.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n apatite:\n github: watzon/apatite\n ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"apatite\"\n```\n\nCheck out the [documentation](https://watzon.github.io/apatite/) for usage examples.\n\n## Roadmap\n\n- [ ] Linear Algebra\n\t- [x] Vector\n\t- [x] Matrix\n\t- [ ] NDArray\n\t- [ ] Line\n\t- [ ] Plane\n\t- [ ] Polygon\n\t- [ ] LinkedList\n\t\n\n\n## Contributing\n\n1. Fork it (Apatite is a fundimental package for scientific computing in Crystal.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","path":"Apatite/LinearAlgebra.html","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"},{"filename":"apatite/linear_algebra/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr"},{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":5,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr"},{"filename":"apatite/linear_algebra.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra.cr"},{"filename":"apatite/linear_algebra/ndarray.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"}],"subclasses":[],"including_types":[{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"}],"namespace":{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"sigmoid(input:Number)-instance-method","html_id":"sigmoid(input:Number)-instance-method","name":"sigmoid","doc":"Calculates the sigmoid curve for a numeric input.\n\n`f(x) = 1/(1 + e^-x)`\n\nSee also: [Sigmoid function (WikiWand)](https://www.wikiwand.com/en/Sigmoid_function)","summary":"Calculates the sigmoid curve for a numeric input.
","abstract":false,"args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"args_string":"(input : Number)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra.cr#L15","def":{"name":"sigmoid","args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = input.to_f64\n1 / (1 + (Math.exp(-num)))\n"}},{"id":"sigmoid_d(input:Number)-instance-method","html_id":"sigmoid_d(input:Number)-instance-method","name":"sigmoid_d","doc":"Calculates the derivative sigmoid curve for a numeric input.\n\n`f'(x) = f(x)(1 - f(x)),`","summary":"Calculates the derivative sigmoid curve for a numeric input.
","abstract":false,"args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"args_string":"(input : Number)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra.cr#L23","def":{"name":"sigmoid_d","args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = input.to_f64\nnum * (1 - num)\n"}}],"macros":[],"types":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrDimensionMismatch","path":"Apatite/LinearAlgebra/ErrDimensionMismatch.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrDimensionMismatch","name":"ErrDimensionMismatch","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrNotRegular","path":"Apatite/LinearAlgebra/ErrNotRegular.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrNotRegular","name":"ErrNotRegular","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrOperationNotDefined","path":"Apatite/LinearAlgebra/ErrOperationNotDefined.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrOperationNotDefined","name":"ErrOperationNotDefined","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":8,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(method,this,other)-class-method","html_id":"new(method,this,other)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"method","doc":null,"default_value":"","external_name":"method","restriction":""},{"name":"this","doc":null,"default_value":"","external_name":"this","restriction":""},{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(method, this, other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr#L9","def":{"name":"new","args":[{"name":"method","doc":null,"default_value":"","external_name":"method","restriction":""},{"name":"this","doc":null,"default_value":"","external_name":"this","restriction":""},{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(method, this, other)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","path":"Apatite/LinearAlgebra/Error.html","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":3,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrDimensionMismatch","kind":"class","full_name":"Apatite::LinearAlgebra::ErrDimensionMismatch","name":"ErrDimensionMismatch"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrNotRegular","kind":"class","full_name":"Apatite::LinearAlgebra::ErrNotRegular","name":"ErrNotRegular"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrOperationNotDefined","kind":"class","full_name":"Apatite::LinearAlgebra::ErrOperationNotDefined","name":"ErrOperationNotDefined"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ZeroVectorError","kind":"class","full_name":"Apatite::LinearAlgebra::ZeroVectorError","name":"ZeroVectorError"}],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix","path":"Apatite/LinearAlgebra/Matrix.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix(T)","name":"Matrix","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"SELECTORS","name":"SELECTORS","value":"{all: true, diagonal: true, off_diagonal: true, lower: true, strict_lower: true, strict_upper: true, upper: true}","doc":null,"summary":null}],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[{"id":"[](*rows)-class-method","html_id":"[](*rows)-class-method","name":"[]","doc":"Creates a matrix where each argument is a row.\n\n```\nMatrix[[25, 93], [-1, 66]]\n# => [ 25, 93,\n# -1, 66 ]\n```","summary":"Creates a matrix where each argument is a row.
","abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"args_string":"(*rows)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L20","def":{"name":"[]","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows(rows, false)"}},{"id":"build(row_count,column_count=row_count,&block:Int32,Int32->T)-class-method","html_id":"build(row_count,column_count=row_count,&block:Int32,Int32->T)-class-method","name":"build","doc":"Creates a matrix of size +row_count+ x +column_count+.\nIt fills the values by calling the given block,\npassing the current row and column.\nReturns an enumerator if no block is given.\n\n```\nm = Matrix.build(2, 4) { |row, col| col - row }\n# => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]\nm = Matrix.build(3) { rand }\n# => a 3x3 matrix with random elements\n```","summary":"Creates a matrix of size +row_count+ x +column_count+.
","abstract":false,"args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"args_string":"(row_count, column_count = row_count, &block : Int32, Int32 -> T)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L69","def":{"name":"build","args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"double_splat":null,"splat_index":null,"yields":2,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(Int32, Int32 -> T)"},"return_type":"","visibility":"Public","body":"row_count = row_count.to_i\ncolumn_count = column_count.to_i\nif row_count < 0 || column_count < 0\n raise(ArgumentError.new)\nend\nrows = Array(T).new(row_count) do |i|\n Array(T).new(column_count) do |j|\n yield i, j\n end\nend\nnew(rows, column_count)\n"}},{"id":"column_vector(column)-class-method","html_id":"column_vector(column)-class-method","name":"column_vector","doc":"Creates a single-column matrix where the values of that column are as given\nin `column`.\n\n```\nMatrix.column_vector([4,5,6])\n# => [ 4,\n# 5,\n# 6 ]\n```","summary":"Creates a single-column matrix where the values of that column are as given in #column
.
Creates a matrix using +columns+ as an array of column vectors.
","abstract":false,"args":[{"name":"columns","doc":null,"default_value":"","external_name":"columns","restriction":""}],"args_string":"(columns)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L54","def":{"name":"columns","args":[{"name":"columns","doc":null,"default_value":"","external_name":"columns","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(rows(columns, false)).transpose"}},{"id":"combine(*matrices,&block)-class-method","html_id":"combine(*matrices,&block)-class-method","name":"combine","doc":"Create a matrix by combining matrices entrywise, using the given block\n\n```\nx = Matrix[[6, 6], [4, 4]]\ny = Matrix[[1, 2], [3, 4]]\nMatrix.combine(x, y) {|a, b| a - b}\n# => Matrix[[5, 4], [1, 0]]\n```","summary":"Create a matrix by combining matrices entrywise, using the given block
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L245","def":{"name":"combine","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"if matrices.empty?\n return Matrix.empty\nend\nmatrices = matrices.map do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\nend\nx = matrices.first\nmatrices.each do |m|\n if (x.row_count == m.row_count) && (x.column_count == m.column_count)\n else\n raise(ErrDimensionMismatch.new)\n end\nend\nrows = Array(T).new(x.row_count) do |i|\n Array(T).new(x.column_count) do |j|\n yield matrices.map do |m|\n m[i, j]\n end\n end\nend\nnew(rows, x.column_count)\n"}},{"id":"diagonal(values:Indexable(T),dummy=nil)-class-method","html_id":"diagonal(values:Indexable(T),dummy=nil)-class-method","name":"diagonal","doc":"Creates a matrix where the diagonal elements are composed of `values`.\n\n```\nMatrix.diagonal(9, 5, -3)\n# => [ 9, 0, 0,\n# 0, 5, 0,\n# 0, 0, -3 ]\n```","summary":"Creates a matrix where the diagonal elements are composed of values
.
Creates a matrix where the diagonal elements are composed of values
.
Creates a empty matrix of #row_count
x #column_count
.
Create a matrix by stacking matrices horizontally
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(x, *matrices)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L217","def":{"name":"hstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"result = x.rows\ntotal_column_count = x.column_count\nmatrices.each do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\n if m.row_count != x.row_count\n raise(ErrDimensionMismatch.new(\"The given matrices must have #{x.row_count} rows, but one has #{m.row_count}\"))\n end\n result.each_with_index do |row, i|\n row.concat(m.rows[i])\n end\n total_column_count = total_column_count + m.column_count\nend\nnew(result, total_column_count)\n"}},{"id":"identity(n)-class-method","html_id":"identity(n)-class-method","name":"identity","doc":"Creates an `n` by `n` identity matrix.\n\n```\nMatrix.identity(2)\n# => [ 1, 0,\n# 0, 1 ]\n```","summary":"Creates an n
by n
identity matrix.
Creates a single-row matrix where the values of that row are as given in #row
.
Creates a matrix where +rows+ is an array of arrays, each of which is a row of the matrix.
","abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Array(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(rows : Indexable(Array(T)), copy = true)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L33","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Array(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if copy\n rows = rows.dup\nend\nrows = rows.to_a\nrows.map! do |row|\n if row\n row = row.dup\n end\n row.to_a\nend\nsize = (rows[0] || ([] of T)).size\nrows.each_with_index do |row, i|\n if row.size == size\n else\n raise(ErrDimensionMismatch.new(\"row size differs (row at index `#{i}` should contain #{size} elements, instead has #{row.size})\"))\n end\nend\nnew(rows, size)\n"}},{"id":"scalar(n,value:T)-class-method","html_id":"scalar(n,value:T)-class-method","name":"scalar","doc":"Creates an +n+ by +n+ diagonal matrix where each diagonal element is\n`value`.\n\n```\nMatrix.scalar(2, 5)\n# => [ 5, 0,\n# 0, 5 ]\n```","summary":"Creates an +n+ by +n+ diagonal matrix where each diagonal element is value
.
Creates an n
by n
identity matrix.
Create a matrix by stacking matrices vertically
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(x, *matrices)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L197","def":{"name":"vstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"result = x.rows\nmatrices.each do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\n if m.column_count != x.column_count\n raise(ErrDimensionMismatch.new(\"The given matrices must have #{x.column_count} columns, but one has #{m.column_count}\"))\n end\n result.concat(m.rows)\nend\nnew(result, x.column_count)\n"}},{"id":"zero(row_count,column_count=row_count)-class-method","html_id":"zero(row_count,column_count=row_count)-class-method","name":"zero","doc":"Creates a zero matrix.\n\n```\nMatrix.zero(2)\n# => [ 0, 0,\n# 0, 0 ]\n```","summary":"Creates a zero matrix.
","abstract":false,"args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"args_string":"(row_count, column_count = row_count)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L140","def":{"name":"zero","args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = Array(T).new(row_count) do\n Array(T).new(column_count, T.new(0))\nend\nnew(rows, column_count)\n"}}],"constructors":[],"instance_methods":[{"id":"*(other)-instance-method","html_id":"*(other)-instance-method","name":"*","doc":"Matrix multiplication\n\n```\nMatrix[[2,4], [6,8]] * Matrix.identity(2)\n# => [ 2, 4,\n# 6, 8 ]\n```","summary":"Matrix multiplication
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L891","def":{"name":"*","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Number\n rows = @rows.map do |row|\n row.map do |e|\n (e * other).as(T)\n end\n end\n Matrix.new(rows, column_count)\nwhen Vector\n m = Matrix.column_vector(other)\n r = self * m\n r.column(0)\nwhen Matrix\n if column_count != other.column_count\n raise(ErrDimensionMismatch.new)\n end\n rows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (0...column_count).reduce(0) do |vij, k|\n vij + (self[i, k] * other[k, j])\n end\n end\n end\n Matrix.new(rows, column_count)\nelse\n self * (Matrix.rows(other))\nend"}},{"id":"**(other)-instance-method","html_id":"**(other)-instance-method","name":"**","doc":"Matrix exponentiation.\n\nEquivalent to multiplying the matrix by itself N times.\nNon integer exponents will be handled by diagonalizing the matrix.\n\n```\nMatrix[[7,6], [3,9]] ** 2\n# => [ 67, 96,\n# 48, 99 ]\n```","summary":"Matrix exponentiation.
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1061","def":{"name":"**","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"+(other:Matrix|Indexable)-instance-method","html_id":"+(other:Matrix|Indexable)-instance-method","name":"+","doc":"Matrix addition\n\n```\nMatrix.scalar(2,5) + Matrix[[1,0], [-4,7]]\n# => [ 6, 0,\n# -4, 1 ]\n```","summary":"Matrix addition
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"args_string":"(other : Matrix | Indexable)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L924","def":{"name":"+","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n other = Matrix.column_vector(other)\nwhen Matrix\nelse\n other = Matrix.rows(other)\nend\nif (row_count == other.row_count) && (column_count == other.column_count)\nelse\n raise(ErrDimensionMismatch.new)\nend\nrows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (self[i, j] + other[i, j]).as(T)\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"-(other:Matrix|Indexable)-instance-method","html_id":"-(other:Matrix|Indexable)-instance-method","name":"-","doc":"Matrix subtraction\n\n```\nMatrix[[1,5], [4,2]] - Matrix[[9,3], [-4,1]]\n# => [-8, 2,\n# 8, 1 ]\n```","summary":"Matrix subtraction
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"args_string":"(other : Matrix | Indexable)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L951","def":{"name":"-","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n other = Matrix.column_vector(other)\nwhen Matrix\nelse\n other = Matrix.rows(other)\nend\nif (row_count == other.row_count) && (column_count == other.column_count)\nelse\n raise(ErrDimensionMismatch.new)\nend\nrows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (self[i, j] - other[i, j]).as(T)\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"/(other)-instance-method","html_id":"/(other)-instance-method","name":"/","doc":"Matrix division (multiplication by the inverse).\n\n```\nMatrix[[7,6], [3,9]] / Matrix[[2,9], [3,1]]\n# => [ -7, 1,\n# -3, -6 ]\n```","summary":"Matrix division (multiplication by the inverse).
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L978","def":{"name":"/","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Number\n rows = @rows.map do |row|\n row.map do |e|\n (e / other).as(T)\n end\n end\n return Matrix.new(rows, column_count)\nwhen Matrix\n return self * other.inverse\nelse\n self / (Matrix.rows(other))\nend"}},{"id":"==(other:Matrix)-instance-method","html_id":"==(other:Matrix)-instance-method","name":"==","doc":"Equality operator","summary":"Equality operator
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix"}],"args_string":"(other : Matrix)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L868","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(rows == other.rows) && (column_count == other.column_count)"}},{"id":"[](i)-instance-method","html_id":"[](i)-instance-method","name":"[]","doc":"Returns row `i` of the matrix as an Array. Raises if the\nindex is not found.","summary":"Returns row i
of the matrix as an Array.
Returns element (i
, j
) of the matrix.
Set the value at index (i
, j
).
Returns row i
of the matrix as an Array.
Returns element (i
, j
) of the matrix.
Returns the adjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L626","def":{"name":"adjugate","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nMatrix.build(row_count, column_count) do |row, column|\n cofactor(column, row)\nend\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":"Returns a clone of the matrix, so that the contents of each do not reference\nidentical objects.\n\nThere should be no good reason to do this since Matrices are immutable.","summary":"Returns a clone of the matrix, so that the contents of each do not reference identical objects.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L876","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.new(@rows.map(&.dup), column_count)"}},{"id":"coerce(klass)-instance-method","html_id":"coerce(klass)-instance-method","name":"coerce","doc":"Attempt to coerce the elements in the matrix to another type.","summary":"Attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""}],"args_string":"(klass)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1365","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rws = @rows.map do |r|\n r.map do |i|\n klass.new(i)\n end\nend\nMatrix.rows(rws)\n"}},{"id":"cofactor(row,column)-instance-method","html_id":"cofactor(row,column)-instance-method","name":"cofactor","doc":"Returns the (row, column) cofactor which is obtained by multiplying\nthe first minor by (-1)**(row + column).\n\n```\nMatrix.diagonal(9, 5, -3, 4).cofactor(1, 1)\n# => -108\n```","summary":"Returns the (row, column) cofactor which is obtained by multiplying the first minor by (-1)**(row + column).
","abstract":false,"args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(row, column)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L612","def":{"name":"cofactor","args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n raise(\"cofactor of empty matrix is not defined\")\nend\nif square?\nelse\n raise(ErrDimensionMismatch.new)\nend\ndet_of_minor = (first_minor(row, column)).determinant\ndet_of_minor * ((-1) ** (row + column))\n"}},{"id":"column(j)-instance-method","html_id":"column(j)-instance-method","name":"column","doc":"Returns column vector `j` of the Matrix as a Vector (starting at 0).\nRaises if the column doesn't exist.","summary":"Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns a block which yields every item in column j
of the Matrix.
Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns the number of columns.
","abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L314","def":{"name":"column_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@column_count"}},{"id":"column_vectors-instance-method","html_id":"column_vectors-instance-method","name":"column_vectors","doc":"Returns an array of the column vectors of the matrix. See `Vector`.","summary":"Returns an array of the column vectors of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1378","def":{"name":"column_vectors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array.new(column_count) do |i|\n column(i)\nend"}},{"id":"combine(*matrices,&block)-instance-method","html_id":"combine(*matrices,&block)-instance-method","name":"combine","doc":"Create a matrix by combining matrices entrywise, using the given block\n\n```\nx = Matrix[[6, 6], [4, 4]]\ny = Matrix[[1, 2], [3, 4]]\nMatrix.combine(x, y) {|a, b| a - b}\n# => Matrix[[5, 4], [1, 0]]\n```","summary":"Create a matrix by combining matrices entrywise, using the given block
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L264","def":{"name":"combine","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"return_type":"","visibility":"Public","body":"Matrix.combine(self, *matrices, &block)"}},{"id":"conj-instance-method","html_id":"conj-instance-method","name":"conj","doc":"Returns the conjugate of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => 1+2i i 0\n# 1 2 3\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].conj\n# => 1-2i -i 0\n# 1 2 3\n```","summary":"Returns the conjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1313","def":{"name":"conj","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#conj only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.conj)\n"}},{"id":"determinant-instance-method","html_id":"determinant-instance-method","name":"determinant","doc":"Returns the determinant of the matrix.\n\nBeware that using Float values can yield erroneous results\nbecause of their lack of precision.\nConsider using exact types like Rational or BigDecimal instead.\n\n```\nMatrix[[7,6], [3,9]].determinant\n# => 45\n```","summary":"Returns the determinant of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1079","def":{"name":"determinant","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nm = rows\ncase row_count\nwhen 0\n +1\nwhen 1\n +m[0][0]\nwhen 2\n ((+m[0][0]) * m[1][1]) - (m[0][1] * m[1][0])\nwhen 3\n m0, m1, m2 = m\n (((((((+m0[0]) * m1[1]) * m2[2]) - ((m0[0] * m1[2]) * m2[1])) - ((m0[1] * m1[0]) * m2[2])) + ((m0[1] * m1[2]) * m2[0])) + ((m0[2] * m1[0]) * m2[1])) - ((m0[2] * m1[1]) * m2[0])\nwhen 4\n m0, m1, m2, m3 = m\n ((((((((((((((((((((((((((+m0[0]) * m1[1]) * m2[2]) * m3[3]) - (((m0[0] * m1[1]) * m2[3]) * m3[2])) - (((m0[0] * m1[2]) * m2[1]) * m3[3])) + (((m0[0] * m1[2]) * m2[3]) * m3[1])) + (((m0[0] * m1[3]) * m2[1]) * m3[2])) - (((m0[0] * m1[3]) * m2[2]) * m3[1])) - (((m0[1] * m1[0]) * m2[2]) * m3[3])) + (((m0[1] * m1[0]) * m2[3]) * m3[2])) + (((m0[1] * m1[2]) * m2[0]) * m3[3])) - (((m0[1] * m1[2]) * m2[3]) * m3[0])) - (((m0[1] * m1[3]) * m2[0]) * m3[2])) + (((m0[1] * m1[3]) * m2[2]) * m3[0])) + (((m0[2] * m1[0]) * m2[1]) * m3[3])) - (((m0[2] * m1[0]) * m2[3]) * m3[1])) - (((m0[2] * m1[1]) * m2[0]) * m3[3])) + (((m0[2] * m1[1]) * m2[3]) * m3[0])) + (((m0[2] * m1[3]) * m2[0]) * m3[1])) - (((m0[2] * m1[3]) * m2[1]) * m3[0])) - (((m0[3] * m1[0]) * m2[1]) * m3[2])) + (((m0[3] * m1[0]) * m2[2]) * m3[1])) + (((m0[3] * m1[1]) * m2[0]) * m3[2])) - (((m0[3] * m1[1]) * m2[2]) * m3[0])) - (((m0[3] * m1[2]) * m2[0]) * m3[1])) + (((m0[3] * m1[2]) * m2[1]) * m3[0])\nelse\n determinant_bareiss\nend\n"}},{"id":"diagonal?-instance-method","html_id":"diagonal?-instance-method","name":"diagonal?","doc":"Returns `true` if this is a diagonal matrix.\n","summary":"Returns true
if this is a diagonal matrix.
Yields all elements of the matrix, starting with those of the first row, or returns an Enumerator if no block given.
","abstract":false,"args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"args_string":"(which = :all, &block : T -> )","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L380","def":{"name":"each","args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> )"},"return_type":"","visibility":"Public","body":"last = column_count\ncase which.to_s\nwhen \"all\"\n @rows.each do |row|\n row.each(&block)\n end\nwhen \"diagonal\"\n @rows.each_with_index do |row, row_index|\n yield row.fetch(row_index) do\n return self\n end\n end\nwhen \"off_diagonal\"\n @rows.each_with_index do |row, row_index|\n column_count.times do |col_index|\n if row_index == col_index\n else\n yield row[col_index]\n end\n end\n end\nwhen \"lower\"\n @rows.each_with_index do |row, row_index|\n 0.upto([row_index, last].min) do |col_index|\n yield row[col_index]\n end\n end\nwhen \"strict_lower\"\n @rows.each_with_index do |row, row_index|\n [row_index, column_count].min.times do |col_index|\n yield row[col_index]\n end\n end\nwhen \"strict_upper\"\n @rows.each_with_index do |row, row_index|\n (row_index + 1).upto(last - 1) do |col_index|\n yield row[col_index]\n end\n end\nwhen \"upper\"\n @rows.each_with_index do |row, row_index|\n row_index.upto(last - 1) do |col_index|\n yield row[col_index]\n end\n end\nelse\n raise(ArgumentError.new(\"expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper\"))\nend\n"}},{"id":"each_with_index(which=:all,&block:T,Int32,Int32->)-instance-method","html_id":"each_with_index(which=:all,&block:T,Int32,Int32->)-instance-method","name":"each_with_index","doc":"Same as #each, but the row index and column index in addition to the element\n\n```\nMatrix[ [1,2], [3,4] ].each_with_index do |e, row, col|\nputs \"#{e} at #{row}, #{col}\"\nend\n# => Prints:\n# 1 at 0, 0\n# 2 at 0, 1\n# 3 at 1, 0\n# 4 at 1, 1\n```","summary":"Same as #each, but the row index and column index in addition to the element
","abstract":false,"args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"args_string":"(which = :all, &block : T, Int32, Int32 -> )","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L438","def":{"name":"each_with_index","args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"double_splat":null,"splat_index":null,"yields":3,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T, Int32, Int32 -> )"},"return_type":"","visibility":"Public","body":"last = column_count\ncase which.to_s\nwhen \"all\"\n @rows.each_with_index do |row, row_index|\n row.each_with_index do |e, col_index|\n block.call(e, row_index, col_index)\n end\n end\nwhen \"diagonal\"\n @rows.each_with_index do |row, row_index|\n block.call(row.fetch(row_index) do\n return self\n end, row_index, row_index)\n end\nwhen \"off_diagonal\"\n @rows.each_with_index do |row, row_index|\n column_count.times do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"lower\"\n @rows.each_with_index do |row, row_index|\n 0.upto([row_index, last].min) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"strict_lower\"\n @rows.each_with_index do |row, row_index|\n [row_index, column_count].min.times do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"strict_upper\"\n @rows.each_with_index do |row, row_index|\n (row_index + 1).upto(last - 1) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"upper\"\n @rows.each_with_index do |row, row_index|\n row_index.upto(last - 1) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nelse\n raise(ArgumentError.new(\"expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper\"))\nend\n"}},{"id":"eigensystem-instance-method","html_id":"eigensystem-instance-method","name":"eigensystem","doc":"Returns the Eigensystem of the matrix\nSee `EigenvalueDecomposition`.\n\nNOTE: Not working yet\n\n```\nm = Matrix[[1, 2], [3, 4]]\nv, d, v_inv = m.eigensystem\nd.diagonal? # => true\nv.inv == v_inv # => true\n(v * d * v_inv).round(5) == m # => true\n```","summary":"Returns the Eigensystem of the matrix See EigenvalueDecomposition
.
Returns true if this matrix is empty.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L705","def":{"name":"empty?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(column_count == 0) || (row_count == 0)"}},{"id":"first_minor(row,column)-instance-method","html_id":"first_minor(row,column)-instance-method","name":"first_minor","doc":"Returns the submatrix obtained by deleting the specified row and column.\n\n```\nMatrix.diagonal(9, 5, -3, 4).first_minor(1, 2)\n# => [ 9, 0, 0,\n# 0, 0, 0,\n# 0, 0, 4 ]\n```","summary":"Returns the submatrix obtained by deleting the specified row and column.
","abstract":false,"args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(row, column)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L585","def":{"name":"first_minor","args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n raise(\"first_minor of empty matrix is not defined\")\nend\nif 0 <= row && row < row_count\nelse\n raise(ArgumentError.new(\"invalid row (#{row.inspect} for 0..#{row_count - 1})\"))\nend\nif 0 <= column && column < column_count\nelse\n raise(ArgumentError.new(\"invalid column (#{column.inspect} for 0..#{column_count - 1})\"))\nend\narrays = to_a\narrays.delete_at(row)\narrays.each do |array|\n array.delete_at(column)\nend\nMatrix.new(arrays, column_count - 1)\n"}},{"id":"hadamard_product(m)-instance-method","html_id":"hadamard_product(m)-instance-method","name":"hadamard_product","doc":"Hadamard product\n\n```\nMatrix[[1,2], [3,4]].hadamard_product Matrix[[1,2], [3,2]]\n# => [ 1, 4,\n# 9, 8 ]\n```","summary":"Hadamard product
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":""}],"args_string":"(m)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L999","def":{"name":"hadamard_product","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"combine(m) do |a, b|\n a * b\nend"}},{"id":"hermitian?-instance-method","html_id":"hermitian?-instance-method","name":"hermitian?","doc":"Returns `true` if this is an hermitian matrix.","summary":"Returns true
if this is an hermitian matrix.
Returns a new matrix resulting by stacking horizontally the receiver with the given matrices
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1161","def":{"name":"hstack","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.hstack(self, *matrices)"}},{"id":"imag-instance-method","html_id":"imag-instance-method","name":"imag","doc":"Returns the imaginary part of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => [ 1+2i, i, 0,\n# 1, 2, 3 ]\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].imag\n# => [ 2i, i, 0,\n# 0, 0, 0 ]\n```","summary":"Returns the imaginary part of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1328","def":{"name":"imag","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#imag only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.imag)\n"}},{"id":"index(i,selector=:all)-instance-method","html_id":"index(i,selector=:all)-instance-method","name":"index","doc":"The index method is specialized to return the index as {row, column}\nIt also accepts an optional `selector` argument, see `#each` for details.\n\n```\nMatrix[ [1,1], [1,1] ].index(1, :strict_lower)\n# => {1, 0}\n```","summary":"The index method is specialized to return the index as {row, column} It also accepts an optional selector
argument, see #each
for details.
Returns the index as {row, column}, using &block
to filter the result.
Returns the inverse of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1013","def":{"name":"inverse","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nlast = row_count - 1\na = self.coerce(Float64)\nm = Matrix(Float64).identity(row_count)\n0.upto(last) do |k|\n i = k\n akk = a[k, k].abs\n (k + 1).upto(last) do |j|\n v = a[j, k].abs\n if v > akk\n i = j\n akk = v\n end\n end\n if akk == 0\n raise(ErrNotRegular.new)\n end\n if i != k\n a.swap_rows(i, k)\n m.swap_rows(i, k)\n end\n akk = a[k, k]\n 0.upto(last) do |ii|\n if ii == k\n next\n end\n q = a[ii, k] / akk\n a[ii, k] = 0.0\n (k + 1).upto(last) do |j|\n __temp_24 = ii\n __temp_25 = j\n a[__temp_24, __temp_25] = a[__temp_24, __temp_25] - (a[k, j] * q)\n end\n 0.upto(last) do |j|\n __temp_27 = ii\n __temp_28 = j\n m[__temp_27, __temp_28] = m[__temp_27, __temp_28] - (m[k, j] * q)\n end\n end\n (k + 1).upto(last) do |j|\n a[k, j] = a[k, j] / akk\n end\n 0.upto(last) do |j|\n m[k, j] = m[k, j] / akk\n end\nend\nm\n"}},{"id":"laplace_expansion(*,row=nil,column=nil)-instance-method","html_id":"laplace_expansion(*,row=nil,column=nil)-instance-method","name":"laplace_expansion","doc":"Returns the Laplace expansion along given row or column.\n\n```\nMatrix[[7,6], [3,9]].laplace_expansion(column: 1)\n# => 45\n\nMatrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0)\n# => Vector[3, -2]\n```","summary":"Returns the Laplace expansion along given row or column.
","abstract":false,"args":[{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"row","doc":null,"default_value":"nil","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"nil","external_name":"column","restriction":""}],"args_string":"(*, row = nil, column = nil)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L642","def":{"name":"laplace_expansion","args":[{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"row","doc":null,"default_value":"nil","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"nil","external_name":"column","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = row || column\nif (!num) || (row && column)\n raise(ArgumentError.new(\"exactly one the row or column arguments must be specified\"))\nend\nif square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nif empty?\n raise(\"laplace_expansion of empty matrix is not defined\")\nend\nif 0 <= num && num < row_count\nelse\n raise(ArgumentError, \"invalid num (#{num.inspect} for 0..#{row_count - 1})\")\nend\nif row\n (row(num)).map_with_index do |e, k|\n e * (cofactor(num, k))\n end.reduce(&.+)\nelse\n (col(num)).map_with_index do |e, k|\n e * (cofactor(k, num))\n end.reduce(&.+)\nend\n"}},{"id":"lower_triangular?-instance-method","html_id":"lower_triangular?-instance-method","name":"lower_triangular?","doc":"Returns true if this matrix is a lower triangular matrix.","summary":"Returns true if this matrix is a lower triangular matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L720","def":{"name":"lower_triangular?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = [] of T\neach(:strict_upper) do |e|\n els << e\nend\nels.all?(&.zero?)\n"}},{"id":"lup-instance-method","html_id":"lup-instance-method","name":"lup","doc":"Returns the LUP decomposition of the matrix\nSee +LUPDecomposition+.\n\nNOTE: Not working yet\n\n```\na = Matrix[[1, 2], [3, 4]]\nl, u, p = a.lup\nl.lower_triangular? # => true\nu.upper_triangular? # => true\np.permutation? # => true\nl * u == p * a # => true\na.lup.solve([2, 5]) # => Vector[(1/1), (1/2)]\n```","summary":"Returns the LUP decomposition of the matrix See +LUPDecomposition+.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1295","def":{"name":"lup","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"LUPDecomposition.new(self)"}},{"id":"map(&block:T->T)-instance-method","html_id":"map(&block:T->T)-instance-method","name":"map","doc":"Returns a Matrix that is the result of iteration of the given block\nover all elements in the matrix.","summary":"Returns a Matrix that is the result of iteration of the given block over all elements in the matrix.
","abstract":false,"args":[],"args_string":"(&block : T -> T)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L359","def":{"name":"map","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> T)"},"return_type":"","visibility":"Public","body":"rows = @rows.map do |row|\n row.map(&block)\nend\nMatrix.new(rows, column_count)\n"}},{"id":"minor(from_row:Int,nrows:Int,from_col:Int,ncols:Int)-instance-method","html_id":"minor(from_row:Int,nrows:Int,from_col:Int,ncols:Int)-instance-method","name":"minor","doc":"Returns a section of the Matrix.\n\n```\nMatrix.diagonal(9, 5, -3).minor(0, 2, 0, 3)\n# => [ 9, 0, 0,\n# 0, 5, 0 ]\n```","summary":"Returns a section of the Matrix.
","abstract":false,"args":[{"name":"from_row","doc":null,"default_value":"","external_name":"from_row","restriction":"Int"},{"name":"nrows","doc":null,"default_value":"","external_name":"nrows","restriction":"Int"},{"name":"from_col","doc":null,"default_value":"","external_name":"from_col","restriction":"Int"},{"name":"ncols","doc":null,"default_value":"","external_name":"ncols","restriction":"Int"}],"args_string":"(from_row : Int, nrows : Int, from_col : Int, ncols : Int)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L563","def":{"name":"minor","args":[{"name":"from_row","doc":null,"default_value":"","external_name":"from_row","restriction":"Int"},{"name":"nrows","doc":null,"default_value":"","external_name":"nrows","restriction":"Int"},{"name":"from_col","doc":null,"default_value":"","external_name":"from_col","restriction":"Int"},{"name":"ncols","doc":null,"default_value":"","external_name":"ncols","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if nrows < 0 || ncols < 0\n return nil\nend\nif from_row < 0\n from_row = from_row + row_count\nend\nif from_col < 0\n from_col = from_col + column_count\nend\nif ((from_row > row_count || from_col > column_count) || from_row < 0) || from_col < 0\n return nil\nend\nrows = @rows[from_row, nrows].map do |row|\n row[from_col, ncols]\nend\nMatrix.new(rows, [column_count - from_col, ncols].min)\n"}},{"id":"minor(row_range:Range,col_range:Range)-instance-method","html_id":"minor(row_range:Range,col_range:Range)-instance-method","name":"minor","doc":"Returns a section of the Matrix.\n\n```\nMatrix.diagonal(9, 5, -3).minor(0..1, 0..2)\n# => [ 9, 0, 0,\n# 0, 5, 0 ]\n```","summary":"Returns a section of the Matrix.
","abstract":false,"args":[{"name":"row_range","doc":null,"default_value":"","external_name":"row_range","restriction":"Range"},{"name":"col_range","doc":null,"default_value":"","external_name":"col_range","restriction":"Range"}],"args_string":"(row_range : Range, col_range : Range)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L532","def":{"name":"minor","args":[{"name":"row_range","doc":null,"default_value":"","external_name":"row_range","restriction":"Range"},{"name":"col_range","doc":null,"default_value":"","external_name":"col_range","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"from_row = row_range.first\nif from_row < 0\n from_row = from_row + row_count\nend\nto_row = row_range.end\nif to_row < 0\n to_row = to_row + row_count\nend\nif row_range.excludes_end?\nelse\n to_row = to_row + 1\nend\nsize_row = to_row - from_row\nfrom_col = col_range.first\nif from_col < 0\n from_col = from_col + column_count\nend\nto_col = col_range.end\nif to_col < 0\n to_col = to_col + column_count\nend\nif col_range.excludes_end?\nelse\n to_col = to_col + 1\nend\nsize_col = to_col - from_col\nif ((from_row > row_count || from_col > column_count) || from_row < 0) || from_col < 0\n return nil\nend\nrows = @rows[from_row, size_row].map do |row|\n row[from_col, size_col]\nend\nMatrix.new(rows, [column_count - from_col, size_col].min)\n"}},{"id":"normal?-instance-method","html_id":"normal?-instance-method","name":"normal?","doc":"Returns `true` if this is a normal matrix.\n\n```\nMatrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].normal?\n# => true\n```","summary":"Returns true
if this is a normal matrix.
Returns true
if this is an orthogonal matrix
Returns true
if this is a permutation matrix
Returns the rank of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1175","def":{"name":"rank","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"a = to_a\nlast_column = column_count - 1\nlast_row = row_count - 1\npivot_row = 0\nprevious_pivot = 1\n0.upto(last_column) do |k|\n switch_row = (pivot_row..last_row).find do |row|\n a[row][k] != 0\n end\n if switch_row\n if pivot_row == switch_row\n else\n a[switch_row], a[pivot_row] = a[pivot_row], a[switch_row]\n end\n pivot = a[pivot_row][k]\n (pivot_row + 1).upto(last_row) do |i|\n ai = a[i]\n (k + 1).upto(last_column) do |j|\n ai[j] = ((pivot * ai[j]) - (ai[k] * a[pivot_row][j])) / previous_pivot\n end\n end\n pivot_row = pivot_row + 1\n previous_pivot = pivot\n end\nend\npivot_row\n"}},{"id":"real-instance-method","html_id":"real-instance-method","name":"real","doc":"Returns the real part of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => [ 1+2i, i, 0,\n# 1, 2, 3 ]\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real\n# => [ 1, 0, 0,\n# 1, 2, 3 ]\n```","summary":"Returns the real part of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1343","def":{"name":"real","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#real only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.real)\n"}},{"id":"real?-instance-method","html_id":"real?-instance-method","name":"real?","doc":"Returns `true` if this matrix contains real numbers,\ni.e. not `Complex`.\n\n```\nrequire \"complex\"\nMatrix[[Complex.new(1, 0)], [Complex.new(0, 1)]].real?\n# => false\n```","summary":"Returns true
if this matrix contains real numbers, i.e.
Returns an array containing matrices corresponding to the real and imaginary parts of the matrix
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1355","def":{"name":"rect","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#real only works with real matrices (i.e. Matrix(Complex))\"))\nend\n[real, imag]\n"}},{"id":"regular?-instance-method","html_id":"regular?-instance-method","name":"regular?","doc":"Returns `true` if this is a regular (i.e. non-singular) matrix.","summary":"Returns true
if this is a regular (i.e.
Returns a matrix with entries rounded to the given precision (see Float#round
)
Returns a block which yields every Vector in the row (starting at 0).
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i, &block : Vector -> )","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L322","def":{"name":"row","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(Vector -> )"},"return_type":"","visibility":"Public","body":"(row(i)).each(&block)"}},{"id":"row(i)-instance-method","html_id":"row(i)-instance-method","name":"row","doc":"Returns row vector number `i` of the Matrix as a Vector (starting\nat 0 like a good boy). Raises if the row doesn't exist.","summary":"Returns row vector number i
of the Matrix as a Vector (starting at 0 like a good boy).
Returns row vector number i
of the Matrix as a Vector (starting at 0 like a good boy).
Returns the number of rows.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L307","def":{"name":"row_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rows.size"}},{"id":"row_vectors-instance-method","html_id":"row_vectors-instance-method","name":"row_vectors","doc":"Returns an array of the row vectors of the matrix. See `Vector`.","summary":"Returns an array of the row vectors of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1371","def":{"name":"row_vectors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array.new(row_count) do |i|\n row(i)\nend"}},{"id":"singular?-instance-method","html_id":"singular?-instance-method","name":"singular?","doc":"Returns `true` if this is a singular matrix.","summary":"Returns true
if this is a singular matrix.
Returns true
if this is a square matrix.
Swaps col1
and col2
Swaps row1
and row2
Returns +true+ if this is a symmetric matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L820","def":{"name":"symmetric?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n return false\nend\nresult = true\neach_with_index(:strict_upper) do |e, row, col|\n if e != rows[col][row]\n result = false\n end\nend\nresult\n"}},{"id":"t-instance-method","html_id":"t-instance-method","name":"t","doc":"Returns the transpose of the matrix.\n\n```\nMatrix[[1,2], [3,4], [5,6]]\n# => [ 1, 2,\n# 3, 4,\n# 5, 6 ]\nMatrix[[1,2], [3,4], [5,6]].transpose\n# => [ 1, 3, 5,\n# 2, 4, 6 ]\n```","summary":"Returns the transpose of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1244","def":{"name":"t","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"transpose"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Returns an array of arrays that describe the rows of the matrix.","summary":"Returns an array of arrays that describe the rows of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1385","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rows.clone"}},{"id":"to_json(json:JSON::Builder)-instance-method","html_id":"to_json(json:JSON::Builder)-instance-method","name":"to_json","doc":"Convert the matrix to a json array","summary":"Convert the matrix to a json array
","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"JSON::Builder"}],"args_string":"(json : JSON::Builder)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1390","def":{"name":"to_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"JSON::Builder"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"json.array do\n each(&.to_json(json))\nend"}},{"id":"to_s(io)-instance-method","html_id":"to_s(io)-instance-method","name":"to_s","doc":null,"summary":null,"abstract":false,"args":[{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":""}],"args_string":"(io)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1400","def":{"name":"to_s","args":[{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n \"Matrix.empty(#{row_count}, #{column_count})\"\nelse\n io << \"Matrix[\"\n io << (rows.map do |row|\n (\"[\" + (row.map do |e|\n e.to_s\n end.join(\", \"))) + \"]\"\n end.join(\", \"))\n io << \"]\"\nend"}},{"id":"tr-instance-method","html_id":"tr-instance-method","name":"tr","doc":"Returns the trace (sum of diagonal elements) of the matrix.\n\n```\nMatrix[[7,6], [3,9]].trace\n# => 16\n```","summary":"Returns the trace (sum of diagonal elements) of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1223","def":{"name":"tr","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"trace"}},{"id":"trace-instance-method","html_id":"trace-instance-method","name":"trace","doc":"Returns the trace (sum of diagonal elements) of the matrix.\n\n```\nMatrix[[7,6], [3,9]].trace\n# => 16\n```","summary":"Returns the trace (sum of diagonal elements) of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1215","def":{"name":"trace","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\n(0...column_count).reduce(0) do |tr, i|\n tr + @rows[i][i]\nend\n"}},{"id":"transpose-instance-method","html_id":"transpose-instance-method","name":"transpose","doc":"Returns the transpose of the matrix.\n\n```\nMatrix[[1,2], [3,4], [5,6]]\n# => [ 1, 2,\n# 3, 4,\n# 5, 6 ]\nMatrix[[1,2], [3,4], [5,6]].transpose\n# => [ 1, 3, 5,\n# 2, 4, 6 ]\n```","summary":"Returns the transpose of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1238","def":{"name":"transpose","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if row_count.zero?\n return self.class.empty(column_count, 0)\nend\nMatrix.new(@rows.transpose, row_count)\n"}},{"id":"unitary?-instance-method","html_id":"unitary?-instance-method","name":"unitary?","doc":"Returns `true` if this is a unitary matrix","summary":"Returns true
if this is a unitary matrix
Returns true if this matrix is a upper triangular matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L852","def":{"name":"upper_triangular?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = [] of T\neach(:strict_lower) do |e|\n els << e\nend\nels.all?(&.zero?)\n"}},{"id":"vstack(*matrices)-instance-method","html_id":"vstack(*matrices)-instance-method","name":"vstack","doc":"Returns a new matrix resulting by stacking vertically\nthe receiver with the given matrices\n\n```\nx = Matrix[[1, 2], [3, 4]]\ny = Matrix[[5, 6], [7, 8]]\nx.vstack(y)\n# => Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]\n```","summary":"Returns a new matrix resulting by stacking vertically the receiver with the given matrices
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1257","def":{"name":"vstack","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.vstack(self, *matrices)"}},{"id":"zero?-instance-method","html_id":"zero?-instance-method","name":"zero?","doc":"Returns `true` if this is a matrix with only zero elements","summary":"Returns true
if this is a matrix with only zero elements
Eigenvalues and eigenvectors of a real matrix.
","class_methods":[],"constructors":[{"id":"new(matrix)-class-method","html_id":"new(matrix)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"args_string":"(matrix)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr#L13","def":{"name":"new","args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(matrix)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix/LupDecomposition","path":"Apatite/LinearAlgebra/Matrix/LupDecomposition.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix::LupDecomposition","name":"LupDecomposition","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":12,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix(T)","name":"Matrix"},"doc":"For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n\nunit lower triangular matrix L, an n-by-n upper triangular matrix U,\nand a m-by-m permutation matrix P so that L*U = P*A.\nIf m < n, then L is m-by-m and U is m-by-n.\n\nThe LUP decomposition with pivoting always exists, even if the matrix is\nsingular, so the constructor will never fail. The primary use of the\nLU decomposition is in the solution of square systems of simultaneous\nlinear equations. This will fail if singular? returns true.","summary":"For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a m-by-m permutation matrix P so that LU = PA.
","class_methods":[],"constructors":[{"id":"new(matrix)-class-method","html_id":"new(matrix)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"args_string":"(matrix)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/lup_decomposition.cr#L13","def":{"name":"new","args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(matrix)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/NDArray","path":"Apatite/LinearAlgebra/NDArray.html","kind":"class","full_name":"Apatite::LinearAlgebra::NDArray","name":"NDArray","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/ndarray.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(data:Array(Number),shape:Array(Int32)?=nil)-class-method","html_id":"new(data:Array(Number),shape:Array(Int32)?=nil)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array(Number)"},{"name":"shape","doc":null,"default_value":"nil","external_name":"shape","restriction":"Array(Int32) | ::Nil"}],"args_string":"(data : Array(Number), shape : Array(Int32)? = nil)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L18","def":{"name":"new","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array(Number)"},{"name":"shape","doc":null,"default_value":"nil","external_name":"shape","restriction":"Array(Int32) | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(data, shape)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"[](*args,**options)-instance-method","html_id":"[](*args,**options)-instance-method","name":"[]","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"[]","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]"}},{"id":"[](*args,**options,&block)-instance-method","html_id":"[](*args,**options,&block)-instance-method","name":"[]","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"[]","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options] do |*yield_args|\n yield *yield_args\nend"}},{"id":"[]=(*args,**options)-instance-method","html_id":"[]=(*args,**options)-instance-method","name":"[]=","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L13","def":{"name":"[]=","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args] = **options"}},{"id":"[]?(*args,**options)-instance-method","html_id":"[]?(*args,**options)-instance-method","name":"[]?","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L12","def":{"name":"[]?","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]?"}},{"id":"[]?(*args,**options,&block)-instance-method","html_id":"[]?(*args,**options,&block)-instance-method","name":"[]?","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L12","def":{"name":"[]?","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]? do |*yield_args|\n yield *yield_args\nend"}},{"id":"abs-instance-method","html_id":"abs-instance-method","name":"abs","doc":"Returns the absolute value of every item in the array","summary":"Returns the absolute value of every item in the array
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L24","def":{"name":"abs","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |e|\n e.abs\nend"}},{"id":"acos-instance-method","html_id":"acos-instance-method","name":"acos","doc":"Returns the arccosine of each element in the current array.","summary":"Returns the arccosine of each element in the current array.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L29","def":{"name":"acos","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"data:Array(Float64)-instance-method","html_id":"data:Array(Float64)-instance-method","name":"data","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Array(Float64)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L9","def":{"name":"data","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(Float64)","visibility":"Public","body":"@data"}},{"id":"shape:Array(Int32)-instance-method","html_id":"shape:Array(Int32)-instance-method","name":"shape","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Array(Int32)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"shape","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(Int32)","visibility":"Public","body":"@shape"}},{"id":"size(*args,**options)-instance-method","html_id":"size(*args,**options)-instance-method","name":"size","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L16","def":{"name":"size","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.size(*args, **options)"}},{"id":"size(*args,**options,&block)-instance-method","html_id":"size(*args,**options,&block)-instance-method","name":"size","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L16","def":{"name":"size","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.size(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"to_unsafe(*args,**options)-instance-method","html_id":"to_unsafe(*args,**options)-instance-method","name":"to_unsafe","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L15","def":{"name":"to_unsafe","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.to_unsafe(*args, **options)"}},{"id":"to_unsafe(*args,**options,&block)-instance-method","html_id":"to_unsafe(*args,**options,&block)-instance-method","name":"to_unsafe","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L15","def":{"name":"to_unsafe","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.to_unsafe(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"unsafe_fetch(*args,**options)-instance-method","html_id":"unsafe_fetch(*args,**options)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L14","def":{"name":"unsafe_fetch","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.unsafe_fetch(*args, **options)"}},{"id":"unsafe_fetch(*args,**options,&block)-instance-method","html_id":"unsafe_fetch(*args,**options,&block)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L14","def":{"name":"unsafe_fetch","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.unsafe_fetch(*args, **options) do |*yield_args|\n yield *yield_args\nend"}}],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Vector","path":"Apatite/LinearAlgebra/Vector.html","kind":"class","full_name":"Apatite::LinearAlgebra::Vector(T)","name":"Vector","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/vector.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":"Represents a mathematical vector, and also constitutes a row or column\nof a `Matrix`","summary":"Represents a mathematical vector, and also constitutes a row or column of a Matrix
Creates a new vector from a list of elements.
","abstract":false,"args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""}],"args_string":"(*array)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L22","def":{"name":"[]","args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new(array)"}},{"id":"basis(size,index)-class-method","html_id":"basis(size,index)-class-method","name":"basis","doc":"Returns a standard basis `n`-vector.","summary":"Returns a standard basis n
-vector.
Creates a vector from an Array.
","abstract":false,"args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(array, copy = true)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L28","def":{"name":"elements","args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if copy\n array = array.clone\nend\nnew(array)\n"}},{"id":"zero(size)-class-method","html_id":"zero(size)-class-method","name":"zero","doc":"Return a zero vector.","summary":"Return a zero vector.
","abstract":false,"args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""}],"args_string":"(size)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L53","def":{"name":"zero","args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size < 0\n raise(ArgumentError.new(\"invalid size (#{size} for 0..)\"))\nend\narray = Array.new(size, 0)\nnew(array)\n"}}],"constructors":[],"instance_methods":[{"id":"*(x)-instance-method","html_id":"*(x)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is a number or a matrix.","summary":"Multiplies the vector by x, where x is a number or a matrix.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L60","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e * x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg0|\n x = __arg0[0]\n y = __arg0[1]\n x * y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"+(x)-instance-method","html_id":"+(x)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L75","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e + x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg1|\n x = __arg1[0]\n y = __arg1[1]\n x + y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"-(x)-instance-method","html_id":"-(x)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L90","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e - x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg2|\n x = __arg2[0]\n y = __arg2[1]\n x - y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"/(x)-instance-method","html_id":"/(x)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L105","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e / x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg3|\n x = __arg3[0]\n y = __arg3[1]\n x / y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"-instance-method","html_id":"-instance-method","name":"<=>","doc":"Take me to your leader","summary":"Take me to your leader
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L129","def":{"name":"<=>","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if other.is_a?(Vector)\n @elements <=> other.elements\nelse\n @elements <=> other\nend"}},{"id":"==(other)-instance-method","html_id":"==(other)-instance-method","name":"==","doc":"Equality operator","summary":"Equality operator
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L120","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if other.is_a?(Vector)\n @elements == other.elements\nelse\n @elements == other\nend"}},{"id":"angle_with(v)-instance-method","html_id":"angle_with(v)-instance-method","name":"angle_with","doc":"Returns an angle with another vector. Result is within the [0…Math::PI].","summary":"Returns an angle with another vector.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L138","def":{"name":"angle_with","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\nprod = magnitude * v.magnitude\nif prod == 0\n raise(ZeroVectorError.new(\"Can't get angle of zero vector\"))\nend\nMath.acos((inner_product(v)) / prod)\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":"Returns a copy of the vector.","summary":"Returns a copy of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L147","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.elements(@elements)"}},{"id":"coerce(klass,*args)-instance-method","html_id":"coerce(klass,*args)-instance-method","name":"coerce","doc":"The coerce method allows you to attempt to coerce the elements\nin the matrix to another type. The type","summary":"The coerce method allows you to attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(klass, *args)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L249","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case klass.to_s\nwhen \"Complex\"\n if args[0]?\n else\n raise(\"coercing to a Complex requires a second argument\")\n end\n els = @elements.map do |e|\n Complex.new(e, args[0].as(Int32))\n end\nwhen \"BigInt\"\n base = args[0]? || 10\n els = @elements.map do |e|\n klass.new(e, base)\n end\nwhen \"BigRational\"\n if args[0]?\n else\n raise(\"coercing to a BigRational requires a second argument to use as a denominator\")\n end\n els = @elements.map do |e|\n klass.new(e, args[0])\n end\nelse\n els = @elements.map do |e|\n klass.new(e)\n end\nend\nVector.elements(els)\n"}},{"id":"cross(v)-instance-method","html_id":"cross(v)-instance-method","name":"cross","doc":"Returns the cross product of this vector with the others.","summary":"Returns the cross product of this vector with the others.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L193","def":{"name":"cross","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"cross_product(v)"}},{"id":"cross_product(*vs)-instance-method","html_id":"cross_product(*vs)-instance-method","name":"cross_product","doc":"Returns the cross product of this vector with the others.","summary":"Returns the cross product of this vector with the others.
","abstract":false,"args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"args_string":"(*vs)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L170","def":{"name":"cross_product","args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size >= 2\nelse\n raise(ErrOperationNotDefined.new(\"cross product is not defined on vectors of dimension #{size}\"))\nend\nif vs.size == (size - 2)\nelse\n raise(ArgumentError.new(\"wrong number of arguments (#{vs.size} for #{size - 2})\"))\nend\nvs.each do |v|\n if v.size == size\n else\n raise(ErrDimensionMismatch.new)\n end\nend\ncase size\nwhen 2\n Vector[-@elements[1], @elements[0]]\nwhen 3\n v = vs[0]\n Vector[(v[2] * @elements[1]) - (v[1] * @elements[2]), (v[0] * @elements[2]) - (v[2] * @elements[0]), (v[1] * @elements[0]) - (v[0] * @elements[1])]\nelse\n rows = (self + vs) + (Array.new(size) do |i|\n Vector.basis(size, i)\n end)\n (Matrix.rows(rows)).laplace_expansion(row: size - 1)\nend\n"}},{"id":"dot(v)-instance-method","html_id":"dot(v)-instance-method","name":"dot","doc":"Returns the inner product of this vector with the other.","summary":"Returns the inner product of this vector with the other.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L207","def":{"name":"dot","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"inner_product(v)"}},{"id":"each(*args,**options)-instance-method","html_id":"each(*args,**options)-instance-method","name":"each","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L14","def":{"name":"each","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.each(*args, **options)"}},{"id":"each(*args,**options,&block)-instance-method","html_id":"each(*args,**options,&block)-instance-method","name":"each","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L14","def":{"name":"each","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.each(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"each2(v,&block)-instance-method","html_id":"each2(v,&block)-instance-method","name":"each2","doc":"Iterate over the elements of this vector and `v` in conjunction.","summary":"Iterate over the elements of this vector and v
in conjunction.
Returns the inner product of this vector with the other.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L198","def":{"name":"inner_product","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\np = 0\neach2(v) do |v1, v2|\n p = p + (v1 * v2)\nend\np\n"}},{"id":"inspect-instance-method","html_id":"inspect-instance-method","name":"inspect","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L286","def":{"name":"inspect","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"<#Vector(#{T}) [#{@elements.join(\", \")}]>\""}},{"id":"magnitude-instance-method","html_id":"magnitude-instance-method","name":"magnitude","doc":"Returns the modulus (Pythagorean distance) of the vector.","summary":"Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L221","def":{"name":"magnitude","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Math.sqrt(@elements.reduce(0) do |v, e|\n v + e.abs2\nend)"}},{"id":"map(&block:T->UNDERSCORE)-instance-method","html_id":"map(&block:T->UNDERSCORE)-instance-method","name":"map","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"(&block : T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L151","def":{"name":"map","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> _)"},"return_type":"","visibility":"Public","body":"els = @elements.map(&block)\nself.class.elements(els, false)\n"}},{"id":"map2(v,&block:T,T->UNDERSCORE)-instance-method","html_id":"map2(v,&block:T,T->UNDERSCORE)-instance-method","name":"map2","doc":null,"summary":null,"abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v, &block : T, T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L156","def":{"name":"map2","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":2,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T, T -> _)"},"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\narr = Array.new(size) do |i|\n yield @elements[i], v[i]\nend\nself.class.elements(arr, false)\n"}},{"id":"norm-instance-method","html_id":"norm-instance-method","name":"norm","doc":"Returns the modulus (Pythagorean distance) of the vector.","summary":"Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L226","def":{"name":"norm","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"magnitude"}},{"id":"normalize-instance-method","html_id":"normalize-instance-method","name":"normalize","doc":"Returns a new vector with the same direction but with norm 1","summary":"Returns a new vector with the same direction but with norm 1
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L231","def":{"name":"normalize","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"n = magnitude\nif n == 0\n raise(ZeroVectorError.new(\"Zero vectors can not be normalized\"))\nend\nself / n\n"}},{"id":"r-instance-method","html_id":"r-instance-method","name":"r","doc":"Returns a new vector with the same direction but with norm 1","summary":"Returns a new vector with the same direction but with norm 1
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L238","def":{"name":"r","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"magnitude"}},{"id":"round(ndigits=0)-instance-method","html_id":"round(ndigits=0)-instance-method","name":"round","doc":"Returns a vector with entries rounded to the given precision.","summary":"Returns a vector with entries rounded to the given precision.
","abstract":false,"args":[{"name":"ndigits","doc":null,"default_value":"0","external_name":"ndigits","restriction":""}],"args_string":"(ndigits = 0)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L243","def":{"name":"round","args":[{"name":"ndigits","doc":null,"default_value":"0","external_name":"ndigits","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |e|\n e.round(ndigits)\nend"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Returns the elements of the vector in an array.","summary":"Returns the elements of the vector in an array.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L268","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.dup"}},{"id":"to_matrix-instance-method","html_id":"to_matrix-instance-method","name":"to_matrix","doc":"Return a single-column matrix from this vector.","summary":"Return a single-column matrix from this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L273","def":{"name":"to_matrix","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.column_vector(self)"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L277","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(\"Vector{\" + (@elements.join(\", \"))) + \"}\""}},{"id":"unsafe_fetch(i)-instance-method","html_id":"unsafe_fetch(i)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L290","def":{"name":"unsafe_fetch","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.unsafe_fetch(i)"}},{"id":"zero?-instance-method","html_id":"zero?-instance-method","name":"zero?","doc":"Returns `true` if all elements are zero.","summary":"Returns true
if all elements are zero.
An Array
is an ordered, integer-indexed collection of objects of type T.
Tests whether all elements evaluate to true
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/core_ext/array.cr#L3","def":{"name":"all?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"each do |i|\n if (!(!i)) == false\n return false\n end\nend\ntrue\n"}},{"id":"any?-instance-method","html_id":"any?-instance-method","name":"any?","doc":"Tests whether any of the elements evaluate to true","summary":"Tests whether any of the elements evaluate to true
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/core_ext/array.cr#L11","def":{"name":"any?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"each do |i|\n if (!(!i)) == true\n return true\n end\nend\nfalse\n"}},{"id":"shape-instance-method","html_id":"shape-instance-method","name":"shape","doc":"Get the array's dimensions","summary":"Get the array's dimensions
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/core_ext/array.cr#L19","def":{"name":"shape","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"max = max_by do |i|\n i.is_a?(Array) ? i.size : i\nend\nmax.is_a?(Array) ? [size, max.size] : [max]\n"}},{"id":"to_vec-instance-method","html_id":"to_vec-instance-method","name":"to_vec","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/core_ext/array.cr#L24","def":{"name":"to_vec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite::Vector.create(self)"}}],"macros":[],"types":[]}]}} \ No newline at end of file diff --git a/docs/search-index.js b/docs/search-index.js index 4fe69a2..4dfdb92 100644 --- a/docs/search-index.js +++ b/docs/search-index.js @@ -1 +1 @@ -crystal_doc_search_index_callback({"repository_name":"github.com/watzon/apatite","body":"# Apatite\n\nApatite is meant to be a collecion of mathmatical and scientific computing algorithms for the Crystal programming language. I don't expect it to ever reach the level of completeness as numpy, but hopefully it can save some people the trouble of implementing these methods on their own.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n apatite:\n github: watzon/apatite\n ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"apatite\"\n```\n\nCheck out the [documentation](https://watzon.github.io/apatite/) for usage examples.\n\n## Roadmap\n\n- [ ] Linear Algebra\n\t- [x] Vector\n\t- [ ] Matrix (_in progress_)\n\t- [ ] NDArray\n\t- [ ] Line\n\t- [ ] Plane\n\t- [ ] Polygon\n\t- [ ] LinkedList\n\t\n\n\n## Contributing\n\n1. Fork it (Apatite is a fundimental package for scientific computing in Crystal.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","path":"Apatite/LinearAlgebra.html","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"},{"filename":"apatite/linear_algebra/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr"},{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr"},{"filename":"apatite/linear_algebra.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra.cr"},{"filename":"apatite/linear_algebra/ndarray.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"}],"subclasses":[],"including_types":[{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"}],"namespace":{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"sigmoid(input:Number)-instance-method","html_id":"sigmoid(input:Number)-instance-method","name":"sigmoid","doc":"Calculates the sigmoid curve for a numeric input.\n\n`f(x) = 1/(1 + e^-x)`\n\nSee also: [Sigmoid function (WikiWand)](https://www.wikiwand.com/en/Sigmoid_function)","summary":"Calculates the sigmoid curve for a numeric input.
","abstract":false,"args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"args_string":"(input : Number)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra.cr#L15","def":{"name":"sigmoid","args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = input.to_f64\n1 / (1 + (Math.exp(-num)))\n"}},{"id":"sigmoid_d(input:Number)-instance-method","html_id":"sigmoid_d(input:Number)-instance-method","name":"sigmoid_d","doc":"Calculates the derivative sigmoid curve for a numeric input.\n\n`f'(x) = f(x)(1 - f(x)),`","summary":"Calculates the derivative sigmoid curve for a numeric input.
","abstract":false,"args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"args_string":"(input : Number)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra.cr#L23","def":{"name":"sigmoid_d","args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = input.to_f64\nnum * (1 - num)\n"}}],"macros":[],"types":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrDimensionMismatch","path":"Apatite/LinearAlgebra/ErrDimensionMismatch.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrDimensionMismatch","name":"ErrDimensionMismatch","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrNotRegular","path":"Apatite/LinearAlgebra/ErrNotRegular.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrNotRegular","name":"ErrNotRegular","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrOperationNotDefined","path":"Apatite/LinearAlgebra/ErrOperationNotDefined.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrOperationNotDefined","name":"ErrOperationNotDefined","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":8,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(method,this,other)-class-method","html_id":"new(method,this,other)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"method","doc":null,"default_value":"","external_name":"method","restriction":""},{"name":"this","doc":null,"default_value":"","external_name":"this","restriction":""},{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(method, this, other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr#L9","def":{"name":"new","args":[{"name":"method","doc":null,"default_value":"","external_name":"method","restriction":""},{"name":"this","doc":null,"default_value":"","external_name":"this","restriction":""},{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(method, this, other)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","path":"Apatite/LinearAlgebra/Error.html","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":3,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrDimensionMismatch","kind":"class","full_name":"Apatite::LinearAlgebra::ErrDimensionMismatch","name":"ErrDimensionMismatch"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrNotRegular","kind":"class","full_name":"Apatite::LinearAlgebra::ErrNotRegular","name":"ErrNotRegular"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrOperationNotDefined","kind":"class","full_name":"Apatite::LinearAlgebra::ErrOperationNotDefined","name":"ErrOperationNotDefined"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ZeroVectorError","kind":"class","full_name":"Apatite::LinearAlgebra::ZeroVectorError","name":"ZeroVectorError"}],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix","path":"Apatite/LinearAlgebra/Matrix.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix(T)","name":"Matrix","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"SELECTORS","name":"SELECTORS","value":"{all: true, diagonal: true, off_diagonal: true, lower: true, strict_lower: true, strict_upper: true, upper: true}","doc":null,"summary":null}],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[{"id":"[](*rows)-class-method","html_id":"[](*rows)-class-method","name":"[]","doc":"Creates a matrix where each argument is a row.\n\n```\nMatrix[[25, 93], [-1, 66]]\n# => [ 25, 93,\n# -1, 66 ]\n```","summary":"Creates a matrix where each argument is a row.
","abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"args_string":"(*rows)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L21","def":{"name":"[]","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows(rows, false)"}},{"id":"build(row_count,column_count=row_count,&block:Int32,Int32->T)-class-method","html_id":"build(row_count,column_count=row_count,&block:Int32,Int32->T)-class-method","name":"build","doc":"Creates a matrix of size +row_count+ x +column_count+.\nIt fills the values by calling the given block,\npassing the current row and column.\nReturns an enumerator if no block is given.\n\n```\nm = Matrix.build(2, 4) { |row, col| col - row }\n# => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]\nm = Matrix.build(3) { rand }\n# => a 3x3 matrix with random elements\n```","summary":"Creates a matrix of size +row_count+ x +column_count+.
","abstract":false,"args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"args_string":"(row_count, column_count = row_count, &block : Int32, Int32 -> T)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L70","def":{"name":"build","args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"double_splat":null,"splat_index":null,"yields":2,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(Int32, Int32 -> T)"},"return_type":"","visibility":"Public","body":"row_count = row_count.to_i\ncolumn_count = column_count.to_i\nif row_count < 0 || column_count < 0\n raise(ArgumentError.new)\nend\nrows = Array(T).new(row_count) do |i|\n Array(T).new(column_count) do |j|\n yield i, j\n end\nend\nnew(rows, column_count)\n"}},{"id":"column_vector(column)-class-method","html_id":"column_vector(column)-class-method","name":"column_vector","doc":"Creates a single-column matrix where the values of that column are as given\nin `column`.\n\n```\nMatrix.column_vector([4,5,6])\n# => [ 4,\n# 5,\n# 6 ]\n```","summary":"Creates a single-column matrix where the values of that column are as given in #column
.
Creates a matrix using +columns+ as an array of column vectors.
","abstract":false,"args":[{"name":"columns","doc":null,"default_value":"","external_name":"columns","restriction":""}],"args_string":"(columns)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L55","def":{"name":"columns","args":[{"name":"columns","doc":null,"default_value":"","external_name":"columns","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(rows(columns, false)).transpose"}},{"id":"combine(*matrices,&block)-class-method","html_id":"combine(*matrices,&block)-class-method","name":"combine","doc":"Create a matrix by combining matrices entrywise, using the given block\n\n```\nx = Matrix[[6, 6], [4, 4]]\ny = Matrix[[1, 2], [3, 4]]\nMatrix.combine(x, y) {|a, b| a - b}\n# => Matrix[[5, 4], [1, 0]]\n```","summary":"Create a matrix by combining matrices entrywise, using the given block
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L245","def":{"name":"combine","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"if matrices.empty?\n return Matrix.empty\nend\nmatrices = matrices.map do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\nend\nx = matrices.first\nmatrices.each do |m|\n if (x.row_count == m.row_count) && (x.column_count == m.column_count)\n else\n raise(ErrDimensionMismatch.new)\n end\nend\nrows = Array(T).new(x.row_count) do |i|\n Array(T).new(x.column_count) do |j|\n yield matrices.map do |m|\n m[i, j]\n end\n end\nend\nnew(rows, x.column_count)\n"}},{"id":"diagonal(values:Indexable(T),dummy=nil)-class-method","html_id":"diagonal(values:Indexable(T),dummy=nil)-class-method","name":"diagonal","doc":"Creates a matrix where the diagonal elements are composed of `values`.\n\n```\nMatrix.diagonal(9, 5, -3)\n# => [ 9, 0, 0,\n# 0, 5, 0,\n# 0, 0, -3 ]\n```","summary":"Creates a matrix where the diagonal elements are composed of values
.
Creates a empty matrix of #row_count
x #column_count
.
Create a matrix by stacking matrices horizontally
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(x, *matrices)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L217","def":{"name":"hstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"result = x.rows\ntotal_column_count = x.column_count\nmatrices.each do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\n if m.row_count != x.row_count\n raise(ErrDimensionMismatch.new(\"The given matrices must have #{x.row_count} rows, but one has #{m.row_count}\"))\n end\n result.each_with_index do |row, i|\n row.concat(m.rows[i])\n end\n total_column_count = total_column_count + m.column_count\nend\nnew(result, total_column_count)\n"}},{"id":"identity(n)-class-method","html_id":"identity(n)-class-method","name":"identity","doc":"Creates an `n` by `n` identity matrix.\n\n```\nMatrix.identity(2)\n# => [ 1, 0,\n# 0, 1 ]\n```","summary":"Creates an n
by n
identity matrix.
Creates a single-row matrix where the values of that row are as given in #row
.
Creates a matrix where +rows+ is an array of arrays, each of which is a row of the matrix.
","abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Array(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(rows : Indexable(Array(T)), copy = true)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L34","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Array(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if copy\n rows = rows.dup\nend\nrows = rows.to_a\nrows.map! do |row|\n if row\n row = row.dup\n end\n row.to_a\nend\nsize = (rows[0] || ([] of T)).size\nrows.each_with_index do |row, i|\n if row.size == size\n else\n raise(ErrDimensionMismatch.new(\"row size differs (row at index `#{i}` should contain #{size} elements, instead has #{row.size})\"))\n end\nend\nnew(rows, size)\n"}},{"id":"scalar(n,value:T)-class-method","html_id":"scalar(n,value:T)-class-method","name":"scalar","doc":"Creates an +n+ by +n+ diagonal matrix where each diagonal element is\n`value`.\n\n```\nMatrix.scalar(2, 5)\n# => [ 5, 0,\n# 0, 5 ]\n```","summary":"Creates an +n+ by +n+ diagonal matrix where each diagonal element is value
.
Creates an n
by n
identity matrix.
Create a matrix by stacking matrices vertically
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(x, *matrices)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L197","def":{"name":"vstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"result = x.rows\nmatrices.each do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\n if m.column_count != x.column_count\n raise(ErrDimensionMismatch.new(\"The given matrices must have #{x.column_count} columns, but one has #{m.column_count}\"))\n end\n result.concat(m.rows)\nend\nnew(result, x.column_count)\n"}},{"id":"zero(row_count,column_count=row_count)-class-method","html_id":"zero(row_count,column_count=row_count)-class-method","name":"zero","doc":"Creates a zero matrix.\n\n```\nMatrix.zero(2)\n# => [ 0, 0,\n# 0, 0 ]\n```","summary":"Creates a zero matrix.
","abstract":false,"args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"args_string":"(row_count, column_count = row_count)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L140","def":{"name":"zero","args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = Array(T).new(row_count) do\n Array(T).new(column_count, T.new(0))\nend\nnew(rows, column_count)\n"}}],"constructors":[],"instance_methods":[{"id":"*(other)-instance-method","html_id":"*(other)-instance-method","name":"*","doc":"Matrix multiplication\n\n```\nMatrix[[2,4], [6,8]] * Matrix.identity(2)\n# => [ 2, 4,\n# 6, 8 ]\n```","summary":"Matrix multiplication
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L891","def":{"name":"*","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Number\n rows = @rows.map do |row|\n row.map do |e|\n (e * other).as(T)\n end\n end\n Matrix.new(rows, column_count)\nwhen Vector\n m = Matrix.column_vector(other)\n r = self * m\n r.column(0)\nwhen Matrix\n if column_count != other.column_count\n raise(ErrDimensionMismatch.new)\n end\n rows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (0...column_count).reduce(0) do |vij, k|\n vij + (self[i, k] * other[k, j])\n end\n end\n end\n Matrix.new(rows, column_count)\nelse\n self * (Matrix.rows(other))\nend"}},{"id":"**(other)-instance-method","html_id":"**(other)-instance-method","name":"**","doc":"Matrix exponentiation.\n\nEquivalent to multiplying the matrix by itself N times.\nNon integer exponents will be handled by diagonalizing the matrix.\n\n```\nMatrix[[7,6], [3,9]] ** 2\n# => [ 67, 96,\n# 48, 99 ]\n```","summary":"Matrix exponentiation.
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1061","def":{"name":"**","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"+(other:Matrix|Indexable)-instance-method","html_id":"+(other:Matrix|Indexable)-instance-method","name":"+","doc":"Matrix addition\n\n```\nMatrix.scalar(2,5) + Matrix[[1,0], [-4,7]]\n# => [ 6, 0,\n# -4, 1 ]\n```","summary":"Matrix addition
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"args_string":"(other : Matrix | Indexable)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L924","def":{"name":"+","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n other = Matrix.column_vector(other)\nwhen Matrix\nelse\n other = Matrix.rows(other)\nend\nif (row_count == other.row_count) && (column_count == other.column_count)\nelse\n raise(ErrDimensionMismatch.new)\nend\nrows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (self[i, j] + other[i, j]).as(T)\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"-(other:Matrix|Indexable)-instance-method","html_id":"-(other:Matrix|Indexable)-instance-method","name":"-","doc":"Matrix subtraction\n\n```\nMatrix[[1,5], [4,2]] - Matrix[[9,3], [-4,1]]\n# => [-8, 2,\n# 8, 1 ]\n```","summary":"Matrix subtraction
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"args_string":"(other : Matrix | Indexable)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L951","def":{"name":"-","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n other = Matrix.column_vector(other)\nwhen Matrix\nelse\n other = Matrix.rows(other)\nend\nif (row_count == other.row_count) && (column_count == other.column_count)\nelse\n raise(ErrDimensionMismatch.new)\nend\nrows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (self[i, j] - other[i, j]).as(T)\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"/(other)-instance-method","html_id":"/(other)-instance-method","name":"/","doc":"Matrix division (multiplication by the inverse).\n\n```\nMatrix[[7,6], [3,9]] / Matrix[[2,9], [3,1]]\n# => [ -7, 1,\n# -3, -6 ]\n```","summary":"Matrix division (multiplication by the inverse).
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L978","def":{"name":"/","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Number\n rows = @rows.map do |row|\n row.map do |e|\n (e / other).as(T)\n end\n end\n return Matrix.new(rows, column_count)\nwhen Matrix\n return self * other.inverse\nelse\n self / (Matrix.rows(other))\nend"}},{"id":"==(other:Matrix)-instance-method","html_id":"==(other:Matrix)-instance-method","name":"==","doc":"Equality operator","summary":"Equality operator
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix"}],"args_string":"(other : Matrix)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L868","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(rows == other.rows) && (column_count == other.column_count)"}},{"id":"[](i,j)-instance-method","html_id":"[](i,j)-instance-method","name":"[]","doc":"Returns element (`i`, `j`) of the matrix. That is: row `i`, column `j`.\nRaises if either index is not found.","summary":"Returns element (i
, j
) of the matrix.
Returns row i
of the matrix as an Array.
Set the value at index (i
, j
).
Returns element (i
, j
) of the matrix.
Returns row i
of the matrix as an Array.
Returns the adjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L626","def":{"name":"adjugate","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nMatrix.build(row_count, column_count) do |row, column|\n cofactor(column, row)\nend\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":"Returns a clone of the matrix, so that the contents of each do not reference\nidentical objects.\n\nThere should be no good reason to do this since Matrices are immutable.","summary":"Returns a clone of the matrix, so that the contents of each do not reference identical objects.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L876","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.new(@rows.map(&.dup), column_count)"}},{"id":"coerce(klass)-instance-method","html_id":"coerce(klass)-instance-method","name":"coerce","doc":"Attempt to coerce the elements in the matrix to another type.","summary":"Attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""}],"args_string":"(klass)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1365","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rws = @rows.map do |r|\n r.map do |i|\n klass.new(i)\n end\nend\nMatrix.rows(rws)\n"}},{"id":"cofactor(row,column)-instance-method","html_id":"cofactor(row,column)-instance-method","name":"cofactor","doc":"Returns the (row, column) cofactor which is obtained by multiplying\nthe first minor by (-1)**(row + column).\n\n```\nMatrix.diagonal(9, 5, -3, 4).cofactor(1, 1)\n# => -108\n```","summary":"Returns the (row, column) cofactor which is obtained by multiplying the first minor by (-1)**(row + column).
","abstract":false,"args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(row, column)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L612","def":{"name":"cofactor","args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n raise(\"cofactor of empty matrix is not defined\")\nend\nif square?\nelse\n raise(ErrDimensionMismatch.new)\nend\ndet_of_minor = (first_minor(row, column)).determinant\ndet_of_minor * ((-1) ** (row + column))\n"}},{"id":"column(j,&block:T->)-instance-method","html_id":"column(j,&block:T->)-instance-method","name":"column","doc":"Returns a block which yields every item in column `j` of the Matrix.","summary":"Returns a block which yields every item in column j
of the Matrix.
Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns the number of columns.
","abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L314","def":{"name":"column_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@column_count"}},{"id":"combine(*matrices,&block)-instance-method","html_id":"combine(*matrices,&block)-instance-method","name":"combine","doc":"Create a matrix by combining matrices entrywise, using the given block\n\n```\nx = Matrix[[6, 6], [4, 4]]\ny = Matrix[[1, 2], [3, 4]]\nMatrix.combine(x, y) {|a, b| a - b}\n# => Matrix[[5, 4], [1, 0]]\n```","summary":"Create a matrix by combining matrices entrywise, using the given block
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L264","def":{"name":"combine","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"return_type":"","visibility":"Public","body":"Matrix.combine(self, *matrices, &block)"}},{"id":"conj-instance-method","html_id":"conj-instance-method","name":"conj","doc":"Returns the conjugate of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => 1+2i i 0\n# 1 2 3\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].conj\n# => 1-2i -i 0\n# 1 2 3\n```","summary":"Returns the conjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1313","def":{"name":"conj","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#conj only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.conj)\n"}},{"id":"determinant-instance-method","html_id":"determinant-instance-method","name":"determinant","doc":"Returns the determinant of the matrix.\n\nBeware that using Float values can yield erroneous results\nbecause of their lack of precision.\nConsider using exact types like Rational or BigDecimal instead.\n\n```\nMatrix[[7,6], [3,9]].determinant\n# => 45\n```","summary":"Returns the determinant of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1079","def":{"name":"determinant","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nm = rows\ncase row_count\nwhen 0\n +1\nwhen 1\n +m[0][0]\nwhen 2\n ((+m[0][0]) * m[1][1]) - (m[0][1] * m[1][0])\nwhen 3\n m0, m1, m2 = m\n (((((((+m0[0]) * m1[1]) * m2[2]) - ((m0[0] * m1[2]) * m2[1])) - ((m0[1] * m1[0]) * m2[2])) + ((m0[1] * m1[2]) * m2[0])) + ((m0[2] * m1[0]) * m2[1])) - ((m0[2] * m1[1]) * m2[0])\nwhen 4\n m0, m1, m2, m3 = m\n ((((((((((((((((((((((((((+m0[0]) * m1[1]) * m2[2]) * m3[3]) - (((m0[0] * m1[1]) * m2[3]) * m3[2])) - (((m0[0] * m1[2]) * m2[1]) * m3[3])) + (((m0[0] * m1[2]) * m2[3]) * m3[1])) + (((m0[0] * m1[3]) * m2[1]) * m3[2])) - (((m0[0] * m1[3]) * m2[2]) * m3[1])) - (((m0[1] * m1[0]) * m2[2]) * m3[3])) + (((m0[1] * m1[0]) * m2[3]) * m3[2])) + (((m0[1] * m1[2]) * m2[0]) * m3[3])) - (((m0[1] * m1[2]) * m2[3]) * m3[0])) - (((m0[1] * m1[3]) * m2[0]) * m3[2])) + (((m0[1] * m1[3]) * m2[2]) * m3[0])) + (((m0[2] * m1[0]) * m2[1]) * m3[3])) - (((m0[2] * m1[0]) * m2[3]) * m3[1])) - (((m0[2] * m1[1]) * m2[0]) * m3[3])) + (((m0[2] * m1[1]) * m2[3]) * m3[0])) + (((m0[2] * m1[3]) * m2[0]) * m3[1])) - (((m0[2] * m1[3]) * m2[1]) * m3[0])) - (((m0[3] * m1[0]) * m2[1]) * m3[2])) + (((m0[3] * m1[0]) * m2[2]) * m3[1])) + (((m0[3] * m1[1]) * m2[0]) * m3[2])) - (((m0[3] * m1[1]) * m2[2]) * m3[0])) - (((m0[3] * m1[2]) * m2[0]) * m3[1])) + (((m0[3] * m1[2]) * m2[1]) * m3[0])\nelse\n determinant_bareiss\nend\n"}},{"id":"diagonal?-instance-method","html_id":"diagonal?-instance-method","name":"diagonal?","doc":"Returns `true` if this is a diagonal matrix.\n","summary":"Returns true
if this is a diagonal matrix.
Yields all elements of the matrix, starting with those of the first row, or returns an Enumerator if no block given.
","abstract":false,"args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"args_string":"(which = :all, &block : T -> )","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L380","def":{"name":"each","args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> )"},"return_type":"","visibility":"Public","body":"last = column_count\ncase which.to_s\nwhen \"all\"\n @rows.each do |row|\n row.each(&block)\n end\nwhen \"diagonal\"\n @rows.each_with_index do |row, row_index|\n yield row.fetch(row_index) do\n return self\n end\n end\nwhen \"off_diagonal\"\n @rows.each_with_index do |row, row_index|\n column_count.times do |col_index|\n if row_index == col_index\n else\n yield row[col_index]\n end\n end\n end\nwhen \"lower\"\n @rows.each_with_index do |row, row_index|\n 0.upto([row_index, last].min) do |col_index|\n yield row[col_index]\n end\n end\nwhen \"strict_lower\"\n @rows.each_with_index do |row, row_index|\n [row_index, column_count].min.times do |col_index|\n yield row[col_index]\n end\n end\nwhen \"strict_upper\"\n @rows.each_with_index do |row, row_index|\n (row_index + 1).upto(last - 1) do |col_index|\n yield row[col_index]\n end\n end\nwhen \"upper\"\n @rows.each_with_index do |row, row_index|\n row_index.upto(last - 1) do |col_index|\n yield row[col_index]\n end\n end\nelse\n raise(ArgumentError.new(\"expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper\"))\nend\n"}},{"id":"each_with_index(which=:all,&block:T,Int32,Int32->)-instance-method","html_id":"each_with_index(which=:all,&block:T,Int32,Int32->)-instance-method","name":"each_with_index","doc":"Same as #each, but the row index and column index in addition to the element\n\n```\nMatrix[ [1,2], [3,4] ].each_with_index do |e, row, col|\nputs \"#{e} at #{row}, #{col}\"\nend\n# => Prints:\n# 1 at 0, 0\n# 2 at 0, 1\n# 3 at 1, 0\n# 4 at 1, 1\n```","summary":"Same as #each, but the row index and column index in addition to the element
","abstract":false,"args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"args_string":"(which = :all, &block : T, Int32, Int32 -> )","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L438","def":{"name":"each_with_index","args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"double_splat":null,"splat_index":null,"yields":3,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T, Int32, Int32 -> )"},"return_type":"","visibility":"Public","body":"last = column_count\ncase which.to_s\nwhen \"all\"\n @rows.each_with_index do |row, row_index|\n row.each_with_index do |e, col_index|\n block.call(e, row_index, col_index)\n end\n end\nwhen \"diagonal\"\n @rows.each_with_index do |row, row_index|\n block.call(row.fetch(row_index) do\n return self\n end, row_index, row_index)\n end\nwhen \"off_diagonal\"\n @rows.each_with_index do |row, row_index|\n column_count.times do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"lower\"\n @rows.each_with_index do |row, row_index|\n 0.upto([row_index, last].min) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"strict_lower\"\n @rows.each_with_index do |row, row_index|\n [row_index, column_count].min.times do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"strict_upper\"\n @rows.each_with_index do |row, row_index|\n (row_index + 1).upto(last - 1) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"upper\"\n @rows.each_with_index do |row, row_index|\n row_index.upto(last - 1) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nelse\n raise(ArgumentError.new(\"expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper\"))\nend\n"}},{"id":"eigensystem-instance-method","html_id":"eigensystem-instance-method","name":"eigensystem","doc":"Returns the Eigensystem of the matrix\nSee `EigenvalueDecomposition`.\n\nNOTE: Not working yet\n\n```\nm = Matrix[[1, 2], [3, 4]]\nv, d, v_inv = m.eigensystem\nd.diagonal? # => true\nv.inv == v_inv # => true\n(v * d * v_inv).round(5) == m # => true\n```","summary":"Returns the Eigensystem of the matrix See EigenvalueDecomposition
.
Returns true if this matrix is empty.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L705","def":{"name":"empty?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(column_count == 0) || (row_count == 0)"}},{"id":"first_minor(row,column)-instance-method","html_id":"first_minor(row,column)-instance-method","name":"first_minor","doc":"Returns the submatrix obtained by deleting the specified row and column.\n\n```\nMatrix.diagonal(9, 5, -3, 4).first_minor(1, 2)\n# => [ 9, 0, 0,\n# 0, 0, 0,\n# 0, 0, 4 ]\n```","summary":"Returns the submatrix obtained by deleting the specified row and column.
","abstract":false,"args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(row, column)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L585","def":{"name":"first_minor","args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n raise(\"first_minor of empty matrix is not defined\")\nend\nif 0 <= row && row < row_count\nelse\n raise(ArgumentError.new(\"invalid row (#{row.inspect} for 0..#{row_count - 1})\"))\nend\nif 0 <= column && column < column_count\nelse\n raise(ArgumentError.new(\"invalid column (#{column.inspect} for 0..#{column_count - 1})\"))\nend\narrays = to_a\narrays.delete_at(row)\narrays.each do |array|\n array.delete_at(column)\nend\nMatrix.new(arrays, column_count - 1)\n"}},{"id":"hadamard_product(m)-instance-method","html_id":"hadamard_product(m)-instance-method","name":"hadamard_product","doc":"Hadamard product\n\n```\nMatrix[[1,2], [3,4]].hadamard_product Matrix[[1,2], [3,2]]\n# => [ 1, 4,\n# 9, 8 ]\n```","summary":"Hadamard product
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":""}],"args_string":"(m)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L999","def":{"name":"hadamard_product","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"combine(m) do |a, b|\n a * b\nend"}},{"id":"hermitian?-instance-method","html_id":"hermitian?-instance-method","name":"hermitian?","doc":"Returns `true` if this is an hermitian matrix.","summary":"Returns true
if this is an hermitian matrix.
Returns a new matrix resulting by stacking horizontally the receiver with the given matrices
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1161","def":{"name":"hstack","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.hstack(self, *matrices)"}},{"id":"imag-instance-method","html_id":"imag-instance-method","name":"imag","doc":"Returns the imaginary part of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => [ 1+2i, i, 0,\n# 1, 2, 3 ]\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].imag\n# => [ 2i, i, 0,\n# 0, 0, 0 ]\n```","summary":"Returns the imaginary part of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1328","def":{"name":"imag","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#imag only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.imag)\n"}},{"id":"index(i,selector=:all)-instance-method","html_id":"index(i,selector=:all)-instance-method","name":"index","doc":"The index method is specialized to return the index as {row, column}\nIt also accepts an optional `selector` argument, see `#each` for details.\n\n```\nMatrix[ [1,1], [1,1] ].index(1, :strict_lower)\n# => {1, 0}\n```","summary":"The index method is specialized to return the index as {row, column} It also accepts an optional selector
argument, see #each
for details.
Returns the index as {row, column}, using &block
to filter the result.
Returns the inverse of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1013","def":{"name":"inverse","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nlast = row_count - 1\na = self.coerce(Float64)\nm = Matrix(Float64).identity(row_count)\n0.upto(last) do |k|\n i = k\n akk = a[k, k].abs\n (k + 1).upto(last) do |j|\n v = a[j, k].abs\n if v > akk\n i = j\n akk = v\n end\n end\n if akk == 0\n raise(ErrNotRegular.new)\n end\n if i != k\n a.swap_rows(i, k)\n m.swap_rows(i, k)\n end\n akk = a[k, k]\n 0.upto(last) do |ii|\n if ii == k\n next\n end\n q = a[ii, k] / akk\n a[ii, k] = 0.0\n (k + 1).upto(last) do |j|\n __temp_24 = ii\n __temp_25 = j\n a[__temp_24, __temp_25] = a[__temp_24, __temp_25] - (a[k, j] * q)\n end\n 0.upto(last) do |j|\n __temp_27 = ii\n __temp_28 = j\n m[__temp_27, __temp_28] = m[__temp_27, __temp_28] - (m[k, j] * q)\n end\n end\n (k + 1).upto(last) do |j|\n a[k, j] = a[k, j] / akk\n end\n 0.upto(last) do |j|\n m[k, j] = m[k, j] / akk\n end\nend\nm\n"}},{"id":"laplace_expansion(*,row=nil,column=nil)-instance-method","html_id":"laplace_expansion(*,row=nil,column=nil)-instance-method","name":"laplace_expansion","doc":"Returns the Laplace expansion along given row or column.\n\n```\nMatrix[[7,6], [3,9]].laplace_expansion(column: 1)\n# => 45\n\nMatrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0)\n# => Vector[3, -2]\n```","summary":"Returns the Laplace expansion along given row or column.
","abstract":false,"args":[{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"row","doc":null,"default_value":"nil","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"nil","external_name":"column","restriction":""}],"args_string":"(*, row = nil, column = nil)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L642","def":{"name":"laplace_expansion","args":[{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"row","doc":null,"default_value":"nil","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"nil","external_name":"column","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = row || column\nif (!num) || (row && column)\n raise(ArgumentError.new(\"exactly one the row or column arguments must be specified\"))\nend\nif square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nif empty?\n raise(\"laplace_expansion of empty matrix is not defined\")\nend\nif 0 <= num && num < row_count\nelse\n raise(ArgumentError, \"invalid num (#{num.inspect} for 0..#{row_count - 1})\")\nend\nif row\n (row(num)).map_with_index do |e, k|\n e * (cofactor(num, k))\n end.reduce(&.+)\nelse\n (col(num)).map_with_index do |e, k|\n e * (cofactor(k, num))\n end.reduce(&.+)\nend\n"}},{"id":"lower_triangular?-instance-method","html_id":"lower_triangular?-instance-method","name":"lower_triangular?","doc":"Returns true if this matrix is a lower triangular matrix.","summary":"Returns true if this matrix is a lower triangular matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L720","def":{"name":"lower_triangular?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = [] of T\neach(:strict_upper) do |e|\n els << e\nend\nels.all?(&.zero?)\n"}},{"id":"lup-instance-method","html_id":"lup-instance-method","name":"lup","doc":"Returns the LUP decomposition of the matrix\nSee +LUPDecomposition+.\n\nNOTE: Not working yet\n\n```\na = Matrix[[1, 2], [3, 4]]\nl, u, p = a.lup\nl.lower_triangular? # => true\nu.upper_triangular? # => true\np.permutation? # => true\nl * u == p * a # => true\na.lup.solve([2, 5]) # => Vector[(1/1), (1/2)]\n```","summary":"Returns the LUP decomposition of the matrix See +LUPDecomposition+.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1295","def":{"name":"lup","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"LUPDecomposition.new(self)"}},{"id":"map(&block:T->T)-instance-method","html_id":"map(&block:T->T)-instance-method","name":"map","doc":"Returns a Matrix that is the result of iteration of the given block\nover all elements in the matrix.","summary":"Returns a Matrix that is the result of iteration of the given block over all elements in the matrix.
","abstract":false,"args":[],"args_string":"(&block : T -> T)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L359","def":{"name":"map","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> T)"},"return_type":"","visibility":"Public","body":"rows = @rows.map do |row|\n row.map(&block)\nend\nMatrix.new(rows, column_count)\n"}},{"id":"minor(row_range:Range,col_range:Range)-instance-method","html_id":"minor(row_range:Range,col_range:Range)-instance-method","name":"minor","doc":"Returns a section of the Matrix.\n\n```\nMatrix.diagonal(9, 5, -3).minor(0..1, 0..2)\n# => [ 9, 0, 0,\n# 0, 5, 0 ]\n```","summary":"Returns a section of the Matrix.
","abstract":false,"args":[{"name":"row_range","doc":null,"default_value":"","external_name":"row_range","restriction":"Range"},{"name":"col_range","doc":null,"default_value":"","external_name":"col_range","restriction":"Range"}],"args_string":"(row_range : Range, col_range : Range)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L532","def":{"name":"minor","args":[{"name":"row_range","doc":null,"default_value":"","external_name":"row_range","restriction":"Range"},{"name":"col_range","doc":null,"default_value":"","external_name":"col_range","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"from_row = row_range.first\nif from_row < 0\n from_row = from_row + row_count\nend\nto_row = row_range.end\nif to_row < 0\n to_row = to_row + row_count\nend\nif row_range.excludes_end?\nelse\n to_row = to_row + 1\nend\nsize_row = to_row - from_row\nfrom_col = col_range.first\nif from_col < 0\n from_col = from_col + column_count\nend\nto_col = col_range.end\nif to_col < 0\n to_col = to_col + column_count\nend\nif col_range.excludes_end?\nelse\n to_col = to_col + 1\nend\nsize_col = to_col - from_col\nif ((from_row > row_count || from_col > column_count) || from_row < 0) || from_col < 0\n return nil\nend\nrows = @rows[from_row, size_row].map do |row|\n row[from_col, size_col]\nend\nMatrix.new(rows, [column_count - from_col, size_col].min)\n"}},{"id":"minor(from_row:Int,nrows:Int,from_col:Int,ncols:Int)-instance-method","html_id":"minor(from_row:Int,nrows:Int,from_col:Int,ncols:Int)-instance-method","name":"minor","doc":"Returns a section of the Matrix.\n\n```\nMatrix.diagonal(9, 5, -3).minor(0, 2, 0, 3)\n# => [ 9, 0, 0,\n# 0, 5, 0 ]\n```","summary":"Returns a section of the Matrix.
","abstract":false,"args":[{"name":"from_row","doc":null,"default_value":"","external_name":"from_row","restriction":"Int"},{"name":"nrows","doc":null,"default_value":"","external_name":"nrows","restriction":"Int"},{"name":"from_col","doc":null,"default_value":"","external_name":"from_col","restriction":"Int"},{"name":"ncols","doc":null,"default_value":"","external_name":"ncols","restriction":"Int"}],"args_string":"(from_row : Int, nrows : Int, from_col : Int, ncols : Int)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L563","def":{"name":"minor","args":[{"name":"from_row","doc":null,"default_value":"","external_name":"from_row","restriction":"Int"},{"name":"nrows","doc":null,"default_value":"","external_name":"nrows","restriction":"Int"},{"name":"from_col","doc":null,"default_value":"","external_name":"from_col","restriction":"Int"},{"name":"ncols","doc":null,"default_value":"","external_name":"ncols","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if nrows < 0 || ncols < 0\n return nil\nend\nif from_row < 0\n from_row = from_row + row_count\nend\nif from_col < 0\n from_col = from_col + column_count\nend\nif ((from_row > row_count || from_col > column_count) || from_row < 0) || from_col < 0\n return nil\nend\nrows = @rows[from_row, nrows].map do |row|\n row[from_col, ncols]\nend\nMatrix.new(rows, [column_count - from_col, ncols].min)\n"}},{"id":"normal?-instance-method","html_id":"normal?-instance-method","name":"normal?","doc":"Returns `true` if this is a normal matrix.\n\n```\nMatrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].normal?\n# => true\n```","summary":"Returns true
if this is a normal matrix.
Returns true
if this is an orthogonal matrix
Returns true
if this is a permutation matrix
Returns the rank of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1175","def":{"name":"rank","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"a = to_a\nlast_column = column_count - 1\nlast_row = row_count - 1\npivot_row = 0\nprevious_pivot = 1\n0.upto(last_column) do |k|\n switch_row = (pivot_row..last_row).find do |row|\n a[row][k] != 0\n end\n if switch_row\n if pivot_row == switch_row\n else\n a[switch_row], a[pivot_row] = a[pivot_row], a[switch_row]\n end\n pivot = a[pivot_row][k]\n (pivot_row + 1).upto(last_row) do |i|\n ai = a[i]\n (k + 1).upto(last_column) do |j|\n ai[j] = ((pivot * ai[j]) - (ai[k] * a[pivot_row][j])) / previous_pivot\n end\n end\n pivot_row = pivot_row + 1\n previous_pivot = pivot\n end\nend\npivot_row\n"}},{"id":"real-instance-method","html_id":"real-instance-method","name":"real","doc":"Returns the real part of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => [ 1+2i, i, 0,\n# 1, 2, 3 ]\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real\n# => [ 1, 0, 0,\n# 1, 2, 3 ]\n```","summary":"Returns the real part of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1343","def":{"name":"real","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#real only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.real)\n"}},{"id":"real?-instance-method","html_id":"real?-instance-method","name":"real?","doc":"Returns `true` if this matrix contains real numbers,\ni.e. not `Complex`.\n\n```\nrequire \"complex\"\nMatrix[[Complex.new(1, 0)], [Complex.new(0, 1)]].real?\n# => false\n```","summary":"Returns true
if this matrix contains real numbers, i.e.
Returns an array containing matrices corresponding to the real and imaginary parts of the matrix
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1355","def":{"name":"rect","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#real only works with real matrices (i.e. Matrix(Complex))\"))\nend\n[real, imag]\n"}},{"id":"regular?-instance-method","html_id":"regular?-instance-method","name":"regular?","doc":"Returns `true` if this is a regular (i.e. non-singular) matrix.","summary":"Returns true
if this is a regular (i.e.
Returns a matrix with entries rounded to the given precision (see Float#round
)
Returns a block which yields every Vector in the row (starting at 0).
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i, &block : Vector -> )","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L322","def":{"name":"row","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(Vector -> )"},"return_type":"","visibility":"Public","body":"(row(i)).each(&block)"}},{"id":"row(i)-instance-method","html_id":"row(i)-instance-method","name":"row","doc":"Returns row vector number `i` of the Matrix as a Vector (starting\nat 0 like a good boy). Raises if the row doesn't exist.","summary":"Returns row vector number i
of the Matrix as a Vector (starting at 0 like a good boy).
Returns row vector number i
of the Matrix as a Vector (starting at 0 like a good boy).
Returns the number of rows.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L307","def":{"name":"row_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rows.size"}},{"id":"singular?-instance-method","html_id":"singular?-instance-method","name":"singular?","doc":"Returns `true` if this is a singular matrix.","summary":"Returns true
if this is a singular matrix.
Returns true
if this is a square matrix.
Swaps col1
and col2
Swaps row1
and row2
Returns +true+ if this is a symmetric matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L820","def":{"name":"symmetric?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n return false\nend\nresult = true\neach_with_index(:strict_upper) do |e, row, col|\n if e != rows[col][row]\n result = false\n end\nend\nresult\n"}},{"id":"t-instance-method","html_id":"t-instance-method","name":"t","doc":"Returns the transpose of the matrix.\n\n```\nMatrix[[1,2], [3,4], [5,6]]\n# => [ 1, 2,\n# 3, 4,\n# 5, 6 ]\nMatrix[[1,2], [3,4], [5,6]].transpose\n# => [ 1, 3, 5,\n# 2, 4, 6 ]\n```","summary":"Returns the transpose of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1244","def":{"name":"t","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"transpose"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Returns this matrix as an `Array(Array(T))`","summary":"Returns this matrix as an Array(Array(T))
Returns the trace (sum of diagonal elements) of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1223","def":{"name":"tr","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"trace"}},{"id":"trace-instance-method","html_id":"trace-instance-method","name":"trace","doc":"Returns the trace (sum of diagonal elements) of the matrix.\n\n```\nMatrix[[7,6], [3,9]].trace\n# => 16\n```","summary":"Returns the trace (sum of diagonal elements) of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1215","def":{"name":"trace","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\n(0...column_count).reduce(0) do |tr, i|\n tr + @rows[i][i]\nend\n"}},{"id":"transpose-instance-method","html_id":"transpose-instance-method","name":"transpose","doc":"Returns the transpose of the matrix.\n\n```\nMatrix[[1,2], [3,4], [5,6]]\n# => [ 1, 2,\n# 3, 4,\n# 5, 6 ]\nMatrix[[1,2], [3,4], [5,6]].transpose\n# => [ 1, 3, 5,\n# 2, 4, 6 ]\n```","summary":"Returns the transpose of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1238","def":{"name":"transpose","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if row_count.zero?\n return self.class.empty(column_count, 0)\nend\nMatrix.new(@rows.transpose, row_count)\n"}},{"id":"unitary?-instance-method","html_id":"unitary?-instance-method","name":"unitary?","doc":"Returns `true` if this is a unitary matrix","summary":"Returns true
if this is a unitary matrix
Returns true if this matrix is a upper triangular matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L852","def":{"name":"upper_triangular?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = [] of T\neach(:strict_lower) do |e|\n els << e\nend\nels.all?(&.zero?)\n"}},{"id":"vstack(*matrices)-instance-method","html_id":"vstack(*matrices)-instance-method","name":"vstack","doc":"Returns a new matrix resulting by stacking vertically\nthe receiver with the given matrices\n\n```\nx = Matrix[[1, 2], [3, 4]]\ny = Matrix[[5, 6], [7, 8]]\nx.vstack(y)\n# => Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]\n```","summary":"Returns a new matrix resulting by stacking vertically the receiver with the given matrices
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix.cr#L1257","def":{"name":"vstack","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.vstack(self, *matrices)"}},{"id":"zero?-instance-method","html_id":"zero?-instance-method","name":"zero?","doc":"Returns `true` if this is a matrix with only zero elements","summary":"Returns true
if this is a matrix with only zero elements
Eigenvalues and eigenvectors of a real matrix.
","class_methods":[],"constructors":[{"id":"new(matrix)-class-method","html_id":"new(matrix)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"args_string":"(matrix)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr#L13","def":{"name":"new","args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(matrix)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix/LupDecomposition","path":"Apatite/LinearAlgebra/Matrix/LupDecomposition.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix::LupDecomposition","name":"LupDecomposition","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":12,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/lup_decomposition.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix(T)","name":"Matrix"},"doc":"For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n\nunit lower triangular matrix L, an n-by-n upper triangular matrix U,\nand a m-by-m permutation matrix P so that L*U = P*A.\nIf m < n, then L is m-by-m and U is m-by-n.\n\nThe LUP decomposition with pivoting always exists, even if the matrix is\nsingular, so the constructor will never fail. The primary use of the\nLU decomposition is in the solution of square systems of simultaneous\nlinear equations. This will fail if singular? returns true.","summary":"For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a m-by-m permutation matrix P so that LU = PA.
","class_methods":[],"constructors":[{"id":"new(matrix)-class-method","html_id":"new(matrix)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"args_string":"(matrix)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/matrix/lup_decomposition.cr#L13","def":{"name":"new","args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(matrix)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/NDArray","path":"Apatite/LinearAlgebra/NDArray.html","kind":"class","full_name":"Apatite::LinearAlgebra::NDArray","name":"NDArray","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/ndarray.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(data:Array(Number),shape:Array(Int32)?=nil)-class-method","html_id":"new(data:Array(Number),shape:Array(Int32)?=nil)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array(Number)"},{"name":"shape","doc":null,"default_value":"nil","external_name":"shape","restriction":"Array(Int32) | ::Nil"}],"args_string":"(data : Array(Number), shape : Array(Int32)? = nil)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L18","def":{"name":"new","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array(Number)"},{"name":"shape","doc":null,"default_value":"nil","external_name":"shape","restriction":"Array(Int32) | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(data, shape)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"[](*args,**options)-instance-method","html_id":"[](*args,**options)-instance-method","name":"[]","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"[]","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]"}},{"id":"[](*args,**options,&block)-instance-method","html_id":"[](*args,**options,&block)-instance-method","name":"[]","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"[]","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options] do |*yield_args|\n yield *yield_args\nend"}},{"id":"[]=(*args,**options)-instance-method","html_id":"[]=(*args,**options)-instance-method","name":"[]=","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L13","def":{"name":"[]=","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args] = **options"}},{"id":"[]?(*args,**options)-instance-method","html_id":"[]?(*args,**options)-instance-method","name":"[]?","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L12","def":{"name":"[]?","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]?"}},{"id":"[]?(*args,**options,&block)-instance-method","html_id":"[]?(*args,**options,&block)-instance-method","name":"[]?","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L12","def":{"name":"[]?","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]? do |*yield_args|\n yield *yield_args\nend"}},{"id":"abs-instance-method","html_id":"abs-instance-method","name":"abs","doc":"Returns the absolute value of every item in the array","summary":"Returns the absolute value of every item in the array
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L24","def":{"name":"abs","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |e|\n e.abs\nend"}},{"id":"acos-instance-method","html_id":"acos-instance-method","name":"acos","doc":"Returns the arccosine of each element in the current array.","summary":"Returns the arccosine of each element in the current array.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L29","def":{"name":"acos","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"data:Array(Float64)-instance-method","html_id":"data:Array(Float64)-instance-method","name":"data","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Array(Float64)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L9","def":{"name":"data","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(Float64)","visibility":"Public","body":"@data"}},{"id":"shape:Array(Int32)-instance-method","html_id":"shape:Array(Int32)-instance-method","name":"shape","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Array(Int32)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"shape","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(Int32)","visibility":"Public","body":"@shape"}},{"id":"size(*args,**options)-instance-method","html_id":"size(*args,**options)-instance-method","name":"size","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L16","def":{"name":"size","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.size(*args, **options)"}},{"id":"size(*args,**options,&block)-instance-method","html_id":"size(*args,**options,&block)-instance-method","name":"size","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L16","def":{"name":"size","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.size(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"to_unsafe(*args,**options)-instance-method","html_id":"to_unsafe(*args,**options)-instance-method","name":"to_unsafe","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L15","def":{"name":"to_unsafe","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.to_unsafe(*args, **options)"}},{"id":"to_unsafe(*args,**options,&block)-instance-method","html_id":"to_unsafe(*args,**options,&block)-instance-method","name":"to_unsafe","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L15","def":{"name":"to_unsafe","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.to_unsafe(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"unsafe_fetch(*args,**options)-instance-method","html_id":"unsafe_fetch(*args,**options)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L14","def":{"name":"unsafe_fetch","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.unsafe_fetch(*args, **options)"}},{"id":"unsafe_fetch(*args,**options,&block)-instance-method","html_id":"unsafe_fetch(*args,**options,&block)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/ndarray.cr#L14","def":{"name":"unsafe_fetch","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.unsafe_fetch(*args, **options) do |*yield_args|\n yield *yield_args\nend"}}],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Vector","path":"Apatite/LinearAlgebra/Vector.html","kind":"class","full_name":"Apatite::LinearAlgebra::Vector(T)","name":"Vector","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/vector.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":"Represents a mathematical vector, and also constitutes a row or column\nof a `Matrix`","summary":"Represents a mathematical vector, and also constitutes a row or column of a Matrix
Creates a new vector from a list of elements.
","abstract":false,"args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""}],"args_string":"(*array)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L22","def":{"name":"[]","args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new(array)"}},{"id":"basis(size,index)-class-method","html_id":"basis(size,index)-class-method","name":"basis","doc":"Returns a standard basis `n`-vector.","summary":"Returns a standard basis n
-vector.
Creates a vector from an Array.
","abstract":false,"args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(array, copy = true)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L28","def":{"name":"elements","args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if copy\n array = array.clone\nend\nnew(array)\n"}},{"id":"zero(size)-class-method","html_id":"zero(size)-class-method","name":"zero","doc":"Return a zero vector.","summary":"Return a zero vector.
","abstract":false,"args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""}],"args_string":"(size)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L53","def":{"name":"zero","args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size < 0\n raise(ArgumentError.new(\"invalid size (#{size} for 0..)\"))\nend\narray = Array.new(size, 0)\nnew(array)\n"}}],"constructors":[],"instance_methods":[{"id":"*(x)-instance-method","html_id":"*(x)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is a number or a matrix.","summary":"Multiplies the vector by x, where x is a number or a matrix.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L60","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e * x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg0|\n x = __arg0[0]\n y = __arg0[1]\n x * y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"+(x)-instance-method","html_id":"+(x)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L75","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e + x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg1|\n x = __arg1[0]\n y = __arg1[1]\n x + y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"-(x)-instance-method","html_id":"-(x)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L90","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e - x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg2|\n x = __arg2[0]\n y = __arg2[1]\n x - y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"/(x)-instance-method","html_id":"/(x)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L105","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e / x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg3|\n x = __arg3[0]\n y = __arg3[1]\n x / y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"-instance-method","html_id":"-instance-method","name":"<=>","doc":"Take me to your leader","summary":"Take me to your leader
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L129","def":{"name":"<=>","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if other.is_a?(Vector)\n @elements <=> other.elements\nelse\n @elements <=> other\nend"}},{"id":"==(other)-instance-method","html_id":"==(other)-instance-method","name":"==","doc":"Equality operator","summary":"Equality operator
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L120","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if other.is_a?(Vector)\n @elements == other.elements\nelse\n @elements == other\nend"}},{"id":"angle_with(v)-instance-method","html_id":"angle_with(v)-instance-method","name":"angle_with","doc":"Returns an angle with another vector. Result is within the [0…Math::PI].","summary":"Returns an angle with another vector.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L138","def":{"name":"angle_with","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\nprod = magnitude * v.magnitude\nif prod == 0\n raise(ZeroVectorError.new(\"Can't get angle of zero vector\"))\nend\nMath.acos((inner_product(v)) / prod)\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":"Returns a copy of the vector.","summary":"Returns a copy of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L147","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.elements(@elements)"}},{"id":"coerce(klass,*args)-instance-method","html_id":"coerce(klass,*args)-instance-method","name":"coerce","doc":"The coerce method allows you to attempt to coerce the elements\nin the matrix to another type. The type","summary":"The coerce method allows you to attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(klass, *args)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L249","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case klass.to_s\nwhen \"Complex\"\n if args[0]?\n else\n raise(\"coercing to a Complex requires a second argument\")\n end\n els = @elements.map do |e|\n Complex.new(e, args[0].as(Int32))\n end\nwhen \"BigInt\"\n base = args[0]? || 10\n els = @elements.map do |e|\n klass.new(e, base)\n end\nwhen \"BigRational\"\n if args[0]?\n else\n raise(\"coercing to a BigRational requires a second argument to use as a denominator\")\n end\n els = @elements.map do |e|\n klass.new(e, args[0])\n end\nelse\n els = @elements.map do |e|\n klass.new(e)\n end\nend\nVector.elements(els)\n"}},{"id":"cross(v)-instance-method","html_id":"cross(v)-instance-method","name":"cross","doc":"Returns the cross product of this vector with the others.","summary":"Returns the cross product of this vector with the others.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L193","def":{"name":"cross","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"cross_product(v)"}},{"id":"cross_product(*vs)-instance-method","html_id":"cross_product(*vs)-instance-method","name":"cross_product","doc":"Returns the cross product of this vector with the others.","summary":"Returns the cross product of this vector with the others.
","abstract":false,"args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"args_string":"(*vs)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L170","def":{"name":"cross_product","args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size >= 2\nelse\n raise(ErrOperationNotDefined.new(\"cross product is not defined on vectors of dimension #{size}\"))\nend\nif vs.size == (size - 2)\nelse\n raise(ArgumentError.new(\"wrong number of arguments (#{vs.size} for #{size - 2})\"))\nend\nvs.each do |v|\n if v.size == size\n else\n raise(ErrDimensionMismatch.new)\n end\nend\ncase size\nwhen 2\n Vector[-@elements[1], @elements[0]]\nwhen 3\n v = vs[0]\n Vector[(v[2] * @elements[1]) - (v[1] * @elements[2]), (v[0] * @elements[2]) - (v[2] * @elements[0]), (v[1] * @elements[0]) - (v[0] * @elements[1])]\nelse\n rows = (self + vs) + (Array.new(size) do |i|\n Vector.basis(size, i)\n end)\n (Matrix.rows(rows)).laplace_expansion(row: size - 1)\nend\n"}},{"id":"dot(v)-instance-method","html_id":"dot(v)-instance-method","name":"dot","doc":"Returns the inner product of this vector with the other.","summary":"Returns the inner product of this vector with the other.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L207","def":{"name":"dot","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"inner_product(v)"}},{"id":"each(*args,**options)-instance-method","html_id":"each(*args,**options)-instance-method","name":"each","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L14","def":{"name":"each","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.each(*args, **options)"}},{"id":"each(*args,**options,&block)-instance-method","html_id":"each(*args,**options,&block)-instance-method","name":"each","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L14","def":{"name":"each","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.each(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"each2(v,&block)-instance-method","html_id":"each2(v,&block)-instance-method","name":"each2","doc":"Iterate over the elements of this vector and `v` in conjunction.","summary":"Iterate over the elements of this vector and v
in conjunction.
Returns the inner product of this vector with the other.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L198","def":{"name":"inner_product","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\np = 0\neach2(v) do |v1, v2|\n p = p + (v1 * v2)\nend\np\n"}},{"id":"inspect-instance-method","html_id":"inspect-instance-method","name":"inspect","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L286","def":{"name":"inspect","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"<#Vector(#{T}) [#{@elements.join(\", \")}]>\""}},{"id":"magnitude-instance-method","html_id":"magnitude-instance-method","name":"magnitude","doc":"Returns the modulus (Pythagorean distance) of the vector.","summary":"Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L221","def":{"name":"magnitude","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Math.sqrt(@elements.reduce(0) do |v, e|\n v + e.abs2\nend)"}},{"id":"map(&block:T->UNDERSCORE)-instance-method","html_id":"map(&block:T->UNDERSCORE)-instance-method","name":"map","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"(&block : T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L151","def":{"name":"map","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> _)"},"return_type":"","visibility":"Public","body":"els = @elements.map(&block)\nself.class.elements(els, false)\n"}},{"id":"map2(v,&block:T,T->UNDERSCORE)-instance-method","html_id":"map2(v,&block:T,T->UNDERSCORE)-instance-method","name":"map2","doc":null,"summary":null,"abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v, &block : T, T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L156","def":{"name":"map2","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":2,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T, T -> _)"},"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\narr = Array.new(size) do |i|\n yield @elements[i], v[i]\nend\nself.class.elements(arr, false)\n"}},{"id":"norm-instance-method","html_id":"norm-instance-method","name":"norm","doc":"Returns the modulus (Pythagorean distance) of the vector.","summary":"Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L226","def":{"name":"norm","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"magnitude"}},{"id":"normalize-instance-method","html_id":"normalize-instance-method","name":"normalize","doc":"Returns a new vector with the same direction but with norm 1","summary":"Returns a new vector with the same direction but with norm 1
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L231","def":{"name":"normalize","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"n = magnitude\nif n == 0\n raise(ZeroVectorError.new(\"Zero vectors can not be normalized\"))\nend\nself / n\n"}},{"id":"r-instance-method","html_id":"r-instance-method","name":"r","doc":"Returns a new vector with the same direction but with norm 1","summary":"Returns a new vector with the same direction but with norm 1
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L238","def":{"name":"r","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"magnitude"}},{"id":"round(ndigits=0)-instance-method","html_id":"round(ndigits=0)-instance-method","name":"round","doc":"Returns a vector with entries rounded to the given precision.","summary":"Returns a vector with entries rounded to the given precision.
","abstract":false,"args":[{"name":"ndigits","doc":null,"default_value":"0","external_name":"ndigits","restriction":""}],"args_string":"(ndigits = 0)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L243","def":{"name":"round","args":[{"name":"ndigits","doc":null,"default_value":"0","external_name":"ndigits","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |e|\n e.round(ndigits)\nend"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Returns the elements of the vector in an array.","summary":"Returns the elements of the vector in an array.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L268","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.dup"}},{"id":"to_matrix-instance-method","html_id":"to_matrix-instance-method","name":"to_matrix","doc":"Return a single-column matrix from this vector.","summary":"Return a single-column matrix from this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L273","def":{"name":"to_matrix","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.column_vector(self)"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L277","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(\"Vector{\" + (@elements.join(\", \"))) + \"}\""}},{"id":"unsafe_fetch(i)-instance-method","html_id":"unsafe_fetch(i)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i)","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/linear_algebra/vector.cr#L290","def":{"name":"unsafe_fetch","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.unsafe_fetch(i)"}},{"id":"zero?-instance-method","html_id":"zero?-instance-method","name":"zero?","doc":"Returns `true` if all elements are zero.","summary":"Returns true
if all elements are zero.
An Array
is an ordered, integer-indexed collection of objects of type T.
Tests whether all elements evaluate to true
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/core_ext/array.cr#L3","def":{"name":"all?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"each do |i|\n if (!(!i)) == false\n return false\n end\nend\ntrue\n"}},{"id":"any?-instance-method","html_id":"any?-instance-method","name":"any?","doc":"Tests whether any of the elements evaluate to true","summary":"Tests whether any of the elements evaluate to true
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/core_ext/array.cr#L11","def":{"name":"any?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"each do |i|\n if (!(!i)) == true\n return true\n end\nend\nfalse\n"}},{"id":"shape-instance-method","html_id":"shape-instance-method","name":"shape","doc":"Get the array's dimensions","summary":"Get the array's dimensions
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/core_ext/array.cr#L19","def":{"name":"shape","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"max = max_by do |i|\n i.is_a?(Array) ? i.size : i\nend\nmax.is_a?(Array) ? [size, max.size] : [max]\n"}},{"id":"to_vec-instance-method","html_id":"to_vec-instance-method","name":"to_vec","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/06bd6fa4ee11fe383cfa0fae10d396c06768c07e/src/apatite/core_ext/array.cr#L24","def":{"name":"to_vec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite::Vector.create(self)"}}],"macros":[],"types":[]}]}}) \ No newline at end of file +crystal_doc_search_index_callback({"repository_name":"github.com/watzon/apatite","body":"# Apatite\n\nApatite is meant to be a collecion of mathmatical and scientific computing algorithms for the Crystal programming language. I don't expect it to ever reach the level of completeness as numpy, but hopefully it can save some people the trouble of implementing these methods on their own.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n apatite:\n github: watzon/apatite\n ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"apatite\"\n```\n\nCheck out the [documentation](https://watzon.github.io/apatite/) for usage examples.\n\n## Roadmap\n\n- [ ] Linear Algebra\n\t- [x] Vector\n\t- [x] Matrix\n\t- [ ] NDArray\n\t- [ ] Line\n\t- [ ] Plane\n\t- [ ] Polygon\n\t- [ ] LinkedList\n\t\n\n\n## Contributing\n\n1. Fork it (Apatite is a fundimental package for scientific computing in Crystal.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","path":"Apatite/LinearAlgebra.html","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"},{"filename":"apatite/linear_algebra/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr"},{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":5,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr"},{"filename":"apatite/linear_algebra.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra.cr"},{"filename":"apatite/linear_algebra/ndarray.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"}],"subclasses":[],"including_types":[{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"}],"namespace":{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[{"id":"sigmoid(input:Number)-instance-method","html_id":"sigmoid(input:Number)-instance-method","name":"sigmoid","doc":"Calculates the sigmoid curve for a numeric input.\n\n`f(x) = 1/(1 + e^-x)`\n\nSee also: [Sigmoid function (WikiWand)](https://www.wikiwand.com/en/Sigmoid_function)","summary":"Calculates the sigmoid curve for a numeric input.
","abstract":false,"args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"args_string":"(input : Number)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra.cr#L15","def":{"name":"sigmoid","args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = input.to_f64\n1 / (1 + (Math.exp(-num)))\n"}},{"id":"sigmoid_d(input:Number)-instance-method","html_id":"sigmoid_d(input:Number)-instance-method","name":"sigmoid_d","doc":"Calculates the derivative sigmoid curve for a numeric input.\n\n`f'(x) = f(x)(1 - f(x)),`","summary":"Calculates the derivative sigmoid curve for a numeric input.
","abstract":false,"args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"args_string":"(input : Number)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra.cr#L23","def":{"name":"sigmoid_d","args":[{"name":"input","doc":null,"default_value":"","external_name":"input","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = input.to_f64\nnum * (1 - num)\n"}}],"macros":[],"types":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrDimensionMismatch","path":"Apatite/LinearAlgebra/ErrDimensionMismatch.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrDimensionMismatch","name":"ErrDimensionMismatch","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrNotRegular","path":"Apatite/LinearAlgebra/ErrNotRegular.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrNotRegular","name":"ErrNotRegular","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrOperationNotDefined","path":"Apatite/LinearAlgebra/ErrOperationNotDefined.html","kind":"class","full_name":"Apatite::LinearAlgebra::ErrOperationNotDefined","name":"ErrOperationNotDefined","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},"ancestors":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error"},{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":8,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(method,this,other)-class-method","html_id":"new(method,this,other)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"method","doc":null,"default_value":"","external_name":"method","restriction":""},{"name":"this","doc":null,"default_value":"","external_name":"this","restriction":""},{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(method, this, other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr#L9","def":{"name":"new","args":[{"name":"method","doc":null,"default_value":"","external_name":"method","restriction":""},{"name":"this","doc":null,"default_value":"","external_name":"this","restriction":""},{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(method, this, other)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Error","path":"Apatite/LinearAlgebra/Error.html","kind":"class","full_name":"Apatite::LinearAlgebra::Error","name":"Error","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},"ancestors":[{"html_id":"github.com/watzon/apatite/Exception","kind":"class","full_name":"Exception","name":"Exception"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/error.cr","line_number":3,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/error.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrDimensionMismatch","kind":"class","full_name":"Apatite::LinearAlgebra::ErrDimensionMismatch","name":"ErrDimensionMismatch"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrNotRegular","kind":"class","full_name":"Apatite::LinearAlgebra::ErrNotRegular","name":"ErrNotRegular"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ErrOperationNotDefined","kind":"class","full_name":"Apatite::LinearAlgebra::ErrOperationNotDefined","name":"ErrOperationNotDefined"},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/ZeroVectorError","kind":"class","full_name":"Apatite::LinearAlgebra::ZeroVectorError","name":"ZeroVectorError"}],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix","path":"Apatite/LinearAlgebra/Matrix.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix(T)","name":"Matrix","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"SELECTORS","name":"SELECTORS","value":"{all: true, diagonal: true, off_diagonal: true, lower: true, strict_lower: true, strict_upper: true, upper: true}","doc":null,"summary":null}],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[{"id":"[](*rows)-class-method","html_id":"[](*rows)-class-method","name":"[]","doc":"Creates a matrix where each argument is a row.\n\n```\nMatrix[[25, 93], [-1, 66]]\n# => [ 25, 93,\n# -1, 66 ]\n```","summary":"Creates a matrix where each argument is a row.
","abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"args_string":"(*rows)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L20","def":{"name":"[]","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows(rows, false)"}},{"id":"build(row_count,column_count=row_count,&block:Int32,Int32->T)-class-method","html_id":"build(row_count,column_count=row_count,&block:Int32,Int32->T)-class-method","name":"build","doc":"Creates a matrix of size +row_count+ x +column_count+.\nIt fills the values by calling the given block,\npassing the current row and column.\nReturns an enumerator if no block is given.\n\n```\nm = Matrix.build(2, 4) { |row, col| col - row }\n# => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]\nm = Matrix.build(3) { rand }\n# => a 3x3 matrix with random elements\n```","summary":"Creates a matrix of size +row_count+ x +column_count+.
","abstract":false,"args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"args_string":"(row_count, column_count = row_count, &block : Int32, Int32 -> T)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L69","def":{"name":"build","args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"double_splat":null,"splat_index":null,"yields":2,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(Int32, Int32 -> T)"},"return_type":"","visibility":"Public","body":"row_count = row_count.to_i\ncolumn_count = column_count.to_i\nif row_count < 0 || column_count < 0\n raise(ArgumentError.new)\nend\nrows = Array(T).new(row_count) do |i|\n Array(T).new(column_count) do |j|\n yield i, j\n end\nend\nnew(rows, column_count)\n"}},{"id":"column_vector(column)-class-method","html_id":"column_vector(column)-class-method","name":"column_vector","doc":"Creates a single-column matrix where the values of that column are as given\nin `column`.\n\n```\nMatrix.column_vector([4,5,6])\n# => [ 4,\n# 5,\n# 6 ]\n```","summary":"Creates a single-column matrix where the values of that column are as given in #column
.
Creates a matrix using +columns+ as an array of column vectors.
","abstract":false,"args":[{"name":"columns","doc":null,"default_value":"","external_name":"columns","restriction":""}],"args_string":"(columns)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L54","def":{"name":"columns","args":[{"name":"columns","doc":null,"default_value":"","external_name":"columns","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(rows(columns, false)).transpose"}},{"id":"combine(*matrices,&block)-class-method","html_id":"combine(*matrices,&block)-class-method","name":"combine","doc":"Create a matrix by combining matrices entrywise, using the given block\n\n```\nx = Matrix[[6, 6], [4, 4]]\ny = Matrix[[1, 2], [3, 4]]\nMatrix.combine(x, y) {|a, b| a - b}\n# => Matrix[[5, 4], [1, 0]]\n```","summary":"Create a matrix by combining matrices entrywise, using the given block
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L245","def":{"name":"combine","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"if matrices.empty?\n return Matrix.empty\nend\nmatrices = matrices.map do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\nend\nx = matrices.first\nmatrices.each do |m|\n if (x.row_count == m.row_count) && (x.column_count == m.column_count)\n else\n raise(ErrDimensionMismatch.new)\n end\nend\nrows = Array(T).new(x.row_count) do |i|\n Array(T).new(x.column_count) do |j|\n yield matrices.map do |m|\n m[i, j]\n end\n end\nend\nnew(rows, x.column_count)\n"}},{"id":"diagonal(values:Indexable(T),dummy=nil)-class-method","html_id":"diagonal(values:Indexable(T),dummy=nil)-class-method","name":"diagonal","doc":"Creates a matrix where the diagonal elements are composed of `values`.\n\n```\nMatrix.diagonal(9, 5, -3)\n# => [ 9, 0, 0,\n# 0, 5, 0,\n# 0, 0, -3 ]\n```","summary":"Creates a matrix where the diagonal elements are composed of values
.
Creates a matrix where the diagonal elements are composed of values
.
Creates a empty matrix of #row_count
x #column_count
.
Create a matrix by stacking matrices horizontally
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(x, *matrices)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L217","def":{"name":"hstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"result = x.rows\ntotal_column_count = x.column_count\nmatrices.each do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\n if m.row_count != x.row_count\n raise(ErrDimensionMismatch.new(\"The given matrices must have #{x.row_count} rows, but one has #{m.row_count}\"))\n end\n result.each_with_index do |row, i|\n row.concat(m.rows[i])\n end\n total_column_count = total_column_count + m.column_count\nend\nnew(result, total_column_count)\n"}},{"id":"identity(n)-class-method","html_id":"identity(n)-class-method","name":"identity","doc":"Creates an `n` by `n` identity matrix.\n\n```\nMatrix.identity(2)\n# => [ 1, 0,\n# 0, 1 ]\n```","summary":"Creates an n
by n
identity matrix.
Creates a single-row matrix where the values of that row are as given in #row
.
Creates a matrix where +rows+ is an array of arrays, each of which is a row of the matrix.
","abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Array(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(rows : Indexable(Array(T)), copy = true)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L33","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Array(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if copy\n rows = rows.dup\nend\nrows = rows.to_a\nrows.map! do |row|\n if row\n row = row.dup\n end\n row.to_a\nend\nsize = (rows[0] || ([] of T)).size\nrows.each_with_index do |row, i|\n if row.size == size\n else\n raise(ErrDimensionMismatch.new(\"row size differs (row at index `#{i}` should contain #{size} elements, instead has #{row.size})\"))\n end\nend\nnew(rows, size)\n"}},{"id":"scalar(n,value:T)-class-method","html_id":"scalar(n,value:T)-class-method","name":"scalar","doc":"Creates an +n+ by +n+ diagonal matrix where each diagonal element is\n`value`.\n\n```\nMatrix.scalar(2, 5)\n# => [ 5, 0,\n# 0, 5 ]\n```","summary":"Creates an +n+ by +n+ diagonal matrix where each diagonal element is value
.
Creates an n
by n
identity matrix.
Create a matrix by stacking matrices vertically
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(x, *matrices)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L197","def":{"name":"vstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"result = x.rows\nmatrices.each do |m|\n m = m.is_a?(Matrix) ? m : rows(m)\n if m.column_count != x.column_count\n raise(ErrDimensionMismatch.new(\"The given matrices must have #{x.column_count} columns, but one has #{m.column_count}\"))\n end\n result.concat(m.rows)\nend\nnew(result, x.column_count)\n"}},{"id":"zero(row_count,column_count=row_count)-class-method","html_id":"zero(row_count,column_count=row_count)-class-method","name":"zero","doc":"Creates a zero matrix.\n\n```\nMatrix.zero(2)\n# => [ 0, 0,\n# 0, 0 ]\n```","summary":"Creates a zero matrix.
","abstract":false,"args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"args_string":"(row_count, column_count = row_count)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L140","def":{"name":"zero","args":[{"name":"row_count","doc":null,"default_value":"","external_name":"row_count","restriction":""},{"name":"column_count","doc":null,"default_value":"row_count","external_name":"column_count","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = Array(T).new(row_count) do\n Array(T).new(column_count, T.new(0))\nend\nnew(rows, column_count)\n"}}],"constructors":[],"instance_methods":[{"id":"*(other)-instance-method","html_id":"*(other)-instance-method","name":"*","doc":"Matrix multiplication\n\n```\nMatrix[[2,4], [6,8]] * Matrix.identity(2)\n# => [ 2, 4,\n# 6, 8 ]\n```","summary":"Matrix multiplication
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L891","def":{"name":"*","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Number\n rows = @rows.map do |row|\n row.map do |e|\n (e * other).as(T)\n end\n end\n Matrix.new(rows, column_count)\nwhen Vector\n m = Matrix.column_vector(other)\n r = self * m\n r.column(0)\nwhen Matrix\n if column_count != other.column_count\n raise(ErrDimensionMismatch.new)\n end\n rows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (0...column_count).reduce(0) do |vij, k|\n vij + (self[i, k] * other[k, j])\n end\n end\n end\n Matrix.new(rows, column_count)\nelse\n self * (Matrix.rows(other))\nend"}},{"id":"**(other)-instance-method","html_id":"**(other)-instance-method","name":"**","doc":"Matrix exponentiation.\n\nEquivalent to multiplying the matrix by itself N times.\nNon integer exponents will be handled by diagonalizing the matrix.\n\n```\nMatrix[[7,6], [3,9]] ** 2\n# => [ 67, 96,\n# 48, 99 ]\n```","summary":"Matrix exponentiation.
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1061","def":{"name":"**","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"+(other:Matrix|Indexable)-instance-method","html_id":"+(other:Matrix|Indexable)-instance-method","name":"+","doc":"Matrix addition\n\n```\nMatrix.scalar(2,5) + Matrix[[1,0], [-4,7]]\n# => [ 6, 0,\n# -4, 1 ]\n```","summary":"Matrix addition
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"args_string":"(other : Matrix | Indexable)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L924","def":{"name":"+","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n other = Matrix.column_vector(other)\nwhen Matrix\nelse\n other = Matrix.rows(other)\nend\nif (row_count == other.row_count) && (column_count == other.column_count)\nelse\n raise(ErrDimensionMismatch.new)\nend\nrows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (self[i, j] + other[i, j]).as(T)\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"-(other:Matrix|Indexable)-instance-method","html_id":"-(other:Matrix|Indexable)-instance-method","name":"-","doc":"Matrix subtraction\n\n```\nMatrix[[1,5], [4,2]] - Matrix[[9,3], [-4,1]]\n# => [-8, 2,\n# 8, 1 ]\n```","summary":"Matrix subtraction
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"args_string":"(other : Matrix | Indexable)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L951","def":{"name":"-","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n other = Matrix.column_vector(other)\nwhen Matrix\nelse\n other = Matrix.rows(other)\nend\nif (row_count == other.row_count) && (column_count == other.column_count)\nelse\n raise(ErrDimensionMismatch.new)\nend\nrows = Array.new(row_count) do |i|\n Array.new(column_count) do |j|\n (self[i, j] - other[i, j]).as(T)\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"/(other)-instance-method","html_id":"/(other)-instance-method","name":"/","doc":"Matrix division (multiplication by the inverse).\n\n```\nMatrix[[7,6], [3,9]] / Matrix[[2,9], [3,1]]\n# => [ -7, 1,\n# -3, -6 ]\n```","summary":"Matrix division (multiplication by the inverse).
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L978","def":{"name":"/","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Number\n rows = @rows.map do |row|\n row.map do |e|\n (e / other).as(T)\n end\n end\n return Matrix.new(rows, column_count)\nwhen Matrix\n return self * other.inverse\nelse\n self / (Matrix.rows(other))\nend"}},{"id":"==(other:Matrix)-instance-method","html_id":"==(other:Matrix)-instance-method","name":"==","doc":"Equality operator","summary":"Equality operator
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix"}],"args_string":"(other : Matrix)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L868","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(rows == other.rows) && (column_count == other.column_count)"}},{"id":"[](i)-instance-method","html_id":"[](i)-instance-method","name":"[]","doc":"Returns row `i` of the matrix as an Array. Raises if the\nindex is not found.","summary":"Returns row i
of the matrix as an Array.
Returns element (i
, j
) of the matrix.
Set the value at index (i
, j
).
Returns row i
of the matrix as an Array.
Returns element (i
, j
) of the matrix.
Returns the adjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L626","def":{"name":"adjugate","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nMatrix.build(row_count, column_count) do |row, column|\n cofactor(column, row)\nend\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":"Returns a clone of the matrix, so that the contents of each do not reference\nidentical objects.\n\nThere should be no good reason to do this since Matrices are immutable.","summary":"Returns a clone of the matrix, so that the contents of each do not reference identical objects.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L876","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.new(@rows.map(&.dup), column_count)"}},{"id":"coerce(klass)-instance-method","html_id":"coerce(klass)-instance-method","name":"coerce","doc":"Attempt to coerce the elements in the matrix to another type.","summary":"Attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""}],"args_string":"(klass)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1365","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rws = @rows.map do |r|\n r.map do |i|\n klass.new(i)\n end\nend\nMatrix.rows(rws)\n"}},{"id":"cofactor(row,column)-instance-method","html_id":"cofactor(row,column)-instance-method","name":"cofactor","doc":"Returns the (row, column) cofactor which is obtained by multiplying\nthe first minor by (-1)**(row + column).\n\n```\nMatrix.diagonal(9, 5, -3, 4).cofactor(1, 1)\n# => -108\n```","summary":"Returns the (row, column) cofactor which is obtained by multiplying the first minor by (-1)**(row + column).
","abstract":false,"args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(row, column)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L612","def":{"name":"cofactor","args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n raise(\"cofactor of empty matrix is not defined\")\nend\nif square?\nelse\n raise(ErrDimensionMismatch.new)\nend\ndet_of_minor = (first_minor(row, column)).determinant\ndet_of_minor * ((-1) ** (row + column))\n"}},{"id":"column(j)-instance-method","html_id":"column(j)-instance-method","name":"column","doc":"Returns column vector `j` of the Matrix as a Vector (starting at 0).\nRaises if the column doesn't exist.","summary":"Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns a block which yields every item in column j
of the Matrix.
Returns column vector j
of the Matrix as a Vector (starting at 0).
Returns the number of columns.
","abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L314","def":{"name":"column_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@column_count"}},{"id":"column_vectors-instance-method","html_id":"column_vectors-instance-method","name":"column_vectors","doc":"Returns an array of the column vectors of the matrix. See `Vector`.","summary":"Returns an array of the column vectors of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1378","def":{"name":"column_vectors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array.new(column_count) do |i|\n column(i)\nend"}},{"id":"combine(*matrices,&block)-instance-method","html_id":"combine(*matrices,&block)-instance-method","name":"combine","doc":"Create a matrix by combining matrices entrywise, using the given block\n\n```\nx = Matrix[[6, 6], [4, 4]]\ny = Matrix[[1, 2], [3, 4]]\nMatrix.combine(x, y) {|a, b| a - b}\n# => Matrix[[5, 4], [1, 0]]\n```","summary":"Create a matrix by combining matrices entrywise, using the given block
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L264","def":{"name":"combine","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"return_type":"","visibility":"Public","body":"Matrix.combine(self, *matrices, &block)"}},{"id":"conj-instance-method","html_id":"conj-instance-method","name":"conj","doc":"Returns the conjugate of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => 1+2i i 0\n# 1 2 3\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].conj\n# => 1-2i -i 0\n# 1 2 3\n```","summary":"Returns the conjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1313","def":{"name":"conj","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#conj only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.conj)\n"}},{"id":"determinant-instance-method","html_id":"determinant-instance-method","name":"determinant","doc":"Returns the determinant of the matrix.\n\nBeware that using Float values can yield erroneous results\nbecause of their lack of precision.\nConsider using exact types like Rational or BigDecimal instead.\n\n```\nMatrix[[7,6], [3,9]].determinant\n# => 45\n```","summary":"Returns the determinant of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1079","def":{"name":"determinant","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nm = rows\ncase row_count\nwhen 0\n +1\nwhen 1\n +m[0][0]\nwhen 2\n ((+m[0][0]) * m[1][1]) - (m[0][1] * m[1][0])\nwhen 3\n m0, m1, m2 = m\n (((((((+m0[0]) * m1[1]) * m2[2]) - ((m0[0] * m1[2]) * m2[1])) - ((m0[1] * m1[0]) * m2[2])) + ((m0[1] * m1[2]) * m2[0])) + ((m0[2] * m1[0]) * m2[1])) - ((m0[2] * m1[1]) * m2[0])\nwhen 4\n m0, m1, m2, m3 = m\n ((((((((((((((((((((((((((+m0[0]) * m1[1]) * m2[2]) * m3[3]) - (((m0[0] * m1[1]) * m2[3]) * m3[2])) - (((m0[0] * m1[2]) * m2[1]) * m3[3])) + (((m0[0] * m1[2]) * m2[3]) * m3[1])) + (((m0[0] * m1[3]) * m2[1]) * m3[2])) - (((m0[0] * m1[3]) * m2[2]) * m3[1])) - (((m0[1] * m1[0]) * m2[2]) * m3[3])) + (((m0[1] * m1[0]) * m2[3]) * m3[2])) + (((m0[1] * m1[2]) * m2[0]) * m3[3])) - (((m0[1] * m1[2]) * m2[3]) * m3[0])) - (((m0[1] * m1[3]) * m2[0]) * m3[2])) + (((m0[1] * m1[3]) * m2[2]) * m3[0])) + (((m0[2] * m1[0]) * m2[1]) * m3[3])) - (((m0[2] * m1[0]) * m2[3]) * m3[1])) - (((m0[2] * m1[1]) * m2[0]) * m3[3])) + (((m0[2] * m1[1]) * m2[3]) * m3[0])) + (((m0[2] * m1[3]) * m2[0]) * m3[1])) - (((m0[2] * m1[3]) * m2[1]) * m3[0])) - (((m0[3] * m1[0]) * m2[1]) * m3[2])) + (((m0[3] * m1[0]) * m2[2]) * m3[1])) + (((m0[3] * m1[1]) * m2[0]) * m3[2])) - (((m0[3] * m1[1]) * m2[2]) * m3[0])) - (((m0[3] * m1[2]) * m2[0]) * m3[1])) + (((m0[3] * m1[2]) * m2[1]) * m3[0])\nelse\n determinant_bareiss\nend\n"}},{"id":"diagonal?-instance-method","html_id":"diagonal?-instance-method","name":"diagonal?","doc":"Returns `true` if this is a diagonal matrix.\n","summary":"Returns true
if this is a diagonal matrix.
Yields all elements of the matrix, starting with those of the first row, or returns an Enumerator if no block given.
","abstract":false,"args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"args_string":"(which = :all, &block : T -> )","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L380","def":{"name":"each","args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> )"},"return_type":"","visibility":"Public","body":"last = column_count\ncase which.to_s\nwhen \"all\"\n @rows.each do |row|\n row.each(&block)\n end\nwhen \"diagonal\"\n @rows.each_with_index do |row, row_index|\n yield row.fetch(row_index) do\n return self\n end\n end\nwhen \"off_diagonal\"\n @rows.each_with_index do |row, row_index|\n column_count.times do |col_index|\n if row_index == col_index\n else\n yield row[col_index]\n end\n end\n end\nwhen \"lower\"\n @rows.each_with_index do |row, row_index|\n 0.upto([row_index, last].min) do |col_index|\n yield row[col_index]\n end\n end\nwhen \"strict_lower\"\n @rows.each_with_index do |row, row_index|\n [row_index, column_count].min.times do |col_index|\n yield row[col_index]\n end\n end\nwhen \"strict_upper\"\n @rows.each_with_index do |row, row_index|\n (row_index + 1).upto(last - 1) do |col_index|\n yield row[col_index]\n end\n end\nwhen \"upper\"\n @rows.each_with_index do |row, row_index|\n row_index.upto(last - 1) do |col_index|\n yield row[col_index]\n end\n end\nelse\n raise(ArgumentError.new(\"expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper\"))\nend\n"}},{"id":"each_with_index(which=:all,&block:T,Int32,Int32->)-instance-method","html_id":"each_with_index(which=:all,&block:T,Int32,Int32->)-instance-method","name":"each_with_index","doc":"Same as #each, but the row index and column index in addition to the element\n\n```\nMatrix[ [1,2], [3,4] ].each_with_index do |e, row, col|\nputs \"#{e} at #{row}, #{col}\"\nend\n# => Prints:\n# 1 at 0, 0\n# 2 at 0, 1\n# 3 at 1, 0\n# 4 at 1, 1\n```","summary":"Same as #each, but the row index and column index in addition to the element
","abstract":false,"args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"args_string":"(which = :all, &block : T, Int32, Int32 -> )","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L438","def":{"name":"each_with_index","args":[{"name":"which","doc":null,"default_value":":all","external_name":"which","restriction":""}],"double_splat":null,"splat_index":null,"yields":3,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T, Int32, Int32 -> )"},"return_type":"","visibility":"Public","body":"last = column_count\ncase which.to_s\nwhen \"all\"\n @rows.each_with_index do |row, row_index|\n row.each_with_index do |e, col_index|\n block.call(e, row_index, col_index)\n end\n end\nwhen \"diagonal\"\n @rows.each_with_index do |row, row_index|\n block.call(row.fetch(row_index) do\n return self\n end, row_index, row_index)\n end\nwhen \"off_diagonal\"\n @rows.each_with_index do |row, row_index|\n column_count.times do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"lower\"\n @rows.each_with_index do |row, row_index|\n 0.upto([row_index, last].min) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"strict_lower\"\n @rows.each_with_index do |row, row_index|\n [row_index, column_count].min.times do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"strict_upper\"\n @rows.each_with_index do |row, row_index|\n (row_index + 1).upto(last - 1) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nwhen \"upper\"\n @rows.each_with_index do |row, row_index|\n row_index.upto(last - 1) do |col_index|\n block.call(row[col_index], row_index, col_index)\n end\n end\nelse\n raise(ArgumentError.new(\"expected #{which.inspect} to be one of :all, :diagonal, :off_diagonal, :lower, :strict_lower, :strict_upper or :upper\"))\nend\n"}},{"id":"eigensystem-instance-method","html_id":"eigensystem-instance-method","name":"eigensystem","doc":"Returns the Eigensystem of the matrix\nSee `EigenvalueDecomposition`.\n\nNOTE: Not working yet\n\n```\nm = Matrix[[1, 2], [3, 4]]\nv, d, v_inv = m.eigensystem\nd.diagonal? # => true\nv.inv == v_inv # => true\n(v * d * v_inv).round(5) == m # => true\n```","summary":"Returns the Eigensystem of the matrix See EigenvalueDecomposition
.
Returns true if this matrix is empty.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L705","def":{"name":"empty?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(column_count == 0) || (row_count == 0)"}},{"id":"first_minor(row,column)-instance-method","html_id":"first_minor(row,column)-instance-method","name":"first_minor","doc":"Returns the submatrix obtained by deleting the specified row and column.\n\n```\nMatrix.diagonal(9, 5, -3, 4).first_minor(1, 2)\n# => [ 9, 0, 0,\n# 0, 0, 0,\n# 0, 0, 4 ]\n```","summary":"Returns the submatrix obtained by deleting the specified row and column.
","abstract":false,"args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(row, column)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L585","def":{"name":"first_minor","args":[{"name":"row","doc":null,"default_value":"","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n raise(\"first_minor of empty matrix is not defined\")\nend\nif 0 <= row && row < row_count\nelse\n raise(ArgumentError.new(\"invalid row (#{row.inspect} for 0..#{row_count - 1})\"))\nend\nif 0 <= column && column < column_count\nelse\n raise(ArgumentError.new(\"invalid column (#{column.inspect} for 0..#{column_count - 1})\"))\nend\narrays = to_a\narrays.delete_at(row)\narrays.each do |array|\n array.delete_at(column)\nend\nMatrix.new(arrays, column_count - 1)\n"}},{"id":"hadamard_product(m)-instance-method","html_id":"hadamard_product(m)-instance-method","name":"hadamard_product","doc":"Hadamard product\n\n```\nMatrix[[1,2], [3,4]].hadamard_product Matrix[[1,2], [3,2]]\n# => [ 1, 4,\n# 9, 8 ]\n```","summary":"Hadamard product
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":""}],"args_string":"(m)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L999","def":{"name":"hadamard_product","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"combine(m) do |a, b|\n a * b\nend"}},{"id":"hermitian?-instance-method","html_id":"hermitian?-instance-method","name":"hermitian?","doc":"Returns `true` if this is an hermitian matrix.","summary":"Returns true
if this is an hermitian matrix.
Returns a new matrix resulting by stacking horizontally the receiver with the given matrices
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1161","def":{"name":"hstack","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.hstack(self, *matrices)"}},{"id":"imag-instance-method","html_id":"imag-instance-method","name":"imag","doc":"Returns the imaginary part of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => [ 1+2i, i, 0,\n# 1, 2, 3 ]\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].imag\n# => [ 2i, i, 0,\n# 0, 0, 0 ]\n```","summary":"Returns the imaginary part of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1328","def":{"name":"imag","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#imag only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.imag)\n"}},{"id":"index(i,selector=:all)-instance-method","html_id":"index(i,selector=:all)-instance-method","name":"index","doc":"The index method is specialized to return the index as {row, column}\nIt also accepts an optional `selector` argument, see `#each` for details.\n\n```\nMatrix[ [1,1], [1,1] ].index(1, :strict_lower)\n# => {1, 0}\n```","summary":"The index method is specialized to return the index as {row, column} It also accepts an optional selector
argument, see #each
for details.
Returns the index as {row, column}, using &block
to filter the result.
Returns the inverse of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1013","def":{"name":"inverse","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nlast = row_count - 1\na = self.coerce(Float64)\nm = Matrix(Float64).identity(row_count)\n0.upto(last) do |k|\n i = k\n akk = a[k, k].abs\n (k + 1).upto(last) do |j|\n v = a[j, k].abs\n if v > akk\n i = j\n akk = v\n end\n end\n if akk == 0\n raise(ErrNotRegular.new)\n end\n if i != k\n a.swap_rows(i, k)\n m.swap_rows(i, k)\n end\n akk = a[k, k]\n 0.upto(last) do |ii|\n if ii == k\n next\n end\n q = a[ii, k] / akk\n a[ii, k] = 0.0\n (k + 1).upto(last) do |j|\n __temp_24 = ii\n __temp_25 = j\n a[__temp_24, __temp_25] = a[__temp_24, __temp_25] - (a[k, j] * q)\n end\n 0.upto(last) do |j|\n __temp_27 = ii\n __temp_28 = j\n m[__temp_27, __temp_28] = m[__temp_27, __temp_28] - (m[k, j] * q)\n end\n end\n (k + 1).upto(last) do |j|\n a[k, j] = a[k, j] / akk\n end\n 0.upto(last) do |j|\n m[k, j] = m[k, j] / akk\n end\nend\nm\n"}},{"id":"laplace_expansion(*,row=nil,column=nil)-instance-method","html_id":"laplace_expansion(*,row=nil,column=nil)-instance-method","name":"laplace_expansion","doc":"Returns the Laplace expansion along given row or column.\n\n```\nMatrix[[7,6], [3,9]].laplace_expansion(column: 1)\n# => 45\n\nMatrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0)\n# => Vector[3, -2]\n```","summary":"Returns the Laplace expansion along given row or column.
","abstract":false,"args":[{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"row","doc":null,"default_value":"nil","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"nil","external_name":"column","restriction":""}],"args_string":"(*, row = nil, column = nil)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L642","def":{"name":"laplace_expansion","args":[{"name":"","doc":null,"default_value":"","external_name":"","restriction":""},{"name":"row","doc":null,"default_value":"nil","external_name":"row","restriction":""},{"name":"column","doc":null,"default_value":"nil","external_name":"column","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"num = row || column\nif (!num) || (row && column)\n raise(ArgumentError.new(\"exactly one the row or column arguments must be specified\"))\nend\nif square?\nelse\n raise(ErrDimensionMismatch.new)\nend\nif empty?\n raise(\"laplace_expansion of empty matrix is not defined\")\nend\nif 0 <= num && num < row_count\nelse\n raise(ArgumentError, \"invalid num (#{num.inspect} for 0..#{row_count - 1})\")\nend\nif row\n (row(num)).map_with_index do |e, k|\n e * (cofactor(num, k))\n end.reduce(&.+)\nelse\n (col(num)).map_with_index do |e, k|\n e * (cofactor(k, num))\n end.reduce(&.+)\nend\n"}},{"id":"lower_triangular?-instance-method","html_id":"lower_triangular?-instance-method","name":"lower_triangular?","doc":"Returns true if this matrix is a lower triangular matrix.","summary":"Returns true if this matrix is a lower triangular matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L720","def":{"name":"lower_triangular?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = [] of T\neach(:strict_upper) do |e|\n els << e\nend\nels.all?(&.zero?)\n"}},{"id":"lup-instance-method","html_id":"lup-instance-method","name":"lup","doc":"Returns the LUP decomposition of the matrix\nSee +LUPDecomposition+.\n\nNOTE: Not working yet\n\n```\na = Matrix[[1, 2], [3, 4]]\nl, u, p = a.lup\nl.lower_triangular? # => true\nu.upper_triangular? # => true\np.permutation? # => true\nl * u == p * a # => true\na.lup.solve([2, 5]) # => Vector[(1/1), (1/2)]\n```","summary":"Returns the LUP decomposition of the matrix See +LUPDecomposition+.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1295","def":{"name":"lup","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"LUPDecomposition.new(self)"}},{"id":"map(&block:T->T)-instance-method","html_id":"map(&block:T->T)-instance-method","name":"map","doc":"Returns a Matrix that is the result of iteration of the given block\nover all elements in the matrix.","summary":"Returns a Matrix that is the result of iteration of the given block over all elements in the matrix.
","abstract":false,"args":[],"args_string":"(&block : T -> T)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L359","def":{"name":"map","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> T)"},"return_type":"","visibility":"Public","body":"rows = @rows.map do |row|\n row.map(&block)\nend\nMatrix.new(rows, column_count)\n"}},{"id":"minor(from_row:Int,nrows:Int,from_col:Int,ncols:Int)-instance-method","html_id":"minor(from_row:Int,nrows:Int,from_col:Int,ncols:Int)-instance-method","name":"minor","doc":"Returns a section of the Matrix.\n\n```\nMatrix.diagonal(9, 5, -3).minor(0, 2, 0, 3)\n# => [ 9, 0, 0,\n# 0, 5, 0 ]\n```","summary":"Returns a section of the Matrix.
","abstract":false,"args":[{"name":"from_row","doc":null,"default_value":"","external_name":"from_row","restriction":"Int"},{"name":"nrows","doc":null,"default_value":"","external_name":"nrows","restriction":"Int"},{"name":"from_col","doc":null,"default_value":"","external_name":"from_col","restriction":"Int"},{"name":"ncols","doc":null,"default_value":"","external_name":"ncols","restriction":"Int"}],"args_string":"(from_row : Int, nrows : Int, from_col : Int, ncols : Int)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L563","def":{"name":"minor","args":[{"name":"from_row","doc":null,"default_value":"","external_name":"from_row","restriction":"Int"},{"name":"nrows","doc":null,"default_value":"","external_name":"nrows","restriction":"Int"},{"name":"from_col","doc":null,"default_value":"","external_name":"from_col","restriction":"Int"},{"name":"ncols","doc":null,"default_value":"","external_name":"ncols","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if nrows < 0 || ncols < 0\n return nil\nend\nif from_row < 0\n from_row = from_row + row_count\nend\nif from_col < 0\n from_col = from_col + column_count\nend\nif ((from_row > row_count || from_col > column_count) || from_row < 0) || from_col < 0\n return nil\nend\nrows = @rows[from_row, nrows].map do |row|\n row[from_col, ncols]\nend\nMatrix.new(rows, [column_count - from_col, ncols].min)\n"}},{"id":"minor(row_range:Range,col_range:Range)-instance-method","html_id":"minor(row_range:Range,col_range:Range)-instance-method","name":"minor","doc":"Returns a section of the Matrix.\n\n```\nMatrix.diagonal(9, 5, -3).minor(0..1, 0..2)\n# => [ 9, 0, 0,\n# 0, 5, 0 ]\n```","summary":"Returns a section of the Matrix.
","abstract":false,"args":[{"name":"row_range","doc":null,"default_value":"","external_name":"row_range","restriction":"Range"},{"name":"col_range","doc":null,"default_value":"","external_name":"col_range","restriction":"Range"}],"args_string":"(row_range : Range, col_range : Range)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L532","def":{"name":"minor","args":[{"name":"row_range","doc":null,"default_value":"","external_name":"row_range","restriction":"Range"},{"name":"col_range","doc":null,"default_value":"","external_name":"col_range","restriction":"Range"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"from_row = row_range.first\nif from_row < 0\n from_row = from_row + row_count\nend\nto_row = row_range.end\nif to_row < 0\n to_row = to_row + row_count\nend\nif row_range.excludes_end?\nelse\n to_row = to_row + 1\nend\nsize_row = to_row - from_row\nfrom_col = col_range.first\nif from_col < 0\n from_col = from_col + column_count\nend\nto_col = col_range.end\nif to_col < 0\n to_col = to_col + column_count\nend\nif col_range.excludes_end?\nelse\n to_col = to_col + 1\nend\nsize_col = to_col - from_col\nif ((from_row > row_count || from_col > column_count) || from_row < 0) || from_col < 0\n return nil\nend\nrows = @rows[from_row, size_row].map do |row|\n row[from_col, size_col]\nend\nMatrix.new(rows, [column_count - from_col, size_col].min)\n"}},{"id":"normal?-instance-method","html_id":"normal?-instance-method","name":"normal?","doc":"Returns `true` if this is a normal matrix.\n\n```\nMatrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].normal?\n# => true\n```","summary":"Returns true
if this is a normal matrix.
Returns true
if this is an orthogonal matrix
Returns true
if this is a permutation matrix
Returns the rank of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1175","def":{"name":"rank","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"a = to_a\nlast_column = column_count - 1\nlast_row = row_count - 1\npivot_row = 0\nprevious_pivot = 1\n0.upto(last_column) do |k|\n switch_row = (pivot_row..last_row).find do |row|\n a[row][k] != 0\n end\n if switch_row\n if pivot_row == switch_row\n else\n a[switch_row], a[pivot_row] = a[pivot_row], a[switch_row]\n end\n pivot = a[pivot_row][k]\n (pivot_row + 1).upto(last_row) do |i|\n ai = a[i]\n (k + 1).upto(last_column) do |j|\n ai[j] = ((pivot * ai[j]) - (ai[k] * a[pivot_row][j])) / previous_pivot\n end\n end\n pivot_row = pivot_row + 1\n previous_pivot = pivot\n end\nend\npivot_row\n"}},{"id":"real-instance-method","html_id":"real-instance-method","name":"real","doc":"Returns the real part of the matrix.\n\n```\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]\n# => [ 1+2i, i, 0,\n# 1, 2, 3 ]\nMatrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real\n# => [ 1, 0, 0,\n# 1, 2, 3 ]\n```","summary":"Returns the real part of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1343","def":{"name":"real","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#real only works with real matrices (i.e. Matrix(Complex))\"))\nend\nmap(&.real)\n"}},{"id":"real?-instance-method","html_id":"real?-instance-method","name":"real?","doc":"Returns `true` if this matrix contains real numbers,\ni.e. not `Complex`.\n\n```\nrequire \"complex\"\nMatrix[[Complex.new(1, 0)], [Complex.new(0, 1)]].real?\n# => false\n```","summary":"Returns true
if this matrix contains real numbers, i.e.
Returns an array containing matrices corresponding to the real and imaginary parts of the matrix
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1355","def":{"name":"rect","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if real?\nelse\n raise(ArgumentError.new(\"Matrix#real only works with real matrices (i.e. Matrix(Complex))\"))\nend\n[real, imag]\n"}},{"id":"regular?-instance-method","html_id":"regular?-instance-method","name":"regular?","doc":"Returns `true` if this is a regular (i.e. non-singular) matrix.","summary":"Returns true
if this is a regular (i.e.
Returns a matrix with entries rounded to the given precision (see Float#round
)
Returns a block which yields every Vector in the row (starting at 0).
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i, &block : Vector -> )","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L322","def":{"name":"row","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(Vector -> )"},"return_type":"","visibility":"Public","body":"(row(i)).each(&block)"}},{"id":"row(i)-instance-method","html_id":"row(i)-instance-method","name":"row","doc":"Returns row vector number `i` of the Matrix as a Vector (starting\nat 0 like a good boy). Raises if the row doesn't exist.","summary":"Returns row vector number i
of the Matrix as a Vector (starting at 0 like a good boy).
Returns row vector number i
of the Matrix as a Vector (starting at 0 like a good boy).
Returns the number of rows.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L307","def":{"name":"row_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rows.size"}},{"id":"row_vectors-instance-method","html_id":"row_vectors-instance-method","name":"row_vectors","doc":"Returns an array of the row vectors of the matrix. See `Vector`.","summary":"Returns an array of the row vectors of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1371","def":{"name":"row_vectors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array.new(row_count) do |i|\n row(i)\nend"}},{"id":"singular?-instance-method","html_id":"singular?-instance-method","name":"singular?","doc":"Returns `true` if this is a singular matrix.","summary":"Returns true
if this is a singular matrix.
Returns true
if this is a square matrix.
Swaps col1
and col2
Swaps row1
and row2
Returns +true+ if this is a symmetric matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L820","def":{"name":"symmetric?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n return false\nend\nresult = true\neach_with_index(:strict_upper) do |e, row, col|\n if e != rows[col][row]\n result = false\n end\nend\nresult\n"}},{"id":"t-instance-method","html_id":"t-instance-method","name":"t","doc":"Returns the transpose of the matrix.\n\n```\nMatrix[[1,2], [3,4], [5,6]]\n# => [ 1, 2,\n# 3, 4,\n# 5, 6 ]\nMatrix[[1,2], [3,4], [5,6]].transpose\n# => [ 1, 3, 5,\n# 2, 4, 6 ]\n```","summary":"Returns the transpose of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1244","def":{"name":"t","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"transpose"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Returns an array of arrays that describe the rows of the matrix.","summary":"Returns an array of arrays that describe the rows of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1385","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@rows.clone"}},{"id":"to_json(json:JSON::Builder)-instance-method","html_id":"to_json(json:JSON::Builder)-instance-method","name":"to_json","doc":"Convert the matrix to a json array","summary":"Convert the matrix to a json array
","abstract":false,"args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"JSON::Builder"}],"args_string":"(json : JSON::Builder)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1390","def":{"name":"to_json","args":[{"name":"json","doc":null,"default_value":"","external_name":"json","restriction":"JSON::Builder"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"json.array do\n each(&.to_json(json))\nend"}},{"id":"to_s(io)-instance-method","html_id":"to_s(io)-instance-method","name":"to_s","doc":null,"summary":null,"abstract":false,"args":[{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":""}],"args_string":"(io)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1400","def":{"name":"to_s","args":[{"name":"io","doc":null,"default_value":"","external_name":"io","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if empty?\n \"Matrix.empty(#{row_count}, #{column_count})\"\nelse\n io << \"Matrix[\"\n io << (rows.map do |row|\n (\"[\" + (row.map do |e|\n e.to_s\n end.join(\", \"))) + \"]\"\n end.join(\", \"))\n io << \"]\"\nend"}},{"id":"tr-instance-method","html_id":"tr-instance-method","name":"tr","doc":"Returns the trace (sum of diagonal elements) of the matrix.\n\n```\nMatrix[[7,6], [3,9]].trace\n# => 16\n```","summary":"Returns the trace (sum of diagonal elements) of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1223","def":{"name":"tr","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"trace"}},{"id":"trace-instance-method","html_id":"trace-instance-method","name":"trace","doc":"Returns the trace (sum of diagonal elements) of the matrix.\n\n```\nMatrix[[7,6], [3,9]].trace\n# => 16\n```","summary":"Returns the trace (sum of diagonal elements) of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1215","def":{"name":"trace","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n raise(ErrDimensionMismatch.new)\nend\n(0...column_count).reduce(0) do |tr, i|\n tr + @rows[i][i]\nend\n"}},{"id":"transpose-instance-method","html_id":"transpose-instance-method","name":"transpose","doc":"Returns the transpose of the matrix.\n\n```\nMatrix[[1,2], [3,4], [5,6]]\n# => [ 1, 2,\n# 3, 4,\n# 5, 6 ]\nMatrix[[1,2], [3,4], [5,6]].transpose\n# => [ 1, 3, 5,\n# 2, 4, 6 ]\n```","summary":"Returns the transpose of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1238","def":{"name":"transpose","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if row_count.zero?\n return self.class.empty(column_count, 0)\nend\nMatrix.new(@rows.transpose, row_count)\n"}},{"id":"unitary?-instance-method","html_id":"unitary?-instance-method","name":"unitary?","doc":"Returns `true` if this is a unitary matrix","summary":"Returns true
if this is a unitary matrix
Returns true if this matrix is a upper triangular matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L852","def":{"name":"upper_triangular?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = [] of T\neach(:strict_lower) do |e|\n els << e\nend\nels.all?(&.zero?)\n"}},{"id":"vstack(*matrices)-instance-method","html_id":"vstack(*matrices)-instance-method","name":"vstack","doc":"Returns a new matrix resulting by stacking vertically\nthe receiver with the given matrices\n\n```\nx = Matrix[[1, 2], [3, 4]]\ny = Matrix[[5, 6], [7, 8]]\nx.vstack(y)\n# => Matrix[[1, 2], [3, 4], [5, 6], [7, 8]]\n```","summary":"Returns a new matrix resulting by stacking vertically the receiver with the given matrices
","abstract":false,"args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"args_string":"(*matrices)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix.cr#L1257","def":{"name":"vstack","args":[{"name":"matrices","doc":null,"default_value":"","external_name":"matrices","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.vstack(self, *matrices)"}},{"id":"zero?-instance-method","html_id":"zero?-instance-method","name":"zero?","doc":"Returns `true` if this is a matrix with only zero elements","summary":"Returns true
if this is a matrix with only zero elements
Eigenvalues and eigenvectors of a real matrix.
","class_methods":[],"constructors":[{"id":"new(matrix)-class-method","html_id":"new(matrix)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"args_string":"(matrix)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/eigenvalue_decomposition.cr#L13","def":{"name":"new","args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(matrix)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix/LupDecomposition","path":"Apatite/LinearAlgebra/Matrix/LupDecomposition.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix::LupDecomposition","name":"LupDecomposition","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/matrix/lup_decomposition.cr","line_number":12,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Matrix","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix(T)","name":"Matrix"},"doc":"For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n\nunit lower triangular matrix L, an n-by-n upper triangular matrix U,\nand a m-by-m permutation matrix P so that L*U = P*A.\nIf m < n, then L is m-by-m and U is m-by-n.\n\nThe LUP decomposition with pivoting always exists, even if the matrix is\nsingular, so the constructor will never fail. The primary use of the\nLU decomposition is in the solution of square systems of simultaneous\nlinear equations. This will fail if singular? returns true.","summary":"For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a m-by-m permutation matrix P so that LU = PA.
","class_methods":[],"constructors":[{"id":"new(matrix)-class-method","html_id":"new(matrix)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"args_string":"(matrix)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/matrix/lup_decomposition.cr#L13","def":{"name":"new","args":[{"name":"matrix","doc":null,"default_value":"","external_name":"matrix","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(matrix)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[],"macros":[],"types":[]}]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/NDArray","path":"Apatite/LinearAlgebra/NDArray.html","kind":"class","full_name":"Apatite::LinearAlgebra::NDArray","name":"NDArray","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/ndarray.cr","line_number":2,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":null,"summary":null,"class_methods":[],"constructors":[{"id":"new(data:Array(Number),shape:Array(Int32)?=nil)-class-method","html_id":"new(data:Array(Number),shape:Array(Int32)?=nil)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array(Number)"},{"name":"shape","doc":null,"default_value":"nil","external_name":"shape","restriction":"Array(Int32) | ::Nil"}],"args_string":"(data : Array(Number), shape : Array(Int32)? = nil)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L18","def":{"name":"new","args":[{"name":"data","doc":null,"default_value":"","external_name":"data","restriction":"Array(Number)"},{"name":"shape","doc":null,"default_value":"nil","external_name":"shape","restriction":"Array(Int32) | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(data, shape)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"[](*args,**options)-instance-method","html_id":"[](*args,**options)-instance-method","name":"[]","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"[]","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]"}},{"id":"[](*args,**options,&block)-instance-method","html_id":"[](*args,**options,&block)-instance-method","name":"[]","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"[]","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options] do |*yield_args|\n yield *yield_args\nend"}},{"id":"[]=(*args,**options)-instance-method","html_id":"[]=(*args,**options)-instance-method","name":"[]=","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L13","def":{"name":"[]=","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args] = **options"}},{"id":"[]?(*args,**options)-instance-method","html_id":"[]?(*args,**options)-instance-method","name":"[]?","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L12","def":{"name":"[]?","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]?"}},{"id":"[]?(*args,**options,&block)-instance-method","html_id":"[]?(*args,**options,&block)-instance-method","name":"[]?","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L12","def":{"name":"[]?","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data[*args, **options]? do |*yield_args|\n yield *yield_args\nend"}},{"id":"abs-instance-method","html_id":"abs-instance-method","name":"abs","doc":"Returns the absolute value of every item in the array","summary":"Returns the absolute value of every item in the array
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L24","def":{"name":"abs","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |e|\n e.abs\nend"}},{"id":"acos-instance-method","html_id":"acos-instance-method","name":"acos","doc":"Returns the arccosine of each element in the current array.","summary":"Returns the arccosine of each element in the current array.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L29","def":{"name":"acos","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"id":"data:Array(Float64)-instance-method","html_id":"data:Array(Float64)-instance-method","name":"data","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Array(Float64)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L9","def":{"name":"data","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(Float64)","visibility":"Public","body":"@data"}},{"id":"shape:Array(Int32)-instance-method","html_id":"shape:Array(Int32)-instance-method","name":"shape","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Array(Int32)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L11","def":{"name":"shape","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Array(Int32)","visibility":"Public","body":"@shape"}},{"id":"size(*args,**options)-instance-method","html_id":"size(*args,**options)-instance-method","name":"size","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L16","def":{"name":"size","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.size(*args, **options)"}},{"id":"size(*args,**options,&block)-instance-method","html_id":"size(*args,**options,&block)-instance-method","name":"size","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L16","def":{"name":"size","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.size(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"to_unsafe(*args,**options)-instance-method","html_id":"to_unsafe(*args,**options)-instance-method","name":"to_unsafe","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L15","def":{"name":"to_unsafe","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.to_unsafe(*args, **options)"}},{"id":"to_unsafe(*args,**options,&block)-instance-method","html_id":"to_unsafe(*args,**options,&block)-instance-method","name":"to_unsafe","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L15","def":{"name":"to_unsafe","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.to_unsafe(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"unsafe_fetch(*args,**options)-instance-method","html_id":"unsafe_fetch(*args,**options)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L14","def":{"name":"unsafe_fetch","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.unsafe_fetch(*args, **options)"}},{"id":"unsafe_fetch(*args,**options,&block)-instance-method","html_id":"unsafe_fetch(*args,**options,&block)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/ndarray.cr#L14","def":{"name":"unsafe_fetch","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@data.unsafe_fetch(*args, **options) do |*yield_args|\n yield *yield_args\nend"}}],"macros":[],"types":[]},{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra/Vector","path":"Apatite/LinearAlgebra/Vector.html","kind":"class","full_name":"Apatite::LinearAlgebra::Vector(T)","name":"Vector","abstract":false,"superclass":{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Iterable","kind":"module","full_name":"Iterable","name":"Iterable"},{"html_id":"github.com/watzon/apatite/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/watzon/apatite/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"apatite/linear_algebra/vector.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[{"html_id":"github.com/watzon/apatite/Comparable","kind":"module","full_name":"Comparable","name":"Comparable"},{"html_id":"github.com/watzon/apatite/Enumerable","kind":"module","full_name":"Enumerable","name":"Enumerable"},{"html_id":"github.com/watzon/apatite/Indexable","kind":"module","full_name":"Indexable","name":"Indexable"}],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"},"doc":"Represents a mathematical vector, and also constitutes a row or column\nof a `Matrix`","summary":"Represents a mathematical vector, and also constitutes a row or column of a Matrix
Creates a new vector from a list of elements.
","abstract":false,"args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""}],"args_string":"(*array)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L22","def":{"name":"[]","args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new(array)"}},{"id":"basis(size,index)-class-method","html_id":"basis(size,index)-class-method","name":"basis","doc":"Returns a standard basis `n`-vector.","summary":"Returns a standard basis n
-vector.
Creates a vector from an Array.
","abstract":false,"args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(array, copy = true)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L28","def":{"name":"elements","args":[{"name":"array","doc":null,"default_value":"","external_name":"array","restriction":""},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if copy\n array = array.clone\nend\nnew(array)\n"}},{"id":"zero(size)-class-method","html_id":"zero(size)-class-method","name":"zero","doc":"Return a zero vector.","summary":"Return a zero vector.
","abstract":false,"args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""}],"args_string":"(size)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L53","def":{"name":"zero","args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size < 0\n raise(ArgumentError.new(\"invalid size (#{size} for 0..)\"))\nend\narray = Array.new(size, 0)\nnew(array)\n"}}],"constructors":[],"instance_methods":[{"id":"*(x)-instance-method","html_id":"*(x)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is a number or a matrix.","summary":"Multiplies the vector by x, where x is a number or a matrix.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L60","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e * x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg0|\n x = __arg0[0]\n y = __arg0[1]\n x * y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"+(x)-instance-method","html_id":"+(x)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L75","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e + x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg1|\n x = __arg1[0]\n y = __arg1[1]\n x + y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"-(x)-instance-method","html_id":"-(x)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L90","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e - x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg2|\n x = __arg2[0]\n y = __arg2[1]\n x - y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"/(x)-instance-method","html_id":"/(x)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"args_string":"(x)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L105","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case x\nwhen Number\n els = @elements.map do |e|\n (e / x).as(T)\n end\n self.class.elements(els, false)\nwhen Vector\n (self.elements.zip(x.elements)).map do |__arg3|\n x = __arg3[0]\n y = __arg3[1]\n x / y\n end\nelse\n raise(ArgumentError.new)\nend"}},{"id":"-instance-method","html_id":"-instance-method","name":"<=>","doc":"Take me to your leader","summary":"Take me to your leader
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L129","def":{"name":"<=>","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if other.is_a?(Vector)\n @elements <=> other.elements\nelse\n @elements <=> other\nend"}},{"id":"==(other)-instance-method","html_id":"==(other)-instance-method","name":"==","doc":"Equality operator","summary":"Equality operator
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L120","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if other.is_a?(Vector)\n @elements == other.elements\nelse\n @elements == other\nend"}},{"id":"angle_with(v)-instance-method","html_id":"angle_with(v)-instance-method","name":"angle_with","doc":"Returns an angle with another vector. Result is within the [0…Math::PI].","summary":"Returns an angle with another vector.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L138","def":{"name":"angle_with","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\nprod = magnitude * v.magnitude\nif prod == 0\n raise(ZeroVectorError.new(\"Can't get angle of zero vector\"))\nend\nMath.acos((inner_product(v)) / prod)\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":"Returns a copy of the vector.","summary":"Returns a copy of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L147","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self.class.elements(@elements)"}},{"id":"coerce(klass,*args)-instance-method","html_id":"coerce(klass,*args)-instance-method","name":"coerce","doc":"The coerce method allows you to attempt to coerce the elements\nin the matrix to another type. The type","summary":"The coerce method allows you to attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(klass, *args)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L249","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":""},{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":null,"splat_index":1,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case klass.to_s\nwhen \"Complex\"\n if args[0]?\n else\n raise(\"coercing to a Complex requires a second argument\")\n end\n els = @elements.map do |e|\n Complex.new(e, args[0].as(Int32))\n end\nwhen \"BigInt\"\n base = args[0]? || 10\n els = @elements.map do |e|\n klass.new(e, base)\n end\nwhen \"BigRational\"\n if args[0]?\n else\n raise(\"coercing to a BigRational requires a second argument to use as a denominator\")\n end\n els = @elements.map do |e|\n klass.new(e, args[0])\n end\nelse\n els = @elements.map do |e|\n klass.new(e)\n end\nend\nVector.elements(els)\n"}},{"id":"cross(v)-instance-method","html_id":"cross(v)-instance-method","name":"cross","doc":"Returns the cross product of this vector with the others.","summary":"Returns the cross product of this vector with the others.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L193","def":{"name":"cross","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"cross_product(v)"}},{"id":"cross_product(*vs)-instance-method","html_id":"cross_product(*vs)-instance-method","name":"cross_product","doc":"Returns the cross product of this vector with the others.","summary":"Returns the cross product of this vector with the others.
","abstract":false,"args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"args_string":"(*vs)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L170","def":{"name":"cross_product","args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size >= 2\nelse\n raise(ErrOperationNotDefined.new(\"cross product is not defined on vectors of dimension #{size}\"))\nend\nif vs.size == (size - 2)\nelse\n raise(ArgumentError.new(\"wrong number of arguments (#{vs.size} for #{size - 2})\"))\nend\nvs.each do |v|\n if v.size == size\n else\n raise(ErrDimensionMismatch.new)\n end\nend\ncase size\nwhen 2\n Vector[-@elements[1], @elements[0]]\nwhen 3\n v = vs[0]\n Vector[(v[2] * @elements[1]) - (v[1] * @elements[2]), (v[0] * @elements[2]) - (v[2] * @elements[0]), (v[1] * @elements[0]) - (v[0] * @elements[1])]\nelse\n rows = (self + vs) + (Array.new(size) do |i|\n Vector.basis(size, i)\n end)\n (Matrix.rows(rows)).laplace_expansion(row: size - 1)\nend\n"}},{"id":"dot(v)-instance-method","html_id":"dot(v)-instance-method","name":"dot","doc":"Returns the inner product of this vector with the other.","summary":"Returns the inner product of this vector with the other.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L207","def":{"name":"dot","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"inner_product(v)"}},{"id":"each(*args,**options)-instance-method","html_id":"each(*args,**options)-instance-method","name":"each","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L14","def":{"name":"each","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.each(*args, **options)"}},{"id":"each(*args,**options,&block)-instance-method","html_id":"each(*args,**options,&block)-instance-method","name":"each","doc":null,"summary":null,"abstract":false,"args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"args_string":"(*args, **options, &block)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L14","def":{"name":"each","args":[{"name":"args","doc":null,"default_value":"","external_name":"args","restriction":""}],"double_splat":{"name":"options","doc":null,"default_value":"","external_name":"options","restriction":""},"splat_index":0,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.each(*args, **options) do |*yield_args|\n yield *yield_args\nend"}},{"id":"each2(v,&block)-instance-method","html_id":"each2(v,&block)-instance-method","name":"each2","doc":"Iterate over the elements of this vector and `v` in conjunction.","summary":"Iterate over the elements of this vector and v
in conjunction.
Returns the inner product of this vector with the other.
","abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L198","def":{"name":"inner_product","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\np = 0\neach2(v) do |v1, v2|\n p = p + (v1 * v2)\nend\np\n"}},{"id":"inspect-instance-method","html_id":"inspect-instance-method","name":"inspect","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L286","def":{"name":"inspect","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"<#Vector(#{T}) [#{@elements.join(\", \")}]>\""}},{"id":"magnitude-instance-method","html_id":"magnitude-instance-method","name":"magnitude","doc":"Returns the modulus (Pythagorean distance) of the vector.","summary":"Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L221","def":{"name":"magnitude","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Math.sqrt(@elements.reduce(0) do |v, e|\n v + e.abs2\nend)"}},{"id":"map(&block:T->UNDERSCORE)-instance-method","html_id":"map(&block:T->UNDERSCORE)-instance-method","name":"map","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"(&block : T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L151","def":{"name":"map","args":[],"double_splat":null,"splat_index":null,"yields":1,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T -> _)"},"return_type":"","visibility":"Public","body":"els = @elements.map(&block)\nself.class.elements(els, false)\n"}},{"id":"map2(v,&block:T,T->UNDERSCORE)-instance-method","html_id":"map2(v,&block:T,T->UNDERSCORE)-instance-method","name":"map2","doc":null,"summary":null,"abstract":false,"args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"args_string":"(v, &block : T, T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L156","def":{"name":"map2","args":[{"name":"v","doc":null,"default_value":"","external_name":"v","restriction":""}],"double_splat":null,"splat_index":null,"yields":2,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":"(T, T -> _)"},"return_type":"","visibility":"Public","body":"if size != v.size\n raise(ErrDimensionMismatch.new)\nend\narr = Array.new(size) do |i|\n yield @elements[i], v[i]\nend\nself.class.elements(arr, false)\n"}},{"id":"norm-instance-method","html_id":"norm-instance-method","name":"norm","doc":"Returns the modulus (Pythagorean distance) of the vector.","summary":"Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L226","def":{"name":"norm","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"magnitude"}},{"id":"normalize-instance-method","html_id":"normalize-instance-method","name":"normalize","doc":"Returns a new vector with the same direction but with norm 1","summary":"Returns a new vector with the same direction but with norm 1
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L231","def":{"name":"normalize","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"n = magnitude\nif n == 0\n raise(ZeroVectorError.new(\"Zero vectors can not be normalized\"))\nend\nself / n\n"}},{"id":"r-instance-method","html_id":"r-instance-method","name":"r","doc":"Returns a new vector with the same direction but with norm 1","summary":"Returns a new vector with the same direction but with norm 1
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L238","def":{"name":"r","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"magnitude"}},{"id":"round(ndigits=0)-instance-method","html_id":"round(ndigits=0)-instance-method","name":"round","doc":"Returns a vector with entries rounded to the given precision.","summary":"Returns a vector with entries rounded to the given precision.
","abstract":false,"args":[{"name":"ndigits","doc":null,"default_value":"0","external_name":"ndigits","restriction":""}],"args_string":"(ndigits = 0)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L243","def":{"name":"round","args":[{"name":"ndigits","doc":null,"default_value":"0","external_name":"ndigits","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |e|\n e.round(ndigits)\nend"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":"Returns the elements of the vector in an array.","summary":"Returns the elements of the vector in an array.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L268","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.dup"}},{"id":"to_matrix-instance-method","html_id":"to_matrix-instance-method","name":"to_matrix","doc":"Return a single-column matrix from this vector.","summary":"Return a single-column matrix from this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L273","def":{"name":"to_matrix","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.column_vector(self)"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L277","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(\"Vector{\" + (@elements.join(\", \"))) + \"}\""}},{"id":"unsafe_fetch(i)-instance-method","html_id":"unsafe_fetch(i)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i)","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/linear_algebra/vector.cr#L290","def":{"name":"unsafe_fetch","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements.unsafe_fetch(i)"}},{"id":"zero?-instance-method","html_id":"zero?-instance-method","name":"zero?","doc":"Returns `true` if all elements are zero.","summary":"Returns true
if all elements are zero.
An Array
is an ordered, integer-indexed collection of objects of type T.
Tests whether all elements evaluate to true
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/core_ext/array.cr#L3","def":{"name":"all?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"each do |i|\n if (!(!i)) == false\n return false\n end\nend\ntrue\n"}},{"id":"any?-instance-method","html_id":"any?-instance-method","name":"any?","doc":"Tests whether any of the elements evaluate to true","summary":"Tests whether any of the elements evaluate to true
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/core_ext/array.cr#L11","def":{"name":"any?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"each do |i|\n if (!(!i)) == true\n return true\n end\nend\nfalse\n"}},{"id":"shape-instance-method","html_id":"shape-instance-method","name":"shape","doc":"Get the array's dimensions","summary":"Get the array's dimensions
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/core_ext/array.cr#L19","def":{"name":"shape","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"max = max_by do |i|\n i.is_a?(Array) ? i.size : i\nend\nmax.is_a?(Array) ? [size, max.size] : [max]\n"}},{"id":"to_vec-instance-method","html_id":"to_vec-instance-method","name":"to_vec","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/6e67ceb81b0b3c61d48b74e5ca5154866a9abd1a/src/apatite/core_ext/array.cr#L24","def":{"name":"to_vec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite::Vector.create(self)"}}],"macros":[],"types":[]}]}}) \ No newline at end of file diff --git a/src/apatite/linear_algebra/matrix.cr b/src/apatite/linear_algebra/matrix.cr index 510ee79..4e22d35 100644 --- a/src/apatite/linear_algebra/matrix.cr +++ b/src/apatite/linear_algebra/matrix.cr @@ -1,4 +1,3 @@ -require "json" require "./vector" require "./matrix/eigenvalue_decomposition" require "./matrix/lup_decomposition" @@ -98,6 +97,7 @@ module Apatite::LinearAlgebra new(rows) end + # ditto def self.diagonal(*values : T) diagonal(values, nil) end @@ -1367,6 +1367,36 @@ module Apatite::LinearAlgebra Matrix.rows(rws) end + # Returns an array of the row vectors of the matrix. See `Vector`. + def row_vectors + Array.new(row_count) {|i| + row(i) + } + end + + # Returns an array of the column vectors of the matrix. See `Vector`. + def column_vectors + Array.new(column_count) {|i| + column(i) + } + end + + # Returns an array of arrays that describe the rows of the matrix. + def to_a + @rows.clone + end + + # Convert the matrix to a json array + def to_json(json : JSON::Builder) + json.array do + each &.to_json(json) + end + end + + #-- + # PRINTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- + #++ + def to_s(io) if empty? "Matrix.empty(#{row_count}, #{column_count})" @@ -1390,17 +1420,6 @@ module Apatite::LinearAlgebra end end - def to_json(json : JSON::Builder) - json.array do - each &.to_json(json) - end - end - - # Returns this matrix as an `Array(Array(T))` - def to_a - @rows.clone - end - def unsafe_fetch(i) @rows.unsafe_fetch(i) end