コード例 #1
0
def tensordot(a, b, axes=2):
    '''Tensor dot product of two arrays
    '''
    if isinstance(axes, int):
        bx = range(axes)
        ao = a.getRank() - axes
        ax = [ ao + i for i in bx ]
    else:
        t = type(axes)
        if t is _types.ListType or t is _types.TupleType:
            if len(axes) == 0:
                raise ValueError, "Given axes sequence should be non-empty"

            if len(axes) == 1:
                ax = axes[0]
                bx = axes[0]
            else:
                ax = axes[0]
                bx = axes[1]

            ta = type(ax)
            tal = ta is _types.ListType or ta is _types.TupleType
            tb = type(bx)
            tbl = tb is _types.ListType or tb is _types.TupleType
            if tal != tbl:
                if tal:
                    bx = list(bx)
                else:
                    ax = list(ax)
        else:
            raise ValueError, "Given axes has wrong type"

    return _linalg.tensorDotProduct(a, b, ax, bx)
コード例 #2
0
ファイル: jymaths.py プロジェクト: DawnScience/scisoft-core
def tensordot(a, b, axes=2):
    '''Tensor dot product of two arrays
    '''
    if isinstance(axes, int):
        bx = list(range(axes))
        ao = a.getRank() - axes
        ax = [ao + i for i in bx]
    else:
        if isinstance(axes, (list, tuple)):
            if len(axes) == 0:
                raise ValueError("Given axes sequence should be non-empty")

            if len(axes) == 1:
                ax = axes[0]
                bx = axes[0]
            else:
                ax = axes[0]
                bx = axes[1]

            tal = isinstance(ax, (list, tuple))
            tbl = isinstance(bx, (list, tuple))
            if tal != tbl:
                if tal:
                    bx = list(bx)
                else:
                    ax = list(ax)
        else:
            raise ValueError("Given axes has wrong type")

    return _linalg.tensorDotProduct(a, b, ax, bx)
コード例 #3
0
def tensordot(a, b, axes=2):
    '''Tensor dot product of two arrays
    '''
    if isinstance(axes, int):
        bx = range(axes)
        ao = a.getRank() - axes
        ax = [ ao + i for i in bx ]
    else:
        t = type(axes)
        if t is _types.ListType or t is _types.TupleType:
            if len(axes) == 0:
                raise ValueError, "Given axes sequence should be non-empty"

            if len(axes) == 1:
                ax = axes[0]
                bx = axes[0]
            else:
                ax = axes[0]
                bx = axes[1]

            ta = type(ax)
            tal = ta is _types.ListType or ta is _types.TupleType
            tb = type(bx)
            tbl = tb is _types.ListType or tb is _types.TupleType
            if tal != tbl:
                if tal:
                    bx = list(bx)
                else:
                    ax = list(ax)
        else:
            raise ValueError, "Given axes has wrong type"

    return _linalg.tensorDotProduct(a, b, ax, bx)
コード例 #4
0
def inner(a, b):
    '''Inner product of two arrays (sum product over last dimensions)'''
    return _linalg.tensorDotProduct(a, b, -1, -1)
コード例 #5
0
ファイル: jymaths.py プロジェクト: DawnScience/scisoft-core
def inner(a, b):
    '''Inner product of two arrays (sum product over last dimensions)'''
    return _linalg.tensorDotProduct(a, b, -1, -1)