Skip to content

Commit

Permalink
Updating InterpolationTable and components
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Sep 14, 2024
1 parent 8c0c3d2 commit 6a8cc58
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/scion/math/HistogramTable/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
HistogramTable( const HistogramTable& ) = default;
HistogramTable( HistogramTable&& ) = default;

HistogramTable& operator=( const HistogramTable& ) = default;
HistogramTable& operator=( HistogramTable&& ) = default;

/**
* @brief Constructor
*
Expand Down
16 changes: 14 additions & 2 deletions src/scion/math/InterpolationTable/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ InterpolationTable& operator=( const InterpolationTable& base ) {

if ( this != &base ) {

new (this) InterpolationTable( base );
Parent::operator=( base );
this->x_ = base.x_;
this->y_ = base.y_;
this->boundaries_ = base.boundaries_;
this->interpolants_ = base.interpolants_;
this->linearised_ = base.linearised_;
this->generateTables();
}
return *this;
}
Expand All @@ -54,7 +60,13 @@ InterpolationTable& operator=( InterpolationTable&& base ) {

if ( this != &base ) {

new (this) InterpolationTable( std::move( base ) );
Parent::operator=( std::move( base ) );
this->x_ = std::move( base.x_ );
this->y_ = std::move( base.y_ );
this->boundaries_ = std::move( base.boundaries_ );
this->interpolants_ = std::move( base.interpolants_ );
this->linearised_ = std::move( base.linearised_ );
this->generateTables();

This comment has been minimized.

Copy link
@joewpeterson

joewpeterson Sep 16, 2024

I'm a little confused about the call to gererateTables and the call move linearised_. tables_ exists in base and was already constructed. Why not just move/copy it?

this->linearised_ is a bool. Might be better just to copy it?

This comment has been minimized.

Copy link
@whaeck

whaeck Sep 16, 2024

Author Member

generateTables() takes the data in x_, y_, boundaries_ and interpolants_ and generates iterator based views into the data. Copying and moving changes those iterators so I need to recreate them after copying/moving. If it wasn't for that part, I could have used the default assignment operators.

And yes, I should just copy that bool. Too much copy/paste :-)

This comment has been minimized.

Copy link
@joewpeterson

joewpeterson Sep 16, 2024

I see. I think then that linearised_ does not even need to be copied. It is re-populated from generateTables()

This comment has been minimized.

Copy link
@joewpeterson

joewpeterson Sep 16, 2024

Ok, I get the explanation for needing new iterators into a copied tables, but if we just move them - this should all be pointing to the same places, yes?

This comment has been minimized.

Copy link
@whaeck

whaeck Sep 16, 2024

Author Member

Iterators can get invalidated when certain operations are performed. With move, I wouldn't know as I would have to look it up (intuitively, I would think they'd stay the same). But, better safe than sorry?

This comment has been minimized.

Copy link
@joewpeterson

joewpeterson Sep 16, 2024

ok, sounds good. I won't fight on this as it is only a slight optimization as far as I can see. My understanding of the move was just you change what entity has ownership of data. Sort equivalent to c calling
b = a; a = null; where a and b are a couple of pointers. Since you're doing that for all pointers, it seems to be that no underlying data is changing so pointers to the underlying data ( and iterators are just pointers+ ) don't change. But, I agree, what you do won't get the wrong result

}
return *this;
}
Expand Down
6 changes: 6 additions & 0 deletions src/scion/math/LinearLinearTable/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
LinearLinearTable( const LinearLinearTable& ) = default;
LinearLinearTable( LinearLinearTable&& ) = default;

LinearLinearTable& operator=( const LinearLinearTable& ) = default;
LinearLinearTable& operator=( LinearLinearTable&& ) = default;

/**
* @brief Constructor
*
Expand Down
6 changes: 6 additions & 0 deletions src/scion/math/LinearLogTable/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
LinearLogTable( const LinearLogTable& ) = default;
LinearLogTable( LinearLogTable&& ) = default;

LinearLogTable& operator=( const LinearLogTable& ) = default;
LinearLogTable& operator=( LinearLogTable&& ) = default;

/**
* @brief Constructor
*
Expand Down
6 changes: 6 additions & 0 deletions src/scion/math/LogLinearTable/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
LogLinearTable( const LogLinearTable& ) = default;
LogLinearTable( LogLinearTable&& ) = default;

LogLinearTable& operator=( const LogLinearTable& ) = default;
LogLinearTable& operator=( LogLinearTable&& ) = default;

/**
* @brief Constructor
*
Expand Down
6 changes: 6 additions & 0 deletions src/scion/math/LogLogTable/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
LogLogTable( const LogLogTable& ) = default;
LogLogTable( LogLogTable&& ) = default;

LogLogTable& operator=( const LogLogTable& ) = default;
LogLogTable& operator=( LogLogTable&& ) = default;

/**
* @brief Constructor
*
Expand Down
6 changes: 6 additions & 0 deletions src/scion/math/OneDimensionalFunctionBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ namespace math {
OneDimensionalFunctionBase( DomainVariant domain ) :
domain_( std::move( domain ) ) {}

OneDimensionalFunctionBase( const OneDimensionalFunctionBase& ) = default;
OneDimensionalFunctionBase( OneDimensionalFunctionBase&& ) = default;

OneDimensionalFunctionBase& operator=( const OneDimensionalFunctionBase& ) = default;
OneDimensionalFunctionBase& operator=( OneDimensionalFunctionBase&& ) = default;

public:

/* methods */
Expand Down
7 changes: 6 additions & 1 deletion src/scion/math/SingleTableBase/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @brief Private constructor
*/
SingleTableBase( IntervalDomain< X >&& domain, XContainer&& x, YContainer&& y ) :
Parent( std::move( domain ) ), interpolator_(),
Parent( std::move( domain ) ), interpolator_(),
x_( std::move( x ) ), y_( std::move( y ) ) {}

protected:
Expand All @@ -19,3 +19,8 @@ SingleTableBase( XContainer x, YContainer y ) :
SingleTableBase( verifyTableAndRetrieveDomain( x, y ),
std::move( x ), std::move( y ) ) {}

SingleTableBase( const SingleTableBase& ) = default;
SingleTableBase( SingleTableBase&& ) = default;

SingleTableBase& operator=( const SingleTableBase& ) = default;
SingleTableBase& operator=( SingleTableBase&& ) = default;

0 comments on commit 6a8cc58

Please sign in to comment.