from tensorflow.python.framework import constant_op

from tensorflow.python.framework import random_seed
from tensorflow.python.ops import variables
from tensorflow.python.ops import array_ops
from tensorflow.python.platform import test


class OpsTest(test.TestCase):
  """Ops tests."""

  def test_softmax_classifier(self):
    with self.cached_session() as session:
      features = array_ops.placeholder(dtypes.float32, [None, 3])
      labels = array_ops.placeholder(dtypes.float32, [None, 2])
      weights = constant_op.constant([[0.1, 0.1], [0.1, 0.1], [0.1, 0.1]])
      biases = constant_op.constant([0.2, 0.3])
      class_weight = constant_op.constant([0.1, 0.9])
      prediction, loss = ops.softmax_classifier(features, labels, weights,
                                                biases, class_weight)
      self.assertEqual(prediction.get_shape()[1], 2)
      self.assertEqual(loss.get_shape(), [])
      value = session.run(loss, {features: [[0.2, 0.3, 0.2]], labels: [[0, 1]]})
      self.assertAllClose(value, 0.55180627)

  def test_embedding_lookup(self):
    d_embed = 5
    n_embed = 10
    ids_shape = (2, 3, 4)
    embeds = np.random.randn(n_embed, d_embed)
    ids = np.random.randint(0, n_embed, ids_shape)
    with self.cached_session():
