Skip to content

nn

Lambda

Bases: nn.Module

Source code in glasses/nn/__init__.py
class Lambda(nn.Module):
    def __init__(self, lambd: Callable[[Tensor], Tensor]):
        """An utility Module, it allows custom function to be passed
        Args:
            lambd (Callable[Tensor]): A function that does something on a tensor

        Usage:

        ```python
            add_two = Lambda(lambd x: x + 2)
            add_two(Tensor([0])) // 2
        ```

        """
        super().__init__()
        self.lambd = lambd

    def forward(self, x: Tensor) -> Tensor:
        return self.lambd(x)

__init__(lambd)

An utility Module, it allows custom function to be passed

Parameters:

Name Type Description Default
lambd Callable[Tensor]

A function that does something on a tensor

required

Usage:

    add_two = Lambda(lambd x: x + 2)
    add_two(Tensor([0])) // 2
Source code in glasses/nn/__init__.py
def __init__(self, lambd: Callable[[Tensor], Tensor]):
    """An utility Module, it allows custom function to be passed
    Args:
        lambd (Callable[Tensor]): A function that does something on a tensor

    Usage:

    ```python
        add_two = Lambda(lambd x: x + 2)
        add_two(Tensor([0])) // 2
    ```

    """
    super().__init__()
    self.lambd = lambd