Skip to content

Commit

Permalink
Replace std::map by std::unordered_map
Browse files Browse the repository at this point in the history
  • Loading branch information
ordinary-slim committed Jan 21, 2025
1 parent ae778af commit 8f9fc4c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions multiphenicsx/cpp/multiphenicsx/fem/DofMapRestriction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ DofMapRestriction::DofMapRestriction(
//-----------------------------------------------------------------------------
void DofMapRestriction::_compute_cell_dofs(std::shared_ptr<const DofMap> dofmap)
{
// Fill in cell dofs first into a temporary std::map
std::map<int, std::vector<std::int32_t>> restricted_cell_dofs;
// Fill in cell dofs first into a temporary std::unordered_map
std::unordered_map<int, std::vector<std::int32_t>> restricted_cell_dofs;
std::size_t restricted_cell_dofs_total_size = 0;
auto unrestricted_cell_dofs = dofmap->map();
const int num_cells = unrestricted_cell_dofs.extent(0);
Expand Down Expand Up @@ -82,7 +82,7 @@ void DofMapRestriction::_compute_cell_dofs(std::shared_ptr<const DofMap> dofmap)
}
}

// Flatten std::map into the std::vector dof_array, and store start/end
// Flatten std::unordered_map into the std::vector dof_array, and store start/end
// indices associated to each cell in cell_bounds
_dof_array.reserve(restricted_cell_dofs_total_size);
_cell_bounds.reserve(num_cells + 1);
Expand Down
10 changes: 5 additions & 5 deletions multiphenicsx/cpp/multiphenicsx/fem/DofMapRestriction.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <dolfinx/common/IndexMap.h>
#include <dolfinx/fem/DofMap.h>
#include <map>
#include <unordered_map>
#include <memory>

namespace multiphenicsx
Expand Down Expand Up @@ -59,13 +59,13 @@ class DofMapRestriction
std::shared_ptr<const dolfinx::fem::DofMap> dofmap() const { return _dofmap; }

/// Return map from unrestricted dofs to restricted dofs
const std::map<std::int32_t, std::int32_t>& unrestricted_to_restricted() const
const std::unordered_map<std::int32_t, std::int32_t>& unrestricted_to_restricted() const
{
return _unrestricted_to_restricted;
}

/// Map from restricted dofs to unrestricted dofs
const std::map<std::int32_t, std::int32_t>& restricted_to_unrestricted() const
const std::unordered_map<std::int32_t, std::int32_t>& restricted_to_unrestricted() const
{
return _restricted_to_unrestricted;
}
Expand Down Expand Up @@ -94,10 +94,10 @@ class DofMapRestriction
std::shared_ptr<const dolfinx::fem::DofMap> _dofmap;

// Map from unrestricted dofs to restricted dofs
std::map<std::int32_t, std::int32_t> _unrestricted_to_restricted;
std::unordered_map<std::int32_t, std::int32_t> _unrestricted_to_restricted;

// Map from restricted dofs to unrestricted dofs
std::map<std::int32_t, std::int32_t> _restricted_to_unrestricted;
std::unordered_map<std::int32_t, std::int32_t> _restricted_to_unrestricted;

// Cell-local-to-dof map after restriction has been carried out
std::vector<std::int32_t> _dof_array;
Expand Down
6 changes: 3 additions & 3 deletions multiphenicsx/cpp/multiphenicsx/la/petsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ MatSubMatrixWrapper::MatSubMatrixWrapper(Mat A, std::array<IS, 2> index_sets)
MatSubMatrixWrapper::MatSubMatrixWrapper(
Mat A, std::array<IS, 2> unrestricted_index_sets,
std::array<IS, 2> restricted_index_sets,
std::array<std::map<std::int32_t, std::int32_t>, 2>
std::array<std::unordered_map<std::int32_t, std::int32_t>, 2>
unrestricted_to_restricted,
std::array<int, 2> unrestricted_to_restricted_bs)
: MatSubMatrixWrapper(A, restricted_index_sets)
Expand Down Expand Up @@ -348,7 +348,7 @@ VecSubVectorReadWrapper::VecSubVectorReadWrapper(Vec x, IS index_set,
//-----------------------------------------------------------------------------
VecSubVectorReadWrapper::VecSubVectorReadWrapper(
Vec x, IS unrestricted_index_set, IS restricted_index_set,
const std::map<std::int32_t, std::int32_t>& unrestricted_to_restricted,
const std::unordered_map<std::int32_t, std::int32_t>& unrestricted_to_restricted,
int unrestricted_to_restricted_bs, bool ghosted)
: _ghosted(ghosted)
{
Expand Down Expand Up @@ -446,7 +446,7 @@ VecSubVectorWrapper::VecSubVectorWrapper(Vec x, IS index_set, bool ghosted)
//-----------------------------------------------------------------------------
VecSubVectorWrapper::VecSubVectorWrapper(
Vec x, IS unrestricted_index_set, IS restricted_index_set,
const std::map<std::int32_t, std::int32_t>& unrestricted_to_restricted,
const std::unordered_map<std::int32_t, std::int32_t>& unrestricted_to_restricted,
int unrestricted_to_restricted_bs, bool ghosted)
: VecSubVectorReadWrapper(x, unrestricted_index_set, restricted_index_set,
unrestricted_to_restricted,
Expand Down
10 changes: 5 additions & 5 deletions multiphenicsx/cpp/multiphenicsx/la/petsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#pragma once

#include <dolfinx/common/IndexMap.h>
#include <map>
#include <unordered_map>
#include <petscmat.h>
#include <petscvec.h>
#include <vector>
Expand Down Expand Up @@ -65,7 +65,7 @@ class MatSubMatrixWrapper
/// Constructor (for cases with restriction)
MatSubMatrixWrapper(Mat A, std::array<IS, 2> unrestricted_index_sets,
std::array<IS, 2> restricted_index_sets,
std::array<std::map<std::int32_t, std::int32_t>, 2>
std::array<std::unordered_map<std::int32_t, std::int32_t>, 2>
unrestricted_to_restricted,
std::array<int, 2> unrestricted_to_restricted_bs);

Expand Down Expand Up @@ -107,7 +107,7 @@ class VecSubVectorReadWrapper
/// Constructor (for cases with restriction)
VecSubVectorReadWrapper(Vec x, IS unrestricted_index_set,
IS restricted_index_set,
const std::map<std::int32_t, std::int32_t>&
const std::unordered_map<std::int32_t, std::int32_t>&
unrestricted_to_restricted,
int unrestricted_to_restricted_bs,
bool ghosted = true);
Expand Down Expand Up @@ -146,7 +146,7 @@ class VecSubVectorWrapper : public VecSubVectorReadWrapper
/// Constructor (for cases with restriction)
VecSubVectorWrapper(Vec x, IS unrestricted_index_set,
IS restricted_index_set,
const std::map<std::int32_t, std::int32_t>&
const std::unordered_map<std::int32_t, std::int32_t>&
unrestricted_to_restricted,
int unrestricted_to_restricted_bs,
bool ghosted = true);
Expand All @@ -172,7 +172,7 @@ class VecSubVectorWrapper : public VecSubVectorReadWrapper
private:
Vec _global_vector;
IS _is;
std::map<std::int32_t, std::int32_t> _restricted_to_unrestricted;
std::unordered_map<std::int32_t, std::int32_t> _restricted_to_unrestricted;
};

} // namespace petsc
Expand Down
2 changes: 1 addition & 1 deletion multiphenicsx/cpp/multiphenicsx/wrappers/fem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <nanobind/ndarray.h>
#include <nanobind/stl/array.h>
#include <nanobind/stl/complex.h>
#include <nanobind/stl/map.h>
#include <nanobind/stl/unordered_map.h>
#include <nanobind/stl/pair.h>
#include <nanobind/stl/shared_ptr.h>
#include <nanobind/stl/string.h>
Expand Down
8 changes: 4 additions & 4 deletions multiphenicsx/cpp/multiphenicsx/wrappers/la.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <nanobind/ndarray.h>
#include <nanobind/stl/array.h>
#include <nanobind/stl/complex.h>
#include <nanobind/stl/map.h>
#include <nanobind/stl/unordered_map.h>
#include <nanobind/stl/pair.h>
#include <nanobind/stl/vector.h>
#include <petsc4py/petsc4py.h>
Expand All @@ -38,7 +38,7 @@ void la_petsc_module(nb::module_& m)
.def(nb::init<Mat, std::array<IS, 2>>(), nb::arg("A"),
nb::arg("index_sets"))
.def(nb::init<Mat, std::array<IS, 2>, std::array<IS, 2>,
std::array<std::map<std::int32_t, std::int32_t>, 2>,
std::array<std::unordered_map<std::int32_t, std::int32_t>, 2>,
std::array<int, 2>>(),
nb::arg("A"), nb::arg("unrestricted_index_sets"),
nb::arg("restricted_index_sets"),
Expand All @@ -57,7 +57,7 @@ void la_petsc_module(nb::module_& m)
m, "VecSubVectorReadWrapper")
.def(nb::init<Vec, IS, bool>(), nb::arg("x"), nb::arg("index_set"),
nb::arg("ghosted") = true)
.def(nb::init<Vec, IS, IS, const std::map<std::int32_t, std::int32_t>&,
.def(nb::init<Vec, IS, IS, const std::unordered_map<std::int32_t, std::int32_t>&,
int, bool>(),
nb::arg("x"), nb::arg("unrestricted_index_set"),
nb::arg("restricted_index_set"),
Expand All @@ -78,7 +78,7 @@ void la_petsc_module(nb::module_& m)
m, "VecSubVectorWrapper")
.def(nb::init<Vec, IS, bool>(), nb::arg("x"), nb::arg("index_set"),
nb::arg("ghosted") = true)
.def(nb::init<Vec, IS, IS, const std::map<std::int32_t, std::int32_t>&,
.def(nb::init<Vec, IS, IS, const std::unordered_map<std::int32_t, std::int32_t>&,
int, bool>(),
nb::arg("x"), nb::arg("unrestricted_index_set"),
nb::arg("restricted_index_set"),
Expand Down

0 comments on commit 8f9fc4c

Please sign in to comment.