test_subtensor.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:Theano-Deep-learning 作者: GeekLiB 项目源码 文件源码
def test_ellipsis(self):
        numpy_n = numpy.arange(24, dtype=self.dtype).reshape((2, 3, 4))
        n = self.shared(numpy_n)
        test_cases = [
            (0, Subtensor, self.sub, numpy.index_exp[...]),
            (1, Subtensor, self.sub, numpy.index_exp[..., 1]),
            (1, Subtensor, self.sub, numpy.index_exp[1, ...]),
            (1, Subtensor, self.sub, numpy.index_exp[..., 1, 2, 3]),
            (1, Subtensor, self.sub, numpy.index_exp[1, ..., 2, 3]),
            (1, Subtensor, self.sub, numpy.index_exp[1, 2, 3, ...]),
            (3, DimShuffle, self.dimshuffle,
             numpy.index_exp[..., [0, 2, 3]]),
            (1, DimShuffle, self.dimshuffle,
             numpy.index_exp[numpy.newaxis, ...]),
            (1, AdvancedSubtensor, self.adv_sub,
             numpy.index_exp[..., numpy.newaxis, [1, 2]])]

        for length, op_type, op_type_opt, slice_ in test_cases:
            numpy_tval = numpy_n[slice_]
            t = n[slice_]
            self.assertTrue(isinstance(t.owner.op, op_type))
            tval = self.eval_output_and_check(t,
                                              op_type=op_type_opt,
                                              length=length)
            assert_equal(tval.shape, numpy_tval.shape)
            assert_array_equal(tval, numpy_tval)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号