# Path: mesh_tensorflow/test_utils.py
# class NumpyConverter(object):
#   def __init__(self):
#   def convert_np_array_to_mtf_tensor(self, x, dim_names=None, dtype=tf.int32):
#   def convert_mtf_tensor_to_np_array(self, x_mtf):
#   def convert_mtf_tensor_to_tf_tensor(self, mtf_tensor):
#   def graph(self):
#   def mesh(self):
#   def session(self):


import mesh_tensorflow as mtf
import numpy as np
import tensorflow.compat.v1 as tf
from mesh_tensorflow import test_utils
from tensorflow.python.framework import test_util as tf_test_util
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for mesh_tensorflow.test_utils."""

# pylint:disable=g-direct-tensorflow-import


class TestUtilsTest(tf.test.TestCase):

  @tf_test_util.run_in_graph_and_eager_modes
  def test_convert_mtf_tensor_to_np_array(self):
    x_np = np.array([[1, 2, 3], [4, 5, 6]])
    converter = test_utils.NumpyConverter()
    shape = mtf.Shape([mtf.Dimension("dim0", 2), mtf.Dimension("dim1", 3)])
    x_mtf = mtf.constant(converter.mesh, x_np, shape=shape, dtype=tf.int32)
    actual = converter.convert_mtf_tensor_to_np_array(x_mtf)
    self.assertAllEqual(x_np, actual)

  @tf_test_util.run_in_graph_and_eager_modes
  def test_convert_mtf_tensor_to_np_array_with_trainable_variable(self):

# Path: mesh_tensorflow/test_utils.py
# class NumpyConverter(object):
#   def __init__(self):
#   def convert_np_array_to_mtf_tensor(self, x, dim_names=None, dtype=tf.int32):
#   def convert_mtf_tensor_to_np_array(self, x_mtf):
#   def convert_mtf_tensor_to_tf_tensor(self, mtf_tensor):
#   def graph(self):
#   def mesh(self):
#   def session(self):


# Path: mesh_tensorflow/test_utils_test.py
import mesh_tensorflow as mtf
import numpy as np
import tensorflow.compat.v1 as tf
from mesh_tensorflow import test_utils
from tensorflow.python.framework import test_util as tf_test_util

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for mesh_tensorflow.test_utils."""

# pylint:disable=g-direct-tensorflow-import


class TestUtilsTest(tf.test.TestCase):

  @tf_test_util.run_in_graph_and_eager_modes
  def test_convert_mtf_tensor_to_np_array(self):
    x_np = np.array([[1, 2, 3], [4, 5, 6]])
    converter = test_utils.NumpyConverter()
    shape = mtf.Shape([mtf.Dimension("dim0", 2), mtf.Dimension("dim1", 3)])
    x_mtf = mtf.constant(converter.mesh, x_np, shape=shape, dtype=tf.int32)
    actual = converter.convert_mtf_tensor_to_np_array(x_mtf)
    self.assertAllEqual(x_np, actual)

  @tf_test_util.run_in_graph_and_eager_modes
  def test_convert_mtf_tensor_to_np_array_with_trainable_variable(self):

    converter = test_utils.NumpyConverter()