Class: TensorStream::Variable
- Inherits:
-
Tensor
- Object
- Tensor
- TensorStream::Variable
show all
- Defined in:
- lib/tensor_stream/variable.rb
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!, #build_buffer, cast_dtype, #collect, const_name, detect_type, #dtype, #eval, #first, #internal?, #open_cl_buffer, placeholder_name, reset_counters, #sync_cl_buffer, #to_a, #to_f, #to_h, #to_i, #to_s, var_name
Methods included from OpHelper
#cons, #dtype_eval, #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.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/tensor_stream/variable.rb', line 4
def initialize(data_type, rank, shape, options = {})
@data_type = data_type
@rank = rank
@shape = TensorShape.new(shape, rank)
@value = nil
@source = set_source(caller_locations)
@graph = options[:graph] || TensorStream.get_default_graph
@name = options[:name] || build_name
if options[:initializer]
@initalizer_tensor = options[:initializer]
end
@trainable = options.fetch(:trainable, true)
@graph.add_variable(self, options)
end
|
Instance Attribute Details
#trainable ⇒ Object
Returns the value of attribute trainable.
3
4
5
|
# File 'lib/tensor_stream/variable.rb', line 3
def trainable
@trainable
end
|
Class Method Details
.global_variables_initializer ⇒ Object
48
49
50
|
# File 'lib/tensor_stream/variable.rb', line 48
def self.global_variables_initializer
variables_initializer(TensorStream::GraphKeys::GLOBAL_VARIABLES)
end
|
.variables_initializer(collection) ⇒ Object
44
45
46
|
# File 'lib/tensor_stream/variable.rb', line 44
def self.variables_initializer(collection)
TensorStream.group(TensorStream.get_default_graph.get_collection(collection).map(&:initializer))
end
|
Instance Method Details
#assign(value) ⇒ Object
24
25
26
|
# File 'lib/tensor_stream/variable.rb', line 24
def assign(value)
Operation.new(:assign, self, value)
end
|
#assign_add(value) ⇒ Object
32
33
34
|
# File 'lib/tensor_stream/variable.rb', line 32
def assign_add(value)
Operation.new(:assign_add, self, value)
end
|
#assign_sub(value) ⇒ Object
40
41
42
|
# File 'lib/tensor_stream/variable.rb', line 40
def assign_sub(value)
Operation.new(:assign_sub, self, value)
end
|
#initializer ⇒ Object
19
20
21
22
|
# File 'lib/tensor_stream/variable.rb', line 19
def initializer
@initalizer_tensor.shape = @shape
assign(@initalizer_tensor)
end
|
#read_value ⇒ Object
28
29
30
|
# File 'lib/tensor_stream/variable.rb', line 28
def read_value
@value
end
|
#to_math(tensor, name_only = false, max_depth = 99) ⇒ Object
36
37
38
|
# File 'lib/tensor_stream/variable.rb', line 36
def to_math(tensor, name_only = false, max_depth = 99)
@name
end
|