Skip to content

Commit

Permalink
removed dimensionality checks for uniform lists move operator=()
Browse files Browse the repository at this point in the history
  • Loading branch information
mfbolus committed Jun 9, 2021
1 parent a8338bd commit ada4169
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 78 deletions.
82 changes: 43 additions & 39 deletions include/ldsCtrlEst_h/lds_uniform_mats.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,45 +232,49 @@ inline UniformMatrixList<D>& UniformMatrixList<D>::operator=(
template <MatrixListFreeDim D>
inline UniformMatrixList<D>& UniformMatrixList<D>::operator=(
UniformMatrixList<D>&& that) noexcept {
// check dimensions
// if empty, assume a default constructed object and safe to move
if (!this->empty()) {
if (this->size() != that.size()) {
std::cerr << "Cannot reassign " << this->size() << " matrices with "
<< that.size() << " matrices. Skipping.\n";
return (*this);
}

// if dimensions a not zero and do not match, skip move with error message.
bool dims_nonzero = true;
for (auto d : dim_) {
if (!(D == kMatFreeDim1) && (d[0] < 1)) {
dims_nonzero = false;
break;
}
if (!(D == kMatFreeDim2) && (d[1] < 1)) {
dims_nonzero = false;
break;
}
}
if (dims_nonzero) {
bool does_match = true;
if (!(D == kMatFreeDim1)) {
does_match = does_match && (dim_[0][0] == that.at(0).n_rows);
}

if (!(D == kMatFreeDim2)) {
does_match = does_match && (dim_[0][1] == that.at(0).n_cols);
}

if (!does_match) {
std::cerr
<< "Cannot move a UniformMatrixList element for an element of "
"different size. Skipping.\n";
return (*this);
}
}
}
// // check dimensions
// // if empty, assume a default constructed object and safe to move
// if (!this->empty()) {
// if (this->size() != that.size()) {
// std::cerr << "Cannot reassign " << this->size() << " matrices with "
// << that.size() << " matrices. Skipping.\n";
// return (*this);
// }
//
// // if dimensions a not zero and do not match, skip move with error
// message. bool dims_nonzero = true; for (auto d : dim_) {
// if (!(D == kMatFreeDim1) && (d[0] < 1)) {
// dims_nonzero = false;
// break;
// }
// if (!(D == kMatFreeDim2) && (d[1] < 1)) {
// dims_nonzero = false;
// break;
// }
// }
//
// if (dims_nonzero) {
// bool does_match = true;
// if (!(D == kMatFreeDim1)) {
// does_match = does_match && (dim_[0][0] == that.at(0).n_rows);
// }
//
// if (!(D == kMatFreeDim2)) {
// does_match = does_match && (dim_[0][1] == that.at(0).n_cols);
// }
//
// if (!does_match) {
// this->at(0).print("this[0] = ");
// that.at(0).print("that[0] = ");
// std::cerr
// << "Cannot move a UniformMatrixList element of size (" <<
// that.at(0).n_rows << "," << that.at(0).n_cols << ") for an
// element of size (" << dim_[0][0] << "," << dim_[0][1] << ").
// Skipping.\n";
// return (*this);
// }
// }
// }

dim_ = that.dim_;
std::vector<Matrix>::operator=(std::move(that));
Expand Down
44 changes: 22 additions & 22 deletions include/ldsCtrlEst_h/lds_uniform_systems.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,28 +198,28 @@ inline UniformSystemList<System>& UniformSystemList<System>::operator=(
template <typename System>
inline UniformSystemList<System>& UniformSystemList<System>::operator=(
UniformSystemList&& that) noexcept {
// check dimensions
// if empty, assume a default constructed object and safe to move
if (!this->empty()) {
if (this->size() != that.size()) {
std::cerr << "Cannot reassign " << this->size() << " systems with "
<< that.size() << " systems. Skipping.\n";
return (*this);
}

// if dimensions a not zero and do not match, skip move with error message.
if (dim_[0] + dim_[1] + dim_[2]) {
bool does_match = (dim_[0] == that.at(0).n_u()) &&
(dim_[1] == that.at(0).n_x()) &&
(dim_[2] == that.at(0).n_y());
if (!does_match) {
std::cerr
<< "Cannot move a UniformSystemList element for an element of "
"different size. Skipping.\n";
return (*this);
}
}
}
// // check dimensions
// // if empty, assume a default constructed object and safe to move
// if (!this->empty()) {
// if (this->size() != that.size()) {
// std::cerr << "Cannot reassign " << this->size() << " systems with "
// << that.size() << " systems. Skipping.\n";
// return (*this);
// }
//
// // if dimensions a not zero and do not match, skip move with error
// message. if (dim_[0] + dim_[1] + dim_[2]) {
// bool does_match = (dim_[0] == that.at(0).n_u()) &&
// (dim_[1] == that.at(0).n_x()) &&
// (dim_[2] == that.at(0).n_y());
// if (!does_match) {
// std::cerr
// << "Cannot move a UniformSystemList element for an element of "
// "different size. Skipping.\n";
// return (*this);
// }
// }
// }

dim_ = that.dim_;
std::vector<System>::operator=(std::move(that));
Expand Down
35 changes: 18 additions & 17 deletions include/ldsCtrlEst_h/lds_uniform_vecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,24 @@ inline UniformVectorList& UniformVectorList::operator=(

inline UniformVectorList& UniformVectorList::operator=(
UniformVectorList&& that) noexcept {
// check dimensions
if (!this->empty()) {
if (this->size() != that.size()) {
std::cerr << "Cannot reassign " << this->size() << " vectors with "
<< that.size() << " vectors. Skipping.\n";
return (*this);
}

if (dim_) {
size_t other_dim(that.dim());
if (dim_ != other_dim) {
std::cerr << "Cannot reassign vectors of size " << dim_
<< " with matrices of size " << other_dim << ". Skipping.\n";
return (*this);
}
}
}
// // check dimensions
// if (!this->empty()) {
// if (this->size() != that.size()) {
// std::cerr << "Cannot reassign " << this->size() << " vectors with "
// << that.size() << " vectors. Skipping.\n";
// return (*this);
// }
//
// if (dim_) {
// size_t other_dim(that.dim());
// if (dim_ != other_dim) {
// std::cerr << "Cannot reassign vectors of size " << dim_
// << " with matrices of size " << other_dim << ".
// Skipping.\n";
// return (*this);
// }
// }
// }

dim_ = that.dim_;
std::vector<Vector>::operator=(std::move(that));
Expand Down

0 comments on commit ada4169

Please sign in to comment.