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

Method _4d_matmul_helper

test/python/test_tensor.py:462–481  ·  view source on GitHub ↗
(self, dev)

Source from the content-addressed store, hash-verified

460 self._3d_matmul_helper(gpu_dev)
461
462 def _4d_matmul_helper(self, dev):
463 np_x1 = np.random.randn(2, 12, 256, 64).astype(np.float32)
464 np_x2 = np.random.randn(2, 12, 64, 256).astype(np.float32)
465 x1 = tensor.from_numpy(np_x1)
466 x1.to_device(dev)
467 x2 = tensor.from_numpy(np_x2)
468 x2.to_device(dev)
469 y = autograd.matmul(x1, x2)
470 np_y = np.matmul(np_x1, np_x2)
471 np.testing.assert_array_almost_equal(tensor.to_numpy(y), np_y)
472
473 np_x1 = np.random.randn(2, 12, 256, 64).astype(np.float32)
474 np_x2 = np.random.randn(2, 12, 64, 1024).astype(np.float32)
475 x1 = tensor.from_numpy(np_x1)
476 x1.to_device(dev)
477 x2 = tensor.from_numpy(np_x2)
478 x2.to_device(dev)
479 y = autograd.matmul(x1, x2)
480 np_y = np.matmul(np_x1, np_x2)
481 np.testing.assert_array_almost_equal(tensor.to_numpy(y), np_y)
482
483 def test_4d_matmul_cpu(self):
484 self._4d_matmul_helper(cpu_dev)

Callers 2

test_4d_matmul_cpuMethod · 0.95
test_4d_matmul_gpuMethod · 0.95

Calls 1

to_deviceMethod · 0.45

Tested by

no test coverage detected