Skip to content

Commit

Permalink
Merge pull request #732 from sahmed95/4.2-release_ready
Browse files Browse the repository at this point in the history
4.2 release ready
  • Loading branch information
ajgpitch committed Jul 27, 2017
2 parents 8f6d6f0 + 24e4051 commit fabf2a9
Show file tree
Hide file tree
Showing 21 changed files with 248 additions and 151 deletions.
72 changes: 36 additions & 36 deletions qutip/cy/graph_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###############################################################################
import numpy as np
cimport numpy as np
cimport numpy as cnp
cimport cython
from libcpp.algorithm cimport sort
from libcpp.vector cimport vector
np.import_array()
cnp.import_array()

include "parameters.pxi"

cdef extern from "numpy/arrayobject.h" nogil:
void PyArray_ENABLEFLAGS(np.ndarray arr, int flags)
void PyArray_ENABLEFLAGS(cnp.ndarray arr, int flags)
void PyDataMem_FREE(void * ptr)
void PyDataMem_RENEW(void * ptr, size_t size)
void PyDataMem_NEW_ZEROED(size_t size, size_t elsize)
Expand Down Expand Up @@ -100,8 +100,8 @@ cpdef int[::1] _node_degrees(int[::1] ind, int[::1] ptr,
@cython.boundscheck(False)
@cython.wraparound(False)
def _breadth_first_search(
np.ndarray[ITYPE_t, ndim=1, mode="c"] ind,
np.ndarray[ITYPE_t, ndim=1, mode="c"] ptr,
cnp.ndarray[ITYPE_t, ndim=1, mode="c"] ind,
cnp.ndarray[ITYPE_t, ndim=1, mode="c"] ptr,
int num_rows, int seed):
"""
Does a breath first search (BSF) of a graph in sparse CSR format matrix
Expand All @@ -112,8 +112,8 @@ def _breadth_first_search(
cdef unsigned int level_start = 0
cdef unsigned int level_end = N
cdef unsigned int current_level = 1
cdef np.ndarray[ITYPE_t] order = -1 * np.ones(num_rows, dtype=ITYPE)
cdef np.ndarray[ITYPE_t] level = -1 * np.ones(num_rows, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] order = -1 * np.ones(num_rows, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] level = -1 * np.ones(num_rows, dtype=ITYPE)

level[seed] = 0
order[0] = seed
Expand Down Expand Up @@ -145,7 +145,7 @@ def _reverse_cuthill_mckee(int[::1] ind, int[::1] ptr, int num_rows):
"""
cdef unsigned int N = 0, N_old, seed, level_start, level_end
cdef unsigned int zz, i, j, ii, jj, kk, ll, level_len, temp, temp2
cdef np.ndarray[int, ndim=1] order = np.zeros(num_rows, dtype=np.int32)
cdef cnp.ndarray[int, ndim=1] order = np.zeros(num_rows, dtype=np.int32)
cdef int[::1] degree = _node_degrees(ind, ptr, num_rows)
cdef int * inds = int_argsort(&degree[0], num_rows)
cdef int * rev_inds = int_argsort(inds, num_rows)
Expand Down Expand Up @@ -210,8 +210,8 @@ def _reverse_cuthill_mckee(int[::1] ind, int[::1] ptr, int num_rows):
@cython.boundscheck(False)
@cython.wraparound(False)
def _pseudo_peripheral_node(
np.ndarray[ITYPE_t, ndim=1, mode="c"] ind,
np.ndarray[ITYPE_t, ndim=1, mode="c"] ptr,
cnp.ndarray[ITYPE_t, ndim=1, mode="c"] ind,
cnp.ndarray[ITYPE_t, ndim=1, mode="c"] ptr,
int num_rows):
"""
Find a pseudo peripheral node of a graph represented by a sparse
Expand All @@ -220,9 +220,9 @@ def _pseudo_peripheral_node(

cdef unsigned int ii, jj, delta, flag, node, start
cdef int maxlevel, minlevel, minlastnodesdegree
cdef np.ndarray[np.intp_t] lastnodes
cdef np.ndarray[np.intp_t] lastnodesdegree
cdef np.ndarray[np.intp_t] degree = np.zeros(num_rows, dtype=ITYPE)
cdef cnp.ndarray[cnp.intp_t] lastnodes
cdef cnp.ndarray[cnp.intp_t] lastnodesdegree
cdef cnp.ndarray[cnp.intp_t] degree = np.zeros(num_rows, dtype=ITYPE)

degree = _node_degrees(ind, ptr, num_rows).astype(ITYPE)
start = 0
Expand Down Expand Up @@ -254,15 +254,15 @@ def _pseudo_peripheral_node(
@cython.boundscheck(False)
@cython.wraparound(False)
def _maximum_bipartite_matching(
np.ndarray[ITYPE_t, ndim=1, mode="c"] inds,
np.ndarray[ITYPE_t, ndim=1, mode="c"] ptrs,
cnp.ndarray[ITYPE_t, ndim=1, mode="c"] inds,
cnp.ndarray[ITYPE_t, ndim=1, mode="c"] ptrs,
int n):

cdef np.ndarray[ITYPE_t] visited = np.zeros(n, dtype=ITYPE)
cdef np.ndarray[ITYPE_t] queue = np.zeros(n, dtype=ITYPE)
cdef np.ndarray[ITYPE_t] previous = np.zeros(n, dtype=ITYPE)
cdef np.ndarray[ITYPE_t] match = -1 * np.ones(n, dtype=ITYPE)
cdef np.ndarray[ITYPE_t] row_match = -1 * np.ones(n, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] visited = np.zeros(n, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] queue = np.zeros(n, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] previous = np.zeros(n, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] match = -1 * np.ones(n, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] row_match = -1 * np.ones(n, dtype=ITYPE)
cdef int queue_ptr, queue_col, ptr, i, j, queue_size
cdef int row, col, temp, eptr, next_num = 1

Expand Down Expand Up @@ -306,9 +306,9 @@ def _maximum_bipartite_matching(
@cython.boundscheck(False)
@cython.wraparound(False)
def _max_row_weights(
np.ndarray[DTYPE_t, ndim=1, mode="c"] data,
np.ndarray[ITYPE_t, ndim=1, mode="c"] inds,
np.ndarray[ITYPE_t, ndim=1, mode="c"] ptrs,
double[::1] data,
int[::1] inds,
int[::1] ptrs,
int ncols):
"""
Finds the largest abs value in each matrix column
Expand All @@ -318,7 +318,7 @@ def _max_row_weights(
This keeps us from having to call abs over and over.
"""
cdef np.ndarray[DTYPE_t] weights = np.zeros(ncols + 1, dtype=DTYPE)
cdef cnp.ndarray[DTYPE_t] weights = np.zeros(ncols + 1, dtype=DTYPE)
cdef int ln, mx, ii, jj
cdef DTYPE_t weight, current

Expand All @@ -343,24 +343,24 @@ def _max_row_weights(
@cython.boundscheck(False)
@cython.wraparound(False)
def _weighted_bipartite_matching(
np.ndarray[DTYPE_t, ndim=1, mode="c"] data,
np.ndarray[ITYPE_t, ndim=1, mode="c"] inds,
np.ndarray[ITYPE_t, ndim=1, mode="c"] ptrs,
double[::1] data,
int[::1] inds,
int[::1] ptrs,
int n):
"""
Here we assume that the user already took the ABS value of the data.
This keeps us from having to call abs over and over.
"""

cdef np.ndarray[ITYPE_t] visited = np.zeros(n, dtype=ITYPE)
cdef np.ndarray[ITYPE_t] queue = np.zeros(n, dtype=ITYPE)
cdef np.ndarray[ITYPE_t] previous = np.zeros(n, dtype=ITYPE)
cdef np.ndarray[ITYPE_t] match = -1 * np.ones(n, dtype=ITYPE)
cdef np.ndarray[ITYPE_t] row_match = -1 * np.ones(n, dtype=ITYPE)
cdef np.ndarray[DTYPE_t] weights = _max_row_weights(data, inds, ptrs, n)
cdef np.ndarray[ITYPE_t] order = np.argsort(-weights[0:n]).astype(ITYPE)
cdef np.ndarray[ITYPE_t] row_order = np.zeros(int(weights[n]), dtype=ITYPE)
cdef np.ndarray[DTYPE_t] temp_weights = np.zeros(int(weights[n]), dtype=DTYPE)
cdef cnp.ndarray[ITYPE_t] visited = np.zeros(n, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] queue = np.zeros(n, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] previous = np.zeros(n, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] match = -1 * np.ones(n, dtype=ITYPE)
cdef cnp.ndarray[ITYPE_t] row_match = -1 * np.ones(n, dtype=ITYPE)
cdef cnp.ndarray[DTYPE_t] weights = _max_row_weights(data, inds, ptrs, n)
cdef cnp.ndarray[ITYPE_t] order = np.argsort(-weights[0:n]).astype(ITYPE)
cdef cnp.ndarray[ITYPE_t] row_order = np.zeros(int(weights[n]), dtype=ITYPE)
cdef cnp.ndarray[DTYPE_t] temp_weights = np.zeros(int(weights[n]), dtype=DTYPE)
cdef int queue_ptr, queue_col, queue_size, next_num
cdef int i, j, zz, ll, kk, row, col, temp, eptr, temp2

Expand Down
4 changes: 2 additions & 2 deletions qutip/cy/heom.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###############################################################################
import numpy as np
cimport numpy as np
cimport numpy as cnp
cimport cython

@cython.boundscheck(False)
Expand All @@ -46,7 +46,7 @@ def cy_pad_csr(object A, int row_scale, int col_scale, int insertrow=0, int inse
cdef int temp, temp2
cdef int[::1] ind = A.indices
cdef int[::1] ptr_in = A.indptr
cdef np.ndarray[int, ndim=1, mode='c'] ptr_out = np.zeros(nrowout+1,dtype=np.int32)
cdef cnp.ndarray[int, ndim=1, mode='c'] ptr_out = np.zeros(nrowout+1,dtype=np.int32)

A._shape = (nrowout, ncolout)
if insertcol == 0:
Expand Down
6 changes: 3 additions & 3 deletions qutip/cy/interpolate.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###############################################################################
import numpy as np
cimport numpy as np
cimport numpy as cnp
from libc.math cimport (fabs, fmin)
cimport cython

Expand Down Expand Up @@ -94,7 +94,7 @@ def arr_interp(double[::1] x, double a, double b, double[::1] c):
cdef size_t ii, jj
cdef int l, m
cdef double pos
cdef np.ndarray[double, ndim=1, mode="c"] out = np.zeros(lenx, dtype=float)
cdef cnp.ndarray[double, ndim=1, mode="c"] out = np.zeros(lenx, dtype=float)

for jj in range(lenx):
l = <int>((x[jj]-a)/h) + 1
Expand All @@ -118,7 +118,7 @@ def arr_zinterp(double[::1] x, double a, double b, complex[::1] c):
cdef size_t ii, jj
cdef int l, m
cdef double pos
cdef np.ndarray[complex, ndim=1, mode="c"] out = np.zeros(lenx, dtype=complex)
cdef cnp.ndarray[complex, ndim=1, mode="c"] out = np.zeros(lenx, dtype=complex)

for jj in range(lenx):
l = <int>((x[jj]-a)/h) + 1
Expand Down
2 changes: 1 addition & 1 deletion qutip/cy/openmp/br_omp.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###############################################################################
cimport numpy as np
cimport numpy as cnp

#Spectral function with signature (w,t)
ctypedef complex (*spec_func)(double, double)
Expand Down
4 changes: 2 additions & 2 deletions qutip/cy/openmp/parfuncs.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###############################################################################
cimport numpy as np
cimport numpy as cnp
cimport cython

cpdef np.ndarray[complex, ndim=1, mode="c"] spmv_csr_openmp(complex[::1] data,
cpdef cnp.ndarray[complex, ndim=1, mode="c"] spmv_csr_openmp(complex[::1] data,
int[::1] ind, int[::1] ptr, complex[::1] vec, unsigned int nthr)


Expand Down
24 changes: 12 additions & 12 deletions qutip/cy/openmp/parfuncs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###############################################################################
import numpy as np
cimport numpy as np
cimport numpy as cnp
cimport cython

cdef extern from "src/zspmv_openmp.hpp" nogil:
Expand All @@ -41,7 +41,7 @@ cdef extern from "src/zspmv_openmp.hpp" nogil:

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef np.ndarray[complex, ndim=1, mode="c"] spmv_openmp(
cpdef cnp.ndarray[complex, ndim=1, mode="c"] spmv_openmp(
object super_op,
complex[::1] vec,
unsigned int nthr):
Expand All @@ -67,7 +67,7 @@ cpdef np.ndarray[complex, ndim=1, mode="c"] spmv_openmp(

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef np.ndarray[complex, ndim=1, mode="c"] spmv_csr_openmp(complex[::1] data,
cpdef cnp.ndarray[complex, ndim=1, mode="c"] spmv_csr_openmp(complex[::1] data,
int[::1] ind, int[::1] ptr, complex[::1] vec, unsigned int nthr):
"""
Sparse matrix, dense vector multiplication.
Expand All @@ -92,7 +92,7 @@ cpdef np.ndarray[complex, ndim=1, mode="c"] spmv_csr_openmp(complex[::1] data,
"""
cdef unsigned int num_rows = vec.shape[0]
cdef np.ndarray[complex, ndim=1, mode="c"] out = np.zeros(num_rows, dtype=complex)
cdef cnp.ndarray[complex, ndim=1, mode="c"] out = np.zeros(num_rows, dtype=complex)
zspmvpy_openmp(&data[0], &ind[0], &ptr[0], &vec[0], 1.0, &out[0], num_rows, nthr)
return out

Expand All @@ -111,7 +111,7 @@ cdef inline void spmvpy_openmp(complex * data, int * ind, int * ptr,

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef np.ndarray[complex, ndim=1, mode="c"] cy_ode_rhs_openmp(
cpdef cnp.ndarray[complex, ndim=1, mode="c"] cy_ode_rhs_openmp(
double t,
complex[::1] rho,
complex[::1] data,
Expand All @@ -120,7 +120,7 @@ cpdef np.ndarray[complex, ndim=1, mode="c"] cy_ode_rhs_openmp(
unsigned int nthr):

cdef unsigned int nrows = rho.shape[0]
cdef np.ndarray[complex, ndim=1, mode="c"] out = \
cdef cnp.ndarray[complex, ndim=1, mode="c"] out = \
np.zeros((nrows), dtype=complex)
zspmvpy_openmp(&data[0], &ind[0], &ptr[0], &rho[0], 1.0, &out[0], nrows, nthr)

Expand All @@ -129,9 +129,9 @@ cpdef np.ndarray[complex, ndim=1, mode="c"] cy_ode_rhs_openmp(

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef np.ndarray[complex, ndim=1, mode="c"] cy_ode_psi_func_td_openmp(
cpdef cnp.ndarray[complex, ndim=1, mode="c"] cy_ode_psi_func_td_openmp(
double t,
np.ndarray[complex, ndim=1, mode="c"] psi,
cnp.ndarray[complex, ndim=1, mode="c"] psi,
object H_func,
object args,
unsigned int nthr):
Expand All @@ -142,9 +142,9 @@ cpdef np.ndarray[complex, ndim=1, mode="c"] cy_ode_psi_func_td_openmp(

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef np.ndarray[complex, ndim=1, mode="c"] cy_ode_psi_func_td_with_state_openmp(
cpdef cnp.ndarray[complex, ndim=1, mode="c"] cy_ode_psi_func_td_with_state_openmp(
double t,
np.ndarray[complex, ndim=1, mode="c"] psi,
cnp.ndarray[complex, ndim=1, mode="c"] psi,
object H_func,
object args,
unsigned int nthr):
Expand All @@ -155,9 +155,9 @@ cpdef np.ndarray[complex, ndim=1, mode="c"] cy_ode_psi_func_td_with_state_openmp

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef np.ndarray[complex, ndim=1, mode="c"] cy_ode_rho_func_td_openmp(
cpdef cnp.ndarray[complex, ndim=1, mode="c"] cy_ode_rho_func_td_openmp(
double t,
np.ndarray[complex, ndim=1, mode="c"] rho,
cnp.ndarray[complex, ndim=1, mode="c"] rho,
object L0,
object L_func,
object args,
Expand Down
10 changes: 6 additions & 4 deletions qutip/cy/parameters.pxi
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import numpy as np
cimport numpy as cnp

DTYPE = np.float64
ctypedef np.float64_t DTYPE_t
ctypedef cnp.float64_t DTYPE_t

ITYPE = np.int32
ctypedef np.int32_t ITYPE_t
ctypedef cnp.int32_t ITYPE_t

CTYPE = np.complex128
ctypedef np.complex128_t CTYPE_t
ctypedef cnp.complex128_t CTYPE_t

CTYPE = np.int64
ctypedef np.int64_t LTYPE_t
ctypedef cnp.int64_t LTYPE_t
12 changes: 6 additions & 6 deletions qutip/cy/ptrace.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import numpy as np
from qutip.cy.spconvert import zcsr_reshape
from qutip.cy.spmath import zcsr_mult
from qutip.fastsparse import fast_csr_matrix
cimport numpy as np
cimport numpy as cnp
cimport cython
from libc.math cimport floor, trunc

Expand All @@ -50,7 +50,7 @@ def _ptrace(object rho, _sel):

cdef size_t mm, ii
cdef int _tmp
cdef np.ndarray[int, ndim=1, mode='c'] drho = np.asarray(rho.dims[0], dtype=np.int32).ravel()
cdef cnp.ndarray[int, ndim=1, mode='c'] drho = np.asarray(rho.dims[0], dtype=np.int32).ravel()

if isinstance(_sel, int):
_sel = np.array([_sel], dtype=np.int32)
Expand All @@ -77,7 +77,7 @@ def _ptrace(object rho, _sel):
_tmp = indrest[mm] * N + indrest[mm]-1
indrest[mm] = _tmp

cdef np.ndarray[int, ndim=1, mode='c'] ind = np.zeros(M**2*indrest.shape[0],dtype=np.int32)
cdef cnp.ndarray[int, ndim=1, mode='c'] ind = np.zeros(M**2*indrest.shape[0],dtype=np.int32)
for mm in range(M**2):
for ii in range(indrest.shape[0]):
ind[mm*indrest.shape[0]+ii] = indrest[ii] + \
Expand All @@ -99,7 +99,7 @@ def _ptrace(object rho, _sel):
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
cpdef np.ndarray[int, ndim=1, mode='c'] _list2ind(int[:,::1] ilist, int[::1] dims):
cpdef cnp.ndarray[int, ndim=1, mode='c'] _list2ind(int[:,::1] ilist, int[::1] dims):
"""!
Private function returning indicies
"""
Expand All @@ -115,13 +115,13 @@ cpdef np.ndarray[int, ndim=1, mode='c'] _list2ind(int[:,::1] ilist, int[::1] dim
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
cpdef np.ndarray[int, ndim=2, mode='c'] _select(int[::1] sel, int[::1] dims, int M):
cpdef cnp.ndarray[int, ndim=2, mode='c'] _select(int[::1] sel, int[::1] dims, int M):
"""
Private function finding selected components
"""
cdef size_t ii, jj, kk
cdef int _sel, _prd
cdef np.ndarray[int, ndim=2, mode='c'] ilist = np.zeros((M, dims.shape[0]), dtype=np.int32)
cdef cnp.ndarray[int, ndim=2, mode='c'] ilist = np.zeros((M, dims.shape[0]), dtype=np.int32)
for jj in range(sel.shape[0]):
_sel = sel[jj]
_prd = 1
Expand Down

0 comments on commit fabf2a9

Please sign in to comment.