给出所编译函数的信息.
CurrentCompiledFunctionData[prop]
给出所编译函数的属性 prop 的值.
CurrentCompiledFunctionData
给出所编译函数的信息.
CurrentCompiledFunctionData[prop]
给出所编译函数的属性 prop 的值.
更多信息
- CurrentCompiledFunctionData 仅在编译代码中可用.
- 通过调用 CurrentCompiledFunctionData 返回的名称将是 FunctionDeclaration 所设置的名称.
- CurrentCompiledFunctionData["ReturnType"] 是访问函数返回类型的一种有用方法.
- 调用 CurrentCompiledFunctionData 会返回类型为 "CompiledFunctionData" 的结果.
- 调用 CurrentCompiledFunctionData 的结果包含了所编译函数的类型信息,因此无法从函数中返回该结果.
- 支持以下属性:
-
"Type" 所编译函数的类型 "ReturnType" 所编译函数返回结果的类型
范例
打开所有单元 关闭所有单元基本范例 (2)
comp = FunctionCompile[Function[Typed[arg, "Integer64"], Echo[CurrentCompiledFunctionData[]]; {arg}]];
comp[10]comp = FunctionCompile[Function[Typed[arg, "Integer64"], Echo[CurrentCompiledFunctionData["Type"]]; {arg}]];
comp[10]comp = FunctionCompile[Function[Typed[arg, "Integer64"], Echo[CurrentCompiledFunctionData["ReturnType"]]; {arg}]];
comp[10]如果 CurrentCompiledFunctionData 出现在具有名称的函数中,则包括在内:
decl = FunctionDeclaration[DemoFunc, Typed[{"Integer64"} -> "PackedArray"::["Integer64", 1]]@Function[{arg}, Echo[CurrentCompiledFunctionData[]];{arg}]];comp = FunctionCompile[decl, Function[Typed[arg, "Integer64"], DemoFunc[arg]]];
comp[10]范围 (3)
CurrentCompiledFunctionData 只能在编译代码中使用:
CurrentCompiledFunctionData[]decl = FunctionDeclaration[makeZero, Typed[ForAllType[e, {} -> e]]@Function[{}, TypeHint[0, CurrentCompiledFunctionData["ReturnType"]]]];comp = FunctionCompile[decl, Function[Typed[arg, "Integer64"], TypeHint[makeZero[], TypeOf[arg]]]];
Information[comp, "Type"]comp = FunctionCompile[decl, Function[Typed[arg, "Real64"], TypeHint[makeZero[], TypeOf[arg]]]];
Information[comp, "Type"]CurrentCompiledFunctionData 的结果可以传递到一个可以提取名称等信息的函数中:
decls = {
FunctionDeclaration[printName, Typed[ForAllType[funTy, {"CompiledFunctionData"::[funTy]} -> "Null"]]@Function[{arg}, Print[arg["Name"]]]
]
,
FunctionDeclaration[functionName["MyFunction"],
Typed[{} -> "Null"]@
Function[{}, printName[CurrentCompiledFunctionData[]]]
]};这将打印出现 CurrentCompiledFunctionData 的函数的名称:
comp = FunctionCompile[decls, Function[{}, functionName["MyFunction"][]]];
comp[]可能存在的问题 (1)
调用 CurrentCompiledFunctionData 的结果无法从函数中返回:
FunctionCompile[Function[{}, CurrentCompiledFunctionData[]]]若将 CurrentCompiledFunctionData[] 转换为 "InertExpression",则编译可能成功:
cf = FunctionCompile[Function[{}, Cast[CurrentCompiledFunctionData[], "InertExpression"]]][]当被调用时,生成的 CompiledFunctionData 对象显示返回类型为 "InertExpression":
cf[]技术笔记
相关指南
-
▪
- 代码编译
文本
Wolfram Research (2025),CurrentCompiledFunctionData,Wolfram 语言函数,https://reference.wolfram.com/language/ref/CurrentCompiledFunctionData.html.
CMS
Wolfram 语言. 2025. "CurrentCompiledFunctionData." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/CurrentCompiledFunctionData.html.
APA
Wolfram 语言. (2025). CurrentCompiledFunctionData. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/CurrentCompiledFunctionData.html 年
BibTeX
@misc{reference.wolfram_2026_currentcompiledfunctiondata, author="Wolfram Research", title="{CurrentCompiledFunctionData}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/CurrentCompiledFunctionData.html}", note=[Accessed: 05-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_currentcompiledfunctiondata, organization={Wolfram Research}, title={CurrentCompiledFunctionData}, year={2025}, url={https://reference.wolfram.com/language/ref/CurrentCompiledFunctionData.html}, note=[Accessed: 05-September-2026]}