(self, dev)
| 1250 | self._clip_helper(gpu_dev) |
| 1251 | |
| 1252 | def _prelu_helper(self, dev): |
| 1253 | x = np.array([0.1, -1.0, -0.4, 4.0, -0.9, |
| 1254 | 9.0]).reshape(3, 2).astype(np.float32) |
| 1255 | slope = np.array([0.1, 1.0, 0.4, 4.0, 0.9, |
| 1256 | 9.0]).reshape(3, 2).astype(np.float32) |
| 1257 | |
| 1258 | x = tensor.from_numpy(x) |
| 1259 | slope = tensor.from_numpy(slope) |
| 1260 | x.to_device(dev) |
| 1261 | slope.to_device(dev) |
| 1262 | |
| 1263 | y = autograd.prelu(x, slope) |
| 1264 | |
| 1265 | # frontend |
| 1266 | model = sonnx.to_onnx([x, slope], [y]) |
| 1267 | # print('The model is:\n{}'.format(model)) |
| 1268 | |
| 1269 | # backend |
| 1270 | sg_ir = sonnx.prepare(model, device=dev) |
| 1271 | sg_ir.is_graph = True |
| 1272 | y_t = sg_ir.run([x, slope]) |
| 1273 | |
| 1274 | np.testing.assert_array_almost_equal(tensor.to_numpy(y), |
| 1275 | tensor.to_numpy(y_t[0]), |
| 1276 | decimal=5) |
| 1277 | |
| 1278 | def test_prelu_cpu(self): |
| 1279 | self._prelu_helper(cpu_dev) |
no test coverage detected