• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python umath_tests.matrix_multiply函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.core.umath_tests.matrix_multiply函数的典型用法代码示例。如果您正苦于以下问题:Python matrix_multiply函数的具体用法?Python matrix_multiply怎么用?Python matrix_multiply使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了matrix_multiply函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: better_rec

 def better_rec(self, w, model, s=1, weights=1, damp_z=1):
     """Quick switch to allow reconstruction at unknown scale
     returns a,r and scale"""
     from numpy.core.umath_tests import matrix_multiply
     proj = matrix_multiply(self.cam[np.newaxis], model)
     proj[:, :2] = (proj[:, :2] * s + w * weights) / (s + weights)
     proj[:, 2] *= damp_z
     out = matrix_multiply(self.cam.T[np.newaxis], proj)
     return out
开发者ID:Weacera,项目名称:tf-pose-estimation,代码行数:9,代码来源:prob_model.py


示例2: test_gufunc_new_axis

    def test_gufunc_new_axis(self):

        @guvectorize([void(float64[:, :], float64[:, :], float64[:, :])],
                     '(m,n),(n,p)->(m,p)',
                     target='cuda')
        def matmulcore(A, B, C):
            m, n = A.shape
            n, p = B.shape
            for i in range(m):
                for j in range(p):
                    C[i, j] = 0
                    for k in range(n):
                        C[i, j] += A[i, k] * B[k, j]

        gufunc = matmulcore

        X = np.random.randn(10, 3, 3)
        Y = np.random.randn(3, 3)

        gold = ut.matrix_multiply(X, Y)

        res1 = gufunc(X, Y)
        np.testing.assert_allclose(gold, res1)

        res2 = gufunc(X, np.tile(Y, (10, 1, 1)))
        np.testing.assert_allclose(gold, res2)
开发者ID:FedericoStra,项目名称:numba,代码行数:26,代码来源:test_gufunc.py


示例3: test_gufunc_auto_transfer

    def test_gufunc_auto_transfer(self):

        @guvectorize([void(float32[:, :], float32[:, :], float32[:, :])],
                     '(m,n),(n,p)->(m,p)',
                     target='cuda')
        def matmulcore(A, B, C):
            m, n = A.shape
            n, p = B.shape
            for i in range(m):
                for j in range(p):
                    C[i, j] = 0
                    for k in range(n):
                        C[i, j] += A[i, k] * B[k, j]

        gufunc = matmulcore
        gufunc.max_blocksize = 512

        matrix_ct = 2
        A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2,
                                                                   4)
        B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4,
                                                                   5)

        dB = cuda.to_device(B)

        C = gufunc(A, dB).copy_to_host()
        Gold = ut.matrix_multiply(A, B)
        self.assertTrue(np.allclose(C, Gold))
开发者ID:FedericoStra,项目名称:numba,代码行数:28,代码来源:test_gufunc.py


示例4: test_gufunc

    def test_gufunc(self):

        @guvectorize([void(float32[:, :], float32[:, :], float32[:, :])],
                     '(m,n),(n,p)->(m,p)',
                     target='cuda')
        def matmulcore(A, B, C):
            m, n = A.shape
            n, p = B.shape
            for i in range(m):
                for j in range(p):
                    C[i, j] = 0
                    for k in range(n):
                        C[i, j] += A[i, k] * B[k, j]

        gufunc = matmulcore
        gufunc.max_blocksize = 512

        matrix_ct = 1001 # an odd number to test thread/block division in CUDA
        A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2,
                                                                   4)
        B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4,
                                                                   5)

        C = gufunc(A, B)
        Gold = ut.matrix_multiply(A, B)
        self.assertTrue(np.allclose(C, Gold))
开发者ID:FedericoStra,项目名称:numba,代码行数:26,代码来源:test_gufunc.py


示例5: test_gufunc_stream

    def test_gufunc_stream(self):
        #cuda.driver.flush_pending_free()
        matrix_ct = 1001 # an odd number to test thread/block division in CUDA
        A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2,
                                                                   4)
        B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4,
                                                                   5)

        ts = time()
        stream = cuda.stream()
        dA = cuda.to_device(A, stream)
        dB = cuda.to_device(B, stream)

        dC = cuda.device_array(shape=(1001, 2, 5), dtype=A.dtype, stream=stream)
        dC = gufunc(dA, dB, out=dC, stream=stream)
        C = dC.copy_to_host(stream=stream)
        stream.synchronize()

        tcuda = time() - ts

        ts = time()
        Gold = ut.matrix_multiply(A, B)
        tcpu = time() - ts

        stream_speedups.append(tcpu / tcuda)

        self.assertTrue(np.allclose(C, Gold))
开发者ID:GaZ3ll3,项目名称:numba,代码行数:27,代码来源:test_gufunc.py


示例6: _map_params_to_P_zero

def _map_params_to_P_zero(params, params_type, initial, params_slice, filler,
                          boo, cholesky_of_P_zero,
                          square_root_filters):
    """Map parameters from params to P_zero."""
    # write params in filler
    filler[:] = 0
    filler[boo] = params[params_slice]

    # transform the filler
    if params_type == 'short' or cholesky_of_P_zero is True:
        if square_root_filters is False:
            # make chol_t to not chol
            filler = matrix_multiply(
                np.transpose(filler, axes=(0, 2, 1)), filler)
    else:
        # make not_chol to not_chol (as covariance matrices are symmetric,
        # only half of its off-diagonal elements have to be estimated. here the
        # lower triangle is filled with he transpose of the upper triangle.)
        for i in range(len(filler)):
            filler[i] += (filler[i] - np.diag(np.diagonal(filler[i]))).T

        if square_root_filters is True:
            # make not_chol to chol_t
            filler = np.transpose(cholesky(filler), axes=(0, 2, 1))

    if square_root_filters is False:
        initial[:] = filler
    else:
        initial[:, :, 1:, 1:] = filler
开发者ID:suri5471,项目名称:skillmodels,代码行数:29,代码来源:parse_params.py


示例7: check_matmul_gufunc

    def check_matmul_gufunc(self, gufunc):
        matrix_ct = 1001
        A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2, 4)
        B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4, 5)

        C = gufunc(A, B)
        Gold = ut.matrix_multiply(A, B)

        self.assertTrue(np.allclose(C, Gold))
开发者ID:stefanseefeld,项目名称:numba,代码行数:9,代码来源:test_gufunc.py


示例8: check_matmul_gufunc

    def check_matmul_gufunc(self, gufunc):
        matrix_ct = 1001
        A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2, 4)
        B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4, 5)

        C = gufunc(A, B)
        Gold = ut.matrix_multiply(A, B)

        np.testing.assert_allclose(C, Gold, rtol=1e-5, atol=1e-8)
开发者ID:FedericoStra,项目名称:numba,代码行数:9,代码来源:test_gufunc.py


示例9: build_and_rot_model

    def build_and_rot_model(a, e, s0, r):
        """
        Build model and rotate according to the identified rotation matrix
        """
        from numpy.core.umath_tests import matrix_multiply

        r2 = Prob3dPose.upgrade_r(r.T).transpose((0, 2, 1))
        mod = Prob3dPose.build_model(a, e, s0)
        mod = matrix_multiply(r2, mod)
        return mod
开发者ID:Weacera,项目名称:tf-pose-estimation,代码行数:10,代码来源:prob_model.py


示例10: transform_points_with_homography

def transform_points_with_homography(H, _xys):
    """
    Args:
        H (ndarray[float64_t, ndim=2]):  homography/perspective matrix
        _xys (ndarray[ndim=2]): (N x 2) array
    """
    xyz  = add_homogenous_coordinate(_xys)
    xyz_t = matrix_multiply(H, xyz)
    xy_t  = remove_homogenous_coordinate(xyz_t)
    return xy_t
开发者ID:Erotemic,项目名称:vtool,代码行数:10,代码来源:linalg.py


示例11: x_to_y

def x_to_y(matFn, date, vecs, reverse=False):
    vecs = np.asarray(vecs)
    assert vecs.ndim == 2 
    assert vecs.shape[1] == 3
        
    et = date2es(date)
    mat = matFn(et)
    if reverse:
        mat = mat.T
    vecsOut = matrix_multiply(mat, vecs[...,np.newaxis]).reshape(vecs.shape)
    return vecsOut
开发者ID:dequis,项目名称:auromat,代码行数:11,代码来源:transform.py


示例12: test_gufunc_adjust_blocksize

    def test_gufunc_adjust_blocksize(self):
        matrix_ct = 1001 # an odd number to test thread/block division in CUDA
        A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2,
                                                                   4)
        B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4,
                                                                   5)

        gufunc.max_blocksize = 32
        C = gufunc(A, B)
        Gold = ut.matrix_multiply(A, B)
        self.assertTrue(np.allclose(C, Gold))
开发者ID:GaZ3ll3,项目名称:numba,代码行数:11,代码来源:test_gufunc.py


示例13: compare_matrix_multiply_results

    def compare_matrix_multiply_results(self, tp):
        d1 = np.array(np.random.rand(2, 3, 4), dtype=tp)
        d2 = np.array(np.random.rand(2, 3, 4), dtype=tp)
        msg = "matrix multiply on type %s" % d1.dtype.name

        def permute_n(n):
            if n == 1:
                return ([0],)
            ret = ()
            base = permute_n(n-1)
            for perm in base:
                for i in range(n):
                    new = perm + [n-1]
                    new[n-1] = new[i]
                    new[i] = n-1
                    ret += (new,)
            return ret

        def slice_n(n):
            if n == 0:
                return ((),)
            ret = ()
            base = slice_n(n-1)
            for sl in base:
                ret += (sl+(slice(None),),)
                ret += (sl+(slice(0, 1),),)
            return ret

        def broadcastable(s1, s2):
            return s1 == s2 or s1 == 1 or s2 == 1

        permute_3 = permute_n(3)
        slice_3 = slice_n(3) + ((slice(None, None, -1),)*3,)

        ref = True
        for p1 in permute_3:
            for p2 in permute_3:
                for s1 in slice_3:
                    for s2 in slice_3:
                        a1 = d1.transpose(p1)[s1]
                        a2 = d2.transpose(p2)[s2]
                        ref = ref and a1.base is not None
                        ref = ref and a2.base is not None
                        if (a1.shape[-1] == a2.shape[-2] and
                                broadcastable(a1.shape[0], a2.shape[0])):
                            assert_array_almost_equal(
                                umt.matrix_multiply(a1, a2),
                                np.sum(a2[..., np.newaxis].swapaxes(-3, -1) *
                                       a1[..., np.newaxis,:], axis=-1),
                                err_msg=msg + ' %s %s' % (str(a1.shape),
                                                          str(a2.shape)))

        assert_equal(ref, True, err_msg="reference check")
开发者ID:BoomShanker,项目名称:numpy,代码行数:53,代码来源:test_ufunc.py


示例14: average

 def average(self):
     
     if len(self.shape) == 1:
         
         import numpy.core.umath_tests as ut
         system = ut.matrix_multiply(self.qs[:,:,np.newaxis], self.qs[:,np.newaxis,:]).sum(axis=0)
         w, v = np.linalg.eigh(system)
         qiT_dot_qref = (self.qs[:,:,np.newaxis] * v[np.newaxis,:,:]).sum(axis=1)
         return Quaternions(v[:,np.argmin((1.-qiT_dot_qref**2).sum(axis=0))])            
     
     else:
         
         raise NotImplementedError('Cannot average multi-dimensionsal Quaternions')
开发者ID:Brimborough,项目名称:deep-motion-analysis,代码行数:13,代码来源:Quaternions.py


示例15: test_gufunc

    def test_gufunc(self):
        gufunc = GUVectorize(matmulcore, '(m,n),(n,p)->(m,p)', target='cpu')
        gufunc.add(argtypes=[float32[:, :], float32[:, :], float32[:, :]])
        gufunc = gufunc.build_ufunc()

        matrix_ct = 1001 # an odd number to test thread/block division in CUDA
        A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2, 4)
        B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4, 5)

        C = gufunc(A, B)
        Gold = ut.matrix_multiply(A, B)

        self.assertTrue(np.allclose(C, Gold))
开发者ID:GaZ3ll3,项目名称:numba,代码行数:13,代码来源:test_gufunc.py


示例16: test_gufunc

    def test_gufunc(self):
        gufunc = GUVectorize(matmulcore, '(m,n),(n,p)->(m,p)',
                             target=self.target)
        gufunc.add((float32[:, :], float32[:, :], float32[:, :]))
        gufunc = gufunc.build_ufunc()

        matrix_ct = 1001
        A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2, 4)
        B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4, 5)

        C = gufunc(A, B)
        Gold = ut.matrix_multiply(A, B)

        self.assertTrue(np.allclose(C, Gold))
开发者ID:MatthieuDartiailh,项目名称:numba,代码行数:14,代码来源:test_gufunc.py


示例17: gmm

def gmm(k, xs, tol=1e-6, max_iter=200):
    """Vectorized version of GMM. Faster than above but still rough."""
    
    n, p = xs.shape
    
    mus, z = initialization.kmeanspp(k, xs, ret='both')
    pis = np.array([len(np.where(z==i)[0])/n for i in np.unique(z)])
    sigmas = np.array([np.eye(p)]*k)

    ll_old = 0
    for i in range(max_iter):
        exp_A = []
        exp_B = []
        ll_new = 0

        # E-step, ws are responsabilities
        ws = np.zeros((k, n))
        for j in range(k):
            ws[j, :] = pis[j]*multivariate_normal(mus[j], sigmas[j]).pdf(xs)
        ws /= ws.sum(0)
            
        # M-step
        pis = ws.sum(axis=1)
        pis /= n

        mus = np.dot(ws, xs)
        mus /= ws.sum(1)[:, None]

        sigmas = np.zeros((k, p, p))
        for j in range(k):
            ys = xs - mus[j, :]
            sigmas[j] = (ws[j,:,None,None]*\
                       matrix_multiply(ys[:,:,None], ys[:,None,:])).sum(axis=0)
        sigmas /= ws.sum(axis=1)[:,None,None]

        # update complete log likelihoood
        ll_new = 0
        for pi, mu, sigma in zip(pis, mus, sigmas):
            ll_new += pi*multivariate_normal(mu, sigma).pdf(xs)
        ll_new = np.log(ll_new).sum()

        # convergence test
        if np.abs(ll_new - ll_old) < tol:
            break
        ll_old = ll_new

    z = ws.T
    labels = np.argmax(z, axis=1)

    return labels
开发者ID:neurodata,项目名称:non-parametric-clustering,代码行数:50,代码来源:gmm.py


示例18: test_cpu_guvectorize

    def test_cpu_guvectorize(self):
        target = 'cpu'

        gufunc = guvectorize([void(float32[:,:], float32[:,:], float32[:,:])],
                             '(m,n),(n,p)->(m,p)',
                             target=target)(matmulcore)

        matrix_ct = 1001 # an odd number to test thread/block division in CUDA
        A = np.arange(matrix_ct * 2 * 4, dtype=np.float32).reshape(matrix_ct, 2, 4)
        B = np.arange(matrix_ct * 4 * 5, dtype=np.float32).reshape(matrix_ct, 4, 5)

        C = gufunc(A, B)
        Gold = ut.matrix_multiply(A, B)

        self.assertTrue(np.allclose(C, Gold))
开发者ID:maartenscholl,项目名称:numba,代码行数:15,代码来源:test_guvectorize_decor.py


示例19: flux_down

 def flux_down(self, fluxDownTop, emission=None):
     '''Compute downwelling radiative flux at interfaces between layers.
     
     Inputs:
         fluxDownTop: flux down at top
         emission: emission from atmospheric levels (N)
             defaults to zero if not given
     Returns:
         vector of downwelling radiative flux between levels (N+1)
         element 0 is the flux down to the surface.'''
     if emission is None:
         emission = np.zeros_like(self.absorptivity)
     E = np.concatenate((emission, np.atleast_1d(fluxDownTop)), axis=-1)
     #  dot product (matrix multiplication) along last axes
     return np.squeeze(matrix_multiply(self.Tdown, E[..., np.newaxis]))
开发者ID:bolliger32,项目名称:climlab,代码行数:15,代码来源:transmissivity.py


示例20: flux_up

 def flux_up(self, fluxUpBottom, emission=None):
     '''Compute upwelling radiative flux at interfaces between layers.
     
     Inputs:
         fluxUpBottom: flux up from bottom
         emission: emission from atmospheric levels (N)
             defaults to zero if not given
     Returns:
         vector of downwelling radiative flux between levels (N+1)
         element N is the flux up to space.'''        
     if emission is None:
         emission = np.zeros_like(self.absorptivity)
     E = np.concatenate((np.atleast_1d(fluxUpBottom),emission), axis=-1)
     #  dot product (matrix multiplication) along last axes
     return np.squeeze(matrix_multiply(self.Tup, E[..., np.newaxis]))
开发者ID:bolliger32,项目名称:climlab,代码行数:15,代码来源:transmissivity.py



注:本文中的numpy.core.umath_tests.matrix_multiply函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ctypeslib.as_array函数代码示例发布时间:2022-05-27
下一篇:
Python umath_tests.innerwt函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap