Calculates the hyperbolic arccosine of the given input tensor element-wise.
| 2098 | |
| 2099 | |
| 2100 | class Acosh(Operator): |
| 2101 | """ |
| 2102 | Calculates the hyperbolic arccosine of the given input tensor element-wise. |
| 2103 | """ |
| 2104 | |
| 2105 | def __init__(self): |
| 2106 | super(Acosh, self).__init__() |
| 2107 | |
| 2108 | def forward(self, x): |
| 2109 | """ |
| 2110 | Args: |
| 2111 | x (CTensor): Input tensor |
| 2112 | Returns: |
| 2113 | CTensor, the output |
| 2114 | """ |
| 2115 | if training: |
| 2116 | self.input = x |
| 2117 | return singa.Acosh(x) |
| 2118 | |
| 2119 | def backward(self, dy): |
| 2120 | """ |
| 2121 | Args: |
| 2122 | dy (CTensor): the gradient tensor from upper operations |
| 2123 | Returns: |
| 2124 | CTensor, the gradient over input |
| 2125 | """ |
| 2126 | dx = singa.SubFloat(self.input, 1.0) |
| 2127 | dx = singa.Sqrt(dx) |
| 2128 | temp = singa.AddFloat(self.input, 1.0) |
| 2129 | temp = singa.Sqrt(temp) |
| 2130 | dx = singa.__mul__(dx, temp) |
| 2131 | dx = singa.PowFloat(dx, -1.0) |
| 2132 | dx *= dy |
| 2133 | return dx |
| 2134 | |
| 2135 | |
| 2136 | def acosh(x): |