commit
99d4289251
@ -0,0 +1,33 @@
|
||||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
|
||||
"""RandomGamma op"""
|
||||
from mindspore.ops.op_info_register import op_info_register, AiCPURegOp, DataType
|
||||
|
||||
gamma_op_info = AiCPURegOp("Gamma") \
|
||||
.fusion_type("OPAQUE") \
|
||||
.input(0, "shape", "required") \
|
||||
.input(1, "alpha", "required") \
|
||||
.input(2, "beta", "required") \
|
||||
.output(0, "output", "required") \
|
||||
.attr("seed", "int") \
|
||||
.dtype_format(DataType.I32_Default, DataType.F32_Default, DataType.F32_Default, DataType.F32_Default) \
|
||||
.dtype_format(DataType.I32_NCHW, DataType.F32_NCHW, DataType.F32_NCHW, DataType.F32_NCHW) \
|
||||
.get_op_info()
|
||||
|
||||
@op_info_register(gamma_op_info)
|
||||
def _gamma_aicpu():
|
||||
"""RandomGamma AiCPU register"""
|
||||
return
|
@ -0,0 +1,32 @@
|
||||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
|
||||
"""RandomPoisson op"""
|
||||
from mindspore.ops.op_info_register import op_info_register, AiCPURegOp, DataType
|
||||
|
||||
poisson_op_info = AiCPURegOp("Poisson") \
|
||||
.fusion_type("OPAQUE") \
|
||||
.input(0, "shape", "required") \
|
||||
.input(1, "mean", "required") \
|
||||
.output(0, "output", "required") \
|
||||
.attr("seed", "int") \
|
||||
.dtype_format(DataType.I32_Default, DataType.F32_Default, DataType.F32_Default) \
|
||||
.dtype_format(DataType.I32_NCHW, DataType.F32_NCHW, DataType.I32_NCHW) \
|
||||
.get_op_info()
|
||||
|
||||
@op_info_register(poisson_op_info)
|
||||
def _poisson_aicpu():
|
||||
"""RandomPoisson AiCPU register"""
|
||||
return
|
@ -0,0 +1,33 @@
|
||||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
|
||||
"""RandomUniformInt op"""
|
||||
from mindspore.ops.op_info_register import op_info_register, AiCPURegOp, DataType
|
||||
|
||||
uniform_int_op_info = AiCPURegOp("UniformInt") \
|
||||
.fusion_type("OPAQUE") \
|
||||
.input(0, "shape", "required") \
|
||||
.input(1, "a", "required") \
|
||||
.input(2, "b", "required") \
|
||||
.output(0, "output", "required") \
|
||||
.attr("seed", "int") \
|
||||
.dtype_format(DataType.I32_Default, DataType.I32_Default, DataType.I32_Default, DataType.F32_Default) \
|
||||
.dtype_format(DataType.I32_NCHW, DataType.I32_NCHW, DataType.I32_NCHW, DataType.I32_NCHW) \
|
||||
.get_op_info()
|
||||
|
||||
@op_info_register(uniform_int_op_info)
|
||||
def _uniform_int_aicpu():
|
||||
"""RandomUniformInt AiCPU register"""
|
||||
return
|
@ -0,0 +1,33 @@
|
||||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
|
||||
"""RandomUniformReal op"""
|
||||
from mindspore.ops.op_info_register import op_info_register, AiCPURegOp, DataType
|
||||
|
||||
uniform_real_op_info = AiCPURegOp("UniformReal") \
|
||||
.fusion_type("OPAQUE") \
|
||||
.input(0, "shape", "required") \
|
||||
.input(1, "a", "required") \
|
||||
.input(2, "b", "required") \
|
||||
.output(0, "output", "required") \
|
||||
.attr("seed", "int") \
|
||||
.dtype_format(DataType.I32_Default, DataType.F32_Default, DataType.F32_Default, DataType.F32_Default) \
|
||||
.dtype_format(DataType.I32_NCHW, DataType.F32_NCHW, DataType.F32_NCHW, DataType.F32_NCHW) \
|
||||
.get_op_info()
|
||||
|
||||
@op_info_register(uniform_real_op_info)
|
||||
def _uniform_real_aicpu():
|
||||
"""RandomUniformReal AiCPU register"""
|
||||
return
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,58 @@
|
||||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
import numpy as np
|
||||
|
||||
import mindspore.context as context
|
||||
import mindspore.nn as nn
|
||||
from mindspore import Tensor
|
||||
from mindspore.ops import operations as P
|
||||
from mindspore.common import dtype as mstype
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
|
||||
|
||||
class Net(nn.Cell):
|
||||
def __init__(self, shape, seed=0):
|
||||
super(Net, self).__init__()
|
||||
self.gamma = P.Gamma(seed=seed)
|
||||
self.shape = shape
|
||||
|
||||
def construct(self, alpha, beta):
|
||||
return self.gamma(self.shape, alpha, beta)
|
||||
|
||||
|
||||
def test_net_1D():
|
||||
seed = 10
|
||||
shape = (3, 2, 4)
|
||||
alpha = 1.0
|
||||
beta = 1.0
|
||||
net = Net(shape, seed)
|
||||
talpha, tbeta = Tensor(alpha, mstype.float32), Tensor(beta, mstype.float32)
|
||||
output = net(talpha, tbeta)
|
||||
print(output.asnumpy())
|
||||
assert output.shape == (3, 2, 4)
|
||||
|
||||
|
||||
def test_net_ND():
|
||||
seed = 10
|
||||
shape = (3, 1, 2)
|
||||
alpha = np.array([[[1], [2]], [[3], [4]], [[5], [6]]]).astype(np.float32)
|
||||
beta = np.array([1.0]).astype(np.float32)
|
||||
net = Net(shape, seed)
|
||||
talpha, tbeta = Tensor(alpha), Tensor(beta)
|
||||
output = net(talpha, tbeta)
|
||||
print(output.asnumpy())
|
||||
assert output.shape == (3, 2, 2)
|
||||
|
@ -0,0 +1,53 @@
|
||||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
import numpy as np
|
||||
|
||||
import mindspore.context as context
|
||||
import mindspore.nn as nn
|
||||
from mindspore import Tensor
|
||||
from mindspore.ops import operations as P
|
||||
from mindspore.common import dtype as mstype
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
|
||||
|
||||
class Net(nn.Cell):
|
||||
def __init__(self, shape):
|
||||
super(Net, self).__init__()
|
||||
self.poisson = P.Poisson()
|
||||
self.shape = shape
|
||||
|
||||
def construct(self, mean):
|
||||
return self.poisson(self.shape, mean)
|
||||
|
||||
|
||||
def test_net_1():
|
||||
shape = (2, 16)
|
||||
mean = np.array([5.0]).astype(np.float32)
|
||||
net = Net(shape)
|
||||
tmean = Tensor(mean)
|
||||
output = net(tmean)
|
||||
print(output.asnumpy())
|
||||
assert output.shape == (2, 16)
|
||||
|
||||
|
||||
def test_net_2():
|
||||
shape = (4, 1)
|
||||
mean = np.array([5.0, 10.0]).astype(np.float32)
|
||||
net = Net(shape)
|
||||
tmean = Tensor(mean)
|
||||
output = net(tmean)
|
||||
print(output.asnumpy())
|
||||
assert output.shape == (4, 2)
|
@ -0,0 +1,57 @@
|
||||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
import numpy as np
|
||||
|
||||
import mindspore.context as context
|
||||
import mindspore.nn as nn
|
||||
from mindspore import Tensor
|
||||
from mindspore.ops import operations as P
|
||||
from mindspore.common import dtype as mstype
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
|
||||
|
||||
class Net(nn.Cell):
|
||||
def __init__(self, shape, seed=0):
|
||||
super(Net, self).__init__()
|
||||
self.uniformint = P.UniformInt(seed=seed)
|
||||
self.shape = shape
|
||||
|
||||
def construct(self, a, b):
|
||||
return self.uniformint(self.shape, a, b)
|
||||
|
||||
|
||||
def test_net_1D():
|
||||
seed = 10
|
||||
shape = (3, 2, 4)
|
||||
a = 1
|
||||
b = 5
|
||||
net = Net(shape, seed)
|
||||
ta, tb = Tensor(a, mstype.int32), Tensor(b, mstype.int32)
|
||||
output = net(ta, tb)
|
||||
print(output.asnumpy())
|
||||
assert output.shape == (3, 2, 4)
|
||||
|
||||
|
||||
def test_net_ND():
|
||||
seed = 10
|
||||
shape = (3, 2, 1)
|
||||
a = np.array([[[1, 2]], [[3, 4]], [[5, 6]]]).astype(np.int32)
|
||||
b = np.array([10]).astype(np.int32)
|
||||
net = Net(shape, seed)
|
||||
ta, tb = Tensor(a), Tensor(b)
|
||||
output = net(ta, tb)
|
||||
print(output.asnumpy())
|
||||
assert output.shape == (3, 2, 2)
|
@ -0,0 +1,57 @@
|
||||
# Copyright 2020 Huawei Technologies Co., Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# ============================================================================
|
||||
import numpy as np
|
||||
|
||||
import mindspore.context as context
|
||||
import mindspore.nn as nn
|
||||
from mindspore import Tensor
|
||||
from mindspore.ops import operations as P
|
||||
from mindspore.common import dtype as mstype
|
||||
|
||||
context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")
|
||||
|
||||
|
||||
class Net(nn.Cell):
|
||||
def __init__(self, shape, seed=0):
|
||||
super(Net, self).__init__()
|
||||
self.uniformreal = P.UniformReal(seed=seed)
|
||||
self.shape = shape
|
||||
|
||||
def construct(self, a, b):
|
||||
return self.uniformreal(self.shape, a, b)
|
||||
|
||||
|
||||
def test_net_1D():
|
||||
seed = 10
|
||||
shape = (3, 2, 4)
|
||||
a = 1.0
|
||||
b = 5.0
|
||||
net = Net(shape, seed)
|
||||
ta, tb = Tensor(a, mstype.float32), Tensor(b, mstype.float32)
|
||||
output = net(ta, tb)
|
||||
print(output.asnumpy())
|
||||
assert output.shape == (3, 2, 4)
|
||||
|
||||
|
||||
def test_net_ND():
|
||||
seed = 10
|
||||
shape = (3, 2, 1)
|
||||
a = np.array([[[1, 2]], [[3, 4]], [[5, 6]]]).astype(np.float32)
|
||||
b = np.array([10]).astype(np.float32)
|
||||
net = Net(shape, seed)
|
||||
ta, tb = Tensor(a), Tensor(b)
|
||||
output = net(ta, tb)
|
||||
print(output.asnumpy())
|
||||
assert output.shape == (3, 2, 2)
|
Loading…
Reference in new issue