8000 Fix torch.histc problem #718 by andreaskoepf · Pull Request #723 · torch/torch7 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix torch.histc problem #718 #723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2016
Merged
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
24 changes: 6 additions & 18 deletions lib/TH/generic/THTensorMath.c
Original file line number Diff line number Diff line change
Expand Up @@ -2409,10 +2409,8 @@ void THTensor_(randn)(THTensor *r_, THGenerator *_generator, THLongStorage *size

void THTensor_(histc)(THTensor *hist, THTensor *tensor, long nbins, real minvalue, real maxvalue)
{
THTensor *clone;
real minval;
real maxval;
real bins;
real *h_data;

THTensor_(resize1d)(hist, nbins);
Expand All @@ -2429,25 +2427,15 @@ void THTensor_(histc)(THTensor *hist, THTensor *tensor, long nbins, real minvalu
minval = minval - 1;
maxval = maxval + 1;
}
bins = (real)(nbins)-1e-6;


clone = THTensor_(newWithSize1d)(THTensor_(nElement)(tensor));
THTensor_(copy)(clone,tensor);
THTensor_(add)(clone, clone, -minval);
THTensor_(div)(clone, clone, (maxval-minval));
THTensor_(mul)(clone, clone, bins);
THTensor_(floor)(clone, clone);
THTensor_(add)(clone, clone, 1);

h_data = THTensor_(data)(hist);

TH_TENSOR_APPLY(real, clone, \
if ((*clone_data <= nbins) && (*clone_data >= 1)) { \
*(h_data + (int)(*clone_data) - 1) += 1; \
});

THTensor_(free)(clone);
TH_TENSOR_APPLY(real, tensor,
if (*tensor_data >= minval && *tensor_data <= maxval) {
const int bin = (int)((*tensor_data-minval) / (maxval-minval) * nbins);
h_data[THMin(bin, nbins-1)] += 1;
}
);
}

#endif /* floating point only part */
Expand Down
0