Git Product home page Git Product logo

Comments (8)

ShrutiRDalvi avatar ShrutiRDalvi commented on June 2, 2024 1

Hello, Is anyone currently working on this, if not I'd love to help out. Thanks

from julia.

dkarrasch avatar dkarrasch commented on June 2, 2024 1

Just go ahead!

from julia.

stevengj avatar stevengj commented on June 2, 2024

Since reverse calls Base._reverse(A, dims), you can overload the latter to dispatch on dims being an integer, e.g.

Base._reverse(A::Diagonal, dims::Integer) = reverse!(Matrix(A); dims)

Should be an easy PR — just add a few of these methods and a test that reverse(A, dims=x) == reverse(Matrix(A), dims=x).

You could also add specialized reverse methods for dims=: (i.e., reversing both dimensions) while you are at it, e.g.

Base._reverse!(A::Diagonal, dims::Colon) = (reverse!(A.diag); A)

(Note that this is the lower-level in-place variant, called by reverse.)

from julia.

ShrutiRDalvi avatar ShrutiRDalvi commented on June 2, 2024

hello, I was struggling a bit with solving this issue. If someone could tell me exactly where(ie in which files) I need to overload the method, that would help a lot, thanks!

from julia.

jishnub avatar jishnub commented on June 2, 2024

Please submit the fixes to the main Julia repo, where you would need to add the methods to "stdlib/LinearAlgebra/src/diagonal.jl" etc. I would recommend extending reverse directly instead of the internal _reverse, as the latter isn't public.

from julia.

Sahiti004 avatar Sahiti004 commented on June 2, 2024

Hi, I've been trying to solve this issue, Can you please clarify some doubts:
1)We do not want the error to be thrown anytime when we try to set off diagonal indices? or only for reverse?

In diagonal.jl:

function setindex!(D::Diagonal, v, i::Int, j::Int)
@BoundsCheck checkbounds(D, i, j)
if i == j
@inbounds D.diag[i] = v
elseif !iszero(v)
throw(ArgumentError(lazy"cannot set off-diagonal entry ($i, $j) to a nonzero value ($v)"))
end
return v
end

Should we convert everything from diagonal to matrix here and then set index?

  1. Should we make changes in the file "base/arraymath.jl", if yes, should we import diagonal, Identity matrix etc to give in place of AbstractArray or AbstractMatrix?

reverse(A::AbstractArray; dims=:) = _reverse(A, dims)
reverse(A::Diagonal, dims=:) =_reverse(Matrix(A), dims)

Thank you

from julia.

stevengj avatar stevengj commented on June 2, 2024

You would need to make the changes in the LinearAlgebra standard library, which is where the types are defined, e.g. in diagonal.jl for handling the Diagonal type. For example, in diagonal.jl, you should only need to add three lines:

Base._reverse(A::Diagonal, dims) = reverse!(Matrix(A); dims)
Base._reverse(A::Diagonal, dims::Colon) = Diagonal(reverse(A.diag))
Base._reverse!(A::Diagonal, dims::Colon) = (reverse!(A.diag); A)

which gives

julia> reverse(Diagonal([1,2,3]))
3×3 Diagonal{Int64, Vector{Int64}}:
 3    
   2  
     1

julia> reverse(Diagonal([1,2,3]), dims=1)
3×3 Matrix{Int64}:
 0  0  3
 0  2  0
 1  0  0

The code for Tridiagonal etcetera should be very similar.

(Similarly, one could add optimized methods for SparseArrays.jl, but that's probably a separate issue. Optimized methods already exist for sparse arrays: JuliaSparse/SparseArrays.jl#450)

We do not want the error to be thrown anytime when we try to set off diagonal indices?

You're not trying to set any offdiagonal indices in the above methods.

reverse!(Diagonal([1,2,3]), dims=1) already correctly throws an error, and will still do so once the above methods are added.

from julia.

Sahiti004 avatar Sahiti004 commented on June 2, 2024

Got it, Thank you, I created a pull request, please review it

from julia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.