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

Method forward

python/singa/autograd.py:505–531  ·  view source on GitHub ↗

Args: x (CTensor): input tensor Returns: a new CTensor with np.clip(x,min,max)

(self, x)

Source from the content-addressed store, hash-verified

503 self.min = min
504
505 def forward(self, x):
506 """
507 Args:
508 x (CTensor): input tensor
509 Returns:
510 a new CTensor with np.clip(x,min,max)
511 """
512 self.mask = singa.Tensor(list(x.shape()), x.device())
513 self.mask.SetFloatValue(1.0)
514
515 if self.min is not None:
516 self.min = float(self.min)
517 mask0 = singa.LTFloat(x, self.min)
518 mask1 = singa.GEFloat(x, self.min)
519 self.mask = singa.__mul__(mask1, self.mask)
520 x = singa.__add__(singa.MultFloat(mask0, self.min),
521 singa.__mul__(mask1, x))
522
523 if self.max is not None:
524 self.max = float(self.max)
525 mask0 = singa.GTFloat(x, self.max)
526 mask1 = singa.LEFloat(x, self.max)
527 self.mask = singa.__mul__(mask1, self.mask)
528 x = singa.__add__(singa.MultFloat(mask0, self.max),
529 singa.__mul__(mask1, x))
530
531 return x
532
533 def backward(self, dy):
534 """

Callers

nothing calls this directly

Calls 5

TensorMethod · 0.80
shapeMethod · 0.80
deviceMethod · 0.80
__mul__Method · 0.45
__add__Method · 0.45

Tested by

no test coverage detected