Code:
Code:
In[]:=
toTestFunction[f_,{vars__Symbol}]:=Function[{vars},Evaluate[{vars,f,Sequence@@Map[D[f,#]&,{vars}]}]];
In[]:=
toTestValues[testFunction_,{vars__List}]:=Flatten[Outer[testFunction,vars],Length[{vars}]-1];
In[]:=
toStdVector[testValues_]:="std::vector<TestValue> testValues = {\n\t"<>StringJoin[Riffle[Map[ToString,Map[CForm,testValues,{-1}]],",\n\t"]]<>"\n};\n";
In[]:=
everythingTogether[f_,{vars__Symbol},{varValues__List},precision_:30]:=Module[{testF,testV,cform},Assert[Length@vars==Length@varValues];testF=toTestFunction[f,{vars}];testV=toTestValues[testF,Map[SetPrecision[#,precision]&,{varValues}]];cform=toStdVector[testV];cform];
Usage example:
Usage example:
In[]:=
lbeta[x_,y_]:=LogGamma[x]+LogGamma[y]-LogGamma[x+y]xs={1,2};ys={3,4,5};
In[]:=
o=everythingTogether[lbeta[x,y],{x,y},{xs,ys}]Export["test.hpp",o,"Text"]
Out[]=
std::vector<TestValue> testValues = { {1., 3., -1.09861228866810969139524523692, -1.83333333333333333333333333333, -0.3333333333333333333333333333}, {1., 4., -1.38629436111989061883446424292, -2.08333333333333333333333333333, -0.25}, {1., 5., -1.60943791243410037460075933323, -2.28333333333333333333333333333, -0.2}, {2., 3., -2.48490664978800031022970947984, -1.0833333333333333333333333333, -0.5833333333333333333333333333}, {2., 4., -2.99573227355399099343522357614, -1.2833333333333333333333333333, -0.45}, {2., 5., -3.40119738166215537541323669161, -1.45, -0.3666666666666666666666666667}};
Out[]=
test.hpp
Examples with different dimension:
Examples with different dimension:
In[]:=
everythingTogether[Gamma[x],{x},{xs}]
Out[]=
std::vector<TestValue> testValues = { {1., 1., -0.57721566490153286060651209008}, {2., 1., 0.42278433509846713939348790992}};
In[]:=
zs={6,7}
Out[]=
{6,7}
In[]:=
everythingTogether[y*Gamma[x]/z,{x,y,z},{xs,ys,zs}]
Out[]=
std::vector<TestValue> testValues = { {1., 3., 6., 0.5, -0.28860783245076643030325604504, 0.166666666666666666666666666667, -0.083333333333333333333333333333}, {1., 3., 7., 0.42857142857142857142857142857, -0.247378142100656940259933752892, 0.142857142857142857142857142857, -0.06122448979591836734693877551}, {1., 4., 6., 0.66666666666666666666666666667, -0.38481044326768857373767472672, 0.166666666666666666666666666667, -0.111111111111111111111111111111}, {1., 4., 7., 0.57142857142857142857142857143, -0.32983752280087592034657833719, 0.142857142857142857142857142857, -0.081632653061224489795918367347}, {1., 5., 6., 0.83333333333333333333333333333, -0.4810130540846107171720934084, 0.166666666666666666666666666667, -0.138888888888888888888888888889}, {1., 5., 7., 0.71428571428571428571428571429, -0.41229690350109490043322292149, 0.142857142857142857142857142857, -0.102040816326530612244897959184}, {2., 3., 6., 0.5, 0.21139216754923356969674395496, 0.166666666666666666666666666667, -0.083333333333333333333333333333}, {2., 3., 7., 0.42857142857142857142857142857, 0.18119328647077163116863767568, 0.142857142857142857142857142857, -0.06122448979591836734693877551}, {2., 4., 6., 0.66666666666666666666666666667, 0.28185622339897809292899193995, 0.166666666666666666666666666667, -0.111111111111111111111111111111}, {2., 4., 7., 0.57142857142857142857142857143, 0.24159104862769550822485023424, 0.142857142857142857142857142857, -0.081632653061224489795918367347}, {2., 5., 6., 0.83333333333333333333333333333, 0.35232027924872261616123992493, 0.166666666666666666666666666667, -0.138888888888888888888888888889}, {2., 5., 7., 0.71428571428571428571428571429, 0.3019888107846193852810627928, 0.142857142857142857142857142857, -0.102040816326530612244897959184}};