27 va_start( vl, npassed );
29 for(
int i=0; i<m*n && i<npassed; i++){
30 fElement[i] = va_arg(vl,
double);
38 for(
int i=0; i<ncomp && i<3; i++){
47 for(
int i=0; i<fMN; i++){
48 fElement[i] = other.fElement[i];
58 for(
int i=0; i<fM*fN; i++){
59 fElement[i] = other.fElement[i];
71 fElement = (
double*) std::malloc(fM*fN*
sizeof(
double));
72 for(
int i=0; i<fN*fM; i++){
85 if(i >= 0 && i< fN*fM)
return true;
90 if (i>=0 && i<fM && j>=0 && j<fN){
98 std::cout<<
"QPMatrix::At(1) - Out if index"<<
"["<<i<<
"]"<<std::endl;
106 std::cout<<
"QPMatrix::At(2) - Out if index "<<
"["<<i<<
","<<j<<
"]"<<std::endl;
109 return fElement[i*fN+j];
113 if(fN == other.fN && fM == other.fM)
return true;
118 if(fN == other.fM && fM == other.fN)
return true;
124 std::cout<<
"QPMatrix::operator[](1) - Out if index"<<
"["<<i<<
"]"<<std::endl;
132 std::cout<<
"QPMatrix::operator()(1) - Out if index"<<
"["<<i<<
"]"<<std::endl;
140 std::cout<<
"QPMatrix::operator()(2) - Out if index"<<
"["<<i<<
"]"<<std::endl;
143 return fElement[i*fM+j];
148 std::cout<<
"QPMatrix::Det() - Determinant can be defined only for square matrix "<<
"["<<fM<<
","<<fN<<
"]"<<std::endl;
153 if(fM==1)
return At(0);
156 return At(0,0)*
At(1,1) -
At(0,1)*
At(1,0);
160 for(
int i=0; i<fN; i++){
169 int ii = fN>fM ? fM : fN;
171 for(
int i=0; i<ii; i++){
181 for(
int i=0; i<fM-1; i++){
182 for(
int j=0; j<fN-1; j++){
194 std::cout<<
"QPMatrix::Cofactor() - Cofactor can be defined only for square matrix "<<
"["<<fM<<
","<<fN<<
"]"<<std::endl;
202 std::cout<<
"QPMatrix::Inverse() - Inverse can be defined only for square matrix "<<
"["<<fM<<
","<<fN<<
"]"<<std::endl;
208 if(det<0.0000000001 && det>-0.0000000001 ){
209 std::cout<<
"QPMatrix::Inverse() - Determinant is near zero. No inverse matrix "<<
"["<<det<<
"]"<<std::endl;
214 for(
int i=0; i<fM; i++){
215 for(
int j=0; j<fN; j++){
230 for(
int i=0; i<fM; i++){
231 for(
int j=0; j<fN; j++){
240 for(
int i=0; i<(self.fN*self.fM); i++){
248 for(
int i=0; i<(self.fN*self.fM); i++){
255 if(self.fN != other.fM){
256 std::cout<<
"QPMatrix::operator*()(3) - inner part of 2 matrices are not same : "<<self.fN<<
", "<<other.fM<<std::endl;
260 for(
int i=0; i<(ans.fM); i++){
261 for(
int j=0; j<(ans.fN); j++){
262 for(
int k=0; k<(self.fN); k++){
263 ans(i,j)+= self.
At(i,k) * other.
At(k,j);
272 std::cout<<
"operator+ (QPMatrix&, QPMatrix&) - Not same shape"<<std::endl;
278 int length = self.fN * self.fM;
279 for(
int i=0; i<length; i++){
280 ans[i] = self[i] + other[i];
289 std::cout<<
"operator- (QPMatrix&, QPMatrix&) - Not same shape"<<std::endl;
295 int length = self.fN * self.fM;
296 for(
int i=0; i<length; i++){
297 ans[i] = self[i] - other[i];
306 std::ostringstream anss;
310 for(
int i=0; i<fM; i++){
311 for(
int j=0; j<fN; j++){
312 anss <<
At(i,j) <<
"\t";
316 anss.unsetf(std::ios::fixed);
318 std::string ans = anss.str();
Dense m×n matrix of double with hand-rolled linear algebra.
bool IsTransShape(QPMatrix &other)
~QPMatrix()
Frees the element storage.
QPMatrix Inverse()
Inverse by the adjugate formula .
std::string Print(bool quite=false)
Formats the matrix as tab-separated rows.
double Trace()
Sum of the diagonal elements up to min(m, n).
double Cofactor(const int i, const int j)
Cofactor where is the minor.
QPMatrix & operator=(const QPMatrix &)
Deep copy assignment; reallocates the storage.
double At(int i)
Value of linear element i of the row-major storage.
QPMatrix()
Null matrix: 0×0, no storage.
QPMatrix SubMatrix(const int i, const int j)
Minor matrix: this matrix with row i and column j removed.
bool IsSameShape(QPMatrix &other)
double & operator[](int i)
Reference to linear element i of the row-major storage.
void Freeing()
Releases the element storage.
double Det()
Determinant by recursive Laplace expansion along the first row.
double & operator()(int i)
Same as operator[].
3-component double vector with hand-rolled operations.