Skip to content

Commit

Permalink
TN: add isblocksparse, isfermionic checkers
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed Nov 18, 2024
1 parent d1ab1e2 commit b90dbf1
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion quimb/tensor/array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
)

from ..core import njit, qarray
from ..utils import compose as fn_compose
from ..linalg.base_linalg import norm_fro_dense
from ..utils import compose as fn_compose


def asarray(array):
Expand Down Expand Up @@ -64,6 +64,34 @@ def _nd_py_iter(x):
return do("array", nested_tup, like=backend)


_blocksparselookup = {}


def isblocksparse(x):
"""Check if `x` is a block-sparse array. Cached on class for speed."""
try:
return _blocksparselookup[x.__class__]
except KeyError:
# XXX: make this a more established interface
isbs = hasattr(x, "align_axes")
_blocksparselookup[x.__class__] = isbs
return isbs


_fermioniclookup = {}


def isfermionic(x):
"""Check if `x` is a fermionic array. Cached on class for speed."""
try:
return _fermioniclookup[x.__class__]
except KeyError:
# XXX: make this a more established interface
isf = hasattr(x, "phase_flip")
_fermioniclookup[x.__class__] = isf
return isf


@functools.lru_cache(2**14)
def calc_fuse_perm_and_shape(shape, axes_groups):
ndim = len(shape)
Expand Down

0 comments on commit b90dbf1

Please sign in to comment.