Comments (8)
Hello, Is anyone currently working on this, if not I'd love to help out. Thanks
from julia.
Just go ahead!
from julia.
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.
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.
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.
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?
- 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.
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.
Got it, Thank you, I created a pull request, please review it
from julia.
Related Issues (20)
- Broken linkerscript, julia fails to link with modern lld versions HOT 2
- Documentation bug: `MainInclude`
- Confusing error when defining a method within nested testsets
- [FEATURE] Using Right Arrow Key to Auto Complete Virtual Text?
- should matrix-vector mul! also protect against aliasing? HOT 2
- code reports an error to line 0 HOT 6
- Average of Dates HOT 15
- safety consideration for operations with incompletely initialized types HOT 2
- Dimension check too restrictive in copytrito! and lacpy!
- LLVMPtr's address space annotation is lost with opaque pointers
- Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffad71a9977 -- gc_setmark_pool_ HOT 9
- confusing error thrown by `display` HOT 1
- Make `ScopedValues.get` a method of `Base.get` HOT 7
- Julia without libstdc++ HOT 8
- `--threads` option seems to now result in segfault in `jl_init_thread_heap` (`julia/src/gc.c:3992`) HOT 1
- `strings/annotated` test relies on that StyledStrings have been loaded HOT 1
- Not all `StridedArray`s follow the strided array API
- GC could do with more consolidated intro user documentation
- Stackoverflow without stacktrace when `convert`ing large tuple HOT 4
- `atexit()` finalizers should not run after encountering `SIGSEGV`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.