Module: Tensorflow::Ops
- Included in:
- Tensorflow
- Defined in:
- lib/tensorflow/ops/ops.rb,
lib/tensorflow/ops/gradients.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cast(x, destination_dtype, source_dtype: nil, truncate: false) ⇒ Object
- #constant(value, dtype: nil, shape: [], name: 'Const') ⇒ Object
- #expand_dims(input, axis) ⇒ Object
- #fill(dims, value, dtype: nil) ⇒ Object
- #identity(input) ⇒ Object
- #ones(dims, dtype: :float) ⇒ Object
- #pack(values, n: nil, typeT: nil, axis: 0) ⇒ Object
- #placeholder(dtype, name: 'Placeholder', shape: nil) ⇒ Object
- #prevent_gradient(input, typeT: nil, message: "") ⇒ Object
- #range(start, limit = nil, delta = 1) ⇒ Object
- #rank(input, typeT: nil) ⇒ Object
- #reshape(tensor, shape) ⇒ Object
- #shape(input, out_type) ⇒ Object
- #split(value, split_dim, num_split: nil, typeT: nil) ⇒ Object
- #split_v(value, size_splits, split_dim = 0, num_split: nil, typeT: nil, tlen: nil) ⇒ Object
- #squeeze(input, axis: nil) ⇒ Object
- #timestamp ⇒ Object
- #transpose(x, perm: [1, 0]) ⇒ Object
- #where(condition, x: nil, y: nil) ⇒ Object
- #zeros(dims, dtype: :float) ⇒ Object
- #zeros_like(x) ⇒ Object
Class Method Details
.broadcast_mul(vector, matrix) ⇒ Object
3 4 5 6 |
# File 'lib/tensorflow/ops/gradients.rb', line 3 def self.broadcast_mul(vector, matrix) vector = Tensorflow.(vector, -1) vector * matrix end |
Instance Method Details
#cast(x, destination_dtype, source_dtype: nil, truncate: false) ⇒ Object
4 5 6 |
# File 'lib/tensorflow/ops/ops.rb', line 4 def cast(x, destination_dtype, source_dtype: nil, truncate: false) RawOps.cast(x, srct: source_dtype, dstt: destination_dtype, truncate: truncate) end |
#constant(value, dtype: nil, shape: [], name: 'Const') ⇒ Object
8 9 10 11 |
# File 'lib/tensorflow/ops/ops.rb', line 8 def constant(value, dtype: nil, shape: [], name: 'Const') tensor = value.is_a?(Tensor) ? value : Tensor.new(value, dtype: dtype, shape: shape) RawOps.const(value: tensor, dtype: tensor.dtype, name: name) end |
#expand_dims(input, axis) ⇒ Object
13 14 15 |
# File 'lib/tensorflow/ops/ops.rb', line 13 def (input, axis) RawOps.(input, axis) end |
#fill(dims, value, dtype: nil) ⇒ Object
17 18 19 |
# File 'lib/tensorflow/ops/ops.rb', line 17 def fill(dims, value, dtype: nil) RawOps.fill(dims, value, typeT: dtype) end |
#identity(input) ⇒ Object
21 22 23 |
# File 'lib/tensorflow/ops/ops.rb', line 21 def identity(input) RawOps.identity(input) end |
#ones(dims, dtype: :float) ⇒ Object
25 26 27 |
# File 'lib/tensorflow/ops/ops.rb', line 25 def ones(dims, dtype: :float) fill(dims, 1, dtype: dtype) end |
#pack(values, n: nil, typeT: nil, axis: 0) ⇒ Object
29 30 31 32 33 |
# File 'lib/tensorflow/ops/ops.rb', line 29 def pack(values, n: nil, typeT: nil, axis: 0) typeT ||= TensorData.figure_dtype(values) n ||= values.count RawOps.pack(values, n: n, typeT: typeT, axis: axis) end |
#placeholder(dtype, name: 'Placeholder', shape: nil) ⇒ Object
35 36 37 |
# File 'lib/tensorflow/ops/ops.rb', line 35 def placeholder(dtype, name: 'Placeholder', shape: nil) RawOps.placeholder(dtype: dtype, shape: shape, name: name) end |
#prevent_gradient(input, typeT: nil, message: "") ⇒ Object
39 40 41 |
# File 'lib/tensorflow/ops/ops.rb', line 39 def prevent_gradient(input, typeT: nil, message: "") RawOps.prevent_gradient(input, typeT: typeT, message: , name: "PreventGradient") end |
#range(start, limit = nil, delta = 1) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/tensorflow/ops/ops.rb', line 47 def range(start, limit = nil, delta = 1) unless limit limit = start start = 0 end RawOps.range(start, limit, delta) end |
#rank(input, typeT: nil) ⇒ Object
43 44 45 |
# File 'lib/tensorflow/ops/ops.rb', line 43 def rank(input, typeT: nil) RawOps.rank(input, typeT: typeT) end |
#reshape(tensor, shape) ⇒ Object
55 56 57 |
# File 'lib/tensorflow/ops/ops.rb', line 55 def reshape(tensor, shape) RawOps.reshape(tensor, shape, typeT: tensor.output_types.first) end |
#shape(input, out_type) ⇒ Object
59 60 61 |
# File 'lib/tensorflow/ops/ops.rb', line 59 def shape(input, out_type) RawOps.shape(input, out_type: out_type) end |
#split(value, split_dim, num_split: nil, typeT: nil) ⇒ Object
63 64 65 |
# File 'lib/tensorflow/ops/ops.rb', line 63 def split(value, split_dim, num_split: nil, typeT: nil) RawOps.split(split_dim, value, num_split: num_split, typeT: typeT) end |
#split_v(value, size_splits, split_dim = 0, num_split: nil, typeT: nil, tlen: nil) ⇒ Object
67 68 69 70 |
# File 'lib/tensorflow/ops/ops.rb', line 67 def split_v(value, size_splits, split_dim=0, num_split: nil, typeT: nil, tlen: nil) num_split ||= size_splits.length RawOps.split_v(value, size_splits, split_dim, num_split: num_split, typeT: typeT, tlen: tlen) end |
#squeeze(input, axis: nil) ⇒ Object
72 73 74 |
# File 'lib/tensorflow/ops/ops.rb', line 72 def squeeze(input, axis: nil) RawOps.squeeze(input, squeeze_dims: axis) end |
#timestamp ⇒ Object
76 77 78 |
# File 'lib/tensorflow/ops/ops.rb', line 76 def RawOps. end |
#transpose(x, perm: [1, 0]) ⇒ Object
80 81 82 |
# File 'lib/tensorflow/ops/ops.rb', line 80 def transpose(x, perm: [1, 0]) RawOps.transpose(x, perm) end |
#where(condition, x: nil, y: nil) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/tensorflow/ops/ops.rb', line 84 def where(condition, x: nil, y: nil) if x.nil? && y.nil? RawOps.where(condition) elsif x && y RawOps.select_v2(condition, x, y) else raise(Error::InvalidArgumentError, "x and y must both be non nil or both be nil") end end |
#zeros(dims, dtype: :float) ⇒ Object
94 95 96 |
# File 'lib/tensorflow/ops/ops.rb', line 94 def zeros(dims, dtype: :float) fill(dims, 0, dtype: dtype) end |
#zeros_like(x) ⇒ Object
98 99 100 |
# File 'lib/tensorflow/ops/ops.rb', line 98 def zeros_like(x) RawOps.zeros_like(x) end |