Commit b4e5e1df authored by rusty1s's avatar rusty1s
Browse files

removed tests on cffi

parent 2816aa60
#include <TH/TH.h> #include <TH/TH.h>
#define scatter_(NAME) TH_CONCAT_4(scatter_, NAME, _, Real) #define scatter_(NAME) TH_CONCAT_4(scatter_, NAME, _, Real)
#define check_(NAME) TH_CONCAT_4(check_, NAME, _, Real)
inline void check_inBoundaries(int idx, int size, long *free) { inline void assertInBoundaries(int idx, int size, long *free) {
if (idx < 0 || idx >= size) { THFree(free); THError("Invalid index"); } if (idx < 0 || idx >= size) { THFree(free); THError("Invalid index"); }
} }
......
...@@ -2,29 +2,12 @@ ...@@ -2,29 +2,12 @@
#define TH_GENERIC_FILE "generic/cpu.c" #define TH_GENERIC_FILE "generic/cpu.c"
#else #else
inline void check_(asserts)(THTensor *output, THLongTensor *index, THTensor *input, int dim) {
// Assert same dimensionality.
THArgCheck(dim >= 0 && dim < THTensor_(nDimension)(output), 4, "Index dimension is out of bounds");
THArgCheck(THLongTensor_nDimension(index) == THTensor_(nDimension)(input), 2, "Index tensor must have same dimensions as input tensor");
THArgCheck(THTensor_(nDimension)(input) == THTensor_(nDimension)(output), 3, "Input tensor must have same dimensions as output tensor");
// Assert same tensor sizes across index and input.
THLongStorage *indexDims = THLongTensor_newSizeOf(index);
THArgCheck(THTensor_(isSize)(input, indexDims), 2, "Index tensor must have the same size as input tensor.");
THLongStorage_free(indexDims);
// Assert same tensor sizes across input and output apart from specified dimension.
for (int d = 0; d < THTensor_(nDimension)(output); d++) {
if (d != dim) THArgCheck(THTensor_(size)(output, d) == THTensor_(size)(input, d), 3, "Input tensor must have same size as output tensor apart from the specified dimension");
}
}
void scatter_(add)(THTensor *output, THLongTensor *index, THTensor *input, int dim) { void scatter_(add)(THTensor *output, THLongTensor *index, THTensor *input, int dim) {
check_(asserts)(output, index, input, dim); long idx; long idx;
TH_TENSOR_DIM_APPLY3(real, output, real, input, long, index, dim, TH_TENSOR_DIM_APPLY3(real, output, real, input, long, index, dim,
for (int i = 0; i < THLongTensor_size(index, dim); i++) { for (int i = 0; i < THLongTensor_size(index, dim); i++) {
idx = *(index_data + i * index_stride); idx = *(index_data + i * index_stride);
check_inBoundaries(idx, output_size, TH_TENSOR_DIM_APPLY_counter); assertInBoundaries(idx, output_size, TH_TENSOR_DIM_APPLY_counter);
output_data[idx] += *(input_data + i * input_stride); output_data[idx] += *(input_data + i * input_stride);
}) })
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment