# Copyright 2019 Google LLC
#
# 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
#
#     https://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 --debug_nans."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from absl.testing import absltest
from absl.testing import parameterized

import numpy as onp

import jax
from jax import test_util as jtu
from jax.test_util import check_grads
from jax import numpy as np
from jax import random

from jax.config import config
config.parse_flags_with_absl()

class DebugNaNsTest(jtu.JaxTestCase):
  def testSingleResultPrimitive(self):
    cfg = config.read("jax_debug_nans")
    config.update("jax_debug_nans", True)
    A = np.array([[1., 2.], [2., 3.]])
    B = np.tanh(A)
    config.update("jax_debug_nans", cfg)
  def testMultipleResultPrimitive(self):
    cfg = config.read("jax_debug_nans")
    config.update("jax_debug_nans", True)
    A = np.array([[1., 2.], [2., 3.]])
    D, V = np.linalg.eig(A)
    config.update("jax_debug_nans", cfg)
  def testJitComputation(self):
    cfg = config.read("jax_debug_nans")
    config.update("jax_debug_nans", True)
    A = np.array([[1., 2.], [2., 3.]])
    B = jax.jit(np.tanh)(A)
    config.update("jax_debug_nans", cfg)

@@ -1048,33 +1048,13 @@
 def 
-testSingleResultPrimitive
+setUp
 (sel
@@ -1053,32 +1053,37 @@
 etUp(self):%0A    
+self.
 cfg = config.rea
@@ -1150,63 +1150,27 @@
 )%0A  
-  A = np.array(%5B%5B1., 2.%5D, %5B2., 3.%5D%5D)%0A    B = np.tanh(A)
+def tearDown(self):
 %0A   
@@ -1194,37 +1194,43 @@
 ax_debug_nans%22, 
+self.
 cfg)%0A
+%0A
   def testMultip
@@ -1227,14 +1227,12 @@
 test
-Multip
+Sing
 leRe
@@ -1260,307 +1260,201 @@
     
-cfg = config.read(%22jax_debug_nans%22)%0A    config.update(%22jax_debug_nans%22, True)%0A    A = np.array(%5B%5B1., 2.%5D, %5B2., 3.%5D%5D)%0A    D, V = np.linalg.eig(A)%0A    config.update(%22jax_debug_nans%22, cfg)%0A  def testJitComputation(self):%0A    cfg = config.read(%22jax_debug_nans%22)%0A    config.update(%22jax_debug_nans%22, True)
+A = np.array(%5B%5B1., 2.%5D, %5B2., 3.%5D%5D)%0A    B = np.tanh(A)%0A  def testMultipleResultPrimitive(self):%0A    A = np.array(%5B%5B1., 2.%5D, %5B2., 3.%5D%5D)%0A    D, V = np.linalg.eig(A)%0A  def testJitComputation(self):
 %0A   
@@ -1521,45 +1521,4 @@
 (A)%0A
-    config.update(%22jax_debug_nans%22, cfg)%0A

use setUp and tearDown