Class: Eigen::Matrix4
- Inherits:
-
Object
- Object
- Eigen::Matrix4
- Defined in:
- lib/eigen/matrix4.rb,
ext/eigen/eigen.cpp
Overview
A 4x4 matrix holding floating-point numbers
Class Method Summary collapse
-
._load(elements) ⇒ Object
:nodoc:.
-
.from_a(*args) ⇒ Matrix4
Create a new matrix from the content of an array.
Instance Method Summary collapse
-
#*(v) ⇒ Matrix4
Multiplies by a scalar.
-
#+(m) ⇒ Matrix4
Sums two matrices.
-
#-(m) ⇒ Matrix4
Subtracts two matrices.
-
#-@(v) ⇒ Matrix4
Returns this matrix’ negation.
-
#/(v) ⇒ Matrix4
Divides this matrix by a scalar.
- #==(m) ⇒ Object
-
#[](row, col) ⇒ Numeric
Accesses an element.
-
#[]=(row, col, value) ⇒ Numeric
Sets an element.
- #_dump(level) ⇒ Object
-
#approx?(m, threshold = dummy_precision) ⇒ Boolean
Verifies that two matrices are within threshold of each other, elementwise.
-
#cols ⇒ Numeric
The number of columns.
-
#dotM(m) ⇒ Numeric
Matrix multiplication.
-
#from_a(array, column_major = true) ⇒ Object
sets matrix from a 1d array.
-
#norm ⇒ Numeric
Returns the matrix’ norm.
-
#rows ⇒ Integer
The number of rows.
-
#size ⇒ Numeric
The number of elements.
-
#T ⇒ Matrix4
Returns the transposed matrix.
-
#to_a(column_major = true) ⇒ Array<Numeric>
Returns the values flattened in a ruby array.
-
#to_s(line_format = "%g %g %g %g") ⇒ Object
:nodoc:.
Class Method Details
._load(elements) ⇒ Object
:nodoc:
85 86 87 88 89 90 91 92 93 |
# File 'lib/eigen/matrix4.rb', line 85 def self._load(elements) # :nodoc: m = new if elements.size == 8 * 16 m.from_a(elements.unpack("E*")) else m.from_a(Marshal.load(elements)['data']) end m end |
.from_a(*args) ⇒ Matrix4
Create a new matrix from the content of an array
14 15 16 17 18 |
# File 'lib/eigen/matrix4.rb', line 14 def self.from_a(*args) m = new m.from_a(*args) m end |
Instance Method Details
#*(v) ⇒ Matrix4
Multiplies by a scalar
#+(m) ⇒ Matrix4
Sums two matrices
#-(m) ⇒ Matrix4
Subtracts two matrices
#-@(v) ⇒ Matrix4
Returns this matrix’ negation
#/(v) ⇒ Matrix4
Divides this matrix by a scalar
#==(m) ⇒ Object
66 67 68 69 |
# File 'lib/eigen/matrix4.rb', line 66 def ==(m) m.kind_of?(self.class) && __equal__(m) end |
#[](row, col) ⇒ Numeric
Accesses an element
|
# File 'lib/eigen/matrix4.rb', line 4
|
#[]=(row, col, value) ⇒ Numeric
Sets an element
#_dump(level) ⇒ Object
81 82 83 |
# File 'lib/eigen/matrix4.rb', line 81 def _dump(level) to_a.pack("E*") end |
#approx?(m, threshold = dummy_precision) ⇒ Boolean
Verifies that two matrices are within threshold of each other, elementwise
#cols ⇒ Numeric
Returns the number of columns.
#dotM(m) ⇒ Numeric
Matrix multiplication
#from_a(array, column_major = true) ⇒ Object
sets matrix from a 1d array
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/eigen/matrix4.rb', line 51 def from_a(array, column_major=true) if array.size > 16 raise ArgumentError, "array should be of size maximum 16" end 16.times do |i| v = array[i] || 0 if column_major self[i%4,i/4] = v else self[i/4,i%4] = v end end end |
#norm ⇒ Numeric
Returns the matrix’ norm
#rows ⇒ Integer
Returns the number of rows.
#size ⇒ Numeric
Returns the number of elements.
#T ⇒ Matrix4
Returns the transposed matrix
#to_a(column_major = true) ⇒ Array<Numeric>
Returns the values flattened in a ruby array
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/eigen/matrix4.rb', line 32 def to_a(column_major=true) a = [] if column_major for j in 0..3 for i in 0..3 a << self[i,j] end end else for i in 0..3 for j in 0..3 a << self[i,j] end end end a end |
#to_s(line_format = "%g %g %g %g") ⇒ Object
:nodoc:
71 72 73 74 75 76 77 78 79 |
# File 'lib/eigen/matrix4.rb', line 71 def to_s(line_format = "%g %g %g %g") # :nodoc: lines = to_a.each_slice(3).to_s <<-EOSTRING Matrix4(#{line_format % lines[0]}" #{line_format % lines[1]}" #{line_format % lines[2]}" #{line_format % lines[3]})" EOSTRING end |