Class: TensorStream::Evaluator::RubyEvaluator

Inherits:
BaseEvaluator show all
Includes:
ArrayOps, ArrayOpsHelper, CheckOps, ImagesOps, MathHelper, MathOps, NNOps, OpHelper, RandomOps, VariableOps
Defined in:
lib/tensor_stream/evaluator/ruby_evaluator.rb

Overview

PURE ruby evaluator used for testing and development

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from VariableOps

included

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, #array_set!, #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, #strided_slice, #strided_slice_grad, #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.



35
36
37
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 35

def retain
  @retain
end

Class Method Details

.get_storage_managerObject



48
49
50
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 48

def self.get_storage_manager
  RubyStorageManager.current_storage_manager
end

Instance Method Details

#complete_eval(tensor, context) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 76

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 : tensor
end

#run(tensor, execution_context) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 52

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



69
70
71
72
73
74
# File 'lib/tensor_stream/evaluator/ruby_evaluator.rb', line 69

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