okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
150c2394f
main
1"""tools/image/gate/test_sampler_ref.py - TEST-ONLY: sampler_ref.py's euler step on numbers that can be done by hand. 2 3python -m pytest tools/image/gate/test_sampler_ref.py""" 4import sys 5import unittest 6from pathlib import Path 7 8import numpy as np 9 10sys .path .insert (0 ,str (Path (__file__ ).resolve ().parent )) 11import sampler_ref as S # noqa: E402 12 13 14class Euler (unittest .TestCase ): 15def test_by_hand (self ): 16"""x = 4, sigmas 1 -> 0.5 -> 0, velocity 4 each time: denoised = 0 both times, so x goes 4 -> 2 -> 0.""" 17x = np .array ([4.0 ,- 4.0 ],dtype = np .float32 ) 18sig = np .array ([1.0 ,0.5 ,0.0 ],dtype = np .float32 ) 19v = np .array ([4.0 ,- 4.0 ],dtype = np .float32 ) 20out = S .euler_flow (x , [v ,v ],sig ) 21self .assertEqual (out .dtype ,np .float32 ) 22self .assertEqual (out .tolist (), [0.0 ,- 0.0 ]) 23 24def test_zero_velocity_with_c_out_keeps_x_denoised (self ): 25"""v = 0: denoised = x, d = 0, x stays.""" 26x = np .linspace (- 3 ,3 ,11 ,dtype = np .float32 ) 27sig = S .sigmas_f32 () 28out = S .euler_flow (x , [np .zeros_like (x )]* 8 ,sig ) 29self .assertTrue (np .array_equal (out ,x )) 30 31def test_turbo_sigmas (self ): 32sig = S .sigmas_f32 () 33self .assertEqual (len (sig ),9 ) 34self .assertEqual ((float (sig [0 ]),float (sig [- 1 ])), (1.0 ,0.0 )) 35self .assertTrue (all (sig [i ]> sig [i + 1 ]for i in range (8 ))) 36from serve import images 37self .assertEqual (S .TURBO_SIGMAS ,images .TURBO_SIGMAS ) 38 39def test_self_test (self ): 40S .self_test () 41 42 43if __name__ == "__main__" : 44unittest .main ()