1#cython: language_level=3 2# This file is part of QuTiP: Quantum Toolbox in Python. 3# 4# Copyright (c) 2011 and later, Paul D. Nation and Robert J. Johansson. 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are 9# met: 10# 11# 1. Redistributions of source code must retain the above copyright notice, 12# this list of conditions and the following disclaimer. 13# 14# 2. Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in the 16# documentation and/or other materials provided with the distribution. 17# 18# 3. Neither the name of the QuTiP: Quantum Toolbox in Python nor the names 19# of its contributors may be used to endorse or promote products derived 20# from this software without specific prior written permission. 21# 22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33############################################################################### 34cimport cython 35from qutip.cy.spmatfuncs cimport spmvpy 36from qutip.cy.openmp.parfuncs cimport spmvpy_openmp 37 38 39@cython.boundscheck(False) 40@cython.wraparound(False) 41def _spmvpy(complex[::1] data, 42 int[::1] ind, 43 int[::1] ptr, 44 complex[::1] vec, 45 complex a, 46 complex[::1] out): 47 spmvpy(&data[0], &ind[0], &ptr[0], &vec[0], a, &out[0], vec.shape[0]) 48 49 50 51@cython.boundscheck(False) 52@cython.wraparound(False) 53def _spmvpy_openmp(complex[::1] data, 54 int[::1] ind, 55 int[::1] ptr, 56 complex[::1] vec, 57 complex a, 58 complex[::1] out, 59 unsigned int num_threads): 60 spmvpy_openmp(&data[0], &ind[0], &ptr[0], &vec[0], a, &out[0], vec.shape[0], num_threads) 61