G-Node / nix

Neuroscience information exchange format
https://readthedocs.org/projects/nixio/
Other
68 stars 36 forks source link

DataView should check the dimensionality of offset and count #786

Closed achilleas-k closed 5 years ago

achilleas-k commented 5 years ago

I could be wrong but I think we don't check the dimensionality of offset and count when creating DataView objects. DataViews are only created internally (users aren't expected to create them manually), so this is probably not strictly necessary, but might be a good bug catcher.

gicmo commented 5 years ago

I think that is implicitly done (DataView.hpp):

if (this->offset + this->count > array.dataExtent()) {
    throw OutOfBounds("Trying to create DataView which is out of bounds");
}

Because comparing the NDSize (offset + count) with dataExtent() will check the dimensionality:

template<typename T>
inline bool NDSize::operator<(const NDSizeBase<T> &lhs, const NDSizeBase<T> &rhs)
{
    if (lhs.size() != rhs.size()) {
        throw IncompatibleDimensions("size must agree to compare",
                                     "NDSizeBase < NDSizeBase ");
    }
achilleas-k commented 5 years ago

You're right. Didn't think to check that. Would you like to add an explicit check? If you think the check in the comparison is enough, just close the issue.

gicmo commented 5 years ago

Would you like to add an explicit check? If you think the check in the comparison is enough, just close the issue.

I think that would be better, yeah, an IncompatibleDimensions with a more specific error message.