From 3e2735c00585c6d31f012a2038aaccefa9679d3d Mon Sep 17 00:00:00 2001
From: Chris Watson
Returns the angle between this vector and another in radians.
Returns whether the vectors are antiparallel to each other.
Get the scalar (dot) product of two vectors.
Returns whether the vectors are parallel to each other.
Returns whether the vectors are perpendicular to each other.
Compute the cosine similarity between two vectors.
Returns the angle between this vector and another in radians.
+If the vectors are mirrored across their axes this will return nil
.
Returns whether the vectors are antiparallel to each other.
Get the scalar (dot) product of two vectors.
+ +[https://en.wikipedia.org/wiki/Scalar_product](https://en.wikipedia.org/wiki/Scalar_product
Returns whether the vectors are parallel to each other.
Returns whether the vectors are perpendicular to each other.
Compute the cosine similarity between two vectors.
self
, assigning the block's value in that index.<
self
, assigning the block's value in that index.<
Matrix
Matrix
Alias for #push
Alias for #push
Matrix
+ When the input is a number, this returns the result of dividing it to all vector elements.
Matrix
Returns a new vector created by normalizing this one to have a magnitude of 1
.
Matrix
Matrix
+ Compute the cosine similarity between this vector and another.
Alias for #push
Alias for #push
nil
.
nil
.
When the input is a number, this returns the result of dividing +it to all vector elements. When it's a vector, the vectors +will be element-wise divided.
Returns a new vector created by normalizing this one
+to have a magnitude of 1
. If the vector is a zero
+vector, it will not be modified.
Compute the cosine similarity between this vector and another.
Apetite.precision
require "apatite"
-TODO Write usage instructions here, but first write the library...
+Check out the documentation for usage examples.
Cartesian unit vector I
"},{"id":"J","name":"J","value":"Vector::J","doc":"Cartesian unit vector J\n\n`Vector{0.0, 1.0, 0.0}`","summary":"Cartesian unit vector J
"},{"id":"K","name":"K","value":"Vector::K","doc":"Cartesian unit vector K\n\n`Vector{0.0, 0.0, 1.0}`","summary":"Cartesian unit vector K
"},{"id":"VERSION","name":"VERSION","value":"\"0.1.0\"","doc":null,"summary":null}],"included_modules":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"}],"extended_modules":[{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Apatite is a fundimental package for scientific computing in Crystal. If that\nsounds like a modified version of the first line from the NumPy homepage,\nthat's because it is. Apatite has (ok, will have) all of the goodness\nof NumPy sitting atop the blazing speed and beautiful syntax\nof Crystal.","summary":"Apatite is a fundimental package for scientific computing in Crystal.
","class_methods":[],"constructors":[],"instance_methods":[{"id":"as_vector(input:Indexable)-instance-method","html_id":"as_vector(input:Indexable)-instance-method","name":"as_vector","doc":"Creates a new vector from the given `input`. Input can be any\n`Indexable` type.","summary":"Creates a new vector from the given input
.
Creates a standard basis-n vector of the given size
and index
.
Creates a matrix where the diagonal elements are composed of values
.
Returns a new empty Vector
Creates a new empty matrix with the given row_count
and column_count
.
Creates a new diagonal matrix of size n
with ones in the diagonal and zeros elsewhere.
Returns a new vector of size n
filled with i
Creates a n x n
identity matrix.
Returns a new vector filled with n
ones.
Creates a new vector of size n
filled with random numbers.
Creates a single-row matrix where the values of that row are as given in row
.
Creates an n
by n
diagonal matrix where each diagonal element is value.
Creates a new vector of size n
, and invokes the block once for each index of self
, assigning the block's value in that index.
Returns a new vector filled with n
zeros.
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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra.cr#L14","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra.cr#L22","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/Matrix","path":"Apatite/LinearAlgebra/Matrix.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix","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.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.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":[{"id":"[](*rows)-class-method","html_id":"[](*rows)-class-method","name":"[]","doc":"Creates a matrix where each argument is a row.","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L22","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)"}},{"id":"build(row_count,column_count=row_count,&block)-class-method","html_id":"build(row_count,column_count=row_count,&block)-class-method","name":"build","doc":"Creates a matrix of size `row_count x column_count`. It fills the values by calling\nthe given block, passing the current row and column.","summary":"Creates a matrix of size row_count x column_count
.
Creates a single-column matrix where the values of that column are as given in column.
","abstract":false,"args":[{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(column)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L39","def":{"name":"col_vector","args":[{"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":"Matrix.new([column].transpose, 1)"}},{"id":"columns(columns)-class-method","html_id":"columns(columns)-class-method","name":"columns","doc":"Creates a matrix using `columns` as an array of column vectors.","summary":"Creates a matrix using .columns
as an array of column vectors.
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
.
Creates a new diagonal matrix of size n
with ones in the diagonal and zeros elsewhere.
TODO
","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L103","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":""}},{"id":"identity(n)-class-method","html_id":"identity(n)-class-method","name":"identity","doc":"Creates a `n x n` identity matrix.","summary":"Creates a n x 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":""}],"args_string":"(rows)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L117","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size = rows[0]? ? rows[0].size : 0\nrows.each do |row|\n if row.size == size\n else\n raise(\"Dimension mismatch: row size differs (#{row.size} should be #{size})\")\n end\nend\nMatrix.new(rows, size)\n"}},{"id":"scalar(n,value)-class-method","html_id":"scalar(n,value)-class-method","name":"scalar","doc":"Creates an `n` by `n` diagonal matrix where each diagonal element is value.","summary":"Creates an n
by n
diagonal matrix where each diagonal element is value.
TODO
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"args_string":"(x, y)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L131","def":{"name":"vstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"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.","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L135","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.new(row_count) do\n Vector.new(column_count)\nend\nMatrix.new(rows, column_count)\n"}}],"constructors":[{"id":"new(rows,column_count:Int32?=nil)-class-method","html_id":"new(rows,column_count:Int32?=nil)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""},{"name":"column_count","doc":null,"default_value":"nil","external_name":"column_count","restriction":"Int32 | ::Nil"}],"args_string":"(rows, column_count : Int32? = nil)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L15","def":{"name":"new","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""},{"name":"column_count","doc":null,"default_value":"nil","external_name":"column_count","restriction":"Int32 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(rows, column_count)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L140","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n (0...column_count).reduce(0.0) do |vij, k|\n vij + (self[i, k] * other[k, j])\n end\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"id":"*(int:Int)-instance-method","html_id":"*(int:Int)-instance-method","name":"*","doc":null,"summary":null,"abstract":false,"args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":"Int"}],"args_string":"(int : Int)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L154","def":{"name":"*","args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = self.rows.map do |row|\n row.map do |e|\n e * int\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"*(ind:Indexable)-instance-method","html_id":"*(ind:Indexable)-instance-method","name":"*","doc":null,"summary":null,"abstract":false,"args":[{"name":"ind","doc":null,"default_value":"","external_name":"ind","restriction":"Indexable"}],"args_string":"(ind : Indexable)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L161","def":{"name":"*","args":[{"name":"ind","doc":null,"default_value":"","external_name":"ind","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m = column_vector\nr = self * m\nr.column(0)\n"}},{"id":"**(int)-instance-method","html_id":"**(int)-instance-method","name":"**","doc":null,"summary":null,"abstract":false,"args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":""}],"args_string":"(int)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L167","def":{"name":"**","args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if int >= 1\nelse\n raise(\"Number can not the less than 1\")\nend\nmat = self\n(int - 1).times do\n mat = mat * self\nend\nmat\n"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L176","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n self[i, j] + other[i, j]\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"id":"+(vec:Indexable)-instance-method","html_id":"+(vec:Indexable)-instance-method","name":"+","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L188","def":{"name":"+","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"vec = vec.is_a?(Vector) ? vec : Vector.create(vec)\nself + (column_vector(vec))\n"}},{"id":"-(vec:Indexable)-instance-method","html_id":"-(vec:Indexable)-instance-method","name":"-","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L205","def":{"name":"-","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"vec = vec.is_a?(Vector) ? vec : Vector.create(vec)\nself + (column_vector(vec))\n"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L193","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n self[i, j] - other[i, j]\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L210","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":"self * other.inverse"}},{"id":"/(vec:Indexable)-instance-method","html_id":"/(vec:Indexable)-instance-method","name":"/","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L214","def":{"name":"/","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = self.rows.map do |row|\n row.map do |e|\n e / other\n end\nend\nreturn new_matrix(rows, column_count)\n"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L221","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":"if (Matrix === other) && (column_count == other.column_count)\nelse\n return false\nend\nrows == other.rows\n"}},{"id":"[](row:Int,col:Int)-instance-method","html_id":"[](row:Int,col:Int)-instance-method","name":"[]","doc":"Returns element `(row, col)` of the matrix. Throws error on index error.","summary":"Returns element (row, col)
of the matrix.
Returns element (row, col)
of the matrix, or nil if the index is not found.
Returns the adjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L239","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(\"Dimention mismatch: `Matrix#adjugate` requires a square matrix.\")\nend\nMatrix.build(row_count, column_count) do |row, column|\n cofactor(column, row)\nend\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 the first minor by (-1)**(row + column)","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L247","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(\"Dimention mismatch: `Matrix#cofactor` requires a square matrix.\")\nend\ndet_of_minor = (first_minor(row, column)).determinant\ndet_of_minor * ((-1.0) ** (row + column))\n"}},{"id":"column(j,&block)-instance-method","html_id":"column(j,&block)-instance-method","name":"column","doc":"Iterates over the specified column in the matrix, returning the Vector's items.","summary":"Iterates over the specified column in the matrix, returning the Vector's items.
","abstract":false,"args":[{"name":"j","doc":null,"default_value":"","external_name":"j","restriction":""}],"args_string":"(j, &block)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L274","def":{"name":"column","args":[{"name":"j","doc":null,"default_value":"","external_name":"j","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"if j >= column_count || j < (-column_count)\n return self\nend\nrow_count.times do |i|\n yield rows[i][j]\nend\nself\n"}},{"id":"column(j)-instance-method","html_id":"column(j)-instance-method","name":"column","doc":"Returns column vector number `j` of the matrix as a `Vector` (starting at 0 like an array).","summary":"Returns column vector number j
of the matrix as a Vector
(starting at 0 like an array).
Returns column vector number j
of the matrix as a Vector
(starting at 0 like an array).
Returns an array of the column vectors of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L283","def":{"name":"column_vectors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array(Vector).new(column_count) do |i|\n column(i)\nend"}},{"id":"determinant-instance-method","html_id":"determinant-instance-method","name":"determinant","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L354","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(\"Dimention mismatch: `Matrix#determinant` requires a square matrix.\")\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":"first_minor(row,column)-instance-method","html_id":"first_minor(row,column)-instance-method","name":"first_minor","doc":null,"summary":null,"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L429","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.map(&.to_a)\narrays.delete_at(row)\narrays.each do |array|\n array.delete_at(column)\nend\nMatrix.new(arrays, column_count - 1)\n"}},{"id":"inverse-instance-method","html_id":"inverse-instance-method","name":"inverse","doc":"Returns the inverse of the matrix.","summary":"Returns the inverse of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L304","def":{"name":"inverse","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n if square?\n else\n raise(\"Dimention mismatch: `Matrix#inverse` requires a square matrix.\")\n end\nend\n(Matrix.identity(row_count)).inverse_from(self)\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.","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L450","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(\"Dimention mismatch: `Matrix#determinant` requires a square matrix.\")\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":"pretty_print(pp):Nil-instance-method","html_id":"pretty_print(pp):Nil-instance-method","name":"pretty_print","doc":null,"summary":null,"abstract":false,"args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"args_string":"(pp) : Nil","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L516","def":{"name":"pretty_print","args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"pp.list(\"[\", self, \"]\") do |vec|\n pp.group do\n vec.to_a.pretty_print(pp)\n end\nend"}},{"id":"row(i,&block)-instance-method","html_id":"row(i,&block)-instance-method","name":"row","doc":null,"summary":null,"abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i, &block)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L475","def":{"name":"row","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"return_type":"","visibility":"Public","body":"(@rows.fetch(i) do\n return self\nend).each(&block)\nself\n"}},{"id":"row(i)-instance-method","html_id":"row(i)-instance-method","name":"row","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L480","def":{"name":"row","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":"Vector.create(rows.fetch(i) do\n [] of Float64\nend)"}},{"id":"row_count:Int32-instance-method","html_id":"row_count:Int32-instance-method","name":"row_count","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L13","def":{"name":"row_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@row_count"}},{"id":"rows-instance-method","html_id":"rows-instance-method","name":"rows","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L484","def":{"name":"rows","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = [] of Vector\nrow_count.times do |i|\n rows << self[i - 1]\nend\nrows\n"}},{"id":"square?-instance-method","html_id":"square?-instance-method","name":"square?","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L492","def":{"name":"square?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"row_count == column_count"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L502","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 << (map do |row|\n (\"{\" + (row.to_a.map do |e|\n e.to_s\n end.join(\", \"))) + \"}\"\n end.join(\", \"))\n io << \"]\"\nend"}},{"id":"transpose-instance-method","html_id":"transpose-instance-method","name":"transpose","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L496","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 Matrix.empty(column_count, 0)\nend\ntransposed = rows.map do |v|\n v.to_a\nend.transpose\nMatrix.new(transposed, row_count)\n"}},{"id":"unsafe_fetch(index:Int)-instance-method","html_id":"unsafe_fetch(index:Int)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"}],"args_string":"(index : Int)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L525","def":{"name":"unsafe_fetch","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@buffer[index]"}}],"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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","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/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/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"I","name":"I","value":"Vector.create([1.0, 0.0, 0.0])","doc":"Cartesian unit vector I","summary":"Cartesian unit vector I
"},{"id":"J","name":"J","value":"Vector.create([0.0, 1.0, 0.0])","doc":"Cartesian unit vector J","summary":"Cartesian unit vector J
"},{"id":"K","name":"K","value":"Vector.create([0.0, 0.0, 1.0])","doc":"Cartesian unit vector K","summary":"Cartesian unit vector K
"}],"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
Returns a standard basis n-vector.
","abstract":false,"args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""},{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":""}],"args_string":"(size, index)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L138","def":{"name":"basis","args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""},{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size < 1\n raise(ArgumentError.new(\"invalid size (#{size} for 1..)\"))\nend\nif 0 <= index && index < size\nelse\n raise(ArgumentError.new(\"invalid index (#{index} for 0...#{size})\"))\nend\nvec = Vector.new(size, 0.0)\nvec[index] = 1.0\nvec\n"}},{"id":"create(elements:Indexable(Number))-class-method","html_id":"create(elements:Indexable(Number))-class-method","name":"create","doc":"Creates a new `Vector` from the elements of another `Indexable`\ncollection.\n\n```\nVector.create([1, 2, 3]) # Vector{1.0, 2.0, 3.0}\n```","summary":"Creates a new Vector
from the elements of another Indexable
collection.
Create a new vector of size n
filled with ones.
Creates a new Vector
of size n
filled with random numbers.
Create a new vector of size n
filled with zeros.
Creates a new Vector
, allocating an internal buffer with the given capacity, and yielding that buffer.
Creates a new Vector
of the given size filled with the same value in each position.
Creates a new empty Vector
backed by a buffer that is initially initial_capacity
big.
Create a new empty Vector
.
Creates a new Vector
of the given size and invokes the given block once for each index of self
, assigning the block's value in that index.
Alias for #push
Combined comparison 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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L339","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":"min_size = Math.min(size, other.size)\n0.upto(min_size - 1) do |i|\n n = @buffer[i] <=> other.to_unsafe[i]\n if n != 0\n return n\n end\nend\nsize <=> other.size\n"}},{"id":"==(other:Vector)-instance-method","html_id":"==(other:Vector)-instance-method","name":"==","doc":null,"summary":null,"abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"args_string":"(other : Vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L353","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"equals?(other) do |x, y|\n x == y\nend"}},{"id":"[](start:Int,count:Int)-instance-method","html_id":"[](start:Int,count:Int)-instance-method","name":"[]","doc":"Returns count or less (if there aren't enough) elements starting at the\ngiven start index.\n\nNegative indices count backward from the end of the vector (-1 is the last\nelement). Additionally, an empty vector is returned when the starting index\nfor an element range is at the end of the vector.\n\nRaises `IndexError` if the starting index is out of range.\n\n```\nv = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nv[1, 3] # => Vector{2.0, 3.0, 4.0}\nv[6, 10] # raise IndexError\n```","summary":"Returns count or less (if there aren't enough) elements starting at the given start index.
","abstract":false,"args":[{"name":"start","doc":null,"default_value":"","external_name":"start","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"}],"args_string":"(start : Int, count : Int)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L191","def":{"name":"[]","args":[{"name":"start","doc":null,"default_value":"","external_name":"start","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nif start == size\n return Vector.new\nend\nif start < 0\n start = start + size\nend\nif 0 <= start && start <= size\nelse\n raise(IndexError.new)\nend\nif count == 0\n return Vector.new\nend\ncount = Math.min(count, size - start)\nVector.build(count) do |buffer|\n buffer.copy_from(@buffer + start, count)\n count\nend\n"}},{"id":"[](range:Range(Int,Int))-instance-method","html_id":"[](range:Range(Int,Int))-instance-method","name":"[]","doc":"Returns all elements that are within the given range.\n\nNegative indices count backward from the end of the vector (-1 is the last\nelement). Additionally, an empty vector is returned when the starting index\nfor an element range is at the end of the vector.\n\nRaises `IndexError` if the starting index is out of range.\n\n```\nv = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nv[1..3] # => Vector{2.0, 3.0, 4.0}\nv[6..10] # raise IndexError\n```","summary":"Returns all elements that are within the given range.
","abstract":false,"args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"}],"args_string":"(range : Range(Int, Int))","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L173","def":{"name":"[]","args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self[*Indexable.range_to_index_and_count(range, size)]"}},{"id":"[]=(index:Int,count:Int,values:Vector)-instance-method","html_id":"[]=(index:Int,count:Int,values:Vector)-instance-method","name":"[]=","doc":"Replaces a subrange with the elements of the given vector.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = Vector{6.0, 7.0, 8.0}\nvec # = Vector{1.0, 6.0, 7.0, 8.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = Vector{6.0, 7.0}\nvec # = Vector{1.0, 6.0, 7.0, 5.0}\n```","summary":"Replaces a subrange with the elements of the given vector.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Vector"}],"args_string":"(index : Int, count : Int, values : Vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L297","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nindex = check_index_out_of_bounds(index)\ncount = ((index + count) <= size) ? count : size - index\ndiff = values.size - count\nif diff == 0\n (@buffer + index).copy_from(values.to_unsafe, values.size)\nelse\n if diff < 0\n diff = -diff\n (@buffer + index).copy_from(values.to_unsafe, values.size)\n ((@buffer + index) + values.size).move_from((@buffer + index) + count, (size - index) - count)\n ((@buffer + @size) - diff).clear(diff)\n @size = @size - diff\n else\n resize_to_capacity(Math.pw2ceil(@size + diff))\n ((@buffer + index) + values.size).move_from((@buffer + index) + count, (size - index) - count)\n (@buffer + index).copy_from(values.to_unsafe, values.size)\n @size = @size + diff\n end\nend\nvalues\n"}},{"id":"[]=(index:Int,count:Int,value)-instance-method","html_id":"[]=(index:Int,count:Int,value)-instance-method","name":"[]=","doc":"Replaces a subrange with a single value. All elements in the range\n`index...index+count` are removed and replaced by a single element\n*value*.\n\nIf *count* is zero, *value* is inserted at *index*.\n\nNegative values of *index* count from the end of the vector.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = 6.0\nvec # => Vector{1.0, 6.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 0] = 6.0\nvec # => Vector{1.0, 6.0, 2.0, 3.0, 4.0, 5.0}\n```","summary":"Replaces a subrange with a single value.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(index : Int, count : Int, value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L248","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nvalue = value.to_f64\nindex = check_index_out_of_bounds(index)\ncount = ((index + count) <= size) ? count : size - index\ncase count\nwhen 0\n insert(index, value)\nwhen 1\n @buffer[index] = value\nelse\n diff = count - 1\n ((@buffer + index) + 1).move_from((@buffer + index) + count, (size - index) - count)\n ((@buffer + @size) - diff).clear(diff)\n @buffer[index] = value\n @size = @size - diff\nend\nvalue\n"}},{"id":"[]=(index:Int,value)-instance-method","html_id":"[]=(index:Int,value)-instance-method","name":"[]=","doc":"Sets the given value at the given index.\n\nNegative indices can be used to start counting from the end of the array.\nRaises `IndexError` if trying to set an element outside the array's range.\n\n```\nvec = Vector{1.0, 2.0, 3.0}\nvec[0] = 5.0\np vec # => Vec{5.0, 2.0, 3.0}\n\nvec[3] = 5.0 # raises IndexError\n```","summary":"Sets the given value at the given index.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(index : Int, value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L226","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"index = check_index_out_of_bounds(index)\n@buffer[index] = value.to_f64\n"}},{"id":"[]=(range:Range(Int,Int),value)-instance-method","html_id":"[]=(range:Range(Int,Int),value)-instance-method","name":"[]=","doc":"Replaces a subrange with a single value.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1..3] = 6.0\nvec # = Vector{1.0, 6.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1...1] = 6\nvec # = Vector{1.0, 6.0, 2.0, 3.0, 4.0, 5.0}\n```","summary":"Replaces a subrange with a single value.
","abstract":false,"args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(range : Range(Int, Int), value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L282","def":{"name":"[]=","args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self[*Indexable.range_to_index_and_count(range, size)] = value.to_f64"}},{"id":"add(value)-instance-method","html_id":"add(value)-instance-method","name":"add","doc":"When the input is a number, this returns the result of adding\nit to all vector elements. When it's a vector, the vectors\nwill be added together.","summary":"When the input is a number, this returns the result of adding it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L488","def":{"name":"add","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a + b\nend"}},{"id":"angle_from(vector)-instance-method","html_id":"angle_from(vector)-instance-method","name":"angle_from","doc":"Returns the angle between this vector and another in radians.\nIf the vectors are mirrored across their axes this will return `nil`.","summary":"Returns the angle between this vector and another in radians.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L440","def":{"name":"angle_from","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = vector.is_a?(Vector) ? vector : Vector.create(vector)\nif size == v.size\nelse\n raise(\"Cannot compute the angle between vectors with different dimensionality\")\nend\ndot = 0_f64\nmod1 = 0_f64\nmod2 = 0_f64\n(zip(vector)).each do |x, v|\n dot = dot + (x * v)\n mod1 = mod1 + (x * x)\n mod2 = mod2 + (v * v)\nend\nmod1 = Math.sqrt(mod1)\nmod2 = Math.sqrt(mod2)\nif (mod2 * mod2) == 0\n return 0.0\nend\ntheta = (dot / (mod1 * mod2)).clamp(-1, 1)\nMath.acos(theta)\n"}},{"id":"antiparallel_to?(vector)-instance-method","html_id":"antiparallel_to?(vector)-instance-method","name":"antiparallel_to?","doc":"Returns whether the vectors are antiparallel to each other.","summary":"Returns whether the vectors are antiparallel to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L475","def":{"name":"antiparallel_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"angle = angle_from(vector)\n(angle - Math::PI).abs <= Apatite.precision\n"}},{"id":"augment(elements)-instance-method","html_id":"augment(elements)-instance-method","name":"augment","doc":"Returns a new vector with the provided `elements` concatenated\non the end.","summary":"Returns a new vector with the provided elements
concatenated on the end.
Returns a new vector with the first n
elements removed from the beginning.
Removes all elements from self.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L782","def":{"name":"clear","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@buffer.clear(@size)\n@size = 0\nself\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L374","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Vector.create(@elements.clone)"}},{"id":"concat(other:Vector)-instance-method","html_id":"concat(other:Vector)-instance-method","name":"concat","doc":null,"summary":null,"abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"args_string":"(other : Vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L731","def":{"name":"concat","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"other_size = other.size\nnew_size = size + other_size\nif new_size > @capacity\n resize_to_capacity(Math.pw2ceil(new_size))\nend\n(@buffer + @size).copy_from(other.to_unsafe, other_size)\n@size = new_size\nself\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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L601","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(*vs)-instance-method","html_id":"cross(*vs)-instance-method","name":"cross","doc":"Returns the cross product of this vector with the others.\n\n```\nv1 = Vector{1.0, 0.0, 0.0}\nv2 = Vector{0.0, 1.0, 0.0}\nv1.cross(v2) => Vector{0.0, 0.0, 1.0}\n```","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L518","def":{"name":"cross","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(\"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(\"Dimension mismatch. Vectors not all the same size.\")\n end\nend\ncase size\nwhen 2\n Vector[-@buffer[1], @buffer[0]]\nwhen 3\n v = vs[0]\n Vector[(v[2] * @buffer[1]) - (v[1] * @buffer[2]), (v[0] * @buffer[2]) - (v[2] * @buffer[0]), (v[1] * @buffer[0]) - (v[0] * @buffer[1])]\nelse\nend\n"}},{"id":"distance_from(obj)-instance-method","html_id":"distance_from(obj)-instance-method","name":"distance_from","doc":"Gets this vector's distance from the argument, when considered\na point in space.","summary":"Gets this vector's distance from the argument, when considered a point in space.
","abstract":false,"args":[{"name":"obj","doc":null,"default_value":"","external_name":"obj","restriction":""}],"args_string":"(obj)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L629","def":{"name":"distance_from","args":[{"name":"obj","doc":null,"default_value":"","external_name":"obj","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if object.is_a?(Plane) || object.is_a?(Line)\n return object.distance_from(self)\nend\nv = elements.is_a?(Vector) ? elements.elements : elements\nif v.size == @elements.size\nelse\n return nil\nend\nsum = 0\npart = 0\neach_with_index do |x, i|\n part = x - v[i - 1]\n sum = sum + (part * part)\nend\nMath.sqrt(sum)\n"}},{"id":"dot(other)-instance-method","html_id":"dot(other)-instance-method","name":"dot","doc":"Get the scalar (dot) product of this vector with `vector`.\n\n[https://en.wikipedia.org/wiki/Scalar_product](https://en.wikipedia.org/wiki/Scalar_product)","summary":"Get the scalar (dot) product of this vector with vector
.
Returns the ith
element of the vector.
Returns true if all vectors are linearly independent.
","abstract":false,"args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"args_string":"(*vs)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L384","def":{"name":"independent?","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":"vs.each do |v|\n if v.size == vs.first.size\n else\n raise(\"Dimension mismatch. Vectors not all the same size.\")\n end\nend\nif vs.size > sv.first.size\n return false\nend\nMatrix[*vs].rank.equal?(vs.count)\n"}},{"id":"lies_in(plane)-instance-method","html_id":"lies_in(plane)-instance-method","name":"lies_in","doc":"Returns true if the vector is a point on the given plane.","summary":"Returns true if the vector is a point on the given plane.
","abstract":false,"args":[{"name":"plane","doc":null,"default_value":"","external_name":"plane","restriction":""}],"args_string":"(plane)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L654","def":{"name":"lies_in","args":[{"name":"plane","doc":null,"default_value":"","external_name":"plane","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"plane.contains(self)"}},{"id":"lies_on(line)-instance-method","html_id":"lies_on(line)-instance-method","name":"lies_on","doc":"Returns true if the vector is a point on the given line","summary":"Returns true if the vector is a point on the given line
","abstract":false,"args":[{"name":"line","doc":null,"default_value":"","external_name":"line","restriction":""}],"args_string":"(line)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L649","def":{"name":"lies_on","args":[{"name":"line","doc":null,"default_value":"","external_name":"line","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"line.contains(self)"}},{"id":"log-instance-method","html_id":"log-instance-method","name":"log","doc":"Return a new `Vector` with the log of every item in `self`.","summary":"Return a new Vector
with the log of every item in self
.
Returns the magnitude/euclidian norm of this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L419","def":{"name":"magnitude","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sum = reduce(0.0) do |acc, e|\n acc = acc + (e * e)\nend\nMath.sqrt(sum)\n"}},{"id":"map(&block)-instance-method","html_id":"map(&block)-instance-method","name":"map","doc":"Invokes the given block for each element of `self`.","summary":"Invokes the given block for each element of self
.
Invokes the given block for each element of self
, replacing the element with the value returned by the block.
Optimized version of Enumerable#map_with_index
.
Like #map_with_index
, but mutates self
instead of allocating a new object.
Returns the (absolute) largest element in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L589","def":{"name":"max","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce do |acc, i|\n i.abs > acc.abs ? i : acc\nend"}},{"id":"max_index-instance-method","html_id":"max_index-instance-method","name":"max_index","doc":"Gets the index of the largest element in this vector.","summary":"Gets the index of the largest element in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L594","def":{"name":"max_index","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"idx = 0\neach_with_index do |e, i|\n idx = e.abs > self[idx].abs ? i : idx\nend\nidx\n"}},{"id":"multiply(value)-instance-method","html_id":"multiply(value)-instance-method","name":"multiply","doc":"When the input is a number, this returns the result of multiplying\nit to all vector elements. When it's a vector, the vectors\nwill be element-wise multiplied.","summary":"When the input is a number, this returns the result of multiplying it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L502","def":{"name":"multiply","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a * b\nend"}},{"id":"parallel_to?(vector)-instance-method","html_id":"parallel_to?(vector)-instance-method","name":"parallel_to?","doc":"Returns whether the vectors are parallel to each other.","summary":"Returns whether the vectors are parallel to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L469","def":{"name":"parallel_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"angle = angle_from(vector)\nangle <= Apatite.precision\n"}},{"id":"perpendicular_to?(vector)-instance-method","html_id":"perpendicular_to?(vector)-instance-method","name":"perpendicular_to?","doc":"Returns whether the vectors are perpendicular to each other.","summary":"Returns whether the vectors are perpendicular to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L481","def":{"name":"perpendicular_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(dot(vector)).abs <= Apatite.precision"}},{"id":"pretty_print(pp):Nil-instance-method","html_id":"pretty_print(pp):Nil-instance-method","name":"pretty_print","doc":null,"summary":null,"abstract":false,"args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"args_string":"(pp) : Nil","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L754","def":{"name":"pretty_print","args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"pp.list(\"Vector{\", self, \"}\")"}},{"id":"product-instance-method","html_id":"product-instance-method","name":"product","doc":"Get the product of all elements in this vector.","summary":"Get the product of all elements in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L567","def":{"name":"product","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce do |acc, v|\n acc = acc * v\nend"}},{"id":"push(*values:Float64)-instance-method","html_id":"push(*values:Float64)-instance-method","name":"push","doc":null,"summary":null,"abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Float64"}],"args_string":"(*values : Float64)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L665","def":{"name":"push","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Float64"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new_size = @size + values.size\nif new_size > @capacity\n resize_to_capacity(Math.pw2ceil(new_size))\nend\nvalues.each_with_index do |value, i|\n @buffer[@size + i] = value\nend\n@size = new_size\nself\n"}},{"id":"push(value:Float64)-instance-method","html_id":"push(value:Float64)-instance-method","name":"push","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Float64"}],"args_string":"(value : Float64)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L658","def":{"name":"push","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"check_needs_resize\n@buffer[@size] = value\n@size = @size + 1\nself\n"}},{"id":"reflection_in(object)-instance-method","html_id":"reflection_in(object)-instance-method","name":"reflection_in","doc":"Returns the result of reflecting the point in the given `object`\n(point, line, or plane).","summary":"Returns the result of reflecting the point in the given object
(point, line, or plane).
Rotates the vector about the given object
.
Gets the result of rounding the elements of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L612","def":{"name":"round","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |x|\n x.round\nend"}},{"id":"set_elements(elements)-instance-method","html_id":"set_elements(elements)-instance-method","name":"set_elements","doc":null,"summary":null,"abstract":false,"args":[{"name":"elements","doc":null,"default_value":"","external_name":"elements","restriction":""}],"args_string":"(elements)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L726","def":{"name":"set_elements","args":[{"name":"elements","doc":null,"default_value":"","external_name":"elements","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements = elements.is_a?(Vector) ? elements.elements : elements\nself\n"}},{"id":"sigmoid-instance-method","html_id":"sigmoid-instance-method","name":"sigmoid","doc":"Sums the numbers in the vector and returns a sigmoid value\nacross the whole vector.","summary":"Sums the numbers in the vector and returns a sigmoid value across the whole vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L707","def":{"name":"sigmoid","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"LinearAlgebra.sigmoid(sum)"}},{"id":"size:Int32-instance-method","html_id":"size:Int32-instance-method","name":"size","doc":"Returns the number of elements in the vector","summary":"Returns the number of elements in the vector
","abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L24","def":{"name":"size","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@size"}},{"id":"snap_to(value)-instance-method","html_id":"snap_to(value)-instance-method","name":"snap_to","doc":"Returns a copy of the vector with elements set to `value` if\nthey differ from it by less than `Apetite.precision`","summary":"Returns a copy of the vector with elements set to value
if they differ from it by less than Apetite.precision
When the input is a number, this returns the result of subtracting it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L495","def":{"name":"subtract","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a - b\nend"}},{"id":"sum-instance-method","html_id":"sum-instance-method","name":"sum","doc":"Returns the sum of all elements in the vector.","summary":"Returns the sum of all elements in the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L507","def":{"name":"sum","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce(0) do |acc, i|\n acc + i\nend"}},{"id":"to_3d-instance-method","html_id":"to_3d-instance-method","name":"to_3d","doc":"Utility to make sure vectors are 3D. If they are 2D, a zero\nz-component is added.","summary":"Utility to make sure vectors are 3D.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L713","def":{"name":"to_3d","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = dup\ncase v.elements.size\nwhen 3\n break\nwhen 2\n v.elements.push(0)\nelse\n return nil\nend\nreturn v\n"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L744","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array(Float64).new(size) do |i|\n self[i]\nend"}},{"id":"to_diagonal_matrix-instance-method","html_id":"to_diagonal_matrix-instance-method","name":"to_diagonal_matrix","doc":"Returns a diagonal `Matrix` with the vectors elements as its\ndiagonal elements.","summary":"Returns a diagonal Matrix
with the vectors elements as its diagonal elements.
Returns a new vector created by normalizing this one to have a magnitude of 1
.
Returns a pointer to the internal buffer where self
's elements are stored.
Returns a vector containing only the first n
elements.
Transpose this vector into a 1xn Matrix
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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/core_ext/array.cr#L24","def":{"name":"to_vec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite::Vector.create(self)"}}],"macros":[],"types":[]}]}} \ No newline at end of file +{"repository_name":"github.com/watzon/apatite","body":"# Apatite\n\nApatite is meant to be a collecion of mathmatical and scientific computing algorithms for the Crystal programming language. I don't expect it to ever reach the level of completeness as numpy, but hopefully it can save some people the trouble of implementing these methods on their own.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n apatite:\n github: watzon/apatite\n ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"apatite\"\n```\n\nCheck out the [documentation](https://watzon.github.io/apatite/) for usage examples.\n\n## Roadmap\n\n- [ ] Linear Algebra\n\t- [x] Vector\n\t- [ ] Matrix (_in progress_)\n\t- [ ] NDArray\n\t- [ ] Line\n\t- [ ] Plane\n\t- [ ] Polygon\n\t- [ ] LinkedList\n\t\n\n\n## Contributing\n\n1. Fork it (Cartesian unit vector I
"},{"id":"J","name":"J","value":"Vector::J","doc":"Cartesian unit vector J\n\n`Vector{0.0, 1.0, 0.0}`","summary":"Cartesian unit vector J
"},{"id":"K","name":"K","value":"Vector::K","doc":"Cartesian unit vector K\n\n`Vector{0.0, 0.0, 1.0}`","summary":"Cartesian unit vector K
"},{"id":"VERSION","name":"VERSION","value":"\"0.1.0\"","doc":null,"summary":null}],"included_modules":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"}],"extended_modules":[{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Apatite is a fundimental package for scientific computing in Crystal. If that\nsounds like a modified version of the first line from the NumPy homepage,\nthat's because it is. Apatite has (ok, will have) all of the goodness\nof NumPy sitting atop the blazing speed and beautiful syntax\nof Crystal.","summary":"Apatite is a fundimental package for scientific computing in Crystal.
","class_methods":[{"id":"approx_precision-class-method","html_id":"approx_precision-class-method","name":"approx_precision","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L18","def":{"name":"approx_precision","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@@approx_precision"}},{"id":"approx_precision=(approx_precision)-class-method","html_id":"approx_precision=(approx_precision)-class-method","name":"approx_precision=","doc":null,"summary":null,"abstract":false,"args":[{"name":"approx_precision","doc":null,"default_value":"","external_name":"approx_precision","restriction":""}],"args_string":"(approx_precision)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L22","def":{"name":"approx_precision=","args":[{"name":"approx_precision","doc":null,"default_value":"","external_name":"approx_precision","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@@approx_precision = approx_precision"}},{"id":"precision-class-method","html_id":"precision-class-method","name":"precision","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L17","def":{"name":"precision","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@@precision"}},{"id":"precision=(precision)-class-method","html_id":"precision=(precision)-class-method","name":"precision=","doc":null,"summary":null,"abstract":false,"args":[{"name":"precision","doc":null,"default_value":"","external_name":"precision","restriction":""}],"args_string":"(precision)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L21","def":{"name":"precision=","args":[{"name":"precision","doc":null,"default_value":"","external_name":"precision","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@@precision = precision"}}],"constructors":[],"instance_methods":[{"id":"angle_from(a,b)-instance-method","html_id":"angle_from(a,b)-instance-method","name":"angle_from","doc":"Returns the angle between this vector and another in radians.\nIf the vectors are mirrored across their axes this will return `nil`.","summary":"Returns the angle between this vector and another in radians.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L145","def":{"name":"angle_from","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if a.size == b.size\nelse\n raise(\"Cannot compute the angle between vectors with different dimensionality\")\nend\ndot = 0_f64\nmod1 = 0_f64\nmod2 = 0_f64\n(a.zip(b)).each do |x, v|\n dot = dot + (x * v)\n mod1 = mod1 + (x * x)\n mod2 = mod2 + (v * v)\nend\nmod1 = Math.sqrt(mod1)\nmod2 = Math.sqrt(mod2)\nif (mod2 * mod2) == 0\n return 0.0\nend\ntheta = (dot / (mod1 * mod2)).clamp(-1, 1)\nMath.acos(theta)\n"}},{"id":"antiparallel_to?(a,b)-instance-method","html_id":"antiparallel_to?(a,b)-instance-method","name":"antiparallel_to?","doc":"Returns whether the vectors are antiparallel to each other.","summary":"Returns whether the vectors are antiparallel to each other.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L178","def":{"name":"antiparallel_to?","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"angle = angle_from(a, b)\n(angle - Math::PI).abs <= precision\n"}},{"id":"as_vector(input:Indexable)-instance-method","html_id":"as_vector(input:Indexable)-instance-method","name":"as_vector","doc":"Creates a new vector from the given `input`. Input can be any\n`Indexable` type.","summary":"Creates a new vector from the given input
.
Creates a standard basis-n vector of the given size
and index
.
Creates a matrix where the diagonal elements are composed of values
.
Get the scalar (dot) product of two vectors.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"args_string":"(x, y)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L125","def":{"name":"dot","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if x.size == y.size\nelse\n raise(\"Cannot compute the dot product of vectors with different dimensionality\")\nend\n(0...x.size).reduce(0) do |acc, i|\n acc + (x[i] * y[i])\nend\n"}},{"id":"empty-instance-method","html_id":"empty-instance-method","name":"empty","doc":"Returns a new empty `Vector`","summary":"Returns a new empty Vector
Creates a new empty matrix with the given row_count
and column_count
.
Creates a new diagonal matrix of size n
with ones in the diagonal and zeros elsewhere.
Returns a new vector of size n
filled with i
Creates a n x n
identity matrix.
Returns a new vector filled with n
ones.
Returns whether the vectors are parallel to each other.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L172","def":{"name":"parallel_to?","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"angle = angle_from(a, b)\nangle <= precision\n"}},{"id":"perpendicular_to?(a,b)-instance-method","html_id":"perpendicular_to?(a,b)-instance-method","name":"perpendicular_to?","doc":"Returns whether the vectors are perpendicular to each other.","summary":"Returns whether the vectors are perpendicular to each other.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L184","def":{"name":"perpendicular_to?","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(dot(a, b)).abs <= precision"}},{"id":"random(n,range=nil)-instance-method","html_id":"random(n,range=nil)-instance-method","name":"random","doc":"Creates a new vector of size `n` filled with random numbers. A `range`\ncan optionally be passed in if you want to limit the random numbers\nto a given range.","summary":"Creates a new vector of size n
filled with random numbers.
Creates a single-row matrix where the values of that row are as given in row
.
Creates an n
by n
diagonal matrix where each diagonal element is value.
Compute the cosine similarity between two vectors.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"args_string":"(x, y)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L136","def":{"name":"similarity","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(dot(x, y)) / ((Math.sqrt(dot(x, x))) * (Math.sqrt(dot(y, y))))"}},{"id":"vector(n,&block)-instance-method","html_id":"vector(n,&block)-instance-method","name":"vector","doc":"Creates a new vector of size `n`, and invokes the block once\nfor each index of `self`, assigning the block's value in that index.","summary":"Creates a new vector of size n
, and invokes the block once for each index of self
, assigning the block's value in that index.
Returns a new vector filled with n
zeros.
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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra.cr#L14","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra.cr#L22","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/Matrix","path":"Apatite/LinearAlgebra/Matrix.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix","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.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.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":[{"id":"[](*rows)-class-method","html_id":"[](*rows)-class-method","name":"[]","doc":"Creates a matrix where each argument is a row.","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L22","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)"}},{"id":"build(row_count,column_count=row_count,&block)-class-method","html_id":"build(row_count,column_count=row_count,&block)-class-method","name":"build","doc":"Creates a matrix of size `row_count x column_count`. It fills the values by calling\nthe given block, passing the current row and column.","summary":"Creates a matrix of size row_count x column_count
.
Creates a single-column matrix where the values of that column are as given in column.
","abstract":false,"args":[{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(column)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L39","def":{"name":"col_vector","args":[{"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":"Matrix.new([column].transpose, 1)"}},{"id":"columns(columns)-class-method","html_id":"columns(columns)-class-method","name":"columns","doc":"Creates a matrix using `columns` as an array of column vectors.","summary":"Creates a matrix using .columns
as an array of column vectors.
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
.
Creates a new diagonal matrix of size n
with ones in the diagonal and zeros elsewhere.
TODO
","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L103","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":""}},{"id":"identity(n)-class-method","html_id":"identity(n)-class-method","name":"identity","doc":"Creates a `n x n` identity matrix.","summary":"Creates a n x 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":""}],"args_string":"(rows)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L117","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size = rows[0]? ? rows[0].size : 0\nrows.each do |row|\n if row.size == size\n else\n raise(\"Dimension mismatch: row size differs (#{row.size} should be #{size})\")\n end\nend\nMatrix.new(rows, size)\n"}},{"id":"scalar(n,value)-class-method","html_id":"scalar(n,value)-class-method","name":"scalar","doc":"Creates an `n` by `n` diagonal matrix where each diagonal element is value.","summary":"Creates an n
by n
diagonal matrix where each diagonal element is value.
TODO
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"args_string":"(x, y)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L131","def":{"name":"vstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"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.","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L135","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.new(row_count) do\n Vector.new(column_count)\nend\nMatrix.new(rows, column_count)\n"}}],"constructors":[{"id":"new(rows,column_count:Int32?=nil)-class-method","html_id":"new(rows,column_count:Int32?=nil)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""},{"name":"column_count","doc":null,"default_value":"nil","external_name":"column_count","restriction":"Int32 | ::Nil"}],"args_string":"(rows, column_count : Int32? = nil)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L15","def":{"name":"new","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""},{"name":"column_count","doc":null,"default_value":"nil","external_name":"column_count","restriction":"Int32 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(rows, column_count)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L140","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n (0...column_count).reduce(0.0) do |vij, k|\n vij + (self[i, k] * other[k, j])\n end\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"id":"*(int:Int)-instance-method","html_id":"*(int:Int)-instance-method","name":"*","doc":null,"summary":null,"abstract":false,"args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":"Int"}],"args_string":"(int : Int)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L154","def":{"name":"*","args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = self.rows.map do |row|\n row.map do |e|\n e * int\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"*(ind:Indexable)-instance-method","html_id":"*(ind:Indexable)-instance-method","name":"*","doc":null,"summary":null,"abstract":false,"args":[{"name":"ind","doc":null,"default_value":"","external_name":"ind","restriction":"Indexable"}],"args_string":"(ind : Indexable)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L161","def":{"name":"*","args":[{"name":"ind","doc":null,"default_value":"","external_name":"ind","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m = column_vector\nr = self * m\nr.column(0)\n"}},{"id":"**(int)-instance-method","html_id":"**(int)-instance-method","name":"**","doc":null,"summary":null,"abstract":false,"args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":""}],"args_string":"(int)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L167","def":{"name":"**","args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if int >= 1\nelse\n raise(\"Number can not the less than 1\")\nend\nmat = self\n(int - 1).times do\n mat = mat * self\nend\nmat\n"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L176","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n self[i, j] + other[i, j]\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"id":"+(vec:Indexable)-instance-method","html_id":"+(vec:Indexable)-instance-method","name":"+","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L188","def":{"name":"+","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"vec = vec.is_a?(Vector) ? vec : Vector.create(vec)\nself + (column_vector(vec))\n"}},{"id":"-(vec:Indexable)-instance-method","html_id":"-(vec:Indexable)-instance-method","name":"-","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L205","def":{"name":"-","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"vec = vec.is_a?(Vector) ? vec : Vector.create(vec)\nself + (column_vector(vec))\n"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L193","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n self[i, j] - other[i, j]\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L210","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":"self * other.inverse"}},{"id":"/(vec:Indexable)-instance-method","html_id":"/(vec:Indexable)-instance-method","name":"/","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L214","def":{"name":"/","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = self.rows.map do |row|\n row.map do |e|\n e / other\n end\nend\nreturn new_matrix(rows, column_count)\n"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L221","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":"if (Matrix === other) && (column_count == other.column_count)\nelse\n return false\nend\nrows == other.rows\n"}},{"id":"[](row:Int,col:Int)-instance-method","html_id":"[](row:Int,col:Int)-instance-method","name":"[]","doc":"Returns element `(row, col)` of the matrix. Throws error on index error.","summary":"Returns element (row, col)
of the matrix.
Returns element (row, col)
of the matrix, or nil if the index is not found.
Returns the adjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L239","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(\"Dimention mismatch: `Matrix#adjugate` requires a square matrix.\")\nend\nMatrix.build(row_count, column_count) do |row, column|\n cofactor(column, row)\nend\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 the first minor by (-1)**(row + column)","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L247","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(\"Dimention mismatch: `Matrix#cofactor` requires a square matrix.\")\nend\ndet_of_minor = (first_minor(row, column)).determinant\ndet_of_minor * ((-1.0) ** (row + column))\n"}},{"id":"column(j,&block)-instance-method","html_id":"column(j,&block)-instance-method","name":"column","doc":"Iterates over the specified column in the matrix, returning the Vector's items.","summary":"Iterates over the specified column in the matrix, returning the Vector's items.
","abstract":false,"args":[{"name":"j","doc":null,"default_value":"","external_name":"j","restriction":""}],"args_string":"(j, &block)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L274","def":{"name":"column","args":[{"name":"j","doc":null,"default_value":"","external_name":"j","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"if j >= column_count || j < (-column_count)\n return self\nend\nrow_count.times do |i|\n yield rows[i][j]\nend\nself\n"}},{"id":"column(j)-instance-method","html_id":"column(j)-instance-method","name":"column","doc":"Returns column vector number `j` of the matrix as a `Vector` (starting at 0 like an array).","summary":"Returns column vector number j
of the matrix as a Vector
(starting at 0 like an array).
Returns column vector number j
of the matrix as a Vector
(starting at 0 like an array).
Returns an array of the column vectors of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L283","def":{"name":"column_vectors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array(Vector).new(column_count) do |i|\n column(i)\nend"}},{"id":"determinant-instance-method","html_id":"determinant-instance-method","name":"determinant","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L354","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(\"Dimention mismatch: `Matrix#determinant` requires a square matrix.\")\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":"first_minor(row,column)-instance-method","html_id":"first_minor(row,column)-instance-method","name":"first_minor","doc":null,"summary":null,"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L429","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.map(&.to_a)\narrays.delete_at(row)\narrays.each do |array|\n array.delete_at(column)\nend\nMatrix.new(arrays, column_count - 1)\n"}},{"id":"inverse-instance-method","html_id":"inverse-instance-method","name":"inverse","doc":"Returns the inverse of the matrix.","summary":"Returns the inverse of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L304","def":{"name":"inverse","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n if square?\n else\n raise(\"Dimention mismatch: `Matrix#inverse` requires a square matrix.\")\n end\nend\n(Matrix.identity(row_count)).inverse_from(self)\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.","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L450","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(\"Dimention mismatch: `Matrix#determinant` requires a square matrix.\")\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":"pretty_print(pp):Nil-instance-method","html_id":"pretty_print(pp):Nil-instance-method","name":"pretty_print","doc":null,"summary":null,"abstract":false,"args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"args_string":"(pp) : Nil","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L516","def":{"name":"pretty_print","args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"pp.list(\"[\", self, \"]\") do |vec|\n pp.group do\n vec.to_a.pretty_print(pp)\n end\nend"}},{"id":"row(i,&block)-instance-method","html_id":"row(i,&block)-instance-method","name":"row","doc":null,"summary":null,"abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i, &block)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L475","def":{"name":"row","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"return_type":"","visibility":"Public","body":"(@rows.fetch(i) do\n return self\nend).each(&block)\nself\n"}},{"id":"row(i)-instance-method","html_id":"row(i)-instance-method","name":"row","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L480","def":{"name":"row","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":"Vector.create(rows.fetch(i) do\n [] of Float64\nend)"}},{"id":"row_count:Int32-instance-method","html_id":"row_count:Int32-instance-method","name":"row_count","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L13","def":{"name":"row_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@row_count"}},{"id":"rows-instance-method","html_id":"rows-instance-method","name":"rows","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L484","def":{"name":"rows","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = [] of Vector\nrow_count.times do |i|\n rows << self[i - 1]\nend\nrows\n"}},{"id":"square?-instance-method","html_id":"square?-instance-method","name":"square?","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L492","def":{"name":"square?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"row_count == column_count"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L502","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 << (map do |row|\n (\"{\" + (row.to_a.map do |e|\n e.to_s\n end.join(\", \"))) + \"}\"\n end.join(\", \"))\n io << \"]\"\nend"}},{"id":"transpose-instance-method","html_id":"transpose-instance-method","name":"transpose","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L496","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 Matrix.empty(column_count, 0)\nend\ntransposed = rows.map do |v|\n v.to_a\nend.transpose\nMatrix.new(transposed, row_count)\n"}},{"id":"unsafe_fetch(index:Int)-instance-method","html_id":"unsafe_fetch(index:Int)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"}],"args_string":"(index : Int)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L525","def":{"name":"unsafe_fetch","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@buffer[index]"}}],"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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","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/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/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"I","name":"I","value":"Vector.create([1.0, 0.0, 0.0])","doc":"Cartesian unit vector I","summary":"Cartesian unit vector I
"},{"id":"J","name":"J","value":"Vector.create([0.0, 1.0, 0.0])","doc":"Cartesian unit vector J","summary":"Cartesian unit vector J
"},{"id":"K","name":"K","value":"Vector.create([0.0, 0.0, 1.0])","doc":"Cartesian unit vector K","summary":"Cartesian unit vector K
"}],"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
Returns a standard basis n-vector.
","abstract":false,"args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""},{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":""}],"args_string":"(size, index)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L138","def":{"name":"basis","args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""},{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size < 1\n raise(ArgumentError.new(\"invalid size (#{size} for 1..)\"))\nend\nif 0 <= index && index < size\nelse\n raise(ArgumentError.new(\"invalid index (#{index} for 0...#{size})\"))\nend\nvec = Vector.new(size, 0.0)\nvec[index] = 1.0\nvec\n"}},{"id":"create(elements:Indexable(Number))-class-method","html_id":"create(elements:Indexable(Number))-class-method","name":"create","doc":"Creates a new `Vector` from the elements of another `Indexable`\ncollection.\n\n```\nVector.create([1, 2, 3]) # Vector{1.0, 2.0, 3.0}\n```","summary":"Creates a new Vector
from the elements of another Indexable
collection.
Create a new vector of size n
filled with ones.
Creates a new Vector
of size n
filled with random numbers.
Create a new vector of size n
filled with zeros.
Creates a new Vector
, allocating an internal buffer with the given capacity, and yielding that buffer.
Creates a new Vector
of the given size filled with the same value in each position.
Creates a new empty Vector
backed by a buffer that is initially initial_capacity
big.
Create a new empty Vector
.
Creates a new Vector
of the given size and invokes the given block once for each index of self
, assigning the block's value in that index.
Alias for #push
Combined comparison 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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L339","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":"min_size = Math.min(size, other.size)\n0.upto(min_size - 1) do |i|\n n = @buffer[i] <=> other.to_unsafe[i]\n if n != 0\n return n\n end\nend\nsize <=> other.size\n"}},{"id":"==(other:Vector)-instance-method","html_id":"==(other:Vector)-instance-method","name":"==","doc":null,"summary":null,"abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"args_string":"(other : Vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L353","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"equals?(other) do |x, y|\n x == y\nend"}},{"id":"[](start:Int,count:Int)-instance-method","html_id":"[](start:Int,count:Int)-instance-method","name":"[]","doc":"Returns count or less (if there aren't enough) elements starting at the\ngiven start index.\n\nNegative indices count backward from the end of the vector (-1 is the last\nelement). Additionally, an empty vector is returned when the starting index\nfor an element range is at the end of the vector.\n\nRaises `IndexError` if the starting index is out of range.\n\n```\nv = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nv[1, 3] # => Vector{2.0, 3.0, 4.0}\nv[6, 10] # raise IndexError\n```","summary":"Returns count or less (if there aren't enough) elements starting at the given start index.
","abstract":false,"args":[{"name":"start","doc":null,"default_value":"","external_name":"start","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"}],"args_string":"(start : Int, count : Int)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L191","def":{"name":"[]","args":[{"name":"start","doc":null,"default_value":"","external_name":"start","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nif start == size\n return Vector.new\nend\nif start < 0\n start = start + size\nend\nif 0 <= start && start <= size\nelse\n raise(IndexError.new)\nend\nif count == 0\n return Vector.new\nend\ncount = Math.min(count, size - start)\nVector.build(count) do |buffer|\n buffer.copy_from(@buffer + start, count)\n count\nend\n"}},{"id":"[](range:Range(Int,Int))-instance-method","html_id":"[](range:Range(Int,Int))-instance-method","name":"[]","doc":"Returns all elements that are within the given range.\n\nNegative indices count backward from the end of the vector (-1 is the last\nelement). Additionally, an empty vector is returned when the starting index\nfor an element range is at the end of the vector.\n\nRaises `IndexError` if the starting index is out of range.\n\n```\nv = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nv[1..3] # => Vector{2.0, 3.0, 4.0}\nv[6..10] # raise IndexError\n```","summary":"Returns all elements that are within the given range.
","abstract":false,"args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"}],"args_string":"(range : Range(Int, Int))","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L173","def":{"name":"[]","args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self[*Indexable.range_to_index_and_count(range, size)]"}},{"id":"[]=(index:Int,count:Int,values:Vector)-instance-method","html_id":"[]=(index:Int,count:Int,values:Vector)-instance-method","name":"[]=","doc":"Replaces a subrange with the elements of the given vector.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = Vector{6.0, 7.0, 8.0}\nvec # = Vector{1.0, 6.0, 7.0, 8.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = Vector{6.0, 7.0}\nvec # = Vector{1.0, 6.0, 7.0, 5.0}\n```","summary":"Replaces a subrange with the elements of the given vector.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Vector"}],"args_string":"(index : Int, count : Int, values : Vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L297","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nindex = check_index_out_of_bounds(index)\ncount = ((index + count) <= size) ? count : size - index\ndiff = values.size - count\nif diff == 0\n (@buffer + index).copy_from(values.to_unsafe, values.size)\nelse\n if diff < 0\n diff = -diff\n (@buffer + index).copy_from(values.to_unsafe, values.size)\n ((@buffer + index) + values.size).move_from((@buffer + index) + count, (size - index) - count)\n ((@buffer + @size) - diff).clear(diff)\n @size = @size - diff\n else\n resize_to_capacity(Math.pw2ceil(@size + diff))\n ((@buffer + index) + values.size).move_from((@buffer + index) + count, (size - index) - count)\n (@buffer + index).copy_from(values.to_unsafe, values.size)\n @size = @size + diff\n end\nend\nvalues\n"}},{"id":"[]=(index:Int,count:Int,value)-instance-method","html_id":"[]=(index:Int,count:Int,value)-instance-method","name":"[]=","doc":"Replaces a subrange with a single value. All elements in the range\n`index...index+count` are removed and replaced by a single element\n*value*.\n\nIf *count* is zero, *value* is inserted at *index*.\n\nNegative values of *index* count from the end of the vector.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = 6.0\nvec # => Vector{1.0, 6.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 0] = 6.0\nvec # => Vector{1.0, 6.0, 2.0, 3.0, 4.0, 5.0}\n```","summary":"Replaces a subrange with a single value.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(index : Int, count : Int, value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L248","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nvalue = value.to_f64\nindex = check_index_out_of_bounds(index)\ncount = ((index + count) <= size) ? count : size - index\ncase count\nwhen 0\n insert(index, value)\nwhen 1\n @buffer[index] = value\nelse\n diff = count - 1\n ((@buffer + index) + 1).move_from((@buffer + index) + count, (size - index) - count)\n ((@buffer + @size) - diff).clear(diff)\n @buffer[index] = value\n @size = @size - diff\nend\nvalue\n"}},{"id":"[]=(index:Int,value)-instance-method","html_id":"[]=(index:Int,value)-instance-method","name":"[]=","doc":"Sets the given value at the given index.\n\nNegative indices can be used to start counting from the end of the array.\nRaises `IndexError` if trying to set an element outside the array's range.\n\n```\nvec = Vector{1.0, 2.0, 3.0}\nvec[0] = 5.0\np vec # => Vec{5.0, 2.0, 3.0}\n\nvec[3] = 5.0 # raises IndexError\n```","summary":"Sets the given value at the given index.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(index : Int, value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L226","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"index = check_index_out_of_bounds(index)\n@buffer[index] = value.to_f64\n"}},{"id":"[]=(range:Range(Int,Int),value)-instance-method","html_id":"[]=(range:Range(Int,Int),value)-instance-method","name":"[]=","doc":"Replaces a subrange with a single value.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1..3] = 6.0\nvec # = Vector{1.0, 6.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1...1] = 6\nvec # = Vector{1.0, 6.0, 2.0, 3.0, 4.0, 5.0}\n```","summary":"Replaces a subrange with a single value.
","abstract":false,"args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(range : Range(Int, Int), value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L282","def":{"name":"[]=","args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self[*Indexable.range_to_index_and_count(range, size)] = value.to_f64"}},{"id":"add(value)-instance-method","html_id":"add(value)-instance-method","name":"add","doc":"When the input is a number, this returns the result of adding\nit to all vector elements. When it's a vector, the vectors\nwill be added together.","summary":"When the input is a number, this returns the result of adding it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L476","def":{"name":"add","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a + b\nend"}},{"id":"angle_from(vector)-instance-method","html_id":"angle_from(vector)-instance-method","name":"angle_from","doc":"Returns the angle between this vector and another in radians.\nIf the vectors are mirrored across their axes this will return `nil`.","summary":"Returns the angle between this vector and another in radians.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L449","def":{"name":"angle_from","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite.angle_from(self, vector)"}},{"id":"antiparallel_to?(vector)-instance-method","html_id":"antiparallel_to?(vector)-instance-method","name":"antiparallel_to?","doc":"Returns whether the vectors are antiparallel to each other.","summary":"Returns whether the vectors are antiparallel to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L464","def":{"name":"antiparallel_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite.antiparallel_to?(self, vector)"}},{"id":"augment(elements)-instance-method","html_id":"augment(elements)-instance-method","name":"augment","doc":"Returns a new vector with the provided `elements` concatenated\non the end.","summary":"Returns a new vector with the provided elements
concatenated on the end.
Returns a new vector with the first n
elements removed from the beginning.
Removes all elements from self.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L768","def":{"name":"clear","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@buffer.clear(@size)\n@size = 0\nself\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L378","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Vector.create(@elements.clone)"}},{"id":"concat(other:Vector)-instance-method","html_id":"concat(other:Vector)-instance-method","name":"concat","doc":null,"summary":null,"abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"args_string":"(other : Vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L717","def":{"name":"concat","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"other_size = other.size\nnew_size = size + other_size\nif new_size > @capacity\n resize_to_capacity(Math.pw2ceil(new_size))\nend\n(@buffer + @size).copy_from(other.to_unsafe, other_size)\n@size = new_size\nself\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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L587","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(*vs)-instance-method","html_id":"cross(*vs)-instance-method","name":"cross","doc":"Returns the cross product of this vector with the others.\n\n```\nv1 = Vector{1.0, 0.0, 0.0}\nv2 = Vector{0.0, 1.0, 0.0}\nv1.cross(v2) => Vector{0.0, 0.0, 1.0}\n```","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L513","def":{"name":"cross","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(\"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(\"Dimension mismatch. Vectors not all the same size.\")\n end\nend\ncase size\nwhen 2\n Vector[-@buffer[1], @buffer[0]]\nwhen 3\n v = vs[0]\n Vector[(v[2] * @buffer[1]) - (v[1] * @buffer[2]), (v[0] * @buffer[2]) - (v[2] * @buffer[0]), (v[1] * @buffer[0]) - (v[0] * @buffer[1])]\nelse\nend\n"}},{"id":"distance_from(obj)-instance-method","html_id":"distance_from(obj)-instance-method","name":"distance_from","doc":"Gets this vector's distance from the argument, when considered\na point in space.","summary":"Gets this vector's distance from the argument, when considered a point in space.
","abstract":false,"args":[{"name":"obj","doc":null,"default_value":"","external_name":"obj","restriction":""}],"args_string":"(obj)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L615","def":{"name":"distance_from","args":[{"name":"obj","doc":null,"default_value":"","external_name":"obj","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if object.is_a?(Plane) || object.is_a?(Line)\n return object.distance_from(self)\nend\nv = elements.is_a?(Vector) ? elements.elements : elements\nif v.size == @elements.size\nelse\n return nil\nend\nsum = 0\npart = 0\neach_with_index do |x, i|\n part = x - v[i - 1]\n sum = sum + (part * part)\nend\nMath.sqrt(sum)\n"}},{"id":"divide(value)-instance-method","html_id":"divide(value)-instance-method","name":"divide","doc":"When the input is a number, this returns the result of dividing\nit to all vector elements. When it's a vector, the vectors\nwill be element-wise divided.","summary":"When the input is a number, this returns the result of dividing it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L497","def":{"name":"divide","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a / b\nend"}},{"id":"dot(other)-instance-method","html_id":"dot(other)-instance-method","name":"dot","doc":"Get the scalar (dot) product of this vector with `vector`.\n\n[https://en.wikipedia.org/wiki/Scalar_product](https://en.wikipedia.org/wiki/Scalar_product)","summary":"Get the scalar (dot) product of this vector with vector
.
Returns the ith
element of the vector.
Returns true if all vectors are linearly independent.
","abstract":false,"args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"args_string":"(*vs)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L388","def":{"name":"independent?","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":"vs.each do |v|\n if v.size == vs.first.size\n else\n raise(\"Dimension mismatch. Vectors not all the same size.\")\n end\nend\nif vs.size > sv.first.size\n return false\nend\nMatrix[*vs].rank.equal?(vs.count)\n"}},{"id":"lies_in(plane)-instance-method","html_id":"lies_in(plane)-instance-method","name":"lies_in","doc":"Returns true if the vector is a point on the given plane.","summary":"Returns true if the vector is a point on the given plane.
","abstract":false,"args":[{"name":"plane","doc":null,"default_value":"","external_name":"plane","restriction":""}],"args_string":"(plane)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L640","def":{"name":"lies_in","args":[{"name":"plane","doc":null,"default_value":"","external_name":"plane","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"plane.contains(self)"}},{"id":"lies_on(line)-instance-method","html_id":"lies_on(line)-instance-method","name":"lies_on","doc":"Returns true if the vector is a point on the given line","summary":"Returns true if the vector is a point on the given line
","abstract":false,"args":[{"name":"line","doc":null,"default_value":"","external_name":"line","restriction":""}],"args_string":"(line)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L635","def":{"name":"lies_on","args":[{"name":"line","doc":null,"default_value":"","external_name":"line","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"line.contains(self)"}},{"id":"log-instance-method","html_id":"log-instance-method","name":"log","doc":"Return a new `Vector` with the log of every item in `self`.","summary":"Return a new Vector
with the log of every item in self
.
Returns the magnitude/euclidian norm of this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L423","def":{"name":"magnitude","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sum = reduce(0.0) do |acc, e|\n acc = acc + (e * e)\nend\nMath.sqrt(sum)\n"}},{"id":"map(&block)-instance-method","html_id":"map(&block)-instance-method","name":"map","doc":"Invokes the given block for each element of `self`.","summary":"Invokes the given block for each element of self
.
Invokes the given block for each element of self
, replacing the element with the value returned by the block.
Optimized version of Enumerable#map_with_index
.
Like #map_with_index
, but mutates self
instead of allocating a new object.
Returns the (absolute) largest element in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L575","def":{"name":"max","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce do |acc, i|\n i.abs > acc.abs ? i : acc\nend"}},{"id":"max_index-instance-method","html_id":"max_index-instance-method","name":"max_index","doc":"Gets the index of the largest element in this vector.","summary":"Gets the index of the largest element in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L580","def":{"name":"max_index","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"idx = 0\neach_with_index do |e, i|\n idx = e.abs > self[idx].abs ? i : idx\nend\nidx\n"}},{"id":"multiply(value)-instance-method","html_id":"multiply(value)-instance-method","name":"multiply","doc":"When the input is a number, this returns the result of multiplying\nit to all vector elements. When it's a vector, the vectors\nwill be element-wise multiplied.","summary":"When the input is a number, this returns the result of multiplying it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L490","def":{"name":"multiply","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a * b\nend"}},{"id":"normalize-instance-method","html_id":"normalize-instance-method","name":"normalize","doc":"Returns a new vector created by normalizing this one\nto have a magnitude of `1`. If the vector is a zero\nvector, it will not be modified.","summary":"Returns a new vector created by normalizing this one to have a magnitude of 1
.
Returns whether the vectors are parallel to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L459","def":{"name":"parallel_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite.parallel_to?(self, vector)"}},{"id":"perpendicular_to?(vector)-instance-method","html_id":"perpendicular_to?(vector)-instance-method","name":"perpendicular_to?","doc":"Returns whether the vectors are perpendicular to each other.","summary":"Returns whether the vectors are perpendicular to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L469","def":{"name":"perpendicular_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite.perpendicular_to?(self, vector)"}},{"id":"pretty_print(pp):Nil-instance-method","html_id":"pretty_print(pp):Nil-instance-method","name":"pretty_print","doc":null,"summary":null,"abstract":false,"args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"args_string":"(pp) : Nil","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L740","def":{"name":"pretty_print","args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"pp.list(\"Vector{\", self, \"}\")"}},{"id":"product-instance-method","html_id":"product-instance-method","name":"product","doc":"Get the product of all elements in this vector.","summary":"Get the product of all elements in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L562","def":{"name":"product","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce do |acc, v|\n acc = acc * v\nend"}},{"id":"push(value:Float64)-instance-method","html_id":"push(value:Float64)-instance-method","name":"push","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Float64"}],"args_string":"(value : Float64)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L644","def":{"name":"push","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"check_needs_resize\n@buffer[@size] = value\n@size = @size + 1\nself\n"}},{"id":"push(*values:Float64)-instance-method","html_id":"push(*values:Float64)-instance-method","name":"push","doc":null,"summary":null,"abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Float64"}],"args_string":"(*values : Float64)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L651","def":{"name":"push","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Float64"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new_size = @size + values.size\nif new_size > @capacity\n resize_to_capacity(Math.pw2ceil(new_size))\nend\nvalues.each_with_index do |value, i|\n @buffer[@size + i] = value\nend\n@size = new_size\nself\n"}},{"id":"reflection_in(object)-instance-method","html_id":"reflection_in(object)-instance-method","name":"reflection_in","doc":"Returns the result of reflecting the point in the given `object`\n(point, line, or plane).","summary":"Returns the result of reflecting the point in the given object
(point, line, or plane).
Rotates the vector about the given object
.
Gets the result of rounding the elements of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L598","def":{"name":"round","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |x|\n x.round\nend"}},{"id":"set_elements(elements)-instance-method","html_id":"set_elements(elements)-instance-method","name":"set_elements","doc":null,"summary":null,"abstract":false,"args":[{"name":"elements","doc":null,"default_value":"","external_name":"elements","restriction":""}],"args_string":"(elements)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L712","def":{"name":"set_elements","args":[{"name":"elements","doc":null,"default_value":"","external_name":"elements","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements = elements.is_a?(Vector) ? elements.elements : elements\nself\n"}},{"id":"sigmoid-instance-method","html_id":"sigmoid-instance-method","name":"sigmoid","doc":"Sums the numbers in the vector and returns a sigmoid value\nacross the whole vector.","summary":"Sums the numbers in the vector and returns a sigmoid value across the whole vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L693","def":{"name":"sigmoid","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"LinearAlgebra.sigmoid(sum)"}},{"id":"similarity(other)-instance-method","html_id":"similarity(other)-instance-method","name":"similarity","doc":"Compute the cosine similarity between this vector and another.","summary":"Compute the cosine similarity between this vector and another.
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L454","def":{"name":"similarity","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":"Apatite.similarity(self, other)"}},{"id":"size:Int32-instance-method","html_id":"size:Int32-instance-method","name":"size","doc":"Returns the number of elements in the vector","summary":"Returns the number of elements in the vector
","abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L24","def":{"name":"size","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@size"}},{"id":"snap_to(value)-instance-method","html_id":"snap_to(value)-instance-method","name":"snap_to","doc":"Returns a copy of the vector with elements set to `value` if\nthey differ from it by less than `Apetite.precision`","summary":"Returns a copy of the vector with elements set to value
if they differ from it by less than Apetite.precision
When the input is a number, this returns the result of subtracting it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L483","def":{"name":"subtract","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a - b\nend"}},{"id":"sum-instance-method","html_id":"sum-instance-method","name":"sum","doc":"Returns the sum of all elements in the vector.","summary":"Returns the sum of all elements in the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L502","def":{"name":"sum","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce(0) do |acc, i|\n acc + i\nend"}},{"id":"to_3d-instance-method","html_id":"to_3d-instance-method","name":"to_3d","doc":"Utility to make sure vectors are 3D. If they are 2D, a zero\nz-component is added.","summary":"Utility to make sure vectors are 3D.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L699","def":{"name":"to_3d","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = dup\ncase v.elements.size\nwhen 3\n break\nwhen 2\n v.elements.push(0)\nelse\n return nil\nend\nreturn v\n"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L730","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array(Float64).new(size) do |i|\n self[i]\nend"}},{"id":"to_diagonal_matrix-instance-method","html_id":"to_diagonal_matrix-instance-method","name":"to_diagonal_matrix","doc":"Returns a diagonal `Matrix` with the vectors elements as its\ndiagonal elements.","summary":"Returns a diagonal Matrix
with the vectors elements as its diagonal elements.
Returns a new vector created by normalizing this one to have a magnitude of 1
.
Returns a pointer to the internal buffer where self
's elements are stored.
Returns a vector containing only the first n
elements.
Transpose this vector into a 1xn Matrix
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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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 67791fc..0d3baee 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\nTODO: Write usage instructions here, but first write the library...\n\n## Roadmap\n\n- [ ] Apetite\n\t- [ ] Vector Math\n\t\t- [ ] Matrix\n\t\t- [ ] NDArray\n\t\t- [x] Vector\n\t\t- [ ] Line\n\t\t- [ ] Plane\n\t\t- [ ] Polygon\n\t\t- [ ] LinkedList\n\t\n\n\n## Contributing\n\n1. Fork it (Cartesian unit vector I
"},{"id":"J","name":"J","value":"Vector::J","doc":"Cartesian unit vector J\n\n`Vector{0.0, 1.0, 0.0}`","summary":"Cartesian unit vector J
"},{"id":"K","name":"K","value":"Vector::K","doc":"Cartesian unit vector K\n\n`Vector{0.0, 0.0, 1.0}`","summary":"Cartesian unit vector K
"},{"id":"VERSION","name":"VERSION","value":"\"0.1.0\"","doc":null,"summary":null}],"included_modules":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"}],"extended_modules":[{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Apatite is a fundimental package for scientific computing in Crystal. If that\nsounds like a modified version of the first line from the NumPy homepage,\nthat's because it is. Apatite has (ok, will have) all of the goodness\nof NumPy sitting atop the blazing speed and beautiful syntax\nof Crystal.","summary":"Apatite is a fundimental package for scientific computing in Crystal.
","class_methods":[],"constructors":[],"instance_methods":[{"id":"as_vector(input:Indexable)-instance-method","html_id":"as_vector(input:Indexable)-instance-method","name":"as_vector","doc":"Creates a new vector from the given `input`. Input can be any\n`Indexable` type.","summary":"Creates a new vector from the given input
.
Creates a standard basis-n vector of the given size
and index
.
Creates a matrix where the diagonal elements are composed of values
.
Returns a new empty Vector
Creates a new empty matrix with the given row_count
and column_count
.
Creates a new diagonal matrix of size n
with ones in the diagonal and zeros elsewhere.
Returns a new vector of size n
filled with i
Creates a n x n
identity matrix.
Returns a new vector filled with n
ones.
Creates a new vector of size n
filled with random numbers.
Creates a single-row matrix where the values of that row are as given in row
.
Creates an n
by n
diagonal matrix where each diagonal element is value.
Creates a new vector of size n
, and invokes the block once for each index of self
, assigning the block's value in that index.
Returns a new vector filled with n
zeros.
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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra.cr#L14","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra.cr#L22","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/Matrix","path":"Apatite/LinearAlgebra/Matrix.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix","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.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.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":[{"id":"[](*rows)-class-method","html_id":"[](*rows)-class-method","name":"[]","doc":"Creates a matrix where each argument is a row.","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L22","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)"}},{"id":"build(row_count,column_count=row_count,&block)-class-method","html_id":"build(row_count,column_count=row_count,&block)-class-method","name":"build","doc":"Creates a matrix of size `row_count x column_count`. It fills the values by calling\nthe given block, passing the current row and column.","summary":"Creates a matrix of size row_count x column_count
.
Creates a single-column matrix where the values of that column are as given in column.
","abstract":false,"args":[{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(column)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L39","def":{"name":"col_vector","args":[{"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":"Matrix.new([column].transpose, 1)"}},{"id":"columns(columns)-class-method","html_id":"columns(columns)-class-method","name":"columns","doc":"Creates a matrix using `columns` as an array of column vectors.","summary":"Creates a matrix using .columns
as an array of column vectors.
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
.
Creates a new diagonal matrix of size n
with ones in the diagonal and zeros elsewhere.
TODO
","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L103","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":""}},{"id":"identity(n)-class-method","html_id":"identity(n)-class-method","name":"identity","doc":"Creates a `n x n` identity matrix.","summary":"Creates a n x 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":""}],"args_string":"(rows)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L117","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size = rows[0]? ? rows[0].size : 0\nrows.each do |row|\n if row.size == size\n else\n raise(\"Dimension mismatch: row size differs (#{row.size} should be #{size})\")\n end\nend\nMatrix.new(rows, size)\n"}},{"id":"scalar(n,value)-class-method","html_id":"scalar(n,value)-class-method","name":"scalar","doc":"Creates an `n` by `n` diagonal matrix where each diagonal element is value.","summary":"Creates an n
by n
diagonal matrix where each diagonal element is value.
TODO
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"args_string":"(x, y)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L131","def":{"name":"vstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"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.","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L135","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.new(row_count) do\n Vector.new(column_count)\nend\nMatrix.new(rows, column_count)\n"}}],"constructors":[{"id":"new(rows,column_count:Int32?=nil)-class-method","html_id":"new(rows,column_count:Int32?=nil)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""},{"name":"column_count","doc":null,"default_value":"nil","external_name":"column_count","restriction":"Int32 | ::Nil"}],"args_string":"(rows, column_count : Int32? = nil)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L15","def":{"name":"new","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""},{"name":"column_count","doc":null,"default_value":"nil","external_name":"column_count","restriction":"Int32 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(rows, column_count)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L140","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n (0...column_count).reduce(0.0) do |vij, k|\n vij + (self[i, k] * other[k, j])\n end\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"id":"*(int:Int)-instance-method","html_id":"*(int:Int)-instance-method","name":"*","doc":null,"summary":null,"abstract":false,"args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":"Int"}],"args_string":"(int : Int)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L154","def":{"name":"*","args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = self.rows.map do |row|\n row.map do |e|\n e * int\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"*(ind:Indexable)-instance-method","html_id":"*(ind:Indexable)-instance-method","name":"*","doc":null,"summary":null,"abstract":false,"args":[{"name":"ind","doc":null,"default_value":"","external_name":"ind","restriction":"Indexable"}],"args_string":"(ind : Indexable)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L161","def":{"name":"*","args":[{"name":"ind","doc":null,"default_value":"","external_name":"ind","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m = column_vector\nr = self * m\nr.column(0)\n"}},{"id":"**(int)-instance-method","html_id":"**(int)-instance-method","name":"**","doc":null,"summary":null,"abstract":false,"args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":""}],"args_string":"(int)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L167","def":{"name":"**","args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if int >= 1\nelse\n raise(\"Number can not the less than 1\")\nend\nmat = self\n(int - 1).times do\n mat = mat * self\nend\nmat\n"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L176","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n self[i, j] + other[i, j]\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"id":"+(vec:Indexable)-instance-method","html_id":"+(vec:Indexable)-instance-method","name":"+","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L188","def":{"name":"+","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"vec = vec.is_a?(Vector) ? vec : Vector.create(vec)\nself + (column_vector(vec))\n"}},{"id":"-(vec:Indexable)-instance-method","html_id":"-(vec:Indexable)-instance-method","name":"-","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L205","def":{"name":"-","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"vec = vec.is_a?(Vector) ? vec : Vector.create(vec)\nself + (column_vector(vec))\n"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L193","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n self[i, j] - other[i, j]\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L210","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":"self * other.inverse"}},{"id":"/(vec:Indexable)-instance-method","html_id":"/(vec:Indexable)-instance-method","name":"/","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L214","def":{"name":"/","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = self.rows.map do |row|\n row.map do |e|\n e / other\n end\nend\nreturn new_matrix(rows, column_count)\n"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L221","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":"if (Matrix === other) && (column_count == other.column_count)\nelse\n return false\nend\nrows == other.rows\n"}},{"id":"[](row:Int,col:Int)-instance-method","html_id":"[](row:Int,col:Int)-instance-method","name":"[]","doc":"Returns element `(row, col)` of the matrix. Throws error on index error.","summary":"Returns element (row, col)
of the matrix.
Returns element (row, col)
of the matrix, or nil if the index is not found.
Returns the adjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L239","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(\"Dimention mismatch: `Matrix#adjugate` requires a square matrix.\")\nend\nMatrix.build(row_count, column_count) do |row, column|\n cofactor(column, row)\nend\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 the first minor by (-1)**(row + column)","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L247","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(\"Dimention mismatch: `Matrix#cofactor` requires a square matrix.\")\nend\ndet_of_minor = (first_minor(row, column)).determinant\ndet_of_minor * ((-1.0) ** (row + column))\n"}},{"id":"column(j,&block)-instance-method","html_id":"column(j,&block)-instance-method","name":"column","doc":"Iterates over the specified column in the matrix, returning the Vector's items.","summary":"Iterates over the specified column in the matrix, returning the Vector's items.
","abstract":false,"args":[{"name":"j","doc":null,"default_value":"","external_name":"j","restriction":""}],"args_string":"(j, &block)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L274","def":{"name":"column","args":[{"name":"j","doc":null,"default_value":"","external_name":"j","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"if j >= column_count || j < (-column_count)\n return self\nend\nrow_count.times do |i|\n yield rows[i][j]\nend\nself\n"}},{"id":"column(j)-instance-method","html_id":"column(j)-instance-method","name":"column","doc":"Returns column vector number `j` of the matrix as a `Vector` (starting at 0 like an array).","summary":"Returns column vector number j
of the matrix as a Vector
(starting at 0 like an array).
Returns column vector number j
of the matrix as a Vector
(starting at 0 like an array).
Returns an array of the column vectors of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L283","def":{"name":"column_vectors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array(Vector).new(column_count) do |i|\n column(i)\nend"}},{"id":"determinant-instance-method","html_id":"determinant-instance-method","name":"determinant","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L354","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(\"Dimention mismatch: `Matrix#determinant` requires a square matrix.\")\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":"first_minor(row,column)-instance-method","html_id":"first_minor(row,column)-instance-method","name":"first_minor","doc":null,"summary":null,"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L429","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.map(&.to_a)\narrays.delete_at(row)\narrays.each do |array|\n array.delete_at(column)\nend\nMatrix.new(arrays, column_count - 1)\n"}},{"id":"inverse-instance-method","html_id":"inverse-instance-method","name":"inverse","doc":"Returns the inverse of the matrix.","summary":"Returns the inverse of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L304","def":{"name":"inverse","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n if square?\n else\n raise(\"Dimention mismatch: `Matrix#inverse` requires a square matrix.\")\n end\nend\n(Matrix.identity(row_count)).inverse_from(self)\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.","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L450","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(\"Dimention mismatch: `Matrix#determinant` requires a square matrix.\")\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":"pretty_print(pp):Nil-instance-method","html_id":"pretty_print(pp):Nil-instance-method","name":"pretty_print","doc":null,"summary":null,"abstract":false,"args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"args_string":"(pp) : Nil","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L516","def":{"name":"pretty_print","args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"pp.list(\"[\", self, \"]\") do |vec|\n pp.group do\n vec.to_a.pretty_print(pp)\n end\nend"}},{"id":"row(i,&block)-instance-method","html_id":"row(i,&block)-instance-method","name":"row","doc":null,"summary":null,"abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i, &block)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L475","def":{"name":"row","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"return_type":"","visibility":"Public","body":"(@rows.fetch(i) do\n return self\nend).each(&block)\nself\n"}},{"id":"row(i)-instance-method","html_id":"row(i)-instance-method","name":"row","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L480","def":{"name":"row","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":"Vector.create(rows.fetch(i) do\n [] of Float64\nend)"}},{"id":"row_count:Int32-instance-method","html_id":"row_count:Int32-instance-method","name":"row_count","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L13","def":{"name":"row_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@row_count"}},{"id":"rows-instance-method","html_id":"rows-instance-method","name":"rows","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L484","def":{"name":"rows","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = [] of Vector\nrow_count.times do |i|\n rows << self[i - 1]\nend\nrows\n"}},{"id":"square?-instance-method","html_id":"square?-instance-method","name":"square?","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L492","def":{"name":"square?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"row_count == column_count"}},{"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L502","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 << (map do |row|\n (\"{\" + (row.to_a.map do |e|\n e.to_s\n end.join(\", \"))) + \"}\"\n end.join(\", \"))\n io << \"]\"\nend"}},{"id":"transpose-instance-method","html_id":"transpose-instance-method","name":"transpose","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L496","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 Matrix.empty(column_count, 0)\nend\ntransposed = rows.map do |v|\n v.to_a\nend.transpose\nMatrix.new(transposed, row_count)\n"}},{"id":"unsafe_fetch(index:Int)-instance-method","html_id":"unsafe_fetch(index:Int)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"}],"args_string":"(index : Int)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/matrix.cr#L525","def":{"name":"unsafe_fetch","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@buffer[index]"}}],"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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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","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/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/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"I","name":"I","value":"Vector.create([1.0, 0.0, 0.0])","doc":"Cartesian unit vector I","summary":"Cartesian unit vector I
"},{"id":"J","name":"J","value":"Vector.create([0.0, 1.0, 0.0])","doc":"Cartesian unit vector J","summary":"Cartesian unit vector J
"},{"id":"K","name":"K","value":"Vector.create([0.0, 0.0, 1.0])","doc":"Cartesian unit vector K","summary":"Cartesian unit vector K
"}],"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
Returns a standard basis n-vector.
","abstract":false,"args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""},{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":""}],"args_string":"(size, index)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L138","def":{"name":"basis","args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""},{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size < 1\n raise(ArgumentError.new(\"invalid size (#{size} for 1..)\"))\nend\nif 0 <= index && index < size\nelse\n raise(ArgumentError.new(\"invalid index (#{index} for 0...#{size})\"))\nend\nvec = Vector.new(size, 0.0)\nvec[index] = 1.0\nvec\n"}},{"id":"create(elements:Indexable(Number))-class-method","html_id":"create(elements:Indexable(Number))-class-method","name":"create","doc":"Creates a new `Vector` from the elements of another `Indexable`\ncollection.\n\n```\nVector.create([1, 2, 3]) # Vector{1.0, 2.0, 3.0}\n```","summary":"Creates a new Vector
from the elements of another Indexable
collection.
Create a new vector of size n
filled with ones.
Creates a new Vector
of size n
filled with random numbers.
Create a new vector of size n
filled with zeros.
Creates a new Vector
, allocating an internal buffer with the given capacity, and yielding that buffer.
Creates a new Vector
of the given size filled with the same value in each position.
Creates a new empty Vector
backed by a buffer that is initially initial_capacity
big.
Create a new empty Vector
.
Creates a new Vector
of the given size and invokes the given block once for each index of self
, assigning the block's value in that index.
Alias for #push
Combined comparison 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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L339","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":"min_size = Math.min(size, other.size)\n0.upto(min_size - 1) do |i|\n n = @buffer[i] <=> other.to_unsafe[i]\n if n != 0\n return n\n end\nend\nsize <=> other.size\n"}},{"id":"==(other:Vector)-instance-method","html_id":"==(other:Vector)-instance-method","name":"==","doc":null,"summary":null,"abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"args_string":"(other : Vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L353","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"equals?(other) do |x, y|\n x == y\nend"}},{"id":"[](start:Int,count:Int)-instance-method","html_id":"[](start:Int,count:Int)-instance-method","name":"[]","doc":"Returns count or less (if there aren't enough) elements starting at the\ngiven start index.\n\nNegative indices count backward from the end of the vector (-1 is the last\nelement). Additionally, an empty vector is returned when the starting index\nfor an element range is at the end of the vector.\n\nRaises `IndexError` if the starting index is out of range.\n\n```\nv = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nv[1, 3] # => Vector{2.0, 3.0, 4.0}\nv[6, 10] # raise IndexError\n```","summary":"Returns count or less (if there aren't enough) elements starting at the given start index.
","abstract":false,"args":[{"name":"start","doc":null,"default_value":"","external_name":"start","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"}],"args_string":"(start : Int, count : Int)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L191","def":{"name":"[]","args":[{"name":"start","doc":null,"default_value":"","external_name":"start","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nif start == size\n return Vector.new\nend\nif start < 0\n start = start + size\nend\nif 0 <= start && start <= size\nelse\n raise(IndexError.new)\nend\nif count == 0\n return Vector.new\nend\ncount = Math.min(count, size - start)\nVector.build(count) do |buffer|\n buffer.copy_from(@buffer + start, count)\n count\nend\n"}},{"id":"[](range:Range(Int,Int))-instance-method","html_id":"[](range:Range(Int,Int))-instance-method","name":"[]","doc":"Returns all elements that are within the given range.\n\nNegative indices count backward from the end of the vector (-1 is the last\nelement). Additionally, an empty vector is returned when the starting index\nfor an element range is at the end of the vector.\n\nRaises `IndexError` if the starting index is out of range.\n\n```\nv = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nv[1..3] # => Vector{2.0, 3.0, 4.0}\nv[6..10] # raise IndexError\n```","summary":"Returns all elements that are within the given range.
","abstract":false,"args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"}],"args_string":"(range : Range(Int, Int))","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L173","def":{"name":"[]","args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self[*Indexable.range_to_index_and_count(range, size)]"}},{"id":"[]=(index:Int,count:Int,values:Vector)-instance-method","html_id":"[]=(index:Int,count:Int,values:Vector)-instance-method","name":"[]=","doc":"Replaces a subrange with the elements of the given vector.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = Vector{6.0, 7.0, 8.0}\nvec # = Vector{1.0, 6.0, 7.0, 8.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = Vector{6.0, 7.0}\nvec # = Vector{1.0, 6.0, 7.0, 5.0}\n```","summary":"Replaces a subrange with the elements of the given vector.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Vector"}],"args_string":"(index : Int, count : Int, values : Vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L297","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nindex = check_index_out_of_bounds(index)\ncount = ((index + count) <= size) ? count : size - index\ndiff = values.size - count\nif diff == 0\n (@buffer + index).copy_from(values.to_unsafe, values.size)\nelse\n if diff < 0\n diff = -diff\n (@buffer + index).copy_from(values.to_unsafe, values.size)\n ((@buffer + index) + values.size).move_from((@buffer + index) + count, (size - index) - count)\n ((@buffer + @size) - diff).clear(diff)\n @size = @size - diff\n else\n resize_to_capacity(Math.pw2ceil(@size + diff))\n ((@buffer + index) + values.size).move_from((@buffer + index) + count, (size - index) - count)\n (@buffer + index).copy_from(values.to_unsafe, values.size)\n @size = @size + diff\n end\nend\nvalues\n"}},{"id":"[]=(index:Int,count:Int,value)-instance-method","html_id":"[]=(index:Int,count:Int,value)-instance-method","name":"[]=","doc":"Replaces a subrange with a single value. All elements in the range\n`index...index+count` are removed and replaced by a single element\n*value*.\n\nIf *count* is zero, *value* is inserted at *index*.\n\nNegative values of *index* count from the end of the vector.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = 6.0\nvec # => Vector{1.0, 6.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 0] = 6.0\nvec # => Vector{1.0, 6.0, 2.0, 3.0, 4.0, 5.0}\n```","summary":"Replaces a subrange with a single value.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(index : Int, count : Int, value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L248","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nvalue = value.to_f64\nindex = check_index_out_of_bounds(index)\ncount = ((index + count) <= size) ? count : size - index\ncase count\nwhen 0\n insert(index, value)\nwhen 1\n @buffer[index] = value\nelse\n diff = count - 1\n ((@buffer + index) + 1).move_from((@buffer + index) + count, (size - index) - count)\n ((@buffer + @size) - diff).clear(diff)\n @buffer[index] = value\n @size = @size - diff\nend\nvalue\n"}},{"id":"[]=(index:Int,value)-instance-method","html_id":"[]=(index:Int,value)-instance-method","name":"[]=","doc":"Sets the given value at the given index.\n\nNegative indices can be used to start counting from the end of the array.\nRaises `IndexError` if trying to set an element outside the array's range.\n\n```\nvec = Vector{1.0, 2.0, 3.0}\nvec[0] = 5.0\np vec # => Vec{5.0, 2.0, 3.0}\n\nvec[3] = 5.0 # raises IndexError\n```","summary":"Sets the given value at the given index.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(index : Int, value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L226","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"index = check_index_out_of_bounds(index)\n@buffer[index] = value.to_f64\n"}},{"id":"[]=(range:Range(Int,Int),value)-instance-method","html_id":"[]=(range:Range(Int,Int),value)-instance-method","name":"[]=","doc":"Replaces a subrange with a single value.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1..3] = 6.0\nvec # = Vector{1.0, 6.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1...1] = 6\nvec # = Vector{1.0, 6.0, 2.0, 3.0, 4.0, 5.0}\n```","summary":"Replaces a subrange with a single value.
","abstract":false,"args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(range : Range(Int, Int), value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L282","def":{"name":"[]=","args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self[*Indexable.range_to_index_and_count(range, size)] = value.to_f64"}},{"id":"add(value)-instance-method","html_id":"add(value)-instance-method","name":"add","doc":"When the input is a number, this returns the result of adding\nit to all vector elements. When it's a vector, the vectors\nwill be added together.","summary":"When the input is a number, this returns the result of adding it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L488","def":{"name":"add","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a + b\nend"}},{"id":"angle_from(vector)-instance-method","html_id":"angle_from(vector)-instance-method","name":"angle_from","doc":"Returns the angle between this vector and another in radians.\nIf the vectors are mirrored across their axes this will return `nil`.","summary":"Returns the angle between this vector and another in radians.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L440","def":{"name":"angle_from","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = vector.is_a?(Vector) ? vector : Vector.create(vector)\nif size == v.size\nelse\n raise(\"Cannot compute the angle between vectors with different dimensionality\")\nend\ndot = 0_f64\nmod1 = 0_f64\nmod2 = 0_f64\n(zip(vector)).each do |x, v|\n dot = dot + (x * v)\n mod1 = mod1 + (x * x)\n mod2 = mod2 + (v * v)\nend\nmod1 = Math.sqrt(mod1)\nmod2 = Math.sqrt(mod2)\nif (mod2 * mod2) == 0\n return 0.0\nend\ntheta = (dot / (mod1 * mod2)).clamp(-1, 1)\nMath.acos(theta)\n"}},{"id":"antiparallel_to?(vector)-instance-method","html_id":"antiparallel_to?(vector)-instance-method","name":"antiparallel_to?","doc":"Returns whether the vectors are antiparallel to each other.","summary":"Returns whether the vectors are antiparallel to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L475","def":{"name":"antiparallel_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"angle = angle_from(vector)\n(angle - Math::PI).abs <= Apatite.precision\n"}},{"id":"augment(elements)-instance-method","html_id":"augment(elements)-instance-method","name":"augment","doc":"Returns a new vector with the provided `elements` concatenated\non the end.","summary":"Returns a new vector with the provided elements
concatenated on the end.
Returns a new vector with the first n
elements removed from the beginning.
Removes all elements from self.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L782","def":{"name":"clear","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@buffer.clear(@size)\n@size = 0\nself\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L374","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Vector.create(@elements.clone)"}},{"id":"concat(other:Vector)-instance-method","html_id":"concat(other:Vector)-instance-method","name":"concat","doc":null,"summary":null,"abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"args_string":"(other : Vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L731","def":{"name":"concat","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"other_size = other.size\nnew_size = size + other_size\nif new_size > @capacity\n resize_to_capacity(Math.pw2ceil(new_size))\nend\n(@buffer + @size).copy_from(other.to_unsafe, other_size)\n@size = new_size\nself\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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L601","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(*vs)-instance-method","html_id":"cross(*vs)-instance-method","name":"cross","doc":"Returns the cross product of this vector with the others.\n\n```\nv1 = Vector{1.0, 0.0, 0.0}\nv2 = Vector{0.0, 1.0, 0.0}\nv1.cross(v2) => Vector{0.0, 0.0, 1.0}\n```","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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L518","def":{"name":"cross","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(\"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(\"Dimension mismatch. Vectors not all the same size.\")\n end\nend\ncase size\nwhen 2\n Vector[-@buffer[1], @buffer[0]]\nwhen 3\n v = vs[0]\n Vector[(v[2] * @buffer[1]) - (v[1] * @buffer[2]), (v[0] * @buffer[2]) - (v[2] * @buffer[0]), (v[1] * @buffer[0]) - (v[0] * @buffer[1])]\nelse\nend\n"}},{"id":"distance_from(obj)-instance-method","html_id":"distance_from(obj)-instance-method","name":"distance_from","doc":"Gets this vector's distance from the argument, when considered\na point in space.","summary":"Gets this vector's distance from the argument, when considered a point in space.
","abstract":false,"args":[{"name":"obj","doc":null,"default_value":"","external_name":"obj","restriction":""}],"args_string":"(obj)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L629","def":{"name":"distance_from","args":[{"name":"obj","doc":null,"default_value":"","external_name":"obj","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if object.is_a?(Plane) || object.is_a?(Line)\n return object.distance_from(self)\nend\nv = elements.is_a?(Vector) ? elements.elements : elements\nif v.size == @elements.size\nelse\n return nil\nend\nsum = 0\npart = 0\neach_with_index do |x, i|\n part = x - v[i - 1]\n sum = sum + (part * part)\nend\nMath.sqrt(sum)\n"}},{"id":"dot(other)-instance-method","html_id":"dot(other)-instance-method","name":"dot","doc":"Get the scalar (dot) product of this vector with `vector`.\n\n[https://en.wikipedia.org/wiki/Scalar_product](https://en.wikipedia.org/wiki/Scalar_product)","summary":"Get the scalar (dot) product of this vector with vector
.
Returns the ith
element of the vector.
Returns true if all vectors are linearly independent.
","abstract":false,"args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"args_string":"(*vs)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L384","def":{"name":"independent?","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":"vs.each do |v|\n if v.size == vs.first.size\n else\n raise(\"Dimension mismatch. Vectors not all the same size.\")\n end\nend\nif vs.size > sv.first.size\n return false\nend\nMatrix[*vs].rank.equal?(vs.count)\n"}},{"id":"lies_in(plane)-instance-method","html_id":"lies_in(plane)-instance-method","name":"lies_in","doc":"Returns true if the vector is a point on the given plane.","summary":"Returns true if the vector is a point on the given plane.
","abstract":false,"args":[{"name":"plane","doc":null,"default_value":"","external_name":"plane","restriction":""}],"args_string":"(plane)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L654","def":{"name":"lies_in","args":[{"name":"plane","doc":null,"default_value":"","external_name":"plane","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"plane.contains(self)"}},{"id":"lies_on(line)-instance-method","html_id":"lies_on(line)-instance-method","name":"lies_on","doc":"Returns true if the vector is a point on the given line","summary":"Returns true if the vector is a point on the given line
","abstract":false,"args":[{"name":"line","doc":null,"default_value":"","external_name":"line","restriction":""}],"args_string":"(line)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L649","def":{"name":"lies_on","args":[{"name":"line","doc":null,"default_value":"","external_name":"line","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"line.contains(self)"}},{"id":"log-instance-method","html_id":"log-instance-method","name":"log","doc":"Return a new `Vector` with the log of every item in `self`.","summary":"Return a new Vector
with the log of every item in self
.
Returns the magnitude/euclidian norm of this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L419","def":{"name":"magnitude","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sum = reduce(0.0) do |acc, e|\n acc = acc + (e * e)\nend\nMath.sqrt(sum)\n"}},{"id":"map(&block)-instance-method","html_id":"map(&block)-instance-method","name":"map","doc":"Invokes the given block for each element of `self`.","summary":"Invokes the given block for each element of self
.
Invokes the given block for each element of self
, replacing the element with the value returned by the block.
Optimized version of Enumerable#map_with_index
.
Like #map_with_index
, but mutates self
instead of allocating a new object.
Returns the (absolute) largest element in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L589","def":{"name":"max","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce do |acc, i|\n i.abs > acc.abs ? i : acc\nend"}},{"id":"max_index-instance-method","html_id":"max_index-instance-method","name":"max_index","doc":"Gets the index of the largest element in this vector.","summary":"Gets the index of the largest element in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L594","def":{"name":"max_index","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"idx = 0\neach_with_index do |e, i|\n idx = e.abs > self[idx].abs ? i : idx\nend\nidx\n"}},{"id":"multiply(value)-instance-method","html_id":"multiply(value)-instance-method","name":"multiply","doc":"When the input is a number, this returns the result of multiplying\nit to all vector elements. When it's a vector, the vectors\nwill be element-wise multiplied.","summary":"When the input is a number, this returns the result of multiplying it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L502","def":{"name":"multiply","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a * b\nend"}},{"id":"parallel_to?(vector)-instance-method","html_id":"parallel_to?(vector)-instance-method","name":"parallel_to?","doc":"Returns whether the vectors are parallel to each other.","summary":"Returns whether the vectors are parallel to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L469","def":{"name":"parallel_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"angle = angle_from(vector)\nangle <= Apatite.precision\n"}},{"id":"perpendicular_to?(vector)-instance-method","html_id":"perpendicular_to?(vector)-instance-method","name":"perpendicular_to?","doc":"Returns whether the vectors are perpendicular to each other.","summary":"Returns whether the vectors are perpendicular to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L481","def":{"name":"perpendicular_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(dot(vector)).abs <= Apatite.precision"}},{"id":"pretty_print(pp):Nil-instance-method","html_id":"pretty_print(pp):Nil-instance-method","name":"pretty_print","doc":null,"summary":null,"abstract":false,"args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"args_string":"(pp) : Nil","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L754","def":{"name":"pretty_print","args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"pp.list(\"Vector{\", self, \"}\")"}},{"id":"product-instance-method","html_id":"product-instance-method","name":"product","doc":"Get the product of all elements in this vector.","summary":"Get the product of all elements in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L567","def":{"name":"product","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce do |acc, v|\n acc = acc * v\nend"}},{"id":"push(*values:Float64)-instance-method","html_id":"push(*values:Float64)-instance-method","name":"push","doc":null,"summary":null,"abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Float64"}],"args_string":"(*values : Float64)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L665","def":{"name":"push","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Float64"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new_size = @size + values.size\nif new_size > @capacity\n resize_to_capacity(Math.pw2ceil(new_size))\nend\nvalues.each_with_index do |value, i|\n @buffer[@size + i] = value\nend\n@size = new_size\nself\n"}},{"id":"push(value:Float64)-instance-method","html_id":"push(value:Float64)-instance-method","name":"push","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Float64"}],"args_string":"(value : Float64)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L658","def":{"name":"push","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"check_needs_resize\n@buffer[@size] = value\n@size = @size + 1\nself\n"}},{"id":"reflection_in(object)-instance-method","html_id":"reflection_in(object)-instance-method","name":"reflection_in","doc":"Returns the result of reflecting the point in the given `object`\n(point, line, or plane).","summary":"Returns the result of reflecting the point in the given object
(point, line, or plane).
Rotates the vector about the given object
.
Gets the result of rounding the elements of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L612","def":{"name":"round","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |x|\n x.round\nend"}},{"id":"set_elements(elements)-instance-method","html_id":"set_elements(elements)-instance-method","name":"set_elements","doc":null,"summary":null,"abstract":false,"args":[{"name":"elements","doc":null,"default_value":"","external_name":"elements","restriction":""}],"args_string":"(elements)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L726","def":{"name":"set_elements","args":[{"name":"elements","doc":null,"default_value":"","external_name":"elements","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements = elements.is_a?(Vector) ? elements.elements : elements\nself\n"}},{"id":"sigmoid-instance-method","html_id":"sigmoid-instance-method","name":"sigmoid","doc":"Sums the numbers in the vector and returns a sigmoid value\nacross the whole vector.","summary":"Sums the numbers in the vector and returns a sigmoid value across the whole vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L707","def":{"name":"sigmoid","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"LinearAlgebra.sigmoid(sum)"}},{"id":"size:Int32-instance-method","html_id":"size:Int32-instance-method","name":"size","doc":"Returns the number of elements in the vector","summary":"Returns the number of elements in the vector
","abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L24","def":{"name":"size","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@size"}},{"id":"snap_to(value)-instance-method","html_id":"snap_to(value)-instance-method","name":"snap_to","doc":"Returns a copy of the vector with elements set to `value` if\nthey differ from it by less than `Apetite.precision`","summary":"Returns a copy of the vector with elements set to value
if they differ from it by less than Apetite.precision
When the input is a number, this returns the result of subtracting it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L495","def":{"name":"subtract","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a - b\nend"}},{"id":"sum-instance-method","html_id":"sum-instance-method","name":"sum","doc":"Returns the sum of all elements in the vector.","summary":"Returns the sum of all elements in the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L507","def":{"name":"sum","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce(0) do |acc, i|\n acc + i\nend"}},{"id":"to_3d-instance-method","html_id":"to_3d-instance-method","name":"to_3d","doc":"Utility to make sure vectors are 3D. If they are 2D, a zero\nz-component is added.","summary":"Utility to make sure vectors are 3D.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L713","def":{"name":"to_3d","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = dup\ncase v.elements.size\nwhen 3\n break\nwhen 2\n v.elements.push(0)\nelse\n return nil\nend\nreturn v\n"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/linear_algebra/vector.cr#L744","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array(Float64).new(size) do |i|\n self[i]\nend"}},{"id":"to_diagonal_matrix-instance-method","html_id":"to_diagonal_matrix-instance-method","name":"to_diagonal_matrix","doc":"Returns a diagonal `Matrix` with the vectors elements as its\ndiagonal elements.","summary":"Returns a diagonal Matrix
with the vectors elements as its diagonal elements.
Returns a new vector created by normalizing this one to have a magnitude of 1
.
Returns a pointer to the internal buffer where self
's elements are stored.
Returns a vector containing only the first n
elements.
Transpose this vector into a 1xn Matrix
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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/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/49a30afcc07bc5354f335c6a6fb5244ed514b63b/src/apatite/core_ext/array.cr#L24","def":{"name":"to_vec","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite::Vector.create(self)"}}],"macros":[],"types":[]}]}}) \ No newline at end of file +crystal_doc_search_index_callback({"repository_name":"github.com/watzon/apatite","body":"# Apatite\n\nApatite is meant to be a collecion of mathmatical and scientific computing algorithms for the Crystal programming language. I don't expect it to ever reach the level of completeness as numpy, but hopefully it can save some people the trouble of implementing these methods on their own.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n ```yaml\n dependencies:\n apatite:\n github: watzon/apatite\n ```\n\n2. Run `shards install`\n\n## Usage\n\n```crystal\nrequire \"apatite\"\n```\n\nCheck out the [documentation](https://watzon.github.io/apatite/) for usage examples.\n\n## Roadmap\n\n- [ ] Linear Algebra\n\t- [x] Vector\n\t- [ ] Matrix (_in progress_)\n\t- [ ] NDArray\n\t- [ ] Line\n\t- [ ] Plane\n\t- [ ] Polygon\n\t- [ ] LinkedList\n\t\n\n\n## Contributing\n\n1. Fork it (Cartesian unit vector I
"},{"id":"J","name":"J","value":"Vector::J","doc":"Cartesian unit vector J\n\n`Vector{0.0, 1.0, 0.0}`","summary":"Cartesian unit vector J
"},{"id":"K","name":"K","value":"Vector::K","doc":"Cartesian unit vector K\n\n`Vector{0.0, 0.0, 1.0}`","summary":"Cartesian unit vector K
"},{"id":"VERSION","name":"VERSION","value":"\"0.1.0\"","doc":null,"summary":null}],"included_modules":[{"html_id":"github.com/watzon/apatite/Apatite/LinearAlgebra","kind":"module","full_name":"Apatite::LinearAlgebra","name":"LinearAlgebra"}],"extended_modules":[{"html_id":"github.com/watzon/apatite/Apatite","kind":"module","full_name":"Apatite","name":"Apatite"}],"subclasses":[],"including_types":[],"namespace":null,"doc":"Apatite is a fundimental package for scientific computing in Crystal. If that\nsounds like a modified version of the first line from the NumPy homepage,\nthat's because it is. Apatite has (ok, will have) all of the goodness\nof NumPy sitting atop the blazing speed and beautiful syntax\nof Crystal.","summary":"Apatite is a fundimental package for scientific computing in Crystal.
","class_methods":[{"id":"approx_precision-class-method","html_id":"approx_precision-class-method","name":"approx_precision","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L18","def":{"name":"approx_precision","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@@approx_precision"}},{"id":"approx_precision=(approx_precision)-class-method","html_id":"approx_precision=(approx_precision)-class-method","name":"approx_precision=","doc":null,"summary":null,"abstract":false,"args":[{"name":"approx_precision","doc":null,"default_value":"","external_name":"approx_precision","restriction":""}],"args_string":"(approx_precision)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L22","def":{"name":"approx_precision=","args":[{"name":"approx_precision","doc":null,"default_value":"","external_name":"approx_precision","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@@approx_precision = approx_precision"}},{"id":"precision-class-method","html_id":"precision-class-method","name":"precision","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L17","def":{"name":"precision","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@@precision"}},{"id":"precision=(precision)-class-method","html_id":"precision=(precision)-class-method","name":"precision=","doc":null,"summary":null,"abstract":false,"args":[{"name":"precision","doc":null,"default_value":"","external_name":"precision","restriction":""}],"args_string":"(precision)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L21","def":{"name":"precision=","args":[{"name":"precision","doc":null,"default_value":"","external_name":"precision","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@@precision = precision"}}],"constructors":[],"instance_methods":[{"id":"angle_from(a,b)-instance-method","html_id":"angle_from(a,b)-instance-method","name":"angle_from","doc":"Returns the angle between this vector and another in radians.\nIf the vectors are mirrored across their axes this will return `nil`.","summary":"Returns the angle between this vector and another in radians.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L145","def":{"name":"angle_from","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if a.size == b.size\nelse\n raise(\"Cannot compute the angle between vectors with different dimensionality\")\nend\ndot = 0_f64\nmod1 = 0_f64\nmod2 = 0_f64\n(a.zip(b)).each do |x, v|\n dot = dot + (x * v)\n mod1 = mod1 + (x * x)\n mod2 = mod2 + (v * v)\nend\nmod1 = Math.sqrt(mod1)\nmod2 = Math.sqrt(mod2)\nif (mod2 * mod2) == 0\n return 0.0\nend\ntheta = (dot / (mod1 * mod2)).clamp(-1, 1)\nMath.acos(theta)\n"}},{"id":"antiparallel_to?(a,b)-instance-method","html_id":"antiparallel_to?(a,b)-instance-method","name":"antiparallel_to?","doc":"Returns whether the vectors are antiparallel to each other.","summary":"Returns whether the vectors are antiparallel to each other.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L178","def":{"name":"antiparallel_to?","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"angle = angle_from(a, b)\n(angle - Math::PI).abs <= precision\n"}},{"id":"as_vector(input:Indexable)-instance-method","html_id":"as_vector(input:Indexable)-instance-method","name":"as_vector","doc":"Creates a new vector from the given `input`. Input can be any\n`Indexable` type.","summary":"Creates a new vector from the given input
.
Creates a standard basis-n vector of the given size
and index
.
Creates a matrix where the diagonal elements are composed of values
.
Get the scalar (dot) product of two vectors.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"args_string":"(x, y)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L125","def":{"name":"dot","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if x.size == y.size\nelse\n raise(\"Cannot compute the dot product of vectors with different dimensionality\")\nend\n(0...x.size).reduce(0) do |acc, i|\n acc + (x[i] * y[i])\nend\n"}},{"id":"empty-instance-method","html_id":"empty-instance-method","name":"empty","doc":"Returns a new empty `Vector`","summary":"Returns a new empty Vector
Creates a new empty matrix with the given row_count
and column_count
.
Creates a new diagonal matrix of size n
with ones in the diagonal and zeros elsewhere.
Returns a new vector of size n
filled with i
Creates a n x n
identity matrix.
Returns a new vector filled with n
ones.
Returns whether the vectors are parallel to each other.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L172","def":{"name":"parallel_to?","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"angle = angle_from(a, b)\nangle <= precision\n"}},{"id":"perpendicular_to?(a,b)-instance-method","html_id":"perpendicular_to?(a,b)-instance-method","name":"perpendicular_to?","doc":"Returns whether the vectors are perpendicular to each other.","summary":"Returns whether the vectors are perpendicular to each other.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"args_string":"(a, b)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L184","def":{"name":"perpendicular_to?","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":""},{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(dot(a, b)).abs <= precision"}},{"id":"random(n,range=nil)-instance-method","html_id":"random(n,range=nil)-instance-method","name":"random","doc":"Creates a new vector of size `n` filled with random numbers. A `range`\ncan optionally be passed in if you want to limit the random numbers\nto a given range.","summary":"Creates a new vector of size n
filled with random numbers.
Creates a single-row matrix where the values of that row are as given in row
.
Creates an n
by n
diagonal matrix where each diagonal element is value.
Compute the cosine similarity between two vectors.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"args_string":"(x, y)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite.cr#L136","def":{"name":"similarity","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"(dot(x, y)) / ((Math.sqrt(dot(x, x))) * (Math.sqrt(dot(y, y))))"}},{"id":"vector(n,&block)-instance-method","html_id":"vector(n,&block)-instance-method","name":"vector","doc":"Creates a new vector of size `n`, and invokes the block once\nfor each index of `self`, assigning the block's value in that index.","summary":"Creates a new vector of size n
, and invokes the block once for each index of self
, assigning the block's value in that index.
Returns a new vector filled with n
zeros.
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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra.cr#L14","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra.cr#L22","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/Matrix","path":"Apatite/LinearAlgebra/Matrix.html","kind":"class","full_name":"Apatite::LinearAlgebra::Matrix","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.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.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":[{"id":"[](*rows)-class-method","html_id":"[](*rows)-class-method","name":"[]","doc":"Creates a matrix where each argument is a row.","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L22","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)"}},{"id":"build(row_count,column_count=row_count,&block)-class-method","html_id":"build(row_count,column_count=row_count,&block)-class-method","name":"build","doc":"Creates a matrix of size `row_count x column_count`. It fills the values by calling\nthe given block, passing the current row and column.","summary":"Creates a matrix of size row_count x column_count
.
Creates a single-column matrix where the values of that column are as given in column.
","abstract":false,"args":[{"name":"column","doc":null,"default_value":"","external_name":"column","restriction":""}],"args_string":"(column)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L39","def":{"name":"col_vector","args":[{"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":"Matrix.new([column].transpose, 1)"}},{"id":"columns(columns)-class-method","html_id":"columns(columns)-class-method","name":"columns","doc":"Creates a matrix using `columns` as an array of column vectors.","summary":"Creates a matrix using .columns
as an array of column vectors.
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
.
Creates a new diagonal matrix of size n
with ones in the diagonal and zeros elsewhere.
TODO
","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L103","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":""}},{"id":"identity(n)-class-method","html_id":"identity(n)-class-method","name":"identity","doc":"Creates a `n x n` identity matrix.","summary":"Creates a n x 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":""}],"args_string":"(rows)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L117","def":{"name":"rows","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"size = rows[0]? ? rows[0].size : 0\nrows.each do |row|\n if row.size == size\n else\n raise(\"Dimension mismatch: row size differs (#{row.size} should be #{size})\")\n end\nend\nMatrix.new(rows, size)\n"}},{"id":"scalar(n,value)-class-method","html_id":"scalar(n,value)-class-method","name":"scalar","doc":"Creates an `n` by `n` diagonal matrix where each diagonal element is value.","summary":"Creates an n
by n
diagonal matrix where each diagonal element is value.
TODO
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"args_string":"(x, y)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L131","def":{"name":"vstack","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":""},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":""}},{"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.","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L135","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.new(row_count) do\n Vector.new(column_count)\nend\nMatrix.new(rows, column_count)\n"}}],"constructors":[{"id":"new(rows,column_count:Int32?=nil)-class-method","html_id":"new(rows,column_count:Int32?=nil)-class-method","name":"new","doc":null,"summary":null,"abstract":false,"args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""},{"name":"column_count","doc":null,"default_value":"nil","external_name":"column_count","restriction":"Int32 | ::Nil"}],"args_string":"(rows, column_count : Int32? = nil)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L15","def":{"name":"new","args":[{"name":"rows","doc":null,"default_value":"","external_name":"rows","restriction":""},{"name":"column_count","doc":null,"default_value":"nil","external_name":"column_count","restriction":"Int32 | ::Nil"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(rows, column_count)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L140","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n (0...column_count).reduce(0.0) do |vij, k|\n vij + (self[i, k] * other[k, j])\n end\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"id":"*(int:Int)-instance-method","html_id":"*(int:Int)-instance-method","name":"*","doc":null,"summary":null,"abstract":false,"args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":"Int"}],"args_string":"(int : Int)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L154","def":{"name":"*","args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = self.rows.map do |row|\n row.map do |e|\n e * int\n end\nend\nMatrix.new(rows, column_count)\n"}},{"id":"*(ind:Indexable)-instance-method","html_id":"*(ind:Indexable)-instance-method","name":"*","doc":null,"summary":null,"abstract":false,"args":[{"name":"ind","doc":null,"default_value":"","external_name":"ind","restriction":"Indexable"}],"args_string":"(ind : Indexable)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L161","def":{"name":"*","args":[{"name":"ind","doc":null,"default_value":"","external_name":"ind","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m = column_vector\nr = self * m\nr.column(0)\n"}},{"id":"**(int)-instance-method","html_id":"**(int)-instance-method","name":"**","doc":null,"summary":null,"abstract":false,"args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":""}],"args_string":"(int)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L167","def":{"name":"**","args":[{"name":"int","doc":null,"default_value":"","external_name":"int","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if int >= 1\nelse\n raise(\"Number can not the less than 1\")\nend\nmat = self\n(int - 1).times do\n mat = mat * self\nend\nmat\n"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L176","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n self[i, j] + other[i, j]\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"id":"+(vec:Indexable)-instance-method","html_id":"+(vec:Indexable)-instance-method","name":"+","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L188","def":{"name":"+","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"vec = vec.is_a?(Vector) ? vec : Vector.create(vec)\nself + (column_vector(vec))\n"}},{"id":"-(vec:Indexable)-instance-method","html_id":"-(vec:Indexable)-instance-method","name":"-","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L205","def":{"name":"-","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"vec = vec.is_a?(Vector) ? vec : Vector.create(vec)\nself + (column_vector(vec))\n"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L193","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":"if column_count != other.column_count\n raise(\"Dimension mismatch\")\nend\nrows = Array.new(row_count) do |i|\n Vector.new(other.column_count) do |j|\n self[i, j] - other[i, j]\n end\nend\nreturn Matrix.new(rows, other.column_count)\n"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L210","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":"self * other.inverse"}},{"id":"/(vec:Indexable)-instance-method","html_id":"/(vec:Indexable)-instance-method","name":"/","doc":null,"summary":null,"abstract":false,"args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"args_string":"(vec : Indexable)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L214","def":{"name":"/","args":[{"name":"vec","doc":null,"default_value":"","external_name":"vec","restriction":"Indexable"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = self.rows.map do |row|\n row.map do |e|\n e / other\n end\nend\nreturn new_matrix(rows, column_count)\n"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L221","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":"if (Matrix === other) && (column_count == other.column_count)\nelse\n return false\nend\nrows == other.rows\n"}},{"id":"[](row:Int,col:Int)-instance-method","html_id":"[](row:Int,col:Int)-instance-method","name":"[]","doc":"Returns element `(row, col)` of the matrix. Throws error on index error.","summary":"Returns element (row, col)
of the matrix.
Returns element (row, col)
of the matrix, or nil if the index is not found.
Returns the adjugate of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L239","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(\"Dimention mismatch: `Matrix#adjugate` requires a square matrix.\")\nend\nMatrix.build(row_count, column_count) do |row, column|\n cofactor(column, row)\nend\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 the first minor by (-1)**(row + column)","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L247","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(\"Dimention mismatch: `Matrix#cofactor` requires a square matrix.\")\nend\ndet_of_minor = (first_minor(row, column)).determinant\ndet_of_minor * ((-1.0) ** (row + column))\n"}},{"id":"column(j,&block)-instance-method","html_id":"column(j,&block)-instance-method","name":"column","doc":"Iterates over the specified column in the matrix, returning the Vector's items.","summary":"Iterates over the specified column in the matrix, returning the Vector's items.
","abstract":false,"args":[{"name":"j","doc":null,"default_value":"","external_name":"j","restriction":""}],"args_string":"(j, &block)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L274","def":{"name":"column","args":[{"name":"j","doc":null,"default_value":"","external_name":"j","restriction":""}],"double_splat":null,"splat_index":null,"yields":1,"block_arg":null,"return_type":"","visibility":"Public","body":"if j >= column_count || j < (-column_count)\n return self\nend\nrow_count.times do |i|\n yield rows[i][j]\nend\nself\n"}},{"id":"column(j)-instance-method","html_id":"column(j)-instance-method","name":"column","doc":"Returns column vector number `j` of the matrix as a `Vector` (starting at 0 like an array).","summary":"Returns column vector number j
of the matrix as a Vector
(starting at 0 like an array).
Returns column vector number j
of the matrix as a Vector
(starting at 0 like an array).
Returns an array of the column vectors of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L283","def":{"name":"column_vectors","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array(Vector).new(column_count) do |i|\n column(i)\nend"}},{"id":"determinant-instance-method","html_id":"determinant-instance-method","name":"determinant","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L354","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(\"Dimention mismatch: `Matrix#determinant` requires a square matrix.\")\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":"first_minor(row,column)-instance-method","html_id":"first_minor(row,column)-instance-method","name":"first_minor","doc":null,"summary":null,"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L429","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.map(&.to_a)\narrays.delete_at(row)\narrays.each do |array|\n array.delete_at(column)\nend\nMatrix.new(arrays, column_count - 1)\n"}},{"id":"inverse-instance-method","html_id":"inverse-instance-method","name":"inverse","doc":"Returns the inverse of the matrix.","summary":"Returns the inverse of the matrix.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L304","def":{"name":"inverse","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if square?\nelse\n if square?\n else\n raise(\"Dimention mismatch: `Matrix#inverse` requires a square matrix.\")\n end\nend\n(Matrix.identity(row_count)).inverse_from(self)\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.","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L450","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(\"Dimention mismatch: `Matrix#determinant` requires a square matrix.\")\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":"pretty_print(pp):Nil-instance-method","html_id":"pretty_print(pp):Nil-instance-method","name":"pretty_print","doc":null,"summary":null,"abstract":false,"args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"args_string":"(pp) : Nil","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L516","def":{"name":"pretty_print","args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"pp.list(\"[\", self, \"]\") do |vec|\n pp.group do\n vec.to_a.pretty_print(pp)\n end\nend"}},{"id":"row(i,&block)-instance-method","html_id":"row(i,&block)-instance-method","name":"row","doc":null,"summary":null,"abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"args_string":"(i, &block)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L475","def":{"name":"row","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":""}],"double_splat":null,"splat_index":null,"yields":0,"block_arg":{"name":"block","doc":null,"default_value":"","external_name":"block","restriction":""},"return_type":"","visibility":"Public","body":"(@rows.fetch(i) do\n return self\nend).each(&block)\nself\n"}},{"id":"row(i)-instance-method","html_id":"row(i)-instance-method","name":"row","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L480","def":{"name":"row","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":"Vector.create(rows.fetch(i) do\n [] of Float64\nend)"}},{"id":"row_count:Int32-instance-method","html_id":"row_count:Int32-instance-method","name":"row_count","doc":null,"summary":null,"abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L13","def":{"name":"row_count","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@row_count"}},{"id":"rows-instance-method","html_id":"rows-instance-method","name":"rows","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L484","def":{"name":"rows","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"rows = [] of Vector\nrow_count.times do |i|\n rows << self[i - 1]\nend\nrows\n"}},{"id":"square?-instance-method","html_id":"square?-instance-method","name":"square?","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L492","def":{"name":"square?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"row_count == column_count"}},{"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L502","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 << (map do |row|\n (\"{\" + (row.to_a.map do |e|\n e.to_s\n end.join(\", \"))) + \"}\"\n end.join(\", \"))\n io << \"]\"\nend"}},{"id":"transpose-instance-method","html_id":"transpose-instance-method","name":"transpose","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L496","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 Matrix.empty(column_count, 0)\nend\ntransposed = rows.map do |v|\n v.to_a\nend.transpose\nMatrix.new(transposed, row_count)\n"}},{"id":"unsafe_fetch(index:Int)-instance-method","html_id":"unsafe_fetch(index:Int)-instance-method","name":"unsafe_fetch","doc":null,"summary":null,"abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"}],"args_string":"(index : Int)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/matrix.cr#L525","def":{"name":"unsafe_fetch","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@buffer[index]"}}],"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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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","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/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/vector.cr","line_number":4,"url":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr"}],"repository_name":"github.com/watzon/apatite","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"I","name":"I","value":"Vector.create([1.0, 0.0, 0.0])","doc":"Cartesian unit vector I","summary":"Cartesian unit vector I
"},{"id":"J","name":"J","value":"Vector.create([0.0, 1.0, 0.0])","doc":"Cartesian unit vector J","summary":"Cartesian unit vector J
"},{"id":"K","name":"K","value":"Vector.create([0.0, 0.0, 1.0])","doc":"Cartesian unit vector K","summary":"Cartesian unit vector K
"}],"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
Returns a standard basis n-vector.
","abstract":false,"args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""},{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":""}],"args_string":"(size, index)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L138","def":{"name":"basis","args":[{"name":"size","doc":null,"default_value":"","external_name":"size","restriction":""},{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if size < 1\n raise(ArgumentError.new(\"invalid size (#{size} for 1..)\"))\nend\nif 0 <= index && index < size\nelse\n raise(ArgumentError.new(\"invalid index (#{index} for 0...#{size})\"))\nend\nvec = Vector.new(size, 0.0)\nvec[index] = 1.0\nvec\n"}},{"id":"create(elements:Indexable(Number))-class-method","html_id":"create(elements:Indexable(Number))-class-method","name":"create","doc":"Creates a new `Vector` from the elements of another `Indexable`\ncollection.\n\n```\nVector.create([1, 2, 3]) # Vector{1.0, 2.0, 3.0}\n```","summary":"Creates a new Vector
from the elements of another Indexable
collection.
Create a new vector of size n
filled with ones.
Creates a new Vector
of size n
filled with random numbers.
Create a new vector of size n
filled with zeros.
Creates a new Vector
, allocating an internal buffer with the given capacity, and yielding that buffer.
Creates a new Vector
of the given size filled with the same value in each position.
Creates a new empty Vector
backed by a buffer that is initially initial_capacity
big.
Create a new empty Vector
.
Creates a new Vector
of the given size and invokes the given block once for each index of self
, assigning the block's value in that index.
Alias for #push
Combined comparison 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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L339","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":"min_size = Math.min(size, other.size)\n0.upto(min_size - 1) do |i|\n n = @buffer[i] <=> other.to_unsafe[i]\n if n != 0\n return n\n end\nend\nsize <=> other.size\n"}},{"id":"==(other:Vector)-instance-method","html_id":"==(other:Vector)-instance-method","name":"==","doc":null,"summary":null,"abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"args_string":"(other : Vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L353","def":{"name":"==","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"equals?(other) do |x, y|\n x == y\nend"}},{"id":"[](start:Int,count:Int)-instance-method","html_id":"[](start:Int,count:Int)-instance-method","name":"[]","doc":"Returns count or less (if there aren't enough) elements starting at the\ngiven start index.\n\nNegative indices count backward from the end of the vector (-1 is the last\nelement). Additionally, an empty vector is returned when the starting index\nfor an element range is at the end of the vector.\n\nRaises `IndexError` if the starting index is out of range.\n\n```\nv = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nv[1, 3] # => Vector{2.0, 3.0, 4.0}\nv[6, 10] # raise IndexError\n```","summary":"Returns count or less (if there aren't enough) elements starting at the given start index.
","abstract":false,"args":[{"name":"start","doc":null,"default_value":"","external_name":"start","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"}],"args_string":"(start : Int, count : Int)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L191","def":{"name":"[]","args":[{"name":"start","doc":null,"default_value":"","external_name":"start","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nif start == size\n return Vector.new\nend\nif start < 0\n start = start + size\nend\nif 0 <= start && start <= size\nelse\n raise(IndexError.new)\nend\nif count == 0\n return Vector.new\nend\ncount = Math.min(count, size - start)\nVector.build(count) do |buffer|\n buffer.copy_from(@buffer + start, count)\n count\nend\n"}},{"id":"[](range:Range(Int,Int))-instance-method","html_id":"[](range:Range(Int,Int))-instance-method","name":"[]","doc":"Returns all elements that are within the given range.\n\nNegative indices count backward from the end of the vector (-1 is the last\nelement). Additionally, an empty vector is returned when the starting index\nfor an element range is at the end of the vector.\n\nRaises `IndexError` if the starting index is out of range.\n\n```\nv = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nv[1..3] # => Vector{2.0, 3.0, 4.0}\nv[6..10] # raise IndexError\n```","summary":"Returns all elements that are within the given range.
","abstract":false,"args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"}],"args_string":"(range : Range(Int, Int))","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L173","def":{"name":"[]","args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self[*Indexable.range_to_index_and_count(range, size)]"}},{"id":"[]=(index:Int,count:Int,values:Vector)-instance-method","html_id":"[]=(index:Int,count:Int,values:Vector)-instance-method","name":"[]=","doc":"Replaces a subrange with the elements of the given vector.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = Vector{6.0, 7.0, 8.0}\nvec # = Vector{1.0, 6.0, 7.0, 8.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = Vector{6.0, 7.0}\nvec # = Vector{1.0, 6.0, 7.0, 5.0}\n```","summary":"Replaces a subrange with the elements of the given vector.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Vector"}],"args_string":"(index : Int, count : Int, values : Vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L297","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nindex = check_index_out_of_bounds(index)\ncount = ((index + count) <= size) ? count : size - index\ndiff = values.size - count\nif diff == 0\n (@buffer + index).copy_from(values.to_unsafe, values.size)\nelse\n if diff < 0\n diff = -diff\n (@buffer + index).copy_from(values.to_unsafe, values.size)\n ((@buffer + index) + values.size).move_from((@buffer + index) + count, (size - index) - count)\n ((@buffer + @size) - diff).clear(diff)\n @size = @size - diff\n else\n resize_to_capacity(Math.pw2ceil(@size + diff))\n ((@buffer + index) + values.size).move_from((@buffer + index) + count, (size - index) - count)\n (@buffer + index).copy_from(values.to_unsafe, values.size)\n @size = @size + diff\n end\nend\nvalues\n"}},{"id":"[]=(index:Int,count:Int,value)-instance-method","html_id":"[]=(index:Int,count:Int,value)-instance-method","name":"[]=","doc":"Replaces a subrange with a single value. All elements in the range\n`index...index+count` are removed and replaced by a single element\n*value*.\n\nIf *count* is zero, *value* is inserted at *index*.\n\nNegative values of *index* count from the end of the vector.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 3] = 6.0\nvec # => Vector{1.0, 6.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1, 0] = 6.0\nvec # => Vector{1.0, 6.0, 2.0, 3.0, 4.0, 5.0}\n```","summary":"Replaces a subrange with a single value.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(index : Int, count : Int, value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L248","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"count","doc":null,"default_value":"","external_name":"count","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if count < 0\n raise(ArgumentError.new(\"Negative count: #{count}\"))\nend\nvalue = value.to_f64\nindex = check_index_out_of_bounds(index)\ncount = ((index + count) <= size) ? count : size - index\ncase count\nwhen 0\n insert(index, value)\nwhen 1\n @buffer[index] = value\nelse\n diff = count - 1\n ((@buffer + index) + 1).move_from((@buffer + index) + count, (size - index) - count)\n ((@buffer + @size) - diff).clear(diff)\n @buffer[index] = value\n @size = @size - diff\nend\nvalue\n"}},{"id":"[]=(index:Int,value)-instance-method","html_id":"[]=(index:Int,value)-instance-method","name":"[]=","doc":"Sets the given value at the given index.\n\nNegative indices can be used to start counting from the end of the array.\nRaises `IndexError` if trying to set an element outside the array's range.\n\n```\nvec = Vector{1.0, 2.0, 3.0}\nvec[0] = 5.0\np vec # => Vec{5.0, 2.0, 3.0}\n\nvec[3] = 5.0 # raises IndexError\n```","summary":"Sets the given value at the given index.
","abstract":false,"args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(index : Int, value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L226","def":{"name":"[]=","args":[{"name":"index","doc":null,"default_value":"","external_name":"index","restriction":"Int"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"index = check_index_out_of_bounds(index)\n@buffer[index] = value.to_f64\n"}},{"id":"[]=(range:Range(Int,Int),value)-instance-method","html_id":"[]=(range:Range(Int,Int),value)-instance-method","name":"[]=","doc":"Replaces a subrange with a single value.\n\n```\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1..3] = 6.0\nvec # = Vector{1.0, 6.0, 5.0}\n\nvec = Vector{1.0, 2.0, 3.0, 4.0, 5.0}\nvec[1...1] = 6\nvec # = Vector{1.0, 6.0, 2.0, 3.0, 4.0, 5.0}\n```","summary":"Replaces a subrange with a single value.
","abstract":false,"args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(range : Range(Int, Int), value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L282","def":{"name":"[]=","args":[{"name":"range","doc":null,"default_value":"","external_name":"range","restriction":"Range(Int, Int)"},{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"self[*Indexable.range_to_index_and_count(range, size)] = value.to_f64"}},{"id":"add(value)-instance-method","html_id":"add(value)-instance-method","name":"add","doc":"When the input is a number, this returns the result of adding\nit to all vector elements. When it's a vector, the vectors\nwill be added together.","summary":"When the input is a number, this returns the result of adding it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L476","def":{"name":"add","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a + b\nend"}},{"id":"angle_from(vector)-instance-method","html_id":"angle_from(vector)-instance-method","name":"angle_from","doc":"Returns the angle between this vector and another in radians.\nIf the vectors are mirrored across their axes this will return `nil`.","summary":"Returns the angle between this vector and another in radians.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L449","def":{"name":"angle_from","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite.angle_from(self, vector)"}},{"id":"antiparallel_to?(vector)-instance-method","html_id":"antiparallel_to?(vector)-instance-method","name":"antiparallel_to?","doc":"Returns whether the vectors are antiparallel to each other.","summary":"Returns whether the vectors are antiparallel to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L464","def":{"name":"antiparallel_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite.antiparallel_to?(self, vector)"}},{"id":"augment(elements)-instance-method","html_id":"augment(elements)-instance-method","name":"augment","doc":"Returns a new vector with the provided `elements` concatenated\non the end.","summary":"Returns a new vector with the provided elements
concatenated on the end.
Returns a new vector with the first n
elements removed from the beginning.
Removes all elements from self.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L768","def":{"name":"clear","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@buffer.clear(@size)\n@size = 0\nself\n"}},{"id":"clone-instance-method","html_id":"clone-instance-method","name":"clone","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L378","def":{"name":"clone","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Vector.create(@elements.clone)"}},{"id":"concat(other:Vector)-instance-method","html_id":"concat(other:Vector)-instance-method","name":"concat","doc":null,"summary":null,"abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"args_string":"(other : Vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L717","def":{"name":"concat","args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":"Vector"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"other_size = other.size\nnew_size = size + other_size\nif new_size > @capacity\n resize_to_capacity(Math.pw2ceil(new_size))\nend\n(@buffer + @size).copy_from(other.to_unsafe, other_size)\n@size = new_size\nself\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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L587","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(*vs)-instance-method","html_id":"cross(*vs)-instance-method","name":"cross","doc":"Returns the cross product of this vector with the others.\n\n```\nv1 = Vector{1.0, 0.0, 0.0}\nv2 = Vector{0.0, 1.0, 0.0}\nv1.cross(v2) => Vector{0.0, 0.0, 1.0}\n```","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/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L513","def":{"name":"cross","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(\"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(\"Dimension mismatch. Vectors not all the same size.\")\n end\nend\ncase size\nwhen 2\n Vector[-@buffer[1], @buffer[0]]\nwhen 3\n v = vs[0]\n Vector[(v[2] * @buffer[1]) - (v[1] * @buffer[2]), (v[0] * @buffer[2]) - (v[2] * @buffer[0]), (v[1] * @buffer[0]) - (v[0] * @buffer[1])]\nelse\nend\n"}},{"id":"distance_from(obj)-instance-method","html_id":"distance_from(obj)-instance-method","name":"distance_from","doc":"Gets this vector's distance from the argument, when considered\na point in space.","summary":"Gets this vector's distance from the argument, when considered a point in space.
","abstract":false,"args":[{"name":"obj","doc":null,"default_value":"","external_name":"obj","restriction":""}],"args_string":"(obj)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L615","def":{"name":"distance_from","args":[{"name":"obj","doc":null,"default_value":"","external_name":"obj","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if object.is_a?(Plane) || object.is_a?(Line)\n return object.distance_from(self)\nend\nv = elements.is_a?(Vector) ? elements.elements : elements\nif v.size == @elements.size\nelse\n return nil\nend\nsum = 0\npart = 0\neach_with_index do |x, i|\n part = x - v[i - 1]\n sum = sum + (part * part)\nend\nMath.sqrt(sum)\n"}},{"id":"divide(value)-instance-method","html_id":"divide(value)-instance-method","name":"divide","doc":"When the input is a number, this returns the result of dividing\nit to all vector elements. When it's a vector, the vectors\nwill be element-wise divided.","summary":"When the input is a number, this returns the result of dividing it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L497","def":{"name":"divide","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a / b\nend"}},{"id":"dot(other)-instance-method","html_id":"dot(other)-instance-method","name":"dot","doc":"Get the scalar (dot) product of this vector with `vector`.\n\n[https://en.wikipedia.org/wiki/Scalar_product](https://en.wikipedia.org/wiki/Scalar_product)","summary":"Get the scalar (dot) product of this vector with vector
.
Returns the ith
element of the vector.
Returns true if all vectors are linearly independent.
","abstract":false,"args":[{"name":"vs","doc":null,"default_value":"","external_name":"vs","restriction":""}],"args_string":"(*vs)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L388","def":{"name":"independent?","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":"vs.each do |v|\n if v.size == vs.first.size\n else\n raise(\"Dimension mismatch. Vectors not all the same size.\")\n end\nend\nif vs.size > sv.first.size\n return false\nend\nMatrix[*vs].rank.equal?(vs.count)\n"}},{"id":"lies_in(plane)-instance-method","html_id":"lies_in(plane)-instance-method","name":"lies_in","doc":"Returns true if the vector is a point on the given plane.","summary":"Returns true if the vector is a point on the given plane.
","abstract":false,"args":[{"name":"plane","doc":null,"default_value":"","external_name":"plane","restriction":""}],"args_string":"(plane)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L640","def":{"name":"lies_in","args":[{"name":"plane","doc":null,"default_value":"","external_name":"plane","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"plane.contains(self)"}},{"id":"lies_on(line)-instance-method","html_id":"lies_on(line)-instance-method","name":"lies_on","doc":"Returns true if the vector is a point on the given line","summary":"Returns true if the vector is a point on the given line
","abstract":false,"args":[{"name":"line","doc":null,"default_value":"","external_name":"line","restriction":""}],"args_string":"(line)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L635","def":{"name":"lies_on","args":[{"name":"line","doc":null,"default_value":"","external_name":"line","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"line.contains(self)"}},{"id":"log-instance-method","html_id":"log-instance-method","name":"log","doc":"Return a new `Vector` with the log of every item in `self`.","summary":"Return a new Vector
with the log of every item in self
.
Returns the magnitude/euclidian norm of this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L423","def":{"name":"magnitude","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sum = reduce(0.0) do |acc, e|\n acc = acc + (e * e)\nend\nMath.sqrt(sum)\n"}},{"id":"map(&block)-instance-method","html_id":"map(&block)-instance-method","name":"map","doc":"Invokes the given block for each element of `self`.","summary":"Invokes the given block for each element of self
.
Invokes the given block for each element of self
, replacing the element with the value returned by the block.
Optimized version of Enumerable#map_with_index
.
Like #map_with_index
, but mutates self
instead of allocating a new object.
Returns the (absolute) largest element in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L575","def":{"name":"max","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce do |acc, i|\n i.abs > acc.abs ? i : acc\nend"}},{"id":"max_index-instance-method","html_id":"max_index-instance-method","name":"max_index","doc":"Gets the index of the largest element in this vector.","summary":"Gets the index of the largest element in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L580","def":{"name":"max_index","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"idx = 0\neach_with_index do |e, i|\n idx = e.abs > self[idx].abs ? i : idx\nend\nidx\n"}},{"id":"multiply(value)-instance-method","html_id":"multiply(value)-instance-method","name":"multiply","doc":"When the input is a number, this returns the result of multiplying\nit to all vector elements. When it's a vector, the vectors\nwill be element-wise multiplied.","summary":"When the input is a number, this returns the result of multiplying it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L490","def":{"name":"multiply","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a * b\nend"}},{"id":"normalize-instance-method","html_id":"normalize-instance-method","name":"normalize","doc":"Returns a new vector created by normalizing this one\nto have a magnitude of `1`. If the vector is a zero\nvector, it will not be modified.","summary":"Returns a new vector created by normalizing this one to have a magnitude of 1
.
Returns whether the vectors are parallel to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L459","def":{"name":"parallel_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite.parallel_to?(self, vector)"}},{"id":"perpendicular_to?(vector)-instance-method","html_id":"perpendicular_to?(vector)-instance-method","name":"perpendicular_to?","doc":"Returns whether the vectors are perpendicular to each other.","summary":"Returns whether the vectors are perpendicular to each other.
","abstract":false,"args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"args_string":"(vector)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L469","def":{"name":"perpendicular_to?","args":[{"name":"vector","doc":null,"default_value":"","external_name":"vector","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Apatite.perpendicular_to?(self, vector)"}},{"id":"pretty_print(pp):Nil-instance-method","html_id":"pretty_print(pp):Nil-instance-method","name":"pretty_print","doc":null,"summary":null,"abstract":false,"args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"args_string":"(pp) : Nil","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L740","def":{"name":"pretty_print","args":[{"name":"pp","doc":null,"default_value":"","external_name":"pp","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Nil","visibility":"Public","body":"pp.list(\"Vector{\", self, \"}\")"}},{"id":"product-instance-method","html_id":"product-instance-method","name":"product","doc":"Get the product of all elements in this vector.","summary":"Get the product of all elements in this vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L562","def":{"name":"product","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce do |acc, v|\n acc = acc * v\nend"}},{"id":"push(value:Float64)-instance-method","html_id":"push(value:Float64)-instance-method","name":"push","doc":null,"summary":null,"abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Float64"}],"args_string":"(value : Float64)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L644","def":{"name":"push","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":"Float64"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"check_needs_resize\n@buffer[@size] = value\n@size = @size + 1\nself\n"}},{"id":"push(*values:Float64)-instance-method","html_id":"push(*values:Float64)-instance-method","name":"push","doc":null,"summary":null,"abstract":false,"args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Float64"}],"args_string":"(*values : Float64)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L651","def":{"name":"push","args":[{"name":"values","doc":null,"default_value":"","external_name":"values","restriction":"Float64"}],"double_splat":null,"splat_index":0,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"new_size = @size + values.size\nif new_size > @capacity\n resize_to_capacity(Math.pw2ceil(new_size))\nend\nvalues.each_with_index do |value, i|\n @buffer[@size + i] = value\nend\n@size = new_size\nself\n"}},{"id":"reflection_in(object)-instance-method","html_id":"reflection_in(object)-instance-method","name":"reflection_in","doc":"Returns the result of reflecting the point in the given `object`\n(point, line, or plane).","summary":"Returns the result of reflecting the point in the given object
(point, line, or plane).
Rotates the vector about the given object
.
Gets the result of rounding the elements of the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L598","def":{"name":"round","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"map do |x|\n x.round\nend"}},{"id":"set_elements(elements)-instance-method","html_id":"set_elements(elements)-instance-method","name":"set_elements","doc":null,"summary":null,"abstract":false,"args":[{"name":"elements","doc":null,"default_value":"","external_name":"elements","restriction":""}],"args_string":"(elements)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L712","def":{"name":"set_elements","args":[{"name":"elements","doc":null,"default_value":"","external_name":"elements","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@elements = elements.is_a?(Vector) ? elements.elements : elements\nself\n"}},{"id":"sigmoid-instance-method","html_id":"sigmoid-instance-method","name":"sigmoid","doc":"Sums the numbers in the vector and returns a sigmoid value\nacross the whole vector.","summary":"Sums the numbers in the vector and returns a sigmoid value across the whole vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L693","def":{"name":"sigmoid","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"LinearAlgebra.sigmoid(sum)"}},{"id":"similarity(other)-instance-method","html_id":"similarity(other)-instance-method","name":"similarity","doc":"Compute the cosine similarity between this vector and another.","summary":"Compute the cosine similarity between this vector and another.
","abstract":false,"args":[{"name":"other","doc":null,"default_value":"","external_name":"other","restriction":""}],"args_string":"(other)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L454","def":{"name":"similarity","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":"Apatite.similarity(self, other)"}},{"id":"size:Int32-instance-method","html_id":"size:Int32-instance-method","name":"size","doc":"Returns the number of elements in the vector","summary":"Returns the number of elements in the vector
","abstract":false,"args":[],"args_string":" : Int32","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L24","def":{"name":"size","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Int32","visibility":"Public","body":"@size"}},{"id":"snap_to(value)-instance-method","html_id":"snap_to(value)-instance-method","name":"snap_to","doc":"Returns a copy of the vector with elements set to `value` if\nthey differ from it by less than `Apetite.precision`","summary":"Returns a copy of the vector with elements set to value
if they differ from it by less than Apetite.precision
When the input is a number, this returns the result of subtracting it to all vector elements.
","abstract":false,"args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"args_string":"(value)","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L483","def":{"name":"subtract","args":[{"name":"value","doc":null,"default_value":"","external_name":"value","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"run_binary_op(value) do |a, b|\n a - b\nend"}},{"id":"sum-instance-method","html_id":"sum-instance-method","name":"sum","doc":"Returns the sum of all elements in the vector.","summary":"Returns the sum of all elements in the vector.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L502","def":{"name":"sum","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"reduce(0) do |acc, i|\n acc + i\nend"}},{"id":"to_3d-instance-method","html_id":"to_3d-instance-method","name":"to_3d","doc":"Utility to make sure vectors are 3D. If they are 2D, a zero\nz-component is added.","summary":"Utility to make sure vectors are 3D.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L699","def":{"name":"to_3d","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"v = dup\ncase v.elements.size\nwhen 3\n break\nwhen 2\n v.elements.push(0)\nelse\n return nil\nend\nreturn v\n"}},{"id":"to_a-instance-method","html_id":"to_a-instance-method","name":"to_a","doc":null,"summary":null,"abstract":false,"args":[],"args_string":"","source_link":"https://github.com/watzon/apatite/blob/ef28e84ecc4b7dc21e66c18464fec0892633d420/src/apatite/linear_algebra/vector.cr#L730","def":{"name":"to_a","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Array(Float64).new(size) do |i|\n self[i]\nend"}},{"id":"to_diagonal_matrix-instance-method","html_id":"to_diagonal_matrix-instance-method","name":"to_diagonal_matrix","doc":"Returns a diagonal `Matrix` with the vectors elements as its\ndiagonal elements.","summary":"Returns a diagonal Matrix
with the vectors elements as its diagonal elements.
Returns a new vector created by normalizing this one to have a magnitude of 1
.
Returns a pointer to the internal buffer where self
's elements are stored.
Returns a vector containing only the first n
elements.
Transpose this vector into a 1xn Matrix
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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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/ef28e84ecc4b7dc21e66c18464fec0892633d420/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