`nunsafe_convert`对于``vector {u}`对于索引而不是uinerange {u}
我注意到用索引向量而不是unitrange给出的索引处理索引时,我注意到了以下错误。
c = rand(10)
c1 = view(c, [1, 3])
c2 = view(c1, 2:2)
Base.unsafe_convert(Ptr{Float64}, c2)
现在返回
ERROR: conversion to pointer not defined for SubArray{Float64, 1, Vector{Float64}, Tuple{Vector{Int64}}, false}
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] unsafe_convert(#unused#::Type{Ptr{Float64}}, a::SubArray{Float64, 1, Vector{Float64}, Tuple{Vector{Int64}}, false})
@ Base ./pointer.jl:67
[3] top-level scope
@ REPL[6]:1
I noticed the following error when handling views with indices given by a vector of indices instead of a UnitRange.
c = rand(10)
c1 = view(c, [1, 3])
c2 = view(c1, 2:2)
Base.unsafe_convert(Ptr{Float64}, c2)
now returns
ERROR: conversion to pointer not defined for SubArray{Float64, 1, Vector{Float64}, Tuple{Vector{Int64}}, false}
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] unsafe_convert(#unused#::Type{Ptr{Float64}}, a::SubArray{Float64, 1, Vector{Float64}, Tuple{Vector{Int64}}, false})
@ Base ./pointer.jl:67
[3] top-level scope
@ REPL[6]:1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们都会给我带来相同的错误(即,对于不连续的视图,明确不允许使用指针 - 由
false> false
键入参数指示):这是有道理的 - 连续块并不是真正有意义的(有关选定索引的信息丢失了)。
但是,您可以为一个范围获得一个指针:
They both result in the same error for me (i.e., taking pointers is just explicitely disallowed for non-contiguous views -- indicated by the
false
type parameter):Which makes sense, as a pointer to a non-contiguous chunk is not really meaningful (the information about the selected indices is lost).
You can get a pointer for a range, though: