(self, dev)
| 236 | self._concat_helper(gpu_dev) |
| 237 | |
| 238 | def _matmul_helper(self, dev): |
| 239 | X1 = np.random.randn(4, 5).astype(np.float32) |
| 240 | X2 = np.random.randn(5, 4).astype(np.float32) |
| 241 | |
| 242 | x1 = tensor.from_numpy(X1) |
| 243 | x2 = tensor.from_numpy(X2) |
| 244 | x1.to_device(dev) |
| 245 | x2.to_device(dev) |
| 246 | |
| 247 | y = autograd.Matmul()(x1, x2)[0] |
| 248 | |
| 249 | # frontend |
| 250 | model = sonnx.to_onnx([x1, x2], [y]) |
| 251 | # print('The model is:\n{}'.format(model)) |
| 252 | |
| 253 | # backend |
| 254 | sg_ir = sonnx.prepare(model, device=dev) |
| 255 | sg_ir.is_graph = True |
| 256 | y_t = sg_ir.run([x1, x2]) |
| 257 | |
| 258 | np.testing.assert_array_almost_equal(tensor.to_numpy(y), |
| 259 | tensor.to_numpy(y_t[0]), |
| 260 | decimal=5) |
| 261 | |
| 262 | def test_matmul_cpu(self): |
| 263 | self._matmul_helper(cpu_dev) |
no test coverage detected