fix specs
This commit is contained in:
parent
4df520caa1
commit
36f3aef41e
|
@ -1 +1 @@
|
||||||
crystal 1.2.0
|
crystal 1.7.2
|
||||||
|
|
|
@ -1464,8 +1464,8 @@ module Apatite
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsafe_fetch(i)
|
def unsafe_fetch(index : Int)
|
||||||
@rows.unsafe_fetch(i)
|
@rows.unsafe_fetch(index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,7 +78,7 @@ module Apatite
|
||||||
# Multiplies the vector by x, where x is a number.
|
# Multiplies the vector by x, where x is a number.
|
||||||
def *(x : Number)
|
def *(x : Number)
|
||||||
els = @elements.map { |e| (e * x).as(T) }
|
els = @elements.map { |e| (e * x).as(T) }
|
||||||
self.class.elements(els, false)
|
{{ @type.name(generic_args: false) }}.elements(els, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Multiplies the vector by x, where x is a matrix.
|
# Multiplies the vector by x, where x is a matrix.
|
||||||
|
@ -89,13 +89,13 @@ module Apatite
|
||||||
# Multiplies the vector by x, where x is another vector.
|
# Multiplies the vector by x, where x is another vector.
|
||||||
def *(x : Vector)
|
def *(x : Vector)
|
||||||
els = self.elements.zip(x.elements).map { |(x, y)| x * y }
|
els = self.elements.zip(x.elements).map { |(x, y)| x * y }
|
||||||
self.class.elements(els, false)
|
{{ @type.name(generic_args: false) }}.elements(els, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Vector addition.
|
# Vector addition.
|
||||||
def +(x : Number)
|
def +(x : Number)
|
||||||
els = @elements.map { |e| (e + x).as(T) }
|
els = @elements.map { |e| (e + x).as(T) }
|
||||||
self.class.elements(els, false)
|
{{ @type.name(generic_args: false) }}.elements(els, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Vector addition.
|
# Vector addition.
|
||||||
|
@ -106,13 +106,13 @@ module Apatite
|
||||||
# Vector addition.
|
# Vector addition.
|
||||||
def +(x : Vector)
|
def +(x : Vector)
|
||||||
els = self.elements.zip(x.elements).map { |(x, y)| x + y }
|
els = self.elements.zip(x.elements).map { |(x, y)| x + y }
|
||||||
self.class.elements(els, false)
|
{{ @type.name(generic_args: false) }}.elements(els, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Vector subtraction.
|
# Vector subtraction.
|
||||||
def -(x : Number)
|
def -(x : Number)
|
||||||
els = @elements.map { |e| (e - x).as(T) }
|
els = @elements.map { |e| (e - x).as(T) }
|
||||||
self.class.elements(els, false)
|
{{ @type.name(generic_args: false) }}.elements(els, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Vector subtraction.
|
# Vector subtraction.
|
||||||
|
@ -123,13 +123,13 @@ module Apatite
|
||||||
# Vector subtraction.
|
# Vector subtraction.
|
||||||
def -(x : Vector)
|
def -(x : Vector)
|
||||||
els = self.elements.zip(x.elements).map { |(x, y)| x - y }
|
els = self.elements.zip(x.elements).map { |(x, y)| x - y }
|
||||||
self.class.elements(els, false)
|
{{ @type.name(generic_args: false) }}.elements(els, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Vector division.
|
# Vector division.
|
||||||
def /(x : Number)
|
def /(x : Number)
|
||||||
els = @elements.map { |e| (e / x).as(T) }
|
els = @elements.map { |e| (e / x).as(T) }
|
||||||
self.class.elements(els, false)
|
{{ @type.name(generic_args: false) }}.elements(els, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Vector division.
|
# Vector division.
|
||||||
|
@ -140,7 +140,7 @@ module Apatite
|
||||||
# Vector division.
|
# Vector division.
|
||||||
def /(x : Vector)
|
def /(x : Vector)
|
||||||
els = self.elements.zip(x.elements).map { |(x, y)| x / y }
|
els = self.elements.zip(x.elements).map { |(x, y)| x / y }
|
||||||
self.class.elements(els, false)
|
{{ @type.name(generic_args: false) }}.elements(els, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Equality operator
|
# Equality operator
|
||||||
|
@ -172,13 +172,13 @@ module Apatite
|
||||||
|
|
||||||
# Returns a copy of the vector.
|
# Returns a copy of the vector.
|
||||||
def clone
|
def clone
|
||||||
self.class.elements(@elements)
|
{{ @type.name(generic_args: false) }}.elements(@elements)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Maps over a vector, passing each element to the block
|
# Maps over a vector, passing each element to the block
|
||||||
def map(&block : T -> _)
|
def map(&block : T -> _)
|
||||||
els = @elements.map(&block)
|
els = @elements.map(&block)
|
||||||
self.class.elements(els, false)
|
{{ @type.name(generic_args: false) }}.elements(els, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Maps over the current vector and `v` in conjunction, passing each
|
# Maps over the current vector and `v` in conjunction, passing each
|
||||||
|
@ -188,7 +188,7 @@ module Apatite
|
||||||
arr = Array.new(size) do |i|
|
arr = Array.new(size) do |i|
|
||||||
yield @elements[i], v[i]
|
yield @elements[i], v[i]
|
||||||
end
|
end
|
||||||
self.class.elements(arr, false)
|
{{ @type.name(generic_args: false) }}.elements(arr, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a single-row matrix from this vector.
|
# Creates a single-row matrix from this vector.
|
||||||
|
@ -275,28 +275,28 @@ module Apatite
|
||||||
# `imag` as the imaginary number.
|
# `imag` as the imaginary number.
|
||||||
def coerce(klass : Complex.class, imag : Number)
|
def coerce(klass : Complex.class, imag : Number)
|
||||||
els = @elements.map { |e| Complex.new(e, imag) }
|
els = @elements.map { |e| Complex.new(e, imag) }
|
||||||
self.class.elements(els)
|
{{ @type.name(generic_args: false) }}.elements(els)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Attempt to coerce the elements in a vector to BigInt with
|
# Attempt to coerce the elements in a vector to BigInt with
|
||||||
# an optional `base` value.
|
# an optional `base` value.
|
||||||
def coerce(klass : BigInt.class, base = 10)
|
def coerce(klass : BigInt.class, base = 10)
|
||||||
els = @elements.map { |e| BigInt.new(e, base) }
|
els = @elements.map { |e| BigInt.new(e, base) }
|
||||||
self.class.elements(els)
|
{{ @type.name(generic_args: false) }}.elements(els)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Attempt to coerce the elements in a vector to BigRational
|
# Attempt to coerce the elements in a vector to BigRational
|
||||||
# with the given `denominator`.
|
# with the given `denominator`.
|
||||||
def coerce(klass : BigRational.class, denominator : Int)
|
def coerce(klass : BigRational.class, denominator : Int)
|
||||||
els = @elements.map { |e| BigRational.new(e, denominator) }
|
els = @elements.map { |e| BigRational.new(e, denominator) }
|
||||||
self.class.elements(els)
|
{{ @type.name(generic_args: false) }}.elements(els)
|
||||||
end
|
end
|
||||||
|
|
||||||
# The coerce method allows you to attempt to coerce the elements
|
# The coerce method allows you to attempt to coerce the elements
|
||||||
# in the matrix to another type.
|
# in the matrix to another type.
|
||||||
def coerce(klass : U.class) : Vector(U) forall U
|
def coerce(klass : U.class) : Vector(U) forall U
|
||||||
els = @elements.map { |e| klass.new(e).as(U) }
|
els = @elements.map { |e| klass.new(e).as(U) }
|
||||||
self.class.elements(els)
|
{{ @type.name(generic_args: false) }}.elements(els)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the elements of the vector in an array.
|
# Returns the elements of the vector in an array.
|
||||||
|
@ -318,12 +318,17 @@ module Apatite
|
||||||
all?(&:zero?)
|
all?(&:zero?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the number of elements in the vector.
|
||||||
|
def size
|
||||||
|
@elements.size
|
||||||
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
"<#Vector(#{T}) [#{@elements.join(", ")}]>"
|
"<#Vector(#{T}) [#{@elements.join(", ")}]>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsafe_fetch(i)
|
def unsafe_fetch(index : Int)
|
||||||
@elements.unsafe_fetch(i)
|
@elements.unsafe_fetch(index)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue