Bug 15738 – Problem with std.experimental.ndslice empty()

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-01T18:09:00Z
Last change time
2016-03-09T10:16:47Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2016-03-01T18:09:41Z
This code asserts, but it's correct: void main() { import std.experimental.ndslice: sliced; auto v = [1]; auto s1 = v[].sliced(1, 1); auto s2 = s1[0 .. $, 0 .. 0]; assert(s2.empty); } If one (or more) coordinate has length zero, empty() must be true.
Comment #1 by ilyayaroshenko — 2016-03-03T20:01:54Z
This is feature, empty is empty!0, so it checks only first dimension. In addition, this is very important for optimization reasons. emptyAny method may be added for desirable behavior.
Comment #2 by bearophile_hugs — 2016-03-05T18:03:28Z
(In reply to Илья Ярошенко from comment #1) > This is feature, empty is empty!0, so it checks only first dimension. In > addition, this is very important for optimization reasons. emptyAny method > may be added for desirable behavior. I think it's a trap. empty === enoty!0 is not explicit. So it should be designed the other way, in an explicit way. If you want to add a empty() method, it should work on the whole tensor. If you want to see if one coordinate is empty, you can add a more specialized method, like emptySide, or something similar.
Comment #3 by ilyayaroshenko — 2016-03-05T18:07:45Z
(In reply to bearophile_hugs from comment #2) > (In reply to Илья Ярошенко from comment #1) > > This is feature, empty is empty!0, so it checks only first dimension. In > > addition, this is very important for optimization reasons. emptyAny method > > may be added for desirable behavior. > > I think it's a trap. empty === enoty!0 is not explicit. So it should be > designed the other way, in an explicit way. If you want to add a empty() > method, it should work on the whole tensor. If you want to see if one > coordinate is empty, you can add a more specialized method, like emptySide, > or something similar. Slice is not a container, so there is no reason for such behavior. `empty` must be as fast as possible because a user may use slices with std.algorithm and std.range.