Skip to main content
added 76 characters in body
Source Link
user293787
  • 12k
  • 11
  • 29

Using a pure function

vec = Function[{x,y,z},{x^0.5*y^0.1,y^0.3*z^0.1,z^2*x*y}];

and inlining definition works:

f = Compile[{{x,_Real,2}},
      Table[vec[x[[i,1]],x[[i,2]],x[[i,3]]],{i,1,Length[tabscord]}],
      CompilationTarget->"C",RuntimeOptions->"Speed",
      CompilationOptions->{"InlineExternalDefinitions"->True}
];

tabscord=RandomReal[{0,1},{10^7,3}];
AbsoluteTiming[f[tabscord];]f[tabscord]
(* takes about 3 seconds *)

See this answer for inlining definitions.

Using a pure function

vec = Function[{x,y,z},{x^0.5*y^0.1,y^0.3*z^0.1,z^2*x*y}];

and inlining definition works:

f = Compile[{{x,_Real,2}},
      Table[vec[x[[i,1]],x[[i,2]],x[[i,3]]],{i,1,Length[tabscord]}],
      CompilationTarget->"C",RuntimeOptions->"Speed",
      CompilationOptions->{"InlineExternalDefinitions"->True}
];

tabscord=RandomReal[{0,1},{10^7,3}];
AbsoluteTiming[f[tabscord];]
(* takes about 3 seconds *)

Using a pure function

vec = Function[{x,y,z},{x^0.5*y^0.1,y^0.3*z^0.1,z^2*x*y}];

and inlining works:

f = Compile[{{x,_Real,2}},
      Table[vec[x[[i,1]],x[[i,2]],x[[i,3]]],{i,1,Length[tabscord]}],
      CompilationTarget->"C",RuntimeOptions->"Speed",
      CompilationOptions->{"InlineExternalDefinitions"->True}
];

tabscord=RandomReal[{0,1},{10^7,3}];
f[tabscord]
(* takes about 3 seconds *)

See this answer for inlining definitions.

Source Link
user293787
  • 12k
  • 11
  • 29

Using a pure function

vec = Function[{x,y,z},{x^0.5*y^0.1,y^0.3*z^0.1,z^2*x*y}];

and inlining definition works:

f = Compile[{{x,_Real,2}},
      Table[vec[x[[i,1]],x[[i,2]],x[[i,3]]],{i,1,Length[tabscord]}],
      CompilationTarget->"C",RuntimeOptions->"Speed",
      CompilationOptions->{"InlineExternalDefinitions"->True}
];

tabscord=RandomReal[{0,1},{10^7,3}];
AbsoluteTiming[f[tabscord];]
(* takes about 3 seconds *)