mpi_util.py
def cdgemm(a, b, alpha=1, c=None, beta=0, ):
    
    '''Matrix-matrix multiplication for double precision arrays
    '''
    m = a.shape[0]
    k = a.shape[1]
    n = b.shape[1]
    if a.flags.c_contiguous:
        trans_a = 'N'
    elif a.flags.f_contiguous:
        trans_a = 'T'
        a = a.T
    else:
        a = np.asarray(a, order='C')
        trans_a = 'N'
        #raise ValueError('a.flags: %s' % str(a.flags))

    assert(k == b.shape[0])
    if b.flags.c_contiguous:
        trans_b = 'N'
    elif b.flags.f_contiguous:
        trans_b = 'T'
        b = b.T
    else:
        b = np.asarray(b, order='C')
        trans_b = 'N'
        #raise ValueError('b.flags: %s' % str(b.flags))

    if c is None:
        c = np.empty((m,n))
        beta = 0
    else:
        assert(c.shape == (m,n))

    offseta=0
    offsetb=0
    offsetc=0
    
    if a.size == 0 or b.size == 0:
        if beta == 0:
            c[:] = 0
        else:
            c[:] *= beta
        return c

    assert(a.flags.c_contiguous)
    assert(b.flags.c_contiguous)
    assert(c.flags.c_contiguous)

    mpi_util.dgemm(ctypes.c_char(trans_b.encode('ascii')),
                       ctypes.c_char(trans_a.encode('ascii')),
                       ctypes.c_int(n), ctypes.c_int(m), ctypes.c_int(k),
                       ctypes.c_int(b.shape[1]), ctypes.c_int(a.shape[1]),
                       ctypes.c_int(c.shape[1]),
                       b.ctypes.data_as(ctypes.c_void_p),
                       a.ctypes.data_as(ctypes.c_void_p),
                       c.ctypes.data_as(ctypes.c_void_p),
                       ctypes.c_double(alpha), ctypes.c_double(beta))
    return c
Matrix-matrix multiplication for double precision arrays
    
Matrix-matrix multiplication for double precision arrays
Matrix - matrix multiplication for double precision arrays
def cdgemm(a, b, alpha=1, c=None, beta=0, ):
    m = a.shape[0]
    k = a.shape[1]
    n = b.shape[1]
    if a.flags.c_contiguous:
        trans_a = 'N'
    elif a.flags.f_contiguous:
        trans_a = 'T'
        a = a.T
    else:
        a = np.asarray(a, order='C')
        trans_a = 'N'
    assert(k == b.shape[0])
    if b.flags.c_contiguous:
        trans_b = 'N'
    elif b.flags.f_contiguous:
        trans_b = 'T'
        b = b.T
    else:
        b = np.asarray(b, order='C')
        trans_b = 'N'
    if c is None:
        c = np.empty((m,n))
        beta = 0
    else:
        assert(c.shape == (m,n))
    offseta=0
    offsetb=0
    offsetc=0
    if a.size == 0 or b.size == 0:
        if beta == 0:
            c[:] = 0
        else:
            c[:] *= beta
        return c
    assert(a.flags.c_contiguous)
    assert(b.flags.c_contiguous)
    assert(c.flags.c_contiguous)
    mpi_util.dgemm(ctypes.c_char(trans_b.encode('ascii')),
                       ctypes.c_char(trans_a.encode('ascii')),
                       ctypes.c_int(n), ctypes.c_int(m), ctypes.c_int(k),
                       ctypes.c_int(b.shape[1]), ctypes.c_int(a.shape[1]),
                       ctypes.c_int(c.shape[1]),
                       b.ctypes.data_as(ctypes.c_void_p),
                       a.ctypes.data_as(ctypes.c_void_p),
                       c.ctypes.data_as(ctypes.c_void_p),
                       ctypes.c_double(alpha), ctypes.c_double(beta))
    return c
def cdgemm ( a , b , alpha = 1 , c = None , beta = 0 , ) : m = a . shape [ 0 ] k = a . shape [ 1 ] n = b . shape [ 1 ] if a . flags . c_contiguous : trans_a = 'N' elif a . flags . f_contiguous : trans_a = 'T' a = a . T else : a = np . asarray ( a , order = 'C' ) trans_a = 'N' assert ( k == b . shape [ 0 ] ) if b . flags . c_contiguous : trans_b = 'N' elif b . flags . f_contiguous : trans_b = 'T' b = b . T else : b = np . asarray ( b , order = 'C' ) trans_b = 'N' if c is None : c = np . empty ( ( m , n ) ) beta = 0 else : assert ( c . shape == ( m , n ) ) offseta = 0 offsetb = 0 offsetc = 0 if a . size == 0 or b . size == 0 : if beta == 0 : c [ : ] = 0 else : c [ : ] *= beta return c assert ( a . flags . c_contiguous ) assert ( b . flags . c_contiguous ) assert ( c . flags . c_contiguous ) mpi_util . dgemm ( ctypes . c_char ( trans_b . encode ( 'ascii' ) ) , ctypes . c_char ( trans_a . encode ( 'ascii' ) ) , ctypes . c_int ( n ) , ctypes . c_int ( m ) , ctypes . c_int ( k ) , ctypes . c_int ( b . shape [ 1 ] ) , ctypes . c_int ( a . shape [ 1 ] ) , ctypes . c_int ( c . shape [ 1 ] ) , b . ctypes . data_as ( ctypes . c_void_p ) , a . ctypes . data_as ( ctypes . c_void_p ) , c . ctypes . data_as ( ctypes . c_void_p ) , ctypes . c_double ( alpha ) , ctypes . c_double ( beta ) ) return c
Matrix-matrix multiplication for double precision arrays
Matrix - matrix multiplication for double precision arrays
'''Matrix-matrix multiplication for double precision arrays
    ''' #raise ValueError('a.flags: %s' % str(a.flags)) #raise ValueError('b.flags: %s' % str(b.flags))
a
b
alpha
c
beta