Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer, es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Ein Anmelden über dieses erzeugt ein neues Konto. Das alte Konto ist über den Reiter "Standard" erreichbar. Die Administratoren

Dear Gitlab user, it is now possible to log in to our service using the ZIH login/LDAP. Logging in via this will create a new account. The old account can be accessed via the "Standard" tab. The administrators

Commit af04434c authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

MatrixVector corrected

parent d35ba5ec
...@@ -685,6 +685,11 @@ INSTALL(FILES ${HEADERS} ...@@ -685,6 +685,11 @@ INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/traits/) DESTINATION include/amdis/traits/)
list(APPEND deb_add_dirs "include/amdis/traits") list(APPEND deb_add_dirs "include/amdis/traits")
FILE(GLOB HEADERS "${SOURCE_DIR}/utility/*.h*")
INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/utility/)
list(APPEND deb_add_dirs "include/amdis/utility")
FILE(GLOB HEADERS "${SOURCE_DIR}/time/*.h") FILE(GLOB HEADERS "${SOURCE_DIR}/time/*.h")
INSTALL(FILES ${HEADERS} INSTALL(FILES ${HEADERS}
DESTINATION include/amdis/time/) DESTINATION include/amdis/time/)
......
...@@ -486,7 +486,7 @@ namespace AMDiS { ...@@ -486,7 +486,7 @@ namespace AMDiS {
elInfo2->worldToCoord(worldVec, &coords2); elInfo2->worldToCoord(worldVec, &coords2);
bool isPositive = true; bool isPositive = true;
for (int j = 0; j < coords2.size(); j++) { for (int j = 0; j < coords2.getSize(); j++) {
if (coords2[j] < -0.00001) { if (coords2[j] < -0.00001) {
isPositive = false; isPositive = false;
break; break;
......
...@@ -215,8 +215,8 @@ namespace AMDiS { ...@@ -215,8 +215,8 @@ namespace AMDiS {
inline void getGrdLambda(mtl::dense2D<double>& grd_lam) inline void getGrdLambda(mtl::dense2D<double>& grd_lam)
{ {
grd_lam.change_dim(grdLambda.size(), Global::getGeo(WORLD)); grd_lam.change_dim(grdLambda.getSize(), Global::getGeo(WORLD));
for (size_t i = 0; i < static_cast<size_t>(grdLambda.size()); i++) for (size_t i = 0; i < static_cast<size_t>(grdLambda.getSize()); i++)
for (size_t j = 0; j < static_cast<size_t>(Global::getGeo(WORLD)); j++) for (size_t j = 0; j < static_cast<size_t>(Global::getGeo(WORLD)); j++)
grd_lam(i,j) = grd_lam[i][j]; grd_lam(i,j) = grd_lam[i][j];
} }
......
...@@ -53,6 +53,8 @@ namespace AMDiS { ...@@ -53,6 +53,8 @@ namespace AMDiS {
template<typename T,GeoIndex d> template<typename T,GeoIndex d>
class FixVec : public Vector<T> class FixVec : public Vector<T>
{ {
typedef FixVec self;
typedef Vector<T> super;
public: public:
/// Constructor without initialisation. initType must be NO_INIT. If dim is /// Constructor without initialisation. initType must be NO_INIT. If dim is
...@@ -80,6 +82,10 @@ namespace AMDiS { ...@@ -80,6 +82,10 @@ namespace AMDiS {
TEST_EXIT_DBG(initType == DEFAULT_VALUE)("wrong initType or wrong initializer\n"); TEST_EXIT_DBG(initType == DEFAULT_VALUE)("wrong initType or wrong initializer\n");
this->set(ini); this->set(ini);
} }
FixVec(self const& other)
: super(other)
{ }
/// Initialisation for dim. /// Initialisation for dim.
inline void init(int dim) inline void init(int dim)
...@@ -94,10 +100,10 @@ namespace AMDiS { ...@@ -94,10 +100,10 @@ namespace AMDiS {
} }
/// Returns the \ref size_ of the FixVec. /// Returns the \ref size_ of the FixVec.
inline int size() const // inline int size() const
{ // {
return this->getSize(); // return this->getSize();
} // }
protected: protected:
/// Determines needed vector size. /// Determines needed vector size.
...@@ -178,7 +184,7 @@ namespace AMDiS { ...@@ -178,7 +184,7 @@ namespace AMDiS {
} }
/// Destructor /// Destructor
virtual ~VectorOfFixVecs() ~VectorOfFixVecs()
{ {
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
delete vec[i]; delete vec[i];
...@@ -274,7 +280,7 @@ namespace AMDiS { ...@@ -274,7 +280,7 @@ namespace AMDiS {
} }
/// destructor /// destructor
virtual ~MatrixOfFixVecs() ~MatrixOfFixVecs()
{ {
for (VectorOfFixVecs<FixVecType>** i = &vec[0]; i < &vec[rows]; i++) for (VectorOfFixVecs<FixVecType>** i = &vec[0]; i < &vec[rows]; i++)
delete *i; delete *i;
...@@ -417,18 +423,19 @@ namespace AMDiS { ...@@ -417,18 +423,19 @@ namespace AMDiS {
{} {}
/// Copy assignement operator /// Copy assignement operator
self& operator=(self other) // self& operator=(self const& other)
{ // {
swap(*this, other); // assert( Global::getGeo(WORLD) == other.getSize() );
return *this; // this->setValues(other.getValArray());
} // return *this;
// }
/// Assignement operator /// Assignement operator
template <typename S> template <typename S>
self& operator=(const Vector<S>& other) self& operator=(const Vector<S>& other)
{ {
TEST_EXIT_DBG( other.getSize() == Global::getGeo(WORLD) ) TEST_EXIT_DBG( other.getSize() == this->size )
("Wrong dimensions in assignment.\n"); ("Wrong dimensions in assignment.\n");
this->setValues(other.getValArray()); this->setValues(other.getValArray());
return *this; return *this;
...@@ -503,26 +510,27 @@ namespace AMDiS { ...@@ -503,26 +510,27 @@ namespace AMDiS {
{ } { }
/// Copy assignment operator /// Copy assignment operator
self& operator=(self other) // self& operator=(self other)
{ // {
swap(*this, other); // swap(*this, other);
return *this; // return *this;
} // }
/// Assignment operator /// Assignment operator
template <typename S> template <typename S>
self& operator=(const Matrix<S>& other) self& operator=(const Matrix<S>& other)
{ {
TEST_EXIT_DBG( other.getNumOfRows() == Global::getGeo(WORLD) && TEST_EXIT_DBG( this->size == other.getSize() &&
other.getNumOfCols() == Global::getGeo(WORLD) ) this->rows == other.getNumRows() &&
("Wrong dimensions in assignment.\n"); this->cols == other.getNumCols() )
("Wrong dimensions in assignment.\n");
this->setValues(other.getValArray()); this->setValues(other.getValArray());
return *this; return *this;
} }
/// Assignment operator for scalars /// Assignment operator for scalars
template <typename S> template <typename S>
typename enable_if<boost::is_convertible<S, T>, WorldMatrix<T> >::type & typename enable_if<boost::is_convertible<S, T>, self>::type &
operator=(S value) operator=(S value)
{ {
this->set(value); this->set(value);
......
...@@ -87,8 +87,8 @@ namespace AMDiS { ...@@ -87,8 +87,8 @@ namespace AMDiS {
{ {
FUNCNAME_DBG("WorldMatrix<T>::vecProduct()"); FUNCNAME_DBG("WorldMatrix<T>::vecProduct()");
TEST_EXIT_DBG(v1.getSize() == v2.getSize())("invalid size 1\n"); TEST_EXIT_DBG(v1.getSize() == v2.getSize())("size(v1) != size(v2), %d != %d\n", v1.getSize(), v2.getSize());
TEST_EXIT_DBG(v1.getSize() == this->getSize())("invalid size 2\n"); TEST_EXIT_DBG(v1.getSize() == this->getNumRows())("size(v1) != num_rows(this), %d != %d\n", v1.getSize(), this->getNumRows());
T *thisIt = this->begin(); T *thisIt = this->begin();
......
...@@ -61,7 +61,7 @@ namespace AMDiS { ...@@ -61,7 +61,7 @@ namespace AMDiS {
FUNCNAME("Msg::wait()"); FUNCNAME("Msg::wait()");
if (w) { if (w) {
std::string line; char line;
MSG("wait for <enter> ..."); MSG("wait for <enter> ...");
std::cin >> line; std::cin >> line;
// char* result = fgets(line, 9, stdin); // char* result = fgets(line, 9, stdin);
......
...@@ -361,7 +361,7 @@ namespace AMDiS { ...@@ -361,7 +361,7 @@ namespace AMDiS {
/// function name nn for message output via MSG, WARNING, ... /// function name nn for message output via MSG, WARNING, ...
#define FUNCNAME(nn) const char *funcName; funcName = nn; #define FUNCNAME(nn) const char *funcName; funcName = nn;
#if (DEBUG == 0) #ifdef NDEBUG
#define FUNCNAME_DBG(nn) #define FUNCNAME_DBG(nn)
#else #else
#define FUNCNAME_DBG(nn) const char *funcName; funcName = nn; #define FUNCNAME_DBG(nn) const char *funcName; funcName = nn;
...@@ -386,18 +386,18 @@ namespace AMDiS { ...@@ -386,18 +386,18 @@ namespace AMDiS {
#define TEST_EXIT(test) if ((test));else ERROR_EXIT #define TEST_EXIT(test) if ((test));else ERROR_EXIT
/// In debug mode, it corresponds to ERROR_EXIT, otherwise it is noop. /// In debug mode, it corresponds to ERROR_EXIT, otherwise it is noop.
#if (DEBUG == 0) #ifdef NDEBUG
#define TEST_EXIT_DBG(test) if (false) Msg::catch_error_exit #define TEST_EXIT_DBG(test) if (false) Msg::catch_error_exit
#define DBG_VAR(var) #define DBG_VAR(var)
#else #else
#define TEST_EXIT_DBG(test) if ((test));else ERROR_EXIT #define TEST_EXIT_DBG(test) if ((test));else ERROR_EXIT
#define DBG_VAR(var) var #define DBG_VAR(var) var
#endif #endif
/// prints a message /// prints a message
#define MSG Msg::print_funcname(funcName), Msg::print #define MSG Msg::print_funcname(funcName), Msg::print
#if (DEBUG == 0) #ifdef NDEBUG
#define MSG_DBG #define MSG_DBG
#else #else
#define MSG_DBG Msg::print_funcname(funcName), Msg::print #define MSG_DBG Msg::print_funcname(funcName), Msg::print
......
...@@ -56,31 +56,11 @@ namespace AMDiS { ...@@ -56,31 +56,11 @@ namespace AMDiS {
{ {
setValues(other.valArray); setValues(other.valArray);
} }
/// Copy constructor for other of different value_type
// TODO: notwendig?
// template <typename S>
// Vector(Vector<S> const& rhs)
// : Serializable(),
// size(rhs.getSize()),
// valArray(size ? new T[size] : NULL)
// {
// setValues(rhs.valArray);
// }
// #if HAS_RVALUE_REFERENCES
// /// move constructor
// Vector(self&& other)
// : Vector()
// {
// swap(*this, other);
// }
// #endif
/// Destructor. /// Destructor.
virtual ~Vector() ~Vector()
{ {
if (valArray != NULL) { if (valArray) {
delete [] valArray; delete [] valArray;
valArray = NULL; valArray = NULL;
} }
...@@ -95,7 +75,7 @@ namespace AMDiS { ...@@ -95,7 +75,7 @@ namespace AMDiS {
inline void resize(int s) inline void resize(int s)
{ {
if (size != s && s > 0) { if (size != s && s > 0) {
if (valArray != NULL) if (valArray)
delete [] valArray; delete [] valArray;
valArray = new T[s]; valArray = new T[s];
size = s; size = s;
...@@ -103,24 +83,9 @@ namespace AMDiS { ...@@ -103,24 +83,9 @@ namespace AMDiS {
} }
/// Assignement operator /// Assignement operator
template <typename S>
typename disable_if< boost::is_same<S, T>, self >::type &
operator=(Vector<S> const& other)
{
assert( size == other.getSize() );
// resize(other.getSize());
setValues(other.getValArray());
return *this;
}
/// copy assignment operator
// self& operator=(self other)
// {
// swap(*this, other);
self& operator=(self const& other) self& operator=(self const& other)
{ {
assert( size == other.getSize() ); resize( other.getSize() );
setValues(other.getValArray()); setValues(other.getValArray());
return *this; return *this;
} }
...@@ -140,73 +105,33 @@ namespace AMDiS { ...@@ -140,73 +105,33 @@ namespace AMDiS {
setValues(vec); setValues(vec);
return *this; return *this;
} }
/// A swap function for Vector, used in the Copy-and-swap idiom
// need non-templated arguments in order to eliminate a friend declaration warning in gcc
friend void swap(Vector& first, Vector& second)
{
using std::swap; // enable ADL
swap(first.size, second.size);
swap(first.valArray, second.valArray);
}
/// Sets all entries to scal. /// Sets all entries to scal.
template <typename S> template <typename S>
typename enable_if< boost::is_convertible<S, T> >::type typename enable_if< boost::is_convertible<S, T> >::type
set(S value) set(S value)
{ {
for (T *thisIt = this->begin(); thisIt != this->end(); ++thisIt) std::fill(begin(), end(), value);
*thisIt = value;
// std::fill(begin(), end(), value);
} }
/// Sets all entries. /// Sets all entries.
template <typename S> template <typename S>
inline void setValues(const S* values) inline void setValues(const S* values)
{ {
T *thisIt; std::copy(values, values + size, begin());
const S *valuesIt;
for (thisIt = this->begin(), valuesIt = values;
thisIt != this->end();
++thisIt, ++valuesIt)
*thisIt = *valuesIt;
// std::copy(values, values + size, valArray);
}
/// Comparison operator.
inline bool operator==(Vector<T> const& rhs) const
{
if (size != rhs.size)
return false;
T const* rhsIt;
T const* thisIt;
for (rhsIt = rhs.begin(), thisIt = this->begin();
rhsIt != rhs.end();
++rhsIt, ++thisIt)
if (*thisIt != *rhsIt)
return false;
return true;
}
/// Comparison operator.
inline bool operator!=(Vector<T> const& rhs) const
{
return !(*this==rhs);
} }
/// Access to the i-th vector element. /// Access to the i-th vector element.
inline T& operator[](int i) inline T& operator[](int i)
{ {
// TEST_EXIT_DBG(i < size && i >= 0)("Invalid index %d!\n", i); TEST_EXIT_DBG((unsigned)i < (unsigned)size)("Invalid index %d!\n", i);
return valArray[i]; return valArray[i];
} }
/// Access to the i-th vector element for const vectors. /// Access to the i-th vector element for const vectors.
inline const T& operator[] (int i) const inline const T& operator[] (int i) const
{ {
// TEST_EXIT_DBG(i < size && i >= 0)("Invalid index %d!\n", i); TEST_EXIT_DBG((unsigned)i < (unsigned)size)("Invalid index %d!\n", i);
return valArray[i]; return valArray[i];
} }
...@@ -288,15 +213,6 @@ namespace AMDiS { ...@@ -288,15 +213,6 @@ namespace AMDiS {
rows(other.getNumRows()), rows(other.getNumRows()),
cols(other.getNumCols()) cols(other.getNumCols())
{ } { }
// #if HAS_RVALUE_REFERENCES
// /// move constructor
// Matrix(self&& other)
// : Matrix()
// {
// swap(*this, other);
// }
// #endif
/// Changes the size of the matrix to newRows x newCols. /// Changes the size of the matrix to newRows x newCols.
inline void resize(int newRows, int newCols) inline void resize(int newRows, int newCols)
...@@ -307,60 +223,22 @@ namespace AMDiS { ...@@ -307,60 +223,22 @@ namespace AMDiS {
cols = newCols; cols = newCols;
} }
} }
// self& operator=(self other)
// {
// swap(*this, other);
// return *this;
// }
self& operator=(self const& other) self& operator=(self const& other)
{ {
assert( this->size == other.getSize() && rows == other.getNumRows() && cols == other.getNumCols() ); resize( other.getNumRows(), other.getNumCols() );
this->setValues(other.getValArray());
return *this;
}
/// Assignement operator
template <typename S>
inline self& operator=(const Matrix<S>& other)
{
assert( rows == other.getNumRows() && cols == other.getNumCols() );
// resize(other.getNumRows(), other.getNumCols());
this->setValues(other.getValArray()); this->setValues(other.getValArray());
return *this; return *this;
} }
/// Assignement operator for scalars. /// Assignement operator for scalars.
self& operator=(T value) template <typename S>
typename enable_if< boost::is_convertible<S, T>, self>::type &
operator=(S value)
{ {
super::set(value); this->set(value);
return *this; return *this;
} }
/// A swap function for Matrix, used in the Copy-and-swap idiom
// need non-templated arguments in order to eliminate a friend declaration warning in gcc
friend void swap(Matrix& first, Matrix& second)
{
using std::swap; // enable ADL
swap(first.rows, second.rows);
swap(first.cols, second.cols);
swap(static_cast<super&>(first), static_cast<super&>(second));
}
/// Comparison operator.
inline bool operator==(const self& rhs) const
{
if (rows != rhs.getNumRows()) return false;
if (cols != rhs.getNumCols()) return false;
return super::operator==(rhs);
}
/// Comparison operator.
inline bool operator!=(const self& rhs) const
{
return !(*this == rhs);
}
/// Access to i-th matrix row. /// Access to i-th matrix row.
inline T *operator[](int i) inline T *operator[](int i)
......
...@@ -473,6 +473,20 @@ namespace AMDiS { ...@@ -473,6 +473,20 @@ namespace AMDiS {
return m1; return m1;
} }
/// matrix += matrix
template <typename T, typename S>
Matrix<T>& operator+=(Matrix<T>& m1, const Matrix<S>& m2)
{
T* m1It;
S const* m2It;
for (m1It = m1.begin(), m2It = m2.begin();
m1It != m1.end();
m1It++, m2It++)
*m1It += *m2It;
return m1;
}
/// matrix := matrix + matrix /// matrix := matrix + matrix
template <typename T, typename S> template <typename T, typename S>
WorldMatrix<T> operator+(WorldMatrix<T> M1, const WorldMatrix<S>& M2 ) WorldMatrix<T> operator+(WorldMatrix<T> M1, const WorldMatrix<S>& M2 )
...@@ -480,6 +494,14 @@ namespace AMDiS { ...@@ -480,6 +494,14 @@ namespace AMDiS {
M1 += M2; M1 += M2;
return M1; return M1;
} }
/// matrix := matrix + matrix
template <typename T, typename S>
Matrix<T> operator+(Matrix<T> M1, const Matrix<S>& M2 )
{
M1 += M2;
return M1;
}
/// matrix -= matrix /// matrix -= matrix
template <typename T, typename S> template <typename T, typename S>
...@@ -494,6 +516,20 @@ namespace AMDiS { ...@@ -494,6 +516,20 @@ namespace AMDiS {