Class: TensorStream::Evaluator::RubyEvaluator

Inherits:
BaseEvaluator show all
Includes:
ArrayOps, ArrayOpsHelper, CheckOps, ImagesOps, MathHelper, MathOps, NNOps, OpHelper, RandomOps
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 CheckOps

included

Methods included from ImagesOps

included

Methods included from RandomOps

included

Methods included from ArrayOps

included

Methods included from NNOps

included

Methods included from MathOps

included

Methods included from MathHelper

#sigmoid

Methods included from ArrayOpsHelper

#_reduced_shape, #arr_pad, #broadcast, #broadcast_dimensions, #deep_dup_array, #gather, #get_rank, #last_axis, #process_function_op, #reduce, #reduce_axis, #shape_diff, #slice_tensor, #softmax, #softmax_grad, #split_tensor, #tile_arr, #transpose_with_perm, #truncate, #vector_op

Methods included from OpHelper

#_op, #cons, #format_source, #fp_type?, #i_cons, #i_op, #i_var, #int_type?, #reduced_shape, #shape_eval, #shape_full_specified, #shapes_fully_specified_and_equal

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.



33
34
35
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 33

def retain
  @retain
end

Instance Method Details

#complete_eval(tensor, context) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 69

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)

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

  tensor.is_a?(OutputGroup) ? tensor.outputs[0] : tensor
end

#run(tensor, execution_context) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 45

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

  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?(Tensor)
          tensor
        else
          tensor.op
        end
  execution_context.deep_merge!(returns: child_context[:returns])
  res
end

#run_with_buffer(tensor, context, execution_context) ⇒ Object



62
63
64
65
66
67
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 62

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