def true_dot(x, y, grad_preserves_dense=True):
 if hasattr(x, 'getnnz'):
  x = as_sparse_variable(x)
  assert (x.format in ['csr', 'csc'])
 if hasattr(y, 'getnnz'):
  y = as_sparse_variable(y)
  assert (y.format in ['csr', 'csc'])
 x_is_sparse_variable = _is_sparse_variable(x)
 y_is_sparse_variable = _is_sparse_variable(y)
 if ((not x_is_sparse_variable) and (not y_is_sparse_variable)):
  raise TypeError()
 if x_is_sparse_variable:
  return TrueDot(grad_preserves_dense)(x, y)
 else:
  assert y_is_sparse_variable
  return transpose(TrueDot(grad_preserves_dense)(y.T, x.T))

def true_dot ( x , y , grad_preserves_dense = True ) : if hasattr ( x , 'getnnz' ) : x = as_sparse_variable ( x ) assert ( x . format in [ 'csr' , 'csc' ] ) if hasattr ( y , 'getnnz' ) : y = as_sparse_variable ( y ) assert ( y . format in [ 'csr' , 'csc' ] ) x_is_sparse_variable = _is_sparse_variable ( x ) y_is_sparse_variable = _is_sparse_variable ( y ) if ( ( not x_is_sparse_variable ) and ( not y_is_sparse_variable ) ) : raise TypeError ( ) if x_is_sparse_variable : return TrueDot ( grad_preserves_dense ) ( x , y ) else : assert y_is_sparse_variable return transpose ( TrueDot ( grad_preserves_dense ) ( y . T , x . T ) )
operation for efficiently calculating the dot product when one or all operands are sparse .