Example #1
0
def test_full_like():
    test_case = Cases()
    for mnp_proto, onp_proto in zip(test_case.mnp_prototypes, test_case.onp_prototypes):
        shape = onp.zeros_like(onp_proto).shape
        fill_value = rand_int()
        actual = mnp.full_like(mnp_proto, mnp.array(fill_value)).asnumpy()
        expected = onp.full_like(onp_proto, fill_value)
        match_array(actual, expected)

        for i in range(len(shape) - 1, 0, -1):
            fill_value = rand_int(*shape[i:])
            actual = mnp.full_like(mnp_proto, mnp.array(fill_value)).asnumpy()
            expected = onp.full_like(onp_proto, fill_value)
            match_array(actual, expected)

            fill_value = rand_int(1, *shape[i + 1:])
            actual = mnp.full_like(mnp_proto, mnp.array(fill_value)).asnumpy()
            expected = onp.full_like(onp_proto, fill_value)
            match_array(actual, expected)
Example #2
0
 def construct(self, inputs: Tensor, mask: Tensor):
     if mask.dtype != mindspore.bool_:
         mask = self.cast(mask, mindspore.bool_)
     masked = mnp.full_like(inputs, self.value)
     outputs = self.select(mask, masked, inputs)
     return outputs