Skip to content

Commit

Permalink
test block functions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxscheurer committed Dec 28, 2020
1 parent 9f5139c commit 7fdf95d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions adcc/OneParticleOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def size(self):
"""
Returns the number of elements of the OneParticleOperator
"""
sh = self.shape
return sh[0] * sh[1]
return np.prod(self.shape)

@property
def blocks_nonzero(self):
Expand All @@ -109,8 +108,8 @@ def block(self, block):
return self._tensors[block]

def __getitem__(self, block):
# TODO: sanity checks
assert block in self.blocks
s1, s2 = split_spaces(block)
if block not in self._tensors:
sym = libadcc.make_symmetry_operator(
self.mospaces, block, self.is_symmetric, "1"
Expand All @@ -125,14 +124,15 @@ def set_block(self, block, tensor):
"""
Assigns tensor to a given block
"""
# TODO: sanity checks
assert block in self.blocks
s1, s2 = split_spaces(block)
self._tensors[block] = tensor

def set_zero_block(self, block):
"""
Set a given block as zero block
"""
# TODO: sanity checks
assert block in self.blocks
self._tensors.pop(block)

Expand Down
8 changes: 7 additions & 1 deletion adcc/test_OneParticleOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,13 @@ def test_imul(self):
a *= 12
assert_array_almost_equal_nulp(a.to_ndarray(), ref)

def test_is_zero_block(self):
def test_block_functions(self):
ref = cache.refstate["h2o_sto3g"]
a = OneParticleOperator(ref.mospaces, is_symmetric=True)
a["o1o1"].set_random()
a["o1v1"].set_random()
a["v1v1"].set_random()
assert a.size == a.shape[0] * a.shape[1]
assert not a.is_zero_block("v1o1")
a.set_zero_block("o1o1")
assert a.is_zero_block("o1o1")

0 comments on commit 7fdf95d

Please sign in to comment.