I need to make this code faster and consume less memory.
makeBZ001[x_] := Module[{dat = x, rt1, rt2, rt3, temp1, temp2, temp3,rm, tempfull,full, bool1, res},
rt1 = ReflectionTransform[{1, -1}]; temp1 = dat;
temp1[[All, 1 ;; 2]] = rt1[temp1[[All, 1 ;; 2]]];
rt2 = ReflectionTransform[{1, 0}];
temp2 = DeleteDuplicates[Join[dat, temp1]];
temp2[[All, 1 ;; 2]] = rt2[temp2[[All, 1 ;; 2]]];
rt3 = ReflectionTransform[{0, -1}];
temp3 = DeleteDuplicates[Join[dat, temp1, temp2]];
temp3[[All, 1 ;; 2]] = rt3[temp3[[All, 1 ;; 2]]];
tempfull = DeleteDuplicates[Join[dat, temp1, temp2, temp3]];
bool1 = RegionMember[Polygon[{{0., 1.}, {-1., 0.}, {0., -1.},{1.,0.}}]]/@ tempfull[[All, 1 ;; 2]];
res = Pick[tempfull, bool1];
res
]
n = 10^5;
data1 = ConstantArray[RandomInteger[{-2, 2}], {n, 2}];
data2 = ConstantArray[RandomInteger[{0, 1}], {n, 21}];
array = {};
If[Dimensions[data1][[1]] == Dimensions[data2][[1]],
Do[temp = ArrayFlatten[{{data1, Transpose[{data2[[All, j]]}]}}];
temp2 = makeBZ001[temp];
pick = Boole[(NumberQ[#1] &) /@ temp2[[All, -1]]];
temp2[[All, -1]] = temp2[[All, -1]] pick;
AppendTo[array, temp2], {j, 2., 21.}];,
Print["Dimensions of data1 and data2 are incompatible."]; Abort[];];
link = Association[];
m = 1;
Do[link[ToString[n]] = m;
m = m + 1;
, {n, {j11, j21, j12, j22, L21, L12, R21, R12, l021, l012, r021, r012, jl11, jl21, jl12, jl22, jr11, jr21, jr12, jr22}}
]
The main idea is to create 20 {~4n,3} lists and reference them by name, such that array[link[ToString[j11]]]
is just array[[1]]
. I had to add a part, pick
variable, to check for numbers like 1.34343-256
which create errors in post processing. I'm looking for any exploit or shortcut to make this faster. Thanks in advance.
Edit Just realized the sample data wont work. Here is actual data you can use to test the code.