MulAddConst

Description

Info

Parent class: Module

Derived classes: -

This module applies a linear operator to the tensor.

Initializing

def __init__(self, a=1.0, b=0.0, inplace=False, name=None):

Parameters

Parameter Allowed types Description Default
a float Coefficient a of the linear operator ax+b. 1.0
b float Coefficient b of the linear operator ax+b . 0.0
inplace bool If True, then the output tensor will be written in the place of the input tensor in memory False
name str Layer name None

Explanations

inplace - flag showing whether additional memory resources should be allocated for the result. If True, then the output tensor will be written in the place of the input tensor in memory, which can negatively affect the network, if the input tensor takes part in calculations on other branches of the graph.

Examples

Necessary imports.

Info

gpuarray is required to properly place the tensor in the GPU

>>> batchsize, maps, h, w = 1, 1, 3, 3
>>> data = gpuarray.to_gpu(np.arange(batchsize * maps * h * w).reshape((batchsize, maps, h, w)).astype(np.float32))

>>> data
[[[[0. 1. 2.]
   [3. 4. 5.]
   [6. 7. 8.]]]]
>>> mulAdd = MulAddConst(a=3.14, b=42.0)
>>> mulAdd(data)

[[[[42.       45.14     48.28    ]
   [51.420002 54.56     57.7     ]
   [60.84     63.98     67.12    ]]]]