Skip to content

adnaanz/lsu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LSU Factorization in PyTorch 🚀

LSU Factorization

Welcome to the LSU repository! This project implements the LSU factorization of a matrix using PyTorch. LSU factorization is an essential technique in numerical linear algebra, allowing for efficient computations and solutions in various applications.

Table of Contents

Introduction

LSU factorization is a variant of LU decomposition, tailored for specific matrix structures. It provides a way to express a matrix as a product of lower and upper triangular matrices. This decomposition is crucial for solving systems of linear equations, inverting matrices, and computing determinants.

Our implementation leverages PyTorch, a powerful library for tensor computations, making it easy to integrate LSU factorization into deep learning workflows. The repository aims to provide a straightforward and efficient solution for those needing LSU factorization in their projects.

To get started, please visit our Releases section for the latest version. You can download the necessary files and execute them to begin your journey with LSU factorization.

Installation

To use this repository, ensure you have Python and PyTorch installed on your system. You can install PyTorch by following the instructions on the official PyTorch website.

Clone the Repository

You can clone the repository using the following command:

git clone https://github.com/adnaanz/lsu.git

Install Requirements

Navigate to the project directory and install the required packages:

cd lsu
pip install -r requirements.txt

Usage

Once you have installed the repository, you can use the LSU factorization functions in your Python scripts. Here’s a basic example:

import torch
from lsu import lsu_factorization

# Create a random matrix
matrix = torch.rand(4, 4)

# Perform LSU factorization
L, S, U = lsu_factorization(matrix)

print("Lower Triangular Matrix L:")
print(L)
print("Diagonal Matrix S:")
print(S)
print("Upper Triangular Matrix U:")
print(U)

Function Overview

  • lsu_factorization(matrix): This function takes a matrix as input and returns the lower triangular matrix ( L ), the diagonal matrix ( S ), and the upper triangular matrix ( U ).

Features

  • Efficient Computation: The implementation is optimized for performance using PyTorch's tensor operations.
  • Easy Integration: Seamlessly integrate LSU factorization into existing PyTorch workflows.
  • Documentation: Comprehensive documentation and examples to help you get started quickly.
  • Support for Different Matrix Sizes: The implementation can handle various matrix sizes and types.

Examples

Here are a few examples to demonstrate the capabilities of the LSU factorization implementation:

Example 1: Basic LSU Factorization

import torch
from lsu import lsu_factorization

matrix = torch.tensor([[4.0, 3.0], [6.0, 3.0]])
L, S, U = lsu_factorization(matrix)

print("Matrix:")
print(matrix)
print("L:")
print(L)
print("S:")
print(S)
print("U:")
print(U)

Example 2: Solving Linear Equations

You can use the factorized matrices to solve linear equations efficiently. Here's how:

import torch
from lsu import lsu_factorization

matrix = torch.tensor([[4.0, 3.0], [6.0, 3.0]])
b = torch.tensor([10.0, 12.0])
L, S, U = lsu_factorization(matrix)

# Forward substitution to solve L * y = b
y = torch.linalg.solve(L, b)

# Back substitution to solve U * x = y
x = torch.linalg.solve(U, y)

print("Solution x:")
print(x)

Contributing

We welcome contributions from the community! If you would like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them.
  4. Push your branch to your forked repository.
  5. Open a pull request with a clear description of your changes.

Please ensure your code adheres to the existing style and includes appropriate tests.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For questions or feedback, please reach out to the repository maintainer:

Thank you for checking out the LSU repository! We hope you find it useful for your matrix factorization needs. For the latest updates and releases, visit our Releases section.