Class: LazyBinaryOperator

Inherits:
BinaryOperator show all
Defined in:
lib/mdarray/lazy_operators.rb

Instance Attribute Summary collapse

Attributes inherited from Operator

#arity, #exec_type, #fmap, #force_type, #helper, #name, #other_args, #post_condition, #pre_condition, #type

Instance Method Summary collapse

Methods inherited from BinaryOperator

#initialize

Methods inherited from Operator

#exec, #initialize

Constructor Details

This class inherits a constructor from BinaryOperator

Instance Attribute Details

#expObject (readonly)

expression in string format



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

def exp
  @exp
end

Instance Method Details

#complex_reduce(*args) ⇒ Object





104
105
106
# File 'lib/mdarray/lazy_operators.rb', line 104

def complex_reduce(*args)
  raise "Cannot reduce array in lazy operation"
end

#default(*args) ⇒ Object


A default binary operator takes two arrays where one array can be degenerated (a number and loops through all elements of the arrays applying a given method to them.

For instance, operator ‘+’ in a + b is a default binary operator.




50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/mdarray/lazy_operators.rb', line 50

def default(*args)

  get_args(*args)
  lazy = @op1

  if (@op1.is_a? LazyMDArray)
    lazy.push(@op2)
    lazy.push(self)
    # @exp << "(" << @op1.exp << name << @op2.id << ")"
  else
    lazy = LazyMDArray.new
    lazy.push(@op1)
    lazy.push(@op2)
    lazy.push(self)
    # p @op1.id
    # p @op2.id
    # p @name
    # @exp << "(" << @op1.id << name << @op2.id << ")"
  end

  return lazy

end

#fill(*args) ⇒ Object


A fill binary operator takes two arrays where one array can be degenerated (a number) and loops through all elements of the arrays, setting the value of the first array to the values of the second.




80
81
82
# File 'lib/mdarray/lazy_operators.rb', line 80

def fill(*args)
  raise "Cannot fill array lazyly"
end

#get_args(*args) ⇒ Object





35
36
37
38
39
40
41
42
# File 'lib/mdarray/lazy_operators.rb', line 35

def get_args(*args)

  @op1 = args.shift
  @op2 = args.shift
  @other_args = args
  @exp = ""

end

#in_place(*args) ⇒ Object





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

def in_place(*args)
  raise "Cannot operate in_place lazyly"
end

#reduce(*args) ⇒ Object





96
97
98
# File 'lib/mdarray/lazy_operators.rb', line 96

def reduce(*args)
  raise "Cannot reduce array in lazy operation"
end