-
Notifications
You must be signed in to change notification settings - Fork 74
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
Cereal for Array, ArrayBase #372
Conversation
…nto cereal-arraybase
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.
wow, this was a more complex serialization, hope ArrayBase is the only (bad) exception.
I don't understand ArrayBase that deeply, but:
- I like the cleanup of veriables & methods
- if the new cerialization works, we're golden 👌
- please use c++ casts (
static_cast<T>(val)
) at the few places, rather than plain C-casts ((T)val
)
src/nupic/ntypes/ArrayBase.cpp
Outdated
NTA_CHECK(type_ == NTA_BasicType_SDR) << "Does not contain an SDR object"; | ||
if (buffer_ == nullptr) { | ||
std::vector<UInt> zeroDim; | ||
zeroDim.push_back(0u); | ||
allocateBuffer(zeroDim); // Create an empty SDR object. | ||
} | ||
SDR& sdr = *((SDR *)buffer_.get()); | ||
sdr::SDR& sdr = *((sdr::SDR *)buffer_.get()); |
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.
nit, can you use static_cast ? (or other relevant c++ casting), it does better checks that the plain C-cast
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.
nit, can you use static_cast ?
I just ever got into the habit of using static_cast. I know what C casting does. Not so sure about the C++ casting. But I guess I should lean to use the new stuff.
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.
have a look, it's a nice c++ feature: https://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-const-cast-and-reinterpret-cast-be-used
My layman's version:
- it's possible to grep sourcecode for the cast
- no performance penalty
- does some checks
- 1st goto version:
static_cast<T>(val)
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'd like to see these implemented for the PR
a.setCount(maxsize); | ||
} | ||
// TODO: Comment this out until we are sure that it is not needed. | ||
//if (offset == 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.
what was this for?Why we don't use it but you wanna keep that?
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.
It was for handling Fan-in merge when buffers could be variable length (Sparse arrays). I don't think any other code was depending on this logic being here so if nothing breaks I will remove the commented out code.
I will need another review before the master changes again. Thanks. |
I will, but you haven't made changes on the last review (?) |
…nto cereal-arraybase
So, you really are going to make me change my coding style. |
Hmmm,
I am going to assume that is not me. |
I am going to be away from my computer for the rest of the day. |
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 the c++ casting fixes, David, the code looks 💯 now!!
- I've fixed the un/signed compared in the test;
- gtest is really bad at hinting where (such small) problem happens, so these are always a PIA
I have lots more cast fixes coming...so don't push to master yet. |
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.
Great having the harderst class Cerealed 👍 👍
Thank you!
oh, you..stop it, you are spoiling me with goodness 😄 This PR has already 👍 from me, so do as you want. You can merge and make the other casts a separate PR. |
I am still getting errors caused by the type of CellIdx
|
Does your compiler not show those warnings? |
And....
|
To be consistent....we should make ALL size related things size_t. This includes the dimensions. |
Oh, and what about the sparse array elements... aren't they also size related? Probably should keep those at UInt32. |
No! (gcc 7.3, linux), I thought those had gone away for you. Try a clean build...
we can't end up with everything size_t'ed :) SDR_sparse_t elements (are now sdr::ElemSparse type) and are/must be matched with connections::CellIdx (so yes, now UInt32, but can change) |
I see them only when I do a clean build. |
That's very strange! can you open an issue for that? Event the CI guys here are satisfied 🤔 |
I am running a unit test and if that passes I will push some more changes. |
crashed. |
let's merge this, and the other can come later.. |
Maybe you can help with this....
Trying to serialize the Dimensions class. This is a subclass of std::vector The above code crashes deep inside the cereal templates (about 5 levels deep). So obviously it does not like something. I have a social engagement in 15 min so I will take this up in the morning. Will push what I have so you can review all of casts..... you asked for them. |
I've reverted the last 2 changes in this PR, to merge this as "cereal", and I'll put them in a new one.
maybe a static/dynamic cast? PS: the new extra casts break some tests, we can fix them, but no need to sweat it. I meant please use the casts for new code, but we don't have to convert all the existing codebase atonce now. |
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.
👍
Ok, I will continue with the Cereal conversions. I have one more PR for Spec and friends (Collection, Scaler, and Value). That would complete all of the lower level modules in ntypes and types. Then I can start in on algorithms, followed by regions and then NetworkAPI. |
This adds Array and ArrayBase to Cereal serialization.