Module: Hornetseye::Methods
- Included in:
- Math
- Defined in:
- lib/multiarray/methods.rb
Overview
Module providing the methods to manipulate array expressions
Class Method Summary collapse
-
.define_binary_method(mod, op, coercion = :coercion) ⇒ Proc
Extend binary method with capability to handle arrays.
-
.define_unary_method(mod, op, conversion = :identity) ⇒ Proc
Extend unary method with capability to handle arrays.
-
.included(mod) ⇒ Object
Extend some methods in the specified module.
Class Method Details
.define_binary_method(mod, op, coercion = :coercion) ⇒ Proc
Extend binary method with capability to handle arrays
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/multiarray/methods.rb', line 91 def define_binary_method( mod, op, coercion = :coercion ) mod.module_eval do define_method "#{op}_with_hornetseye" do |a,b| if a.matched? or b.matched? a = Node.match(a, b).new a unless a.matched? b = Node.match(b, a).new b unless b.matched? if a.dimension == 0 and a.variables.empty? and b.dimension == 0 and b.variables.empty? target = a.typecode.send coercion, b.typecode target.new mod.send(op, a.simplify.get, b.simplify.get) else Hornetseye::ElementWise( proc { |x,y| mod.send op, x, y }, "#{mod}.#{op}", proc { |t,u| t.send coercion, u } ). new(a, b).force end else send "#{op}_without_hornetseye", a, b end end alias_method_chain op, :hornetseye module_function "#{op}_without_hornetseye" module_function op end end |
.define_unary_method(mod, op, conversion = :identity) ⇒ Proc
Extend unary method with capability to handle arrays
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/multiarray/methods.rb', line 58 def define_unary_method( mod, op, conversion = :identity ) mod.module_eval do define_method "#{op}_with_hornetseye" do |a| if a.matched? if a.dimension == 0 and a.variables.empty? target = a.typecode.send conversion target.new mod.send( op, a.simplify.get ) else Hornetseye::ElementWise( proc { |x| mod.send op, x }, "#{mod}.#{op}", proc { |x| x.send conversion } ). new(a).force end else send "#{op}_without_hornetseye", a end end alias_method_chain op, :hornetseye module_function "#{op}_without_hornetseye" module_function op end end |
.included(mod) ⇒ Object
Extend some methods in the specified module
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/multiarray/methods.rb', line 29 def Methods.included( mod ) define_unary_method mod, :sqrt , :float define_unary_method mod, :log , :float define_unary_method mod, :log10, :float define_unary_method mod, :exp , :float define_unary_method mod, :cos , :float define_unary_method mod, :sin , :float define_unary_method mod, :tan , :float define_unary_method mod, :acos , :float define_unary_method mod, :asin , :float define_unary_method mod, :atan , :float define_unary_method mod, :cosh , :float define_unary_method mod, :sinh , :float define_unary_method mod, :tanh , :float define_unary_method mod, :acosh, :float define_unary_method mod, :asinh, :float define_unary_method mod, :atanh, :float define_binary_method mod, :atan2, :floating define_binary_method mod, :hypot, :floating end |