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

Matrix-Vector, Vector-Matrix, Vector-Vector product #276

Closed
oxinabox opened this issue Oct 8, 2020 · 3 comments · Fixed by #305
Closed

Matrix-Vector, Vector-Matrix, Vector-Vector product #276

oxinabox opened this issue Oct 8, 2020 · 3 comments · Fixed by #305
Labels

Comments

@oxinabox
Copy link
Member

oxinabox commented Oct 8, 2020

I think this can probably use the same rules as out Matrix-Matrix products,
but it wants some tests to confirm.
Might even be just swapping AbstractMatrix for AbstractVecOrMat

A lot of these products are nonsense.
but that is ok, they will error on the primal pass

@gxyd
Copy link
Contributor

gxyd commented Nov 9, 2020

Though a vector-matrix product is valid and can be computed.

julia> A
2-element Array{Float64,1}:
 -3.0
  0.0
julia> B
1×4 Array{Float64,2}:
 -9.0  7.0  -5.0  -7.0
julia> A * B
2×4 Array{Float64,2}:
 27.0  -21.0  15.0  21.0
  0.0    0.0   0.0   0.0

But in the rule definition mul! is used, documentation of which says:

mul!(Y, A, B) -> Y

Calculates the matrix-matrix or matrix-vector product $AB$
and stores the result in Y, overwriting the existing value of Y.
Note that Y must not be aliased with either A or B.

So it would be ok from the primal computation side, but would error while computing its derivative.

@gxyd
Copy link
Contributor

gxyd commented Nov 10, 2020

@oxinabox anything on the above?

@oxinabox
Copy link
Member Author

I don't understand the problem.

mul! works fine for any mixture of matrixes, vectors, and numbers, that doesn't result in a dimension mismatch.
Except for Union{Transpose{<:Vector}, Adjoint{<:Vector}}, * Vector since that one yeilds a scalar.

But in anycase for things that don't work by relaxing signatures we just write a seperate rule, and it is not a problem?

gxyd pushed a commit to gxyd/ChainRules.jl that referenced this issue Nov 11, 2020
oxinabox added a commit that referenced this issue Nov 17, 2020
* add rules for vector-matrix and matrix-vector product

Fixes #276

* fix bug in test function writing

* add separate dispatch for Vector * Matrix

* fix tests for Matrix*Vector, Vector*Matrix

* fix test

* Assert about size

* bump version

Co-authored-by: Lyndon White <oxinabox@ucc.asn.au>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants