--
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/e227c031-cdae-4e05-a7b2-6c34ff7d1da8n%40googlegroups.com.
"""Unpickle a Node"cdef np.ndarray _get_node_ndarray(self):
node_ndarray = d['nodes']
node_ndarray.astype(NODE_DTYPE, casting="same_kind")
...
"""Wraps nodes as a NumPy struct array to return to user.
Keep reference to the existing class.
"""
cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp> self.node_count
cdef np.npy_intp strides[1]
strides[0] = sizeof(Node)
cdef np.ndarray arr
Py_INCREF(NODE_DTYPE)
# I use NODE_DTYPE here
arr = PyArray_NewFromDescr(<PyTypeObject *> np.ndarray,
<np.dtype> NODE_DTYPE, 1, shape,strides, <void*> self.nodes,np.NPY_DEFAULT, None)
Py_INCREF(self)
if PyArray_SetBaseObject(arr, <PyObject*> self) < 0:
raise ValueError("Can't initialize array.")
return arrThanks for all the help. Let me know if I can provide more information.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/7e9377fd-aa63-51c1-cb24-e70e0c8c1b76%40d-woods.co.uk.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/9e820c4d-dd4a-4624-8c89-36e5a84f936cn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/CAJ1JY4oFQyx_HPLEmAERke8%2B3UgQR2HQQtB6UymLj0zEAqvKtw%40mail.gmail.com.
cdef __cinit__(self, n_cols):# compute the numpy dtype when instantiating cuz we'll know n_colsself.node_dtype = np.dtype([("I", np.int), ("k", np.float64), ("weights", np.float32, n_cols), ("indicies", np.int, n_cols)])cpdef pickle/unpickle():# we'll know how many nodes we have# so I can initialize the array needed in numpy to hold all the data from all nodes
arr = np.zeros((num_nodes * size_of_each_node,), dtype=self.node_dtype)
cdef get_node_vals(node) nogil:
# I can say set the node weights/indices on the fly as needed
vector[float] weights = get_weights(...)vector[float] indices = get_indices(...)
node.indices = indices
node.weights = weights
To view this discussion on the web visit https://groups.google.com/d/msgid/cython-users/90b35484-9dd2-d582-87e1-efa1ef91c7eb%40d-woods.co.uk.