Ejemplo n.º 1
0
 def __init__(self, start, limit=None, delta=1):
     super(Range, self).__init__()
     validator.check_value_type("start", start, [int, float], self.cls_name)
     validator.check_value_type("delta", delta, [int, float], self.cls_name)
     if delta == 0:
         raise ValueError("The input of `delta` can not be equal to zero.")
     if limit is not None:
         validator.check_value_type("limit", limit, [int, float],
                                    self.cls_name)
         if isinstance(start, int) and isinstance(
                 limit, int) and isinstance(delta, int):
             self.dtype = mstype.int32
         else:
             self.dtype = mstype.float32
     else:
         if isinstance(start, int) and isinstance(delta, int):
             self.dtype = mstype.int32
         else:
             self.dtype = mstype.float32
     if isinstance(start, int):
         start = float(start)
     if isinstance(limit, int):
         limit = float(limit)
     if isinstance(delta, int):
         delta = float(delta)
     self.range_x = P.Range(start, limit, delta)
     if limit is None:
         length_input = math.ceil(start / delta)
     else:
         length_input = math.ceil((limit - start) / delta)
     self.input_tensor = Tensor(list(range(length_input)), self.dtype)
Ejemplo n.º 2
0
 def __init__(self,
              weight,
              start,
              limit,
              delta,
              strategy1=None,
              strategy2=None,
              strategy3=None):
     super().__init__()
     self.mul = P.Mul().shard(strategy1)
     if isinstance(start, float):
         self.type = mstype.float32
     else:
         self.type = mstype.int32
     self.start = Tensor(start, self.type)
     self.limit = Tensor(limit, self.type)
     self.delta = Tensor(delta, self.type)
     self.range = P.Range()
     self.range.shard(strategy2)
     self.mul2 = P.Mul().shard(strategy3)
     self.weight = Parameter(weight, "w")
Ejemplo n.º 3
0
def test_range_invalid_max_output_length():
    with pytest.raises(ValueError):
        _ = P.Range(0)
        _ = P.Range(-1)
        _ = P.Range(None)
        _ = P.Range('5')
Ejemplo n.º 4
0
 def __init__(self, maxlen=10000):
     super(RangeNet, self).__init__()
     self.range = P.Range(maxlen)
Ejemplo n.º 5
0
 def __init__(self):
     super(RangeNet, self).__init__()
     self.range = P.Range()