Created
June 30, 2015 19:10
-
-
Save vighneshbirodkar/95e10d2a6637d629ede2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# distutils: language = c++ | |
from cython.parallel import parallel, prange | |
from libcpp.vector cimport vector | |
from libc.stdlib cimport malloc, free | |
cdef struct Data: | |
int x | |
int y | |
cdef Data* data_ptr | |
cdef vector[Data]* data_vector | |
cdef vector[Data]** vector_array | |
cdef int scale_num = 10 | |
cdef int scale = 0 | |
cdef Data* data_array = <Data*>malloc(sizeof(Data)*scale_num) | |
vector_array = <vector[Data]**>malloc(scale_num*sizeof(void*)) | |
for scale in range(scale_num): | |
vector_array[scale] = new vector[Data]() | |
with nogil: | |
for scale in prange(scale_num): | |
# Add elements to vector_array[scale] here | |
data_array[scale].x = scale | |
data_array[scale].y = scale*10 | |
vector_array[scale] = new vector[Data]() | |
vector_array[scale].push_back(data_array[scale]) | |
data_array[scale].x *= 2 | |
data_array[scale].y *= 2 | |
vector_array[scale].push_back(data_array[scale]) | |
cdef int a,b | |
a = 1 | |
for scale in range(scale_num): | |
data_vector = vector_array[scale] | |
print("Vector ", data_vector.at(0).x, ", ", data_vector.at(0).y) | |
print("Vector ", data_vector.at(1).x, ", ", data_vector.at(1).y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment