Skip to content

Commit 1963d25

Browse files
improve coverage
1 parent e8f3046 commit 1963d25

File tree

7 files changed

+42
-40
lines changed

7 files changed

+42
-40
lines changed

example/advanced/define_custom_low_rank_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66

77
class CustomSVD(Htool.VirtualLowRankGenerator):
8-
def __init__(self, generator: Htool.VirtualGenerator):
9-
super().__init__()
8+
def __init__(self, generator: Htool.VirtualGenerator, allow_copy: bool = True):
9+
super().__init__(allow_copy)
1010
self.generator = generator
1111

1212
def build_low_rank_approximation(self, rows, cols, epsilon):

src/htool/hmatrix/interfaces/virtual_low_rank_generator.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class VirtualLowRankGeneratorPython : public VirtualLowRankGenerator<Coefficient
4444
return success;
4545
}
4646

47-
bool copy_low_rank_approximation(int M, int N, const int *const rows, const int *const cols, int reqrank, LowRankMatrix<CoefficientPrecision> &lrmat) const override {
48-
Logger::get_instance().log(LogLevel::ERROR, "copy_low_rank_approximation with required rank is not implemented in the python interface."); // LCOV_EXCL_LINE
49-
return false; // LCOV_EXCL_LINE
47+
bool copy_low_rank_approximation(int M, int N, const int *const rows, const int *const cols, int reqrank, LowRankMatrix<CoefficientPrecision> &lrmat) const override { // LCOV_EXCL_LINE
48+
Logger::get_instance().log(LogLevel::ERROR, "copy_low_rank_approximation with required rank is not implemented in the python interface."); // LCOV_EXCL_LINE
49+
return false; // LCOV_EXCL_LINE
5050
}
5151

5252
// lcov does not see it because of trampoline I assume
@@ -84,7 +84,7 @@ template <typename CoefficientPrecision>
8484
void declare_custom_VirtualLowRankGenerator(py::module &m, const std::string &className) {
8585
using Class = VirtualLowRankGeneratorPython<CoefficientPrecision>;
8686
py::class_<Class, std::shared_ptr<Class>, PyVirtualLowRankGenerator<CoefficientPrecision>> py_class(m, className.c_str());
87-
py_class.def(py::init<>());
87+
py_class.def(py::init<bool>(), "allow_copy"_a = true);
8888
py_class.def("build_low_rank_approximation", &Class::build_low_rank_approximation);
8989
py_class.def("set_U", &Class::set_U);
9090
py_class.def("set_V", &Class::set_V);

src/htool/matplotlib/cluster.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ void declare_matplotlib_cluster(py::module &m) {
1515

1616
// Runtime checks
1717
if (spatial_dimension == 3 && ax.attr("name").cast<std::string>() != "3d") {
18-
htool::Logger::get_instance()
19-
.log(LogLevel::WARNING, "Axes object is not 3d while coordinates are 3d.");
18+
htool::Logger::get_instance().log(LogLevel::WARNING, "Axes object is not 3d while coordinates are 3d."); // LCOV_EXCL_LINE
2019
}
2120
if (spatial_dimension == 2 && ax.attr("name").cast<std::string>() != "rectilinear") {
22-
htool::Logger::get_instance()
23-
.log(LogLevel::WARNING, "Axes object is not rectilinear while coordinates are 2d.");
21+
htool::Logger::get_instance().log(LogLevel::WARNING, "Axes object is not rectilinear while coordinates are 2d."); // LCOV_EXCL_LINE
2422
}
2523

2624
std::vector<double> output((spatial_dimension)*root_cluster_size);
@@ -59,8 +57,7 @@ void declare_matplotlib_cluster(py::module &m) {
5957
colormap = plt.attr("get_cmap")("tab20");
6058
}
6159
if (counter > 20) {
62-
htool::Logger::get_instance()
63-
.log(LogLevel::WARNING, "Colormap does not support more than 20 colors.");
60+
htool::Logger::get_instance().log(LogLevel::WARNING, "Colormap does not support more than 20 colors."); // LCOV_EXCL_LINE
6461
}
6562

6663
py::object norm = colors.attr("Normalize")("vmin"_a = (*std::min_element(partition_numbers.begin(), partition_numbers.end())), "vmax"_a = (*std::max_element(partition_numbers.begin(), partition_numbers.end())));

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,10 @@ def geometry(partition_type: str, dimension: int, nb_rows: int, nb_cols: int, sy
139139

140140

141141
@pytest.fixture
142-
def cluster(geometry, symmetry, partition_type):
142+
def cluster(geometry, symmetry, partition_type, number_of_children):
143143
# Parameters
144144
[target_points, source_points, target_partition] = geometry
145145
maximal_leaf_size = 10
146-
number_of_children = 2
147146

148147
# Build clusters
149148
cluster_builder = Htool.ClusterTreeBuilder()

tests/test_cluster.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55

66

77
@pytest.mark.parametrize(
8-
"dimension,nb_rows,nb_cols,symmetry,partition_type",
8+
"dimension,nb_rows,nb_cols,symmetry,partition_type,number_of_children",
99
[
10-
(2, 500, 500, "N", "None"),
11-
(3, 500, 500, "N", "None"),
12-
(2, 500, 500, "N", "Local"),
13-
(3, 500, 500, "N", "Local"),
14-
(2, 500, 500, "N", "Global"),
15-
(3, 500, 500, "N", "Global"),
10+
(2, 500, 500, "N", "None", 2),
11+
(3, 500, 500, "N", "None", 2),
12+
(2, 500, 500, "N", "Local", 2),
13+
(3, 500, 500, "N", "Local", 2),
14+
(2, 500, 500, "N", "Global", 2),
15+
(3, 500, 500, "N", "Global", 2),
16+
(2, 500, 500, "N", "None", 3),
17+
(2, 500, 500, "N", "None", 9),
18+
(2, 500, 500, "N", "None", 10),
1619
],
1720
)
1821
def test_cluster(geometry, cluster):

tests/test_distributed_operator.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@
1515
# ids=["default_hmatrix_build", "custom_hmatrix_build"],
1616
# )
1717
@pytest.mark.parametrize(
18-
"nb_rows,nb_cols,symmetry,UPLO,use_default_build,low_rank_approximation,dense_blocks_generator,local_operator,partition_type",
18+
"nb_rows,nb_cols,symmetry,UPLO,use_default_build,low_rank_approximation,dense_blocks_generator,local_operator,partition_type,number_of_children",
1919
[
20-
(400, 400, "S", "L", True, False, False, "None", "None"),
21-
(400, 400, "S", "U", True, False, False, "None", "None"),
22-
(400, 400, "N", "N", True, False, False, "None", "None"),
23-
(400, 200, "N", "N", True, False, False, "None", "None"),
24-
(400, 400, "S", "L", False, True, True, "None", "None"),
25-
(400, 400, "S", "U", False, True, True, "None", "None"),
26-
(400, 400, "N", "N", False, True, True, "None", "None"),
27-
(400, 200, "N", "N", False, True, True, "None", "None"),
28-
(400, 400, "S", "L", False, False, False, "ExtraDiagonal", "None"),
29-
(400, 400, "S", "U", False, False, False, "ExtraDiagonal", "None"),
30-
(400, 400, "N", "N", False, False, False, "ExtraDiagonal", "None"),
31-
(400, 200, "N", "N", False, False, False, "ExtraDiagonal", "None"),
32-
(400, 400, "S", "L", False, False, False, "LocalAndExtraDiagonal", "None"),
33-
(400, 400, "S", "U", False, False, False, "LocalAndExtraDiagonal", "None"),
34-
(400, 400, "N", "N", False, False, False, "LocalAndExtraDiagonal", "None"),
35-
(400, 200, "N", "N", False, False, False, "LocalAndExtraDiagonal", "None"),
36-
(400, 200, "N", "N", True, False, False, "None", "Local"),
20+
(400, 400, "S", "L", True, False, False, "None", "None", 2),
21+
(400, 400, "S", "U", True, False, False, "None", "None", 2),
22+
(400, 400, "N", "N", True, False, False, "None", "None", 2),
23+
(400, 200, "N", "N", True, False, False, "None", "None", 2),
24+
(400, 400, "S", "L", False, True, True, "None", "None", 2),
25+
(400, 400, "S", "U", False, True, True, "None", "None", 2),
26+
(400, 400, "N", "N", False, True, True, "None", "None", 2),
27+
(400, 200, "N", "N", False, True, True, "None", "None", 2),
28+
(400, 400, "S", "L", False, False, False, "ExtraDiagonal", "None", 2),
29+
(400, 400, "S", "U", False, False, False, "ExtraDiagonal", "None", 2),
30+
(400, 400, "N", "N", False, False, False, "ExtraDiagonal", "None", 2),
31+
(400, 200, "N", "N", False, False, False, "ExtraDiagonal", "None", 2),
32+
(400, 400, "S", "L", False, False, False, "LocalAndExtraDiagonal", "None", 2),
33+
(400, 400, "S", "U", False, False, False, "LocalAndExtraDiagonal", "None", 2),
34+
(400, 400, "N", "N", False, False, False, "LocalAndExtraDiagonal", "None", 2),
35+
(400, 200, "N", "N", False, False, False, "LocalAndExtraDiagonal", "None", 2),
36+
(400, 200, "N", "N", True, False, False, "None", "Local", 2),
3737
],
3838
indirect=["low_rank_approximation", "dense_blocks_generator", "local_operator"],
3939
)

tests/test_hmatrix.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_hmatrix(loglevel):
4545
generator = CustomGenerator(target_points, source_points)
4646

4747
# Custom low rank generator
48-
low_rank_generator = CustomSVD(generator)
48+
low_rank_generator = CustomSVD(generator, False)
4949

5050
# Build HMatrix
5151
hmatrix_builder = Htool.HMatrixTreeBuilder(epsilon, eta, "N", "N")
@@ -74,3 +74,6 @@ def test_hmatrix(loglevel):
7474
hmatrix_local_information = hmatrix.get_local_information()
7575
print(hmatrix_tree_parameter)
7676
print(hmatrix_local_information)
77+
78+
# Clear low rank matrices stored in low_rank_generator when disallowing copy
79+
low_rank_generator.clear_data()

0 commit comments

Comments
 (0)