Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is `*` documented in tensorflow?

I don't find where * is documented. It seems that it can be equivalent to either tf.multiply or tf.scalar_mul. Is it so?

like image 245
user1424739 Avatar asked Dec 11 '17 04:12

user1424739


People also ask

What is API in TensorFlow?

The TensorFlow Core APIs provide a set of comprehensive, composable, and extensible low-level APIs for high-performance (distributed & accelerated) computation, primarily aimed at building machine learning (ML) models as well as authoring ML workflow tools and frameworks within the TensorFlow platform.

Which client languages are supported in TensorFlow?

TensorFlow can be used in a wide variety of programming languages, including Python, JavaScript, C++, and Java. This flexibility lends itself to a range of applications in many different sectors.

What is a TensorFlow core?

TensorFlow is an end-to-end open source platform for machine learning. TensorFlow makes it easy for beginners and experts to create machine learning models.

What is TF constant?

tf. constant is useful for asserting that the value can be embedded that way. If the argument dtype is not specified, then the type is inferred from the type of value . # Constant 1-D Tensor from a python list. tf.


1 Answers

The most reliable documentation is the source code:

def _mul_dispatch(x, y, name=None):
  """Dispatches cwise mul for "Dense*Dense" and "Dense*Sparse"."""
  is_tensor_y = isinstance(y, ops.Tensor)
  if is_tensor_y:
    return gen_math_ops._mul(x, y, name=name)
  else:
    assert isinstance(y, sparse_tensor.SparseTensor)  # Case: Dense * Sparse.
    new_vals = gen_sparse_ops.sparse_dense_cwise_mul(y.indices, y.values,
                                                     y.dense_shape, x, name)
    return sparse_tensor.SparseTensor(y.indices, new_vals, y.dense_shape)

...

_OverrideBinaryOperatorHelper(_mul_dispatch, "mul")

This means __mul__ operator overload, which does _mul_dispatch. As you can see, it calls either gen_math_ops._mul (which is the under-the-hood core function of tf.multiply) or sparse_dense_cwise_mul if the tensor is sparse.

By the way, tf.scalar_mul is just a wrapper over scalar * x (source code), so it's basically the same thing, but the dependency is the other way around.

like image 117
Maxim Avatar answered Sep 19 '22 16:09

Maxim