Class: Operator

Inherits:
Object
  • Object
show all
Defined in:
lib/mdarray/operators.rb

Direct Known Subclasses

BinaryOperator, UnaryOperator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, arity, exec_type, force_type = nil, pre_condition = nil, post_condition = nil) ⇒ Operator





98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/mdarray/operators.rb', line 98

def initialize(name, arity, exec_type, force_type = nil, pre_condition = nil, 
               post_condition = nil)

  @name = name
  @arity = arity
  @exec_type = exec_type
  @helper = nil
  @force_type = force_type
  @pre_condition = pre_condition  # proc to be executed before the main loop
  @pre_condition_result = nil
  @post_condition = post_condition # proc to be executed after the main loop

end

Instance Attribute Details

#arityObject (readonly)

number of arguments to the operator



85
86
87
# File 'lib/mdarray/operators.rb', line 85

def arity
  @arity
end

#exec_typeObject (readonly)

type of operator execution, e.g., default, in_place, numeric



86
87
88
# File 'lib/mdarray/operators.rb', line 86

def exec_type
  @exec_type
end

#fmapObject (readonly)

function map for this operator



88
89
90
# File 'lib/mdarray/operators.rb', line 88

def fmap
  @fmap
end

#force_typeObject (readonly)

force this type as the result type



89
90
91
# File 'lib/mdarray/operators.rb', line 89

def force_type
  @force_type
end

#helperObject (readonly)

helper method for this operator



87
88
89
# File 'lib/mdarray/operators.rb', line 87

def helper
  @helper
end

#nameObject (readonly)

Returns the value of attribute name.



83
84
85
# File 'lib/mdarray/operators.rb', line 83

def name
  @name
end

#other_argsObject (readonly)

list of arguments to the operator other than the operands



92
93
94
# File 'lib/mdarray/operators.rb', line 92

def other_args
  @other_args
end

#post_conditionObject (readonly)

proc to be executed after the operator’s execution



91
92
93
# File 'lib/mdarray/operators.rb', line 91

def post_condition
  @post_condition
end

#pre_conditionObject (readonly)

proc to be executed before the operator’s execution



90
91
92
# File 'lib/mdarray/operators.rb', line 90

def pre_condition
  @pre_condition
end

#typeObject (readonly)

resulting type of the operation



84
85
86
# File 'lib/mdarray/operators.rb', line 84

def type
  @type
end

Instance Method Details

#exec(*args) ⇒ Object





116
117
118
119
120
121
122
# File 'lib/mdarray/operators.rb', line 116

def exec(*args)

  @pre_condition_result = @pre_condition.call(*args) if @pre_condition
  result = method(@exec_type).call(*args)
  (@post_condition)? @post_condition.call(result, *args) : result

end