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:
authorTrevor Killeen <killeentm@gmail.com>2017-08-08 17:36:44 +0300
committerSoumith Chintala <soumith@gmail.com>2017-08-15 09:58:14 +0300
commit0ed5623489039ed42d3920e60070e78125743a0a (patch)
treef66298d9668900f5faa2030389f567f2265981fb
parent56877b64af0bc805371eb06a0bb4505b351d16bb (diff)
move clamped random functions out of cwrap and into TH
-rw-r--r--lib/TH/generic/THTensorRandom.c10
-rw-r--r--lib/TH/generic/THTensorRandom.h2
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/TH/generic/THTensorRandom.c b/lib/TH/generic/THTensorRandom.c
index fe1401c..5bfabbc 100644
--- a/lib/TH/generic/THTensorRandom.c
+++ b/lib/TH/generic/THTensorRandom.c
@@ -23,6 +23,16 @@ void THTensor_(random)(THTensor *self, THGenerator *_generator)
#endif
}
+void THTensor_(clampedRandom)(THTensor *self, THGenerator *_generator, long min, long max) {
+ THArgCheck(max > min, 2, "max must be greater than min");
+ TH_TENSOR_APPLY(real, self, *self_data = (real)((THRandom_random(_generator) % (max - min)) + min);)
+}
+
+void THTensor_(cappedRandom)(THTensor *self, THGenerator *_generator, long max) {
+ THArgCheck(max > 0, 1, "max must be positive");
+ THTensor_(clampedRandom)(self, _generator, 0, max);
+}
+
void THTensor_(geometric)(THTensor *self, THGenerator *_generator, double p)
{
TH_TENSOR_APPLY(real, self, *self_data = (real)THRandom_geometric(_generator, p););
diff --git a/lib/TH/generic/THTensorRandom.h b/lib/TH/generic/THTensorRandom.h
index f79a86e..145c7d7 100644
--- a/lib/TH/generic/THTensorRandom.h
+++ b/lib/TH/generic/THTensorRandom.h
@@ -3,6 +3,8 @@
#else
TH_API void THTensor_(random)(THTensor *self, THGenerator *_generator);
+TH_API void THTensor_(clampedRandom)(THTensor *self, THGenerator *_generator, long min, long max);
+TH_API void THTensor_(cappedRandom)(THTensor *self, THGenerator *_generator, long max);
TH_API void THTensor_(geometric)(THTensor *self, THGenerator *_generator, double p);
TH_API void THTensor_(bernoulli)(THTensor *self, THGenerator *_generator, double p);
TH_API void THTensor_(bernoulli_FloatTensor)(THTensor *self, THGenerator *_generator, THFloatTensor *p);