Class: TensorStream::VariableScope

Inherits:
Object
  • Object
show all
Includes:
OpHelper
Defined in:
lib/tensor_stream/variable_scope.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Constructor Details

#initialize(name: nil, reuse: nil, initializer: nil) ⇒ VariableScope

Returns a new instance of VariableScope.



7
8
9
10
11
12
# File 'lib/tensor_stream/variable_scope.rb', line 7

def initialize(name: nil, reuse: nil, initializer: nil)
  @name = name
  @reuse = reuse
  @initializer = initializer
  @used_names = []
end

Instance Attribute Details

#initializerObject

Returns the value of attribute initializer.



4
5
6
# File 'lib/tensor_stream/variable_scope.rb', line 4

def initializer
  @initializer
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/tensor_stream/variable_scope.rb', line 4

def name
  @name
end

#reuseObject

Returns the value of attribute reuse.



4
5
6
# File 'lib/tensor_stream/variable_scope.rb', line 4

def reuse
  @reuse
end

#used_namesObject (readonly)

Returns the value of attribute used_names.



5
6
7
# File 'lib/tensor_stream/variable_scope.rb', line 5

def used_names
  @used_names
end

Instance Method Details

#get_variable(name, dtype: nil, shape: nil, initializer: nil, trainable: true, collections: nil, validate_shape: false) ⇒ Object



14
15
16
17
18
# File 'lib/tensor_stream/variable_scope.rb', line 14

def get_variable(name, dtype: nil, shape: nil, initializer: nil, trainable: true, collections: nil, validate_shape: false)
  raise TensorStream::ValueError, "validate_shape=true and initializer does not have a defined shape" if validate_shape && !shape.nil && initializer.is_a?(Tensor)

  i_var(dtype || :float32, nil, shape, self, collections: collections, name: name, initializer: initializer, trainable: trainable)
end

#register_name(name) ⇒ Object



20
21
22
# File 'lib/tensor_stream/variable_scope.rb', line 20

def register_name(name)
  @used_names << name unless @used_names.include?(name)
end