英文:
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 |
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论