Class: TensorStream::Variable
- Inherits:
-
Tensor
- Object
- Tensor
- TensorStream::Variable
show all
- Defined in:
- lib/tensor_stream/variable.rb
Overview
Class that defines a TensorStream variable
Instance Attribute Summary collapse
Attributes inherited from Tensor
#breakpoint, #data_type, #given_name, #graph, #internal, #is_const, #name, #native_buffer, #rank, #shape, #source, #value
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Tensor
#!=, #*, #**, #+, #-, #-@, #/, #<, #<=, #==, #>, #>=, #[], #auto_math, #breakpoint!, cast_dtype, #collect, detect_type, #dtype, #eval, #first, #internal?, reset_counters, #to_a, #to_f, #to_h, #to_i, #to_s
Methods included from OpHelper
#cons, #dtype_eval, #fp_type?, #i_cons, #i_op, #op, #shape_eval, #val_to_dtype
Constructor Details
#initialize(data_type, rank, shape, options = {}) ⇒ Variable
Returns a new instance of Variable.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/tensor_stream/variable.rb', line 5
def initialize(data_type, rank, shape, options = {})
@graph = options[:graph] || TensorStream.get_default_graph
@data_type = data_type
@rank = rank
@shape = TensorShape.new(shape, rank)
@value = nil
@source = format_source(caller_locations)
@name = options[:name] || build_name
@initalizer_tensor = options[:initializer] if options[:initializer]
@trainable = options.fetch(:trainable, true)
@graph.add_variable(self, options)
end
|
Instance Attribute Details
#trainable ⇒ Object
Returns the value of attribute trainable.
4
5
6
|
# File 'lib/tensor_stream/variable.rb', line 4
def trainable
@trainable
end
|
Class Method Details
.global_variables_initializer ⇒ Object
49
50
51
|
# File 'lib/tensor_stream/variable.rb', line 49
def self.global_variables_initializer
variables_initializer(TensorStream::GraphKeys::GLOBAL_VARIABLES)
end
|
.variables_initializer(collection) ⇒ Object
45
46
47
|
# File 'lib/tensor_stream/variable.rb', line 45
def self.variables_initializer(collection)
TensorStream.group(TensorStream.get_default_graph.get_collection(collection).map(&:initializer))
end
|
Instance Method Details
#assign(value) ⇒ Object
25
26
27
|
# File 'lib/tensor_stream/variable.rb', line 25
def assign(value)
Operation.new(:assign, self, value)
end
|
#assign_add(value) ⇒ Object
33
34
35
|
# File 'lib/tensor_stream/variable.rb', line 33
def assign_add(value)
Operation.new(:assign_add, self, value)
end
|
#assign_sub(value) ⇒ Object
41
42
43
|
# File 'lib/tensor_stream/variable.rb', line 41
def assign_sub(value)
Operation.new(:assign_sub, self, value)
end
|
#initializer ⇒ Object
20
21
22
23
|
# File 'lib/tensor_stream/variable.rb', line 20
def initializer
@initalizer_tensor.shape = @shape
assign(@initalizer_tensor)
end
|
#read_value ⇒ Object
29
30
31
|
# File 'lib/tensor_stream/variable.rb', line 29
def read_value
@value
end
|
#to_math(_tensor, _name_only = false, _max_depth = 99) ⇒ Object
37
38
39
|
# File 'lib/tensor_stream/variable.rb', line 37
def to_math(_tensor, _name_only = false, _max_depth = 99)
@name
end
|