fix doc model part 2
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Module for performing integral for continuous convolution
|
||||
Module to perform integration for continuous convolution.
|
||||
"""
|
||||
|
||||
import torch
|
||||
@@ -7,17 +7,18 @@ import torch
|
||||
|
||||
class Integral:
|
||||
"""
|
||||
Integral class for continous convolution
|
||||
Class allowing integration for continous convolution.
|
||||
"""
|
||||
|
||||
def __init__(self, param):
|
||||
"""
|
||||
Initialize the integral class
|
||||
Initializzation of the :class:`Integral` class.
|
||||
|
||||
:param param: type of continuous convolution
|
||||
:param param: The type of continuous convolution.
|
||||
:type param: string
|
||||
:raises TypeError: If the parameter is neither ``discrete``
|
||||
nor ``continuous``.
|
||||
"""
|
||||
|
||||
if param == "discrete":
|
||||
self.make_integral = self.integral_param_disc
|
||||
elif param == "continuous":
|
||||
@@ -26,46 +27,47 @@ class Integral:
|
||||
raise TypeError
|
||||
|
||||
def __call__(self, *args, **kwds):
|
||||
"""
|
||||
Call the integral function
|
||||
|
||||
:param list args: Arguments for the integral function.
|
||||
:param dict kwds: Keyword arguments for the integral function.
|
||||
:return: The integral of the input.
|
||||
:rtype: torch.tensor
|
||||
"""
|
||||
return self.make_integral(*args, **kwds)
|
||||
|
||||
def _prepend_zero(self, x):
|
||||
"""Create bins for performing integral
|
||||
"""
|
||||
Create bins to perform integration.
|
||||
|
||||
:param x: input tensor
|
||||
:type x: torch.tensor
|
||||
:return: bins for integrals
|
||||
:rtype: torch.tensor
|
||||
:param torch.Tensor x: The input tensor.
|
||||
:return: The bins for the integral.
|
||||
:rtype: torch.Tensor
|
||||
"""
|
||||
return torch.cat((torch.zeros(1, dtype=x.dtype, device=x.device), x))
|
||||
|
||||
def integral_param_disc(self, x, y, idx):
|
||||
"""Perform discretize integral
|
||||
with discrete parameters
|
||||
"""
|
||||
Perform discrete integration with discrete parameters.
|
||||
|
||||
:param x: input vector
|
||||
:type x: torch.tensor
|
||||
:param y: input vector
|
||||
:type y: torch.tensor
|
||||
:param idx: indeces for different strides
|
||||
:type idx: list
|
||||
:return: integral
|
||||
:rtype: torch.tensor
|
||||
:param torch.Tensor x: The first input tensor.
|
||||
:param torch.Tensor y: The second input tensor.
|
||||
:param list[int] idx: The indices for different strides.
|
||||
:return: The discrete integral.
|
||||
:rtype: torch.Tensor
|
||||
"""
|
||||
cs_idxes = self._prepend_zero(torch.cumsum(torch.tensor(idx), 0))
|
||||
cs = self._prepend_zero(torch.cumsum(x.flatten() * y.flatten(), 0))
|
||||
return cs[cs_idxes[1:]] - cs[cs_idxes[:-1]]
|
||||
|
||||
def integral_param_cont(self, x, y, idx):
|
||||
"""Perform discretize integral for continuous convolution
|
||||
with continuous parameters
|
||||
"""
|
||||
Perform continuous integration with continuous parameters.
|
||||
|
||||
:param x: input vector
|
||||
:type x: torch.tensor
|
||||
:param y: input vector
|
||||
:type y: torch.tensor
|
||||
:param idx: indeces for different strides
|
||||
:type idx: list
|
||||
:return: integral
|
||||
:rtype: torch.tensor
|
||||
:param torch.Tensor x: The first input tensor.
|
||||
:param torch.Tensor y: The second input tensor.
|
||||
:param list[int] idx: The indices for different strides.
|
||||
:raises NotImplementedError: The method is not implemented.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
Reference in New Issue
Block a user