From 358fd0071afc8a9ddd5e37c2f5113b3d90c2efab Mon Sep 17 00:00:00 2001 From: Jon Alberdi Date: Tue, 12 Feb 2019 16:22:29 +0100 Subject: [PATCH] Use memoryviews for sample_weight_data Use https://cython.readthedocs.io/en/latest/src/userguide/numpy_tutorial.html#efficient-indexing-with-memoryviews instead of casting the arrays.data attribute into a DOUBLE*. The former strategy generated segfaults in some servers. --- pyfm_fast.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfm_fast.pyx b/pyfm_fast.pyx index 8c5c82a..051115a 100644 --- a/pyfm_fast.pyx +++ b/pyfm_fast.pyx @@ -485,7 +485,7 @@ cdef class CSRDataset: cdef INTEGER *feature_indices_ptr cdef np.ndarray index cdef INTEGER *index_data_ptr - cdef DOUBLE *sample_weight_data + cdef DOUBLE [:] sample_weight_data def __cinit__(self, np.ndarray[DOUBLE, ndim=1, mode='c'] X_data, np.ndarray[INTEGER, ndim=1, mode='c'] X_indptr, @@ -522,7 +522,7 @@ cdef class CSRDataset: self.X_indptr_ptr = X_indptr.data self.X_indices_ptr = X_indices.data self.Y_data_ptr = Y.data - self.sample_weight_data = sample_weight.data + self.sample_weight_data = sample_weight # Use index array for fast shuffling cdef np.ndarray[INTEGER, ndim=1, mode='c'] index = np.arange(0, self.n_samples,