你可以如何在Julia中实现广播特化?

huangapple go评论57阅读模式
英文:

How can you specialize broadcasting in julia?

问题

我想为广播操作编写自定义方法

f.(v)

用于我的自定义函数 f。我需要做什么?

英文:

I want to write custom method for the broadcast operation

f.(v)

for my custom function f. What do I need to do for this?

答案1

得分: 1

你需要搜索有关Julia接口(非广播)的内容,以找到相关手册。

摘录:

需要实现的方法 简要描述
Base.BroadcastStyle(::Type{SrcType}) = SrcStyle() SrcType 的广播行为
Base.similar(bc::Broadcasted{DestStyle}, ::Type{ElType}) 分配输出容器
可选方法
Base.BroadcastStyle(::Style1, ::Style2) = Style12() 混合样式的优先规则
Base.axes(x) 声明 x 的索引,如 axes(x) 中所示。
Base.broadcastable(x) x 转换为具有 axes 并支持索引的对象
绕过默认机制
Base.copy(bc::Broadcasted{DestStyle}) 自定义 broadcast 的实现
Base.copyto!(dest, bc::Broadcasted{DestStyle}) 自定义 broadcast! 的实现,专门针对 DestStyle
Base.copyto!(dest::DestType, bc::Broadcasted{Nothing}) 自定义 broadcast! 的实现,专门针对 DestType
Base.Broadcast.broadcasted(f, args...) 在融合表达式中覆盖默认的延迟行为
Base.Broadcast.instantiate(bc::Broadcasted{DestStyle}) 覆盖延迟广播的轴计算
英文:

You need to google for julia interfaces (not broadcasting) to find the relevant manual

excerpt:

Methods to implement Brief description
Base.BroadcastStyle(::Type{SrcType}) = SrcStyle() Broadcasting behavior of SrcType
Base.similar(bc::Broadcasted{DestStyle}, ::Type{ElType}) Allocation of output container
Optional methods
Base.BroadcastStyle(::Style1, ::Style2) = Style12() Precedence rules for mixing styles
Base.axes(x) Declaration of the indices of x, as per axes(x).
Base.broadcastable(x) Convert x to an object that has axes and supports indexing
Bypassing default machinery
Base.copy(bc::Broadcasted{DestStyle}) Custom implementation of broadcast
Base.copyto!(dest, bc::Broadcasted{DestStyle}) Custom implementation of broadcast!, specializing on DestStyle
Base.copyto!(dest::DestType, bc::Broadcasted{Nothing}) Custom implementation of broadcast!, specializing on DestType
Base.Broadcast.broadcasted(f, args...) Override the default lazy behavior within a fused expression
Base.Broadcast.instantiate(bc::Broadcasted{DestStyle}) Override the computation of the lazy broadcast's axes

huangapple
  • 本文由 发表于 2023年6月1日 00:47:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定