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

Make convert(::Type{(Lower|Upper)Triangular}, A::Bidiagonal) preserve storage structure. Add equivalent methods for Unit(Lower|Upper)Triangular. #17656

Closed
wants to merge 1 commit into from

Conversation

Sacha0
Copy link
Member

@Sacha0 Sacha0 commented Jul 27, 2016

convert(::Type{LowerTriangular}, A::Bidiagonal) and convert(::Type{UpperTriangular}, A::Bidiagonal) do not preserve Bidiagonal storage structure due to full calls, respectively returning LowerTriangular{T,Matrix{T}} and UpperTriangular{T,Matrix{T}}. Equivalent methods for Unit(Lower|Upper)Triangular do not exist.

This pull request makes the former ((Lower|Upper)Triangular) methods preserve Bidiagonal storage structure, introduces equivalent methods for Unit(Lower|Upper)Triangular, revises related error throws, and tests the lot. Best!

…idiagional storage structure. Add equivalent methods for conversion from Bidiagonal to Unit(Upper|Lower)Triangular. Group methods and revise error messages. Test.
# methods for conversion from Bidiagonal to [Unit](Upper|Lower)Triangular
function convert(::Type{LowerTriangular}, A::Bidiagonal)
if A.isupper
throw(ArgumentError("upper Bidiagonal matrices cannot be converted to LowerTriangular"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it could if all the off-diagonals are zero?

Copy link
Member Author

@Sacha0 Sacha0 Jul 27, 2016

Choose a reason for hiding this comment

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

It could, which segues to a related issue.

On the one hand, existing {constructors for annotation types} that accept an A<:AbstractMatrix as the primary argument do not require that A 'conform' to the annotation. For example, LowerTriangular(Bidiagonal(rand(5), rand(4), true)) and Symmetric(rand(5,5)) are always valid.

On the other hand, convert(::Type{$(AnnotationType)}, A::$(SpecialMatrixType))-like methods inconsistently require that A 'conform' to the annotation type either in storage structure (e.g. as in the code you identified) or in value (e.g. as in your suggestion). And equivalent convert methods from other storage types (e.g. Matrix, SparseMatrixCSC) to annotation types do not appear to exist. For example, convert(LowerTriangular, rand(4, 4)) throws a MethodError.

Do convert methods from special matrix types to annotation types make sense generally? If so, how should they behave? Also if so, shouldn't equivalent convert methods from other storage types to annotation types exist? And otherwise, why do these particular methods exist?

Thoughts? Best!

Edit: Maybe I should open a dedicated issue?
Edit: grep -rn 'convert(LowerTriangular base/` yields nothing, FWIW.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're very much getting into #8001 territory here. If you think of the "annotation wrapper type" as a view into whatever subset of the underlying array happens to be important for that type of annotation, then I guess the structure and the contents of the "inactive" part of the wrapper-type view don't actually matter and could be anything.

Is wrapping around an object always the meaning we should give for convert here? Maybe not as that could get confusing. But then since constructors and convert are pretty closely tied together at the moment, I'm not sure what syntax you would use as an alternative to the constructors.

@Sacha0
Copy link
Member Author

Sacha0 commented Jul 31, 2016

Superseded by #17723.

@Sacha0 Sacha0 closed this Jul 31, 2016
@Sacha0 Sacha0 deleted the bidiagconvtri branch August 7, 2016 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants