test_map.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:bifrost 作者: ledatelescope 项目源码 文件源码
def test_polarisation_products(self):
        n = 89
        real = np.random.randint(-127, 128, size=(n,2)).astype(np.float32)
        imag = np.random.randint(-127, 128, size=(n,2)).astype(np.float32)
        a = real + 1j * imag
        a_orig = a
        a = bf.asarray(a, space='cuda')
        b = bf.empty_like(a)
        for _ in xrange(3):
            bf.map('''
            auto x = a(_,0);
            auto y = a(_,1);
            b(_,0).assign(x.mag2(), y.mag2());
            b(_,1) = x*y.conj();
            ''', shape=b.shape[:-1], data={'a': a, 'b': b})
        b = b.copy('system')
        a = a_orig
        gold = np.empty_like(a)
        def mag2(x):
            return x.real * x.real + x.imag * x.imag
        gold[...,0] = mag2(a[...,0]) + 1j * mag2(a[...,1])
        gold[...,1] = a[...,0] * a[...,1].conj()
        np.testing.assert_equal(b, gold)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号