4 added 94 characters in body
source | link
  1. Is Array Table the best way to implement this, or is there another way to go about this?

  2. If I don't care about the individual values, but only care about applying Mean@Abs@Flatten@#& to the final arrays, is there trick I could use to speed this up further? (UPDATE: Sum[Abs@f,{x,674},{y,674}]/674^2 is the fastest yet, actually—very reasonably so.)

  1. Is Array Table the best way to implement this, or is there another way to go about this?

  2. If I don't care about the individual values, but only care about applying Mean@Abs@Flatten@#& to the final arrays, is there trick I could use to speed this up further?

  1. Is Array Table the best way to implement this, or is there another way to go about this?

  2. If I don't care about the individual values, but only care about applying Mean@Abs@Flatten@#& to the final arrays, is there trick I could use to speed this up further? (UPDATE: Sum[Abs@f,{x,674},{y,674}]/674^2 is the fastest yet, actually—very reasonably so.)

3 added 76 characters in body
source | link

Results using AbsoluteTiming:

enter image description here

Array works basically like I'd expect—after all, even though f is not a beautiful function given that it's a ListInterpolation over a surface, finding these values amounts to plugging two integers into a polynomial—it doesn't seem like it should take very long. My curiosity is regarding why Replace, Map, and AssociationMap all seem to come out the same, Table seems to be middling, and Array destroys them all. I don't understand the underlying mechanisms that should determine these trends.

Array works basically like I'd expect—after all, even though f is not a beautiful function given that it's a ListInterpolation over a surface, finding these values amounts to plugging two integers into a polynomial—it doesn't seem like it should take very long. My curiosity is regarding why Replace, Map, and AssociationMap all seem to come out the same, Table seems to be middling, and Array destroys them all. I don't understand the underlying mechanisms that should determine these trends.

Results using AbsoluteTiming:

enter image description here

Array works basically like I'd expect—after all, even though f is not a beautiful function given that it's a ListInterpolation over a surface, finding these values amounts to plugging two integers into a polynomial—it doesn't seem like it should take very long. My curiosity is regarding why Replace, Map, and AssociationMap all seem to come out the same, Table seems to be middling, and Array destroys them all. I don't understand the underlying mechanisms that should determine these trends.

2 added 515 characters in body
source | link

EDIT: Actually, it looks like part of this is bogus—Array doesn't actually work on this input (I'm often a little shaky on what kind of input, exactly, works for interpolated functions...) which I should have realized from the flat timing curve. Array is now in line with the non-Table cluster, making Table the fastest (but still slower than I'd like). The image has been updated. I also think that I should maybe rerun these with AbsoluteTiming; I'm seeing some disparity here and there.

I have a function f which is an Interpolation of two variables, say x and y. In my full use case, I have 200 different such fs, and each one should act on a simple 674x674 array which is just an array of coordinates (i.e. just {{{1, 1}, {1, 2}, {1, 3}}, {{2, 1},... if the arrays in question were only 3x3).

TableTiming = Table[First@Timing@Table[f, {x, i}, {y, i}], {i, 100}];

ReplaceTiming = Table[With[{z = Table[{x -> a, y -> b}, {a, i}, {b,i}]}, First@Timing[f /. z]], {i, 100}];

g2[i_, j_] := f /. {x -> i, y -> j}

ArrayTiming = Table[First@Timing[f~Array~Table[First@Timing[g2~Array~{i, i}], {i, 100}];

g[{i_, j_}] := f /. {x -> i, y -> j}

MapTiming = Table[With[{z = Flatten[Table[{a, b}, {a, i}, {b, i}], 1]}, First@Timing[g /@ z]], {i, 100}];

AssociationMapTiming = Table[With[{z = Flatten[Table[{a, b}, {a, i},{b, i}], 1]}, First@Timing[Values@AssociationMap[g, z]]], {i, 100}];

The results:

timing results for various functions

or, on a ListLogLogPlot:

loglog plot of timingsenter image description here

Array works basically like I'd expect—after all, even though f is not a beautiful function given that it's a ListInterpolation over a surface, finding these values amounts to plugging two integers into a polynomial—it doesn't seem like it should take very long.Array works basically like I'd expect—after all, even though f is not a beautiful function given that it's a ListInterpolation over a surface, finding these values amounts to plugging two integers into a polynomial—it doesn't seem like it should take very long. My curiosity is regarding why Replace, Map, and AssociationMap all seem to come out the same, Table seems to be middling, and Array destroys them all., and Array destroys them all. I don't understand the underlying mechanisms that should determine these trends.

  1. Is Array ArrayTable the best way to implement this, or is there another way to go about this?

  2. If I don't care about the individual values, but only care about applying Mean@Abs@Flatten@#& to the final arrays, is there trick I could use to speed this up further?

I have a function f which is an Interpolation of two variables, say x and y. In my full use case, I have 200 different such fs, and each one should act on a simple 674x674 array which is just an array of coordinates (i.e. just {{{1, 1}, {1, 2}, {1, 3}}, {{2, 1},... if the arrays in question were only 3x3).

TableTiming = Table[First@Timing@Table[f, {x, i}, {y, i}], {i, 100}];

ReplaceTiming = Table[With[{z = Table[{x -> a, y -> b}, {a, i}, {b,i}]}, First@Timing[f /. z]], {i, 100}];

ArrayTiming = Table[First@Timing[f~Array~{i, i}], {i, 100}];

g[{i_, j_}] := f /. {x -> i, y -> j}

MapTiming = Table[With[{z = Flatten[Table[{a, b}, {a, i}, {b, i}], 1]}, First@Timing[g /@ z]], {i, 100}];

AssociationMapTiming = Table[With[{z = Flatten[Table[{a, b}, {a, i},{b, i}], 1]}, First@Timing[Values@AssociationMap[g, z]]], {i, 100}];

The results:

timing results for various functions

or, on a ListLogLogPlot:

loglog plot of timings

Array works basically like I'd expect—after all, even though f is not a beautiful function given that it's a ListInterpolation over a surface, finding these values amounts to plugging two integers into a polynomial—it doesn't seem like it should take very long. My curiosity is regarding why Replace, Map, and AssociationMap all seem to come out the same, Table seems to be middling, and Array destroys them all. I don't understand the underlying mechanisms that should determine these trends.

  1. Is Array the best way to implement this, or is there another way to go about this?

  2. If I don't care about the individual values, but only care about applying Mean@Abs@Flatten@#& to the final arrays, is there trick I could use to speed this up further?

EDIT: Actually, it looks like part of this is bogus—Array doesn't actually work on this input (I'm often a little shaky on what kind of input, exactly, works for interpolated functions...) which I should have realized from the flat timing curve. Array is now in line with the non-Table cluster, making Table the fastest (but still slower than I'd like). The image has been updated. I also think that I should maybe rerun these with AbsoluteTiming; I'm seeing some disparity here and there.

I have a function f which is an Interpolation of two variables, say x and y. In my full use case, I have 200 different such fs, and each one should act on a simple 674x674 array which is just an array of coordinates (i.e. just {{{1, 1}, {1, 2}, {1, 3}}, {{2, 1},... if the arrays in question were only 3x3).

TableTiming = Table[First@Timing@Table[f, {x, i}, {y, i}], {i, 100}];

ReplaceTiming = Table[With[{z = Table[{x -> a, y -> b}, {a, i}, {b,i}]}, First@Timing[f /. z]], {i, 100}];

g2[i_, j_] := f /. {x -> i, y -> j}

ArrayTiming = Table[First@Timing[g2~Array~{i, i}], {i, 100}];

g[{i_, j_}] := f /. {x -> i, y -> j}

MapTiming = Table[With[{z = Flatten[Table[{a, b}, {a, i}, {b, i}], 1]}, First@Timing[g /@ z]], {i, 100}];

AssociationMapTiming = Table[With[{z = Flatten[Table[{a, b}, {a, i},{b, i}], 1]}, First@Timing[Values@AssociationMap[g, z]]], {i, 100}];

The results:

enter image description here

Array works basically like I'd expect—after all, even though f is not a beautiful function given that it's a ListInterpolation over a surface, finding these values amounts to plugging two integers into a polynomial—it doesn't seem like it should take very long. My curiosity is regarding why Replace, Map, and AssociationMap all seem to come out the same, Table seems to be middling, and Array destroys them all. I don't understand the underlying mechanisms that should determine these trends.

  1. Is Array Table the best way to implement this, or is there another way to go about this?

  2. If I don't care about the individual values, but only care about applying Mean@Abs@Flatten@#& to the final arrays, is there trick I could use to speed this up further?

1
source | link