File tree Expand file tree Collapse file tree
tests/test_gradient_evolution Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,19 +35,24 @@ def test_gradient_comparison(verbose = False):
3535 minim .meaningful_factor = 1e-10
3636 minim .max_ka = 5
3737
38- ka = 0
39- def compare_gradients (dyn_grad , struct_grad ):
40- if not os .path .exists ("grad_{}.dat" .format (ka )):
41- np .savetxt ("grad_{}.dat" .format (ka ), dyn_grad [0 ,:,:])
42- else :
43- correct_grad = np .loadtxt ("grad_{}.dat" .format (ka ))
44- diff = np .max (np .abs (dyn_grad - correct_grad ))
45- print ("KA = {} | difference = {}" .format (ka , diff ))
38+ class CG :
39+ def __init__ (self ):
40+ self .ka = 0
41+ def compare_gradients (self , dyn_grad , struct_grad ):
42+ ka = self .ka
4643
47-
44+ if not os .path .exists ("grad_{}.dat" .format (ka )):
45+ np .savetxt ("grad_{}.dat" .format (ka ), dyn_grad [0 ,:,:])
46+ else :
47+ correct_grad = np .loadtxt ("grad_{}.dat" .format (ka ))
48+ diff = np .max (np .abs (dyn_grad - correct_grad ))
49+ print ("KA = {} | difference = {}" .format (ka , diff ))
50+ self .ka += 1
51+
52+ cg = CG ()
4853
4954 minim .init ()
50- minim .run (custom_function_gradient = compare_gradients )
55+ minim .run (custom_function_gradient = cg . compare_gradients )
5156 minim .finalize ()
5257
5358
You can’t perform that action at this time.
0 commit comments