Skip to content

Instantly share code, notes, and snippets.

@JohanMabille
Created August 11, 2020 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohanMabille/5b520acddd6a5cfae5f843e80e2e4521 to your computer and use it in GitHub Desktop.
Save JohanMabille/5b520acddd6a5cfae5f843e80e2e4521 to your computer and use it in GitHub Desktop.
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