Module: NumRuby
- Defined in:
- lib/numruby/numruby.rb,
ext/ruby_nmatrix.c
Defined Under Namespace
Class Method Summary collapse
- .append(a, b) ⇒ Object
- .arange(len) ⇒ Object
- .array(shape, elements, options = {}) ⇒ Object
- .average ⇒ Object
-
.broadcast_to ⇒ Object
rb_define_singleton_method(NumRuby, "matrix", nmatrix_init, -1);.
- .hstack(objs) ⇒ Object
- .ones ⇒ Object
-
.sin(obj) ⇒ Object
unary operations.
- .vstack(objs) ⇒ Object
- .zeros ⇒ Object
Class Method Details
.append(a, b) ⇒ Object
28 29 30 |
# File 'lib/numruby/numruby.rb', line 28 def self.append(a, b) self.vstack([a,b]) end |
.arange(len) ⇒ Object
14 15 16 17 |
# File 'lib/numruby/numruby.rb', line 14 def self.arange(len) elements = Array(0..len) NMatrix.new([len,1], elements, :nm_int) end |
.array(shape, elements, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/numruby/numruby.rb', line 3 def self.array(shape, elements, = {}) if([:dtype]) dtype = [:dtype] else dtype = :nm_float64 end NMatrix.new(shape, elements, dtype) end |
.average ⇒ Object
345 |
# File 'ext/ruby_nmatrix.c', line 345 VALUE average_nmatrix(int argc, VALUE* argv); |
.broadcast_to ⇒ Object
rb_define_singleton_method(NumRuby, "matrix", nmatrix_init, -1);
349 |
# File 'ext/ruby_nmatrix.c', line 349 VALUE nm_broadcast_to(int argc, VALUE* argv); |
.hstack(objs) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/numruby/numruby.rb', line 49 def self.hstack(objs) return nil unless objs.is_a?(Array) rows = objs[0].shape[0] cols = objs[0].shape[1] * objs.length result = NumRuby.zeros([rows, cols]) objs.each do |obj| #check num_rows mismatch end # (0..result.shape[1]).each do |col_index| # result[col_index, *] = objs[x][col_index, *] # index = (col_index == cols ? 0 : index + 1) # end result end |
.ones ⇒ Object
348 |
# File 'ext/ruby_nmatrix.c', line 348 VALUE ones_nmatrix(int argc, VALUE* argv); |
.sin(obj) ⇒ Object
unary operations
20 21 22 23 24 25 26 |
# File 'lib/numruby/numruby.rb', line 20 def self.sin(obj) if obj.is_a?(NMatrix) obj.sin() else Math.sin(obj) end end |
.vstack(objs) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/numruby/numruby.rb', line 32 def self.vstack(objs) return nil unless objs.is_a?(Array) rows = objs[0].shape[0] * objs.length cols = objs[0].shape[1] result = NumRuby.zeros([rows, cols]) objs.each do |obj| #check num_cols mismatch # (0..objs.shape[0]).each end # (0..result.shape[0]).each do |row_index| # result[row_index, *] = objs[x][row_index, *] # index = (row_index == rows ? 0 : index + 1) # end result end |
.zeros ⇒ Object
347 |
# File 'ext/ruby_nmatrix.c', line 347 VALUE zeros_nmatrix(int argc, VALUE* argv); |