# Path: ldif/torch/sif.py
# def ensure_are_tensors(named_tensors):
# def ensure_type(v, t, name):
# def _load_v1_txt(path):
# def _tile_for_symgroups(elements, symmetry_count):
# def reflect_z(samples):
# def _generate_symgroup_samples(samples, element_count, symmetry_count):
# def _generate_symgroup_frames(world2local, symmetry_count):
#   def __init__(self, constants, centers, radii, rotations, symmetry_count):
#   def from_file(cls, path):
#   def from_flat_tensor(cls, tensor, symmetry_count):
#   def to_flat_tensor(self):
#   def rbf_influence(self, samples):
#   def effective_element_count(self):
#   def constants(self):
#   def _tiled_constants(self):
#   def _tiled_centers(self):
#   def _tiled_radii(self):
#   def _tiled_rotations(self):
#   def world2local(self):
#   def eval(self, samples):
# class Sif(object):


import os
import sys
import unittest
import numpy as np
import torch
from ldif.torch import sif
      self.assertAlmostEqual(values[i], expected_values[i])
    
  def test_evaluation_sym_nobatch(self):
    sif_path = os.path.join(TEST_DATA_DIR, 'b831f60f211435df5bbc861d0124304c.txt')
    shape = sif.Sif.from_file(sif_path)
    samples = torch.Tensor([[0.02, 0.008, -0.05]]).cuda()
    expected_values = [-0.238868]
    values = shape.eval(samples).cpu().numpy()
    self.assertEqual(values.shape, (1,))
    for i in range(len(expected_values)):
      self.assertAlmostEqual(values[i], expected_values[i], places=5)

  def test_evaluation_sym_batch(self):
    # TODO(kgenova) Need to replace the nosym with something that batches with the second.
    sif_a_path = os.path.join(TEST_DATA_DIR, 'b7eefc4c25dd9e49238581dd5a8af82c.txt')
    sif_b_path = os.path.join(TEST_DATA_DIR, 'b831f60f211435df5bbc861d0124304c.txt') 
    shape = sif.Sif.from_file([sif_a_path, sif_b_path])
    samples = torch.Tensor([[0.02, 0.008, -0.05],
      [0.0, 0.0, 0.0]]).cuda()
    expected_values = np.array([[-0.126568, -0.11410],
      [ -0.238868, -0.590321]], dtype=np.float32)
    values = shape.eval(samples).cpu().numpy()
    self.assertEqual(values.shape, (2,2))
    for bi in range(2):
      for si in range(2):
        self.assertAlmostEqual(values[bi, si], expected_values[bi, si], places=5)

  def test_world2local(self):
    """Tests that the code successfully produces 4x4 matrices (only)"""
    sif_path = os.path.join(TEST_DATA_DIR, 'b831f60f211435df5bbc861d0124304c.txt')

# Path: ldif/torch/sif.py
# def ensure_are_tensors(named_tensors):
# def ensure_type(v, t, name):
# def _load_v1_txt(path):
# def _tile_for_symgroups(elements, symmetry_count):
# def reflect_z(samples):
# def _generate_symgroup_samples(samples, element_count, symmetry_count):
# def _generate_symgroup_frames(world2local, symmetry_count):
#   def __init__(self, constants, centers, radii, rotations, symmetry_count):
#   def from_file(cls, path):
#   def from_flat_tensor(cls, tensor, symmetry_count):
#   def to_flat_tensor(self):
#   def rbf_influence(self, samples):
#   def effective_element_count(self):
#   def constants(self):
#   def _tiled_constants(self):
#   def _tiled_centers(self):
#   def _tiled_radii(self):
#   def _tiled_rotations(self):
#   def world2local(self):
#   def eval(self, samples):
# class Sif(object):


# Path: ldif/torch/sif_test.py
import os
import sys
import unittest
import numpy as np
import torch
from ldif.torch import sif

      self.assertAlmostEqual(values[i], expected_values[i])
    
  def test_evaluation_sym_nobatch(self):
    sif_path = os.path.join(TEST_DATA_DIR, 'b831f60f211435df5bbc861d0124304c.txt')
    shape = sif.Sif.from_file(sif_path)
    samples = torch.Tensor([[0.02, 0.008, -0.05]]).cuda()
    expected_values = [-0.238868]
    values = shape.eval(samples).cpu().numpy()
    self.assertEqual(values.shape, (1,))
    for i in range(len(expected_values)):
      self.assertAlmostEqual(values[i], expected_values[i], places=5)

  def test_evaluation_sym_batch(self):
    # TODO(kgenova) Need to replace the nosym with something that batches with the second.
    sif_a_path = os.path.join(TEST_DATA_DIR, 'b7eefc4c25dd9e49238581dd5a8af82c.txt')
    sif_b_path = os.path.join(TEST_DATA_DIR, 'b831f60f211435df5bbc861d0124304c.txt') 
    shape = sif.Sif.from_file([sif_a_path, sif_b_path])
    samples = torch.Tensor([[0.02, 0.008, -0.05],
      [0.0, 0.0, 0.0]]).cuda()
    expected_values = np.array([[-0.126568, -0.11410],
      [ -0.238868, -0.590321]], dtype=np.float32)
    values = shape.eval(samples).cpu().numpy()
    self.assertEqual(values.shape, (2,2))
    for bi in range(2):
      for si in range(2):
        self.assertAlmostEqual(values[bi, si], expected_values[bi, si], places=5)

  def test_world2local(self):
    """Tests that the code successfully produces 4x4 matrices (only)"""
    sif_path = os.path.join(TEST_DATA_DIR, 'b831f60f211435df5bbc861d0124304c.txt')

    shape = sif.Sif.from_file(sif_path)