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)
评论列表
文章目录