18 #ifndef _POLYNOMIAL_TESTUTILS_IPP
19 #define _POLYNOMIAL_TESTUTILS_IPP
21 #include "../include/Polynomial.hpp"
22 #include "../include/Matrix.ipp"
29 template <
typename FieldT>
35 for(
size_t i = 0; i < lhs.
size(); ++i){
36 if (lhs[i] != rhs[i]) {
50 auto areSame = [](
double a,
double b)->
bool {
52 return std::fabs(a-b) < double(1e-6);
54 for(
size_t i = 0; i < lhs.
size(); ++i){
55 if (!areSame(lhs[i],rhs[i])) {
68 std::regex matrixDimensionRegex (
"MatDim(\\d+)");
69 std::smatch matrixDimensionMatch;
70 if(!std::regex_search(filename,matrixDimensionMatch,matrixDimensionRegex))
72 throw std::invalid_argument(
"readInputSize: The filename does not have pattern \"MatDim#\" ");
74 std::regex polyDegreeRegex(
"PolyDegree(\\d+)");
75 std::smatch polyDegreeMatch;
76 if(!std::regex_search(filename,polyDegreeMatch,polyDegreeRegex)) {
77 throw std::invalid_argument(
"readInputSize: The filename doesn not have pattern \"PolyDegree#\" ");
79 return std::make_pair(std::stoul(matrixDimensionMatch[1]),std::stoul(polyDegreeMatch[1]));
85 template <
typename FieldT>
98 template<
typename FieldT>
100 if(pmat==
nullptr)
throw std::invalid_argument(
"createMatrixWithPolynomialEnties: Pointer to matrix is null");
101 std::pair<size_t,size_t> matrixDim_PolyDegree_pair =
readInputSize(inputfile);
102 size_t matrixDim=matrixDim_PolyDegree_pair.first;
103 size_t PolyDegree=matrixDim_PolyDegree_pair.second;
107 std::ifstream file (inputfile);
108 if(!file.is_open())
throw std::invalid_argument(
"createMatrixWithPolynomialEntries: Failed to open inputfile");
110 for(
size_t entryNumber =0; entryNumber < matrixDim*matrixDim ; ) {
111 for (
size_t columnNumber=0;columnNumber<matrixDim;++columnNumber) {
114 std::stringstream linestream(line);
117 EntryT ijth_polynomial;
118 for (
size_t i_coef =0; i_coef < PolyDegree+1 ;++i_coef) {
120 getline(linestream,coef,
',');
121 ijth_polynomial.appendTerm(stringToField<FieldT>(coef));
124 (*pmat)(rowNumber,columnNumber)=ijth_polynomial;
132 template <
typename FieldT>
135 std::ifstream file (resultfile);
136 if(!file.is_open())
throw std::invalid_argument(
"readPolynomialFromFile: Failed to open resultfile");
139 while(getline(file,line)) {
144 #endif // _POLYNOMIAL_TESTUTILS_H
void appendTerm(FieldT coeff)
Append new terms by pushing back coefficients.
Polynomial< FieldT > readPolynomialFromFile(const std::string &resultfile)
boost::numeric::ublas::matrix< EntryT > Matrix
Typedef for the main matrix class.
FieldT stringToField(const std::string &s)
Function to convert string to various number types or coef types. Specialize for every supported type...
std::pair< size_t, size_t > readInputSize(const std::string filename)
Function to read the size of matrix and polynomial entries from filename of the input file...
void createMatrixWithPolynomialEntries(const std::string &inputfile, Matrix< Polynomial< FieldT >> *pmat)
Read the input and output files and create the matrix of polynomials.
Contains the definition for the abstract base class which will be used by different multiplication al...
bool operator==(const Polynomial< FieldT > &lhs, const Polynomial< FieldT > &rhs)