okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-5 fccdb48a3 (image noise switch, step 1 only) into f-own-int150c2394f

main
1.5 KiB44 linesraw
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
3    python -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):
15    def 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."""
17        x = np.array([4.0, -4.0], dtype=np.float32)
18        sig = np.array([1.0, 0.5, 0.0], dtype=np.float32)
19        v = np.array([4.0, -4.0], dtype=np.float32)
20        out = S.euler_flow(x, [v, v], sig)
21        self.assertEqual(out.dtype, np.float32)
22        self.assertEqual(out.tolist(), [0.0, -0.0])
23
24    def test_zero_velocity_with_c_out_keeps_x_denoised(self):
25        """v = 0: denoised = x, d = 0, x stays."""
26        x = np.linspace(-3, 3, 11, dtype=np.float32)
27        sig = S.sigmas_f32()
28        out = S.euler_flow(x, [np.zeros_like(x)] * 8, sig)
29        self.assertTrue(np.array_equal(out, x))
30
31    def test_turbo_sigmas(self):
32        sig = S.sigmas_f32()
33        self.assertEqual(len(sig), 9)
34        self.assertEqual((float(sig[0]), float(sig[-1])), (1.0, 0.0))
35        self.assertTrue(all(sig[i] > sig[i + 1] for i in range(8)))
36        from serve import images
37        self.assertEqual(S.TURBO_SIGMAS, images.TURBO_SIGMAS)
38
39    def test_self_test(self):
40        S.self_test()
41
42
43if __name__ == "__main__":
44    unittest.main()