Skip to content

Commit

Permalink
Use unbounded_array_wrapper with custom_allocator in type aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-ai-integration[bot] authored and ohhmm committed Sep 17, 2024
1 parent cb48bb0 commit e915df7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions omnn/extrapolator/Extrapolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ using namespace boost::numeric::ublas;
// Correct usage of Boost Ublas vector and matrix with custom_allocator
// Replace incorrect allocator functions with correct Boost Ublas container functions

// Ensure that matrix_t, vector_t, and permutation_matrix_t are using std::vector with custom_allocator
using matrix_t = boost::numeric::ublas::matrix<Valuable, boost::numeric::ublas::basic_row_major<>, std::vector<Valuable, custom_allocator<Valuable>>>;
using vector_t = boost::numeric::ublas::vector<Valuable, std::vector<Valuable, custom_allocator<Valuable>>>;
using permutation_matrix_t = boost::numeric::ublas::permutation_matrix<std::size_t, std::vector<std::size_t, custom_allocator<std::size_t>>>;
// Ensure that matrix_t, vector_t, and permutation_matrix_t are using unbounded_array_wrapper with custom_allocator
using matrix_t = boost::numeric::ublas::matrix<Valuable, boost::numeric::ublas::basic_row_major<>, unbounded_array_wrapper<Valuable>>;
using vector_t = boost::numeric::ublas::vector<Valuable, unbounded_array_wrapper<Valuable>>;
using permutation_matrix_t = boost::numeric::ublas::permutation_matrix<std::size_t, unbounded_array_wrapper<std::size_t>>;

// This function calculates the determinant of a matrix using LU factorization
auto det_fast(matrix_t matrix) {
Expand Down Expand Up @@ -110,7 +110,8 @@ Extrapolator::solution_t Extrapolator::Solve(const vector_t& augment) const
auto sz1 = size1();
auto sz2 = size2();

vector_t a(sz2); // Initialize vector with size using custom_allocator implicitly
// Initialize vector with size and default value
vector_t a(sz2, Valuable(0));
const vector_t* au = &augment;
if (sz1 > sz2 + 1 /*augment*/) {
// make square matrix to make it solvable by boost ublas
Expand All @@ -124,14 +125,14 @@ Extrapolator::solution_t Extrapolator::Solve(const vector_t& augment) const
for (auto j = sz2; j--;) {
e(0, j) += operator()(i, j);
}
a(0) += augment(i); // Use vector's operator[] provided by unbounded_array_wrapper for element access
a(i - d) = (*au)(i); // Use vector's operator() provided by Boost Ublas for element access
}

for (auto i = d; i < sz1; ++i) {
for (auto j = sz2; j--;) {
e(i - d, j) = operator()(i, j);
}
a(i - d) = augment(i); // Use vector's operator[] provided by unbounded_array_wrapper for element access
a(i - d) = (*au)(i); // Use vector's operator() provided by Boost Ublas for element access
}
au = &a;
}
Expand Down

0 comments on commit e915df7

Please sign in to comment.