Enable two-dimensional array in the existing data structure#51
Enable two-dimensional array in the existing data structure#51mphoward merged 13 commits intorefactor-anisofrom
Conversation
mphoward
left a comment
There was a problem hiding this comment.
Generally a good first pass! Here are some comments that need addressing / clarification.
include/flyft/data_layout.h
Outdated
| { | ||
| class DataLayout | ||
| { | ||
| //! DataLayout class generates the template for the custom data types used in the software |
There was a problem hiding this comment.
These are not proper doxygen comments. Please read about how you mark either short vs. long descriptions, and we can discuss if you have questions.
src/data_layout.cc
Outdated
| DataLayout::DataLayout() | ||
| { | ||
| const std::vector<int>& shape_ = {0, 0}; | ||
| } |
There was a problem hiding this comment.
Wouldn't the default be an empty array now?
| DataLayout::DataLayout() | |
| { | |
| const std::vector<int>& shape_ = {0, 0}; | |
| } | |
| DataLayout::DataLayout() | |
| { | |
| } |
src/data_layout.cc
Outdated
| //! Strided indexing scheme for converting | ||
| //! N dimensional array into one dimensional array |
There was a problem hiding this comment.
Doxygen comments do not go in regular code, use regular comments
src/data_layout.cc
Outdated
| int DataLayout::size() const | ||
| std::vector<int> DataLayout::size() const | ||
| { | ||
| return shape(); |
There was a problem hiding this comment.
This isn't right anymore: you want to take the product of the shape_ to return the total size
include/flyft/data_view.h
Outdated
| reference operator()(const std::vector<int>& idx) const | ||
| { | ||
| return data_[layout_(start_ + idx)]; | ||
| std::transform(idx.begin(), idx.end(), start_, idx.begin(), std::plus<int>()); |
There was a problem hiding this comment.
What is this doing, and why can't you just pass the idx directly? It doesn't seem like this should do anything / work because idx is const.
There was a problem hiding this comment.
I was trying elementwise summation of the idx vector with start_ to replicate the operation performed in the previous implementation of this function without using loops
There was a problem hiding this comment.
Oh, got it! Yes, this is necessary then, but you should use a new local variable to hold the result. std::transform is essentially a loop, so I doubt it will be more performant than a loop.
include/flyft/data_view.h
Outdated
| } | ||
|
|
||
| private: | ||
| /// @brief |
There was a problem hiding this comment.
That was auto-generated by accident. I will remove it
include/flyft/data_layout.h
Outdated
| //! DataLayout | ||
| /*! | ||
| * Generates data structure for the custom data types used in the software. | ||
| * The class provides get and set functions for the array index and implements N-dimensional array | ||
| * mapping into one dimensional array using strided indexing scheme. | ||
| */ |
There was a problem hiding this comment.
The short description should be what the object is (the class name will be part of what doxygen generates), then the long description should describe what the class does (potentially with examples longer term)
| //! DataLayout | |
| /*! | |
| * Generates data structure for the custom data types used in the software. | |
| * The class provides get and set functions for the array index and implements N-dimensional array | |
| * mapping into one dimensional array using strided indexing scheme. | |
| */ | |
| //! Multidimensional array layout | |
| /*! | |
| * DataLayout maps an N-dimensional index to one-dimensional | |
| * index using row-major ordering. Negative indexes are supported | |
| * and interpreted as relative to the zero-index. | |
| */ |
include/flyft/data_layout.h
Outdated
| //! Constructor for the DataLayout | ||
| /*! | ||
| * \param shape_ Shape of the index array | ||
| */ |
There was a problem hiding this comment.
Don't include class name in short descriptions. Use periods to end parameter descriptions. Parameter name needs to match argument name.
| //! Constructor for the DataLayout | |
| /*! | |
| * \param shape_ Shape of the index array | |
| */ | |
| //! Constructor | |
| /*! | |
| * \param shape Number of elements in array along each dimension. | |
| */ |
include/flyft/data_layout.h
Outdated
| // Getter for the class | ||
| int operator()(const std::vector<int>& idx) const; |
There was a problem hiding this comment.
This is not a doxygen comment and not descriptive
| // Getter for the class | |
| int operator()(const std::vector<int>& idx) const; | |
| //! Map a multidimensional index to a one-dimensional index | |
| /*! | |
| * \param idx Multidimensional index. | |
| * \return One-dimensional index. | |
| * | |
| * Row-major ordering is used. | |
| */ | |
| int operator()(const std::vector<int>& idx) const; |
include/flyft/data_layout.h
Outdated
| // Setter for shape | ||
| std::vector<int> shape() const; |
There was a problem hiding this comment.
This is not doxygen and it is also not a setter. It's OK, though, to only use a short description for getters.
| // Setter for shape | |
| std::vector<int> shape() const; | |
| //! Shape of the layout in each dimension | |
| std::vector<int> shape() const; |
include/flyft/data_layout.h
Outdated
|
|
||
| // Setter for shape | ||
| std::vector<int> shape() const; | ||
| // Getter for shape |
There was a problem hiding this comment.
| // Getter for shape | |
| //! Total number of elements in the layout |
| bool operator==(const DataLayout& other) const; | ||
| bool operator!=(const DataLayout& other) const; |
There was a problem hiding this comment.
| bool operator==(const DataLayout& other) const; | |
| bool operator!=(const DataLayout& other) const; | |
| //! Test if two layouts are equal | |
| /*! | |
| * \return True if the layouts have the same shape. | |
| */ | |
| bool operator==(const DataLayout& other) const; | |
| //! Test if two layouts are not equal | |
| bool operator!=(const DataLayout& other) const; |
include/flyft/data_layout.h
Outdated
|
|
||
| private: | ||
| int shape_; | ||
| std::vector<int> shape_; |
There was a problem hiding this comment.
| std::vector<int> shape_; | |
| std::vector<int> shape_; //!< Multidimensional shape of layout |
src/data_layout.cc
Outdated
| { | ||
|
|
||
| DataLayout::DataLayout() : shape_(0) {} | ||
| // Default constructor |
There was a problem hiding this comment.
I tend to like putting all the doxygen comments in the header. They only need to be in one spot.
include/flyft/data_layout.h
Outdated
| { | ||
| //! Multidimensional array layout | ||
| /*! | ||
| * DataLayout maps an N-dimensional index to one-dimensional |
There was a problem hiding this comment.
| * DataLayout maps an N-dimensional index to one-dimensional | |
| * DataLayout maps an N-dimensional index to a one-dimensional |
include/flyft/data_layout.h
Outdated
| public: | ||
| DataLayout(); | ||
| explicit DataLayout(int shape_); | ||
| //! Constructor for the DataLayout |
There was a problem hiding this comment.
| //! Constructor for the DataLayout | |
| //! Constructor |
include/flyft/data_layout.h
Outdated
| explicit DataLayout(int shape_); | ||
| //! Constructor for the DataLayout | ||
| /*! | ||
| * \param shape_ Shape of the index array. |
There was a problem hiding this comment.
| * \param shape_ Shape of the index array. | |
| * \param shape Shape of the index array. |
include/flyft/data_layout.h
Outdated
| //! Shape of the layout in each dimension | ||
| std::vector<int> shape() const; | ||
|
|
||
| //! Shape of the layout in each dimension |
There was a problem hiding this comment.
| //! Shape of the layout in each dimension | |
| //! Total number of elements in the layout |
include/flyft/data_view.h
Outdated
| /*! | ||
| * DataView provides ability to view a certain section of the multidimensional array | ||
| */ | ||
|
|
include/flyft/data_view.h
Outdated
| //! Overloading the constructor | ||
| /*! | ||
| * \param data_ Pointer to the data. | ||
| * \param layout_ Layout of the data. | ||
| * \param start_ Start of the array. | ||
| * \param end_ End of the array. | ||
| */ | ||
|
|
||
| DataView() : DataView(nullptr, DataLayout()) {} | ||
|
|
||
| DataView(pointer data, const DataLayout& layout) : DataView(data, layout, 0, layout.shape()) {} |
There was a problem hiding this comment.
You need to document each constructor with the actual arguments of it, as they are named in the signature of the function. Documentation is needed for the third constructor still along with a short description.
| //! Overloading the constructor | |
| /*! | |
| * \param data_ Pointer to the data. | |
| * \param layout_ Layout of the data. | |
| * \param start_ Start of the array. | |
| * \param end_ End of the array. | |
| */ | |
| DataView() : DataView(nullptr, DataLayout()) {} | |
| DataView(pointer data, const DataLayout& layout) : DataView(data, layout, 0, layout.shape()) {} | |
| //! Empty constructor | |
| /*! | |
| * The default is a null pointer to a zero-size layout. | |
| */ | |
| DataView() : DataView(nullptr, DataLayout()) {} | |
| //! Constructor | |
| /*! | |
| * \param data Pointer to the data. | |
| * \param layout Layout of the data. | |
| */ | |
| DataView(pointer data, const DataLayout& layout) : DataView(data, layout, 0, layout.shape()) {} |
include/flyft/data_view.h
Outdated
| } | ||
|
|
||
| reference operator()(int idx) const | ||
| //! Map multi-dimensional array to one dimension |
There was a problem hiding this comment.
This is not what this function does... it returns a reference to the referenced element of the data.
include/flyft/data_view.h
Outdated
| //! Shape of the one-dimensional array | ||
| int shape() const | ||
| { | ||
| return end_ - start_; | ||
| } | ||
|
|
||
| //! Number of elements in the one-dimensional array | ||
| int size() const | ||
| { | ||
| return shape(); | ||
| } |
There was a problem hiding this comment.
These are not correct for a multidimensional layout... the shape should be multidimensional. Additionally, I am noticing that start and end need to be generalized to be multi-indexes.
size should be the total number of elements in the view, though.
| //! Test if pointer to the data is not a null pointer | ||
| /*! | ||
| * \return True if pointer is not a null pointer. | ||
| */ | ||
| explicit operator bool() const | ||
| { | ||
| return (data_ != nullptr); | ||
| } |
There was a problem hiding this comment.
This comment is describing the implementation, not the actual method. A DataView is not null if it is a view of valid data.
mphoward
left a comment
There was a problem hiding this comment.
This looks good to go! I had one small comment: let me know if you want to make that change, and otherwise I'll merge so we can move onto the next steps.
src/data_layout.cc
Outdated
| int N = shape_.size(); | ||
| int size = 1; | ||
| for (int i = 0; i < N; ++i) | ||
| { | ||
| size *= shape_[i]; | ||
| } | ||
| return size; |
There was a problem hiding this comment.
Could this be done with std::accumulate like you did in data_view.h? I'm good with this solution if you prefer, though!
There was a problem hiding this comment.
I will change this to the same implementation as the data_view.h one so that it is consistent. Thank you for noticing it!
mphoward
left a comment
There was a problem hiding this comment.
Thanks! I just created a new branch refactor-aniso that we can use to stage these changes as we work on them. Please base your next branches and PRs off refactor-aniso, thanks!
No description provided.