First of all, on a general note, if you wrap your code in a triple tick block ``` <code goes here> ```
it will be displayed much more nicely.
To your actual questions:
The reason why many things in Julia are stored in special types (not just Q
of a QR decomposition) is generally two fold:

Data structuring: we can store the object much more efficiently while still make them behave as if they were, say, an AbstractMatrix
. This is known as duck typing. As long as it quacks and walks like a duck, from an outsiders point of view it is a duck. Example: Diagonal(D)
. Clearly, it would be a waste of memory to store all the zero matrix elements for a diagonal matrix. Hence, internally, we only store the diagonal entries as a vector (see here that this is indeed what Julia does.). However, the Diagonal
matrix will still behave like a regular matrix in many cases.

Method dispatch: special function implementations. Julia always selects a specific method of a function based on all argument types (multiple dispatch). We can utilize this to implement special, fast algorithms for certain matrix types. Example: say, I’d want to calculate the determinant of a Diagonal
matrix. Naively, I could treat it like any other Matrix
and use something like the Rule of Sarrus (assuming 3x3
here for the sake of the argument). Obviously, it would be much more efficient to only multiply the nonzero diagonal elements. This is precisely what Julia does.
Turning to your specific case, we can check what that QRCompactWY
object really is by asking for help in the REPL, ? QRCompactWY
, or consulting the docs. Personally, I don’t know anything about this format (frankly, I also don’t care), but there I’d find all the implementation details. In many cases, a QRCompactWY
will just behave like a matrix. For example, I can multiply it with a vector, which will call a nongeneric implementation of *
in qr.jl
(check @which Q * rand(3)
).
If you feel that log(Q::QRCompactWY)
should work as well, than perhaps there is a special implementation or a fallback method missing in stdlib/LinearAlgebra/qr.jl
. You could consider opening an issue or even better a pull request in that case.
Note that you can always access the fallback by changing Q
s type (and hence its data structure) first, by calling log(Matrix(Q))
.