Skip to content

Add

Description

Info

Parent class: Module

Derived classes: -

This module implements the operation of element-wise addition of input tensors from the passed list.

Initializing

def __init__(self, name=None):

Parameters

Parameter Allowed types Description Default
name str Layer name None

Explanations

-

Examples

Necessary imports.

import numpy as np
from PuzzleLib.Backend import gpuarray
from PuzzleLib.Modules import Add

Info

gpuarray is required to properly place the tensor in the GPU.

Let us form several data tensors, which will then be put in a list and summed element-wise.

d, h, w = 2, 3, 2
data1 = gpuarray.to_gpu(np.arange(d * h * w).reshape((d, h, w)).astype(np.float32))
data2 = data1.copy()
data3 = data1.copy()
print(data1)
[[[ 0.  1.]
  [ 2.  3.]
  [ 4.  5.]]

 [[ 6.  7.]
  [ 8.  9.]
  [10. 11.]]]
add = Add()
print(add([data1, data2, data3]))
[[[ 0.  3.]
  [ 6.  9.]
  [12. 15.]]

 [[18. 21.]
  [24. 27.]
  [30. 33.]]]