Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/torch7.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/TH/generic/THTensorMath.c')
-rw-r--r--lib/TH/generic/THTensorMath.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/TH/generic/THTensorMath.c b/lib/TH/generic/THTensorMath.c
index e04d3b6..765f9c4 100644
--- a/lib/TH/generic/THTensorMath.c
+++ b/lib/TH/generic/THTensorMath.c
@@ -2538,5 +2538,44 @@ void THTensor_(histc)(THTensor *hist, THTensor *tensor, long nbins, real minvalu
);
}
+void THTensor_(histc2)(THTensor *hist, THTensor *tensor, long nbins, real minvalue, real maxvalue)
+{
+ THArgCheck(THTensor_(nDimension)(tensor) < 3, 2, "invalid dimension %d, the input must be a 2d tensor", THTensor_(nDimension)(tensor));
+
+ int dimension = 1;
+ THArgCheck(dimension >= 0 && dimension < THTensor_(nDimension)(tensor), 2, "invalid dimension %d",
+ dimension + TH_INDEX_BASE);
+
+ real minval;
+ real maxval;
+ real *h_data;
+
+ THTensor_(resize2d)(hist, tensor->size[0], nbins);
+ THTensor_(zero)(hist);
+
+ minval = minvalue;
+ maxval = maxvalue;
+ if (minval == maxval)
+ {
+ minval = THTensor_(minall)(tensor);
+ maxval = THTensor_(maxall)(tensor);
+ }
+ if (minval == maxval)
+ {
+ minval = minval - 1;
+ maxval = maxval + 1;
+ }
+
+ TH_TENSOR_DIM_APPLY2(real, tensor, real, hist, dimension, long i;
+ for(i = 0; i < tensor_size; i++)
+ {
+ if(tensor_data[i*tensor_stride] >= minval && tensor_data[i*tensor_stride] <= maxval) {
+ const int bin = (int)((tensor_data[i*tensor_stride]-minval) / (maxval-minval) * nbins);
+ hist_data[THMin(bin, nbins-1)] += 1;
+ }
+ }
+ );
+}
+
#endif /* floating point only part */
#endif