Mathematical large-panel periodic interpolation

I have a very large table in Mathematica ((dimcub-1) ^ 3 elements) coming from the inverse FFT. I need to use periodic interpolation in this table. Since periodic interpolation requires the first elements and the last elements to be equal, I manually create a new element table dim ^ 3 and use it in my interpolation. It works, but it is ugly / slow, and because of my superfluous staging table, I rather hit memory. Can someone tell me how to turn my old table into a periodic one by adding elements or using my non-periodic table to create periodic interpolation? Here is my current code snippet:

mr 1 - new table:

 mr1 = Table[ 0. , {i, 1, dimcub}, {j, 1, dimcub}, {k, 1, dimcub}]; Do[Do[ Do[ mr1[[m, n, k]] = oldtable[[m, n, k]] ; , {m, 1, dimcub - 1}]; , {n, 1, dimcub - 1}]; , {k, 1, dimcub - 1}]; Do[Do[ mr1[[m, n, dimcub]] = mr1[[m, n, 1]]; mr1[[m, dimcub, n]] = mr1[[m, 1, n]]; mr1[[dimcub, m, n]] = mr1[[1, m, n]]; , {m, 1, dimcub - 1}]; mr1[[n, dimcub, dimcub]] = mr1[[n, 1, 1]]; mr1[[dimcub, n, dimcub]] = mr1[[1, n, 1]]; mr1[[dimcub, dimcub, n]] = mr1[[1, 1, n]]; , {n, 1, dimcub - 1}]; mr1[[dimcub, dimcub, dimcub]] = mr1[[1, 1, 1]]; Remove[oldtable]; myinterpolatingfunction = ListInterpolation[mr1, {{1, dimcub}, {1, dimcub}, {1, dimcub}}, InterpolationOrder -> 1, PeriodicInterpolation -> True]; Remove[mr1]; 

myinterpolatingfunction takes up much less memory and works great after deleting old tables. Any help would be greatly appreciated.

+7
source share
4 answers

Thanks for all the answers. I tried the Leonid sentence, but when I print my antique table, it was still (dimcub -1) ^ 3 dimensional. New elements have been defined, and I see them individually, but they do not appear as part of the old table when printing the entire table. So, I got something similar that does exactly what I need:

 oldtable= PadRight[oldtable, {dimcub, dimcub, dimcub}]; oldtable[[All, All, dimcub]] = oldtable[[All, All, 1]]; oldtable[[All, dimcub, All]] = oldtable[[All, 1, All]]; oldtable[[dimcub, All, All]] = oldtable[[1, All, All]]; oldtable[[All, dimcub, dimcub]] = oldtable[[All, 1, 1]]; oldtable[[dimcub, All, dimcub]] = oldtable[[1, All, 1]]; oldtable[[dimcub, dimcub, All]] = oldtable[[1, 1, All]]; oldtable[[dimcub, dimcub, dimcub]] = oldtable[[1, 1, 1]]; 

The Wizard answer is too advanced for my math level ..

+4
source

The answers of Leonid and Mr. Weiser do too much work. In the case of Leonid, only the first three lines are needed. To show this, I changed the last 4 Set to Equal s:

 In[65]:= len = 4; oldtable = Partition[Partition[Range[len^3], len], len] Out[65]= {{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}, {{17, 18, 19, 20}, {21, 22, 23, 24}, {25, 26, 27, 28}, {29, 30, 31, 32}}, {{33, 34, 35, 36}, {37, 38, 39, 40}, {41, 42, 43, 44}, {45, 46, 47, 48}}, {{49, 50, 51, 52}, {53, 54, 55, 56}, {57, 58, 59, 60}, {61, 62, 63, 64}}} In[66]:= oldtable[[All, All, -1]] = oldtable[[All, All, 1]]; oldtable[[All, -1, All]] = oldtable[[All, 1, All]]; oldtable[[-1, All, All]] = oldtable[[1, All, All]]; oldtable[[All, -1, -1]] == oldtable[[All, 1, 1]] oldtable[[-1, All, -1]] == oldtable[[1, All, 1]] oldtable[[-1, -1, All]] == oldtable[[1, 1, All]] oldtable[[-1, -1, -1]] == oldtable[[1, 1, 1]] Out[69]= True Out[70]= True Out[71]= True Out[72]= True 

What Leonid does is illustrated in the figures below. Lines 4-6 of his code do something as shown in the left panel: copying a line (darker color) of an already copied plane (light colors). Line 7 is shown in the right pane. This is a copy of a cell to a cell with diagonally opposite positions, and its action is not included in one of the first three copy actions separately, but is the result of their sequential operation.

enter image description here

+9
source

You can get it much faster and more efficiently with memory by modifying the original table as follows:

 oldtable[[All, All, -1]] = oldtable[[All, All, 1]]; oldtable[[All, -1, All]] = oldtable[[All, 1, All]]; oldtable[[-1, All, All]] = oldtable[[1, All, All]]; oldtable[[All, -1, -1]] = oldtable[[All, 1, 1]]; oldtable[[-1, All, -1]] = oldtable[[1, All, 1]]; oldtable[[-1, -1, All]] = oldtable[[1, 1, All]]; oldtable[[-1, -1, -1]] = oldtable[[1, 1, 1]]; 

These assignments replace nested loops and work much faster, plus you do not need memory to store a copy. This is based on the extended vectorized functionality of the Part command (indexing an array and general expression), in particular vectorized assignments. It is also important to have a numerical array in the form of a Packed array , which is often the case.

+8
source

Just because I'm a little versed, Leonid’s solution can be written as:

 a = {0, 1}~Tuples~3~SortBy~Tr // Rest; MapThread[ (oldtable[[Sequence @@ #]] = oldtable[[Sequence @@ #2]]) &, {-a, a} /. 0 -> All ]; 
+5
source