1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "guarded_philox_random.h"
17 #include "random.h"
18 
19 namespace tensorflow {
20 
Init(int64 seed,int64 seed2)21 void GuardedPhiloxRandom::Init(int64 seed, int64 seed2) {
22     //  CHECK(!initialized_);
23     if (seed == 0 && seed2 == 0) {
24         // If both seeds are unspecified, use completely random seeds.
25         seed = random::New64();
26         seed2 = random::New64();
27     }
28     //  mutex_lock lock(mu_);
29     generator_ = random::PhiloxRandom(seed, seed2);
30     initialized_ = true;
31 }
32 
Init(random::PhiloxRandom::ResultType counter,random::PhiloxRandom::Key key)33 void GuardedPhiloxRandom::Init(random::PhiloxRandom::ResultType counter,
34                                random::PhiloxRandom::Key key) {
35     //  CHECK(!initialized_);
36     //  mutex_lock lock(mu_);
37     generator_ = random::PhiloxRandom(counter, key);
38     initialized_ = true;
39 }
40 
ReserveSamples128(int64 samples)41 random::PhiloxRandom GuardedPhiloxRandom::ReserveSamples128(int64 samples) {
42     //  CHECK(initialized_);
43     //  mutex_lock lock(mu_);
44     auto local = generator_;
45     generator_.Skip(samples);
46     return local;
47 }
48 
49 }  // namespace tensorflow
50