Skip to content

Commit fc3437f

Browse files
committed
Replace ->elsize by PyArray_ITEMSIZE
1 parent 4c231f1 commit fc3437f

File tree

5 files changed

+66
-66
lines changed

5 files changed

+66
-66
lines changed

pytensor/sparse/basic.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,7 +3607,7 @@ def perform(self, node, inputs, outputs):
36073607
out[0] = g_a_data
36083608

36093609
def c_code_cache_version(self):
3610-
return (1,)
3610+
return (2,)
36113611

36123612
def c_code(self, node, name, inputs, outputs, sub):
36133613
(_indices, _indptr, _d, _g) = inputs
@@ -3643,11 +3643,11 @@ def c_code(self, node, name, inputs, outputs, sub):
36433643
npy_intp nnz = PyArray_DIMS({_indices})[0];
36443644
npy_intp N = PyArray_DIMS({_indptr})[0]-1; //TODO: error checking with this
36453645
3646-
npy_intp Sindices = PyArray_STRIDES({_indices})[0]/PyArray_DESCR({_indices})->elsize;
3647-
npy_intp Sindptr = PyArray_STRIDES({_indptr})[0]/PyArray_DESCR({_indptr})->elsize;
3646+
npy_intp Sindices = PyArray_STRIDES({_indices})[0]/PyArray_ITEMSIZE({_indices});
3647+
npy_intp Sindptr = PyArray_STRIDES({_indptr})[0]/PyArray_ITEMSIZE({_indptr});
36483648
3649-
const npy_intp Sd1 = PyArray_STRIDES({_d})[1]/PyArray_DESCR({_d})->elsize;
3650-
const npy_intp Sg1 = PyArray_STRIDES({_g})[1]/PyArray_DESCR({_g})->elsize;
3649+
const npy_intp Sd1 = PyArray_STRIDES({_d})[1]/PyArray_ITEMSIZE({_d});
3650+
const npy_intp Sg1 = PyArray_STRIDES({_g})[1]/PyArray_ITEMSIZE({_g});
36513651
36523652
const npy_intp K = PyArray_DIMS({_d})[1];
36533653
@@ -3740,7 +3740,7 @@ def perform(self, node, inputs, outputs):
37403740
out[0] = g_a_data
37413741

37423742
def c_code_cache_version(self):
3743-
return (1,)
3743+
return (2,)
37443744

37453745
def c_code(self, node, name, inputs, outputs, sub):
37463746
(_indices, _indptr, _d, _g) = inputs
@@ -3777,11 +3777,11 @@ def c_code(self, node, name, inputs, outputs, sub):
37773777
// extract number of rows
37783778
npy_intp N = PyArray_DIMS({_indptr})[0]-1; //TODO: error checking with this
37793779
3780-
npy_intp Sindices = PyArray_STRIDES({_indices})[0]/PyArray_DESCR({_indices})->elsize;
3781-
npy_intp Sindptr = PyArray_STRIDES({_indptr})[0]/PyArray_DESCR({_indptr})->elsize;
3780+
npy_intp Sindices = PyArray_STRIDES({_indices})[0]/PyArray_ITEMSIZE({_indices});
3781+
npy_intp Sindptr = PyArray_STRIDES({_indptr})[0]/PyArray_ITEMSIZE({_indptr});
37823782
3783-
const npy_intp Sd1 = PyArray_STRIDES({_d})[1]/PyArray_DESCR({_d})->elsize;
3784-
const npy_intp Sg1 = PyArray_STRIDES({_g})[1]/PyArray_DESCR({_g})->elsize;
3783+
const npy_intp Sd1 = PyArray_STRIDES({_d})[1]/PyArray_ITEMSIZE({_d});
3784+
const npy_intp Sg1 = PyArray_STRIDES({_g})[1]/PyArray_ITEMSIZE({_g});
37853785
37863786
const npy_intp K = PyArray_DIMS({_d})[1];
37873787

pytensor/sparse/rewriting.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ def c_code(self, node, name, inputs, outputs, sub):
158158
159159
dtype_{y}* ydata = (dtype_{y}*)PyArray_DATA({y});
160160
dtype_{z}* zdata = (dtype_{z}*)PyArray_DATA({z});
161-
npy_intp Yi = PyArray_STRIDES({y})[0]/PyArray_DESCR({y})->elsize;
162-
npy_intp Yj = PyArray_STRIDES({y})[1]/PyArray_DESCR({y})->elsize;
161+
npy_intp Yi = PyArray_STRIDES({y})[0]/PyArray_ITEMSIZE({y});
162+
npy_intp Yj = PyArray_STRIDES({y})[1]/PyArray_ITEMSIZE({y});
163163
164164
npy_intp pos;
165165
if ({format} == 0){{
@@ -186,7 +186,7 @@ def infer_shape(self, fgraph, node, shapes):
186186
return [shapes[3]]
187187

188188
def c_code_cache_version(self):
189-
return (2,)
189+
return (3,)
190190

191191

192192
@node_rewriter([sparse.AddSD])
@@ -360,13 +360,13 @@ def c_code(self, node, name, inputs, outputs, sub):
360360
{{PyErr_SetString(PyExc_NotImplementedError, "array too big (overflows int32 index)"); {fail};}}
361361
362362
// strides tell you how many bytes to skip to go to next column/row entry
363-
npy_intp Szm = PyArray_STRIDES({z})[0] / PyArray_DESCR({z})->elsize;
364-
npy_intp Szn = PyArray_STRIDES({z})[1] / PyArray_DESCR({z})->elsize;
365-
//npy_intp Sbm = PyArray_STRIDES({b})[0] / PyArray_DESCR({b})->elsize;
366-
npy_intp Sbn = PyArray_STRIDES({b})[1] / PyArray_DESCR({b})->elsize;
367-
npy_intp Sval = PyArray_STRIDES({a_val})[0] / PyArray_DESCR({a_val})->elsize;
368-
npy_intp Sind = PyArray_STRIDES({a_ind})[0] / PyArray_DESCR({a_ind})->elsize;
369-
npy_intp Sptr = PyArray_STRIDES({a_ptr})[0] / PyArray_DESCR({a_ptr})->elsize;
363+
npy_intp Szm = PyArray_STRIDES({z})[0] / PyArray_ITEMSIZE({z});
364+
npy_intp Szn = PyArray_STRIDES({z})[1] / PyArray_ITEMSIZE({z});
365+
//npy_intp Sbm = PyArray_STRIDES({b})[0] / PyArray_ITEMSIZE({b});
366+
npy_intp Sbn = PyArray_STRIDES({b})[1] / PyArray_ITEMSIZE({b});
367+
npy_intp Sval = PyArray_STRIDES({a_val})[0] / PyArray_ITEMSIZE({a_val});
368+
npy_intp Sind = PyArray_STRIDES({a_ind})[0] / PyArray_ITEMSIZE({a_ind});
369+
npy_intp Sptr = PyArray_STRIDES({a_ptr})[0] / PyArray_ITEMSIZE({a_ptr});
370370
371371
// pointers to access actual data in the arrays passed as params.
372372
dtype_{z}* __restrict__ Dz = (dtype_{z}*)PyArray_DATA({z});
@@ -435,7 +435,7 @@ def c_code(self, node, name, inputs, outputs, sub):
435435
return rval
436436

437437
def c_code_cache_version(self):
438-
return (3,)
438+
return (4,)
439439

440440

441441
sd_csc = StructuredDotCSC()
@@ -553,13 +553,13 @@ def c_code(self, node, name, inputs, outputs, sub):
553553
{{PyErr_SetString(PyExc_NotImplementedError, "array too big (overflows int32 index)"); {fail};}}
554554
555555
// strides tell you how many bytes to skip to go to next column/row entry
556-
npy_intp Szm = PyArray_STRIDES({z})[0] / PyArray_DESCR({z})->elsize;
557-
npy_intp Szn = PyArray_STRIDES({z})[1] / PyArray_DESCR({z})->elsize;
558-
npy_intp Sbm = PyArray_STRIDES({b})[0] / PyArray_DESCR({b})->elsize;
559-
npy_intp Sbn = PyArray_STRIDES({b})[1] / PyArray_DESCR({b})->elsize;
560-
npy_intp Sval = PyArray_STRIDES({a_val})[0] / PyArray_DESCR({a_val})->elsize;
561-
npy_intp Sind = PyArray_STRIDES({a_ind})[0] / PyArray_DESCR({a_ind})->elsize;
562-
npy_intp Sptr = PyArray_STRIDES({a_ptr})[0] / PyArray_DESCR({a_ptr})->elsize;
556+
npy_intp Szm = PyArray_STRIDES({z})[0] / PyArray_ITEMSIZE({z});
557+
npy_intp Szn = PyArray_STRIDES({z})[1] / PyArray_ITEMSIZE({z});
558+
npy_intp Sbm = PyArray_STRIDES({b})[0] / PyArray_ITEMSIZE({b});
559+
npy_intp Sbn = PyArray_STRIDES({b})[1] / PyArray_ITEMSIZE({b});
560+
npy_intp Sval = PyArray_STRIDES({a_val})[0] / PyArray_ITEMSIZE({a_val});
561+
npy_intp Sind = PyArray_STRIDES({a_ind})[0] / PyArray_ITEMSIZE({a_ind});
562+
npy_intp Sptr = PyArray_STRIDES({a_ptr})[0] / PyArray_ITEMSIZE({a_ptr});
563563
564564
// pointers to access actual data in the arrays passed as params.
565565
dtype_{z}* __restrict__ Dz = (dtype_{z}*)PyArray_DATA({z});
@@ -612,7 +612,7 @@ def c_code(self, node, name, inputs, outputs, sub):
612612
""".format(**dict(locals(), **sub))
613613

614614
def c_code_cache_version(self):
615-
return (2,)
615+
return (3,)
616616

617617

618618
sd_csr = StructuredDotCSR()
@@ -842,12 +842,12 @@ def c_code(self, node, name, inputs, outputs, sub):
842842
const npy_int32 * __restrict__ Dptr = (npy_int32*)PyArray_DATA({x_ptr});
843843
const dtype_{alpha} alpha = ((dtype_{alpha}*)PyArray_DATA({alpha}))[0];
844844
845-
npy_intp Sz = PyArray_STRIDES({z})[1] / PyArray_DESCR({z})->elsize;
846-
npy_intp Szn = PyArray_STRIDES({zn})[1] / PyArray_DESCR({zn})->elsize;
847-
npy_intp Sval = PyArray_STRIDES({x_val})[0] / PyArray_DESCR({x_val})->elsize;
848-
npy_intp Sind = PyArray_STRIDES({x_ind})[0] / PyArray_DESCR({x_ind})->elsize;
849-
npy_intp Sptr = PyArray_STRIDES({x_ptr})[0] / PyArray_DESCR({x_ptr})->elsize;
850-
npy_intp Sy = PyArray_STRIDES({y})[1] / PyArray_DESCR({y})->elsize;
845+
npy_intp Sz = PyArray_STRIDES({z})[1] / PyArray_ITEMSIZE({z});
846+
npy_intp Szn = PyArray_STRIDES({zn})[1] / PyArray_ITEMSIZE({zn});
847+
npy_intp Sval = PyArray_STRIDES({x_val})[0] / PyArray_ITEMSIZE({x_val});
848+
npy_intp Sind = PyArray_STRIDES({x_ind})[0] / PyArray_ITEMSIZE({x_ind});
849+
npy_intp Sptr = PyArray_STRIDES({x_ptr})[0] / PyArray_ITEMSIZE({x_ptr});
850+
npy_intp Sy = PyArray_STRIDES({y})[1] / PyArray_ITEMSIZE({y});
851851
852852
// blas expects ints; convert here (rather than just making N etc ints) to avoid potential overflow in the negative-stride correction
853853
if ((N > 0x7fffffffL)||(Sy > 0x7fffffffL)||(Szn > 0x7fffffffL)||(Sy < -0x7fffffffL)||(Szn < -0x7fffffffL))
@@ -893,7 +893,7 @@ def c_code(self, node, name, inputs, outputs, sub):
893893
return rval
894894

895895
def c_code_cache_version(self):
896-
return (3, blas.blas_header_version())
896+
return (4, blas.blas_header_version())
897897

898898

899899
usmm_csc_dense = UsmmCscDense(inplace=False)
@@ -1031,13 +1031,13 @@ def c_code(self, node, name, inputs, outputs, sub):
10311031
npy_intp sp_dim = (M == a_dim_0)?a_dim_1:a_dim_0;
10321032
10331033
// strides tell you how many bytes to skip to go to next column/row entry
1034-
npy_intp Sz = PyArray_STRIDES({z})[0] / PyArray_DESCR({z})->elsize;
1035-
npy_intp Sa_val = PyArray_STRIDES({a_val})[0] / PyArray_DESCR({a_val})->elsize;
1036-
npy_intp Sa_ind = PyArray_STRIDES({a_ind})[0] / PyArray_DESCR({a_ind})->elsize;
1037-
npy_intp Sa_ptr = PyArray_STRIDES({a_ptr})[0] / PyArray_DESCR({a_ptr})->elsize;
1038-
npy_intp Sb_val = PyArray_STRIDES({b_val})[0] / PyArray_DESCR({b_val})->elsize;
1039-
npy_intp Sb_ind = PyArray_STRIDES({b_ind})[0] / PyArray_DESCR({b_ind})->elsize;
1040-
npy_intp Sb_ptr = PyArray_STRIDES({b_ptr})[0] / PyArray_DESCR({b_ptr})->elsize;
1034+
npy_intp Sz = PyArray_STRIDES({z})[0] / PyArray_ITEMSIZE({z});
1035+
npy_intp Sa_val = PyArray_STRIDES({a_val})[0] / PyArray_ITEMSIZE({a_val});
1036+
npy_intp Sa_ind = PyArray_STRIDES({a_ind})[0] / PyArray_ITEMSIZE({a_ind});
1037+
npy_intp Sa_ptr = PyArray_STRIDES({a_ptr})[0] / PyArray_ITEMSIZE({a_ptr});
1038+
npy_intp Sb_val = PyArray_STRIDES({b_val})[0] / PyArray_ITEMSIZE({b_val});
1039+
npy_intp Sb_ind = PyArray_STRIDES({b_ind})[0] / PyArray_ITEMSIZE({b_ind});
1040+
npy_intp Sb_ptr = PyArray_STRIDES({b_ptr})[0] / PyArray_ITEMSIZE({b_ptr});
10411041
10421042
// pointers to access actual data in the arrays passed as params.
10431043
dtype_{z}* __restrict__ Dz = (dtype_{z}*)PyArray_DATA({z});
@@ -1082,7 +1082,7 @@ def c_code(self, node, name, inputs, outputs, sub):
10821082
""".format(**dict(locals(), **sub))
10831083

10841084
def c_code_cache_version(self):
1085-
return (3,)
1085+
return (4,)
10861086

10871087

10881088
csm_grad_c = CSMGradC()
@@ -1476,7 +1476,7 @@ def make_node(self, a_data, a_indices, a_indptr, b):
14761476
)
14771477

14781478
def c_code_cache_version(self):
1479-
return (2,)
1479+
return (3,)
14801480

14811481
def c_code(self, node, name, inputs, outputs, sub):
14821482
(
@@ -1537,7 +1537,7 @@ def c_code(self, node, name, inputs, outputs, sub):
15371537
15381538
dtype_{_zout} * const __restrict__ zout = (dtype_{_zout}*)PyArray_DATA({_zout});
15391539
1540-
const npy_intp Sb = PyArray_STRIDES({_b})[0] / PyArray_DESCR({_b})->elsize;
1540+
const npy_intp Sb = PyArray_STRIDES({_b})[0] / PyArray_ITEMSIZE({_b});
15411541
15421542
// loop over rows
15431543
for (npy_intp j = 0; j < N; ++j)
@@ -1648,7 +1648,7 @@ def make_node(self, a_data, a_indices, a_indptr, b):
16481648
)
16491649

16501650
def c_code_cache_version(self):
1651-
return (3,)
1651+
return (4,)
16521652

16531653
def c_code(self, node, name, inputs, outputs, sub):
16541654
(
@@ -1715,7 +1715,7 @@ def c_code(self, node, name, inputs, outputs, sub):
17151715
17161716
dtype_{_zout} * const __restrict__ zout = (dtype_{_zout}*)PyArray_DATA({_zout});
17171717
1718-
const npy_intp Sb = PyArray_STRIDES({_b})[0] / PyArray_DESCR({_b})->elsize;
1718+
const npy_intp Sb = PyArray_STRIDES({_b})[0] / PyArray_ITEMSIZE({_b});
17191719
17201720
// loop over columns
17211721
for (npy_intp j = 0; j < N; ++j)
@@ -1860,7 +1860,7 @@ def make_node(self, x, y, p_data, p_ind, p_ptr, p_ncols):
18601860
)
18611861

18621862
def c_code_cache_version(self):
1863-
return (4, blas.blas_header_version())
1863+
return (5, blas.blas_header_version())
18641864

18651865
def c_support_code(self, **kwargs):
18661866
return blas.blas_header_text()
@@ -1986,14 +1986,14 @@ def c_code(self, node, name, inputs, outputs, sub):
19861986
dtype_{z_ind}* __restrict__ Dzi = (dtype_{z_ind}*)PyArray_DATA({z_ind});
19871987
dtype_{z_ptr}* __restrict__ Dzp = (dtype_{z_ptr}*)PyArray_DATA({z_ptr});
19881988
1989-
const npy_intp Sdx = PyArray_STRIDES({x})[1]/PyArray_DESCR({x})->elsize;
1990-
const npy_intp Sdy = PyArray_STRIDES({y})[1]/PyArray_DESCR({y})->elsize;
1991-
const npy_intp Sdpd = PyArray_STRIDES({p_data})[0] / PyArray_DESCR({p_data})->elsize;
1992-
const npy_intp Sdpi = PyArray_STRIDES({p_ind})[0] / PyArray_DESCR({p_ind})->elsize;
1993-
const npy_intp Sdpp = PyArray_STRIDES({p_ptr})[0] / PyArray_DESCR({p_ptr})->elsize;
1994-
const npy_intp Sdzd = PyArray_STRIDES({z_data})[0] / PyArray_DESCR({z_data})->elsize;
1995-
const npy_intp Sdzi = PyArray_STRIDES({z_ind})[0] / PyArray_DESCR({z_ind})->elsize;
1996-
const npy_intp Sdzp = PyArray_STRIDES({z_ptr})[0] / PyArray_DESCR({z_ptr})->elsize;
1989+
const npy_intp Sdx = PyArray_STRIDES({x})[1]/PyArray_ITEMSIZE({x});
1990+
const npy_intp Sdy = PyArray_STRIDES({y})[1]/PyArray_ITEMSIZE({y});
1991+
const npy_intp Sdpd = PyArray_STRIDES({p_data})[0] / PyArray_ITEMSIZE({p_data});
1992+
const npy_intp Sdpi = PyArray_STRIDES({p_ind})[0] / PyArray_ITEMSIZE({p_ind});
1993+
const npy_intp Sdpp = PyArray_STRIDES({p_ptr})[0] / PyArray_ITEMSIZE({p_ptr});
1994+
const npy_intp Sdzd = PyArray_STRIDES({z_data})[0] / PyArray_ITEMSIZE({z_data});
1995+
const npy_intp Sdzi = PyArray_STRIDES({z_ind})[0] / PyArray_ITEMSIZE({z_ind});
1996+
const npy_intp Sdzp = PyArray_STRIDES({z_ptr})[0] / PyArray_ITEMSIZE({z_ptr});
19971997
19981998
memcpy(Dzi, Dpi, PyArray_DIMS({p_ind})[0]*sizeof(dtype_{p_ind}));
19991999
memcpy(Dzp, Dpp, PyArray_DIMS({p_ptr})[0]*sizeof(dtype_{p_ptr}));

pytensor/tensor/blas.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def c_header_dirs(self, **kwargs):
504504
int unit = 0;
505505
506506
int type_num = PyArray_DESCR(%(_x)s)->type_num;
507-
int type_size = PyArray_DESCR(%(_x)s)->elsize; // in bytes
507+
int type_size = PyArray_ITEMSIZE(%(_x)s); // in bytes
508508
509509
npy_intp* Nx = PyArray_DIMS(%(_x)s);
510510
npy_intp* Ny = PyArray_DIMS(%(_y)s);
@@ -795,7 +795,7 @@ def build_gemm_call(self):
795795
)
796796

797797
def build_gemm_version(self):
798-
return (13, blas_header_version())
798+
return (14, blas_header_version())
799799

800800

801801
class Gemm(GemmRelated):
@@ -1870,7 +1870,7 @@ def contiguous(var, ndim):
18701870

18711871
return """
18721872
int type_num = PyArray_DESCR({_x})->type_num;
1873-
int type_size = PyArray_DESCR({_x})->elsize; // in bytes
1873+
int type_size = PyArray_ITEMSIZE({_x}); // in bytes
18741874
18751875
if (PyArray_NDIM({_x}) != 3) {{
18761876
PyErr_Format(PyExc_NotImplementedError,
@@ -1930,7 +1930,7 @@ def contiguous(var, ndim):
19301930
def c_code_cache_version(self):
19311931
from pytensor.tensor.blas_headers import blas_header_version
19321932

1933-
return (5, blas_header_version())
1933+
return (6, blas_header_version())
19341934

19351935
def grad(self, inp, grads):
19361936
x, y = inp

pytensor/tensor/blas_headers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ def openblas_threads_text():
10611061

10621062
def blas_header_version():
10631063
# Version for the base header
1064-
version = (9,)
1064+
version = (10,)
10651065
if detect_macos_sdot_bug():
10661066
if detect_macos_sdot_bug.fix_works:
10671067
# Version with fix
@@ -1079,7 +1079,7 @@ def ____gemm_code(check_ab, a_init, b_init):
10791079
const char * error_string = NULL;
10801080
10811081
int type_num = PyArray_DESCR(_x)->type_num;
1082-
int type_size = PyArray_DESCR(_x)->elsize; // in bytes
1082+
int type_size = PyArray_ITEMSIZE(_x); // in bytes
10831083
10841084
npy_intp* Nx = PyArray_DIMS(_x);
10851085
npy_intp* Ny = PyArray_DIMS(_y);

tests/compile/test_debugmode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def dontuse_perform(self, node, inp, out_):
145145
raise ValueError(self.behaviour)
146146

147147
def c_code_cache_version(self):
148-
return (1,)
148+
return (2,)
149149

150150
def c_code(self, node, name, inp, out, sub):
151151
(a,) = inp
@@ -164,8 +164,8 @@ def c_code(self, node, name, inp, out, sub):
164164
prep_vars = """
165165
//the output array has size M x N
166166
npy_intp M = PyArray_DIMS(%(a)s)[0];
167-
npy_intp Sa = PyArray_STRIDES(%(a)s)[0] / PyArray_DESCR(%(a)s)->elsize;
168-
npy_intp Sz = PyArray_STRIDES(%(z)s)[0] / PyArray_DESCR(%(z)s)->elsize;
167+
npy_intp Sa = PyArray_STRIDES(%(a)s)[0] / PyArray_ITEMSIZE(%(a)s);
168+
npy_intp Sz = PyArray_STRIDES(%(z)s)[0] / PyArray_ITEMSIZE(%(z)s);
169169
170170
npy_double * Da = (npy_double*)PyArray_BYTES(%(a)s);
171171
npy_double * Dz = (npy_double*)PyArray_BYTES(%(z)s);

0 commit comments

Comments
 (0)