From e94a07db28136448d6d4a3f2daddd44ce1bc975a Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 4 Jul 2016 22:57:09 -0700 Subject: [PATCH] Simplify csr.cg and use operations from .ops --- opencl_fdfd/csr.py | 166 +++++++++------------------------------------ 1 file changed, 33 insertions(+), 133 deletions(-) diff --git a/opencl_fdfd/csr.py b/opencl_fdfd/csr.py index d3314e4..e42ad8f 100644 --- a/opencl_fdfd/csr.py +++ b/opencl_fdfd/csr.py @@ -1,128 +1,12 @@ import numpy from numpy.linalg import norm - import pyopencl import pyopencl.array -from pyopencl.elementwise import ElementwiseKernel -from pyopencl.reduction import ReductionKernel import time -def type_to_C(float_type: numpy.float32 or numpy.float64) -> str: - """ - Returns a string corresponding to the C equivalent of a numpy type. - - :param float_type: numpy type: float32, float64, complex64, complex128 - :return: string containing the corresponding C type (eg. 'double') - """ - types = { - numpy.float32: 'float', - numpy.float64: 'double', - numpy.complex64: 'cfloat_t', - numpy.complex128: 'cdouble_t', - } - if float_type not in types: - raise Exception('Unsupported type') - - return types[float_type] - - -def create_ops(context): - preamble = ''' - #define PYOPENCL_DEFINE_CDOUBLE - #include - ''' - - ctype = type_to_C(numpy.complex128) - - # ------------------------------------- - - spmv_source = ''' - int start = m_row_ptr[i]; - int stop = m_row_ptr[i+1]; - cdouble_t dot = cdouble_new(0.0, 0.0); - - int col_ind, d_ind; - for (int j=start; j