Giter Club home page Giter Club logo

Comments (4)

dsharlet avatar dsharlet commented on June 2, 2024

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.

benweiss avatar benweiss commented on June 2, 2024

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.

dsharlet avatar dsharlet commented on June 2, 2024

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.

benweiss avatar benweiss commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.