Skip to content

Commit

Permalink
Use builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericgig committed May 13, 2024
1 parent 8db7701 commit 78ca4a2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions qutip/core/data/csr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from cpython cimport mem

import numbers
import warnings

import builtins
import numpy as np
cimport numpy as cnp
import scipy.sparse
Expand Down Expand Up @@ -101,7 +101,8 @@ cdef class CSR(base.Data):
if len(arg) != 3:
raise ValueError("arg must be a (data, col_index, row_index) tuple")
if np.lib.NumpyVersion(np.__version__) < '2.0.0b1':
copy = bool(copy)
# np2 accept None which act as np1's False
copy = builtins.bool(copy)
data = np.array(arg[0], dtype=np.complex128, copy=copy, order='C')
col_index = np.array(arg[1], dtype=idxint_dtype, copy=copy, order='C')
row_index = np.array(arg[2], dtype=idxint_dtype, copy=copy, order='C')
Expand Down
5 changes: 3 additions & 2 deletions qutip/core/data/dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from libc.string cimport memcpy
cimport cython

import numbers

import builtins
import numpy as np
cimport numpy as cnp
from scipy.linalg cimport cython_blas as blas
Expand Down Expand Up @@ -41,7 +41,8 @@ class OrderEfficiencyWarning(EfficiencyWarning):
cdef class Dense(base.Data):
def __init__(self, data, shape=None, copy=True):
if np.lib.NumpyVersion(np.__version__) < '2.0.0b1':
copy = bool(copy)
# np2 accept None which act as np1's False
copy = builtins.bool(copy)
base = np.array(data, dtype=np.complex128, order='K', copy=copy)
# Ensure that the array is contiguous.
# Non contiguous array with copy=False would otherwise slip through
Expand Down
6 changes: 3 additions & 3 deletions qutip/core/data/dia.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from cpython cimport mem

import numbers
import warnings

import builtins
import numpy as np
cimport numpy as cnp
import scipy.sparse
Expand Down Expand Up @@ -81,14 +81,14 @@ cdef class Dia(base.Data):
"shapes do not match: ", str(shape), " and ", str(arg.shape),
]))
shape = arg.shape
#
arg = (arg.data, arg.offsets)
if not isinstance(arg, tuple):
raise TypeError("arg must be a scipy matrix or tuple")
if len(arg) != 2:
raise ValueError("arg must be a (data, offsets) tuple")
if np.lib.NumpyVersion(np.__version__) < '2.0.0b1':
copy = bool(copy)
# np2 accept None which act as np1's False
copy = builtins.bool(copy)
data = np.array(arg[0], dtype=np.complex128, copy=copy, order='C')
offsets = np.array(arg[1], dtype=idxint_dtype, copy=copy, order='C')

Expand Down

0 comments on commit 78ca4a2

Please sign in to comment.