diff options
author | Manjunath Kudlur <keveman@gmail.com> | 2015-12-02 09:12:45 -0800 |
---|---|---|
committer | Manjunath Kudlur <keveman@gmail.com> | 2015-12-02 09:19:48 -0800 |
commit | fa095c5db0ac9cfe2328a19b32ae208e58e3746a (patch) | |
tree | 0ea34b3110247357202386d91aac9a0083b0b9cf /tensorflow/core/lib/random | |
parent | f586a5ee94465f8f482964c6bbcc1206f160af35 (diff) |
TensorFlow: upstream changes to git
Change 109195845
Fix TensorFlow for build against Bazel 0.1.2rc2
Two things are currently broken with TensorFlow and Bazel 0.1.2:
- Bazel now use sandboxing by default on Linux and have fixed it for cc_* rules.
Undeclared headers are not mounted in the sandbox which make several cc_* rules
fails.
- Bazel now enforce strict header checking and some target were missing
headers even though the headers were mounted in the sandbox. This change
adds a "strict_headers" target that globs every headers of the core
library and add it to the `tf_cc_tests` targets.
Change 109162708
Fix various website issues
- Fix headline in os_setup.md
- Fix #anchor links
Change 109162129
Fix numbers in mnist tutorial, fixes #362
Change 109158967
Fix typo in word2vec tutorial, fixes #347
Change 109151855
Fix tile and its gradient for scalars on GPUs
Eigen doesn't handle scalars on GPUs in all cases. Fortunately, both
tile and its gradient are the identity for scalars, so we can just copy
the input to the output.
Fixes https://github.com/tensorflow/tensorflow/issues/391.
Change 109140763
Support int32 and int64 in tf.random_uniform
This requires a new RandomUniformInt op on the C++ side since the op needs
to know minval and maxval.
Fixes https://github.com/tensorflow/tensorflow/issues/364.
Change 109140738
Fix spacing in docs.
Change 109140030
Fix content nav to not hide the bottom 100 or so px.
Change 109139967
Add license files to TensorBoard files, fix mnist_with_summaries test
Change 109138333
Fix typos in docstring
Change 109138098
Fix some missing resources in the website.
Fixes #366.
Change 109123771
Make sparse_to_dense's default_value default to 0
Nearly all uses of sparse_to_dense use 0 as the default. The
same goes for sparse_tensor_to_dense.
Base CL: 109198336
Diffstat (limited to 'tensorflow/core/lib/random')
-rw-r--r-- | tensorflow/core/lib/random/random_distributions.h | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tensorflow/core/lib/random/random_distributions.h b/tensorflow/core/lib/random/random_distributions.h index ba3f6f95e4..745b1cf9f4 100644 --- a/tensorflow/core/lib/random/random_distributions.h +++ b/tensorflow/core/lib/random/random_distributions.h @@ -88,6 +88,71 @@ class UniformDistribution<Generator, double> { } }; +template <class Generator> +class UniformDistribution<Generator, int32> { + public: + // The number of elements that will be returned. + static const int kResultElementCount = Generator::kResultElementCount; + // Indicate that this distribution may take variable number of samples + // during the runtime. + static const bool kVariableSamplesPerOutput = false; + typedef Array<int32, kResultElementCount> ResultType; + typedef int32 ResultElementType; + + // Must have lo < hi + UniformDistribution(int32 lo, int32 hi) : lo_(lo), range_(hi - lo) {} + + PHILOX_DEVICE_INLINE + ResultType operator()(Generator* gen) { + typename Generator::ResultType sample = (*gen)(); + ResultType result; + for (int i = 0; i < kResultElementCount; ++i) { + result[i] = lo_ + static_cast<int32>(sample[i] % range_); + } + return result; + } + + private: + // Note that lo_ is intentionally signed while range_ is intentionally + // unsigned. This is because hi - lo can overflow signed integers if + // lo < 0 < hi, but always fits in unsigned. + int32 lo_; + uint32 range_; +}; + +template <class Generator> +class UniformDistribution<Generator, int64> { + public: + // The number of elements that will be returned. + static const int kResultElementCount = Generator::kResultElementCount / 2; + // Indicate that this distribution may take variable number of samples + // during the runtime. + static const bool kVariableSamplesPerOutput = false; + typedef Array<int64, kResultElementCount> ResultType; + typedef int64 ResultElementType; + + // Must have lo < hi + UniformDistribution(int64 lo, int64 hi) : lo_(lo), range_(hi - lo) {} + + PHILOX_DEVICE_INLINE + ResultType operator()(Generator* gen) { + typename Generator::ResultType sample = (*gen)(); + ResultType result; + for (int i = 0; i < kResultElementCount; ++i) { + auto bits = sample[2 * i] | static_cast<uint64>(sample[2 * i + 1]) << 32; + result[i] = lo_ + static_cast<int64>(bits % range_); + } + return result; + } + + private: + // Note that lo_ is intentionally signed while range_ is intentionally + // unsigned. This is because hi - lo can overflow signed integers if + // lo < 0 < hi, but always fits in unsigned. + int64 lo_; + uint64 range_; +}; + // A class that adapts the underlying native multiple samples to return a single // sample at a time. template <class Generator> |