tensorflow 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32ac7a47334631b2c5393721e5a7f848a26d9535b473557e146e8e6b4b6337be
4
- data.tar.gz: 21ca600101471ee43edd9a404f3072d67cbbdfa44f412ba8ec76a2546973087d
3
+ metadata.gz: 509b05a4a14e0bbb314c682f4172959b264e6709f92afc0fa0a749afccfe233b
4
+ data.tar.gz: daa060a1cb5c2602a652d87b75986a78a0d440c631b5fd7363e822363339f0ca
5
5
  SHA512:
6
- metadata.gz: 601c99ff6035138797f0e14a0f5f2c52ae68b4ee4c5223ef5676e45aaf2f61a7994f0a2ce2ad353b03fa503d7ad8fd6e9c49ba7567fbdcee2156bffe6d36a4c4
7
- data.tar.gz: 825d6b40f58f3cbe4d1c6f5b9cff5c7a739b730a89e025bf305bcdf3789269ce34f851709a0294d2c830ca1621a08ff3a67b352422bafd92eb8dec30f65e42e3
6
+ metadata.gz: '0755950b3b9865fe17a60efa970c23afcbbba33250b78e78bed7ddb907d90ecdfe64ffdd3fc48533ab6a30fbee6a64dbe6fd4d30e8554ca5c3f9535ea46e1daa'
7
+ data.tar.gz: 7307f84476cf789486a4f21328056a5abc5485a9dadeff99216dfa12f7a68c2b24f410fdb7caaca1c90a43d3497e03bb9459dbb876543819dce5e210afd02e3a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.1
2
+
3
+ - Added more operations
4
+ - Added support for more data types
5
+ - Added MNIST dataset
6
+
1
7
  ## 0.1.0
2
8
 
3
9
  - First release
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  [TensorFlow](https://github.com/tensorflow/tensorflow) - the end-to-end machine learning platform - for Ruby
4
4
 
5
- :fire: Uses the C API for blazing performance
5
+ :fire: Uses the C API under the hood
6
+
7
+ [![Build Status](https://travis-ci.org/ankane/tensorflow.svg?branch=master)](https://travis-ci.org/ankane/tensorflow)
6
8
 
7
9
  ## Installation
8
10
 
@@ -20,7 +22,7 @@ gem 'tensorflow'
20
22
 
21
23
  ## Getting Started
22
24
 
23
- This library follows the TensorFlow 2.0 [Python API](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf). Many methods and options are missing at the moment. PRs welcome!
25
+ This library follows the TensorFlow 2.0 [Python API](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf). Many methods and options are missing at the moment. Here’s the [current plan](https://github.com/ankane/tensorflow/issues/1). Additional PRs welcome!
24
26
 
25
27
  ## Constants
26
28
 
@@ -41,7 +43,6 @@ w = v + 1
41
43
 
42
44
  ```ruby
43
45
  def fizzbuzz(max_num)
44
- counter = Tf.constant(0)
45
46
  max_num.times do |i|
46
47
  num = Tf.constant(i + 1)
47
48
  if (num % 3).to_i == 0 && (num % 5).to_i == 0
@@ -91,9 +92,11 @@ Run:
91
92
  brew install tensorflow
92
93
  ```
93
94
 
95
+ Alternatively, download the [shared library](https://www.tensorflow.org/install/lang_c#download) and move the files in `lib` to `/usr/local/lib`.
96
+
94
97
  ### Linux
95
98
 
96
- Download the [shared library](https://www.tensorflow.org/install/lang_c#download) and move `libtensorflow.so` to `/usr/local/lib`.
99
+ Download the [shared library](https://www.tensorflow.org/install/lang_c#download) and move the files in `lib` to `/usr/local/lib`.
97
100
 
98
101
  ### Windows
99
102
 
@@ -9,8 +9,15 @@ module TensorFlow
9
9
  raise LoadError, "Could not find TensorFlow"
10
10
  end
11
11
 
12
+ class Buffer < ::FFI::Struct
13
+ layout :data, :pointer,
14
+ :length, :size_t,
15
+ :data_deallocator, :pointer
16
+ end
17
+
12
18
  # https://github.com/tensorflow/tensorflow/blob/master/tensorflow/c/c_api.h
13
19
  attach_function :TF_Version, %i[], :string
20
+ attach_function :TF_GetAllOpList, %i[], Buffer.by_ref
14
21
 
15
22
  # https://github.com/tensorflow/tensorflow/blob/master/tensorflow/c/tf_attrtype.h
16
23
  AttrType = enum(:string, :int, :float, :bool, :type, :shape, :tensor, :placeholder, :func)
@@ -0,0 +1,17 @@
1
+ module TensorFlow
2
+ module Keras
3
+ module Datasets
4
+ module MNIST
5
+ def self.load_data
6
+ # TODO verify hash
7
+ data = Utils.load_dataset(
8
+ "mnist.npz",
9
+ "https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz"
10
+ )
11
+
12
+ [[data["x_train"], data["y_train"]], [data["x_test"], data["y_test"]]]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module TensorFlow
2
+ module Keras
3
+ module Layers
4
+ class Dense
5
+ def initialize(units, activation: nil)
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module TensorFlow
2
+ module Keras
3
+ module Layers
4
+ class Dropout
5
+ def initialize(rate)
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module TensorFlow
2
+ module Keras
3
+ module Layers
4
+ class Flatten
5
+ def initialize(input_shape: nil)
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ module TensorFlow
2
+ module Keras
3
+ module Models
4
+ class Sequential
5
+ def initialize(layers = [])
6
+ @layers = []
7
+
8
+ layers.each do |layer|
9
+ add(layer)
10
+ end
11
+ end
12
+
13
+ def add(layer)
14
+ @layers << layer
15
+ end
16
+
17
+ def compile(optimizer: nil, loss: nil, metrics: nil)
18
+ raise "Not implemented"
19
+ end
20
+
21
+ def fit(x, y, epochs: nil)
22
+ raise "Not implemented"
23
+ end
24
+
25
+ def evaluate(x, y)
26
+ raise "Not implemented"
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,465 @@
1
+ module TensorFlow
2
+ module Math
3
+ class << self
4
+ def abs(x)
5
+ RawOps.abs(x: x)
6
+ end
7
+
8
+ # def accumulate_n
9
+ # end
10
+
11
+ def acos(x)
12
+ RawOps.acos(x: x)
13
+ end
14
+
15
+ def acosh(x)
16
+ RawOps.acosh(x: x)
17
+ end
18
+
19
+ def add(x, y)
20
+ RawOps.add(x: x, y: y)
21
+ end
22
+
23
+ def add_n(inputs)
24
+ RawOps.add_n(inputs: inputs)
25
+ end
26
+
27
+ def angle(input)
28
+ RawOps.angle(input: input)
29
+ end
30
+
31
+ # def argmax
32
+ # end
33
+
34
+ # def argmin
35
+ # end
36
+
37
+ def asin(x)
38
+ RawOps.asin(x: x)
39
+ end
40
+
41
+ def asinh(x)
42
+ RawOps.asinh(x: x)
43
+ end
44
+
45
+ def atan(x)
46
+ RawOps.atan(x: x)
47
+ end
48
+
49
+ def atan2(y, x)
50
+ RawOps.atan2(y: y, x: x)
51
+ end
52
+
53
+ def atanh(x)
54
+ RawOps.atanh(x: x)
55
+ end
56
+
57
+ # def bessel_i0
58
+ # end
59
+
60
+ def bessel_i0e(x)
61
+ RawOps.bessel_i0e(x: x)
62
+ end
63
+
64
+ # def bessel_i1
65
+ # end
66
+
67
+ def bessel_i1e(x)
68
+ RawOps.bessel_i1e(x: x)
69
+ end
70
+
71
+ def betainc(a, b, x)
72
+ RawOps.betainc(a: a, b: b, x: x)
73
+ end
74
+
75
+ def bincount(arr, size, weights)
76
+ RawOps.bincount(arr: arr, size: size, weights: weights)
77
+ end
78
+
79
+ def ceil(x)
80
+ RawOps.ceil(x: x)
81
+ end
82
+
83
+ # def confusion_matrix
84
+ # end
85
+
86
+ def conj(input)
87
+ RawOps.conj(input: input)
88
+ end
89
+
90
+ def cos(x)
91
+ RawOps.cos(x: x)
92
+ end
93
+
94
+ def cosh(x)
95
+ RawOps.cosh(x: x)
96
+ end
97
+
98
+ # def count_nonzero
99
+ # end
100
+
101
+ def cumprod(x, axis, exclusive: nil, reverse: nil)
102
+ RawOps.cumprod(x: x, axis: axis, exclusive: exclusive, reverse: reverse)
103
+ end
104
+
105
+ def cumsum(x, axis, exclusive: nil, reverse: nil)
106
+ RawOps.cumsum(x: x, axis: axis, exclusive: exclusive, reverse: reverse)
107
+ end
108
+
109
+ # def cumulative_logsumexp
110
+ # end
111
+
112
+ def digamma(x)
113
+ RawOps.digamma(x: x)
114
+ end
115
+
116
+ def divide(x, y)
117
+ RawOps.div(x: x, y: y)
118
+ end
119
+
120
+ # def divide_no_nan
121
+ # end
122
+
123
+ def equal(x, y)
124
+ RawOps.equal(x: x, y: y)
125
+ end
126
+
127
+ def erf(x)
128
+ RawOps.erf(x: x)
129
+ end
130
+
131
+ def erfc(x)
132
+ RawOps.erfc(x: x)
133
+ end
134
+
135
+ def exp(x)
136
+ RawOps.exp(x: x)
137
+ end
138
+
139
+ def expm1(x)
140
+ RawOps.expm1(x: x)
141
+ end
142
+
143
+ def floor(x)
144
+ RawOps.floor(x: x)
145
+ end
146
+
147
+ def floordiv(x, y)
148
+ RawOps.floor_div(x: x, y: y)
149
+ end
150
+
151
+ def floormod(x, y)
152
+ RawOps.floor_mod(x: x, y: y)
153
+ end
154
+
155
+ def greater(x, y)
156
+ RawOps.greater(x: x, y: y)
157
+ end
158
+
159
+ def greater_equal(x, y)
160
+ RawOps.greater_equal(x: x, y: y)
161
+ end
162
+
163
+ def igamma(a, x)
164
+ RawOps.igamma(a: a, x: x)
165
+ end
166
+
167
+ def igammac(a, x)
168
+ RawOps.igammac(a: a, x: x)
169
+ end
170
+
171
+ def imag(input)
172
+ RawOps.imag(input: input)
173
+ end
174
+
175
+ def in_top_k(predictions, targets, k: nil)
176
+ RawOps.in_top_k(predictions: predictions, targets: targets, k: k)
177
+ end
178
+
179
+ def invert_permutation(x)
180
+ RawOps.invert_permutation(x: x)
181
+ end
182
+
183
+ def is_finite(x)
184
+ RawOps.is_finite(x: x)
185
+ end
186
+
187
+ def is_inf(x)
188
+ RawOps.is_inf(x: x)
189
+ end
190
+
191
+ def is_nan(x)
192
+ RawOps.is_nan(x: x)
193
+ end
194
+
195
+ # def is_non_decreasing
196
+ # end
197
+
198
+ # def is_strictly_increasing
199
+ # end
200
+
201
+ # def l2_normalize
202
+ # end
203
+
204
+ # def lbeta
205
+ # end
206
+
207
+ def less(x, y)
208
+ RawOps.less(x: x, y: y)
209
+ end
210
+
211
+ def less_equal(x, y)
212
+ RawOps.less_equal(x: x, y: y)
213
+ end
214
+
215
+ def lgamma(x)
216
+ RawOps.lgamma(x: x)
217
+ end
218
+
219
+ def log(x)
220
+ RawOps.log(x: x)
221
+ end
222
+
223
+ def log1p(x)
224
+ RawOps.log1p(x: x)
225
+ end
226
+
227
+ # def log_sigmoid
228
+ # end
229
+
230
+ def log_softmax(logits)
231
+ RawOps.log_softmax(logits: logits)
232
+ end
233
+
234
+ def logical_and(x, y)
235
+ RawOps.logical_and(x: x, y: y)
236
+ end
237
+
238
+ def logical_not(x)
239
+ RawOps.logical_not(x: x)
240
+ end
241
+
242
+ def logical_or(x, y)
243
+ RawOps.logical_or(x: x, y: y)
244
+ end
245
+
246
+ # def logical_xor
247
+ # end
248
+
249
+ def maximum(x, y)
250
+ RawOps.maximum(x: x, y: y)
251
+ end
252
+
253
+ def minimum(x, y)
254
+ RawOps.minimum(x: x, y: y)
255
+ end
256
+
257
+ def mod(x, y)
258
+ RawOps.mod(x: x, y: y)
259
+ end
260
+
261
+ def multiply(x, y)
262
+ RawOps.mul(x: x, y: y)
263
+ end
264
+
265
+ # def multiply_no_nan
266
+ # end
267
+
268
+ # def negative
269
+ # end
270
+
271
+ # def nextafter
272
+ # end
273
+
274
+ def not_equal(x, y)
275
+ RawOps.not_equal(x: x, y: y)
276
+ end
277
+
278
+ def polygamma(a, x)
279
+ RawOps.polygamma(a: a, x: x)
280
+ end
281
+
282
+ # def polyval
283
+ # end
284
+
285
+ def pow(x, y)
286
+ RawOps.pow(x: x, y: y)
287
+ end
288
+
289
+ def real(input)
290
+ RawOps.real(input: input)
291
+ end
292
+
293
+ def reciprocal(x)
294
+ RawOps.reciprocal(x: x)
295
+ end
296
+
297
+ # def reciprocal_no_nan
298
+ # end
299
+
300
+ # def reduce_all
301
+ # end
302
+
303
+ # def reduce_any
304
+ # end
305
+
306
+ # def reduce_euclidean_norm
307
+ # end
308
+
309
+ # def reduce_logsumexp
310
+ # end
311
+
312
+ # def reduce_max
313
+ # end
314
+
315
+ # def reduce_mean
316
+ # end
317
+
318
+ # def reduce_min
319
+ # end
320
+
321
+ # def reduce_prod
322
+ # end
323
+
324
+ # def reduce_std
325
+ # end
326
+
327
+ # def reduce_sum
328
+ # end
329
+
330
+ # def reduce_variance
331
+ # end
332
+
333
+ def rint(x)
334
+ RawOps.rint(x: x)
335
+ end
336
+
337
+ def round(x)
338
+ RawOps.round(x: x)
339
+ end
340
+
341
+ def rsqrt(x)
342
+ RawOps.rsqrt(x: x)
343
+ end
344
+
345
+ # def scalar_mul
346
+ # end
347
+
348
+ def segment_max(data, segment_ids)
349
+ RawOps.segment_max(data: data, segment_ids: segment_ids)
350
+ end
351
+
352
+ def segment_mean(data, segment_ids)
353
+ RawOps.segment_mean(data: data, segment_ids: segment_ids)
354
+ end
355
+
356
+ def segment_min(data, segment_ids)
357
+ RawOps.segment_min(data: data, segment_ids: segment_ids)
358
+ end
359
+
360
+ def segment_prod(data, segment_ids)
361
+ RawOps.segment_prod(data: data, segment_ids: segment_ids)
362
+ end
363
+
364
+ def segment_sum(data, segment_ids)
365
+ RawOps.segment_sum(data: data, segment_ids: segment_ids)
366
+ end
367
+
368
+ def sigmoid(x)
369
+ RawOps.sigmoid(x: x)
370
+ end
371
+
372
+ def sign(x)
373
+ RawOps.sign(x: x)
374
+ end
375
+
376
+ def sin(x)
377
+ RawOps.sin(x: x)
378
+ end
379
+
380
+ def sinh(x)
381
+ RawOps.sinh(x: x)
382
+ end
383
+
384
+ def softmax(logits)
385
+ RawOps.softmax(logits: logits)
386
+ end
387
+
388
+ def softplus(features)
389
+ RawOps.softplus(features: features)
390
+ end
391
+
392
+ def softsign(features)
393
+ RawOps.softsign(features: features)
394
+ end
395
+
396
+ def sqrt(x)
397
+ RawOps.sqrt(x: x)
398
+ end
399
+
400
+ def square(x)
401
+ RawOps.square(x: x)
402
+ end
403
+
404
+ def squared_difference(x, y)
405
+ RawOps.squared_difference(x: x, y: y)
406
+ end
407
+
408
+ def subtract(x, y)
409
+ RawOps.sub(x: x, y: y)
410
+ end
411
+
412
+ def tan(x)
413
+ RawOps.tan(x: x)
414
+ end
415
+
416
+ def tanh(x)
417
+ RawOps.tanh(x: x)
418
+ end
419
+
420
+ def top_k(input, k: nil, sorted: nil)
421
+ RawOps.top_k(input: input, k: k, sorted: sorted)
422
+ end
423
+
424
+ # def truediv
425
+ # end
426
+
427
+ def unsorted_segment_max(data, segment_ids, num_segments)
428
+ RawOps.unsorted_segment_max(data: data, segment_ids: segment_ids, num_segments: num_segments)
429
+ end
430
+
431
+ # def unsorted_segment_mean
432
+ # end
433
+
434
+ def unsorted_segment_min(data, segment_ids, num_segments)
435
+ RawOps.unsorted_segment_min(data: data, segment_ids: segment_ids, num_segments: num_segments)
436
+ end
437
+
438
+ def unsorted_segment_prod(data, segment_ids, num_segments)
439
+ RawOps.unsorted_segment_prod(data: data, segment_ids: segment_ids, num_segments: num_segments)
440
+ end
441
+
442
+ # def unsorted_segment_sqrt_n
443
+ # end
444
+
445
+ def unsorted_segment_sum(data, segment_ids, num_segments)
446
+ RawOps.unsorted_segment_sum(data: data, segment_ids: segment_ids, num_segments: num_segments)
447
+ end
448
+
449
+ def xdivy(x, y)
450
+ RawOps.xdivy(x: x, y: y)
451
+ end
452
+
453
+ def xlogy(x, y)
454
+ RawOps.xlogy(x: x, y: y)
455
+ end
456
+
457
+ # def zero_fraction
458
+ # end
459
+
460
+ def zeta(x, q)
461
+ RawOps.zeta(x: x, q: q)
462
+ end
463
+ end
464
+ end
465
+ end
@@ -0,0 +1,51 @@
1
+ # keep in alphabetical order
2
+ module TensorFlow
3
+ module Ops
4
+ def eye(num_rows, num_columns: nil)
5
+ num_columns ||= num_rows
6
+ zeros = self.zeros([num_rows, num_columns])
7
+ ones = self.ones([num_rows])
8
+ RawOps.matrix_set_diag(input: zeros, diagonal: ones)
9
+ end
10
+
11
+ def fill(dims, value)
12
+ RawOps.fill(dims: dims, value: value)
13
+ end
14
+
15
+ def identity(input)
16
+ RawOps.identity(input: input)
17
+ end
18
+
19
+ def matmul(a, b)
20
+ RawOps.mat_mul(a: a, b: b)
21
+ end
22
+
23
+ def ones(dims)
24
+ fill(dims, 1)
25
+ end
26
+
27
+ def range(start, limit = nil, delta = 1)
28
+ unless limit
29
+ limit = start
30
+ start = 0
31
+ end
32
+ RawOps.range(start: start, limit: limit, delta: delta)
33
+ end
34
+
35
+ def timestamp
36
+ RawOps.timestamp
37
+ end
38
+
39
+ def transpose(x, perm: [1, 0])
40
+ RawOps.transpose(x: x, perm: perm)
41
+ end
42
+
43
+ def zeros(dims)
44
+ fill(dims, 0)
45
+ end
46
+
47
+ def zeros_like(x)
48
+ RawOps.zeros_like(x: x)
49
+ end
50
+ end
51
+ end