Module: RubyFunctions

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.binary_helperObject (readonly)

Returns the value of attribute binary_helper.



29
30
31
# File 'lib/mdarray/ruby_functions.rb', line 29

def binary_helper
  @binary_helper
end

.unary_helperObject (readonly)

Returns the value of attribute unary_helper.



30
31
32
# File 'lib/mdarray/ruby_functions.rb', line 30

def unary_helper
  @unary_helper
end

Instance Method Details

#make_binary_operator(name, type, func) ⇒ Object


Creates a single type of method.




57
58
59
# File 'lib/mdarray/ruby_functions.rb', line 57

def make_binary_operator(name, type, func)
  make_binary_op(name, type, func, RubyFunctions.binary_helper)
end

#make_binary_operators(name, func, default = true, in_place = true) ⇒ Object


Creates the default and in_place type of methods. The default method will generate a new array as result and the implace method will overwrite the first array with the result.




42
43
44
45
46
47
48
49
50
51
# File 'lib/mdarray/ruby_functions.rb', line 42

def make_binary_operators(name, func, default = true, in_place = true)

  if (default)
    make_binary_op(name, :default, func, RubyFunctions.binary_helper)
  end
  if (in_place)
    make_binary_op(name + "!", :in_place, func, RubyFunctions.binary_helper)
  end

end

#make_comparison_operator(name, func) ⇒ Object





90
91
92
93
94
95
96
97
98
99
# File 'lib/mdarray/ruby_functions.rb', line 90

def make_comparison_operator(name, func)

  make_binary_op("_#{name}", "default", func, RubyFunctions.binary_helper, "boolean")

  define_method(name) do |op2, requested_type = nil, *args|
    return false if op2 == nil
    self.send("_#{name}", op2, requested_type, *args)
  end

end

#make_unary_operator(name, type, func) ⇒ Object


Creates a single type of method.




82
83
84
# File 'lib/mdarray/ruby_functions.rb', line 82

def make_unary_operator(name, type, func)
  make_unary_op(name, type, func, RubyFunctions.unary_helper)
end

#make_unary_operators(name, func, default = true, in_place = true) ⇒ Object


Creates the default and in_place type of methods. The default method will generate a new array as result and the implace method will overwrite the first array with the result.




67
68
69
70
71
72
73
74
75
76
# File 'lib/mdarray/ruby_functions.rb', line 67

def make_unary_operators(name, func, default = true, in_place = true)

  if (default)
    make_unary_op(name, :default, func, RubyFunctions.unary_helper)
  end
  if (in_place)
    make_unary_op(name + "!", :in_place, func, RubyFunctions.unary_helper)
  end

end

#ruby_binary_function(long_name, proc) ⇒ Object





105
106
107
# File 'lib/mdarray/ruby_functions.rb', line 105

def ruby_binary_function(long_name, proc)
  [long_name, "RubyFunctions", proc, "*", "*", "*"]
end

#ruby_unary_function(long_name, proc) ⇒ Object





113
114
115
# File 'lib/mdarray/ruby_functions.rb', line 113

def ruby_unary_function(long_name, proc)
  [long_name, "RubyFunctions", proc, "*", "*", "*"]
end