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

Class Sign

python/singa/autograd.py:2789–2817  ·  view source on GitHub ↗

Calculate the sign of the given input tensor element-wise. If input > 0, output 1. if input < 0, output -1. if input == 0, output 0.

Source from the content-addressed store, hash-verified

2787
2788
2789class Sign(Operator):
2790 """
2791 Calculate the sign of the given input tensor element-wise. If input > 0,
2792 output 1. if input < 0, output -1. if input == 0, output 0.
2793 """
2794
2795 def __init__(self):
2796 super(Sign, self).__init__()
2797
2798 def forward(self, a):
2799 """
2800 Args:
2801 a (CTensor): Input tensor
2802 Returns:
2803 CTensor, the output
2804 """
2805 if training:
2806 self.input = a
2807 return singa.Sign(a)
2808
2809 def backward(self, dy):
2810 """
2811 Args:
2812 dy (CTensor): the gradient tensor from upper operations
2813 Returns:
2814 CTensor, the gradient over input
2815 """
2816 dx = singa.MultFloat(dy, 0.0)
2817 return dx
2818
2819
2820def sign(a):

Callers 3

signFunction · 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