Fix bug in cat (non-contiguous first input)
diff --git a/generic/THTensorMath.c b/generic/THTensorMath.c
index 78ee056..82d4a0a 100644
--- a/generic/THTensorMath.c
+++ b/generic/THTensorMath.c
@@ -2043,7 +2043,7 @@
long offset;
int maxDim = dimension + 1;
int allEmpty = 1;
- int allContiguous = 1;
+ int allContiguous;
int ldimension = dimension;
for (i = 0; i < numInputs; i++)
@@ -2074,10 +2074,6 @@
// accumulate the size over the dimension we want to cat on.
// Empty tensors are allowed
dimSize += i < inputs[j]->nDimension ? inputs[j]->size[i] : THMin(inputs[j]->nDimension, 1);
- if(inputs[j]->nDimension)
- {
- allContiguous = allContiguous && THTensor_(isContiguous)(inputs[j]);
- }
}
}
else
@@ -2108,6 +2104,12 @@
{
THTensor_(resize)(result, size, NULL);
+ // Check contiguity of all inputs and result
+ for (i = 0; i < numInputs; i++) {
+ if(inputs[i]->nDimension) {
+ allContiguous = allContiguous && THTensor_(isContiguous)(inputs[i]);
+ }
+ }
allContiguous = allContiguous && THTensor_(isContiguous)(result);
// First path is for contiguous inputs along dim 1