Thread overview | |||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 02, 2018 stride in slices | ||||
---|---|---|---|---|
| ||||
Proposal: [a..b;m] m is the stride, if ; is not a good char then |, :, !, or # could be good chars. |
June 02, 2018 Re: stride in slices | ||||
---|---|---|---|---|
| ||||
Posted in reply to DigitalDesigns | On Saturday, 2 June 2018 at 18:49:51 UTC, DigitalDesigns wrote:
> Proposal:
>
> [a..b;m]
>
> m is the stride, if ; is not a good char then |, :, !, or # could be good chars.
Ranges work for this and don’t need special syntax. Just saying.
|
June 03, 2018 Re: stride in slices | ||||
---|---|---|---|---|
| ||||
Posted in reply to DigitalDesigns | On Saturday, 2 June 2018 at 18:49:51 UTC, DigitalDesigns wrote:
> Proposal:
>
> [a..b;m]
>
> m is the stride, if ; is not a good char then |, :, !, or # could be good chars.
This is exactly what std.range.stride does. The syntax [a..b;m] directly translates to [a..b].stride(m).
|
June 03, 2018 Re: stride in slices | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Sunday, 3 June 2018 at 07:30:56 UTC, Meta wrote: > On Saturday, 2 June 2018 at 18:49:51 UTC, DigitalDesigns wrote: >> Proposal: >> >> [a..b;m] >> >> m is the stride, if ; is not a good char then |, :, !, or # could be good chars. > > This is exactly what std.range.stride does. The syntax [a..b;m] directly translates to [a..b].stride(m). We even have slide which is a generalization of stride (striding is sliding with a window size of 1): [a..b].slide(1, m) https://dlang.org/phobos/std_range.html#slide |
June 03, 2018 Re: stride in slices | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Sunday, 3 June 2018 at 07:30:56 UTC, Meta wrote:
> On Saturday, 2 June 2018 at 18:49:51 UTC, DigitalDesigns wrote:
>> Proposal:
>>
>> [a..b;m]
>>
>> m is the stride, if ; is not a good char then |, :, !, or # could be good chars.
>
> This is exactly what std.range.stride does. The syntax [a..b;m] directly translates to [a..b].stride(m).
So, can I do
X[a..b].stride(m) = 0;
? Just curious because if it is exactly the same notion then I should be able to do it, right?
Of course, I'm sure another hoop could be created to jump through and it will work, will it still be exactly the same though?
If there is an efficient and optimal setting so one could get the same effect, then I guess it might be a direct translation. If not then it isn't.
What I am looking for is a sort of zeromemory or memset with stride. It should not allocate a new array or be significantly slower. I'd like some proof that they are "equivalent" such as a disassembly or a profiling... just to satisfy my own skepticism.
|
June 04, 2018 Re: stride in slices | ||||
---|---|---|---|---|
| ||||
Posted in reply to DigitalDesigns | On Sunday, 3 June 2018 at 11:13:52 UTC, DigitalDesigns wrote: > On Sunday, 3 June 2018 at 07:30:56 UTC, Meta wrote: >> On Saturday, 2 June 2018 at 18:49:51 UTC, DigitalDesigns wrote: >>> Proposal: >>> >>> [a..b;m] >>> >>> m is the stride, if ; is not a good char then |, :, !, or # could be good chars. >> >> This is exactly what std.range.stride does. The syntax [a..b;m] directly translates to [a..b].stride(m). > > > So, can I do > > X[a..b].stride(m) = 0; You can use std.algorithm.iteration.each to modify a range in-place: https://run.dlang.io/is/2jjZHh |
June 04, 2018 Re: stride in slices | ||||
---|---|---|---|---|
| ||||
Posted in reply to DigitalDesigns | On 6/3/18 7:13 AM, DigitalDesigns wrote: > On Sunday, 3 June 2018 at 07:30:56 UTC, Meta wrote: >> On Saturday, 2 June 2018 at 18:49:51 UTC, DigitalDesigns wrote: >>> Proposal: >>> >>> [a..b;m] >>> >>> m is the stride, if ; is not a good char then |, :, !, or # could be good chars. >> >> This is exactly what std.range.stride does. The syntax [a..b;m] directly translates to [a..b].stride(m). > > > So, can I do > > X[a..b].stride(m) = 0; X[a..b].stride(m).fill(0); > ? Just curious because if it is exactly the same notion then I should be able to do it, right? You are confusing range and array syntax. All of what you want exists, but isn't necessarily using the same syntax. > Of course, I'm sure another hoop could be created to jump through and it will work, will it still be exactly the same though? > > If there is an efficient and optimal setting so one could get the same effect, then I guess it might be a direct translation. If not then it isn't. > > What I am looking for is a sort of zeromemory or memset with stride. It should not allocate a new array or be significantly slower. I'd like some proof that they are "equivalent" such as a disassembly or a profiling... just to satisfy my own skepticism. fill is what you are looking for. Note, it's not going to necessarily be as efficient, but it's likely to be close. -Steve |
June 04, 2018 Re: stride in slices | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Monday, 4 June 2018 at 15:43:20 UTC, Steven Schveighoffer wrote: > Note, it's not going to necessarily be as efficient, but it's likely to be close. > > -Steve I've compared the range versions with a for-loop. For integers and longs or high stride amounts the time is roughly equal, but for bytes with low stride amounts it can be up to twice as slow. https://run.dlang.io/is/BoTflQ 50 Mb array, type = byte, stride = 3, compiler = LDC -O4 -release For-loop 18 ms Fill(0) 33 ms each! 33 ms With stride = 13: For-loop 7.3 ms Fill(0) 7.5 ms each! 7.8 ms |
June 04, 2018 Re: stride in slices | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis | On 6/4/18 1:40 PM, Dennis wrote:
> On Monday, 4 June 2018 at 15:43:20 UTC, Steven Schveighoffer wrote:
>> Note, it's not going to necessarily be as efficient, but it's likely to be close.
>
> I've compared the range versions with a for-loop. For integers and longs or high stride amounts the time is roughly equal, but for bytes with low stride amounts it can be up to twice as slow.
> https://run.dlang.io/is/BoTflQ
>
> 50 Mb array, type = byte, stride = 3, compiler = LDC -O4 -release
> For-loop 18 ms
> Fill(0) 33 ms
> each! 33 ms
>
> With stride = 13:
> For-loop 7.3 ms
> Fill(0) 7.5 ms
> each! 7.8 ms
Interesting!
BTW, do you have cross-module inlining on? I wonder if that makes a difference if you didn't have it on before. (I'm somewhat speaking from ignorance, as I've heard people talk about this limitation, but am not sure exactly when it's enabled)
-Steve
|
June 04, 2018 Re: stride in slices | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Monday, 4 June 2018 at 18:11:47 UTC, Steven Schveighoffer wrote:
> BTW, do you have cross-module inlining on? I wonder if that makes a difference if you didn't have it on before. (I'm somewhat speaking from ignorance, as I've heard people talk about this limitation, but am not sure exactly when it's enabled)
I don't know much about this either. Clang has link-time optimization with -O4, but looking at the --help of LDC it turns out -O4 is equivalent to -O3 for D. Maybe someone else knows?
|
Copyright © 1999-2021 by the D Language Foundation