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 test_matrix(self):
     a = numpy.matrix([[3, 4], [100, 200]])
     b = numpy.matrix([[1, 2], [50, 2]])
     d = element_wise_divide(a, b)
     self.assertTrue((d == [[3, 2], [2, 100]]).all())
 def test_long_arrays(self):
     a = numpy.matrix([3, 4, 10, 100, 9])
     b = numpy.matrix([1, 2, 5, 12, 3])
     d = element_wise_divide(a, b)
     self.assertTrue((d == [3, 2, 2, 25/3, 3]).all())
 def test_basic(self):
     a = numpy.matrix([3, 4])
     b = numpy.matrix([1, 2])
     d = element_wise_divide(a, b)
     self.assertTrue((d == [3, 2]).all())