Skip to content

Conversation

mcabbott
Copy link
Collaborator

@mcabbott mcabbott commented Nov 27, 2024

This copies JuliaLang/julia#43719 to the new LinearAlgebra.jl repository (partly to see if this all works!) The original PR was JuliaLang/julia#39467

Tests passed on CI in Feb, but I have not checked anything locally.

(Closes JuliaLang/julia#43719)

@KristofferC
Copy link
Member

The windows CI error

ERROR: Unable to open agent private key path 'C:\secrets/agent.key'!  Make sure your agent has this file deployed within it!

happens spuriously and even happens on Julia repo tests sometimes.

@mcabbott
Copy link
Collaborator Author

mcabbott commented Dec 4, 2024

Bump? After rebasing this passes CI.

The original PR was approved, but reverted because it broke the tests of some later PR (which was merged first). That code has since been edited not to rely on the absence of this optimisation, which is why tests pass again now.

(In fact I have a merge button, but am not sure what the rules are on my using it, and thus would prefer someone else to approve.)


# these make eachrow(A') produce simpler views
@inline Base.unsafe_view(A::Transpose{<:Number, <:AbstractMatrix}, i::Integer, j::AbstractArray) =
Base.unsafe_view(parent(A), j, i)
Copy link
Member

@jishnub jishnub Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably call view on the parent, as the parent might have a specialized view implementation that avoids the SubArray wrapper.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we also do something similar for transposes of AbstractVectors, with one AbstractVector index?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially said the wrong thing, because I've forgotten how this all works, but in fact that case is already handled (and tested). It's why the reshape(v, ::Val{1}) method is defined above.

I'm hesitant to start editing as I do not have the details fresh in my head, and do not wish to introduce fresh mistakes. The pervious PR reverted mine with no changes, this PR un-does the reversion.

Base.reshape(v::AdjointAbsVec{<:Real}, ::Val{1}) = parent(v)

# these make eachrow(A') produce simpler views
@inline Base.unsafe_view(A::Transpose{<:Number, <:AbstractMatrix}, i::Integer, j::AbstractArray) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use the alias TransposeAbsMat like the TransposeAbsVec alias used in reshape?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK why it's written this way, it's possible I followed nearby code which writes e.g. Base.strides(A::Adjoint{<:Real, <:AbstractMatrix}) and does not seem to use TransposeAbsMat. Maybe I was concerned about order of definitions or something?

vec(v::TransposeAbsVec{<:Number}) = parent(v)
vec(v::AdjointAbsVec{<:Real}) = parent(v)

Base.reshape(v::TransposeAbsVec{<:Number}, ::Val{1}) = parent(v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should reshape(v, ::Colon) and such behave identically? Or is the Val(1) reshaping used in the view below? E.g.:

julia> v = 1:4
1:4

julia> reshape(v', :)
4-element reshape(adjoint(::UnitRange{Int64}), 4) with eltype Int64:
 1
 2
 3
 4

julia> reshape(v', Val(1))
1:4

It might be a good idea to have these all return a range, but that may be a separate PR.

Copy link
Collaborator Author

@mcabbott mcabbott Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this PR is only about view. And some views call this (internal?) method with Val.

The "supported" way to do that reshape is:

julia> vec(v')
1:4

The default definition is vec(a::AbstractArray) = reshape(a,length(a)), and at present reshape(v', 4) also has no shortcut.

Copy link
Member

@jishnub jishnub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@mcabbott mcabbott merged commit 4a3dbf8 into JuliaLang:master Dec 4, 2024
2 checks passed
@mcabbott mcabbott deleted the adjointview branch December 4, 2024 18:04
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

Successfully merging this pull request may close these issues.

3 participants