Class: TensorStream::Evaluator::RubyEvaluator

Inherits:
BaseEvaluator show all
Includes:
ArrayOpsHelper, MathHelper, OpHelper
Defined in:
lib/tensor_stream/evaluator/ruby_evaluator.rb

Overview

PURE ruby evaluator used for testing and development

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MathHelper

#sigmoid

Methods included from ArrayOpsHelper

#broadcast, #broadcast_dimensions, #get_rank, #process_function_op, #reduced_shape, #shape_diff, #slice_tensor, #softmax, #softmax_grad, #tile_arr, #truncate, #vector_op

Methods included from OpHelper

#_op, #cons, #dtype_eval, #format_source, #fp_type?, #i_cons, #i_op, #shape_eval, #val_to_dtype

Methods inherited from BaseEvaluator

default_device, fetch_device, #initialize, #invoke, ops, query_device, query_supported_devices, register_op

Constructor Details

This class inherits a constructor from TensorStream::Evaluator::BaseEvaluator

Instance Attribute Details

#retainObject

Returns the value of attribute retain.



27
28
29
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 27

def retain
  @retain
end

Instance Method Details

#complete_eval(tensor, context) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 61

def complete_eval(tensor, context)
  Kernel.loop do
    old_tensor = tensor
    tensor = run(tensor, context)

    tensor = tensor.map { |t| complete_eval(t, context) } if tensor.is_a?(Array) && !tensor.empty? && tensor[0].is_a?(Tensor)

    return tensor if old_tensor.equal?(tensor)
    return tensor unless tensor.is_a?(Tensor)
  end
end

#run(tensor, execution_context) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 33

def run(tensor, execution_context)
  if tensor.is_a?(Array) && tensor.size > 0 && tensor[0].is_a?(Tensor)
    return tensor.map { |t| run(t, execution_context) }
  end

  tensor = tensor.call if tensor.is_a?(Proc)

  child_context = execution_context.dup
  res = if tensor.is_a?(Operation)
          eval_operation(tensor, child_context)
        elsif tensor.is_a?(Variable)
          eval_variable(tensor, child_context)
        elsif tensor.is_a?(Placeholder)
          resolve_placeholder(tensor, child_context)
        else
          eval_tensor(tensor, child_context)
        end
  execution_context.deep_merge!(returns: child_context[:returns])
  res
end

#run_with_buffer(tensor, context, execution_context) ⇒ Object



54
55
56
57
58
59
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 54

def run_with_buffer(tensor, context, execution_context)
  @context = context
  @context[:_cache][:_cl_buffers] ||= {} if context[:_cache]
  result = run(tensor, execution_context)
  TensorStream::Buffer.new(data_type: tensor.data_type, buffer: result)
end