Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning on strides(a::AbstractArray) when plotting array reshaped from stridden subvector #391

Closed
wsshin opened this issue Sep 24, 2018 · 3 comments

Comments

@wsshin
Copy link

wsshin commented Sep 24, 2018

I get a warning when using pcolor on a matrix generated by reshape on a stridden subvector. For example,

using PyPlot
a = rand(10);
b = @view a[1:3:end];  # stridden subvector
c = reshape(b, 2, :);  # reshape subvector into matrix
pcolor(c)

produces the following warning:

┌ Warning: The default `strides(a::AbstractArray)` implementation is deprecated for general arrays.
│ Specialize `strides(::Base.ReshapedArray)` if `Base.ReshapedArray` indeed uses a strided representation in memory.
│ Warning: inappropriately implementing this method for an array type that does not use strided
│ storage may lead to incorrect results or segfaults.
│   caller = ip:0x0
└ @ Core :-1
┌ Warning: The default `strides(a::AbstractArray)` implementation is deprecated for general arrays.
│ Specialize `strides(::Base.ReshapedArray)` if `Base.ReshapedArray` indeed uses a strided representation in memory.
│ Warning: inappropriately implementing this method for an array type that does not use strided
│ storage may lead to incorrect results or segfaults.
│   caller = stride at abstractarray.jl:350 [inlined]
└ @ Core ./abstractarray.jl:350

If a matrix itself is stridden (instead of a vector being stridden and reshaped into a matrix), then the warning does not occur.

Here is the version information:

julia> VERSION
v"0.7.1-pre.0"
@wsshin
Copy link
Author

wsshin commented Sep 24, 2018

Related to #380, but the specific warning message is different: #380 is about strides(::Adjoint), whereas the present warning is about strides(::Base.ReshapedArray).

@dlfivefifty
Copy link

I got it while trying to do a spy plot on a sparse matrix:

julia> spy(M)
ERROR: MethodError: no method matching strides(::SparseMatrixCSC{Float64,Int64})
Closest candidates are:
  strides(::SubArray{T,2,BlockBandedMatrices.BlockSkylineMatrix{T,LL,UU},Tuple{BlockArrays.BlockSlice{Block{1,Int64}},BlockArrays.BlockSlice{Block{1,Int64}}},false} where UU where LL where T) at /Users/sheehanolver/Projects/BlockBandedMatrices.jl/src/BlockSkylineMatrix.jl:404
  strides(::SubArray{#s148,2,BlockBandedMatrices.BlockSkylineMatrix{#s148,LL,UU},Tuple{BlockArrays.BlockSlice{#s147},BlockArrays.BlockSlice{Block{1,Int64}}},L} where L where #s147<:Union{Block{1,Int64}, BlockRange{1,Tuple{UnitRange{Int64}}}} where #s148) where {LL, UU} at /Users/sheehanolver/Projects/BlockBandedMatrices.jl/src/linalg.jl:263
  strides(::SubArray{#s148,2,BlockBandedMatrices.BlockSkylineMatrix{#s148,LL,UU},Tuple{BlockArrays.BlockSlice{BlockRange{1,Tuple{UnitRange{Int64}}}},BlockArrays.BlockSlice{BlockArrays.BlockIndexRange{1,Tuple{UnitRange{Int64}}}}},L} where L where #s148) where {LL, UU} at /Users/sheehanolver/Projects/BlockBandedMatrices.jl/src/linalg.jl:283
  ...
Stacktrace:
 [1] stride(::SparseMatrixCSC{Float64,Int64}, ::Int64) at ./abstractarray.jl:342
 [2] array2py(::SparseMatrixCSC{Float64,Int64}, ::Int64, ::Int64) at /Users/sheehanolver/.julia/packages/PyCall/0jMpb/src/conversions.jl:313
 [3] array2py at /Users/sheehanolver/.julia/packages/PyCall/0jMpb/src/conversions.jl:325 [inlined]
 [4] Type at /Users/sheehanolver/.julia/packages/PyCall/0jMpb/src/conversions.jl:327 [inlined]
 [5] _pycall!(::PyCall.PyObject, ::PyCall.PyObject, ::Tuple{SparseMatrixCSC{Float64,Int64}}, ::Int64, ::Ptr{Nothing}) at /Users/sheehanolver/.julia/packages/PyCall/0jMpb/src/pyfncall.jl:24
 [6] #pycall#88 at /Users/sheehanolver/.julia/packages/PyCall/0jMpb/src/pyfncall.jl:11 [inlined]
 [7] pycall at /Users/sheehanolver/.julia/packages/PyCall/0jMpb/src/pyfncall.jl:86 [inlined]
 [8] #spy#108(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::SparseMatrixCSC{Float64,Int64}) at /Users/sheehanolver/.julia/packages/PyPlot/fZuOQ/src/PyPlot.jl:179
 [9] spy(::SparseMatrixCSC{Float64,Int64}) at /Users/sheehanolver/.julia/packages/PyPlot/fZuOQ/src/PyPlot.jl:176
 [10] top-level scope at none:0

@stevengj
Copy link
Member

Closed by JuliaPy/PyCall.jl#653

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants