1# Copyright 2019 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"""Tests for numpy_dataset.""" 16 17import numpy as np 18 19from tensorflow.python.distribute import numpy_dataset 20from tensorflow.python.eager import test 21from tensorflow.python.framework import test_util 22from tensorflow.python.ops import variable_scope 23 24 25class InitVarFromNumpyTest(test.TestCase): 26 27 @test_util.run_in_graph_and_eager_modes 28 def test_creating_var_with_numpy_arrays(self): 29 with self.cached_session() as session: 30 x = np.asarray(np.random.random((64, 3)), dtype=np.float32) 31 initial = np.zeros_like(x) 32 var_x = variable_scope.variable(initial) 33 numpy_dataset.init_var_from_numpy(var_x, x, session) 34 val = self.evaluate(var_x.value()) 35 # Verify that the numpy value is copied to the variable. 36 self.assertAllEqual(x, val) 37 38 39if __name__ == '__main__': 40 test.main() 41