-
Notifications
You must be signed in to change notification settings - Fork 704
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
dim.h: truncate() should be documented #945
Comments
This removes all dimensions of size 1 from the end of the dim object. A PR documenting this would be welcome. |
If so, I think the implementation is not that efficient. /**
* \brief [TODO]
* \details [long description]
* \return [description]
*/
inline Dim truncate() const {
Dim r = *this;
unsigned int m = 1;
unsigned int s = size();
for (unsigned int i = 1; i < s; ++i)
if (size(i) > 1) m = i + 1;
r.resize(m);
return r;
}
inline unsigned int size() const {
return batch_size() * bd;
}
inline unsigned int batch_size() const {
unsigned int p = 1;
for (unsigned int i = 0; i < nd; ++i) p *= d[i];
return p;
}
inline void resize(unsigned int i) {
// if i < nd, it will remove size of dimension 1.
while(nd < i)
d[nd++] = 1;
nd = i;
}
inline unsigned int size(unsigned int i) const { return (*this)[i]; }
inline unsigned int operator[](unsigned int i) const { return i < nd ? d[i] : 1; } The For example:
I will try to figure out why dimensions of 1 should be removed in |
It might be worth considering to remove the dimension truncation for better consistency? That's what already happened for some operations touched by #776. |
* remote use GPU:0 by default when use --dynet-gpu * fix error * Comment DeviceMempool enum * #945 1. add doc for Dim::truncate 2. reimplement Dim::truncate 3. add tests for dim
fixed by #970 I think |
size(i)
definitions can not be found. And I want to know the purpose of truncate which means description. And it is related to find the problem of cdiv (#892)Thanks in advance.
The text was updated successfully, but these errors were encountered: