Skip to content

Commit

Permalink
Remove redundant comments, defaulted constructors, and defaulted oper…
Browse files Browse the repository at this point in the history
…ator=
  • Loading branch information
calcmogul committed Dec 14, 2023
1 parent d44c4f2 commit 119ca7e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 97 deletions.
15 changes: 0 additions & 15 deletions include/sleipnir/Pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,9 @@ class PoolResource {
*/
PoolResource() { AddChunk(); }

/**
* Copy constructor.
*/
PoolResource(const PoolResource&) = delete;

/**
* Copy-assignment operator.
*/
PoolResource& operator=(const PoolResource&) = delete;

/**
* Move constructor.
*/
PoolResource(PoolResource&&) = default;

/**
* Move-assignment operator.
*/
PoolResource& operator=(PoolResource&&) = default;

/**
Expand Down
22 changes: 1 addition & 21 deletions include/sleipnir/autodiff/Expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,10 @@ struct SLEIPNIR_DLLEXPORT Expression {
uint32_t refCount = 0;

/**
* Default constructor.
* Constructs a constant expression with a value of zero.
*/
Expression() = default;

/**
* Copy constructor.
*/
Expression(const Expression&) = default;

/**
* Copy-assignment operator.
*/
Expression& operator=(const Expression&) = default;

/**
* Move constructor.
*/
Expression(Expression&&) = default;

/**
* Move-assignment operator.
*/
Expression& operator=(Expression&&) = default;

/**
* Constructs a nullary expression (an operator with no arguments).
*
Expand Down
24 changes: 2 additions & 22 deletions include/sleipnir/autodiff/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,9 @@ class SLEIPNIR_DLLEXPORT Variable {
detail::ExpressionPtr expr = detail::Zero();

/**
* Constructs an uninitialized Variable.
* Constructs a Variable initialized to zero.
*/
constexpr Variable() = default;

/**
* Copy constructor.
*/
Variable(const Variable&) = default;

/**
* Copy assignment operator.
*/
Variable& operator=(const Variable&) = default;

/**
* Move constructor.
*/
Variable(Variable&&) = default;

/**
* Move assignment operator.
*/
Variable& operator=(Variable&&) = default;
Variable() = default;

/**
* Constructs a Variable from a double.
Expand Down
81 changes: 42 additions & 39 deletions include/sleipnir/autodiff/VariableBlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,48 @@ namespace sleipnir {
template <typename Mat>
class VariableBlock {
public:
/**
* Copy constructs a VariableBlock to the block.
*/
VariableBlock(const VariableBlock<Mat>& values) {
m_mat = values.m_mat;
m_rowOffset = values.m_rowOffset;
m_colOffset = values.m_colOffset;
m_blockRows = values.m_blockRows;
m_blockCols = values.m_blockCols;
}

/**
* Assigns a VariableBlock to the block.
*/
VariableBlock<Mat>& operator=(VariableBlock<Mat>& values) {
if (this == &values) {
return *this;
}

if (m_mat == nullptr) {
m_mat = values.m_mat;
m_rowOffset = values.m_rowOffset;
m_colOffset = values.m_colOffset;
m_blockRows = values.m_blockRows;
m_blockCols = values.m_blockCols;
} else {
assert(Rows() == values.Rows());
assert(Cols() == values.Cols());

for (int row = 0; row < Rows(); ++row) {
for (int col = 0; col < Cols(); ++col) {
(*this)(row, col) = values(row, col);
}
}
}

return *this;
}

VariableBlock(VariableBlock<Mat>&&) = default;
VariableBlock<Mat>& operator=(VariableBlock<Mat>&&) = default;

/**
* Constructs a Variable block pointing to all of the given matrix.
*
Expand Down Expand Up @@ -73,45 +115,6 @@ class VariableBlock {
return *this;
}

/**
* Copy constructs a VariableBlock to the block.
*/
VariableBlock(const VariableBlock<Mat>& values) {
m_mat = values.m_mat;
m_rowOffset = values.m_rowOffset;
m_colOffset = values.m_colOffset;
m_blockRows = values.m_blockRows;
m_blockCols = values.m_blockCols;
}

/**
* Assigns a VariableBlock to the block.
*/
VariableBlock<Mat>& operator=(VariableBlock<Mat>& values) {
if (this == &values) {
return *this;
}

if (m_mat == nullptr) {
m_mat = values.m_mat;
m_rowOffset = values.m_rowOffset;
m_colOffset = values.m_colOffset;
m_blockRows = values.m_blockRows;
m_blockCols = values.m_blockCols;
} else {
assert(Rows() == values.Rows());
assert(Cols() == values.Cols());

for (int row = 0; row < Rows(); ++row) {
for (int col = 0; col < Cols(); ++col) {
(*this)(row, col) = values(row, col);
}
}
}

return *this;
}

/**
* Assigns an Eigen matrix to the block.
*/
Expand Down

0 comments on commit 119ca7e

Please sign in to comment.