def _isqubitdims(dims): """Checks whether all entries in a dims list are integer powers of 2. Parameters ---------- dims : nested list of ints Dimensions to be checked. Returns ------- isqubitdims : bool True if and only if every member of the flattened dims list is an integer power of 2. """ return all([2**floor(log2(dim)) == dim for dim in flatten(dims)])
def _isqubitdims(dims): """Checks whether all entries in a dims list are integer powers of 2. Parameters ---------- dims : nested list of ints Dimensions to be checked. Returns ------- isqubitdims : bool True if and only if every member of the flattened dims list is an integer power of 2. """ return all([ 2**floor(log2(dim)) == dim for dim in flatten(dims) ])
def test_unflatten(): l = [[[10, 20, 30], [40, 50, 60]], [[70, 80, 90], [100, 110, 120]]] labels = enumerate_flat(l) assert unflatten(flatten(l), labels) == l
def test_flatten(): l = [[[0], 1], 2] assert_equal(flatten(l), [0, 1, 2])