# Path: t3f/utils.py
# def unravel_index(indices, shape):
# def replace_tf_svd_with_np_svd():
#   def my_svd(tensor, full_matrices=False, compute_uv=True):
# def in_eager_mode():


import numpy as np
import tensorflow as tf
from t3f import utils
tf.compat.v1.enable_eager_execution()



class UtilsTest(tf.test.TestCase):

  def testUnravelIndex(self):
    # 2D.
    shape = (7, 6)
    linear_idx = [22, 41, 37]
    desired = [[3, 4], [6, 5], [6, 1]]
    actual = utils.unravel_index(linear_idx, shape)
    self.assertAllEqual(desired, self.evaluate(actual))
    # 3D.
    shape = (2, 3, 4)
    linear_idx = [19, 17, 0, 23]
    desired = [[1, 1, 3], [1, 1, 1], [0, 0, 0], [1, 2, 3]]

# Path: t3f/utils.py
# def unravel_index(indices, shape):
# def replace_tf_svd_with_np_svd():
#   def my_svd(tensor, full_matrices=False, compute_uv=True):
# def in_eager_mode():


# Path: t3f/utils_test.py
import numpy as np
import tensorflow as tf
from t3f import utils

tf.compat.v1.enable_eager_execution()



class UtilsTest(tf.test.TestCase):

  def testUnravelIndex(self):
    # 2D.
    shape = (7, 6)
    linear_idx = [22, 41, 37]
    desired = [[3, 4], [6, 5], [6, 1]]
    actual = utils.unravel_index(linear_idx, shape)
    self.assertAllEqual(desired, self.evaluate(actual))
    # 3D.
    shape = (2, 3, 4)
    linear_idx = [19, 17, 0, 23]
    desired = [[1, 1, 3], [1, 1, 1], [0, 0, 0], [1, 2, 3]]

    actual = utils.unravel_index(linear_idx, shape)