Ejemplo n.º 1
0
def test_eigh_raises():
    np.random.seed(10)
    num_charges = 1
    D = 20
    R = 3
    charges = [
        BaseCharge(np.random.randint(-5, 6, (num_charges, D), dtype=np.int16),
                   charge_types=[U1Charge] * num_charges) for n in range(R)
    ]
    flows = [False] * R
    inds = [Index(charges[n], flows[n]) for n in range(R)]
    A = BlockSparseTensor.random(inds)
    with pytest.raises(NotImplementedError):
        eigh(A)
Ejemplo n.º 2
0
def test_eigh_prod(dtype, Ds, num_charges):
  np.random.seed(10)
  R = len(Ds)
  charges = [
      BaseCharge(
          np.random.randint(-5, 6, (num_charges, Ds[n]), dtype=np.int16),
          charge_types=[U1Charge] * num_charges) for n in range(R)
  ]
  flows = [False] * R
  inds = [Index(charges[n], flows[n]) for n in range(R)]
  A = BlockSparseTensor.random(
      inds + [i.copy().flip_flow() for i in inds], dtype=dtype)
  dims = np.prod(Ds)
  A = A.reshape([dims, dims])
  B = A + A.T.conj()
  E, V = eigh(B)
  B_ = V @ diag(E) @ V.conj().T
  np.testing.assert_allclose(B.data, B_.data)
  for n in range(len(B._charges)):
    assert charge_equal(B_._charges[n], B._charges[n])