Skip to content

Commit 41d2068

Browse files
committed
<fix>[PWMap::inverse]: fixed PWMap inverse singleton domain and constant expression
1 parent 0726f39 commit 41d2068

5 files changed

Lines changed: 19 additions & 6 deletions

File tree

sbg/dom_ord_pwmap.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ DomOrdPWMap DomOrdPWMap::inverse() const
440440
DomOrdPWMap result;
441441

442442
for (const MapEntry& entry : _pieces) {
443-
Map m = entry.map();
444-
result.emplace(Map{m.image(), m.law().inverse()});
443+
result.emplace(entry.map().inverse());
445444
}
446445

447446
return result;

sbg/map.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ Set Map::preImage(const Set& subcodom) const
128128
.intersection(_domain);
129129
}
130130

131+
Map Map::inverse() const
132+
{
133+
if (_domain.cardinal() == 1) {
134+
return Map{image(), _domain.minElem()};
135+
}
136+
137+
return Map{image(), _law.inverse()};
138+
}
139+
131140
Map Map::composition(const Map& other) const
132141
{
133142
Set result_domain = _domain.intersection(other.image());

sbg/map.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ class Map {
113113
* @param subcodom Set of elements in the image of the map for which the
114114
* pre image will be calculated.
115115
*/
116-
Set preImage(const Set& subcodom) const; // opt
116+
Set preImage(const Set& subcodom) const;
117+
118+
/**
119+
* @brief Calculates the inverse of a map.
120+
* Precondition: map should be bijective.
121+
*/
122+
Map inverse() const;
117123

118124
/**
119125
* @brief Calculate the composition of \p this with \p other, i.e.

sbg/ord_pwmap.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ OrdPWMap OrdPWMap::inverse() const
416416
OrdPWMap result;
417417

418418
for (const MapEntry& entry : _pieces) {
419-
Map m = entry.map();
420-
result.emplace(Map{m.image(), m.law().inverse()});
419+
result.emplace(entry.map().inverse());
421420
}
422421

423422
return result;

sbg/unord_pwmap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ UnordPWMap UnordPWMap::inverse() const
248248
UnordPWMap result;
249249

250250
for (const Map& m : _pieces) {
251-
result.emplaceBack(m.image(), m.law().inverse());
251+
result.pushBack(m.inverse());
252252
}
253253

254254
return result;

0 commit comments

Comments
 (0)