#pragma once
#include "sigmoid.h"
#include <iostream>
#include <vector>
using namespace std;

class DenseMatrix
{
    private:
        vector<double> M;
        size_t n;
        size_t m;


    public:
        vector<double> Mult(const vector<double> &x) const
        {
            vector<double> y(n,0);
            for(size_t i = 0; i < n; ++i)   // iterate row
            {
                for(size_t j = 0; j < m; ++j)   // iterate column
                {
                    y[i] += M[i*m + j]*x[j];
                }
            }
            return y;
        }

        vector<double> MultT(const vector<double> &y) const
        {
            vector<double> x(m,0);
            for(size_t j = 0; j < m; ++j)   // iterate column
            {
                for(size_t i = 0; i < n; ++i)   // iterate row
                {
                    x[j] += M[i*m + j]*y[i];
                }
            }
            return x;
        }

        void Print() const
        {
            for(size_t i = 0; i < n; ++i)   // iterate row
            {
                for(size_t j = 0; j < m; ++j)   // iterate column
                {
                    cout << M[i*m + j] << "  ";
                }
                cout << endl;
            }
            cout << endl;
        }


        DenseMatrix(size_t n, size_t m)
        {
            this->n = n;
            this->m = m;
            M = vector<double>(n*m);
            size_t nm = max(n,m);

            for(size_t i = 0; i < n; ++i)   // iterate row
            {
                for(size_t j = 0; j < m; ++j)   // iterate column
                {
                    M[i*m + j] = sigmoid(x_entry(i,nm))*sigmoid(x_entry(j,nm));
                }
            }
        }
};