|
| 1 | +/***************************************************************************** |
| 2 | + Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +******************************************************************************/ |
| 16 | + |
| 17 | +namespace Tensorflow.Operations.Initializers |
| 18 | +{ |
| 19 | + public class Constant<T> : IInitializer |
| 20 | + { |
| 21 | + TF_DataType dtype; |
| 22 | + T value; |
| 23 | + bool _verify_shape; |
| 24 | + |
| 25 | + public Constant(T value, TF_DataType dtype = TF_DataType.TF_FLOAT, bool verify_shape = false) |
| 26 | + { |
| 27 | + this.value = value; |
| 28 | + this.dtype = dtype; |
| 29 | + _verify_shape = verify_shape; |
| 30 | + } |
| 31 | + |
| 32 | + public Tensor call(TensorShape shape, TF_DataType dtype = TF_DataType.DtInvalid, bool? verify_shape = null) |
| 33 | + { |
| 34 | + if (dtype == TF_DataType.DtInvalid) |
| 35 | + dtype = this.dtype; |
| 36 | + |
| 37 | + if (!verify_shape.HasValue) |
| 38 | + verify_shape = _verify_shape; |
| 39 | + |
| 40 | + return constant_op._constant_impl(value, dtype, shape, |
| 41 | + name: "Const", |
| 42 | + verify_shape: verify_shape.Value, |
| 43 | + allow_broadcast: false); |
| 44 | + } |
| 45 | + |
| 46 | + public object get_config() |
| 47 | + { |
| 48 | + return new |
| 49 | + { |
| 50 | + value, |
| 51 | + dtype = dtype.name() |
| 52 | + }; |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments