MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / slerp

Function slerp

diffusers/examples/community/interpolate_stable_diffusion.py:22–46  ·  view source on GitHub ↗

helper function to spherically interpolate two arrays v1 v2

(t, v0, v1, DOT_THRESHOLD=0.9995)

Source from the content-addressed store, hash-verified

20
21
22def slerp(t, v0, v1, DOT_THRESHOLD=0.9995):
23 """helper function to spherically interpolate two arrays v1 v2"""
24
25 if not isinstance(v0, np.ndarray):
26 inputs_are_torch = True
27 input_device = v0.device
28 v0 = v0.cpu().numpy()
29 v1 = v1.cpu().numpy()
30
31 dot = np.sum(v0 * v1 / (np.linalg.norm(v0) * np.linalg.norm(v1)))
32 if np.abs(dot) > DOT_THRESHOLD:
33 v2 = (1 - t) * v0 + t * v1
34 else:
35 theta_0 = np.arccos(dot)
36 sin_theta_0 = np.sin(theta_0)
37 theta_t = theta_0 * t
38 sin_theta_t = np.sin(theta_t)
39 s0 = np.sin(theta_0 - theta_t) / sin_theta_0
40 s1 = sin_theta_t / sin_theta_0
41 v2 = s0 * v0 + s1 * v1
42
43 if inputs_are_torch:
44 v2 = torch.from_numpy(v2).to(input_device)
45
46 return v2
47
48
49class StableDiffusionWalkPipeline(DiffusionPipeline, StableDiffusionMixin):

Callers 1

walkMethod · 0.70

Calls 1

toMethod · 0.45

Tested by

no test coverage detected