Created
August 11, 2020 12:21
-
-
Save JohanMabille/5b520acddd6a5cfae5f843e80e2e4521 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class base | |
{ | |
public: | |
virtual void compute() = 0; | |
}; | |
class coo_matrix_impl : public base | |
{ | |
public: | |
void compute() override; | |
private: | |
coo_matrix m_impl; | |
}; | |
class csr_matrix_impl : public base | |
{ | |
public: | |
void compute() override; | |
private: | |
csr_matrix m_impl; | |
}; | |
enum class sparse_type | |
{ | |
coo, | |
csr | |
}; | |
base* make_sparse(sparse_type type) | |
{ | |
return type == sparse_type::coo ? new coo_impl() : new csr_impl(); | |
} | |
void solve(const base& matrix, ...) | |
{ | |
// ... | |
} | |
template <class M> | |
void solve_impl(const M& matrix, ...) | |
{ | |
// common stuff | |
} | |
template <class M> | |
void solve(const M& matrix, ...); | |
template <> | |
void solve<coo_matrix>(const coo_matrix& matrix, ...) | |
{ | |
solive_impl(matrix); | |
} | |
template <> | |
void solve<csr_matrix>(const csr_matrix& matrix, ...) | |
{ | |
solive_impl(matrix); | |
} | |
void invoke_solver(sparse_type st) | |
{ | |
switch(st) | |
{ | |
case sparse_type::coo: | |
{ | |
coo_matrix m; | |
solve(m); | |
break; | |
} | |
case sparse_type::csr: | |
default: | |
{ | |
csr_matrix m; | |
solve(m); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment