Class: MDMatrix
- Inherits:
-
Object
- Object
- MDMatrix
- Defined in:
- lib/colt/matrix/colt_matrix.rb
Direct Known Subclasses
DoubleMDMatrix3D, FloatMDMatrix3D, FloatingMDMatrix1D, FloatingMDMatrix2D, IntMDMatrix1D, IntMDMatrix2D, IntMDMatrix3D, LongMDMatrix1D, LongMDMatrix2D, LongMDMatrix3D
Instance Attribute Summary collapse
-
#colt_matrix ⇒ Object
readonly
Returns the value of attribute colt_matrix.
-
#mdarray ⇒ Object
readonly
Returns the value of attribute mdarray.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
Class Method Summary collapse
-
.build(type, shape, storage = nil) ⇒ Object
————————————————————————————.
-
.double(shape, storage = nil) ⇒ Object
————————————————————————————.
-
.float(shape, storage = nil) ⇒ Object
————————————————————————————.
-
.from_colt_matrix(colt_matrix) ⇒ Object
———————————————————————————— Creates a new MDMatrix from a given colt_matrix ————————————————————————————.
-
.from_mdarray(mdarray) ⇒ Object
———————————————————————————— Creates a MDMatrix from an MDArray.
-
.int(shape, storage = nil) ⇒ Object
————————————————————————————.
-
.long(shape, storage = nil) ⇒ Object
————————————————————————————.
Instance Method Summary collapse
-
#initialize(mdarray, colt_matrix) ⇒ MDMatrix
constructor
————————————————————————————.
-
#normalize! ⇒ Object
————————————————————————————.
-
#print ⇒ Object
————————————————————————————.
-
#sum ⇒ Object
————————————————————————————.
Constructor Details
#initialize(mdarray, colt_matrix) ⇒ MDMatrix
47 48 49 50 51 52 |
# File 'lib/colt/matrix/colt_matrix.rb', line 47 def initialize(mdarray, colt_matrix) @mdarray = mdarray @colt_matrix = colt_matrix @rank = @mdarray.rank @algebra = nil end |
Instance Attribute Details
#colt_matrix ⇒ Object (readonly)
Returns the value of attribute colt_matrix.
39 40 41 |
# File 'lib/colt/matrix/colt_matrix.rb', line 39 def colt_matrix @colt_matrix end |
#mdarray ⇒ Object (readonly)
Returns the value of attribute mdarray.
40 41 42 |
# File 'lib/colt/matrix/colt_matrix.rb', line 40 def mdarray @mdarray end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
41 42 43 |
# File 'lib/colt/matrix/colt_matrix.rb', line 41 def rank @rank end |
Class Method Details
.build(type, shape, storage = nil) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/colt/matrix/colt_matrix.rb', line 58 def self.build(type, shape, storage = nil) if (shape.size > 3) raise "Cannot create MDMatrix of size greater than 3" end self.from_mdarray(MDArray.build(type, shape, storage)) end |
.double(shape, storage = nil) ⇒ Object
69 70 71 |
# File 'lib/colt/matrix/colt_matrix.rb', line 69 def self.double(shape, storage = nil) self.build("double", shape, storage) end |
.float(shape, storage = nil) ⇒ Object
77 78 79 |
# File 'lib/colt/matrix/colt_matrix.rb', line 77 def self.float(shape, storage = nil) self.build("float", shape, storage) end |
.from_colt_matrix(colt_matrix) ⇒ Object
Creates a new MDMatrix from a given colt_matrix
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/colt/matrix/colt_matrix.rb', line 123 def self.from_colt_matrix(colt_matrix) if (colt_matrix.is_a? DenseDoubleMatrix3D) mdarray = MDArray.from_jstorage("double", [colt_matrix.slices, colt_matrix.rows, colt_matrix.columns], colt_matrix.elements) return DoubleMDMatrix3D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseFloatMatrix3D) mdarray = MDArray.from_jstorage("float", [colt_matrix.slices, colt_matrix.rows, colt_matrix.columns], colt_matrix.elements) return FloatMDMatrix3D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseLongMatrix3D) mdarray = MDArray.from_jstorage("long", [colt_matrix.slices, colt_matrix.rows, colt_matrix.columns], colt_matrix.elements) return LongMDMatrix3D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseIntMatrix3D) mdarray = MDArray.from_jstorage("int", [colt_matrix.slices, colt_matrix.rows, colt_matrix.columns], colt_matrix.elements) return IntMDMatrix3D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseDoubleMatrix2D) mdarray = MDArray.from_jstorage("double", [colt_matrix.rows, colt_matrix.columns], colt_matrix.elements) return DoubleMDMatrix2D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseFloatMatrix2D) mdarray = MDArray.from_jstorage("float", [colt_matrix.rows, colt_matrix.columns], colt_matrix.elements) return FloatMDMatrix2D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseLongMatrix2D) mdarray = MDArray.from_jstorage("long", [colt_matrix.rows, colt_matrix.columns], colt_matrix.elements) return LongMDMatrix2D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseIntMatrix2D) mdarray = MDArray.from_jstorage("int", [colt_matrix.rows, colt_matrix.columns], colt_matrix.elements) return IntMDMatrix2D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseDoubleMatrix1D) mdarray = MDArray.from_jstorage("double", [colt_matrix.size], colt_matrix.elements) return DoubleMDMatrix1D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseFloatMatrix1D) mdarray = MDArray.from_jstorage("float", [colt_matrix.size], colt_matrix.elements) return FloatMDMatrix1D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseLongMatrix1D) mdarray = MDArray.from_jstorage("long", [colt_matrix.size], colt_matrix.elements) return LongMDMatrix1D.from_mdarray(mdarray) elsif (colt_matrix.is_a? DenseIntMatrix1D) mdarray = MDArray.from_jstorage("int", [colt_matrix.size], colt_matrix.elements) return IntMDMatrix1D.from_mdarray(mdarray) end end |
.from_mdarray(mdarray) ⇒ Object
Creates a MDMatrix from an MDArray. (int rows, int columns, double[] elements, int rowZero, int columnZero, int rowStride, int columnStride, boolean isView)
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/colt/matrix/colt_matrix.rb', line 103 def self.from_mdarray(mdarray) case mdarray.rank when 1 dense1D(mdarray) when 2 dense2D(mdarray) when 3 dense3D(mdarray) else raise "Cannot create MDMatrix of rank greater than 3" end end |
.int(shape, storage = nil) ⇒ Object
93 94 95 |
# File 'lib/colt/matrix/colt_matrix.rb', line 93 def self.int(shape, storage = nil) self.build("int", shape, storage) end |
.long(shape, storage = nil) ⇒ Object
85 86 87 |
# File 'lib/colt/matrix/colt_matrix.rb', line 85 def self.long(shape, storage = nil) self.build("long", shape, storage) end |
Instance Method Details
#normalize! ⇒ Object
181 182 183 |
# File 'lib/colt/matrix/colt_matrix.rb', line 181 def normalize! @colt_matrix.normalize end |
#print ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/colt/matrix/colt_matrix.rb', line 197 def print case mdarray.type when "double" formatter = DoubleFormatter.new when "float" formatter = FloatFormatter.new when "long" formatter = LongFormatter.new when "int" formatter = IntFormatter.new end printf(formatter.toString(@colt_matrix)) end |
#sum ⇒ Object
189 190 191 |
# File 'lib/colt/matrix/colt_matrix.rb', line 189 def sum @colt_matrix.zSum end |