1# Copyright 2020 Huawei Technologies Co., Ltd 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================ 15 16import mindspore.context as context 17import mindspore.nn.probability.distribution as msd 18 19context.set_context(device_target='GPU') 20 21def test_categorical1(): 22 cat1 = msd.Categorical(probs=[[0.9, 0.2], [0.9, 0.2]]) 23 cat1out1 = cat1.sample((1,)) 24 cat1out2 = cat1.sample((3, 2)) 25 cat1out3 = cat1.sample((6,)) 26 assert cat1out1.asnumpy().shape == (2, 1) 27 assert cat1out2.asnumpy().shape == (2, 3, 2) 28 assert cat1out3.asnumpy().shape == (2, 6) 29 30 cat1 = msd.Categorical(probs=[0.9, 0.2]) 31 cat1out1 = cat1.sample((1,)) 32 cat1out2 = cat1.sample((3, 2)) 33 cat1out3 = cat1.sample((6,)) 34 assert cat1out1.asnumpy().shape == (1,) 35 assert cat1out2.asnumpy().shape == (3, 2) 36 assert cat1out3.asnumpy().shape == (6,) 37