Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions LinAlg/identifiers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef IDENTIFIERS_H
#define IDENTIFIERS_H

namespace Identifiers{

struct from{
from(unsigned interval) : interval(interval) {};

unsigned interval;
};

struct to{
to(unsigned interval) : interval(interval) {};

unsigned interval;
};

unsigned* operator, (from from_interval, to to_interval)
{
unsigned* ret = new unsigned[2];

ret[0] = from_interval.interval;
ret[1] = to_interval.interval;

return ret;
}
}

#endif // IDENTIFIERS_H
18 changes: 12 additions & 6 deletions LinAlg/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <cstdlib>
#include <iostream>

#include "identifiers.h"

using namespace Identifiers;

namespace LinAlg {
template<typename Type>
class Matrix
Expand All @@ -33,8 +37,11 @@ namespace LinAlg {
bool isSquare ();

Type& operator() (unsigned row, unsigned column);
Type operator() (unsigned row, unsigned column) const;
void operator() (unsigned row, unsigned column, Type number);
Type operator() (unsigned row, unsigned column) const;

LinAlg::Matrix<Type> operator() (unsigned* row_interval, unsigned column) const;
LinAlg::Matrix<Type> operator() (unsigned row, unsigned* column_interval) const;
LinAlg::Matrix<Type> operator() (unsigned* row_interval, unsigned* column_interval) const;

void operator= (std::string rhs);
LinAlg::Matrix<Type>& operator= (const LinAlg::Matrix<Type>& otherMatrix);
Expand Down Expand Up @@ -71,10 +78,7 @@ namespace LinAlg {

//Should be declared as friend.
template<typename OtherMatrixType>
friend void swap (LinAlg::Matrix<Type>& lhs, LinAlg::Matrix<OtherMatrixType>& rhs) {lhs.swap(rhs);};

//Should be declared as friend.

friend void swap (LinAlg::Matrix<Type>& lhs, LinAlg::Matrix<OtherMatrixType>& rhs) {lhs.swap(rhs);};

private:
void Init (std::string Mat);
Expand Down Expand Up @@ -136,6 +140,8 @@ namespace LinAlg {
template<typename Type>
bool operator!= (const LinAlg::Matrix<Type>& lhs, const LinAlg::Matrix<Type>& rhs) {return !(lhs == rhs);}

unsigned* operator, (from from_interval, to to_interval);

template<typename Type>
void Zeros (LinAlg::Matrix<Type>& Mat);

Expand Down
2 changes: 1 addition & 1 deletion LinAlg/src/linalg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ LinAlg::Matrix<Type> LinAlg::EigenValues(const LinAlg::Matrix<Type> &matrix_to_g
}

return ret;
}
}
74 changes: 72 additions & 2 deletions LinAlg/src/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,79 @@ Type LinAlg::Matrix<Type>::operator() (unsigned row, unsigned column) const
}

template<typename Type>
void LinAlg::Matrix<Type>::operator() (unsigned row, unsigned column, Type number)
LinAlg::Matrix<Type> LinAlg::Matrix<Type>::operator ()(unsigned* row_interval, unsigned* column_interval)const
{
LinAlg::Matrix<Type> Ret;

if(row_interval[0] < row_interval[1]){
if(column_interval[0] < column_interval[1]){
Ret.Init(row_interval[1] - row_interval[0] + 1, column_interval[1] - column_interval[0] + 1);
for(unsigned i = row_interval[0]; i <= row_interval[1]; ++i)
for(unsigned j = column_interval[0]; j <= column_interval[1]; ++j)
Ret.mat[i - row_interval[0]][j - column_interval[0]] = this->mat[i-1][j-1];

}else{
Ret.Init(row_interval[1] - row_interval[0] + 1, column_interval[0] - column_interval[1] + 1);
for(unsigned i = row_interval[0]; i <= row_interval[1]; ++i)
for(unsigned j = column_interval[0]; j >= column_interval[1]; --j)
Ret.mat[i - row_interval[0]][column_interval[0] - j] = this->mat[i-1][j - 1];
}

} else{
if(column_interval[0] < column_interval[1]){
Ret.Init(row_interval[0] - row_interval[1] + 1, column_interval[1] - column_interval[0] + 1);
for(unsigned i = row_interval[0]; i >= row_interval[1]; --i)
for(unsigned j = column_interval[0]; j <= column_interval[1]; ++j)
Ret.mat[row_interval[0] - i][j - column_interval[0]] = this->mat[i-1][j-1];
}else{
Ret.Init(row_interval[0] - row_interval[1] + 1, column_interval[0] - column_interval[1] + 1);
for(unsigned i = row_interval[0]; i >= row_interval[1]; --i)
for(unsigned j = column_interval[0]; j >= column_interval[1]; --j)
Ret.mat[row_interval[0] - i][column_interval[0] - j] = this->mat[i-1][j - 1];
}
}

return Ret;
}

template<typename Type>
LinAlg::Matrix<Type> LinAlg::Matrix<Type>::operator ()(unsigned row, unsigned* column_interval)const
{
LinAlg::Matrix<Type> Ret;


if(column_interval[0] < column_interval[1]){
Ret.Init(1, column_interval[1] - column_interval[0] + 1);
for(unsigned j = column_interval[0]; j <= column_interval[1]; ++j)
Ret.mat[row - 1][j - column_interval[0]] = this->mat[row - 1][j - 1];

}else{
Ret.Init(1, column_interval[0] - column_interval[1] + 1);
for(unsigned j = column_interval[0]; j >= column_interval[1]; --j)
Ret.mat[row - 1][column_interval[0] - j] = this->mat[row - 1][j - 1];
}

return Ret;
}

template<typename Type>
LinAlg::Matrix<Type> LinAlg::Matrix<Type>::operator ()(unsigned* row_interval, unsigned column)const
{
this->Add(row, column, number);
LinAlg::Matrix<Type> Ret;

if(row_interval[0] < row_interval[1]){
Ret.Init(row_interval[1] - row_interval[0] + 1, 1);
for(unsigned i = row_interval[0]; i <= row_interval[1]; ++i)
Ret.mat[i - row_interval[0]][column - 1] = this->mat[i - 1][column - 1];
} else{
unsigned aux = row_interval[0] - row_interval[1] + 1;

Ret.Init(row_interval[0] - row_interval[1] + 1, 1);
for(unsigned i = row_interval[0]; i >= row_interval[1]; --i)
Ret.mat[row_interval[0] - i][column - 1] = this->mat[i - 1][column - 1];
}

return Ret;
}

template<typename Type>
Expand Down