| 135 | expected=np.array([[-1, 1]], dtype=dtype)) |
| 136 | |
| 137 | def testFloatOps(self): |
| 138 | for dtype in self.float_types: |
| 139 | x = np.arange(-0.90, 0.90, 0.25) |
| 140 | self._assertOpOutputMatchesExpected( |
| 141 | math_ops.acos, x.astype(dtype), expected=np.arccos(x).astype(dtype)) |
| 142 | self._assertOpOutputMatchesExpected( |
| 143 | math_ops.asin, x.astype(dtype), expected=np.arcsin(x).astype(dtype)) |
| 144 | x = np.arange(-3, 3).reshape(1, 3, 2) |
| 145 | self._assertOpOutputMatchesExpected( |
| 146 | math_ops.atan, x.astype(dtype), expected=np.arctan(x).astype(dtype)) |
| 147 | |
| 148 | self._assertOpOutputMatchesExpected( |
| 149 | math_ops.acosh, |
| 150 | np.array([1, 2, 3, 4], dtype=dtype), |
| 151 | expected=np.array( |
| 152 | [0, 1.3169579, 1.76274717, 2.06343707], dtype=dtype)) |
| 153 | |
| 154 | self._assertOpOutputMatchesExpected( |
| 155 | math_ops.asinh, |
| 156 | np.array([1, 2, 3, 4], dtype=dtype), |
| 157 | expected=np.array( |
| 158 | [0.88137359, 1.44363548, 1.81844646, 2.09471255], dtype=dtype)) |
| 159 | |
| 160 | self._assertOpOutputMatchesExpected( |
| 161 | math_ops.atanh, |
| 162 | np.array([0.1, 0.2, 0.3, 0.4], dtype=dtype), |
| 163 | expected=np.array( |
| 164 | [0.10033535, 0.20273255, 0.3095196, 0.42364893], dtype=dtype)) |
| 165 | |
| 166 | self._assertOpOutputMatchesExpected( |
| 167 | math_ops.ceil, |
| 168 | np.array([[-1.7, 1.2]], dtype=dtype), |
| 169 | expected=np.array([[-1, 2]], dtype=dtype)) |
| 170 | |
| 171 | self._assertOpOutputMatchesExpected( |
| 172 | math_ops.cosh, |
| 173 | np.array([1, 2, 3, 4], dtype=dtype), |
| 174 | expected=np.array( |
| 175 | [1.54308063, 3.76219569, 10.067662, 27.30823284], dtype=dtype)) |
| 176 | |
| 177 | # Disable float16 testing for now |
| 178 | if dtype != np.float16: |
| 179 | x = np.arange(-10, 10, 1).astype(dtype) |
| 180 | with self.session() as session: |
| 181 | erf_x = session.run(math_ops.erf(x)) |
| 182 | erfc_x = session.run(math_ops.erfc(x)) |
| 183 | |
| 184 | self._assertOpOutputMatchesExpected(math_ops.erf, x, expected=erf_x) |
| 185 | self._assertOpOutputMatchesExpected(math_ops.erfc, x, expected=erfc_x) |
| 186 | |
| 187 | self._assertOpOutputMatchesExpected( |
| 188 | math_ops.exp, |
| 189 | np.array([[-1, 1]], dtype=dtype), |
| 190 | expected=np.array([[0.36787945, 2.7182817]], dtype=dtype)) |
| 191 | |
| 192 | self._assertOpOutputMatchesExpected( |
| 193 | math_ops.expm1, |
| 194 | np.array([[-1, 1]], dtype=dtype), |