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

isone(A) throws error when A is not a StridedMatrix #25516

Closed
dlfivefifty opened this issue Jan 11, 2018 · 1 comment · Fixed by #41634
Closed

isone(A) throws error when A is not a StridedMatrix #25516

dlfivefifty opened this issue Jan 11, 2018 · 1 comment · Fixed by #41634
Labels
good first issue Indicates a good issue for first-time contributors to Julia

Comments

@dlfivefifty
Copy link
Contributor

This is inconsistent (I came across it while looking through Base to see if I can resolve #10385):

julia> V = view(rand(5,5), [1,3,4], :)
3×5 view(::Array{Float64,2}, [1, 3, 4], :) with eltype Float64:
 0.68645    0.906707  0.474079  0.156336  0.689158 
 0.0366613  0.705923  0.286435  0.169441  0.0788967
 0.602231   0.19818   0.883198  0.796978  0.416841 

julia> isone(V)
ERROR: DimensionMismatch("multiplicative identity defined only for square matrices")
Stacktrace:
 [1] _one at ./array.jl:393 [inlined]
 [2] one at ./array.jl:397 [inlined]
 [3] isone(::SubArray{Float64,2,Array{Float64,2},Tuple{Array{Int64,1},Base.Slice{Base.OneTo{Int64}}},false}) at ./number.jl:45
 [4] top-level scope

julia> isone(rand(3,5))
false

A simple fix is to replace isone(A::StridedMatrix) definition with isone(A::AbstractMatrix).

(I don't see any reason why the definitions for isone were specialized to StridedMatrix.)

@sostock sostock added the good first issue Indicates a good issue for first-time contributors to Julia label Jul 10, 2021
@ThatcherT
Copy link
Contributor

I'm a first time contributor so I'm not entirely sure I've done this correctly. I opened up a pull request with the changes suggested by @dlfivefifty and I added a simple test. Do I need to take anymore action @sostock?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants