Skip to content

Commit

Permalink
bug fix: type_erasure deduce if in valid state from size_ value, SFIN…
Browse files Browse the repository at this point in the history
…AE selected iterative optimizer constructors for empty callback list
  • Loading branch information
AlePalu committed Jan 19, 2024
1 parent 93ce5f8 commit d13bc31
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions fdaPDE/optimization/bfgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ template <int N, typename... Args> class BFGS {

// constructor
BFGS() = default;
template <int N_ = sizeof...(Args), typename std::enable_if<N_ != 0, int>::type = 0>
BFGS(std::size_t max_iter, double tol, double step) : max_iter_(max_iter), tol_(tol), step_(step) {};
BFGS(std::size_t max_iter, double tol, double step, Args&... callbacks) :
max_iter_(max_iter), tol_(tol), step_(step), callbacks_(std::make_tuple(std::forward<Args>(callbacks)...)) {};
Expand Down
1 change: 1 addition & 0 deletions fdaPDE/optimization/gradient_descent.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ template <int N, typename... Args> class GradientDescent {

// constructor
GradientDescent() = default;
template <int N_ = sizeof...(Args), typename std::enable_if<N_ != 0, int>::type = 0>
GradientDescent(std::size_t max_iter, double tol, double step) : max_iter_(max_iter), tol_(tol), step_(step) {};
GradientDescent(std::size_t max_iter, double tol, double step, Args&... callbacks) :
max_iter_(max_iter), tol_(tol), step_(step), callbacks_(std::make_tuple(std::forward<Args>(callbacks)...)) {};
Expand Down
1 change: 1 addition & 0 deletions fdaPDE/optimization/newton.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ template <int N, typename... Args> class Newton {

// constructor
Newton() = default;
template <int N_ = sizeof...(Args), typename std::enable_if<N_ != 0, int>::type = 0>
Newton(std::size_t max_iter, double tol, double step) : max_iter_(max_iter), tol_(tol), step_(step) {};
Newton(std::size_t max_iter, double tol, double step, Args&... callbacks) :
max_iter_(max_iter), tol_(tol), step_(step), callbacks_(std::make_tuple(std::forward<Args>(callbacks)...)) {};
Expand Down
7 changes: 3 additions & 4 deletions fdaPDE/utils/type_erasure.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ struct shared_storage {
std::shared_ptr<void> ptr_ = nullptr;
void* ptr() { return ptr_.get(); }
const void* ptr() const { return ptr_.get(); }
operator bool() const { return ptr_ == nullptr; }

shared_storage() = default;
template <typename T> shared_storage(const T& obj) : ptr_(std::make_shared<T>(obj)) {};
Expand All @@ -106,7 +105,6 @@ struct non_owning_storage {
const void* ptr_ = nullptr;
void* ptr() { return const_cast<void*>(ptr_); }
const void* ptr() const { return ptr_; }
operator bool() const { return ptr_ == nullptr; }

non_owning_storage() = default;
template <typename T> non_owning_storage(T& obj) : ptr_(&obj) {};
Expand Down Expand Up @@ -158,7 +156,6 @@ struct heap_storage {
// getter to holded data
void* ptr() { return ptr_; };
const void* ptr() const { return ptr_; }
operator bool() const { return ptr_ != nullptr; }

~heap_storage() {
// free memory and restore status
Expand Down Expand Up @@ -206,8 +203,10 @@ struct vtable_handler {
~vtable_handler() {
if(vtable_) delete[] vtable_;
vtable_ = nullptr;
size_ = 0;
}

operator bool() const { return size_ != 0; }
virtual void* __data() = 0; // pointer to stored object
virtual const void* __data() const = 0;
};
Expand Down Expand Up @@ -256,7 +255,7 @@ template <typename StorageType, typename... I> class erase : vtable_handler, pub

virtual void* __data() override { return data_.ptr(); }
virtual const void* __data() const override { return data_.ptr(); }
operator bool() const { return data_.operator bool(); }
operator bool() const { return vtable_handler::operator bool(); }

virtual ~erase() = default;
private:
Expand Down

0 comments on commit d13bc31

Please sign in to comment.