You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In https://github.com/solvcon/modmesh/pull/107/files#r928056902 (and the associated issue #52 (comment)), we decided to make SimpleArray support view. This is an extensive subject. We can probably start the discussions with the following points: (i) meta data of array and view, (ii) memory management, and (iii) runtime and compile-time behaviors.
Meta data
An array is a combination of a contiguous buffer and the associated meta data, whose major components are shape and stride. A view shares the same buffer with an array but uses different meta data. In this sense, a view is also an array, and probably we can use the same object to represent both a (full) array and a (partial) view. (A special case of a view is to use exactly the same shape and stride as the associated array.)
The current implementation of SimpleArray keeps a clear separation between the buffer and the meta data. The memory buffer is managed by using the class ConcreteBuffer. The meta data are kept right in the class template SimpleArray.
Memory management
The term "view" implies that it does not create the memory buffer. I am not sure if a view should own the buffer. If it does, an atomic (or lock) is required in the creation of a view. If not, it is faster but more susceptible to memory errors. Both are useful.
Multiple views or arrays may own the same single buffer. For debugging we may want to know where to find the owners of the buffer. A global tracker object may be made to support the debugging feature.
Modmesh extensively uses arrays as lookup tables. We have not had a columnar container but SimpleArray should be part of it.
Runtime and compile time
Currently SimpleArray calculates indices during runtime. SimpleArray view should also support runtime index calculation. But it is more likely that a view represents a small chunk of the buffer and reduced dimension. For the small array or view it makes sense to determine the index value during compile time.
To improve efficiency of a small view it also makes sense to avoid unnecessary view object creation. The view object may remember the calculated index and work like an iterator.
Other notes
There are already array and view libraries available, e.g., https://xtensor.readthedocs.io/en/latest/ . Modmesh implements its own array code for full control for optimization and memory management. The arrays are the foundation of modmesh and we would like to control everything of it. Although third-party libraries offer more features, they also involve more efforts in maintenance. It may or may not be more productive in the end of the day.
SimpleArray should be made to support general-purpose array operations, but the focus on modmesh may not be lost. It should be kept simple, like one or two thousand lines of code. It should always be possible to pack (amalgamate) it in a single header file.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In https://github.com/solvcon/modmesh/pull/107/files#r928056902 (and the associated issue #52 (comment)), we decided to make
SimpleArray
support view. This is an extensive subject. We can probably start the discussions with the following points: (i) meta data of array and view, (ii) memory management, and (iii) runtime and compile-time behaviors.Meta data
An array is a combination of a contiguous buffer and the associated meta data, whose major components are shape and stride. A view shares the same buffer with an array but uses different meta data. In this sense, a view is also an array, and probably we can use the same object to represent both a (full) array and a (partial) view. (A special case of a view is to use exactly the same shape and stride as the associated array.)
The current implementation of
SimpleArray
keeps a clear separation between the buffer and the meta data. The memory buffer is managed by using the classConcreteBuffer
. The meta data are kept right in the class templateSimpleArray
.Memory management
The term "view" implies that it does not create the memory buffer. I am not sure if a view should own the buffer. If it does, an atomic (or lock) is required in the creation of a view. If not, it is faster but more susceptible to memory errors. Both are useful.
Multiple views or arrays may own the same single buffer. For debugging we may want to know where to find the owners of the buffer. A global tracker object may be made to support the debugging feature.
Modmesh extensively uses arrays as lookup tables. We have not had a columnar container but
SimpleArray
should be part of it.Runtime and compile time
Currently
SimpleArray
calculates indices during runtime.SimpleArray
view should also support runtime index calculation. But it is more likely that a view represents a small chunk of the buffer and reduced dimension. For the small array or view it makes sense to determine the index value during compile time.To improve efficiency of a small view it also makes sense to avoid unnecessary view object creation. The view object may remember the calculated index and work like an iterator.
Other notes
There are already array and view libraries available, e.g., https://xtensor.readthedocs.io/en/latest/ . Modmesh implements its own array code for full control for optimization and memory management. The arrays are the foundation of modmesh and we would like to control everything of it. Although third-party libraries offer more features, they also involve more efforts in maintenance. It may or may not be more productive in the end of the day.
SimpleArray
should be made to support general-purpose array operations, but the focus on modmesh may not be lost. It should be kept simple, like one or two thousand lines of code. It should always be possible to pack (amalgamate) it in a single header file.Beta Was this translation helpful? Give feedback.
All reactions