-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partition and ExtendableSquareMatrix data structures #399
base: devel
Are you sure you want to change the base?
Conversation
Corresponding tests created.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #399 +/- ##
==========================================
+ Coverage 72.14% 73.90% +1.76%
==========================================
Files 30 33 +3
Lines 3712 3982 +270
Branches 847 887 +40
==========================================
+ Hits 2678 2943 +265
Misses 738 738
- Partials 296 301 +5 ☔ View full report in Codecov by Sentry. |
Thank you for the PR. I will be reviewing the PR throughout the week. Is that good enough for your needs? |
@Adda0 Thanks for your reaction, yes, that is ok! I have just made few little changes:
|
I have just made one more little change:
|
I have just realized that I had passed several vectors to functions without using constant reference even though these vectors are not modified within corresponding functions, so I have fixed it. Namely:
|
Hey. Sorry for the delay. Still working on it. Things got in the way. |
I have just did one more little change. I have deleted the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My initial thoughts. I did not review the feasibility of the solution, only the format and the overall structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be more readable if we had all class declarations first, and only then all class method definitions. But it might be OK as it is. Any opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestion. I am able to do this if the others agree.
In context of readability, I have to say that there will be one more class in this file in the future (namely PartitionRelationPair
which will combine Partition
and ExtendableSquareMatrix
). It means that there will be several hundred of LOCs added to this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I would probably split as much as possible, into different files and delimiting declarations from definitions if it is not possible otherwise. But that depends on what others have to say on this topic, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Adda0 Thanks for your answer. I have just realized that the current approach can't work. I wrote everything in one header file which contained
- classes with simple declarations of methods inside of
class { ... }
- definitions of class methods oustide of
class { ... }
- inlined ordinary functions
However, I have misunderstood before and the methods were not inlined since they were not defined directly inside of class { ... }
(I thought that it is sufficient that they are class methods to be inlined and the exact location of their definition does not matter). This caused violation of ODR
. Thus, I had to change the structure of the file.
Since several of the methods are quite long, I have decided to split the file into multiple files. Currently (after my last commit), the structure is as follows:
include/mata/utils/partition.hh
contains declaration of thePartition
class and methodsinclude/mata/utils/extendable-square-matrix.hh
contains definitions of theExtendableSquareMatrix
class and its methods (the same for the subclassesCascadeSquareMatrix
,DynamicSquareMatrix
,HashedSquareMatrix
)- The methods are quite short so I kept them inside the
class { ... }
definition and I did not createextendable-square-matrix.cc
file
- The methods are quite short so I kept them inside the
src/partition.cc
contains definitions of thePartition
class methodstests/partition.cc
contains tests which coverPartition
classtests/extendable-square-matrix.cc
contains tests which coverExtendableSquareMatrix
class
Is this ok? I was not sure whether the location of the src/partition.cc
is OK since there is no src/utils
directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would mirror the folder hierarchy for header files in source as well. Having src/utils/partition.cc
seems reasonable to me.
Otherwise, I personally am very happy with this separation. Lukáš should have the last say, however.
…om m_varName to var_name_
…om m_varName to var_name_
Thanks for your suggestions. I have resolved several of them and I will continue later today. The last fix caused few unsuccessful checks but I have not discovered the cause yet, I will inspect it more thoroughly later today. |
… the desired element by now
…e ExtendableSquareMatrix placed after the definition of the class
I have made several changes in the In the previous version, In the current version,
The other methods were changed to reflect the current representation of the partition. |
This looks beautiful. I will review the changes during this week. The description above looks great, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good to me overall. I have fixed a few typos and simplified some constructs, which will be added in the following commits.
Before merging, all debug prints should be removed from the tests.
When all of these issues are resolved, I think we can merge the PR.
Considering your time constraints, would you like me to resolve these issues so that you can focus on your own problems?
src/partition.cc
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should go to src/utils/partition.cc
. Since we do not have a src/utils/
folder, I would say we should create one and move this file there.
* | ||
**/ | ||
|
||
using MatrixType = enum MatrixType { None, Cascade, Dynamic, Hashed }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use enum class
. It is much safer to use (prevents accidental implicit conversions). You use the elements in this enum as elements of an enum class in the code, anyway.
|
||
// type of the matrix which will be chosen as soon as the | ||
// child class will be created | ||
MatrixType m_type{MatrixType::None}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MatrixType m_type{MatrixType::None}; | |
MatrixType type_{MatrixType::None}; |
If the m_
stands only for a member
. We use <name>_
for private member instead of m_<name>
.
* @param[in] j column of the matrix | ||
* @param[in] value a value which will be assigned to the memory cell | ||
*/ | ||
virtual void set(size_t i, size_t j, T value = T()) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default arguments on a virtual method should be prohibited. It a very error-prone feature of C++. See SO discussion, for example.
For the sake of clarity, I think we should split this method into
void set(i, j) // Running the default constructor on the type.
void set(i, j, value) // Passing the user-given value by value.
* @param[in] placeholde value which will be assigned to the | ||
* newly allocated memory cells | ||
*/ | ||
virtual void extend(T placeholder = T()) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as with set()
should be done for extend()
. So:
void extend() // Extending with default initialized values.
void extend(T placeholder) // Extending with a user-specified value.
* the default value of the type T. | ||
* @brief changes the n x n matrix to the (n+1) x (n+1) matrix with | ||
* copying of the existing data | ||
* @param[in] placeholde value which will be assigned to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no placeholder in the function arguments. Also, typo.
tests/partition.cc
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove debug prints in the tests.
Due to some performance issues with this approach, I am converting the PR to a draft until we decide to work on this PR further. @kocotom, when you have free time again, feel free to let me know how to proceed with this PR further. No rush, though. |
I have implemented two data structures:
Partition
, an efficient representation of set partition with the ability toExtendableSquareMatrix
, an abstract representation of binary relation over a set, a matrix of counters etc. with the ability ton x n
matrix to the(n+1) x (n+1)
matrix (ifn < capacity
)I have also implemented three concrete representations of the
ExtendableSquareMatrix
which inherit from that structure and implement the virtual methods get, set and extend:CascadeSquareMatrix
(I'm not sure whether the name is appropriate)DynamicSquareMatrix
HashedSquareMatrix
These data structures are implemented in the file
partition-relation-pair.hh
. Soon there will be a data structurePartitionRelationPair
which use combination ofPartition
andExtendableSquareMatrix
but it is not fully done yet so I have not included it.I have also added a lot of tests which work with these data structures.
The code is massively commented to ease understanding.