Apatite
-Apatite 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.
+Apatite is a collection of mathematical and scientific algorithms. Currently it implements the API from Ruby's Matrix
class for both Matrix
and Vector
. This API will be added to as needs arise. The goal is for this project to eventually contain everything you could get from SciPy, but in pure Crystal.
Installation
diff --git a/docs/index.json b/docs/index.json index 12b147c..acfd5fb 100644 --- a/docs/index.json +++ b/docs/index.json @@ -1 +1 @@ -{"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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/error.cr"},{"filename":"apatite/linear_algebra/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr"},{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":5,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr"},{"filename":"apatite/linear_algebra.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra.cr"},{"filename":"apatite/linear_algebra/ndarray.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L263","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:T)-class-method","html_id":"diagonal(*values:T)-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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L235","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\nNOTE: An explicit type is required since it cannot be inferred.\n\n```\nMatrix(Int32).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(Indexable(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(rows : Indexable(Indexable(T)), copy = true)","source_link":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L33","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Indexable(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.map(&.to_a).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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L215","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L158","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":[{"id":"new(pull:JSON::PullParser)-class-method","html_id":"new(pull:JSON::PullParser)-class-method","name":"new","doc":"Creates a new `Matrix` instance from a `JSON::PullParser`.\nDefaults to a Float64 matrix.","summary":"Creates a new Matrix
instance from a JSON::PullParser
.
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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L909","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1079","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L942","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L969","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L996","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L886","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L644","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L894","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1383","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L630","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L332","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1396","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L282","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1331","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1097","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L398","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L456","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L723","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L603","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1017","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1179","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1346","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1031","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L660","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L738","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1313","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L377","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L581","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L550","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1193","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1361","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1373","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L340","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L325","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1389","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L838","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1262","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1403","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1408","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 @rows.to_json(json)\nend"}},{"id":"to_matrix-instance-method","html_id":"to_matrix-instance-method","name":"to_matrix","doc":"Just in case","summary":"Just in case
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1415","def":{"name":"to_matrix","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self"}},{"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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1423","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1241","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1233","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1256","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L870","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1275","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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":"independent?(*vs)-class-method","html_id":"independent?(*vs)-class-method","name":"independent?","doc":"Returns `true` if all of vectors are linearly independent.\n\n```\nVector.independent?(Vector[1,0], Vector[0,1])\n# => true\n\nVector.independent?(Vector[1,2], Vector[2,4])\n# => false\n```","summary":"Returns true
if all of vectors are linearly independent.
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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L61","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L68","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 Matrix\n (Matrix.column_vector(self)) * x\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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L83","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 Matrix\n (Matrix.column_vector(self)) + x\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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L98","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 Matrix\n (Matrix.column_vector(self)) - x\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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L113","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 Matrix\n (Matrix.column_vector(self)) / x\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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L137","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L128","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L146","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L155","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L257","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":"covector-instance-method","html_id":"covector-instance-method","name":"covector","doc":"Creates a single-row matrix from this vector.","summary":"Creates a single-row matrix from this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L173","def":{"name":"covector","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.row_vector(self)"}},{"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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L201","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L178","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L215","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L206","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L294","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L229","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L159","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L164","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L234","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L239","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L246","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L251","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L276","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L281","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L285","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L298","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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 a collection of mathematical and scientific algorithms. Currently it implements the API from Ruby's `Matrix` class for both `Matrix` and `Vector`. This API will be added to as needs arise. The goal is for this project to eventually contain everything you could get from SciPy, but in pure Crystal.\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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/error.cr"},{"filename":"apatite/linear_algebra/vector.cr","line_number":5,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr"},{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":5,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr"},{"filename":"apatite/linear_algebra.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra.cr"},{"filename":"apatite/linear_algebra/ndarray.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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":7,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L263","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:T)-class-method","html_id":"diagonal(*values:T)-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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L235","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\nNOTE: An explicit type is required since it cannot be inferred.\n\n```\nMatrix(Int32).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(Indexable(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(rows : Indexable(Indexable(T)), copy = true)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L33","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Indexable(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.map(&.to_a).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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L215","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L158","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":[{"id":"new(pull:JSON::PullParser)-class-method","html_id":"new(pull:JSON::PullParser)-class-method","name":"new","doc":"Creates a new `Matrix` instance from a `JSON::PullParser`.\nDefaults to a Float64 matrix.","summary":"Creates a new Matrix
instance from a JSON::PullParser
.
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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L913","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1083","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L946","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L973","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1000","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":null,"summary":null,"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L295","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"}},{"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L890","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 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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L648","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L898","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1387","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L634","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L336","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1400","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L282","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1335","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1101","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L402","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L460","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L727","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L607","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1021","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1183","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1350","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1035","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L664","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.new(\"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 (column(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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L742","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1317","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L381","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L585","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L554","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1197","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1365","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1377","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L344","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L329","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1393","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L842","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1266","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1407","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1412","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 @rows.to_json(json)\nend"}},{"id":"to_matrix-instance-method","html_id":"to_matrix-instance-method","name":"to_matrix","doc":"Just in case","summary":"Just in case
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1419","def":{"name":"to_matrix","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self"}},{"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1427","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1245","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1237","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1260","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L874","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1279","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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":[],"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/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":8,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L23","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L29","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":"independent?(*vs)-class-method","html_id":"independent?(*vs)-class-method","name":"independent?","doc":"Returns `true` if all of vectors are linearly independent.\n\n```\nVector.independent?(Vector[1,0], Vector[0,1])\n# => true\n\nVector.independent?(Vector[1,2], Vector[2,4])\n# => false\n```","summary":"Returns true
if all of vectors are linearly independent.
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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L62","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, T.new(0))\nnew(array)\n"}}],"constructors":[],"instance_methods":[{"id":"*(x:Number)-instance-method","html_id":"*(x:Number)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is a number.","summary":"Multiplies the vector by x, where x is a number.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"args_string":"(x : Number)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L79","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = @elements.map do |e|\n (e * x).as(T)\nend\nself.class.elements(els, false)\n"}},{"id":"*(x:Vector)-instance-method","html_id":"*(x:Vector)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is another vector.","summary":"Multiplies the vector by x, where x is another vector.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"args_string":"(x : Vector)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L90","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = (self.elements.zip(x.elements)).map do |__arg0|\n x = __arg0[0]\n y = __arg0[1]\n x * y\nend\nself.class.elements(els, false)\n"}},{"id":"*(x:Matrix)-instance-method","html_id":"*(x:Matrix)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is a matrix.","summary":"Multiplies the vector by x, where x is a matrix.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"args_string":"(x : Matrix)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L85","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(Matrix.column_vector(self)) * x"}},{"id":"+(x:Matrix)-instance-method","html_id":"+(x:Matrix)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"args_string":"(x : Matrix)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L102","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(Matrix.column_vector(self)) + x"}},{"id":"+(x:Number)-instance-method","html_id":"+(x:Number)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"args_string":"(x : Number)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L96","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = @elements.map do |e|\n (e + x).as(T)\nend\nself.class.elements(els, false)\n"}},{"id":"+(x:Vector)-instance-method","html_id":"+(x:Vector)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"args_string":"(x : Vector)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L107","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = (self.elements.zip(x.elements)).map do |__arg1|\n x = __arg1[0]\n y = __arg1[1]\n x + y\nend\nself.class.elements(els, false)\n"}},{"id":"-(x:Matrix)-instance-method","html_id":"-(x:Matrix)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"args_string":"(x : Matrix)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L119","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(Matrix.column_vector(self)) - x"}},{"id":"-(x:Vector)-instance-method","html_id":"-(x:Vector)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"args_string":"(x : Vector)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L124","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = (self.elements.zip(x.elements)).map do |__arg2|\n x = __arg2[0]\n y = __arg2[1]\n x - y\nend\nself.class.elements(els, false)\n"}},{"id":"-(x:Number)-instance-method","html_id":"-(x:Number)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"args_string":"(x : Number)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L113","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = @elements.map do |e|\n (e - x).as(T)\nend\nself.class.elements(els, false)\n"}},{"id":"/(x:Matrix)-instance-method","html_id":"/(x:Matrix)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"args_string":"(x : Matrix)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L136","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(Matrix.column_vector(self)) / x"}},{"id":"/(x:Number)-instance-method","html_id":"/(x:Number)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"args_string":"(x : Number)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L130","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = @elements.map do |e|\n (e / x).as(T)\nend\nself.class.elements(els, false)\n"}},{"id":"/(x:Vector)-instance-method","html_id":"/(x:Vector)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"args_string":"(x : Vector)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L141","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = (self.elements.zip(x.elements)).map do |__arg3|\n x = __arg3[0]\n y = __arg3[1]\n x / y\nend\nself.class.elements(els, false)\n"}},{"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L156","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:Vector|Indexable)-instance-method","html_id":"(other:Vector|Indexable)-instance-method","name":"<=>","doc":"Alien mothership","summary":"Alien mothership
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector | Indexable"}],"args_string":"(other : Vector | Indexable)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L69","def":{"name":"<=>","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n elements <=> other.elements\nwhen Indexable\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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L147","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L165","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L174","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:BigRational.class,denominator:Int)-instance-method","html_id":"coerce(klass:BigRational.class,denominator:Int)-instance-method","name":"coerce","doc":"Attempt to coerce the elements in a vector to BigRational\nwith the given `denominator`.","summary":"Attempt to coerce the elements in a vector to BigRational with the given denominator
.
The coerce method allows you to attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":"U.class"}],"args_string":"(klass : U.class) : Apatite::LinearAlgebra::Vector(U) forall U","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L297","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":"U.class"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Vector(U)","visibility":"Public","body":"els = @elements.map do |e|\n (klass.new(e)).as(U)\nend\nVector.elements(els)\n"}},{"id":"coerce(klass:BigInt.class,base=10)-instance-method","html_id":"coerce(klass:BigInt.class,base=10)-instance-method","name":"coerce","doc":"Attempt to coerce the elements in a vector to BigInt with\nan optional `base` value.","summary":"Attempt to coerce the elements in a vector to BigInt with an optional base
value.
Attempt to coerce the elements in a vector to Complex with imag
as the imaginary number.
Creates a single-row matrix from this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L195","def":{"name":"covector","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.row_vector(self)"}},{"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L223","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L200","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.to_a, Array.new(size) do |i|\n Vector.basis(size, i)\n end].flatten\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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L234","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,&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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L15","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":"each(v,&block)-instance-method","html_id":"each(v,&block)-instance-method","name":"each","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L228","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\n(map(v) do |v1, v2|\n v1 * v2\nend).sum\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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L321","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L248","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":"Maps over a vector, passing each element to the block","summary":"Maps over a vector, passing each element to the block
","abstract":false,"args":[],"args_string":"(&block : T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L179","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":"map(v,&block:T,T->UNDERSCORE)-instance-method","html_id":"map(v,&block:T,T->UNDERSCORE)-instance-method","name":"map","doc":"Maps over the current vector and `v` in conjunction, passing each\nelement in each to the block and returning a new vector","summary":"Maps over the current vector and v
in conjunction, passing each element in each to the block and returning a new vector
Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L253","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L258","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\n(self.coerce(Float64)) / 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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L265","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L270","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L303","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L308","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L312","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L325","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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 f781a16..f6deffd 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- [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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/error.cr"},{"filename":"apatite/linear_algebra/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr"},{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":5,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr"},{"filename":"apatite/linear_algebra.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra.cr"},{"filename":"apatite/linear_algebra/ndarray.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L263","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:T)-class-method","html_id":"diagonal(*values:T)-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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L235","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\nNOTE: An explicit type is required since it cannot be inferred.\n\n```\nMatrix(Int32).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(Indexable(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(rows : Indexable(Indexable(T)), copy = true)","source_link":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L33","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Indexable(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.map(&.to_a).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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L215","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L158","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":[{"id":"new(pull:JSON::PullParser)-class-method","html_id":"new(pull:JSON::PullParser)-class-method","name":"new","doc":"Creates a new `Matrix` instance from a `JSON::PullParser`.\nDefaults to a Float64 matrix.","summary":"Creates a new Matrix
instance from a JSON::PullParser
.
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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L909","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1079","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L942","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L969","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L996","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L886","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L644","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L894","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1383","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L630","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L332","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1396","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L282","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1331","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1097","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L398","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L456","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L723","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L603","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1017","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1179","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1346","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1031","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L660","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L738","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1313","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L377","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L581","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L550","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1193","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1361","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1373","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L340","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L325","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1389","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L838","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1262","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1403","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1408","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 @rows.to_json(json)\nend"}},{"id":"to_matrix-instance-method","html_id":"to_matrix-instance-method","name":"to_matrix","doc":"Just in case","summary":"Just in case
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1415","def":{"name":"to_matrix","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self"}},{"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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1423","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1241","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1233","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1256","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L870","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/matrix.cr#L1275","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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":"independent?(*vs)-class-method","html_id":"independent?(*vs)-class-method","name":"independent?","doc":"Returns `true` if all of vectors are linearly independent.\n\n```\nVector.independent?(Vector[1,0], Vector[0,1])\n# => true\n\nVector.independent?(Vector[1,2], Vector[2,4])\n# => false\n```","summary":"Returns true
if all of vectors are linearly independent.
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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L61","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L68","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 Matrix\n (Matrix.column_vector(self)) * x\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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L83","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 Matrix\n (Matrix.column_vector(self)) + x\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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L98","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 Matrix\n (Matrix.column_vector(self)) - x\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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L113","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 Matrix\n (Matrix.column_vector(self)) / x\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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L137","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L128","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L146","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L155","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L257","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":"covector-instance-method","html_id":"covector-instance-method","name":"covector","doc":"Creates a single-row matrix from this vector.","summary":"Creates a single-row matrix from this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L173","def":{"name":"covector","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.row_vector(self)"}},{"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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L201","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L178","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L215","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L206","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L294","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L229","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L159","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L164","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L234","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L239","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L246","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L251","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L276","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L281","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L285","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/src/apatite/linear_algebra/vector.cr#L298","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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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/fd6da99f9d1de3a90a6315a813fcb7206a053d9a/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 a collection of mathematical and scientific algorithms. Currently it implements the API from Ruby's `Matrix` class for both `Matrix` and `Vector`. This API will be added to as needs arise. The goal is for this project to eventually contain everything you could get from SciPy, but in pure Crystal.\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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/error.cr"},{"filename":"apatite/linear_algebra/vector.cr","line_number":5,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr"},{"filename":"apatite/linear_algebra/matrix/eigenvalue_decomposition.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":5,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr"},{"filename":"apatite/linear_algebra.cr","line_number":7,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra.cr"},{"filename":"apatite/linear_algebra/ndarray.cr","line_number":1,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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":7,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix/lup_decomposition.cr"},{"filename":"apatite/linear_algebra/matrix.cr","line_number":6,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L263","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:T)-class-method","html_id":"diagonal(*values:T)-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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L235","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\nNOTE: An explicit type is required since it cannot be inferred.\n\n```\nMatrix(Int32).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(Indexable(T))"},{"name":"copy","doc":null,"default_value":"true","external_name":"copy","restriction":""}],"args_string":"(rows : Indexable(Indexable(T)), copy = true)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L33","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":"Indexable(Indexable(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.map(&.to_a).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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L215","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L158","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":[{"id":"new(pull:JSON::PullParser)-class-method","html_id":"new(pull:JSON::PullParser)-class-method","name":"new","doc":"Creates a new `Matrix` instance from a `JSON::PullParser`.\nDefaults to a Float64 matrix.","summary":"Creates a new Matrix
instance from a JSON::PullParser
.
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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L913","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1083","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L946","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L973","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1000","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":null,"summary":null,"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L295","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"}},{"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L890","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 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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L648","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L898","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1387","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L634","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L336","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1400","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L282","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1335","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1101","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L402","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L460","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L727","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L607","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1021","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1183","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1350","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1035","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L664","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.new(\"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 (column(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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L742","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1317","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L381","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L585","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L554","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1197","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1365","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1377","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L344","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L329","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1393","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L842","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1266","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1407","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1412","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 @rows.to_json(json)\nend"}},{"id":"to_matrix-instance-method","html_id":"to_matrix-instance-method","name":"to_matrix","doc":"Just in case","summary":"Just in case
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1419","def":{"name":"to_matrix","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self"}},{"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1427","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1245","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1237","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1260","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L874","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/matrix.cr#L1279","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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":[],"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/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":8,"url":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L23","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L29","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":"independent?(*vs)-class-method","html_id":"independent?(*vs)-class-method","name":"independent?","doc":"Returns `true` if all of vectors are linearly independent.\n\n```\nVector.independent?(Vector[1,0], Vector[0,1])\n# => true\n\nVector.independent?(Vector[1,2], Vector[2,4])\n# => false\n```","summary":"Returns true
if all of vectors are linearly independent.
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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L62","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, T.new(0))\nnew(array)\n"}}],"constructors":[],"instance_methods":[{"id":"*(x:Number)-instance-method","html_id":"*(x:Number)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is a number.","summary":"Multiplies the vector by x, where x is a number.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"args_string":"(x : Number)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L79","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = @elements.map do |e|\n (e * x).as(T)\nend\nself.class.elements(els, false)\n"}},{"id":"*(x:Vector)-instance-method","html_id":"*(x:Vector)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is another vector.","summary":"Multiplies the vector by x, where x is another vector.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"args_string":"(x : Vector)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L90","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = (self.elements.zip(x.elements)).map do |__arg0|\n x = __arg0[0]\n y = __arg0[1]\n x * y\nend\nself.class.elements(els, false)\n"}},{"id":"*(x:Matrix)-instance-method","html_id":"*(x:Matrix)-instance-method","name":"*","doc":"Multiplies the vector by x, where x is a matrix.","summary":"Multiplies the vector by x, where x is a matrix.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"args_string":"(x : Matrix)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L85","def":{"name":"*","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(Matrix.column_vector(self)) * x"}},{"id":"+(x:Matrix)-instance-method","html_id":"+(x:Matrix)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"args_string":"(x : Matrix)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L102","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(Matrix.column_vector(self)) + x"}},{"id":"+(x:Number)-instance-method","html_id":"+(x:Number)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"args_string":"(x : Number)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L96","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = @elements.map do |e|\n (e + x).as(T)\nend\nself.class.elements(els, false)\n"}},{"id":"+(x:Vector)-instance-method","html_id":"+(x:Vector)-instance-method","name":"+","doc":"Vector addition.","summary":"Vector addition.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"args_string":"(x : Vector)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L107","def":{"name":"+","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = (self.elements.zip(x.elements)).map do |__arg1|\n x = __arg1[0]\n y = __arg1[1]\n x + y\nend\nself.class.elements(els, false)\n"}},{"id":"-(x:Matrix)-instance-method","html_id":"-(x:Matrix)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"args_string":"(x : Matrix)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L119","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(Matrix.column_vector(self)) - x"}},{"id":"-(x:Vector)-instance-method","html_id":"-(x:Vector)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"args_string":"(x : Vector)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L124","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = (self.elements.zip(x.elements)).map do |__arg2|\n x = __arg2[0]\n y = __arg2[1]\n x - y\nend\nself.class.elements(els, false)\n"}},{"id":"-(x:Number)-instance-method","html_id":"-(x:Number)-instance-method","name":"-","doc":"Vector subtraction.","summary":"Vector subtraction.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"args_string":"(x : Number)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L113","def":{"name":"-","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = @elements.map do |e|\n (e - x).as(T)\nend\nself.class.elements(els, false)\n"}},{"id":"/(x:Matrix)-instance-method","html_id":"/(x:Matrix)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"args_string":"(x : Matrix)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L136","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Matrix"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(Matrix.column_vector(self)) / x"}},{"id":"/(x:Number)-instance-method","html_id":"/(x:Number)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"args_string":"(x : Number)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L130","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Number"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = @elements.map do |e|\n (e / x).as(T)\nend\nself.class.elements(els, false)\n"}},{"id":"/(x:Vector)-instance-method","html_id":"/(x:Vector)-instance-method","name":"/","doc":"Vector division.","summary":"Vector division.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"args_string":"(x : Vector)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L141","def":{"name":"/","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"els = (self.elements.zip(x.elements)).map do |__arg3|\n x = __arg3[0]\n y = __arg3[1]\n x / y\nend\nself.class.elements(els, false)\n"}},{"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L156","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:Vector|Indexable)-instance-method","html_id":"(other:Vector|Indexable)-instance-method","name":"<=>","doc":"Alien mothership","summary":"Alien mothership
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector | Indexable"}],"args_string":"(other : Vector | Indexable)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L69","def":{"name":"<=>","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector | Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case other\nwhen Vector\n elements <=> other.elements\nwhen Indexable\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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L147","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L165","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L174","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:BigRational.class,denominator:Int)-instance-method","html_id":"coerce(klass:BigRational.class,denominator:Int)-instance-method","name":"coerce","doc":"Attempt to coerce the elements in a vector to BigRational\nwith the given `denominator`.","summary":"Attempt to coerce the elements in a vector to BigRational with the given denominator
.
The coerce method allows you to attempt to coerce the elements in the matrix to another type.
","abstract":false,"args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":"U.class"}],"args_string":"(klass : U.class) : Apatite::LinearAlgebra::Vector(U) forall U","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L297","def":{"name":"coerce","args":[{"name":"klass","doc":null,"default_value":"","external_name":"klass","restriction":"U.class"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Vector(U)","visibility":"Public","body":"els = @elements.map do |e|\n (klass.new(e)).as(U)\nend\nVector.elements(els)\n"}},{"id":"coerce(klass:BigInt.class,base=10)-instance-method","html_id":"coerce(klass:BigInt.class,base=10)-instance-method","name":"coerce","doc":"Attempt to coerce the elements in a vector to BigInt with\nan optional `base` value.","summary":"Attempt to coerce the elements in a vector to BigInt with an optional base
value.
Attempt to coerce the elements in a vector to Complex with imag
as the imaginary number.
Creates a single-row matrix from this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L195","def":{"name":"covector","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Matrix.row_vector(self)"}},{"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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L223","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L200","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.to_a, Array.new(size) do |i|\n Vector.basis(size, i)\n end].flatten\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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L234","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,&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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L15","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":"each(v,&block)-instance-method","html_id":"each(v,&block)-instance-method","name":"each","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L228","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\n(map(v) do |v1, v2|\n v1 * v2\nend).sum\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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L321","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L248","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":"Maps over a vector, passing each element to the block","summary":"Maps over a vector, passing each element to the block
","abstract":false,"args":[],"args_string":"(&block : T -> UNDERSCORE)","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L179","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":"map(v,&block:T,T->UNDERSCORE)-instance-method","html_id":"map(v,&block:T,T->UNDERSCORE)-instance-method","name":"map","doc":"Maps over the current vector and `v` in conjunction, passing each\nelement in each to the block and returning a new vector","summary":"Maps over the current vector and v
in conjunction, passing each element in each to the block and returning a new vector
Returns the modulus (Pythagorean distance) of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L253","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L258","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\n(self.coerce(Float64)) / 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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L265","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L270","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L303","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L308","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L312","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/src/apatite/linear_algebra/vector.cr#L325","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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/c7bc6f4f5ec3f4b2725b0b6bdf03d9524007e864/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/spec/apatite/vector_spec.cr b/spec/apatite/vector_spec.cr index 6f59cfa..5165c90 100644 --- a/spec/apatite/vector_spec.cr +++ b/spec/apatite/vector_spec.cr @@ -1,161 +1,259 @@ require "../spec_helper" describe "Apatite::Vector" do - x = Apatite::Vector.new([3, 4]) + describe ".[]" do + it "creates a new vector from a list of elements" do + vec = Apatite::Vector[1, 2, 3] + vec.should be_a Apatite::Vector(Int32) + vec[0].should eq 1 + vec[2].should eq 3 + end + end + + describe ".elements" do + it "creates a new vector from an Array" do + arr = [1, 2, 3] + vec = Apatite::Vector.elements(arr) + vec.should be_a Apatite::Vector(Int32) + vec[0].should eq 1 + vec[2].should eq 3 + end + end + + describe ".basis" do + it "creates a standard basis-n vector" do + vec = Apatite::Vector.basis(5, 1) + vec.should eq Apatite::Vector[0, 1, 0, 0, 0] + + vec = Apatite::Vector.basis(3, 2) + vec.should eq Apatite::Vector[0, 0, 1] + end + end + + describe ".independent?" do + it "returns true if all of vectors are linearly independent" do + Apatite::Vector.independent?(Apatite::Vector[1,0], Apatite::Vector[0,1]).should be_true + Apatite::Vector.independent?(Apatite::Vector[1,2], Apatite::Vector[2,4]).should be_false + end + end + + describe ".zero" do + it "creates a new zero vector" do + vec = Apatite::Vector(Int32).zero(5) + vec.should eq Apatite::Vector[0, 0, 0, 0, 0] + end + end describe "#==" do it "is true if elements are the same" do - (x == Apatite::Vector.new([3, 4])).should be_true + x = Apatite::Vector.elements([3, 4]) + (x == Apatite::Vector.elements([3, 4])).should be_true end it "is false if elements are different" do - (x == Apatite::Vector.new([7, 1])).should be_false + x = Apatite::Vector.elements([3, 4]) + (x == Apatite::Vector.elements([7, 1])).should be_false end end - describe "#e" do - it "returns the `ith` element in the vector" do - x.e(2).should eq(4) + describe "#+" do + it "adds a number to every item in the vector" do + vec = Apatite::Vector[1, 2, 3] + vec2 = vec + 2 + vec2.should eq Apatite::Vector[3, 4, 5] end - it "returns `nil` if `n` is out of range" do - x.e(7).should be_nil + it "adds the items in one vector to each parallel item in another" do + vec1 = Apatite::Vector[1, 2, 3] + vec2 = Apatite::Vector[3, 2, 1] + vec3 = vec1 + vec2 + + vec3.should be_a Apatite::Vector(Int32) + vec3.should eq Apatite::Vector[4, 4, 4] + end + + pending "adds a vector to a matrix" + end + + describe "#-" do + it "subtracts a number from every item in the vector" do + vec = Apatite::Vector[3, 4, 5] + vec2 = vec - 2 + vec2.should eq Apatite::Vector[1, 2, 3] + end + + it "subtracts the items in one vector from each parallel item in another" do + vec1 = Apatite::Vector[1, 2, 3] + vec2 = Apatite::Vector[3, 2, 1] + vec3 = vec1 - vec2 + + vec3.should be_a Apatite::Vector(Int32) + vec3.should eq Apatite::Vector[-2, 0, 2] + end + + pending "subtracts a vector from a matrix" + end + + describe "#*" do + it "multiplies every item in the vector by a number" do + vec = Apatite::Vector[2, 3, 4] + vec2 = vec * 2 + vec2.should eq Apatite::Vector[4, 6, 8] + end + + it "multiplies the items in one vector with each parallel item in another" do + vec1 = Apatite::Vector[1, 2, 3] + vec2 = Apatite::Vector[3, 2, 1] + vec3 = vec1 * vec2 + + vec3.should be_a Apatite::Vector(Int32) + vec3.should eq Apatite::Vector[3, 4, 3] + end + + pending "multiplies a vector with a matrix" + end + + describe "#/" do + it "divides every item in the vector by a number" do + vec = Apatite::Vector[2.0, 3.0, 4.0] + vec2 = vec / 2 + vec2.should eq Apatite::Vector[1.0, 1.5, 2.0] + end + + it "divides the items in one vector by each parallel item in another" do + vec1 = Apatite::Vector[1.0, 2.0, 3.0] + vec2 = Apatite::Vector[3.0, 2.0, 1.0] + vec3 = vec1 / vec2 + + vec3.should be_a Apatite::Vector(Float64) + vec3.should eq Apatite::Vector[0.3333333333333333, 1.0, 3.0] + end + + pending "divides a vector by a matrix" + end + + describe "#==" do + it "ensures two vectors are equal" do + vec1 = Apatite::Vector[1, 2, 3] + vec2 = Apatite::Vector[1, 2, 3] + (vec1 == vec2).should be_true + end + + it "checks equality between a vector and an array" do + vec = Apatite::Vector[1, 2, 3] + arr = [1, 2, 3] + (vec == arr).should be_true end end - describe "#to_unit_vector" do - it "successfully converts a vector to a unit vector" do - res = [0.6, 0.8] - x.to_unit_vector.each_with_index do |e, i| - e.should be_close(res[i], 0.1) + describe "#angle_with" do + it "returns an angle with another vector" do + vec1 = Apatite::Vector[1, 2, 3] + vec2 = Apatite::Vector[3, 2, 1] + vec1.angle_with(vec2).should eq 0.7751933733103613 + end + end + + describe "#clone" do + it "creates a copy of the vector" do + vec = Apatite::Vector[1, 2, 3] + cpy = vec.clone + vec.should eq cpy + vec.object_id.should_not eq cpy.object_id + end + end + + describe "#map" do + it "should map over a vector's elements" do + vec1 = Apatite::Vector[1, 2, 3] + vec2 = vec1.map(&.succ) + vec2.should eq Apatite::Vector[2, 3, 4] + end + + it "should map over two vectors simultaniously" do + vec1 = Apatite::Vector[1, 2, 3] + vec2 = Apatite::Vector[4, 5, 6] + vec3 = vec1.map(vec2) { |v1, v2| v1 + v2 } + vec3.should eq Apatite::Vector[5, 7, 9] + end + end + + describe "#covector" do + it "should create a single row matrix from the vector" do + vec = Apatite::Vector[1, 2, 3] + mat = vec.covector + + mat.should be_a Apatite::Matrix(Int32) + mat.row_count.should eq 1 + mat[0].should eq [1, 2, 3] + end + end + + describe "#cross_product" do + it "should return the cross product of multiple vectors" do + vec1 = Apatite::Vector[1, 2, 3] + cross = vec1.cross_product(Apatite::Vector[3, 4, 5]) + cross.should eq Apatite::Vector[-2, 4, -2] + end + end + + describe "#inner_product" do + it "should return the inner product of two vectors" do + vec = Apatite::Vector[1, 2, 3] + prod = vec.inner_product(Apatite::Vector[3, 4, 5]) + prod.should eq 26 + end + end + + describe "#each" do + it "should iterate over each item in the vector" do + vec = Apatite::Vector[1, 2, 3] + index = 0 + vec.each do |n| + n.should eq index + 1 + index += 1 end end end - describe "#dimensions" do - it "gets vector's dimensions" do - x.dimensions.should eq({1, 2}) + describe "#magnitude" do + it "should return the modulus of a vector" do + vec = Apatite::Vector[1, 2, 3] + vec.magnitude.should eq 3.7416573867739413 end end - describe "#rows" do - it "gets vector's rows" do - x.rows.should eq(1) + describe "#normalize" do + it "should return a vector with the same direction, but norm 1" do + vec = Apatite::Vector[1, 2, 3] + vec.normalize.should eq Apatite::Vector[0.2672612419124244, 0.5345224838248488, 0.8017837257372732] end end - describe "#cols" do - it "gets vector's columns" do - x.cols.should eq(2) + describe "#round" do + it "should round each entry in the vector" do + vec = Apatite::Vector[0.2672612419124244, 0.5345224838248488, 0.8017837257372732] + vec.round(2).should eq Apatite::Vector[0.27, 0.53, 0.80] end end - describe "#product" do - it "computes the product of a vector" do - x.product.should eq(12) - end - end - - describe "#angle_from" do - it "should compute the angle between `y` and `z`" do - y = Apatite::Vector.create([1, 1]) - z = Apatite::Vector.create([1, 0]) - y.angle_from(z).should be_close(Math::PI / 4, 0.1) - end - end - - describe "#parallel_to?" do - it "correctly determines if a vector is parallel to another" do - x.parallel_to?(Apatite::Vector.create([6, 8])).should be_true - x.parallel_to?(Apatite::Vector.create([1, 1])).should be_false - end - end - - describe "#antiparallel_to?" do - it "correctly determines if a vector is antiparallel to another" do - x.antiparallel_to?(Apatite::Vector.create([-3, -4])).should be_true - x.antiparallel_to?(x).should be_false - end - end - - describe "#perpendicular_to?" do - it "correctly determines if a vector is antiparallel to another" do - x.perpendicular_to?(Apatite::Vector.create([-4, 3])).should be_true - x.perpendicular_to?(x).should be_false - end - end - - describe "#dot" do - it "calculates the dot product of the vector and another vector" do - x.dot(Apatite::Vector.create([2, 3])).should eq(18) - end - end - - describe "#add" do - it "adds a number to every item in a vector" do - x.add(2).should eq([5, 6]) + describe "#coerce" do + it "should return a new vector with elements of a different type" do + vec = Apatite::Vector[1, 2, 3] + flt = vec.coerce(Float64) + flt.should be_a Apatite::Vector(Float64) end - it "adds an enumerable to a vector" do - x.add([3, 2]).should eq([6, 6]) - end - end - - describe "#subtract" do - it "subtracts a number from every item in a vector" do - x.subtract(2).should eq([1, 2]) + it "should work with big rationals" do + vec = Apatite::Vector[1, 2, 3] + rat = vec.coerce(BigRational, 2) + rat.should be_a Apatite::Vector(BigRational) end - it "subtracts an enumerable from a vector" do - x.subtract([3, 2]).should eq([0, 2]) + it "should work with complex numbers" do + vec = Apatite::Vector[1, 2, 3] + com = vec.coerce(Complex, 1) + com.should be_a Apatite::Vector(Complex) end end - - describe "#multiply" do - it "multiplies a number with every item in a vector" do - x.multiply(2).should eq([6, 8]) - end - - it "multiplies an enumerable with a vector" do - x.multiply([3, 2]).should eq([9, 8]) - end - end - - describe "#sum" do - it "sums all items in a vector" do - x.sum.should eq(7) - end - end - - describe "#chomp" do - it "returns a new vector with the first `n` items of the old vector" do - x.chomp(1).should eq([4]) - end - end - - describe "#top" do - it "returns a new vector with the last `n` items of the old vector" do - x.top(1).should eq([3]) - end - end - - describe "#augment" do - it "creates a new vector with the elements fro vector b appended to those from vector a" do - y = x.clone - y.augment(Apatite::Vector.create([5])).should eq([3, 4, 5]) - end - end - - describe ".log" do - it "should calculate the log of the vector" do - pp x - x.log.should eq([1.0986122886681098, 1.3862943611198906]) - end - end - - it "should allow for scalar addition" do - a = Apatite::Vector.create([2, 3, 4]) - b = a.add(1) - b.should eq([3, 4, 5]) - end end diff --git a/src/apatite/linear_algebra/error.cr b/src/apatite/linear_algebra/error.cr index c08bdad..d4612a3 100644 --- a/src/apatite/linear_algebra/error.cr +++ b/src/apatite/linear_algebra/error.cr @@ -4,12 +4,6 @@ module Apatite class ErrDimensionMismatch < Error; end class ZeroVectorError < Error; end class ErrNotRegular < Error; end - - class ErrOperationNotDefined < Error - def initialize(method, this, other) - message = "no overload matches '#{this}##{method}' with type #{other}" - super(message) - end - end + class ErrOperationNotDefined < Error; end end end diff --git a/src/apatite/linear_algebra/matrix.cr b/src/apatite/linear_algebra/matrix.cr index 8501a93..bc2d358 100644 --- a/src/apatite/linear_algebra/matrix.cr +++ b/src/apatite/linear_algebra/matrix.cr @@ -292,6 +292,10 @@ module Apatite::LinearAlgebra @column_count = column_count || rows[0].try &.size end + def <=>(other : Matrix) + rows <=> other.rows + end + # Returns row `i` of the matrix as an Array. Raises if the # index is not found. def [](i) @@ -668,7 +672,7 @@ module Apatite::LinearAlgebra raise "laplace_expansion of empty matrix is not defined" if empty? unless 0 <= num && num < row_count - raise ArgumentError, "invalid num (#{num.inspect} for 0..#{row_count - 1})" + raise ArgumentError.new("invalid num (#{num.inspect} for 0..#{row_count - 1})") end if row @@ -676,7 +680,7 @@ module Apatite::LinearAlgebra e * cofactor(num, k) end.reduce(&.+) else - col(num).map_with_index do |e, k| + column(num).map_with_index do |e, k| e * cofactor(k, num) end.reduce(&.+) end diff --git a/src/apatite/linear_algebra/ndarray.cr b/src/apatite/linear_algebra/ndarray.cr index 0b2b3b6..8d6a702 100644 --- a/src/apatite/linear_algebra/ndarray.cr +++ b/src/apatite/linear_algebra/ndarray.cr @@ -1,32 +1,32 @@ module Apatite::LinearAlgebra class NDArray - include Enumerable(Float64) - include Indexable(Float64) - include Comparable(NDArray) + # include Enumerable(Float64) + # include Indexable(Float64) + # include Comparable(NDArray) - getter data : Array(Float64) + # getter data : Array(Float64) - getter shape : Array(Int32) + # getter shape : Array(Int32) - delegate :[], to: @data - delegate :[]?, to: @data - delegate :[]=, to: @data - delegate :unsafe_fetch, to: @data - delegate :to_unsafe, to: @data - delegate :size, to: @data + # delegate :[], to: @data + # delegate :[]?, to: @data + # delegate :[]=, to: @data + # delegate :unsafe_fetch, to: @data + # delegate :to_unsafe, to: @data + # delegate :size, to: @data - def initialize(data : Array(Number), shape : Array(Int32)? = nil) - @data = data.is_a?(Array(Float64)) ? data.flatten : data.flatten.map(&.to_f64) - @shape = shape || [@data.size] - end + # def initialize(data : Array(Number), shape : Array(Int32)? = nil) + # @data = data.is_a?(Array(Float64)) ? data.flatten : data.flatten.map(&.to_f64) + # @shape = shape || [@data.size] + # end - # Returns the absolute value of every item in the array - def abs - map { |e| e.abs } - end + # # Returns the absolute value of every item in the array + # def abs + # map { |e| e.abs } + # end - # Returns the arccosine of each element in the current array. - def acos - end + # # Returns the arccosine of each element in the current array. + # def acos + # end end end diff --git a/src/apatite/linear_algebra/vector.cr b/src/apatite/linear_algebra/vector.cr index 4a542e3..1d1206c 100644 --- a/src/apatite/linear_algebra/vector.cr +++ b/src/apatite/linear_algebra/vector.cr @@ -1,5 +1,6 @@ +require "complex" +require "big" require "json" -require "./matrix" module Apatite::LinearAlgebra # Represents a mathematical vector, and also constitutes a row or column @@ -48,7 +49,7 @@ module Apatite::LinearAlgebra # Vector.independent?(Vector[1,2], Vector[2,4]) # # => false # ``` - def Vector.independent?(*vs) + def self.independent?(*vs) vs.each do |v| raise "expected Vector, but got #{v.class}" unless v.is_a?(Vector) raise ErrDimensionMismatch.new unless v.size == vs.first.size @@ -64,64 +65,82 @@ module Apatite::LinearAlgebra new(array) end - # Multiplies the vector by x, where x is a number or a matrix. - def *(x) - case x - when Number - els = @elements.map { |e| (e * x).as(T) } - self.class.elements(els, false) - when Matrix - Matrix.column_vector(self) * x + # Alien mothership + def <=>(other : Vector | Indexable) + case other when Vector - self.elements.zip(x.elements).map { |(x, y)| x * y } - else - raise ArgumentError.new + elements <=> other.elements + when Indexable + elements <=> other end end + # Multiplies the vector by x, where x is a number. + def *(x : Number) + els = @elements.map { |e| (e * x).as(T) } + self.class.elements(els, false) + end + + # Multiplies the vector by x, where x is a matrix. + def *(x : Matrix) + Matrix.column_vector(self) * x + end + + # Multiplies the vector by x, where x is another vector. + def *(x : Vector) + els = self.elements.zip(x.elements).map { |(x, y)| x * y } + self.class.elements(els, false) + end + # Vector addition. - def +(x) - case x - when Number - els = @elements.map { |e| (e + x).as(T) } - self.class.elements(els, false) - when Matrix - Matrix.column_vector(self) + x - when Vector - self.elements.zip(x.elements).map { |(x, y)| x + y } - else - raise ArgumentError.new - end + def +(x : Number) + els = @elements.map { |e| (e + x).as(T) } + self.class.elements(els, false) + end + + # Vector addition. + def +(x : Matrix) + Matrix.column_vector(self) + x + end + + # Vector addition. + def +(x : Vector) + els = self.elements.zip(x.elements).map { |(x, y)| x + y } + self.class.elements(els, false) end # Vector subtraction. - def -(x) - case x - when Number - els = @elements.map { |e| (e - x).as(T) } - self.class.elements(els, false) - when Matrix - Matrix.column_vector(self) - x - when Vector - self.elements.zip(x.elements).map { |(x, y)| x - y } - else - raise ArgumentError.new - end + def -(x : Number) + els = @elements.map { |e| (e - x).as(T) } + self.class.elements(els, false) + end + + # Vector subtraction. + def -(x : Matrix) + Matrix.column_vector(self) - x + end + + # Vector subtraction. + def -(x : Vector) + els = self.elements.zip(x.elements).map { |(x, y)| x - y } + self.class.elements(els, false) end # Vector division. - def /(x) - case x - when Number - els = @elements.map { |e| (e / x).as(T) } - self.class.elements(els, false) - when Matrix - Matrix.column_vector(self) / x - when Vector - self.elements.zip(x.elements).map { |(x, y)| x / y } - else - raise ArgumentError.new - end + def /(x : Number) + els = @elements.map { |e| (e / x).as(T) } + self.class.elements(els, false) + end + + # Vector division. + def /(x : Matrix) + Matrix.column_vector(self) / x + end + + # Vector division. + def /(x : Vector) + els = self.elements.zip(x.elements).map { |(x, y)| x / y } + self.class.elements(els, false) end # Equality operator @@ -156,12 +175,15 @@ module Apatite::LinearAlgebra self.class.elements(@elements) end + # Maps over a vector, passing each element to the block def map(&block : T -> _) els = @elements.map(&block) self.class.elements(els, false) end - def map2(v, &block : T, T -> _) + # Maps over the current vector and `v` in conjunction, passing each + # element in each to the block and returning a new vector + def map(v, &block : T, T -> _) raise ErrDimensionMismatch.new if size != v.size arr = Array.new(size) do |i| yield @elements[i], v[i] @@ -192,7 +214,7 @@ module Apatite::LinearAlgebra v[0]*@elements[2] - v[2]*@elements[0], v[1]*@elements[0] - v[0]*@elements[1] ] else - rows = self + vs + Array.new(size) {|i| Vector.basis(size, i) } + rows = [self, vs.to_a, Array.new(size) {|i| Vector.basis(size, i) }].flatten Matrix.rows(rows).laplace_expansion(row: size - 1) end end @@ -205,10 +227,7 @@ module Apatite::LinearAlgebra # Returns the inner product of this vector with the other. def inner_product(v) raise ErrDimensionMismatch.new if size != v.size - - p = 0 - each2(v) { |v1, v2| p += v1 * v2 } - p + map(v) { |v1, v2| v1 * v2 }.sum end # ditto @@ -217,7 +236,7 @@ module Apatite::LinearAlgebra end # Iterate over the elements of this vector and `v` in conjunction. - def each2(v, &block) + def each(v, &block) raise ErrDimensionMismatch.new if size != v.size size.times do |i| yield @elements[i], v[i] @@ -239,7 +258,7 @@ module Apatite::LinearAlgebra def normalize n = magnitude raise ZeroVectorError.new("Zero vectors can not be normalized") if n == 0 - self / n + self.coerce(Float64) / n end # ditto @@ -252,23 +271,31 @@ module Apatite::LinearAlgebra map{ |e| e.round(ndigits) } end - # The coerce method allows you to attempt to coerce the elements - # in the matrix to another type. The type - def coerce(klass, *args) - case klass.to_s - when "Complex" - raise "coercing to a Complex requires a second argument" unless args[0]? - els = @elements.map { |e| Complex.new(e, args[0].as(Int32)) } - when "BigInt" - base = args[0]? || 10 - els = @elements.map { |e| klass.new(e, base) } - when "BigRational" - raise "coercing to a BigRational requires a second argument to use as a denominator" unless args[0]? - els = @elements.map { |e| klass.new(e, args[0]) } - else - els = @elements.map { |e| klass.new(e) } - end + # Attempt to coerce the elements in a vector to Complex with + # `imag` as the imaginary number. + def coerce(klass : Complex.class, imag : Number) + els = @elements.map { |e| Complex.new(e, imag) } + Vector.elements(els) + end + # Attempt to coerce the elements in a vector to BigInt with + # an optional `base` value. + def coerce(klass : BigInt.class, base = 10) + els = @elements.map { |e| BigInt.new(e, base) } + Vector.elements(els) + end + + # Attempt to coerce the elements in a vector to BigRational + # with the given `denominator`. + def coerce(klass : BigRational.class, denominator : Int) + els = @elements.map { |e| BigRational.new(e, denominator) } + Vector.elements(els) + end + + # The coerce method allows you to attempt to coerce the elements + # in the matrix to another type. + def coerce(klass : U.class) : Vector(U) forall U + els = @elements.map { |e| klass.new(e).as(U) } Vector.elements(els) end