test_multiarray.py 文件源码

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

项目:radar 作者: amoose136 项目源码 文件源码
def test_out_arg(self):
        a = np.ones((2, 2), dtype=np.float)
        b = np.ones((2, 2), dtype=np.float)
        tgt = np.full((2,2), 2, dtype=np.float)

        # test as positional argument
        msg = "out positional argument"
        out = np.zeros((2, 2), dtype=np.float)
        self.matmul(a, b, out)
        assert_array_equal(out, tgt, err_msg=msg)

        # test as keyword argument
        msg = "out keyword argument"
        out = np.zeros((2, 2), dtype=np.float)
        self.matmul(a, b, out=out)
        assert_array_equal(out, tgt, err_msg=msg)

        # test out with not allowed type cast (safe casting)
        # einsum and cblas raise different error types, so
        # use Exception.
        msg = "out argument with illegal cast"
        out = np.zeros((2, 2), dtype=np.int32)
        assert_raises(Exception, self.matmul, a, b, out=out)

        # skip following tests for now, cblas does not allow non-contiguous
        # outputs and consistency with dot would require same type,
        # dimensions, subtype, and c_contiguous.

        # test out with allowed type cast
        # msg = "out argument with allowed cast"
        # out = np.zeros((2, 2), dtype=np.complex128)
        # self.matmul(a, b, out=out)
        # assert_array_equal(out, tgt, err_msg=msg)

        # test out non-contiguous
        # msg = "out argument with non-contiguous layout"
        # c = np.zeros((2, 2, 2), dtype=np.float)
        # self.matmul(a, b, out=c[..., 0])
        # assert_array_equal(c, tgt, err_msg=msg)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号