use continuous copies for concatenate if arrays are not contiguous on axis
@@ -2406,17 +2406,27 @@ cpdef ndarray concatenate(tup, axis, shape, dtype):
ret = ndarray(shape, dtype=dtype)
- if len(tup) > 3:
all_same_type = True
all_one_and_contiguous = True
+ any_contiguous_on_axis = False
dtype = tup[0].dtype
for a in tup:
all_same_type = all_same_type and (a.dtype == dtype)
all_one_and_contiguous = (
all_one_and_contiguous and a._c_contiguous and
a._shape[axis] == 1)
+ any_contiguous_on_axis = (
+ any_contiguous_on_axis or
+ a._strides[axis] == a.itemsize)
- if all_same_type:
+ if not all_same_type or not any_contiguous_on_axis:
+ skip = (slice(None),) * axis
+ i = 0
+ for a in tup:
+ aw = a._shape[axis]
+ ret[skip + (slice(i, i + aw),)] = a
+ i += aw
+ else:
ptrs = numpy.ndarray(len(tup), numpy.int64)
for i, a in enumerate(tup):
ptrs[i] = a.data.ptr
@@ -2440,15 +2450,6 @@ cpdef ndarray concatenate(tup, axis, shape, dtype):
x, axis, array(cum_sizes), array(x_strides), ret)
return ret
- skip = (slice(None),) * axis
- i = 0
- for a in tup:
- aw = a._shape[axis]
- ret[skip + (slice(i, i + aw),)] = a
- i += aw
-
- return ret
-
cdef _concatenate_kernel_one = ElementwiseKernel(
'raw P x, int32 base',
'T y',
