Sha256: 1cc0a6085c4641b0e7d711a324127c1a490e24ee4b0e41a68a1123d84280ff68

Contents?: true

Size: 694 Bytes

Versions: 3

Compression:

Stored size: 694 Bytes

Contents

module TensorStream
  # High level math functions
  class Maths
    extend TensorStream::OpHelper

    module MathFunctions

      ##
      # Normalizes along dimension axis using an L2 norm.
      def l2_normalize(x, axis: nil, epsilon: 1e-12, name: nil)
        TensorStream.name_scope(name, "l2_normalize", values: [x]) do |name|
          x = TensorStream.convert_to_tensor(x, name: "x")
          square_sum = TensorStream.reduce_sum(TensorStream.square(x), axis, keepdims: true)
          x_inv_norm = TensorStream.rsqrt(TensorStream.maximum(square_sum, epsilon))
          TensorStream.multiply(x, x_inv_norm, name: name)
        end
      end
    end

    extend MathFunctions
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tensor_stream-1.0.9 lib/tensor_stream/math/math_ops.rb
tensor_stream-1.0.8 lib/tensor_stream/math/math_ops.rb
tensor_stream-1.0.7 lib/tensor_stream/math/math_ops.rb