Comments (4)
I think this is the same problem as here: https://github.com/dsharlet/array/blob/master/test/shape.cpp#L184
This has come up before in other contexts too. The problem is that when the extent is 1, there's no real constraint on the stride, so the automatic stride algorithm just gives it something that seems reasonable to it. I think this is hard to fix without baking some crappy heuristic into the algorithm. @fbleibel-g might have more information about those other contexts he can share with you.
from array.
Hi Dillon,
I tried adding a few lines to solve this issue, and it seemed to work. In 'is_stride_ok()' in array.h, I did the following (inserted the middle 'if()' block):
if (is_unresolved(dim.stride())) {
// If the dimension has an unknown stride, it's OK, we're
// resolving the current dim first.
return true;
}
if (extent == 1 && abs(stride) == abs(dim.stride()) && dim.extent() > 1) {
// Special-cases "extent == 1" to avoid unexpectedly giving a stride of 1 for
// outer dimensions; e.g. the y-stride for single-row interleaved images, or
// the plane-stride for single-plane Planar images.
return false;
}
if (dim.extent() * abs(dim.stride()) <= stride) {
// The dim is completely inside the proposed stride.
return true;
}
This "fixes" the cases mentioned. It also enables the commented-out test you mentioned above. Curious what you think? If it looks ok, I can submit it as a PR, or feel free to incorporate it.
Thanks,
Ben
from array.
Hmm, that is a lot less crufty than I thought would be necessary.
I played around with this a bit and added some more tests to see what it does in these cases:
// Stride one dimensions mixed in with extent 1 dimensions.
check_resolved_strides<3>({1, 1, {0, 2, 1}}, {2, 2, 1});
check_resolved_strides<3>({1, {0, 2, 1}, 1}, {2, 1, 2});
check_resolved_strides<3>({1, 10, {0, 2, 1}}, {2, 2, 1});
check_resolved_strides<3>({5, {0, 2, 1}, 1}, {2, 1, 10});
It does produce reasonable results in these cases.
I think you should send it as a PR (with the extra tests above), this is a really nice improvement.
from array.
Thanks Dillon, I've sent a PR with my changes and your added tests. Let me know if it needs a CLA.
The only non-obvious side effect I've encountered from this change is that it is no longer possible to implicitly cast between interleaved and planar single-channel images, since the channel strides now differ. Probably this is a good thing; it's most likely a bug if anyone's code was trying to do that. But the assertion it triggers could trivially be modified to still allow it, if there were any reason to.
from array.
Related Issues (20)
- clang with -O3 generates significantly worse code than with -O2 HOT 1
- whole-matrix einsum is slower than hand-written code HOT 2
- Remove copies from Einstein expression construction HOT 1
- Consider removing make_dense* functions
- Comparison with mdspan/mdarray HOT 1
- auto_allocator could fall back to a base allocator when the allocation is too big
- array's move constructor default constructs an allocator before using the other allocator
- Reshape an array in runtime HOT 1
- Host doxygen generated docs somewhere HOT 1
- Template argument order issue in make_* functions that return an array
- Write a FAQ with examples of how to do common tasks HOT 1
- Need a version of generate() that takes indices HOT 3
- Numpy -> nda::array cheat sheet?
- Alias for a fixed size array allocated on the stack HOT 6
- call of overloaded βfor_each_value_in_order<(nda::shape<>::rank() - 1)>(nda::shape<>::index_type, void (&)(const int&, int&), std::pair<const int*, std::tuple<> >&, std::pair<int*, std::tuple<> >&)β is ambiguous HOT 4
- `make` broken on Apple Silicon Macs with Xcode HOT 1
- reinterpret_shape doesn't resolve bare shape HOT 3
- const_cast for array_ref<const T> HOT 8
- errors.cpp test is failing silently on gcc
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from array.