Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
np.asarray(self.indices, dtype=idx_dtype),
self.data,
np.asarray(other.indptr, dtype=idx_dtype),
np.asarray(other.indices, dtype=idx_dtype),
other.data,
indptr, indices, data)
actual_nnz = indptr[-1]
indices = indices[:actual_nnz]
data = data[:actual_nnz]
if actual_nnz < maxnnz // 2:
# too much waste, trim arrays
indices = indices.copy()
data = data.copy()
if isinstance(other, fast_csr_matrix) and (not op in bool_ops):
A = fast_csr_matrix((data, indices, indptr), dtype=data.dtype, shape=self.shape)
else:
A = csr_matrix((data, indices, indptr), dtype=data.dtype, shape=self.shape)
return A
np.asarray(self.indptr, dtype=idx_dtype),
np.asarray(self.indices, dtype=idx_dtype),
self.data,
np.asarray(other.indptr, dtype=idx_dtype),
np.asarray(other.indices, dtype=idx_dtype),
other.data,
indptr, indices, data)
actual_nnz = indptr[-1]
indices = indices[:actual_nnz]
data = data[:actual_nnz]
if actual_nnz < maxnnz // 2:
# too much waste, trim arrays
indices = indices.copy()
data = data.copy()
if isinstance(other, fast_csr_matrix) and (not op in bool_ops):
A = fast_csr_matrix((data, indices, indptr), dtype=data.dtype, shape=self.shape)
else:
A = csr_matrix((data, indices, indptr), dtype=data.dtype, shape=self.shape)
return A
self._data = inpt
self.dims = dims
self._isherm = False
return
if fast == 'mc-dm':
# fast Qobj construction for use in mcsolve with dm output
self._data = inpt
self.dims = dims
self._isherm = True
return
if isinstance(inpt, Qobj):
# if input is already Qobj then return identical copy
self._data = fast_csr_matrix((inpt.data.data, inpt.data.indices,
inpt.data.indptr),
shape=inpt.shape, copy=copy)
if not np.any(dims):
# Dimensions of quantum object used for keeping track of tensor
# components
self.dims = inpt.dims
else:
self.dims = dims
self.superrep = inpt.superrep
self._isunitary = inpt._isunitary
elif inpt is None:
# initialize an empty Qobj with correct dimensions and shape
else:
N, M = 1, 1
self.dims = [[N], [M]]
self._data = fast_csr_matrix(shape=(N, M))
elif isinstance(inpt, list) or isinstance(inpt, tuple):
# case where input is a list
data = np.array(inpt)
if len(data.shape) == 1:
# if list has only one dimension (i.e [5,4])
data = data.transpose()
_tmp = sp.csr_matrix(data, dtype=complex)
self._data = fast_csr_matrix((_tmp.data, _tmp.indices, _tmp.indptr),
shape=_tmp.shape)
if not np.any(dims):
self.dims = [[int(data.shape[0])], [int(data.shape[1])]]
else:
self.dims = dims
elif isinstance(inpt, np.ndarray) or sp.issparse(inpt):
# case where input is array or sparse
if inpt.ndim == 1:
inpt = inpt[:, np.newaxis]
do_copy = copy
if not isinstance(inpt, fast_csr_matrix):
_tmp = sp.csr_matrix(inpt, dtype=complex, copy=do_copy)
_tmp.sort_indices() #Make sure indices are sorted.
do_copy = 0
def _with_data(self,data,copy=True):
"""Returns a matrix with the same sparsity structure as self,
but with different data. By default the structure arrays
(i.e. .indptr and .indices) are copied.
"""
# We need this just in case something like abs(data) gets called
# does nothing if data.dtype is complex.
data = np.asarray(data, dtype=complex)
if copy:
return fast_csr_matrix((data,self.indices.copy(),self.indptr.copy()),
shape=self.shape,dtype=data.dtype)
else:
return fast_csr_matrix((data,self.indices,self.indptr),
shape=self.shape,dtype=data.dtype)
Quantum object: dims = [[4], [4]], \
shape = [4, 4], type = oper, isHerm = False
Qobj data =
[[ 0.00000000+0.j 1.00000000+0.j 0.00000000+0.j 0.00000000+0.j]
[ 0.00000000+0.j 0.00000000+0.j 1.41421356+0.j 0.00000000+0.j]
[ 0.00000000+0.j 0.00000000+0.j 0.00000000+0.j 1.73205081+0.j]
[ 0.00000000+0.j 0.00000000+0.j 0.00000000+0.j 0.00000000+0.j]]
'''
if not isinstance(N, (int, np.integer)): # raise error if N not integer
raise ValueError("Hilbert space dimension must be integer value")
data = np.sqrt(np.arange(offset+1, N+offset, dtype=complex))
ind = np.arange(1,N, dtype=np.int32)
ptr = np.arange(N+1, dtype=np.int32)
ptr[-1] = N-1
return Qobj(fast_csr_matrix((data,ind,ptr),shape=(N,N)), isherm=False)
Internal functions for generating the data representing the J-z operator.
"""
N = int(2*j+1)
data = np.array([j-k for k in range(N) if (j-k)!=0], dtype=complex)
# Even shaped matrix
if (N % 2 == 0):
ind = np.arange(N, dtype=np.int32)
ptr = np.arange(N+1,dtype=np.int32)
ptr[-1] = N
# Odd shaped matrix
else:
j = int(j)
ind = np.array(list(range(j))+list(range(j+1,N)), dtype=np.int32)
ptr = np.array(list(range(j+1))+list(range(j,N)), dtype=np.int32)
ptr[-1] = N-1
return fast_csr_matrix((data,ind,ptr), shape=(N,N))
if len(np.setdiff1d(cperm, np.arange(ncols))) != 0:
raise Exception('Invalid column permutation array.')
shp = A.shape
kind = A.getformat()
if kind == 'csr':
flag = 0
elif kind == 'csc':
flag = 1
else:
raise Exception('Input must be Qobj, CSR, or CSC matrix.')
data, ind, ptr = _sparse_permute(A.data, A.indices, A.indptr,
nrows, ncols, rperm, cperm, flag)
if kind == 'csr':
return fast_csr_matrix((data, ind, ptr), shape=shp)
elif kind == 'csc':
return sp.csc_matrix((data, ind, ptr), shape=shp, dtype=data.dtype)
def _jplus(j):
"""
Internal functions for generating the data representing the J-plus
operator.
"""
m = np.arange(j, -j - 1, -1, dtype=complex)
data = (np.sqrt(j * (j + 1.0) - (m + 1.0) * m))[1:]
N = m.shape[0]
ind = np.arange(1, N, dtype=np.int32)
ptr = np.array(list(range(N-1))+[N-1]*2, dtype=np.int32)
ptr[-1] = N-1
return fast_csr_matrix((data,ind,ptr), shape=(N,N))