コード例 #1
0
ファイル: __init__.py プロジェクト: jinlccs/CNTK
def times(left, right, name=None):
    """
    Tensor times operation. The output of this operation is the
    tensor product of the two input tensors. It supports broadcasting. In
    case of scalars its backward pass to left propagates right
    times the received gradient and vice versa.

    Example:
        >>> C.eval(C.times([[1,2],[3,4]], [5,6]))
        [array([[ 17.,  39.]])]
        
        >>> C.eval(C.times([[1,2],[3,4],[5,6]], [[0.5,0.25],[0.25,0.5]]))
        [array([[[ 1.  ,  1.25],
                 [ 2.5 ,  2.75],
                 [ 4.  ,  4.25]]])]

    Args:
        left: left side tensor
        right: right side tensor
        name: the name of the node in the network            
    Returns:
        :class:`cntk.graph.ComputationNode`
    """
    from cntk.ops.cntk2 import Times
    return Times(left, right, name=name)
コード例 #2
0
ファイル: __init__.py プロジェクト: ironhide23586/CNTK
def times(left, right, output_rank=1, name=None):
    """
    The output of this operation is the matrix product of the two input matrices.
    It supports broadcasting. Sparse is supported in the right operand, if it is a matrix.
    The operator '@' has been overloaded such that in Python 3.5 and later X @ W equals times(X, W).

    Example:
        >>> C.eval(C.times([[1,2],[3,4]], [5,6]))
        [array([[ 17.,  39.]])]
        
        >>> C.eval(cntk.times(np.reshape(np.arange(8), (2,2,2)),np.reshape(np.arange(8), (2,2,2)), output_rank=1))        
        [array([[[ 28.,  34.],
        [ 76.,  98.]]])]
        
        >>> C.eval(cntk.times(np.reshape(np.arange(8), (2,2,2)),np.reshape(np.arange(8), (2,2,2)), output_rank=2))        
        [array([[[[[  4.,   5.],
          [  6.,   7.]],

         [[ 12.,  17.],
          [ 22.,  27.]]],


        [[[ 20.,  29.],
          [ 38.,  47.]],

         [[ 28.,  41.],
          [ 54.,  67.]]]]])]

    Args:
        left: left side matrix or tensor
        right: right side matrix or tensor
        output_rank: in case we have tensors as arguemnts, output_rank represents
            the number of axes to be collapsed in order to transform the tensors
            into matrices, perform the operation and then reshape back (explode the axes)
        name: the name of the node in the network            

    Returns:
        :class:`cntk.graph.ComputationNode`
    """
    from cntk.ops.cntk2 import Times   
    # CNTK uses column vectors and column major representation, thus we reverse
    # params    
    op = Times(right, left, outputRank=output_rank, name=name)
    wrap_numpy_arrays(op)    
    op.rank = op.x.rank + op.y.rank - 2    
    return op
コード例 #3
0
ファイル: __init__.py プロジェクト: msincenselee/CNTK
def times(left, right, output_rank=1, name=None):
    """
    The output of this operation is the matrix product of the two input matrices.
    It supports broadcasting. Sparse is supported in the right operand, if it is a matrix.
    The operator '@' has been overloaded such that in Python 3.5 and later X @ W equals times(X, W).

    Example:
        >>> C.eval(C.times([[1,2],[3,4]], [5,6]))
        [array([[ 17.,  39.]])]
        
        >>> C.eval(cntk.times(np.reshape(np.arange(8), (2,2,2)),np.reshape(np.arange(8), (2,2,2)), output_rank=1))        
        [array([[[ 28.,  34.],
        [ 76.,  98.]]])]
        
        >>> C.eval(cntk.times(np.reshape(np.arange(8), (2,2,2)),np.reshape(np.arange(8), (2,2,2)), output_rank=2))        
        [array([[[[[  4.,   5.],
                   [  6.,   7.]],
                  [[ 12.,  17.],
                   [ 22.,  27.]]],
                 [[[ 20.,  29.],
                   [ 38.,  47.]],
                  [[ 28.,  41.],
                   [ 54.,  67.]]]]])]

    Args:
        left: left side matrix or tensor
        right: right side matrix or tensor
        output_rank (int): in case we have tensors as arguemnts, output_rank represents
            the number of axes to be collapsed in order to transform the tensors
            into matrices, perform the operation and then reshape back (explode the axes)
        name (str): the name of the node in the network            

    Returns:
        :class:`cntk.graph.ComputationNode`
    """
    from cntk.ops.cntk2 import Times
    # CNTK uses column vectors and column major representation, thus we reverse
    # params
    op = Times(right, left, outputRank=output_rank, name=name)
    wrap_numpy_arrays(op)
    op.rank = op.x.rank + op.y.rank - 2
    return op
コード例 #4
0
ファイル: __init__.py プロジェクト: salomarx/CNTK
def times(left, right, output_rank=1, name=None):
    """
    The output of this operation is the matrix product of the two input matrices.
    It supports broadcasting. In case of scalars its backward pass to left propagates right
    times the received gradient and vice versa.
    The operator (@) has been overloaded and can equally be used instead of times().
    However, it is supported in python versions 3.5 or above.

    Example:
        >>> C.eval(C.times([[1,2],[3,4]], [5,6]))
        [array([[ 17.,  39.]])]
        
        >>> C.eval(cntk.times(np.reshape(np.arange(8), (2,2,2)),np.reshape(np.arange(8), (2,2,2)), output_rank=1))        
        [array([[[ 28.,  34.],
        [ 76.,  98.]]])]
        
        >>> C.eval(cntk.times(np.reshape(np.arange(8), (2,2,2)),np.reshape(np.arange(8), (2,2,2)), output_rank=2))        
        [array([[[[[  4.,   5.],
          [  6.,   7.]],

         [[ 12.,  17.],
          [ 22.,  27.]]],


        [[[ 20.,  29.],
          [ 38.,  47.]],

         [[ 28.,  41.],
          [ 54.,  67.]]]]])]

    Args:
        left: left side matrix or tensor
        right: right side matrix or tensor
        output_rank: in case we have tensors as arguemnts, output_rank represents
            the number of axes to be collapsed in order to transform the tensors
            into matrices, perform the operation and then reshape back (explode the axes)
        name: the name of the node in the network            
    Returns:
        :class:`cntk.graph.ComputationNode`
    """
    from cntk.ops.cntk2 import Times
    return Times(left, right, outputRank=output_rank, name=name)