Class: LazyMDArray
- Inherits:
-
ByteMDArray
- Object
- MDArray
- NumericalMDArray
- DoubleMDArray
- FloatMDArray
- LongMDArray
- IntMDArray
- ShortMDArray
- ByteMDArray
- LazyMDArray
- Defined in:
- lib/mdarray/lazy_mdarray.rb
Defined Under Namespace
Classes: BinaryComp, UnaryComp
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Attributes inherited from DoubleMDArray
Attributes inherited from MDArray
#binary_operator, #coerced, #float_output_precision, #float_output_suppress_small, #formatter, #id, #inf_str, #int_output_size, #local_index, #local_iterator, #max_line_width, #nan_str, #nc_array, #prefix, #separator, #summary_edge_items, #summary_threshold, #type, #unary_operator
Instance Method Summary collapse
-
#apply(*args) ⇒ Object
(also: #[])
—————————————————————————————.
-
#initialize ⇒ LazyMDArray
constructor
—————————————————————————————.
-
#pop ⇒ Object
—————————————————————————————.
-
#print ⇒ Object
—————————————————————————————.
-
#push(elmt) ⇒ Object
—————————————————————————————.
-
#rpn(nl = true) ⇒ Object
————————————————————————————— Shows this LazyMDArray in Reverse Polish Notation.
-
#test_janino_function ⇒ Object
—————————————————————————————.
Methods included from CernIntFunctions
Methods included from FunctionCreation
#make_binary_op, #make_unary_op
Methods included from CernFunctions
#cern_binary_function, #cern_comparison_function, #cern_unary_function, #make_binary_operator, #make_binary_operators, #make_comparison_operator, #make_unary_operator, #make_unary_operators
Methods included from CernLongFunctions
Methods included from RubyFunctions
#make_binary_operator, #make_binary_operators, #make_comparison_operator, #make_unary_operator, #make_unary_operators, #ruby_binary_function, #ruby_unary_function
Methods included from CernFloatFunctions
Methods inherited from DoubleMDArray
Methods included from CernDoubleFunctions
Methods inherited from NumericalMDArray
Methods included from NumericFunctions
Methods inherited from MDArray
#[]=, #apply_over_axes, arange, boolean, build, build_from_nc_array, byte, calc_value, char, #compatible, #copy, #csv1d, double, #dtype, #each, #each_cont, #each_slice, #each_with_counter, #flip, float, from_jstorage, fromfunction, function_map_to_csv, #get, #get_as, #get_binary_op, #get_counter, #get_current_index, #get_element_type, #get_index, #get_iterator_fast, #get_next, #get_rank, #get_scalar, #get_shape, #get_size, #get_unary_op, #immutable, init_with, int, #jget, lazy=, linspace, long, make_binary_op, make_unary_op, #ndenumerate, #ndim, #next, ones, #permute, #print0d, #print1d, print_function_map, #printing_defaults, #rank, #reduce, #region, register_function, #reset_traversal, #reshape, #reshape!, rstring, #section, #section?, #section_with_stride, select_function, #set, set_lazy, #set_next, #set_scalar, #shape, short, #size, #slice, string, structure, #to_csv, #to_s, #to_string, #transpose, typed_arange, upcast
Constructor Details
#initialize ⇒ LazyMDArray
82 83 84 85 86 87 88 89 |
# File 'lib/mdarray/lazy_mdarray.rb', line 82 def initialize @stack = Array.new @type = "lazy" @previous_binary_operator = nil @previous_unary_operator = nil end |
Instance Attribute Details
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
32 33 34 |
# File 'lib/mdarray/lazy_mdarray.rb', line 32 def stack @stack end |
Instance Method Details
#apply(*args) ⇒ Object Also known as: []
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/mdarray/lazy_mdarray.rb', line 127 def apply(*args) type, shape, function = validate_fast(args) result = MDArray.build(type, shape) helper = Java::RbMdarrayLoopsLazy::DefaultLazyOperator helper.send("apply", result.nc_array, function) result end |
#pop ⇒ Object
103 104 105 |
# File 'lib/mdarray/lazy_mdarray.rb', line 103 def pop @stack.pop end |
#print ⇒ Object
172 173 174 175 |
# File 'lib/mdarray/lazy_mdarray.rb', line 172 def print Kernel.print "[Lazy MDArray]\n" p rpn end |
#push(elmt) ⇒ Object
95 96 97 |
# File 'lib/mdarray/lazy_mdarray.rb', line 95 def push(elmt) @stack << elmt end |
#rpn(nl = true) ⇒ Object
Shows this LazyMDArray in Reverse Polish Notation. Mainly for debugging purposes.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/mdarray/lazy_mdarray.rb', line 144 def rpn(nl = true) exp = String.new @stack.each do |elmt| if (elmt.is_a? LazyMDArray) exp << elmt.rpn(false) elsif (elmt.is_a? Numeric) exp << elmt << " " elsif (elmt.is_a? Operator) exp << elmt.name << " " elsif (elmt.is_a? MDArray) exp << elmt.type << " " else raise "Wrong element type in Array" end end exp end |
#test_janino_function ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mdarray/lazy_mdarray.rb', line 111 def test_janino_function $exp = ExpressionEvaluator.new $exp.setExpressionType(Java::CernColtFunctionTdouble::DoubleFunction.java_class) class_type = Java::JavaLang::Class.forName("java.lang.Class") array = Java::JavaLangReflect::Array.newInstance(class_type, 2) array[0] = Java::double.java_class array[1] = Java::double.java_class $exp.setParameters(["a", "b"].to_java(:string), array) $exp.cook("a + b") end |