@@ -6,6 +6,7 @@ from libcpp.string cimport string
6
6
from libcpp.vector cimport vector
7
7
from cpython cimport PyObject, Py_XINCREF, Py_XDECREF, \
8
8
PyObject_CallMethodObjArgs
9
+ from libc.stdlib cimport malloc, free
9
10
from libc.string cimport memcpy
10
11
import cython
11
12
import itertools
@@ -2118,7 +2119,7 @@ cdef class DenseMatrixBase(MatrixBase):
2118
2119
return self .nrows()* self .ncols()
2119
2120
2120
2121
def ravel (self ):
2121
- return [self .get (i, j) for i in range (self .nrows()) for j in range (self .ncols())]
2122
+ return [self ._get (i, j) for i in range (self .nrows()) for j in range (self .ncols())]
2122
2123
2123
2124
def reshape (self , rows , cols ):
2124
2125
if len (self ) != rows* cols:
@@ -3110,7 +3111,8 @@ cdef class _Lambdify(object):
3110
3111
"""
3111
3112
cdef size_t args_size, tot_out_size
3112
3113
cdef list out_shapes
3113
- cdef vector[int ] out_sizes, accum_out_sizes
3114
+ cdef int * out_sizes
3115
+ cdef int * accum_out_sizes
3114
3116
cdef readonly bool real
3115
3117
cdef readonly int n_exprs
3116
3118
@@ -3119,9 +3121,20 @@ cdef class _Lambdify(object):
3119
3121
self .out_shapes = [get_shape(expr) for expr in exprs]
3120
3122
self .n_exprs = len (exprs)
3121
3123
self .args_size = _size(args)
3122
- self .out_sizes = [reduce (mul, shape or (1 ,)) for shape in self .out_shapes]
3123
- self .accum_out_sizes = [sum (self .out_sizes[:i]) for i in range (self .n_exprs + 1 )]
3124
- self .tot_out_size = sum (self .out_sizes)
3124
+ self .out_sizes = < int * > malloc(sizeof(int )* self .n_exprs)
3125
+ self .accum_out_sizes = < int * > malloc(sizeof(int )* (self .n_exprs+ 1 ))
3126
+ self .tot_out_size = 0
3127
+ for idx, shape in enumerate (self .out_shapes):
3128
+ self .out_sizes[idx] = reduce (mul, shape or (1 ,))
3129
+ self .tot_out_size += self .out_sizes[idx]
3130
+ for i in range (self .n_exprs + 1 ):
3131
+ self .accum_out_sizes[i] = 0
3132
+ for j in range (i):
3133
+ self .accum_out_sizes[i] += self .out_sizes[j]
3134
+
3135
+ def __dealloc__ (self ):
3136
+ free(self .out_sizes)
3137
+ free(self .accum_out_sizes)
3125
3138
3126
3139
def __init__ (self , args , *exprs , bool real = True ):
3127
3140
cdef:
@@ -3221,7 +3234,7 @@ cdef class _Lambdify(object):
3221
3234
if nbroadcast > 1 and self .args_size == 1 and inp_shape[- 1 ] != 1 : # Implicit reshape
3222
3235
inp_shape = inp_shape + (1 ,)
3223
3236
new_out_shapes = [inp_shape[:- 1 ] + out_shape for out_shape in self .out_shapes]
3224
- new_out_sizes = [nbroadcast* out_size for out_size in self .out_sizes ]
3237
+ new_out_sizes = [nbroadcast* self .out_sizes[i] for i in range ( self .n_exprs) ]
3225
3238
new_tot_out_size = nbroadcast * self .tot_out_size
3226
3239
if use_numpy is None :
3227
3240
try :
0 commit comments