Sha256: 04db34832e3a86ef0a755248d4e5085a9340b09cbfadcbe137d0d1d50965803c

Contents?: true

Size: 654 Bytes

Versions: 9

Compression:

Stored size: 654 Bytes

Contents

TensorStream::OpMaker.define_operation :pow do |op|
  op.what_it_does "Computes the power of one value to another X^Y element wise"

  op.parameter :input_a, "tensor X"
  op.parameter :input_b, "tensor Y"

  op.apply_data_type_coercion!
  op.supports_broadcasting!

  op.option :name, "Optional name", :nil

  op.define_gradient do |grad, node, params|
    x, y = params
    z = node
    sx = ts.shape(x)
    sy = ts.shape(y)
    rx, ry = _broadcast_gradient_args(sx, sy)
    gx = ts.reduce_sum(grad * y * ts.pow(x, y - 1), rx)

    log_x = ts.where(x > 0, ts.log(x), ts.zeros_like(x))
    gy = ts.reduce_sum(grad * z * log_x, ry)

    [gx, gy]
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tensor_stream-1.0.9 lib/tensor_stream/ops/pow.rb
tensor_stream-1.0.8 lib/tensor_stream/ops/pow.rb
tensor_stream-1.0.7 lib/tensor_stream/ops/pow.rb
tensor_stream-1.0.6 lib/tensor_stream/ops/pow.rb
tensor_stream-1.0.5 lib/tensor_stream/ops/pow.rb
tensor_stream-1.0.4 lib/tensor_stream/ops/pow.rb
tensor_stream-1.0.3 lib/tensor_stream/ops/pow.rb
tensor_stream-1.0.2 lib/tensor_stream/ops/pow.rb
tensor_stream-1.0.1 lib/tensor_stream/ops/pow.rb