Suppose I have a function with a signature like g[expr, _?(f), {1}, Heads -> False]
and I want to access it as an operator by giving the first argument last. I see there are various ways of doing this:
First as explicit Curry
form:
(*curry approach*)
type1[f_]:=CurryApplied[g,{4,1,2,3}][_?(f),{1},Heads->False];
type2= f\[Function]CurryApplied[g,{4,1,2,3}][_?(f),{1},Heads->False];
Next maybe as a Function
approach:
(*function approach*)
type3[f_]:=g[#,_?(f),{1},Heads->False]&;
type4= f\[Function]g[#,_?(f),{1},Heads->False]&;
Also since only two level of calls are required, as a SubValue
:
(*subvalue approach*)
type5[f_][expr_]:=g[expr,_?(f),{1},Heads->False];
Now my question is what is the "proper" and most efficient way to do this kind of call. I try timing the calls as follows:
data1=Table[RepeatedTiming[type1[f]@expr],{1000}][[;;,1]];
data2=Table[RepeatedTiming[type2[f]@expr],{1000}][[;;,1]];
data3=Table[RepeatedTiming[type3[f]@expr],{1000}][[;;,1]];
data4=Table[RepeatedTiming[type4[f]@expr],{1000}][[;;,1]];
data5=Table[RepeatedTiming[type5[f]@expr],{1000}][[;;,1]];
I try to compare the timing:
DistributionChart[{data1,data2},ChartElementFunction->"PointDensity"]
DistributionChart[{data3,data4,data5},ChartElementFunction->"PointDensity"]
It appears SubValue
way of calling is the fastest. The new way of Curry
is slowest. Can someone explain why there are differences in timing?
Also, I don't know why I get a Pink Box
when using "PointDensity"
. Am I using "PointDensity"
incorrectly? (I am on 12.1)
By the way, the Pink Box
appears to be a bug and is reproducible by the following command:
DistributionChart[RandomReal[{1*^-7,1*^-6},{3,100}],ChartElementFunction->"PointDensity"]
OperatorApplied
into the mix since it is apparently more closely associated with applications. Also, "proper" is going to be subjective/context-dependent although you seem to be mostly conflating it with efficiency. If that is the main goal then including "proper" might confuse the issue; if the broader "proper" is intended (which I would be interested in) then maybe consider broadening the question to "What is the best way to Curry?" $\endgroup$ – Ronald Monson May 3 '20 at 0:57