Ejemplo n.º 1
0
    def test_normalize(self):
        df_target = bu.col_matrix(v=dict(x=1, y=1))
        df_true = bu.col_matrix(v=dict(x=1/np.sqrt(2), y=1/np.sqrt(2)))

        df_res = bu.normalize(df_target)

        self.assertTrue(df_true.equals(df_res))
Ejemplo n.º 2
0
    def setUp(self):
        self.df_basis = \
            bu.col_matrix(
                v1 = dict(x=1, y=1),
                v2 = dict(x=1, y=-1)
            )

        self.df_basis_ill = \
            bu.col_matrix(
                v1 = dict(x=1, y=1),
                v2 = dict(x=1, y=1 - 1e-9)
            )

        self.df_b1 = bu.col_matrix(
            v = dict(x=1., y=1.)
        ).sort_values("rowname").reset_index(drop=True)

        self.df_b1_ill = bu.col_matrix(
            v = dict(x=1., y=1.),
            w = dict(x=1., y=1.)
        ).sort_values("rowname").reset_index(drop=True)

        self.df_x1 = bu.col_matrix(
            v = dict(v1=1., v2=0.)
        ).sort_values("rowname").reset_index(drop=True)
Ejemplo n.º 3
0
    def test_add_col(self):
        df_ful = bu.col_matrix(
            rho = dict(M=1, L=-3),
            U   = dict(L=1, T=-1),
            D   = dict(L=1)
        ).sort_values("rowname") \
         .reset_index(drop=True)

        df_sub = bu.col_matrix(rho=dict(M=1, L=-3), U=dict(L=1, T=-1))

        df_res = bu.add_col(df_sub, D=dict(L=1)) \
                   .sort_values("rowname") \
                   .reset_index(drop=True)

        pd.testing.assert_frame_equal(df_ful,
                                      df_res,
                                      check_exact=False,
                                      check_dtype=False,
                                      check_column_type=False)

        with self.assertRaises(ValueError):
            bu.add_col(pd.DataFrame(), D=dict(M=1))

        with self.assertWarns(Warning):
            bu.add_col(df_sub, D=[0, 1, 0])
Ejemplo n.º 4
0
    def test_complete(self):
        df_dim = bu.col_matrix(
            rho = dict(M=1, L=-3),
            U   = dict(L=1, T=-1),
            D   = dict(L=1),
            mu  = dict(M=1, L=-1, T=-1),
            eps = dict(L=1)
        )
        df = bu.col_matrix(Re=dict(rho=1, U=1, D=1, mu=-1))
        df_res = bu.complete(df, df_dim)
        df_true = bu.col_matrix(Re=dict(rho=1.0, U=1.0, D=1.0, mu=-1.0, eps=0.0))

        # Original weights not scrambled
        self.assertTrue(
            df_res[["rowname", "Re"]]
            .sort_values("rowname")
            .reset_index(drop=True)
            .equals(
                df_true
                .sort_values("rowname")
                .reset_index(drop=True)
            )
        )
        # Given basis dimensionless
        self.assertTrue(np.all(
            np.abs(bu.inner(df_dim, df_res).drop("rowname", axis=1).values) < 1e-6
        ))
Ejemplo n.º 5
0
 def setUp(self):
     self.df_dim = bu.col_matrix(
         x = dict(M=1),
         y = dict(M=1)
     )
     self.df_pi = bu.col_matrix(
         pi0 = dict(x=-1 / np.sqrt(2), y=+1 / np.sqrt(2))
     )
Ejemplo n.º 6
0
    def test_col_matrix(self):
        df_dim = bu.col_matrix(
            rho=dict(M=1, L=-3),
            U=dict(L=1, T=-1),
            D=dict(L=1),
            mu=dict(M=1, L=-1, T=-1),
            eps=dict(L=1)).sort_values("rowname").reset_index(drop=True)

        self.assertTrue(self.df_dim[df_dim.columns].equals(df_dim))
Ejemplo n.º 7
0
    def test_nondim(self):
        df_dim = bu.row_matrix(L = dict(u=1, v=1))
        df = bu.col_matrix(q = dict(L=1))
        df_res = bu.nondim(df, df_dim) \
                   .sort_values("rowname") \
                   .reset_index(drop=True)

        df_true = bu.col_matrix(q = dict(u=-0.5, v=-0.5)) \
                    .sort_values("rowname") \
                    .reset_index(drop=True)

        pd.testing.assert_frame_equal(
            df_res,
            df_true,
            check_exact=False
        )

        with self.assertRaises(ValueError):
            bu.nondim(pd.DataFrame(), df_dim)
        with self.assertRaises(ValueError):
            bu.nondim(df, pd.DataFrame())
        with self.assertRaises(ValueError):
            bu.nondim(bu.col_matrix(q = dict(T=1)), df_dim)
Ejemplo n.º 8
0
    def test_inner(self):
        df = bu.col_matrix(
            v = dict(x=+1, y=+1),
            w = dict(x=-1, y=+1)
        )

        # Full weights
        df_w1 = bu.col_matrix(z = dict(v=1, w=1))
        df_r1 = bu.inner(df, df_w1)
        df_t1 = bu.col_matrix(z = dict(x=0, y=2))

        # Missing weights
        df_w2 = bu.col_matrix(z = dict(v=1))
        df_r2 = bu.inner(df, df_w2)
        df_t2 = bu.col_matrix(z = dict(x=+1, y=+1))

        pd.testing.assert_frame_equal(
            df_r1,
            df_t1,
            check_exact=False
        )

        pd.testing.assert_frame_equal(
            df_r2,
            df_t2,
            check_exact=False
        )

        with self.assertRaises(ValueError):
            bu.inner(pd.DataFrame(), df_w1)

        with self.assertRaises(ValueError):
            bu.inner(df, pd.DataFrame())

        with self.assertRaises(ValueError):
            bu.inner(bu.col_matrix(w=dict(x=1, y=1)), df_w1)
Ejemplo n.º 9
0
    def test_rowname(self):
        df_tmp = bu.col_matrix(x=dict(a=1), rowname="foo")

        df_ref = pd.DataFrame({"foo": ["a"], "x": [1]})

        self.assertTrue(df_ref.equals(df_tmp))
Ejemplo n.º 10
0
    def setUp(self):
        self.df = bu.col_matrix(v = dict(x=+1, y=+1))

        self.df_v1 = bu.col_matrix(w = dict(x=+1, y=-1))
        self.df_v2 = bu.col_matrix(w = dict(x=+1, y=+1))
Ejemplo n.º 11
0
    def test_rank(self):
        df_low = bu.col_matrix(v1=dict(x=1, y=1), v2=dict(x=2, y=2))
        df_full = bu.col_matrix(v1=dict(x=1, y=1), v2=dict(x=1, y=0))

        self.assertTrue(bu.rank(df_low) == 1)
        self.assertTrue(bu.rank(df_full) == 2)