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

Class Abs

python/singa/autograd.py:2667–2689  ·  view source on GitHub ↗

`y = abs(x)`, is applied to the tensor elementwise.

Source from the content-addressed store, hash-verified

2665
2666
2667class Abs(Operator):
2668 """
2669 `y = abs(x)`, is applied to the tensor elementwise.
2670 """
2671
2672 def forward(self, a):
2673 """
2674 Return `abs(a)`, where a is CTensor.
2675 """
2676 if training:
2677 self.input = a
2678 return singa.Abs(a)
2679
2680 def backward(self, dy):
2681 """
2682 Args:
2683 dy (CTensor): the gradient tensor from upper operations
2684 Returns:
2685 CTensor, the gradient over input
2686 """
2687 dx = singa.Sign(self.input)
2688 dx *= dy
2689 return dx
2690
2691
2692def abs(a):

Callers 3

absFunction · 0.70
TEST_FFunction · 0.50
TEST_FFunction · 0.50

Calls

no outgoing calls

Tested by 2

TEST_FFunction · 0.40
TEST_FFunction · 0.40