Julia 使用get和set索引函数进行基于范围的切片?
如何允许使用get和set索引函数进行基于范围的切片 它们是副本还是视图?观点更可取Julia 使用get和set索引函数进行基于范围的切片?,julia,Julia,如何允许使用get和set索引函数进行基于范围的切片 它们是副本还是视图?观点更可取 function Base.getindex(cb::CircularMatrix, I::Vararg{Int,2}) cb.buffer[I[1], _buffer_index_checked(cb, I[2])] end function Base.setindex!(cb::CircularMatrix, data, I::Vararg{Int,2}) cb.buffer[I[1],
function Base.getindex(cb::CircularMatrix, I::Vararg{Int,2})
cb.buffer[I[1], _buffer_index_checked(cb, I[2])]
end
function Base.setindex!(cb::CircularMatrix, data, I::Vararg{Int,2})
cb.buffer[I[1], _buffer_index_checked(cb, I[2])] = data
cb
end
s = CircluarMatrix{Int}(5, 5)
s[:, 5]
s[5, :]
只需将
CircularMatrix
定义为AbstractMatrix
的子类型,您就可以免费获得它。方括号索引返回副本;使用view
或@views
获取视图。只需将CircularMatrix
定义为AbstractMatrix
的子类型,即可免费获取。方括号索引返回副本;使用view
或@views
获取视图。