1 /* Copyright 2020 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 #ifndef TENSORFLOW_CORE_KERNELS_STATELESS_RANDOM_OPS_V2_H_
17 #define TENSORFLOW_CORE_KERNELS_STATELESS_RANDOM_OPS_V2_H_
18
19 #include "tensorflow/core/framework/rng_alg.h"
20 #include "tensorflow/core/framework/tensor_shape.h"
21
22 namespace tensorflow {
23
CheckKeyCounterShape(Algorithm const & alg,TensorShape const & key_shape,TensorShape const & counter_shape)24 inline Status CheckKeyCounterShape(Algorithm const& alg,
25 TensorShape const& key_shape,
26 TensorShape const& counter_shape) {
27 if (!(key_shape.dims() == 1 && key_shape.dim_size(0) == RNG_KEY_SIZE)) {
28 return errors::InvalidArgument(
29 "key must have shape [", RNG_KEY_SIZE, "], not ",
30 key_shape.DebugString(),
31 ". (Note that batched keys are not supported yet.)");
32 }
33 auto counter_size = GetCounterSize(alg);
34 if (!(counter_shape.dims() == 1 &&
35 counter_shape.dim_size(0) >= counter_size)) {
36 return errors::InvalidArgument(
37 "counter must be a vector with length at least ", counter_size,
38 "; got shape: ", counter_shape.DebugString(),
39 ". (Note that batched counters are not supported yet.)");
40 }
41 return OkStatus();
42 }
43
44 } // end namespace tensorflow
45
46 #endif // TENSORFLOW_CORE_KERNELS_STATELESS_RANDOM_OPS_V2_H_
47