I have the following codes:
julia> A = [1 2; 3 4];
julia> function test!(A)
A = permutedims(A, [2,1])
test! (generic function with 1 method)
Could someone explain why I reassign A inside test!, but A is not changed? Thanks!
Never mind, I have answer to my own question (I can change the values but cannot change the pointer and permutedims create a new local variable). I have another related question. I have the following codes:
A = [1 2; 3 4]
b = [5.0 7; 6 8]
sol = A\b
b .= sol
b = permutedims(b,[2,1]) # permute rows vs columns
b = permutedims(b,[2,1])
The idea is I want to call solve two times, first with the columns, then with the rows. However, I do not want to create new local variable. If permutedims can manipulate b (like reshape) and does not create new local variable, then it will be great! Is there anyway to handle this case? Basically the idea is I do not want to create a local variable to improve the performance. Thanks.
b' which is a lazy transpose. Also, consider calling
factorize(A) and use the returned object to solve twice.
julia> using LinearAlgebra
ldiv!(Y, A, B) -> Y
Compute A \ B in-place and store the result in Y, returning the result.
The argument A should not be a matrix. Rather, instead of matrices it should be
a factorization object (e.g. produced by factorize or cholesky). The reason for
this is that factorization itself is both expensive and typically allocates
memory (although it can also be done in-place via, e.g., lu!), and
performance-critical situations requiring ldiv! usually also require
fine-grained control over the factorization of A.