tensor_stream 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 5adc4dd6bb2c50782e1f0463723d18e395cc0d72480fc79e80df1e0b1e0f1a52
4
- data.tar.gz: 64ebe439640a9cb4281b73da9b9c0830b7a8ef722fd7c50582179cab84f1c7e3
2
+ SHA1:
3
+ metadata.gz: fdcfc961fddc348440126986de425c0b1784c235
4
+ data.tar.gz: 35649e38711773b0caf91ed791166cc8a733c2a4
5
5
  SHA512:
6
- metadata.gz: 04b240ea9ea146fc3db61f1ebbe75c63f1cc1c4c425b27b8cce239a4d900d74466c81c92f0282ca099c2061078096f00a80c2bf1019bcadc80c7da7e3b7edfe1
7
- data.tar.gz: e2e8fa75f95c2e4a442d66c95f1e17dcea881c4dc52d7c5a43fdf2a720bea2b1ccc6d3dbc3c359492ba6959fbcb727e91974d79f25a86255f6edff1ccf04b429
6
+ metadata.gz: a2ac76af196eab64d2fadd327e724fd927f3de52d2fd1043896299f95022f92c5c5d833d0d18ed16ce1b5acac1fb29d292bb73f4036a15265ddea662af87a09c
7
+ data.tar.gz: bd0b0b4078bd9d347e984bc2dde41952cd268b75d5697a1f7b722792fc171ff19bb9aebc41ec0199c092494f1aa9e0e3f9e635d848cf0e7cdb68b132ce66ebd7
data/README.md CHANGED
@@ -114,7 +114,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
114
114
 
115
115
  ## Contributing
116
116
 
117
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cl-brains. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
117
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tensor_stream. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
118
118
 
119
119
 
120
120
  ## License
@@ -262,6 +262,16 @@ module TensorStream
262
262
  b = complete_eval(b, child_context)
263
263
 
264
264
  call_vector_op(:greater, a, b, child_context, ->(t, u) { t > u })
265
+ when :greater_equal
266
+ a = complete_eval(a, child_context)
267
+ b = complete_eval(b, child_context)
268
+
269
+ call_vector_op(:greater_equal, a, b, child_context, ->(t, u) { t >= u })
270
+ when :less_equal
271
+ a = complete_eval(a, child_context)
272
+ b = complete_eval(b, child_context)
273
+
274
+ call_vector_op(:less_equal, a, b, child_context, ->(t, u) { t <= u })
265
275
  when :zeros, :ones, :zeros_like, :ones_like
266
276
 
267
277
  shape = if %i[zeros_like ones_like].include?(tensor.operation)
@@ -309,24 +319,7 @@ module TensorStream
309
319
 
310
320
  (Matrix[*matrix_a] * Matrix[*matrix_b]).to_a
311
321
  when :gradients
312
- b.collect do |xs|
313
- fail "#{xs} passed is not a tensor object" unless xs.is_a?(Tensor)
314
- xs_val = complete_eval(xs, child_context)
315
- target_shape = shape_eval(xs_val)
316
-
317
- stops = tensor.options[:stop_gradients] ? tensor.options[:stop_gradients].map(&:name).join('_') : ''
318
- gradient_program_name = "grad_#{tensor.name}_#{xs.name}_#{stops}".to_sym
319
-
320
- tensor_program = if tensor.graph.node_added?(gradient_program_name)
321
- tensor.graph.get_node(gradient_program_name)
322
- else
323
- derivative_ops = TensorStream::MathGradients.derivative(a, xs, graph: tensor.graph, stop_gradients: tensor.options[:stop_gradients], target_shape: target_shape)
324
- unit_matrix = op(:ones_like, xs)
325
- tensor.graph.add_node!(gradient_program_name, unit_matrix * derivative_ops)
326
- end
327
-
328
- complete_eval(tensor_program, child_context)
329
- end
322
+ fail "not implemented in evaluator"
330
323
  when :identity
331
324
  complete_eval(a, child_context)
332
325
  when :print
@@ -7,11 +7,10 @@ module TensorStream
7
7
  gradient_program_name = "_grad_#{tensor.name}_#{dx.name}"
8
8
  return options[:graph].get_node(gradient_program_name) if options[:graph] && options[:graph].node_added?(gradient_program_name)
9
9
 
10
- target_shape = options[:target_shape]
11
10
  constant_options = { dtype: options[:dtype] }
12
- constant_options_1 = { dtype: options[:dtype] || tensor.data_type, shape: target_shape }
11
+ constant_options_1 = { dtype: options[:dtype] || tensor.data_type }
13
12
 
14
- return i_cons(1, constant_options_1) if tensor.equal?(dx)
13
+ return i_op(:ones_like, dx, constant_options_1) if tensor.equal?(dx)
15
14
  return i_cons(0, constant_options) if options[:stop_gradients] && _include?(options[:stop_gradients], tensor)
16
15
 
17
16
  if tensor.is_a?(Operation)
@@ -85,8 +84,8 @@ module TensorStream
85
84
  tensor_shape1 = tensor.items[1].shape ? tensor.items[1].shape.shape : nil
86
85
  tensor_shape0 = tensor.items[0].shape ? tensor.items[0].shape.shape : nil
87
86
 
88
- derivative_a = derivative(tensor.items[0], dx, target_shape: target_shape)
89
- derivative_b = derivative(tensor.items[1], dx, target_shape: target_shape)
87
+ derivative_a = derivative(tensor.items[0], dx)
88
+ derivative_b = derivative(tensor.items[1], dx)
90
89
 
91
90
  s0 = i_op(:shape, tensor.items[0])
92
91
  s1 = i_op(:shape, tensor.items[1])
@@ -101,7 +100,7 @@ module TensorStream
101
100
  pad_zeros: true,
102
101
  name: 'matrix_dy')
103
102
 
104
- zero_vect = i_op(:zeros, target_shape, nil, name: 'zero_vect')
103
+ zero_vect = i_op(:zeros_like, dx, nil, name: 'zero_vect')
105
104
 
106
105
  # matmul_db = op(:transpose, matmul_db, nil).first
107
106
 
@@ -8,14 +8,30 @@ module TensorStream
8
8
  end
9
9
 
10
10
  def gradients(ys, xs, grad_ys: nil,
11
- name: 'gradients',
12
- colocate_gradients_with_ops: false,
13
- gate_gradients: false,
14
- aggregation_method: nil,
15
- stop_gradients: nil
16
- )
17
- options = { stop_gradients: stop_gradients}
18
- op(:gradients, ys, xs, options)
11
+ name: 'gradients',
12
+ colocate_gradients_with_ops: false,
13
+ gate_gradients: false,
14
+ aggregation_method: nil,
15
+ stop_gradients: nil
16
+ )
17
+
18
+ gs = xs.collect do |x|
19
+ fail "#{x} passed is not a tensor object" unless x.is_a?(Tensor)
20
+
21
+ stops = stop_gradients ? stop_gradients.map(&:name).join('_') : ''
22
+ gradient_program_name = "grad_#{ys.name}_#{x.name}_#{stops}".to_sym
23
+
24
+ tensor_program = if ys.graph.node_added?(gradient_program_name)
25
+ ys.graph.get_node(gradient_program_name)
26
+ else
27
+ derivative_ops = TensorStream::MathGradients.derivative(ys, x, graph: ys.graph,
28
+ stop_gradients: stop_gradients)
29
+ unit_matrix = op(:ones_like, x)
30
+ ys.graph.add_node!(gradient_program_name, unit_matrix * derivative_ops)
31
+ end
32
+ tensor_program
33
+ end
34
+ TensorStream.group(gs)
19
35
  end
20
36
 
21
37
  def random_uniform(shape, dtype: :float32, minval: 0, maxval: 1, seed: nil, name: nil)
@@ -67,6 +83,14 @@ module TensorStream
67
83
  def greater(a, b, name: nil)
68
84
  op(:greater, a, b, name: name)
69
85
  end
86
+
87
+ def greater_equal(a, b, name: nil)
88
+ op(:greater_equal, a, b, name: name)
89
+ end
90
+
91
+ def less_equal(a, b, name: nil)
92
+ op(:less_equal, a, b, name: name)
93
+ end
70
94
 
71
95
  def reduce_mean(input_tensor, axis = nil, keepdims: false, name: nil)
72
96
  op(:reduce_mean, input_tensor, nil, axis: axis, keepdims: keepdims, name: name)
@@ -133,10 +133,6 @@ module TensorStream
133
133
  op(:not_equal, self, operand)
134
134
  end
135
135
 
136
- def <=(operand)
137
- op(:less_equal, self, operand)
138
- end
139
-
140
136
  def >(operand)
141
137
  op(:greater, self, operand)
142
138
  end
@@ -145,6 +141,10 @@ module TensorStream
145
141
  op(:greater_equal, self, operand)
146
142
  end
147
143
 
144
+ def <=(operand)
145
+ op(:less_equal, self, operand)
146
+ end
147
+
148
148
  def collect(&block)
149
149
  @value.collect(&block)
150
150
  end
@@ -1,5 +1,5 @@
1
1
  module TensorStream
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
 
4
4
  def self.version
5
5
  VERSION
metadata CHANGED
@@ -1,108 +1,108 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tensor_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Emmanuel Dayo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: bundler
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: '1.14'
19
- name: bundler
20
- prerelease: false
21
20
  type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.14'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: rake
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - "~>"
31
32
  - !ruby/object:Gem::Version
32
33
  version: '10.0'
33
- name: rake
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rspec
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '3.0'
47
- name: rspec
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: awesome_print
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - ">="
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
- name: awesome_print
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: rubocop
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - ">="
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
- name: rubocop
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
+ name: deep_merge
84
85
  requirement: !ruby/object:Gem::Requirement
85
86
  requirements:
86
87
  - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
- name: deep_merge
90
- prerelease: false
91
90
  type: :runtime
91
+ prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
+ name: concurrent-ruby
98
99
  requirement: !ruby/object:Gem::Requirement
99
100
  requirements:
100
101
  - - ">="
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
- name: concurrent-ruby
104
- prerelease: false
105
104
  type: :runtime
105
+ prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
@@ -162,7 +162,7 @@ licenses:
162
162
  - MIT
163
163
  metadata:
164
164
  allowed_push_host: https://rubygems.org
165
- post_install_message:
165
+ post_install_message:
166
166
  rdoc_options: []
167
167
  require_paths:
168
168
  - lib
@@ -177,9 +177,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  requirements: []
180
- rubyforge_project:
181
- rubygems_version: 2.6.13
182
- signing_key:
180
+ rubyforge_project:
181
+ rubygems_version: 2.6.11
182
+ signing_key:
183
183
  specification_version: 4
184
184
  summary: A Pure ruby tensorflow implementation
185
185
  test_files: []