Module: TensorStream::Ops

Included in:
TensorStream
Defined in:
lib/tensor_stream/ops.rb

Overview

Class that defines all available ops supported by TensorStream

Constant Summary collapse

FLOATING_POINT_TYPES =
i[float32 float64 float].freeze
INTEGER_TYPES =
i[int32 int int64].freeze
NUMERIC_TYPES =
FLOATING_POINT_TYPES + INTEGER_TYPES

Instance Method Summary collapse

Instance Method Details

#abs(input, name: nil) ⇒ Object

Computes the absolute value of a tensor.



485
486
487
# File 'lib/tensor_stream/ops.rb', line 485

def abs(input, name: nil)
  _op(:abs, input, nil, name: name)
end

#acos(input, name: nil) ⇒ Object

Computes acos of input element-wise



316
317
318
319
# File 'lib/tensor_stream/ops.rb', line 316

def acos(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:acos, input, name: name)
end

#add(input_a, input_b, name: nil) ⇒ Object

Returns x + y element-wise.

This operation supports broadcasting



294
295
296
297
# File 'lib/tensor_stream/ops.rb', line 294

def add(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:add, input_a, input_b, name: name)
end

#add_n(inputs, name: nil) ⇒ Object

Adds all input tensors element-wise.

Elements must all be the same shape and type



303
304
305
# File 'lib/tensor_stream/ops.rb', line 303

def add_n(inputs, name: nil)
  _op(:add_n, *inputs, name: name)
end

#argmax(input, axis = nil, name: nil, dimension: nil, output_type: :int32) ⇒ Object

Returns the index with the largest value across axes of a tensor.

Argmuments

input A Tensor. Must be one of the following types: float32, float64, int32, int16 axis Describes which axis of the input Tensor to reduce across. For vectors, use axis = 0 output_type Output data type defaults to int32



16
17
18
# File 'lib/tensor_stream/ops.rb', line 16

def argmax(input, axis = nil, name: nil, dimension: nil, output_type: :int32)
  _op(:argmax, input, nil, axis: axis, name: name, dimension: dimension, data_type: output_type)
end

#argmin(input, axis = nil, name: nil, dimension: nil, output_type: :int32) ⇒ Object

Returns the index with the smallest value across axes of a tensor.

Argmuments

input A Tensor. Must be one of the following types: float32, float64, int32, int16 axis Describes which axis of the input Tensor to reduce across. For vectors, use axis = 0 output_type Output data type defaults to int32



28
29
30
# File 'lib/tensor_stream/ops.rb', line 28

def argmin(input, axis = nil, name: nil, dimension: nil, output_type: :int32)
  _op(:argmin, input, nil, axis: axis, name: name, dimension: dimension, data_type: output_type)
end

#asin(input, name: nil) ⇒ Object

Computes asin of input element-wise



309
310
311
312
# File 'lib/tensor_stream/ops.rb', line 309

def asin(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:asin, input, name: name)
end

#broadcast_gradient_args(shape_a, shape_b, name: nil) ⇒ Object



611
612
613
614
# File 'lib/tensor_stream/ops.rb', line 611

def broadcast_gradient_args(shape_a, shape_b, name: nil)
  op_result = _op(:broadcast_gradient_args, shape_a, shape_b, name: name)
  [op_result[0], op_result[1]]
end

#cast(input, dtype, name: nil) ⇒ Object

Casts a tensor to a new type.



389
390
391
# File 'lib/tensor_stream/ops.rb', line 389

def cast(input, dtype, name: nil)
  _op(:cast, input, nil, data_type: dtype, name: name)
end

#ceil(input, name: nil) ⇒ Object

Returns element-wise smallest integer in not less than x



171
172
173
174
# File 'lib/tensor_stream/ops.rb', line 171

def ceil(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:ceil, input, name: name)
end

#check_numerics(tensor, message, name: nil) ⇒ Object

Checks a tensor for NaN and Inf values. When run, reports an InvalidArgument error if tensor has any values that are not a number (NaN) or infinity (Inf). Otherwise, passes tensor as-is.



599
600
601
# File 'lib/tensor_stream/ops.rb', line 599

def check_numerics(tensor, message, name: nil)
  _op(:check_numerics, tensor, nil, message: message, name: name)
end

#concat(values, axis, name: 'concat') ⇒ Object

Concatenates tensors along one dimension.



247
248
249
# File 'lib/tensor_stream/ops.rb', line 247

def concat(values, axis, name: 'concat')
  _op(:concat, values, nil, axis: axis, name: name)
end

#cond(pred, true_fn, false_fn, name: nil) ⇒ Object

Return true_fn() if the predicate pred is true else false_fn().



280
281
282
# File 'lib/tensor_stream/ops.rb', line 280

def cond(pred, true_fn, false_fn, name: nil)
  _op(:cond, true_fn, false_fn, pred: pred, name: name)
end

#cos(input, name: nil) ⇒ Object

Computes cos of input element-wise.



506
507
508
509
# File 'lib/tensor_stream/ops.rb', line 506

def cos(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:cos, input, nil, name: name)
end

#div(input_a, input_b, name: nil) ⇒ Object

Divides x / y elementwise This operation supports broadcasting



471
472
473
474
# File 'lib/tensor_stream/ops.rb', line 471

def div(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:div, input_a, input_b, name: name)
end

#equal(input_a, input_b, name: nil) ⇒ Object

Returns the truth value of (x == y) element-wise.



415
416
417
418
# File 'lib/tensor_stream/ops.rb', line 415

def equal(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:equal, input_a, input_b, name: name)
end

#exp(input, name: nil) ⇒ Object

Computes exponential of x element-wise.



548
549
550
551
# File 'lib/tensor_stream/ops.rb', line 548

def exp(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:exp, input, nil, name: name)
end

#expand_dims(input, axis = nil, name: nil) ⇒ Object



89
90
91
# File 'lib/tensor_stream/ops.rb', line 89

def expand_dims(input, axis = nil, name: nil)
  _op(:expand_dims, input, axis, name: name)
end

#eye(num_rows, num_columns: nil, dtype: :float32, name: nil) ⇒ Object

Construct an identity matrix



85
86
87
# File 'lib/tensor_stream/ops.rb', line 85

def eye(num_rows, num_columns: nil, dtype: :float32, name: nil)
  _op(:eye, num_rows, num_columns || num_rows, data_type: dtype, name: name)
end

#fill(dims, value, name: nil) ⇒ Object

Creates a tensor filled with a scalar value.

This operation creates a tensor of shape dims and fills it with value.

For example: Output tensor has shape [2, 3]. fill([2, 3], 9) => [[9, 9, 9]

[9, 9, 9]]


562
563
564
# File 'lib/tensor_stream/ops.rb', line 562

def fill(dims, value, name: nil)
  _op(:fill, dims, value, name: name)
end

#floor(input, name: nil) ⇒ Object

Returns element-wise largest integer not greater than x.



164
165
166
167
# File 'lib/tensor_stream/ops.rb', line 164

def floor(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:floor, input, name: name)
end

#floor_div(input_a, input_b, name: nil) ⇒ Object

Returns element-wise integer divistion.



339
340
341
342
# File 'lib/tensor_stream/ops.rb', line 339

def floor_div(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:floor_div, input_a, input_b, name: name)
end

#glorot_uniform_initializer(seed: nil, dtype: nil) ⇒ Object

The Glorot uniform initializer, also called Xavier uniform initializer.

It draws samples from a uniform distribution within [-limit, limit] where limit is sqrt(6 / (fan_in + fan_out)) where fan_in is the number of input units in the weight tensor and fan_out is the number of output units in the weight tensor.



130
131
132
# File 'lib/tensor_stream/ops.rb', line 130

def glorot_uniform_initializer(seed: nil, dtype: nil)
  TensorStream::Initializer.new(-> { _op(:glorot_uniform, nil, nil, seed: seed, data_type: dtype) })
end

#gradients(tensor_ys, wrt_xs, name: 'gradients', stop_gradients: nil) ⇒ Object

Constructs symbolic derivatives of ys of input w.r.t. x in wrt_xs.

ys and xs are each a Tensor or a list of tensors. grad_ys is a list of Tensor, holding the gradients received by the ys. The list must be the same length as ys.

Arguments: tensor_ys : A Tensor or list of tensors to be differentiated. wrt_xs : A Tensor or list of tensors to be used for differentiation. stop_gradients : Optional. A Tensor or list of tensors not to differentiate through



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/tensor_stream/ops.rb', line 41

def gradients(tensor_ys, wrt_xs, name: 'gradients', stop_gradients: nil)
  gs = wrt_xs.collect do |x|
    stops = stop_gradients ? stop_gradients.map(&:name).join('_') : ''
    gradient_program_name = "grad_#{tensor_ys.name}_#{x.name}_#{stops}".to_sym
    tensor_graph = tensor_ys.graph

    tensor_program = if tensor_graph.node_added?(gradient_program_name)
                       tensor_graph.get_node(gradient_program_name)
                     else
                       tensor_graph.name_scope("gradient_wrt_#{x.name}") do
                         derivative_ops = TensorStream::MathGradients.derivative(tensor_ys, x, graph: tensor_graph,
                                                                                               stop_gradients: stop_gradients)
                         tensor_graph.add_node!(gradient_program_name, derivative_ops)
                       end
                     end
    tensor_program
  end
  TensorStream.group(gs)
end

#greater(input_a, input_b, name: nil) ⇒ Object

Returns the truth value of (x > y) element-wise. This operation supports broadcasting



194
195
196
197
# File 'lib/tensor_stream/ops.rb', line 194

def greater(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:greater, input_a, input_b, name: name)
end

#greater_equal(input_a, input_b, name: nil) ⇒ Object

Returns the truth value of (x >= y) element-wise.

This operation supports broadcasting



203
204
205
206
# File 'lib/tensor_stream/ops.rb', line 203

def greater_equal(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:greater_equal, input_a, input_b, name: name)
end

#identity(input, name: nil) ⇒ Object

Return a tensor with the same shape and contents as input.



448
449
450
# File 'lib/tensor_stream/ops.rb', line 448

def identity(input, name: nil)
  _op(:identity, input, nil, name: name)
end

#less(input_a, input_b, name: nil) ⇒ Object

Returns the truth value of (x < y) element-wise. This operation supports broadcasting



179
180
181
182
# File 'lib/tensor_stream/ops.rb', line 179

def less(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:less, input_a, input_b, name: name)
end

#less_equal(input_a, input_b, name: nil) ⇒ Object

Returns the truth value of (x <= y) element-wise.



210
211
212
213
# File 'lib/tensor_stream/ops.rb', line 210

def less_equal(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:less_equal, input_a, input_b, name: name)
end

#log(input, name: nil) ⇒ Object

Computes natural logarithm of x element-wise.



534
535
536
537
# File 'lib/tensor_stream/ops.rb', line 534

def log(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:log, input, nil, name: name)
end

#log1p(input, name: nil) ⇒ Object

Computes natural logarithm of (1 + x) element-wise.



541
542
543
544
# File 'lib/tensor_stream/ops.rb', line 541

def log1p(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:log1p, input, nil, name: name)
end

#logical_and(input_a, input_b, name: nil) ⇒ Object

Returns the truth value of x AND y element-wise.



186
187
188
189
# File 'lib/tensor_stream/ops.rb', line 186

def logical_and(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:logical_and, input_a, input_b, name: name)
end

#matmul(input_a, input_b, transpose_a: false, transpose_b: false, name: nil) ⇒ Object

Multiplies matrix a by matrix b, producing a * b. The inputs must, following any transpositions, be tensors of rank 2 .



576
577
578
579
580
581
# File 'lib/tensor_stream/ops.rb', line 576

def matmul(input_a, input_b, transpose_a: false,
           transpose_b: false,
           name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:mat_mul, input_a, input_b, transpose_a: transpose_a, transpose_b: transpose_b, name: name)
end

#max(input_a, input_b, name: nil) ⇒ Object

Returns the max of x and y (i.e. x > y ? x : y) element-wise.



359
360
361
362
363
364
# File 'lib/tensor_stream/ops.rb', line 359

def max(input_a, input_b, name: nil)
  check_allowed_types(input_a, NUMERIC_TYPES)
  check_allowed_types(input_b, NUMERIC_TYPES)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:max, input_a, input_b, name: name)
end

#maximum(input_a, input_b, name: nil) ⇒ Object

Returns the max of x and y (i.e. x > y ? x : y) element-wise.



368
369
370
# File 'lib/tensor_stream/ops.rb', line 368

def maximum(input_a, input_b, name: nil)
  max(input_a, input_b, name: name)
end

#min(input_a, input_b, name: nil) ⇒ Object

Returns the min of x and y (i.e. x < y ? x : y) element-wise.



374
375
376
377
378
379
# File 'lib/tensor_stream/ops.rb', line 374

def min(input_a, input_b, name: nil)
  check_allowed_types(input_a, NUMERIC_TYPES)
  check_allowed_types(input_b, NUMERIC_TYPES)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:min, input_a, input_b, name: name)
end

#minimum(input_a, input_b, name: nil) ⇒ Object

Returns the min of x and y (i.e. x < y ? x : y) element-wise.



383
384
385
# File 'lib/tensor_stream/ops.rb', line 383

def minimum(input_a, input_b, name: nil)
  min(input_a, input_b, name: name)
end

#mod(input_a, input_b, name: nil) ⇒ Object

Returns element-wise remainder of division.



332
333
334
335
# File 'lib/tensor_stream/ops.rb', line 332

def mod(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:mod, input_a, input_b, name: name)
end

#mul(input_a, input_b, name: nil) ⇒ Object

Returns x * y element-wise. This operation supports broadcasting



463
464
465
466
# File 'lib/tensor_stream/ops.rb', line 463

def mul(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:mul, input_a, input_b, name: name)
end

#multiply(input_a, input_b, name: nil) ⇒ Object

Returns x * y element-wise. This operation supports broadcasting



455
456
457
458
# File 'lib/tensor_stream/ops.rb', line 455

def multiply(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:mul, input_a, input_b, name: name)
end

#negate(input, name: nil) ⇒ Object

Computes numerical negative value element-wise.



403
404
405
# File 'lib/tensor_stream/ops.rb', line 403

def negate(input, name: nil)
  _op(:negate, input, nil, name: name)
end

#negative(input, name: nil) ⇒ Object

Computes numerical negative value element-wise.



409
410
411
# File 'lib/tensor_stream/ops.rb', line 409

def negative(input, name: nil)
  negate(input, name: name)
end

#not_equal(input_a, input_b, name: nil) ⇒ Object

Returns the truth value of (x != y) element-wise. This ops supports broadcasting



423
424
425
426
# File 'lib/tensor_stream/ops.rb', line 423

def not_equal(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:not_equal, input_a, input_b, name: name)
end

#ones(shape, dtype: :float32, name: nil) ⇒ Object

Creates a tensor with all elements set to 1.



158
159
160
# File 'lib/tensor_stream/ops.rb', line 158

def ones(shape, dtype: :float32, name: nil)
  _op(:ones, shape, nil, data_type: dtype, name: name)
end

#ones_like(tensor, dtype: nil, name: nil) ⇒ Object

Creates a tensor with all elements set to 1. Given a single tensor (tensor), this operation returns a tensor of the same type and shape as tensor with all elements set to 1. Optionally, you can specify a new type (dtype) for the returned tensor.



442
443
444
# File 'lib/tensor_stream/ops.rb', line 442

def ones_like(tensor, dtype: nil, name: nil)
  _op(:ones_like, tensor, nil, data_type: dtype, name: name)
end

#pad(tensor, paddings, mode: 'CONSTANT', name: nil) ⇒ Object

Pads a tensor. This operation pads a tensor according to the paddings you specify.



592
593
594
# File 'lib/tensor_stream/ops.rb', line 592

def pad(tensor, paddings, mode: 'CONSTANT', name: nil)
  _op(:pad, tensor, nil, paddings: paddings, mode: mode, name: name)
end

#pow(input_a, input_e, name: nil) ⇒ Object

Computes the power of one value to another.



478
479
480
481
# File 'lib/tensor_stream/ops.rb', line 478

def pow(input_a, input_e, name: nil)
  input_a, input_e = check_data_types(input_a, input_e)
  _op(:pow, input_a, input_e, name: name)
end

Prints a list of tensors.

This is an identity op (behaves like tf.identity) with the side effect of printing data when evaluating.



397
398
399
# File 'lib/tensor_stream/ops.rb', line 397

def print(input, data, message: nil, name: nil)
  _op(:print, input, data, message: message, name: name)
end

#random_normal(shape, dtype: :float32, mean: 0.0, stddev: 1.0, seed: nil, name: nil) ⇒ Object

Outputs random values from a normal distribution.



70
71
72
73
# File 'lib/tensor_stream/ops.rb', line 70

def random_normal(shape, dtype: :float32, mean: 0.0, stddev: 1.0, seed: nil, name: nil)
  options = { shape: shape, dtype: dtype, mean: mean, stddev: stddev, seed: seed, name: name }
  _op(:random_standard_normal, nil, nil, options)
end

#random_uniform(shape, dtype: :float32, minval: 0, maxval: 1, seed: nil, name: nil) ⇒ Object

Outputs random values from a uniform distribution.



63
64
65
66
# File 'lib/tensor_stream/ops.rb', line 63

def random_uniform(shape, dtype: :float32, minval: 0, maxval: 1, seed: nil, name: nil)
  options = { shape: shape, dtype: dtype, minval: minval, maxval: maxval, seed: seed, name: name }
  _op(:random_uniform, nil, nil, options)
end

#random_uniform_initializer(minval: 0, maxval: 1, seed: nil, dtype: nil) ⇒ Object

Initializer that generates tensors with a uniform distribution.



136
137
138
# File 'lib/tensor_stream/ops.rb', line 136

def random_uniform_initializer(minval: 0, maxval: 1, seed: nil, dtype: nil)
  TensorStream::Initializer.new(-> { _op(:random_uniform, nil, nil, minval: 0, maxval: 1, seed: seed, data_type: dtype) })
end

#range(start, limit, delta = 1, dtype: nil, name: 'range') ⇒ Object



344
345
346
# File 'lib/tensor_stream/ops.rb', line 344

def range(start, limit, delta = 1, dtype: nil, name: 'range')
  _op(:range, start, limit, delta, data_type: dtype, name: name)
end

#rank(input, name: nil) ⇒ Object

Returns the rank of a tensor.



114
115
116
# File 'lib/tensor_stream/ops.rb', line 114

def rank(input, name: nil)
  _op(:rank, input, name: name)
end

#reciprocal(tensor, name: nil) ⇒ Object

Computes the reciprocal of x element-wise.



274
275
276
# File 'lib/tensor_stream/ops.rb', line 274

def reciprocal(tensor, name: nil)
  _op(:reciprocal, tensor, nil, name: name)
end

#reduce_mean(input_tensor, axis = nil, keepdims: false, name: nil) ⇒ Object

Computes the mean of elements across dimensions of a tensor.



217
218
219
# File 'lib/tensor_stream/ops.rb', line 217

def reduce_mean(input_tensor, axis = nil, keepdims: false, name: nil)
  _op(:mean, input_tensor, axis, keepdims: keepdims, name: name)
end

#reduce_prod(input, axis = nil, keepdims: false, name: nil) ⇒ Object

Computes the product of elements across dimensions of a tensor.

Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keepdims is true, the reduced dimensions are retained with length 1.

If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned.



241
242
243
# File 'lib/tensor_stream/ops.rb', line 241

def reduce_prod(input, axis = nil, keepdims: false, name: nil)
  _op(:prod, input, axis, keepdims: keepdims, name: name)
end

#reduce_sum(input_tensor, axis = nil, keepdims: false, name: nil) ⇒ Object

Computes the sum of elements across dimensions of a tensor.

Reduces input_tensor along the dimensions given in axis. Unless keepdims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keepdims is true, the reduced dimensions are retained with length 1. If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned.



229
230
231
# File 'lib/tensor_stream/ops.rb', line 229

def reduce_sum(input_tensor, axis = nil, keepdims: false, name: nil)
  _op(:sum, input_tensor, axis, keepdims: keepdims, name: name)
end

#reshape(tensor, shape, name: nil) ⇒ Object

Reshapes a tensor.

Given tensor, this operation returns a tensor that has the same values as tensor with shape shape.



255
256
257
# File 'lib/tensor_stream/ops.rb', line 255

def reshape(tensor, shape, name: nil)
  _op(:reshape, tensor, shape, name: name)
end

#round(tensor, name: nil) ⇒ Object

Rounds the values of a tensor to the nearest integer, element-wise



267
268
269
270
# File 'lib/tensor_stream/ops.rb', line 267

def round(tensor, name: nil)
  check_allowed_types(tensor, FLOATING_POINT_TYPES)
  _op(:round, tensor, nil, name: name)
end

#shape(input, name: nil, out_type: :int32) ⇒ Object

This operation returns a 1-D integer tensor representing the shape of input



95
96
97
98
99
100
# File 'lib/tensor_stream/ops.rb', line 95

def shape(input, name: nil, out_type: :int32)
  return constant(shape_eval(input, out_type), dtype: out_type, name: name) if input.is_a?(Array)
  return constant(input.shape.shape, dtype: out_type, name: "Shape/#{input.name}") if shape_full_specified(input)

  _op(:shape, input, nil, name: name, out_type: out_type)
end

#sigmoid(input, name: nil) ⇒ Object

Computes sigmoid of x element-wise.



568
569
570
571
# File 'lib/tensor_stream/ops.rb', line 568

def sigmoid(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:sigmoid, input, nil, name: name)
end

#sign(input, name: nil) ⇒ Object

Returns an element-wise indication of the sign of a number. y = sign(x) = -1 if x < 0; 0 if x == 0 or tf.is_nan(x); 1 if x > 0. Zero is returned for NaN inputs.



493
494
495
# File 'lib/tensor_stream/ops.rb', line 493

def sign(input, name: nil)
  _op(:sign, input, nil, name: name)
end

#sin(input, name: nil) ⇒ Object

Computes sin of input element-wise.



499
500
501
502
# File 'lib/tensor_stream/ops.rb', line 499

def sin(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:sin, input, nil, name: name)
end

#size(tensor, name: nil, out_type: :int32) ⇒ Object



603
604
605
# File 'lib/tensor_stream/ops.rb', line 603

def size(tensor, name: nil, out_type: :int32)
  _op(:size, tensor, name: name, out_type: out_type)
end

#slice(input, start, size, name: nil) ⇒ Object

Extracts a slice from a tensor.

This operation extracts a slice of size size from a tensor input starting at the location specified by begin. The slice size is represented as a tensor shape, where size is the number of elements of the ‘i’th dimension of input that you want to slice. The starting location (begin) for the slice is represented as an offset in each dimension of input. In other words, begin is the offset into the ‘i’th dimension of input that you want to slice from.



146
147
148
# File 'lib/tensor_stream/ops.rb', line 146

def slice(input, start, size, name: nil)
  _op(:slice, input, start, size: size, name: name)
end

#sqrt(input, name: nil) ⇒ Object

Computes sqrt of input element-wise.



527
528
529
530
# File 'lib/tensor_stream/ops.rb', line 527

def sqrt(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:sqrt, input, nil, name: name)
end

#square(tensor, name: nil) ⇒ Object

Computes square of x element-wise.



261
262
263
# File 'lib/tensor_stream/ops.rb', line 261

def square(tensor, name: nil)
  _op(:square, tensor, nil, name: name)
end

#squared_difference(input_a, input_b, name: nil) ⇒ Object



607
608
609
# File 'lib/tensor_stream/ops.rb', line 607

def squared_difference(input_a, input_b, name: nil)
  _op(:squared_difference, input_a, input_b, name: name)
end

#stop_gradient(tensor, options = {}) ⇒ Object

Stops gradient computation.

When executed in a graph, this op outputs its input tensor as-is.



79
80
81
# File 'lib/tensor_stream/ops.rb', line 79

def stop_gradient(tensor, options = {})
  _op(:stop_gradient, tensor, nil, options)
end

#sub(input_a, input_b, name: nil) ⇒ Object

Returns x - y element-wise.

This operation supports boradcasting



325
326
327
328
# File 'lib/tensor_stream/ops.rb', line 325

def sub(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  _op(:sub, input_a, input_b, name: name)
end

#subtract(input_a, input_b, name: nil) ⇒ Object

Returns x - y element-wise.

This operation supports boradcasting



352
353
354
355
# File 'lib/tensor_stream/ops.rb', line 352

def subtract(input_a, input_b, name: nil)
  input_a, input_b = check_data_types(input_a, input_b)
  sub(input_a, input_b, name: name)
end

#tan(input, name: nil) ⇒ Object

Computes tan of input element-wise.



513
514
515
516
# File 'lib/tensor_stream/ops.rb', line 513

def tan(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:tan, input, nil, name: name)
end

#tanh(input, name: nil) ⇒ Object

Computes tanh of input element-wise.



520
521
522
523
# File 'lib/tensor_stream/ops.rb', line 520

def tanh(input, name: nil)
  check_allowed_types(input, FLOATING_POINT_TYPES)
  _op(:tanh, input, nil, name: name)
end

#tile(input, multiples, name: nil) ⇒ Object

Constructs a tensor by tiling a given tensor.

This operation creates a new tensor by replicating input multiples times. The output tensor’s i’th dimension has input.dims(i) * multiples elements, and the values of input are replicated multiples times along the ‘i’th dimension. For example, tiling [a b c d] by [2] produces [a b c d a b c d].



108
109
110
# File 'lib/tensor_stream/ops.rb', line 108

def tile(input, multiples, name: nil)
  _op(:tile, input, multiples, name: name)
end

#transpose(tensor, perm: nil, name: 'transpose') ⇒ Object

Transposes a. Permutes the dimensions according to perm.



585
586
587
# File 'lib/tensor_stream/ops.rb', line 585

def transpose(tensor, perm: nil, name: 'transpose')
  _op(:transpose, tensor, nil, perm: perm, name: name)
end

#where(condition, true_t = nil, false_t = nil, name: nil) ⇒ Object

Return the elements, either from x or y, depending on the condition.



286
287
288
# File 'lib/tensor_stream/ops.rb', line 286

def where(condition, true_t = nil, false_t = nil, name: nil)
  _op(:where, true_t, false_t, pred: condition, name: name)
end

#zeros(shape, dtype: :float32, name: nil) ⇒ Object

Creates a tensor with all elements set to zero



152
153
154
# File 'lib/tensor_stream/ops.rb', line 152

def zeros(shape, dtype: :float32, name: nil)
  _op(:zeros, shape, nil, data_type: dtype, name: name)
end

#zeros_initializer(dtype: nil) ⇒ Object

initializer that generates tensors initialized to 0.



120
121
122
# File 'lib/tensor_stream/ops.rb', line 120

def zeros_initializer(dtype: nil)
  TensorStream::Initializer.new(-> { _op(:zeros, nil, nil, data_type: dtype) })
end

#zeros_like(tensor, dtype: nil, name: nil) ⇒ Object

reates a tensor with all elements set to zero. Given a single tensor (tensor), this operation returns a tensor of the same type and shape as tensor with all elements set to zero. Optionally, you can use dtype to specify a new type for the returned tensor.



433
434
435
# File 'lib/tensor_stream/ops.rb', line 433

def zeros_like(tensor, dtype: nil, name: nil)
  _op(:zeros_like, tensor, nil, data_type: dtype, name: name)
end