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

Method cossim_helper

test/python/test_operation.py:3217–3235  ·  view source on GitHub ↗
(self, dev)

Source from the content-addressed store, hash-verified

3215 dx, dhx, dcx, dw = _rnn.backward(dy.data)
3216
3217 def cossim_helper(self, dev):
3218 A = np.random.randn(*[3, 10]).astype(np.float32)
3219 B = np.random.randn(*[3, 10]).astype(np.float32)
3220
3221 a = tensor.from_numpy(A)
3222 a.to_device(dev)
3223 b = tensor.from_numpy(B)
3224 b.to_device(dev)
3225
3226 DY = np.random.randn(3).astype(np.float32)
3227 dy = tensor.from_numpy(DY)
3228 dy.to_device(dev)
3229
3230 y = autograd.cossim(a, b)
3231 da, db = y.creator.backward(dy.data) # CTensor
3232
3233 self.check_shape(y.shape, (3,))
3234 self.check_shape(da.shape(), (3, 10))
3235 self.check_shape(db.shape(), (3, 10))
3236
3237 def test_cossim_cpu(self):
3238 self.cossim_helper(cpu_dev)

Callers 2

test_cossim_cpuMethod · 0.95
test_cossim_gpuMethod · 0.95

Calls 4

check_shapeMethod · 0.95
shapeMethod · 0.80
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected