I am working on a library (in my spare time) that I hope to open source soon. One of the elements in the library is a method for calculating the determinant of a given input matrix. For this, I have created a sub-project called "LUDecomposition" because I will use LU Decomposition in order to calculate the Determinant.
Now, my best approach was:
Have a class "LUDecomposition" which calculates the LU Decomposition of an input signal
Have another class "Determinant" which uses the
LUDecomposition
for the calculate and then returns this.
Currently, it is contained in one file, and, "Determinant" is inheriting from "LUDecompostion" but it does not look right, since, the relationship makes no sense. LUDecomposition
-> CAN BE/IS A
Determinant
But I cannot see any other option other than having a method inside the "LU Decomposition" and returning it from there. BUT the only problem is that, what if I did not want the users of the library/interface to know how the determinant is calculated?
#include <iostream>
#include <vector>
typedef std::vector<double> Vector;
namespace LUDecomposition {
class LUDecompostion {
public:
LUDecompostion();
template<typename Inverse>
LUDecompostion(Inverse begin, Inverse end)
: matrix_input(begin, end)
{
const size_t matrix_size = matrix_input.size();
this->upper.resize(matrix_size, std::vector<double>(matrix_size));
this->lower.resize(matrix_size, std::vector<double>(matrix_size));
Solve();
}
void Solve();
std::vector<Vector> getUpper();
std::vector<Vector> getLower();
protected:
std::vector<Vector> matrix_input;
std::vector<Vector> upper;
std::vector<Vector> lower;
};
/*
Class Determinant
*/
class Determinant : public LUDecomposition {
public:
Determinant();
template<typename Inverse>
Determinant(Inverse begin, Inverse end)
: matrix_input(begin, end)
{
/*
TO DO
TO DO
TO DO
*/
}
};
}
EDIT:
namespace LUP
{
class LUPDecomposition {
public:
LUPDecomposition()
{
}
string getLower()
{
return "This is the lower matrix";
}
string getUpper()
{
return "This is the upper matrix";
}
protected:
std::vector<double> data;
};
LUPDecomposition FactorMatrix()
{
return LUPDecomposition();
}
}