Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions aten/src/ATen/native/Indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ static std::vector<Tensor> expandByteTensors(const Tensor & self, TensorList ind
}
// Replace with nonzeros
auto nonzero = index.nonzero();
#ifndef USE_TH_SIZE_ZERO_DIM
auto special_empty = nonzero.numel() == 0;
#else
auto special_empty = false;
#endif
for (int64_t j = 0; j < index.dim(); j++) {
if (special_empty) {
// We can't call select on an empty tensor so we just create an empty
Expand Down Expand Up @@ -214,26 +210,10 @@ static Tensor computeLinearIndex(const Tensor & src, TensorList indices) {
return linearIndex;
}

#ifndef USE_TH_SIZE_ZERO_DIM
static bool hasEmptyTensor(TensorList tensors) {
for (auto& tensor : tensors) {
if (tensor.defined() && tensor.numel() == 0) {
return true;
}
}
return false;
}
#endif

static std::tuple<Tensor, Tensor> makeLinearIndex(Tensor self, TensorList orig) {
checkIndexTensorTypes(orig);
// first expand ByteTensor (boolean masks) into 1 or more LongTensors
auto indices = expandByteTensors(self, orig);
#ifndef USE_TH_SIZE_ZERO_DIM
if (hasEmptyTensor(indices)) {
return std::make_tuple(self, self.type().toScalarType(kLong).tensor());
}
#endif
// next broadcast all index tensors together
indices = expand_outplace(indices);
// add missing null Tensors so that it matches self.dim()
Expand Down
8 changes: 0 additions & 8 deletions aten/src/ATen/native/TensorFactories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,9 @@ Tensor& eye_out_cpu(Tensor& result, int64_t n) {
}

Tensor& eye_out_cpu(Tensor& result, int64_t n, int64_t m) {
#ifndef USE_TH_SIZE_ZERO_DIM
AT_CHECK(n > 0, "n must be greater than 0, got ", n);
#else
AT_CHECK(n >= 0, "n must be greater or equal to 0, got ", n);
#endif

#ifndef USE_TH_SIZE_ZERO_DIM
if(m <= 0) {
#else
if(m < 0) {
#endif
m = n;
}

Expand Down
26 changes: 0 additions & 26 deletions aten/src/ATen/native/TensorShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ Tensor diagonal(const Tensor& self, int64_t offset, int64_t dim1_, int64_t dim2_
} else {
diag_size = std::max<int64_t>(std::min(self.size(dim1)+offset, self.size(dim2)), 0);
}
#ifndef USE_TH_SIZE_ZERO_DIM
AT_CHECK(diag_size > 0, "invalid diagonal offset ", offset); // the diagonal offset was too large in magnitude
#endif

// NumPy allows you to specify offsets "off the end"; let's just be careful not to
// set a ridiculous storage_offset in that case (technically it shouldn't matter
Expand Down Expand Up @@ -157,11 +154,7 @@ Tensor narrow(const Tensor& self, int64_t dim, int64_t start, int64_t length) {
if (start != cur_size) { // start being the end is valid, but not a valid dim specification.
start = maybe_wrap_dim(start, cur_size);
}
#ifndef USE_TH_SIZE_ZERO_DIM
if (length <= 0 || start > cur_size - length) {
#else
if (length < 0 || start > cur_size - length) {
#endif
AT_ERROR("start (", start, ") + length (", length, ") exceeds dimension size (", cur_size, ").");
}
return at::slice(self, dim, start, start + length, 1);
Expand Down Expand Up @@ -246,14 +239,6 @@ static std::vector<int64_t> infer_size(IntList shape, int64_t numel) {
AT_CHECK(newsize != 0, "cannot reshape tensor of 0 elements into shape ", shape);
res[*infer_dim] = numel / newsize;
}
#ifndef USE_TH_SIZE_ZERO_DIM
if (numel == 0) {
// Collapse zero-element shapes into one dimension because TH handles zeros
// in sizes strangely: x.resize_(1, 0) has shape (1,). TODO: remove this
// once we have multi-dimensional empty tensors.
return {0};
}
#endif
return res;
}

Expand Down Expand Up @@ -327,12 +312,6 @@ Tensor slice(const Tensor& self, int64_t dim, int64_t start, int64_t end, int64_
}
auto storage_offset = self.storage_offset() + start * strides[dim];
auto len = end - start;
#ifndef USE_TH_SIZE_ZERO_DIM
if (len == 0) {
// TODO: currently we don't have support for 0-sized dims, return size 0 tensor for now
return self.type().tensor();
}
#endif
sizes[dim] = (len + step - 1) / step; // round-up
strides[dim] *= step;
return self.as_strided(sizes, strides, storage_offset);
Expand Down Expand Up @@ -539,11 +518,6 @@ inferSqueezeGeometry(const Tensor& tensor, int64_t dim) {

std::tuple<std::vector<int64_t>, std::vector<int64_t> >
inferUnsqueezeGeometry(const Tensor& tensor, int64_t dim) {
#ifndef USE_TH_SIZE_ZERO_DIM
if (tensor.numel() == 0) {
throw std::runtime_error("cannot unsqueeze empty tensor");
}
#endif
std::vector<int64_t> sizes(tensor.sizes());
std::vector<int64_t> strides(tensor.strides());
int64_t new_stride = dim >= tensor.dim() ? 1 : sizes[dim] * strides[dim];
Expand Down
8 changes: 0 additions & 8 deletions aten/src/ATen/native/cuda/TensorFactories.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,9 @@ Tensor& eye_out_cuda(Tensor& result, int64_t n) {
}

Tensor& eye_out_cuda(Tensor& result, int64_t n, int64_t m) {
#ifndef USE_TH_SIZE_ZERO_DIM
AT_CHECK(n > 0, "n must be greater than 0, got ", n);
#else
AT_CHECK(n >= 0, "n must be greater or equal to 0, got ", n);
#endif

#ifndef USE_TH_SIZE_ZERO_DIM
if(m <= 0) {
#else
if(m < 0) {
#endif
m = n;
}

Expand Down
17 changes: 0 additions & 17 deletions aten/src/ATen/test/scalar_tensor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,13 @@ void test(Type &T) {
require_equal_size_dim(t2, ones({0}, T));

// unsqueeze
#ifndef USE_TH_SIZE_ZERO_DIM
if (t.numel() != 0) {
REQUIRE(t.unsqueeze(0).dim() == t.dim() + 1);
} else {
REQUIRE_THROWS(t.unsqueeze(0));
}
#else
REQUIRE(t.unsqueeze(0).dim() == t.dim() + 1);
#endif

// unsqueeze_
{
auto t2 = ones(*s, T);
#ifndef USE_TH_SIZE_ZERO_DIM
if (t2.numel() != 0) {
auto r = t2.unsqueeze_(0);
REQUIRE(r.dim() == t.dim() + 1);
} else {
REQUIRE_THROWS(t2.unsqueeze_(0));
}
#else
auto r = t2.unsqueeze_(0);
REQUIRE(r.dim() == t.dim() + 1);
#endif
}

// squeeze (with dimension argument)
Expand Down
23 changes: 0 additions & 23 deletions aten/src/TH/generic/THTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,7 @@ void THTensor_(narrow)(THTensor *self, THTensor *src, int dimension, int64_t fir

THArgCheck( (dimension >= 0) && (dimension < src->dim()), 2, "out of range");
THArgCheck( firstIndex >= 0, 3, "out of range");
#ifdef USE_TH_SIZE_ZERO_DIM
THArgCheck( size >= 0, 4, "out of range");
#else
THArgCheck( size > 0, 4, "out of range");
#endif
THArgCheck(firstIndex <= src->size(dimension) - size, 4, "out of range");

THTensor_(set)(self, src);
Expand All @@ -396,12 +392,8 @@ void THTensor_(select)(THTensor *self, THTensor *src, int dimension, int64_t sli
if(!src)
src = self;

#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(THTensor_nDimensionLegacyAll(src) > 1, 1, "cannot select on a vector");
#else
#ifndef USE_TH_SCALAR
THArgCheck(src->dim() > 1, 1, "cannot select on a vector");
#endif
#endif
THArgCheck((dimension >= 0) && (dimension < src->dim()), 2, "out of range");
THArgCheck((sliceIndex >= 0) && (sliceIndex < src->size(dimension)), 3, "out of range");
Expand Down Expand Up @@ -446,9 +438,6 @@ void THTensor_(unfold)(THTensor *self, THTensor *src, int dimension, int64_t siz
if(!src)
src = self;

#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(!src->is_empty(), 1, "cannot unfold an empty tensor");
#endif
THArgCheck((dimension >= 0) && (dimension < src->dim()), 2, "out of range");
THArgCheck(size <= src->size(dimension), 3, "out of range");
THArgCheck(step > 0, 4, "invalid step");
Expand Down Expand Up @@ -547,9 +536,6 @@ void THTensor_(unsqueeze1d)(THTensor *self, THTensor *src, int dimension)
src = self;

THArgCheck((dimension >= 0) && (dimension <= src->dim()), 2, "dimension out of range");
#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(!src->is_empty(), 2, "cannot unsqueeze empty tensor");
#endif

THTensor_(set)(self, src);

Expand Down Expand Up @@ -728,15 +714,6 @@ void THTensor_(resizeNd)(THTensor *self, int nDimension, int64_t *size, int64_t

for(d = 0; d < nDimension; d++)
{
#ifndef USE_TH_SIZE_ZERO_DIM
// we can't support this unless we have arbitrary 0-sized dimensions, but some calls to this
// currently exist and expect a size [0] tensor to be returned.
if (d == 0 && size[d] == 0) {
nDimension = 1;
} else {
AT_CHECK(size[d] > 0, "sizes must be non-negative");
}
#endif
if((self->dim() > d) && (size[d] != self->size(d))) {
hascorrectsize = false;
}
Expand Down
25 changes: 0 additions & 25 deletions aten/src/TH/generic/THTensorEvenMoreMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,8 @@ void THTensor_(indexSelect)(THTensor *tensor, THTensor *src, int dim, THLongTens
int64_t *index_data;
real *tensor_data, *src_data;

#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(THTensor_nDimensionLegacyAll(index) <= 1, 3, "Index is supposed to be an empty tensor or a vector");
THArgCheck(dim < THTensor_nDimensionLegacyAll(src), 4, "Indexing dim %d is out of bounds of tensor", dim + TH_INDEX_BASE);
THArgCheck(THTensor_nDimensionLegacyAll(src) > 0, 2, "Source tensor is empty");
#else
THArgCheck(index->dim() == 1, 3, "Index is supposed to be 1-dimensional");
THArgCheck(dim < src->dim(), 4, "Indexing dim %d is out of bounds of tensor", dim + TH_INDEX_BASE);
//THArgCheck(src->dim() > 0, 2, "Source tensor is empty");
#endif

numel = THLongTensor_nElement(index);

Expand Down Expand Up @@ -354,13 +347,8 @@ void THTensor_(indexAdd)(THTensor *tensor, int dim, THLongTensor *index, THTenso
int64_t *index_data;

numel = THLongTensor_nElement(index);
#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(THTensor_nDimensionLegacyAll(index) == 1, 3, "Index is supposed to be a vector");
THArgCheck(dim < THTensor_nDimensionLegacyAll(src), 4,"Indexing dim %d is out of bounds of tensor", dim + TH_INDEX_BASE);
#else
THArgCheck(index->dim() == 1, 3, "Index is supposed to be a vector");
THArgCheck(dim < src->dim(), 4,"Indexing dim %d is out of bounds of tensor", dim + TH_INDEX_BASE);
#endif
THArgCheck(numel == src->size(dim),4,"Number of indices should be equal to source:size(dim)");

index = THLongTensor_newContiguous(index);
Expand Down Expand Up @@ -400,13 +388,8 @@ void THTensor_(indexFill)(THTensor *tensor, int dim, THLongTensor *index, real v
int64_t *index_data;

numel = THLongTensor_nElement(index);
#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(THTensor_nDimensionLegacyAll(index) == 1, 3, "Index is supposed to be a vector");
THArgCheck(dim < THTensor_nDimensionLegacyAll(tensor), 4,"Indexing dim %d is out of bounds of tensor", dim + TH_INDEX_BASE);
#else
THArgCheck(index->dim() == 1, 3, "Index is supposed to be a vector");
THArgCheck(dim < tensor->dim(), 4,"Indexing dim %d is out of bounds of tensor", dim + TH_INDEX_BASE);
#endif

index = THLongTensor_newContiguous(index);
index_data = THLongTensor_data(index);
Expand Down Expand Up @@ -459,19 +442,11 @@ void THTensor_(scatter)(THTensor *tensor, int dim, THLongTensor *index, THTensor
{
int64_t elems_per_row, i, idx;

#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(dim < THTensor_(nDimensionLegacyAll)(tensor), 2, "Index dimension is out of bounds");
THArgCheck(THLongTensor_nDimensionLegacyAll(index) == THTensor_(nDimensionLegacyAll)(tensor), 3,
"Index tensor must have same dimensions as output tensor");
THArgCheck(THTensor_(nDimensionLegacyAll)(src) == THTensor_(nDimensionLegacyAll)(tensor), 4,
"Input tensor must have same dimensions as output tensor");
#else
THArgCheck(dim < THTensor_(nDimensionLegacyNoScalars)(tensor), 2, "Index dimension is out of bounds");
THArgCheck(THLongTensor_nDimensionLegacyNoScalars(index) == THTensor_(nDimensionLegacyNoScalars)(tensor), 3,
"Index tensor must have same dimensions as output tensor");
THArgCheck(THTensor_(nDimensionLegacyNoScalars)(src) == THTensor_(nDimensionLegacyNoScalars)(tensor), 4,
"Input tensor must have same dimensions as output tensor");
#endif

elems_per_row = THLongTensor_size(index, dim);

Expand Down
11 changes: 0 additions & 11 deletions aten/src/TH/generic/THTensorMoreMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,6 @@ void THTensor_(onesLike)(THTensor *r_, THTensor *input)

void THTensor_(diag)(THTensor *r_, THTensor *t, int k)
{
#ifndef USE_TH_SIZE_ZERO_DIM
AT_ASSERT(!t->is_empty())
#endif
THArgCheck(THTensor_(nDimensionLegacyNoScalars)(t) == 1 || THTensor_(nDimensionLegacyNoScalars)(t) == 2, 1, "matrix or a vector expected");

if(THTensor_(nDimensionLegacyNoScalars)(t) == 1)
Expand Down Expand Up @@ -1186,19 +1183,11 @@ void THTensor_(median)(THTensor *values_, THLongTensor *indices_, THTensor *t, i

void THTensor_(topk)(THTensor *rt_, THLongTensor *ri_, THTensor *t, int64_t k, int dim, int dir, int sorted)
{
#ifndef USE_TH_SIZE_ZERO_DIM
int numDims = THTensor_(nDimensionLegacyAll)(t);
#else
int numDims = THTensor_(nDimensionLegacyNoScalars)(t);
#endif
THArgCheck(dim >= 0 && dim < numDims, 3, "dim not in range");

int64_t sliceSize = THTensor_(size)(t, dim);
#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(k > 0 && k <= sliceSize, 2, "k not in range for dimension");
#else
THArgCheck(k >= 0 && k <= sliceSize, 2, "k not in range for dimension");
#endif

THTensor *tmpResults = THTensor_(new)();
THTensor_(resize1d)(tmpResults, sliceSize);
Expand Down
12 changes: 0 additions & 12 deletions aten/src/THC/THCTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ void THCTensor_resizeNd(THCState *state, THCTensor *self, int nDimension, int64_

for(d = 0; d < nDimension; d++)
{
#ifndef USE_TH_SIZE_ZERO_DIM
// we can't support this unless we have arbitrary 0-sized dimensions, but some calls to this
// currently exist and expect a size [0] tensor to be returned.
if (d == 0 && size[d] == 0) {
nDimension = 1;
} else {
AT_CHECK(size[d] > 0, "sizes must be non-negative");
}
#endif
if((self->dim() > d) && (size[d] != self->size(d))) {
hascorrectsize = false;
}
Expand Down Expand Up @@ -234,9 +225,6 @@ void THCTensor_unsqueeze1d(THCState *state, THCTensor *self, THCTensor *src, int
src = self;

THArgCheck((dimension >= 0) && (dimension <= src->dim()), 3, "dimension out of range");
#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(!src->is_empty(), 3, "cannot unsqueeze empty tensor");
#endif

THCTensor_set(state, self, src);

Expand Down
11 changes: 0 additions & 11 deletions aten/src/THC/generic/THCTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,7 @@ void THCTensor_(narrow)(THCState *state, THCTensor *self, THCTensor *src, int di

THArgCheck( (dimension >= 0) && (dimension < src->dim()), 3, "out of range");
THArgCheck( firstIndex >= 0, 4, "out of range");
#ifdef USE_TH_SIZE_ZERO_DIM
THArgCheck( size >= 0, 5, "out of range");
#else
THArgCheck( size > 0, 5, "out of range");
#endif
THArgCheck(firstIndex+size <= src->size(dimension), 5, "out of range");

THCTensor_(set)(state, self, src);
Expand All @@ -390,12 +386,8 @@ void THCTensor_(select)(THCState *state, THCTensor *self, THCTensor *src, int di
if(!src)
src = self;

#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(THTensor_nDimensionLegacyAll(src) > 1, 1, "cannot select on a vector");
#else
#ifndef USE_TH_SCALAR
THArgCheck(src->dim() > 1, 1, "cannot select on a vector");
#endif
#endif
THArgCheck((dimension >= 0) && (dimension < src->dim()), 3, "out of range");
THArgCheck((sliceIndex >= 0) && (sliceIndex < src->size(dimension)), 4, "out of range");
Expand Down Expand Up @@ -440,9 +432,6 @@ void THCTensor_(unfold)(THCState *state, THCTensor *self, THCTensor *src, int di
if(!src)
src = self;

#ifndef USE_TH_SIZE_ZERO_DIM
THArgCheck(!src->is_empty(), 1, "cannot unfold an empty tensor");
#endif
THArgCheck(dimension < src->dim(), 2, "out of range");
THArgCheck(size <= src->size(dimension), 3, "out of range");
THArgCheck(step > 0, 4, "invalid step");
Expand Down
Loading