示例#1
0
 def _create_guess(self):
     if not hasattr(self, "_matD"):
         self._build_interim_matricies()
     ret = (matops.create_random(matops.count_rows(self._matb), True)
            if self._guess_source == IterativeInitialGuess.RANDOM_MATRIX
            else matops.create_zeros(matops.count_rows(self._matb)))
     ret = matops.reshape(ret, (-1, 1))
     return ret
示例#2
0
def _assert_expected_matrix_sizes(directory, exp_size):
    def assert_vector(vector):
        assert matops.is_vector(vector)
        if matops.is_vvector(vector):
            assert matops.count_rows(vector) == exp_size
        else:
            assert matops.count_columns(vector) == exp_size

    # if not path.isdir(directory):
    if directory is None:
        # directory doesn't exist, we weren't supposed to do this assert so
        # just silently continue
        return

    if exp_size is None:
        # size doesn't exist, we weren't supposed to do this assert so
        # just silently continue
        return

    items = matops.load_files(directory, None, False)
    print(items)

    assert matops.is_square(items["matA"])
    assert matops.count_rows(items["matA"]) == exp_size
    assert_vector(items["matb"])
    assert_vector(items["matsoln"])
    if "omega" in items:
        assert isinstance(items["omega"], float)
def test_count_rows(name, data, exception):
    inp = create_matrix(getattr(data.input, "mat", None))

    with exception:
        act = matops.count_rows(inp)

        exp = data.expect

        assert act == exp
示例#4
0
    def _create_crout_lu_factors(self):
        size = matops.count_rows(self._matA)
        matL = matops.create_identity(size)
        matU = matops.create_identity(size)

        for index in range(size):
            matL = self._calculate_l_column(matL, matU, index, size)
            matU = self._calculate_u_row(matL, matU, index, size)

        return (matL, matU)
示例#5
0
 def _create_guess(self):
     if not hasattr(self, "_matC"):
         self._build_interim_matricies()
     rows = matops.count_rows(self._matb)
     creators = {
         IterativeInitialGuess.MATRIX_C: lambda: matops.deepcopy(self._matC),
         IterativeInitialGuess.RANDOM_MATRIX: lambda: matops.create_random(
             rows, True
         ),
         IterativeInitialGuess.MATRIX_OF_ZEROS: lambda: matops.create_zeros(rows, 1),
     }
     return creators.get(self._guess_source)()
示例#6
0
 def assert_vector(vector):
     assert matops.is_vector(vector)
     if matops.is_vvector(vector):
         assert matops.count_rows(vector) == exp_size
     else:
         assert matops.count_columns(vector) == exp_size