/*
 *
 */

#include "iostream"

#define Y_SIZE 3
double* multiply( double ivec[], int N, double mtx[][Y_SIZE] );


int main() {
	int Nx = 4;

	double ivec[Nx] = {1, 2, 50, 3.141517181920};
	double mtx[Nx][Y_SIZE] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}};

	// print vector
	std::cout << "Vector = ";
	std::cout << "[ ";
	for ( int i = 0; i < Nx; i++){
		std::cout << ivec[i] << ", " ;
	}
	std::cout << "]" << std::endl;

	// print matrix
	std::cout << "Matrix = ";
	std::cout << "[";
	for ( int i = 0; i < Nx; i++ ){
		std::cout << "[ ";
		for ( int j = 0; j < Y_SIZE; j++ ){
			std::cout << mtx[i][j] << ", " ;
		}
		std::cout << "]," << std::endl;
	}
	std::cout << "]" << std::endl;




	double * nvec = multiply( ivec, Nx, mtx );


	// print new vector
	std::cout << "Result = ";
	std::cout << "[ ";
	for ( int i = 0; i < Y_SIZE; i++){
		std::cout << nvec[i] << ", ";
	}
	std::cout << "]" << std::endl;
	delete nvec;
	
	// print the matrix as it is stored in memory
	std::cout << "In-Memory Matrix = ";
	std::cout << "[" << std::endl;

	for ( int i = 0; i < Nx*Y_SIZE; i++ ){
		std::cout << mtx[0][i] << ", ";
	}
	std::cout << std::endl; 
	std::cout << "]" << std::endl;

}


double* multiply( double ivec[], int N, double mtx[][Y_SIZE] ){
	//allocate the new vector of length N
	double * nvec = new double[Y_SIZE];

	for ( int j = 0; j < Y_SIZE; j++ ){
		for ( int i = 0; i < N; i++ ){
			nvec[j] += ivec[i]*mtx[i][j];
		}

	}

	return nvec;
}
