Module: CNTK::VariableExtend

Included in:
Constant, Parameter
Defined in:
lib/cntk/variable.rb

Instance Method Summary collapse

Instance Method Details

#create_from(val, shape, dtype, device, name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cntk/variable.rb', line 58

def create_from(val, shape, dtype, device, name)
  case val
  when NDArrayView, Value, Variable, Numo::NArray
    if shape
      raise "can't accept #{val.class} and shape at the same time" 
    end
    case val
    when Variable
      new(val)
    when NDArrayView
      new(val, name)
    when Value
      new(val.data, name)
    else
      new(NDArrayView.create(val), name)
    end
  when Numeric, Dictionary
    if shape
      new(shape, dtype, val, device, name)
    else
      new([], dtype, val, device, name)
    end
  else
    raise ArgumentError, "NDArrayView, Value, Variable, Numo::NArray, Initializer, or Numeric expected"
  end
end