Skip to content

Commit

Permalink
Added triangular window function.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankong committed Jul 21, 2018
1 parent 4c0ca03 commit b262c97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion sigpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,30 @@ def ones_like(input):
return ones(input.shape, dtype=input.dtype, device=get_device(input))


def triang(shape, dtype=np.complex, device=cpu_device):
"""Create multi-dimensional triangular window.
Args:
shape (tuple of ints): Output shape.
dtype (Dtype): Output data-type.
device (Device): Output device.
Returns:
array: All-ones array.
"""
device = Device(device)
xp = device.xp

with device:
window = 1
for n, i in enumerate(shape[::-1]):
w = 1 - xp.abs(xp.arange(i, dtype=dtype) - i // 2 + ((i + 1) % 2) / 2) / ((i + 1) // 2)
window *= w.reshape([i] + [1] * n)

return window


def dot(input1, input2):
"""Compute dot product.
Expand Down Expand Up @@ -634,7 +658,7 @@ def norm(input):
xp = device.xp

with device:
return norm2(input)**0.5
return norm2(input)**0.5


def monte_carlo_sure(f, y, sigma, eps=1e-10):
Expand Down
4 changes: 4 additions & 0 deletions sigpy/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def test_dirac(self):
truth = [0, 0, 1, 0]
npt.assert_allclose(output, truth)

def test_triang(self):
npt.assert_allclose(util.triang([3]), [0.5, 1, 0.5])
npt.assert_allclose(util.triang([4]), [0.25, 0.75, 0.75, 0.25])

def test_resize(self):

# Zero-pad
Expand Down

0 comments on commit b262c97

Please sign in to comment.