2424
2525#include "array_assign.h"
2626
27+ /* Check both uint and true alignment */
28+ NPY_NO_EXPORT int
29+ copycast_isaligned (int ndim , npy_intp * shape ,
30+ PyArray_Descr * dtype , char * data , npy_intp * strides )
31+ {
32+ int aligned ;
33+ int big_aln , small_aln ;
34+
35+ int uint_aln = npy_uint_alignment (dtype -> elsize );
36+ int true_aln = dtype -> alignment ;
37+
38+ /* uint alignment can be 0, meaning not uint alignable */
39+ if (uint_aln == 0 ) {
40+ return 0 ;
41+ }
42+
43+ if (true_aln >= uint_aln ) {
44+ big_aln = true_aln ;
45+ small_aln = uint_aln ;
46+ }
47+ else {
48+ big_aln = uint_aln ;
49+ small_aln = true_aln ;
50+ }
51+
52+ aligned = raw_array_is_aligned (ndim , shape , data , strides , big_aln );
53+ if (aligned && big_aln % small_aln != 0 ) {
54+ aligned = raw_array_is_aligned (ndim , shape , data , strides , small_aln );
55+ }
56+ return aligned ;
57+ }
58+
2759/*
2860 * Assigns the array from 'src' to 'dst'. The strides must already have
2961 * been broadcast.
@@ -48,15 +80,9 @@ raw_array_assign_array(int ndim, npy_intp *shape,
4880
4981 NPY_BEGIN_THREADS_DEF ;
5082
51- /* Check both uint and true alignment */
52- aligned = raw_array_is_aligned (ndim , shape , dst_data , dst_strides ,
53- npy_uint_alignment (dst_dtype -> elsize )) &&
54- raw_array_is_aligned (ndim , shape , dst_data , dst_strides ,
55- dst_dtype -> alignment ) &&
56- raw_array_is_aligned (ndim , shape , src_data , src_strides ,
57- npy_uint_alignment (src_dtype -> elsize ));
58<
8000
code> - raw_array_is_aligned (ndim , shape , src_data , src_strides ,
59- src_dtype -> alignment );
83+ aligned =
84+ copycast_isaligned (ndim , shape , dst_dtype , dst_data , dst_strides ) &&
85+ copycast_isaligned (ndim , shape , src_dtype , src_data , src_strides );
6086
6187 /* Use raw iteration with no heap allocation */
6288 if (PyArray_PrepareTwoRawArrayIter (
@@ -137,15 +163,9 @@ raw_array_wheremasked_assign_array(int ndim, npy_intp *shape,
137163
138164 NPY_BEGIN_THREADS_DEF ;
139165
140- /* Check both uint and true alignment */
141- aligned = raw_array_is_aligned (ndim , shape , dst_data , dst_strides ,
142- npy_uint_alignment (dst_dtype -> elsize )) &&
143- raw_array_is_aligned (ndim , shape , dst_data , dst_strides ,
144- dst_dtype -> alignment ) &&
145- raw_array_is_aligned (ndim , shape , src_data , src_strides ,
146- npy_uint_alignment (src_dtype -> elsize ));
147- raw_array_is_aligned (ndim , shape , src_data , src_strides ,
148- src_dtype -> alignment );
166+ aligned =
167+ copycast_isaligned (ndim , shape , dst_dtype , dst_data , dst_strides ) &&
168+ copycast_isaligned (ndim , shape , src_dtype , src_data , src_strides );
149169
150170 /* Use raw iteration with no heap allocation */
151171 if (PyArray_PrepareThreeRawArrayIter (
0 commit comments