- Notifications
You must be signed in to change notification settings - Fork 36
Add accessFlat/indexStrideValue #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@ ## master #273 +/- ## ========================================== + Coverage 90.46% 90.51% +0.05% ========================================== Files 52 52 Lines 10991 11041 +50 ========================================== + Hits 9943 9994 +51 + Misses 1048 1047 -1
Continue to review full report at Codecov.
|
source/mir/ndslice/slice.d Outdated
| return n * _strides[0]; | ||
| } else { | ||
| return indexStride(numIndex(n)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this compiles, but the code is almost the same that was used in FlattenedIterator.
ptrdiff_t valStride()(ptrdiff_t n) @safe scope const { ptrdiff_t _shift; foreach_reverse (i; Iota!(1, N)) { immutable v = n / ptrdiff_t(_lengths[i]); n %= ptrdiff_t(_lengths[i]); static if (i == S) _shift += n; else _shift += n * _strides[i]; n = v; } _shift += n * _strides[0]; return _shift; }There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, any reason to make it public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@9il Not really. indexStride was public and I tried to take the same approach. I can make changes private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ok to make it public, but I am not sure about naming, and we need docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below. Happy to add more docs later today. Flexible on naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, this code is for Canonical and Universal slices. Contiguous should just return the n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
source/mir/ndslice/slice.d Outdated
| } | ||
| | ||
| /// | ||
| auto ref at(size_t n) scope return @trusted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also needs more docs and more verbose name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to add more docs later today. Any suggestion on name? Maybe access or accessFlat? I am flexible.
Along the same lines, should gmean/hmean be renamed geometricMean/harmonicMean? Might need deprecation given that there have been releases...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accessFlag looks good. Existing names in stat are good as well.
source/mir/ndslice/slice.d Outdated
| assert(mut == x); | ||
| } | ||
| | ||
| size_t[N] numIndex(size_t n) @safe scope const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused, can be removed though
Facilitates easier access to slice contents, especially when not contiguous.