Bug 17742 – std.range.transposed does not have opIndex

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-08-10T23:32:39Z
Last change time
2017-12-18T22:56:19Z
Assigned to
No Owner
Creator
Vladimir Panteleev

Comments

Comment #0 by dlang-bugzilla — 2017-08-10T23:32:39Z
auto ror = 5.iota.map!(y => 5.iota.map!(x => x * y).array).array; assert(ror[3][2] == 6); // OK auto result = ror.transposed; assert(result[3][2] == 6); // Error
Comment #1 by schveiguy — 2017-10-30T15:37:39Z
Vladimir, would appreciate your input on the PR: https://github.com/dlang/phobos/pull/5805 Currently, transposed uses `filter` to remove elements from the range transposition when the underlying column has become empty. So for instance: assert([[1,2,3], [4,5], [6,7,8]].transposed.equal([[1,4,6], [2,5,7], [3,8]]); Note the jaggedness of the range of ranges changes in weird ways, especially when holes appear in the middle. While this may be reasonable, it precludes performing opIndex on an element of the transposed result. So while transposed can be indexed if the ranges individually can be indexed, the resulting elements cannot be, making your code example unimplementable.
Comment #2 by dlang-bugzilla — 2017-10-30T15:57:42Z
Ouch. I didn't realize transposed works with jagged arrays. Considering this issue and that transposed doesn't work with static arrays (because they're not ranges), maybe a separate function would be better, which is closer to the matrix operation (in supporting indexing and static arrays).
Comment #3 by github-bugzilla — 2017-11-07T16:19:26Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/ac29b7bada5ba51fe053f3d4e274eb3a0e2b3417 Fix Issue 17742 - std.range.transposed does not have opIndex https://github.com/dlang/phobos/commit/b95f73a2c79689768b4a5d8df337882dccba844f Merge pull request #5805 from Darredevil/issue-17742-transposed-opIndex Fix Issue 17742 - std.range.transposed does not have opIndex merged-on-behalf-of: Steven Schveighoffer <[email protected]>
Comment #4 by github-bugzilla — 2017-12-18T22:56:19Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/ac29b7bada5ba51fe053f3d4e274eb3a0e2b3417 Fix Issue 17742 - std.range.transposed does not have opIndex https://github.com/dlang/phobos/commit/b95f73a2c79689768b4a5d8df337882dccba844f Merge pull request #5805 from Darredevil/issue-17742-transposed-opIndex