interval¶
- dnois.utils.interval(n: int, spacing: float | Tensor = None, center: float | Tensor = None, symmetric: bool = False, **kwargs) Tensor ¶
Create a 1D evenly spaced grid.
>>> interval(3, 0.1) tensor([-0.10, 0.00, 0.10]) >>> interval(3, torch.tensor([0.1, 0.2])) tensor([[-0.10, 0.00, 0.10], [-0.20, 0.00, 0.20]]) >>> interval(3, torch.tensor([0.1, 0.2]), torch.tensor([-1, 1])) tensor([[-1.10, -1.00, -0.90], [ 0.80, 1.00, 1.20]]) >>> interval(4) tensor([-2., -1., 0., 1.]) >>> interval(4, symmetric=True) tensor([-1.50, -0.50, 0.50, 1.50])
- Parameters:
n (int) – Number of grid points.
spacing (float or Tensor.) – Spacing between grid points. If a tensor with shape
(...)
, the returned tensor will have shape(..., n)
. Default: 1.center (float or Tensor.) – Center of resulted grid points. If a tensor with shape
(...)
, the returned tensor will have shape(..., n)
. Default: 0.symmetric (bool) – If
True
, grid points are symmetric w.r.t.center
. Otherwise,n // 2
points are smaller,n // 2 - 1
points are larger and one point iscenter
value. Only matters whenn
is even. Default:False
.kwargs – Tensor creation arguments passes to
torch.linspace()
likedevice
.
- Returns:
A tensor of shape
(n,)
ifspacing
andcenter
are both scalars, otherwise of shape(*<broadcast shape of spacing and center>, n)
.- Return type:
Tensor