Exemple #1
0
    def test_functions_solve(self, arrays):
        m_ss, m_sb, m_bs = arrays[:-1]
        v_s = hn.core_only(arrays[-1], dims=1)
        smol, wide, tall = [arr.shape for arr in arrays[:-1]]
        hy.assume(hn.all_well_behaved(m_ss))

        # with self.subTest('solve'):
        expect = gf.return_shape('(a,b),(b,c)->(a,c)', smol, wide)
        self.assertArrayShape(la.solve(m_ss, m_sb), expect)
        self.assertArrayShape(la.solve(m_ss, v_s), smol[:-1])
        # with self.subTest('rsolve'):
        expect = gf.return_shape('(a,b),(b,c)->(a,c)', tall, smol)
        self.assertArrayShape(la.rsolve(m_bs, m_ss), expect)
        self.assertArrayShape(la.rsolve(v_s, m_ss), smol[:-1])
Exemple #2
0
    def test_functions_matrdiv(self, arrays):
        m_ss, m_sb, m_bs = arrays[:-2]
        v_s, v_b = hn.core_only(*arrays[-2:], dims=1)
        smol, wide, tall = [arr.shape for arr in arrays[:-2]]
        hy.assume(hn.all_well_behaved(m_ss))
        hy.assume(hn.wide(m_sb))

        # with self.subTest('rsolve'):
        expect = gf.return_shape('(a,b),(c,b)->(a,c)', tall, smol)
        self.assertArrayShape(la.matrdiv(m_bs, m_ss), expect)
        self.assertArrayShape(la.matrdiv(v_s, m_ss), smol[:-1])
        # with self.subTest('rlstsq'):
        expect = gf.return_shape('(a,b),(c,b)->(a,c)', smol, tall)
        self.assertArrayShape(la.matrdiv(m_ss, m_bs), expect)
        self.assertArrayShape(la.matrdiv(v_b, m_sb), wide[:-1])
        self.assertArrayShape(la.matrdiv(m_ss, v_s), smol[:-1])
        self.assertArrayShape(la.matrdiv(v_s, m_bs), tall[:-1])
Exemple #3
0
    def test_functions_matmul(self, arrays):
        m_sb, m_bs = arrays[:-2]
        v_s, v_b = hn.core_only(*arrays[-2:], dims=1)
        wide, tall = [arr.shape for arr in arrays[:-2]]

        # with self.subTest('matmul'):
        expect = gf.return_shape('(a,b),(b,c)->(a,c)', tall, wide)
        self.assertArrayShape(la.matmul(m_bs, m_sb), expect)
        self.assertArrayShape(la.matmul(m_bs, v_s), tall[:-1])
        self.assertArrayShape(la.matmul(v_b, m_bs), utn.drop(tall))
        self.assertArrayShape(la.matmul(v_s, v_s), ())
        # with self.subTest('rmatmul'):
        expect = gf.return_shape('(a,b),(b,c)->(a,c)', wide, tall)
        self.assertArrayShape(gf.rmatmul(m_bs, m_sb), expect)
        self.assertArrayShape(gf.rmatmul(m_sb, v_s), utn.drop(wide))
        self.assertArrayShape(gf.rmatmul(v_b, m_sb), wide[:-1])
        self.assertArrayShape(gf.rmatmul(v_b, v_b), ())
Exemple #4
0
    def test_functions_matldiv(self, arrays):
        m_ss, m_sb, m_bb, m_bs = arrays[:-1]
        v_s = hn.core_only(arrays[-1], dims=1)
        smol, wide, big, tall = [arr.shape for arr in arrays[:-1]]
        hy.assume(hn.all_well_behaved(m_ss))
        hy.assume(hn.wide(m_sb))

        # with self.subTest('solve'):
        expect = gf.return_shape('(a,b),(a,c)->(b,c)', smol, wide)
        self.assertArrayShape(la.matldiv(m_ss, m_sb), expect)
        self.assertArrayShape(la.matldiv(m_ss, v_s), smol[:-1])
        # with self.subTest('lstsq'):
        expect = gf.return_shape('(a,b),(a,c)->(b,c)', tall, big)
        self.assertArrayShape(la.matldiv(m_bs, m_bb), expect)
        expect = gf.return_shape('(a,b),(a,c)->(b,c)', wide, smol)
        self.assertArrayShape(la.matldiv(m_sb, m_ss), expect)
        self.assertArrayShape(la.matldiv(m_sb, v_s), utn.drop(wide))
        self.assertArrayShape(la.matldiv(v_s, m_ss), smol[:-1])
Exemple #5
0
    def test_functions_lstsq(self, arrays):
        m_ss, m_sb, m_bb, m_bs = arrays[:-2]
        v_s, v_b = hn.core_only(*arrays[-2:], dims=1)
        smol, wide, big, tall = [arr.shape for arr in arrays[:-2]]

        # with self.subTest('lstsq'):
        expect = gf.return_shape('(a,b),(a,c)->(b,c)', tall, big)
        self.assertArrayShape(la.lstsq(m_bs, m_bb), expect)
        expect = gf.return_shape('(a,b),(a,c)->(b,c)', wide, smol)
        self.assertArrayShape(la.lstsq(m_sb, m_ss), expect)
        self.assertArrayShape(la.lstsq(m_sb, v_s), utn.drop(wide))
        self.assertArrayShape(la.lstsq(v_s, m_ss), smol[:-1])
        # with self.subTest('rlstsq'):
        expect = gf.return_shape('(a,b),(c,b)->(a,c)', smol, tall)
        self.assertArrayShape(la.rlstsq(m_ss, m_bs), expect)
        expect = gf.return_shape('(a,b),(c,b)->(a,c)', big, wide)
        self.assertArrayShape(la.rlstsq(m_bb, m_sb), expect)
        self.assertArrayShape(la.rlstsq(v_b, m_sb), wide[:-1])
        self.assertArrayShape(la.rlstsq(m_ss, v_s), smol[:-1])
        self.assertArrayShape(la.rlstsq(v_s, m_bs), tall[:-1])