Skip to main content
added 140 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

With versions 10.4.1 and 11.0.1 "Periodic" works:

MovingMap[f, Range[5], 1, "Periodic"]
MovingMap[f, Range[5], {1, Left}, "Periodic"]
MovingMap[f, Range[5], 2, "Periodic"]
MovingMap[f, Range[5], {2, Center}, "Periodic"]
{f[{5, 1}], f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}]}
{f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}], f[{5, 1}]}
{f[{4, 5, 1}], f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}]}
{f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}], f[{4, 5, 1}]}

But MovingMap is still one order of magnitude slower than Map + Partition:

ClearSystemCache[]
m1 = MovingMap[f, Range[10^6], {2, Center}, "Periodic"]; // RepeatedTiming
ClearSystemCache[]
m2 = f /@ Partition[ArrayPad[Range[10^6], {1, 1}, "Periodic"], 3, 1]; // RepeatedTiming
ClearSystemCache[]
m3 = f /@ Partition[Range[10^6], 3, 1, {2, 2}]; // RepeatedTiming
ClearSystemCache[]
m4 = Developer`PartitionMap[f, Range[10^6], 3, 1, {2, 2}]; // RepeatedTiming
m1 === m2 === m3 === m4
{6.8360, Null}

{0.95950, Null}

{0.95190987, Null}

{1.07, Null}

True

With versions 10.4.1 and 11.0.1 "Periodic" works:

MovingMap[f, Range[5], 1, "Periodic"]
MovingMap[f, Range[5], {1, Left}, "Periodic"]
MovingMap[f, Range[5], 2, "Periodic"]
MovingMap[f, Range[5], {2, Center}, "Periodic"]
{f[{5, 1}], f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}]}
{f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}], f[{5, 1}]}
{f[{4, 5, 1}], f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}]}
{f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}], f[{4, 5, 1}]}

But MovingMap is still one order of magnitude slower than Map + Partition:

ClearSystemCache[]
m1 = MovingMap[f, Range[10^6], {2, Center}, "Periodic"]; // RepeatedTiming
ClearSystemCache[]
m2 = f /@ Partition[ArrayPad[Range[10^6], {1, 1}, "Periodic"], 3, 1]; // RepeatedTiming
ClearSystemCache[]
m3 = f /@ Partition[Range[10^6], 3, 1, {2, 2}]; // RepeatedTiming
m1 === m2 === m3
{6.83, Null}

{0.95, Null}

{0.95190, Null}

True

With versions 10.4.1 and 11.0.1 "Periodic" works:

MovingMap[f, Range[5], 1, "Periodic"]
MovingMap[f, Range[5], {1, Left}, "Periodic"]
MovingMap[f, Range[5], 2, "Periodic"]
MovingMap[f, Range[5], {2, Center}, "Periodic"]
{f[{5, 1}], f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}]}
{f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}], f[{5, 1}]}
{f[{4, 5, 1}], f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}]}
{f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}], f[{4, 5, 1}]}

But MovingMap is still one order of magnitude slower than Map + Partition:

ClearSystemCache[]
m1 = MovingMap[f, Range[10^6], {2, Center}, "Periodic"]; // RepeatedTiming
ClearSystemCache[]
m2 = f /@ Partition[ArrayPad[Range[10^6], {1, 1}, "Periodic"], 3, 1]; // RepeatedTiming
ClearSystemCache[]
m3 = f /@ Partition[Range[10^6], 3, 1, {2, 2}]; // RepeatedTiming
ClearSystemCache[]
m4 = Developer`PartitionMap[f, Range[10^6], 3, 1, {2, 2}]; // RepeatedTiming
m1 === m2 === m3 === m4
{6.60, Null}

{0.950, Null}

{0.987, Null}

{1.07, Null}

True
added 204 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

With versions 10.4.1 and 11.0.1 "Periodic" works:

MovingMap[f, Range[5], 1, "Periodic"]
MovingMap[f, Range[5], {1, Left}, "Periodic"]
MovingMap[f, Range[5], 2, "Periodic"]
MovingMap[f, Range[5], {2, Center}, "Periodic"]
{f[{5, 1}], f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}]}
{f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}], f[{5, 1}]}
{f[{4, 5, 1}], f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}]}
{f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}], f[{4, 5, 1}]}

But MovingMap is still 10 timesone order of magnitude slower than Map + Partition:

ClearSystemCache[]
m1 = MovingMap[f, Range[10^6], {2, Center}, "Periodic"]; // TimingRepeatedTiming
ClearSystemCache[]
m2 = f /@ Partition[ArrayPad[Range[10^6], {1, 1}, "Periodic"], 3, 1]; // TimingRepeatedTiming
ClearSystemCache[]
m3 = f /@ Partition[Range[10^6], 3, 1, {2, 2}]; // RepeatedTiming
m1 === m2 === m3
{56.8812483, Null}

{0.57720495, Null}

{0.95190, Null}

True

With versions 10.4.1 and 11.0.1 "Periodic" works:

MovingMap[f, Range[5], 1, "Periodic"]
MovingMap[f, Range[5], {1, Left}, "Periodic"]
MovingMap[f, Range[5], 2, "Periodic"]
MovingMap[f, Range[5], {2, Center}, "Periodic"]
{f[{5, 1}], f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}]}
{f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}], f[{5, 1}]}
{f[{4, 5, 1}], f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}]}
{f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}], f[{4, 5, 1}]}

But MovingMap is still 10 times slower than Map + Partition:

m1 = MovingMap[f, Range[10^6], {2, Center}, "Periodic"]; // Timing
m2 = f /@ Partition[ArrayPad[Range[10^6], {1, 1}, "Periodic"], 3, 1]; // Timing
m1 === m2
{5.88124, Null}

{0.577204, Null}

True

With versions 10.4.1 and 11.0.1 "Periodic" works:

MovingMap[f, Range[5], 1, "Periodic"]
MovingMap[f, Range[5], {1, Left}, "Periodic"]
MovingMap[f, Range[5], 2, "Periodic"]
MovingMap[f, Range[5], {2, Center}, "Periodic"]
{f[{5, 1}], f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}]}
{f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}], f[{5, 1}]}
{f[{4, 5, 1}], f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}]}
{f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}], f[{4, 5, 1}]}

But MovingMap is still one order of magnitude slower than Map + Partition:

ClearSystemCache[]
m1 = MovingMap[f, Range[10^6], {2, Center}, "Periodic"]; // RepeatedTiming
ClearSystemCache[]
m2 = f /@ Partition[ArrayPad[Range[10^6], {1, 1}, "Periodic"], 3, 1]; // RepeatedTiming
ClearSystemCache[]
m3 = f /@ Partition[Range[10^6], 3, 1, {2, 2}]; // RepeatedTiming
m1 === m2 === m3
{6.83, Null}

{0.95, Null}

{0.95190, Null}

True
added 327 characters in body
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375

With versions 10.4.1 and 11.0.1 "Periodic" works:

MovingMap[f, Range[5], 1, "Periodic"]
MovingMap[f, Range[5], {1, Left}, "Periodic"]
MovingMap[f, Range[5], 2, "Periodic"]
MovingMap[f, Range[5], {2, Center}, "Periodic"]
{f[{5, 1}], f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}]}
{f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}], f[{5, 1}]}
{f[{4, 5, 1}], f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}]}
{f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}], f[{4, 5, 1}]}

But MovingMap is still 10 times slower than Map + Partition:

m1 = MovingMap[f, Range[10^6], {2, Center}, "Periodic"]; // Timing
m2 = f /@ Partition[ArrayPad[Range[10^6], {1, 1}, "Periodic"], 3, 1]; // Timing
m1 === m2
{5.88124, Null}

{0.577204, Null}

True

With versions 10.4.1 and 11.0.1 "Periodic" works:

MovingMap[f, Range[5], 1, "Periodic"]
MovingMap[f, Range[5], {1, Left}, "Periodic"]
MovingMap[f, Range[5], 2, "Periodic"]
MovingMap[f, Range[5], {2, Center}, "Periodic"]
{f[{5, 1}], f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}]}
{f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}], f[{5, 1}]}
{f[{4, 5, 1}], f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}]}
{f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}], f[{4, 5, 1}]}

With versions 10.4.1 and 11.0.1 "Periodic" works:

MovingMap[f, Range[5], 1, "Periodic"]
MovingMap[f, Range[5], {1, Left}, "Periodic"]
MovingMap[f, Range[5], 2, "Periodic"]
MovingMap[f, Range[5], {2, Center}, "Periodic"]
{f[{5, 1}], f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}]}
{f[{1, 2}], f[{2, 3}], f[{3, 4}], f[{4, 5}], f[{5, 1}]}
{f[{4, 5, 1}], f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}]}
{f[{5, 1, 2}], f[{1, 2, 3}], f[{2, 3, 4}], f[{3, 4, 5}], f[{4, 5, 1}]}

But MovingMap is still 10 times slower than Map + Partition:

m1 = MovingMap[f, Range[10^6], {2, Center}, "Periodic"]; // Timing
m2 = f /@ Partition[ArrayPad[Range[10^6], {1, 1}, "Periodic"], 3, 1]; // Timing
m1 === m2
{5.88124, Null}

{0.577204, Null}

True
Source Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading