Skip to content

Commit 88964ca

Browse files
committed
Split sparsity representation
Make a distinction between Sparsity with static size (needed to store them at compile-time), Sparsity with dynamic size and simple view. This allows removing some templating.
1 parent df2ebd2 commit 88964ca

File tree

65 files changed

+841
-573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+841
-573
lines changed

ctldl/factor_data/empty_factor_data_diagonal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ctldl {
88

99
template <class FactorData>
1010
struct EmptyFactorDataDiagonal {
11-
static constexpr auto sparsity = makeEmptySparsityCSR<0, 0>();
11+
static constexpr auto sparsity = makeEmptySparsityStaticCSR<0, 0>();
1212
using Value = typename FactorData::Value;
1313
static constexpr std::array<Value, 0> D{};
1414
};

ctldl/factor_data/empty_factor_data_left.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ template <class FactorData>
1111
struct EmptyFactorDataLeft {
1212
static constexpr auto num_rows = FactorData::sparsity.numRows();
1313
using Value = typename FactorData::Value;
14-
static constexpr auto sparsity = makeEmptySparsityCSR<num_rows, 0>();
14+
static constexpr auto sparsity = makeEmptySparsityStaticCSR<num_rows, 0>();
1515
static constexpr std::array<Value, 0> L{};
1616
static constexpr auto permutation_row = FactorData::permutation_row;
1717
static constexpr PermutationStatic<0> permutation_col{};

ctldl/factor_data/factorization.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace ctldl {
2222

23-
template <Sparsity sparsity_orig, class Value_,
23+
template <SparsityStatic sparsity_orig, class Value_,
2424
PermutationStatic<sparsity_orig.numRows()> permutation_in =
2525
PermutationIdentity{}>
2626
class Factorization {
@@ -59,7 +59,7 @@ class Factorization {
5959
}
6060

6161
static constexpr auto sparsity =
62-
SparsityCSR(getFilledInSparsity<sparsity_orig, permutation>());
62+
SparsityStaticCSR(getFilledInSparsity<sparsity_orig, permutation>());
6363
static constexpr auto nnz = std::size_t{sparsity.nnz()};
6464
static constexpr auto permutation_row = permutation;
6565
static constexpr auto permutation_col = permutation;

ctldl/factor_data/factorization_already_permuted.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace ctldl {
1313
// We implement that by unpermuting the sparsity and letting the Factorization
1414
// permute it back again. That way we factorize the correct sparsity and also
1515
// remember the correct permutation within Factorization.
16-
template <Sparsity sparsity, class Value, PermutationStatic permutation>
16+
template <SparsityStatic sparsity, class Value, PermutationStatic permutation>
1717
using FactorizationAlreadyPermuted =
18-
Factorization<getSparsityLowerTriangle<sparsity>(
18+
Factorization<getSparsityStaticLowerTriangle<sparsity>(
1919
invertPermutation(permutation)),
2020
Value, permutation>;
2121

ctldl/factor_data/factorization_repeating_block_tridiagonal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace ctldl {
2323
// [ : : : ]
2424
// [ B A B']
2525
// [ B A ]
26-
template <Sparsity sparsity_A, Sparsity sparsity_B, class Value_,
26+
template <SparsityStatic sparsity_A, SparsityStatic sparsity_B, class Value_,
2727
PermutationStatic<sparsity_A.numRows()> permutation_in =
2828
PermutationIdentity{}>
2929
class FactorizationRepeatingBlockTridiagonal {

ctldl/factor_data/factorization_repeating_block_tridiagonal_arrowhead_linked.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class FactorizationRepeatingBlockTridiagonalArrowheadLinked {
5656
static constexpr auto sparsity_factor_start_tridiag = helper_start.block21;
5757
static constexpr auto sparsity_factor_start_outer = helper_start.block31;
5858
static constexpr auto sparsity_tridiag_diag = helper_start.block22;
59-
static constexpr auto sparsity_tridiag_subdiag = getSparsityPermuted(
59+
static constexpr auto sparsity_tridiag_subdiag = getSparsityStaticPermuted(
6060
sparsity.tridiag.subdiag, permutation_tridiag, permutation_tridiag);
6161
static constexpr auto sparsity_outer_subdiag = helper_start.block32;
6262
static constexpr auto sparsity_outer_diag = helper_start.block33;
@@ -66,10 +66,13 @@ class FactorizationRepeatingBlockTridiagonalArrowheadLinked {
6666
PermutationStatic<dim_tridiag>{}, PermutationStatic<dim_outer>{}>();
6767

6868
static constexpr auto helper = [] {
69-
constexpr auto sparsity_link_tridiag_permuted_cols = getSparsityPermuted(
70-
sparsity.link.prev, PermutationStatic<dim_link>{}, permutation_tridiag);
71-
constexpr auto sparsity_link_outer_permuted_rows = getSparsityPermuted(
72-
sparsity.link.next, permutation_outer, PermutationStatic<dim_link>{});
69+
constexpr auto sparsity_link_tridiag_permuted_cols =
70+
getSparsityStaticPermuted(sparsity.link.prev,
71+
PermutationStatic<dim_link>{},
72+
permutation_tridiag);
73+
constexpr auto sparsity_link_outer_permuted_rows =
74+
getSparsityStaticPermuted(sparsity.link.next, permutation_outer,
75+
PermutationStatic<dim_link>{});
7376
return getFilledInSparsityBlocked3x3<
7477
sparsity_factor.diag, sparsity_link_tridiag_permuted_cols,
7578
sparsity.link.diag, sparsity_factor.outer,

ctldl/factor_data/factorization_repeating_block_tridiagonal_arrowhead_linked.test.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,30 @@ BOOST_AUTO_TEST_CASE(SplinePrepermuted) {
2020

2121
constexpr auto sparsity = SparsityToFactorizeTridiagonalArrowheadLinked{
2222
SparsityToFactorizeStart{
23-
makeEmptySparsity<dim_start, dim_start>(),
24-
makeSparsity<dim_tridiag, dim_start>(
23+
makeEmptySparsityStatic<dim_start, dim_start>(),
24+
makeSparsityStatic<dim_tridiag, dim_start>(
2525
{{3, 0}, {3, 1}, {4, 1}, {4, 3}, {5, 2}, {5, 3}}),
26-
makeEmptySparsity<dim_outer, dim_start>()},
26+
makeEmptySparsityStatic<dim_outer, dim_start>()},
2727
SparsityToFactorizeTridiagonal{
28-
makeSparsity<dim_tridiag, dim_tridiag>(
28+
makeSparsityStatic<dim_tridiag, dim_tridiag>(
2929
{{3, 0}, {3, 2}, {4, 2}, {5, 1}, {6, 4}, {6, 5}}),
30-
makeSparsity<dim_tridiag, dim_tridiag>(
30+
makeSparsityStatic<dim_tridiag, dim_tridiag>(
3131
{{3, 0}, {3, 2}, {4, 2}, {4, 6}, {5, 1}, {5, 6}})},
32-
SparsityToFactorizeLink{makeEmptySparsity<dim_link, dim_tridiag>(),
33-
makeEmptySparsity<dim_link, dim_link>(),
34-
makeEmptySparsity<dim_outer, dim_link>()},
35-
SparsityToFactorizeOuter{makeEmptySparsity<dim_outer, dim_tridiag>(),
36-
makeEmptySparsity<dim_outer, dim_outer>()}};
32+
SparsityToFactorizeLink{makeEmptySparsityStatic<dim_link, dim_tridiag>(),
33+
makeEmptySparsityStatic<dim_link, dim_link>(),
34+
makeEmptySparsityStatic<dim_outer, dim_link>()},
35+
SparsityToFactorizeOuter{
36+
makeEmptySparsityStatic<dim_outer, dim_tridiag>(),
37+
makeEmptySparsityStatic<dim_outer, dim_outer>()}};
3738

3839
using Factorization =
3940
FactorizationRepeatingBlockTridiagonalArrowheadLinked<sparsity, double>;
4041

41-
constexpr auto diag_correct = makeSparsity<dim_tridiag, dim_tridiag>(
42+
constexpr auto diag_correct = makeSparsityStatic<dim_tridiag, dim_tridiag>(
4243
{{3, 0}, {3, 2}, {4, 2}, {4, 3}, {5, 1}, {5, 3}, {5, 4}, {6, 4}, {6, 5}});
4344
CTLDL_TEST_STATIC(isSparsityEqual(Factorization::FactorTridiagDiag::sparsity,
4445
diag_correct));
45-
constexpr auto subdiag_correct = makeSparsity<dim_tridiag, dim_tridiag>(
46+
constexpr auto subdiag_correct = makeSparsityStatic<dim_tridiag, dim_tridiag>(
4647
{{3, 0}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6},
4748
{4, 2}, {4, 3}, {4, 4}, {4, 5}, {4, 6},
4849
{5, 1}, {5, 5}, {5, 6}});
@@ -63,33 +64,34 @@ BOOST_AUTO_TEST_CASE(Spline) {
6364

6465
constexpr auto sparsity = SparsityToFactorizeTridiagonalArrowheadLinked{
6566
SparsityToFactorizeStart{
66-
makeEmptySparsity<dim_start, dim_start>(),
67-
makeSparsity<dim_tridiag, dim_start>(
67+
makeEmptySparsityStatic<dim_start, dim_start>(),
68+
makeSparsityStatic<dim_tridiag, dim_start>(
6869
{{0, 0}, {0, 1}, {1, 1}, {1, 3}, {2, 2}, {2, 3}}),
69-
makeEmptySparsity<dim_outer, dim_start>(),
70+
makeEmptySparsityStatic<dim_outer, dim_start>(),
7071
permutation_start,
7172
},
7273
SparsityToFactorizeTridiagonal{
73-
makeSparsity<dim_tridiag, dim_tridiag>(
74+
makeSparsityStatic<dim_tridiag, dim_tridiag>(
7475
{{3, 0}, {4, 0}, {4, 1}, {5, 2}, {6, 1}, {6, 2}}),
75-
makeSparsity<dim_tridiag, dim_tridiag>(
76+
makeSparsityStatic<dim_tridiag, dim_tridiag>(
7677
{{0, 3}, {0, 4}, {1, 4}, {1, 6}, {2, 5}, {2, 6}}),
7778
permutation_tridiag,
7879
},
79-
SparsityToFactorizeLink{makeEmptySparsity<dim_link, dim_tridiag>(),
80-
makeEmptySparsity<dim_link, dim_link>(),
81-
makeEmptySparsity<dim_outer, dim_link>()},
82-
SparsityToFactorizeOuter{makeEmptySparsity<dim_outer, dim_tridiag>(),
83-
makeEmptySparsity<dim_outer, dim_outer>()}};
80+
SparsityToFactorizeLink{makeEmptySparsityStatic<dim_link, dim_tridiag>(),
81+
makeEmptySparsityStatic<dim_link, dim_link>(),
82+
makeEmptySparsityStatic<dim_outer, dim_link>()},
83+
SparsityToFactorizeOuter{
84+
makeEmptySparsityStatic<dim_outer, dim_tridiag>(),
85+
makeEmptySparsityStatic<dim_outer, dim_outer>()}};
8486

8587
using Factorization =
8688
FactorizationRepeatingBlockTridiagonalArrowheadLinked<sparsity, double>;
8789

88-
constexpr auto diag_correct = makeSparsity<dim_tridiag, dim_tridiag>(
90+
constexpr auto diag_correct = makeSparsityStatic<dim_tridiag, dim_tridiag>(
8991
{{3, 0}, {3, 2}, {4, 2}, {4, 3}, {5, 1}, {5, 3}, {5, 4}, {6, 4}, {6, 5}});
9092
CTLDL_TEST_STATIC(isSparsityEqual(Factorization::FactorTridiagDiag::sparsity,
9193
diag_correct));
92-
constexpr auto subdiag_correct = makeSparsity<dim_tridiag, dim_tridiag>(
94+
constexpr auto subdiag_correct = makeSparsityStatic<dim_tridiag, dim_tridiag>(
9395
{{3, 0}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {3, 6},
9496
{4, 2}, {4, 3}, {4, 4}, {4, 5}, {4, 6},
9597
{5, 1}, {5, 5}, {5, 6}});

ctldl/factor_data/factorization_subdiagonal_block.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
namespace ctldl {
1818

19-
template <Sparsity sparsity_in, class Value_,
19+
template <SparsityStatic sparsity_in, class Value_,
2020
PermutationStatic<sparsity_in.numRows()> permutation_row_in =
2121
PermutationIdentity{},
2222
PermutationStatic<sparsity_in.numCols()> permutation_col_in =
2323
PermutationIdentity{}>
2424
class FactorizationSubdiagonalBlock {
2525
public:
26-
static constexpr auto sparsity = makeSparsityCSR(sparsity_in);
26+
static constexpr auto sparsity = makeSparsityStaticCSR(sparsity_in);
2727
static constexpr auto nnz = std::size_t{sparsity.nnz()};
2828
static constexpr auto num_rows = std::size_t{sparsity.numRows()};
2929
static constexpr auto num_cols = std::size_t{sparsity.numCols()};

ctldl/factor_data/sparsity_to_factorize_link.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,27 @@ struct SparsityToFactorizeLink {
3333
static constexpr auto dim_prev = dim_prev_;
3434
static constexpr auto dim = dim_link;
3535
static constexpr auto dim_next = dim_next_;
36-
Sparsity<nnz_prev, dim_link, dim_prev_> prev;
37-
Sparsity<nnz_link, dim_link, dim_link> diag;
38-
Sparsity<nnz_next, dim_next_, dim_link> next;
36+
SparsityStatic<nnz_prev, dim_link, dim_prev_> prev;
37+
SparsityStatic<nnz_link, dim_link, dim_link> diag;
38+
SparsityStatic<nnz_next, dim_next_, dim_link> next;
3939
PermutationStatic<dim_link> permutation = PermutationIdentity{};
4040
};
4141

4242
template <class Prev, class Diag, class Next,
4343
class PermutationIn = PermutationIdentity>
4444
SparsityToFactorizeLink(Prev, Diag, Next, PermutationIn = PermutationIdentity{})
45-
-> SparsityToFactorizeLink<
46-
ctad_t<Sparsity, Prev>::numCols(), ctad_t<Sparsity, Diag>::numRows(),
47-
ctad_t<Sparsity, Next>::numRows(), ctad_t<Sparsity, Prev>::nnz(),
48-
ctad_t<Sparsity, Diag>::nnz(), ctad_t<Sparsity, Next>::nnz()>;
45+
-> SparsityToFactorizeLink<ctad_t<SparsityStatic, Prev>::numCols(),
46+
ctad_t<SparsityStatic, Diag>::numRows(),
47+
ctad_t<SparsityStatic, Next>::numRows(),
48+
ctad_t<SparsityStatic, Prev>::nnz(),
49+
ctad_t<SparsityStatic, Diag>::nnz(),
50+
ctad_t<SparsityStatic, Next>::nnz()>;
4951

5052
template <std::size_t dim_prev, std::size_t dim_link, std::size_t dim_next>
5153
constexpr auto makeEmptySparsityToFactorizeLink() {
52-
return SparsityToFactorizeLink{makeEmptySparsity<dim_link, dim_prev>(),
53-
makeEmptySparsity<dim_link, dim_link>(),
54-
makeEmptySparsity<dim_next, dim_link>()};
54+
return SparsityToFactorizeLink{makeEmptySparsityStatic<dim_link, dim_prev>(),
55+
makeEmptySparsityStatic<dim_link, dim_link>(),
56+
makeEmptySparsityStatic<dim_next, dim_link>()};
5557
}
5658

5759
} // namespace ctldl

ctldl/factor_data/sparsity_to_factorize_outer.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,23 @@ template <std::size_t dim_inner_, std::size_t dim_outer,
3838
struct SparsityToFactorizeOuter {
3939
static constexpr auto dim = dim_outer;
4040
static constexpr auto dim_inner = dim_inner_;
41-
Sparsity<nnz_subdiag, dim_outer, dim_inner_> subdiag;
42-
Sparsity<nnz_diag, dim_outer, dim_outer> diag;
41+
SparsityStatic<nnz_subdiag, dim_outer, dim_inner_> subdiag;
42+
SparsityStatic<nnz_diag, dim_outer, dim_outer> diag;
4343
PermutationStatic<dim_outer> permutation = PermutationIdentity{};
4444
};
4545

4646
template <class Subdiag, class Diag, class PermutationIn = PermutationIdentity>
4747
SparsityToFactorizeOuter(Subdiag, Diag, PermutationIn = PermutationIdentity{})
48-
-> SparsityToFactorizeOuter<
49-
ctad_t<Sparsity, Subdiag>::numCols(), ctad_t<Sparsity, Diag>::numRows(),
50-
ctad_t<Sparsity, Subdiag>::nnz(), ctad_t<Sparsity, Diag>::nnz()>;
48+
-> SparsityToFactorizeOuter<ctad_t<SparsityStatic, Subdiag>::numCols(),
49+
ctad_t<SparsityStatic, Diag>::numRows(),
50+
ctad_t<SparsityStatic, Subdiag>::nnz(),
51+
ctad_t<SparsityStatic, Diag>::nnz()>;
5152

5253
template <std::size_t dim_inner, std::size_t dim_outer>
5354
constexpr auto makeEmptySparsityToFactorizeOuter() {
54-
return SparsityToFactorizeOuter{makeEmptySparsity<dim_outer, dim_inner>(),
55-
makeEmptySparsity<dim_outer, dim_outer>()};
55+
return SparsityToFactorizeOuter{
56+
makeEmptySparsityStatic<dim_outer, dim_inner>(),
57+
makeEmptySparsityStatic<dim_outer, dim_outer>()};
5658
}
5759

5860
} // namespace ctldl

0 commit comments

Comments
 (0)