#include "matrix_operations.h"
#include "matrix.h"
#include "matrix_alloc.h"
#include "stdio.h"


Matrix matrix_mult(Matrix A, Matrix B)
{
	Matrix C = matrix_alloc(A.rows, B.cols);
	
	for(int i = 0; i < A.rows; i++){
		for(int j = 0; j < B.cols; j++){
			for(int k = 0; k < A.cols; k++){
				C.data[i][j] += A.data[i][k]*B.data[k][j];
			}	
		}
	}	
	return C;
}

Matrix matrix_add(Matrix A, Matrix B)
{
	Matrix C = matrix_alloc(A.rows, B.cols);

	for(int i = 0; i < A.rows; i++){
		for(int j = 0; j < B.cols; j++){
				C.data[i][j] += A.data[i][j]+B.data[i][j];
		}
	}
	return C;
}

void matrix_print(Matrix A)
{
	for(int i = 0; i < A.rows; i++){
		for(int j = 0; j < A.cols; j++){
			printf("%lf ", A.data[i][j]);
		}
		putchar('\n');
	}
}


Matrix matrix_number_product(Matrix A, double num)
{
	Matrix C = matrix_alloc(A.rows, A.cols);
	for(int i = 0; i < C.rows; i++){
		for(int j = 0; j < C.cols; j++)
			C.data[i][j] = C.data[i][j]*num;
	}
	return C;
}
