Check contiguous
@@ -1985,8 +1985,14 @@ cpdef ndarray _repeat(ndarray a, repeats, axis=None):
cpdef ndarray concatenate(tup, axis, shape, dtype):
cdef ndarray ret
- ret = ndarray(shape, dtype=dtype)
cdef int base
+ ret = ndarray(shape, dtype=dtype)
+
+ all_contiguous = True
+ for a in tup:
+ all_contiguous &= a._c_contiguous
+
+ if all_contiguous and axis == 0:
base = numpy.prod(shape[axis+1:], dtype='i')
x = array([a.data.ptr for a in tup])
axis_sizes = array([a.shape[axis] for a in tup], 'i')
@@ -2026,8 +2032,17 @@ cpdef ndarray concatenate(tup, axis, shape, dtype):
)
kernel(
x, axis, axis_sizes, x_strides, array(shape, 'i'), base, ret)
+ else:
+ 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
+
# -----------------------------------------------------------------------------
# Binary operations
# -----------------------------------------------------------------------------
