-
Notifications
You must be signed in to change notification settings - Fork 6
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
Indicate QuArray as transposed/dual #9
Comments
+1 It is safe to assume that |
@jiahao I would promote the idea of implementing dual vector space in the base Julia. To me, Julia makes vectors as pure one-dimensional objects that is really a good thing. Yet, I feel the vectors in Julia are lack of some native mathematical structures, which might have lead to the problems of vector transposes and so forth. There have been various solutions proposed by @StefanKarpinski, @andreasnoack, @Jutho and others. I think maybe we can use @andreasnoack's idea to implement something for |
I don't think the basic Vector's in Julia need a mathematical structure, they are programming structures, i.e. lists, the computer theory type of vector. Sometimes they represent mathematical vectors, sometimes something different, and sometimes it is more natural to represent mathematical vectors in a different way that doesn't fit in the AbstractVector type hierarchy. If one tries to force a specific mathematical structure in Julia base, it will never be possible to satisfy everybody's need. That being said, there does need to be a simple wrapper type for representing the transpose of vector or matrix, in order to be able to support writing compact matrix algebra expressions involving products of vectors and matrices and their transposes. I think that's also the conclusion from JuliaLang/julia#6837. |
If we use a wrapper type for transposition, how do we handle other wrapper types with QuArrays as fields? This is relevant because DiracArrays in QuDirac are wrappers around QuArrays (I want to avoid having to duplicate functionality that already exists in QuBase). For example, we can define the following right now:
...and delegate the transpose to This could be a non-issue if we defined things like so:
This allows |
The other potential way forward to solve the above issue is to try to write QuArray methods more generically than they have been written so far. We could define basic accessor methods on QuArray, and then make all of our other methods act on AbstractQuArray. Or even further, we could go the duck typing route for such methods, only using type annotations to avoid ambiguity (which, I believe, is the "Julian" way anyway). I think lessening the type restrictions on the functions we have could put us in a better position to tackle future work. I'll try to get a PR in this weekend so that we have a more practical basis for discussing this. |
After spending a good amount of time playing around with QuCoeffs and reviewing the code from JuliaLang/julia#6837, I've gone back and implemented lazy Transpose/CTranspose/Conjugate wrapper types for QuArrays and tossed away the QuCoeffs work. In an attempt to kick the tires a bit, the new stuff is currently on master (see 87bb3a6). It's mostly inspired by JuliaLang/julia@1919d59. However, without the limitation on having these types be subtyped to AbstractArray, our implementation becomes a little simpler. I've also included a Conjugate type for the same reasons of view vs. copy consistency that have been previously discussed. At this point, I've tried a bunch of different ways to wrap eagerly conjugated/transposed coefficients in a way that solves the relevant ambiguity issues, but every method I thought of ended up being too inconsistent to be sustainable. My goal was to solve the problem in such a way that we could fall back to the "multiplication zoo" (A_mul_b etc.) on the wrapped coefficients for most operations, the benefit being that a lot of coefficient container types are going to have those methods already overloaded to act efficiently with that type. When I went to define some of these methods for general QuArray operations, though, enforcing type consistency became nightmarish - I couldn't trust operations on eagerly transposed arrays to return arrays of the expected dimensionality...which is, I suppose, the crux of the issue in the first place. Thus, I've implemented the aforementioned lazy types and have landed on the side of us doing the work to define efficient multiplication methods for special array representations. Though it'll be more work, it will at the very least be consistent and easier to reason about. Thoughts? |
Maybe I am making this too simple, but given the implementation in master, couldn't we just have
and so on (probably plus some checks and taking care of products of basis functions)? Or maybe this is what you meant? I think this would be fine. Of course we want to have mutating versions as well, which might be trickier ... I noticed that |
What I was having trouble with was ensuring the proper return type for an operation by falling back to the Mathematically, it's a row vector - currently, a QuArray row vector is explicitly a We can't wrap it in a QuArray without vectorizing the result first, since coefficient dimension is enforced to equal the number of bases present, such that a QuVector really stores a V<:AbstractVector and not a M<:AbstractMatrix (which could actually be a Julian row vector). Previously, this was not the case - the dimension of a QuArray was solely defined by the number of bases present, so that one could have a QuArray row vector of type Now that I've actually written that out, perhaps it wouldn't be a bad thing to go back to conflating row vectors and column vectors. It's still better than conflating row vectors and matrices, and might allow us to fall back to Also, the switch from |
Since we don't store the actual coefficients in |
So, basically this should work and is type-safe
(I am still using |
^Perfect, made a PR using this method. Hopefully if there aren't any problems with it we can finally close this issue. |
Closed by JuliaLang/julia#14 |
We should have some way to indicate that a
QuVector
or aQuMatrix
is transposed/dual. I am thinking of something like JuliaLang/julia#6837, i.e. introducing a dual/transposed type. This would make it easier to define inner products and such.references: JuliaLang/julia#6837, JuliaLang/LinearAlgebra.jl#42
The text was updated successfully, but these errors were encountered: