afnio.cognitive.modules.add
afnio.cognitive.modules.add.Add
Bases: Module
Performs element-wise addition of two input Variables.
This module utilizes the Add operation from
afnio.autodiff.basic_ops. The inputs must be instances of the
Variable class. The forward method applies the addition
operation to the data field of the inputs and returns
the resulting Variable.
Note
This module does not have any trainable parameters.
Examples:
>>> from afnio import cognitive as cog
>>> class Addition(cog.Module):
... def __init__(self):
... super().__init__()
... self.add = cog.Add()
>>> def forward(self, x, y):
... return self.add(x, y)
>>> input1 = afnio.Variable(data="abc", role="input1")
>>> input2 = afnio.Variable(data="def", role="input2")
>>> addition = Addition()
>>> result = addition(input1, input2)
>>> print(result.data)
'abcdef'
>>> print(result.role)
'input1 and input2'
Raises:
| Type | Description |
|---|---|
TypeError
|
If either input is not an instance of |
TypeError
|
If addition between the input types is not allowed. |
ValueError
|
|
ValueError
|
If list |
See Also
afnio.autodiff.basic_ops.Add
for the underlying operation.
Source code in afnio/cognitive/modules/add.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
forward(x, y)
Forward pass for element-wise addition.
Warning
Users should not call this method directly. Instead, they should call the
module instance itself, which will internally invoke this forward method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Variable
|
The first input |
required |
y
|
Variable
|
The second input |
required |
Returns:
| Type | Description |
|---|---|
Variable
|
A new |
Raises:
| Type | Description |
|---|---|
TypeError
|
If either input is not an instance
of |
TypeError
|
If addition between the input types is not allowed. |
ValueError
|
|
ValueError
|
If list |
Source code in afnio/cognitive/modules/add.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |