MCPcopy Create free account
hub / github.com/apache/singa / forward

Method forward

python/singa/autograd.py:1656–1683  ·  view source on GitHub ↗

Args: x (CTensor): input W (CTensor): weight b (CTensor): bias Returns: CTensor

(self, x, W, b=None)

Source from the content-addressed store, hash-verified

1654 self.odd_padding = odd_padding
1655
1656 def forward(self, x, W, b=None):
1657 """
1658 Args:
1659 x (CTensor): input
1660 W (CTensor): weight
1661 b (CTensor): bias
1662 Returns:
1663 CTensor
1664 """
1665 assert x.nDim() == 4, "The dimensions of input should be 4D."
1666 if self.odd_padding != (0, 0, 0, 0):
1667 x = utils.handle_odd_pad_fwd(x, self.odd_padding)
1668
1669 if training:
1670 if self.handle.bias_term:
1671 self.inputs = (x, W, b)
1672 else:
1673 self.inputs = (x, W)
1674
1675 if not self.handle.bias_term:
1676 # create empty bias tensor for Cpp API
1677 b = CTensor((self.handle.num_filters,), x.device())
1678 b.SetFloatValue(0.0)
1679
1680 if (type(self.handle) != singa.ConvHandle):
1681 return singa.GpuConvForward(x, W, b, self.handle)
1682 else:
1683 return singa.CpuConvForward(x, W, b, self.handle)
1684
1685 def backward(self, dy):
1686 """

Callers

nothing calls this directly

Calls 3

typeFunction · 0.85
nDimMethod · 0.80
deviceMethod · 0.80

Tested by

no test coverage detected