def test_rlstsq_qr_flexible_signature_with_vectors_vv(self, v_s, v_b, fun): hy.assume(len(v_s) != len(v_b)) hy.assume(la.norm(v_s) > 0.) tau = tau_len_vec(v_s, fun) self.assertArrayShapesAre(fun(v_s, v_s), ((), v_s.shape, tau)) with self.assertRaisesRegex(*utn.core_dim_err): fun(v_s, v_b)
def test_rqr_lstsq_flexible_signature_with_vectors_vv(self, v_s, v_b, fun): hy.assume(len(v_s) != len(v_b)) hy.assume(la.norm(v_s) > 0.) _, x_f, tau = fun(v_s, v_s) self.assertArrayShape(gfl.qr_lstsq(x_f, tau, v_s), ()) self.assertArrayShape(gfl.rqr_lstsq(v_s, x_f, tau), ()) with self.assertRaisesRegex(*utn.core_dim_err): gfl.qr_lstsq(x_f, tau, v_b) with self.assertRaisesRegex(*utn.core_dim_err): gfl.rqr_lstsq(v_b, x_f, tau)
def test_rlstsq_qr_flexible_signature_with_vectors_mv(self, arrays, fun): m_sb, m_bs = arrays[:-1] wide = m_sb.shape v_b = hn.core_only(arrays[-1], dims=1) hy.assume(hn.wide(m_sb)) hy.assume(la.norm(v_b) > 0.) tau = m_sb.shape[:-2] + tau_len_vec(v_b, fun) self.assertArrayShapesAre(fun(m_sb, v_b), (wide[:-1], utn.drop(wide), tau)) with self.assertRaisesRegex(*utn.core_dim_err): fun(m_bs, v_b)
def test_rqr_lstsq_flexible_signature_with_vectors_mv(self, arrays, fun): m_sb, m_bs = hn.core_only(*arrays[:-1]) v_s = hn.core_only(arrays[-1], dims=1) wide, tall = [arr.shape[-2:] for arr in arrays[:-1]] hy.assume(hn.wide(m_sb)) hy.assume(la.norm(v_s) > 0.) _, x_f, tau = fun(m_bs, v_s) expect = utn.array_return_shape('(m,n),(n,p)->(m,p)', m_bs, m_sb)[:-1] self.assertArrayShape(gfl.qr_lstsq(x_f, tau, m_sb), expect) self.assertArrayShape(gfl.rqr_lstsq(m_bs, x_f, tau), tall[:-1]) with self.assertRaisesRegex(*utn.core_dim_err): gfl.qr_lstsq(x_f, tau, m_bs) self.assertArrayShape(gfl.rqr_lstsq(v_s, x_f, tau), tall[:-2]) m_sb, m_bs = arrays[:-1] wide, tall = [arr.shape for arr in arrays[:-1]] _, x_f, tau = fun(m_bs, v_s) x_f, tau = unbroadcast_factors(v_s, x_f, tau) self.assertArrayShape(gfl.qr_lstsq(x_f, tau, m_sb), utn.drop(wide)) self.assertArrayShape(gfl.rqr_lstsq(m_bs, x_f, tau), tall[:-1])