def test_simple_case(self):
        output = run_ras(self.row_sums, self.column_sums)
        r = get_row_sum(output)
        c = get_col_sum(output)

        self.assertTrue((get_row_sum(output) == self.row_sums).all())
        self.assertTrue((get_col_sum(output) == self.column_sums).all())
def run_model(consumption: numpy.matrix, production: numpy.matrix,
              emissions: numpy.matrix, final_demand: numpy.matrix=None) -> numpy.matrix:
    """
    :param consumption: U
    :param production: V
    :param emissions: e
    :return:
    """
    i = numpy.identity(len(consumption))

    q = get_row_sum(production.source_data.elements)
    g = get_col_sum(production.source_data.elements)

    if final_demand is None:
        y = get_row_sum(consumption.source_data.elements)
    else:
        y = final_demand

    b = matrix_divide(consumption.source_data.elements, diagonal(g))
    d = matrix_divide(production.source_data.elements, diagonal(q))

    a = matrix_multiply(b, d)

    money_part = matrix_multiply(inv(i - a), y)

    return element_wise_divide(emissions.source_data.elements, money_part)
 def _get_row_and_column_sums(m: numpy.matrix):
     just_numbers = TotalsOnlyDataSource._remove_cs_and_make_elements_float(m)
     row_sums = matrix_functions.get_row_sum(just_numbers.elements.astype(float))
     column_sums = matrix_functions.get_col_sum(just_numbers.elements.astype(float))
     return row_sums, column_sums
 def test_matrix_col_sum(self):
     m = numpy.matrix([[1, 4], [2, 6]])
     rs = get_col_sum(m)
     self.assertTrue((rs == [3, 10]).all())
 def test_vector_col_sum(self):
     m = numpy.matrix([1, 2, 4])
     rs = get_col_sum(m)
     self.assertTrue((rs == [1, 2, 4]).all())
 def test_single_element_col_sum(self):
     m = numpy.matrix([1])
     rs = get_col_sum(m)
     self.assertTrue((rs == [1]).all())
 def test_empty_matrix_col_sum(self):
     m = numpy.matrix([])
     rs = get_col_sum(m)
     self.assertTrue((rs == []).all())
 def test_type_col_sum(self):
     m = numpy.matrix([1])
     self.assertIs(type(get_col_sum(m)), numpy.matrix)
 def setUp(self):
     self.matrix = numpy.matrix([[1, 2], [3, 4]])
     self.row_sums = get_row_sum(self.matrix)
     self.column_sums = get_col_sum(self.matrix)