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

Method forward

python/singa/autograd.py:4962–4978  ·  view source on GitHub ↗

forward of CosSim Args: a (CTensor): input tensor. b (CTensor): input tensor. Returns: the output CTensor.

(self, a, b)

Source from the content-addressed store, hash-verified

4960 return singa.Reshape(ret, [ret.shape()[0]]) # b
4961
4962 def forward(self, a, b):
4963 """
4964 forward of CosSim
4965 Args:
4966 a (CTensor): input tensor.
4967 b (CTensor): input tensor.
4968 Returns:
4969 the output CTensor.
4970 """
4971 ad = CosSim.dot(a, a)
4972 bd = CosSim.dot(b, b)
4973 ap = singa.PowFloat(ad, 0.5)
4974 bp = singa.PowFloat(bd, 0.5)
4975 ret = singa.__div__(CosSim.dot(a, b), singa.__mul__(ap, bp))
4976 if training:
4977 self.cache = (a, b, ad, bd, ap, bp, ret)
4978 return ret
4979
4980 def backward(self, dy):
4981 """

Callers

nothing calls this directly

Calls 3

dotMethod · 0.80
__div__Method · 0.45
__mul__Method · 0.45

Tested by

no test coverage detected