#pragma once

#include "./core/omp_config.h"

#include "./utils/vector.h"
#include "./utils/matrix.h"
#include "./utils/random.h"


namespace neural_networks{

	template <typename T>
	struct Dense_Layer{

			utils::Matrix<T> _inputs;
			utils::Matrix<T> weights;
			utils::Vector<T> biases;
			utils::Matrix<T> outputs;

			utils::Matrix<T> dweights;
			utils::Vector<T> dbiases;
			utils::Matrix<T> dinputs;

			
			// Default Constructor
			Dense_Layer() = default;

			// Constructor
	    	Dense_Layer(const uint64_t n_inputs, const uint64_t n_neurons){
	        	
	        	weights.random(n_inputs, n_neurons, -1, 1);
	        	biases.resize(n_neurons, T{0});
	        	
	        }

	        void forward(const utils::Matrix<T>& inputs){
	        	_inputs = inputs;
			    outputs = numerics::matadd(numerics::matmul_auto(inputs, weights), biases, "row");
	        }

	        void backward(const utils::Matrix<T>& dvalues){
	        	// Gradients on parameters
	        	dweights  = numerics::matmul(numerics::transpose(_inputs), dvalues);
	        	dbiases = numerics::matsum(dvalues, "row");
	        	//Gradient on values
	        	dinputs = numerics::matmul(dvalues, numerics::transpose(weights));

	        }

	};



} // end namespace neural_networks