Complex tensorsΒΆ

Complex tensors are stored in the ctensor class. ctensor supports all the same operations as rtensor.

>>> A=cnine.ctensor.gaussian(4,4)
>>> A
[ (1.3828,0.74589) (0.0523187,-1.75177) (-0.904146,-0.965146) (1.87065,-0.474282) ]
[ (-1.66043,-0.546571) (-0.688081,-0.0384917) (0.0757219,0.194947) (1.47339,-0.485144) ]
[ (0.097221,-0.370271) (-0.89237,-1.12408) (-0.228782,1.73664) (1.16493,0.882195) ]
[ (0.584898,-1.50279) (-0.660558,0.570759) (0.534755,-0.929941) (-0.607787,-0.934988) ]

>>> A(1,2)
(0.075721874833107+0.1949467808008194j)
>>> A[1,2]=3+4j
>>> A
[ (1.3828,0.74589) (0.0523187,-1.75177) (-0.904146,-0.965146) (1.87065,-0.474282) ]
[ (-1.66043,-0.546571) (-0.688081,-0.0384917) (3,4) (1.47339,-0.485144) ]
[ (0.097221,-0.370271) (-0.89237,-1.12408) (-0.228782,1.73664) (1.16493,0.882195) ]
[ (0.584898,-1.50279) (-0.660558,0.570759) (0.534755,-0.929941) (-0.607787,-0.934988) ]

In addition, it also has conj and herm methods to take the conjugate and conjugate transpose (Hermitian conjugate) of the tensor.

>>> A=cnine.ctensor.gaussian(4,4)
>>> print(A.conj())
[ (-1.23974,-0.584898) (-0.407472,0.660558) (1.61201,-0.534755) (0.399771,0.607787) ]
[ (1.3828,-0.74589) (0.0523187,1.75177) (-0.904146,0.965146) (1.87065,0.474282) ]
[ (-1.66043,0.546571) (-0.688081,0.0384917) (0.0757219,-0.194947) (1.47339,0.485144) ]
[ (0.097221,0.370271) (-0.89237,1.12408) (-0.228782,-1.73664) (1.16493,-0.882195) ]

A ctensor can be converted to a (single precision) complex Pytorch tensor and vica versa with the same syntax we use to convert rtensors.

>>> A=cnine.ctensor.gaussian(3,3)
>>> A
[ (-1.50279,0.570759) (-0.929941,-0.934988) (-0.764676,0.250854) ]
[ (-0.188164,-1.51315) (1.32256,1.93468) (1.25244,1.0417) ]
[ (-0.696964,0.537104) (0.694816,0.541231) (-1.96886,0.354178) ]

>>> B=A.torch()
>>> B
tensor([[-1.5028+0.5708j, -0.9299-0.9350j, -0.7647+0.2509j],
        [-0.1882-1.5131j,  1.3226+1.9347j,  1.2524+1.0417j],
        [-0.6970+0.5371j,  0.6948+0.5412j, -1.9689+0.3542j]])
>>> A=torch.rand([3,3],dtype=torch.cfloat)
>>> A
tensor([[0.0931+0.4546j, 0.5153+0.3481j, 0.2664+0.9136j],
        [0.3851+0.0492j, 0.2501+0.5490j, 0.1102+0.8175j],
        [0.6905+0.2471j, 0.1203+0.2893j, 0.0232+0.9650j]])
>>> B=cnine.ctensor(A)
>>> B
[ (0.0931288,0.454564) (0.515316,0.348107) (0.266408,0.913579) ]
[ (0.385131,0.0491744) (0.250079,0.54895) (0.110203,0.817535) ]
[ (0.6905,0.247147) (0.120259,0.28926) (0.0231515,0.965036) ]