MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / squarepulse

Function squarepulse

monai/transforms/utils.py:2229–2248  ·  view source on GitHub ↗

compute squarepulse using pytorch equivalent to numpy implementation from https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.square.html

(sig, duty: float = 0.5)

Source from the content-addressed store, hash-verified

2227
2228
2229def squarepulse(sig, duty: float = 0.5):
2230 """
2231 compute squarepulse using pytorch
2232 equivalent to numpy implementation from
2233 https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.square.html
2234 """
2235 t, w = convert_to_tensor(sig), convert_to_tensor(duty)
2236 w = convert_to_tensor(w)
2237 t = convert_to_tensor(t)
2238
2239 y = torch.zeros(t.shape)
2240
2241 mask1 = (w > 1) | (w < 0)
2242
2243 tmod = torch.remainder(t, 2 * torch.pi)
2244 mask2 = (~mask1) & (tmod < w * 2 * torch.pi)
2245 y[mask2] = 1
2246 mask3 = (~mask1) & (~mask2)
2247 y[mask3] = -1
2248 return y
2249
2250
2251def _to_numpy_resample_interp_mode(interp_mode):

Callers 2

__call__Method · 0.90
__call__Method · 0.90

Calls 1

convert_to_tensorFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…