Skip to content

Commit

Permalink
Update rotating_frame to use arraylias (#290)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Puzzuoli <[email protected]>
  • Loading branch information
to24toro and DanPuzzuoli committed Jan 24, 2024
1 parent 0165df1 commit 21d4efe
Show file tree
Hide file tree
Showing 4 changed files with 348 additions and 247 deletions.
6 changes: 5 additions & 1 deletion qiskit_dynamics/arraylias/register_functions/asarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@
import numpy as np
from scipy.sparse import csr_matrix, issparse

from qiskit_dynamics.type_utils import isinstance_qutip_qobj


def register_asarray(alias):
"""register asarray functions to each array libraries"""

@alias.register_default(path="asarray")
def _(arr):
if isinstance_qutip_qobj(arr):
return csr_matrix(arr)
return np.asarray(arr)

@alias.register_function(lib="scipy_sparse", path="asarray")
def _(arr):
if issparse(arr):
if issparse(arr) or issparse(arr[0]):
return arr
return csr_matrix(arr)

Expand Down
Loading

0 comments on commit 21d4efe

Please sign in to comment.