2017-12-11 148 views

Trả lời

3

Các tài liệu đáng tin cậy nhất là 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") 

Điều này có nghĩa __mul__ điều hành quá tải, mà không _mul_dispatch. Như bạn có thể thấy, nó gọi là gen_math_ops._mul (đó là chức năng cốt lõi dưới mui xe của tf.multiply) hoặc sparse_dense_cwise_mul nếu tensor bị thưa thớt.

Bằng cách này, tf.scalar_mul chỉ là một trình bao bọc trên scalar * x (source code), vì vậy về cơ bản nó giống nhau, nhưng sự phụ thuộc là cách khác.

Các vấn đề liên quan