Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Add lu decomposition for Tensors #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jofrevalles
Copy link
Member

@jofrevalles jofrevalles commented May 8, 2023

Summary

This PR adds a new lu function for tensors, extending the LinearAlgebra.lu function (resolve #3). The new lu function returns the LU decomposition of a Tensor, where the tensor can be recovered by contracting the permutation tensor P, the tensor L, and tensor U. The tensors L and U are reshaped versions of the original lower and upper triangular matrices obtained during the decomposition process, respectively.

This implementation is inspired by the LU decomposition in the scipy library, as it returns the permutation tensor P allowing the original tensor A to be recovered with the contraction A = P * L * U. This contrasts with LinearAlgebra, where the permutation vector p is returned, and the original matrix can be recovered with P' * A = L * U (where P' is the permutation matrix built from p).

Please let me know if there are any concerns or issues with extending the LinearAlgebra library in this manner.

We have also added tests for this new function.

Example

A usage example of the lu function:

julia> using Tenet; using LinearAlgebra; using Test

julia> tensor = Tensor(rand(4, 4, 4), (:i, :j, :k))
4×4×4 Tensor{Float64, 3, Array{Float64, 3}}:
...

julia> P, L, U = lu(tensor, left_inds = labels(tensor)[1:2])
...

julia> @test contract(contract(P, L), U)  tensor
Test Passed

@codecov
Copy link

codecov bot commented May 8, 2023

Codecov Report

Merging #26 (dc51736) into master (bff2de5) will increase coverage by 1.56%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #26      +/-   ##
==========================================
+ Coverage   82.67%   84.23%   +1.56%     
==========================================
  Files           5        5              
  Lines         202      222      +20     
==========================================
+ Hits          167      187      +20     
  Misses         35       35              
Impacted Files Coverage Δ
src/Numerics.jl 95.71% <100.00%> (+1.71%) ⬆️

@jofrevalles jofrevalles requested a review from mofeing May 17, 2023 08:47
@mofeing
Copy link
Member

mofeing commented May 17, 2023

I need more time to check why we need P and the details of the implementation. Since this is not a hurry, I will check it out whenever I have some free time.

@mofeing mofeing added the on-hold Blocked due to some reason label Jul 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
on-hold Blocked due to some reason
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement LU factorization
2 participants