-
Notifications
You must be signed in to change notification settings - Fork 4
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
Unify Methods for Array64 and Arrayb #8
Comments
I like the idea of combining the ndim meta-data. Shape, error, and the like will be the same no matter the underlying type. The use of Rather than trying to go all-or-nothing on combining, I'd suggest we look at combining the meta-data, while maintaining type-specific data buffers: type nDimArray struct {
shape []int
strides []int
err error
debug, stack string
}
// Array64 is an n-dimensional array of float64 data
type Array64 struct {
nDimArray
data []float64
}
// Arrayb is an n-dimensional array of boolean values
type Arrayb struct {
nDimArray
data []bool
} With this design, we can completely hoist Shape, Reshape, Flatten, and all error handling into |
Thanks for the input, I didn't know that! EDIT: moved the rest of this comment to new issue |
I submitted a pull request that just implements the new layout and makes fixes the all methods to use it. How are the methods on nDimMetadata supposed to access data? func (a *nDimMetadata) GetErr() (err error) {
if a == nil || (a.data == nil && a.err == nil) {
return NilError
}
err = a.err
a.err, a.debug, a.stack = nil, "", ""
return
} It now throws an error because a nDimMetadata obviously has no field data. What is the cleanest way to get around this? The data is also accessed in a lot of methods that could be generalized otherwise. |
For those methods, I was using |
There is a lot of redundancy in the Array64 and Arrayb methods. Quite a few of them are exactly the same, except for the input/return type.
Consider e.g. the Reshape() method of Array64 and Arrayb: The are identical, the only difference beeing in the declaration:
vs.
This is not specific to this example and applies for a lot of code.
To simplify the code it would be possible to add a general n-Dimensional structure independent to the underlying type. The type of data (bool for Arrayb and float64 for Array64) would be encapsulated in a interface.
This would be a possible implementation:
Methods that are identical for both Array types could be implemented on nDimObject that way.
I will create a pull request on a separate branch. It sure removes a lot of code and simplifies it (in my opinion) a lot.
I understand this is a major change to the structure of the project and you me want to go in a different direction. Let me know what you think of the idea!
P.S. this approach would make it a lot easier to implement new types of array (maybe for ints?) in the future if needed.
The text was updated successfully, but these errors were encountered: