{"id":22895501,"url":"https://github.com/kgruiz/linalg-practice","last_synced_at":"2026-04-21T16:40:10.694Z","repository":{"id":259311670,"uuid":"876973238","full_name":"kgruiz/LinAlg-Practice","owner":"kgruiz","description":"LinAlg-Practice is a Python library developed to deepen my understanding of linear algebra through hands-on implementation of various matrix operations. It includes comprehensive tests that compare the results with established libraries like NumPy to ensure accuracy and reliability.","archived":false,"fork":false,"pushed_at":"2024-11-28T06:31:19.000Z","size":293,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T01:44:17.777Z","etag":null,"topics":["algorithms","data-science","linear-algebra","math","matrix-operations","numpy","python","sympy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kgruiz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-22T21:38:00.000Z","updated_at":"2024-11-28T06:31:23.000Z","dependencies_parsed_at":"2024-12-13T23:30:03.251Z","dependency_job_id":null,"html_url":"https://github.com/kgruiz/LinAlg-Practice","commit_stats":null,"previous_names":["kgruiz/linalg-practice"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgruiz%2FLinAlg-Practice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgruiz%2FLinAlg-Practice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgruiz%2FLinAlg-Practice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kgruiz%2FLinAlg-Practice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kgruiz","download_url":"https://codeload.github.com/kgruiz/LinAlg-Practice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246552892,"owners_count":20795837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","data-science","linear-algebra","math","matrix-operations","numpy","python","sympy"],"created_at":"2024-12-13T23:29:55.772Z","updated_at":"2026-04-21T16:40:05.643Z","avatar_url":"https://github.com/kgruiz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LinAlg-Practice\n\nA comprehensive Python library designed to deepen my understanding of linear algebra through hands-on implementation. LinAlg-Practice offers advanced matrix operations, including Reduced Row Echelon Form (RREF), QR Decomposition, Gram-Schmidt Orthogonalization, matrix inversion, determinant calculation, and more. The accompanying tests in `Main.py` compare my implementations with established packages like NumPy to ensure accuracy and reliability.\n\n## Table of Contents\n\n- [Features](#features)\n  - [Matrix Types](#matrix-types)\n  - [Basic Matrix Operations](#basic-matrix-operations)\n  - [Advanced Matrix Operations](#advanced-matrix-operations)\n  - [Vector Operations](#vector-operations)\n  - [Utilities](#utilities)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Basic Operations](#basic-operations)\n  - [Advanced Operations](#advanced-operations)\n  - [Vector Operations](#vector-operations)\n  - [Utilities](#utilities)\n- [Testing Framework](#testing-framework)\n- [Performance Analysis](#performance-analysis)\n\n## Features\n\n### Matrix Types\n\n- **Matrix**: Represents an integer matrix with support for symbolic entries using `sympy`.\n- **FloatMatrix**: Represents a floating-point matrix, allowing for decimal precision.\n- **Base2Matrix**: Represents a binary matrix (elements are either 0 or 1), useful for applications in computer science and information theory.\n\n### Basic Matrix Operations\n\n- **Addition (`MatrixAdd`)**: Add two matrices of identical dimensions.\n- **Subtraction (`MatrixSubtract`)**: Subtract one matrix from another of identical dimensions.\n- **Scalar Multiplication (`ScalarMultiply`)**: Multiply a matrix by a scalar value.\n- **Transpose (`Transpose`)**: Transpose a matrix, swapping rows with columns.\n\n### Advanced Matrix Operations\n\n- **Matrix Multiplication (`MatrixMultiply`)**: Multiply two matrices, ensuring the number of columns in the first matrix matches the number of rows in the second.\n- **Reduced Row Echelon Form (`RREF` and `Base2RREF`)**: Convert a matrix to its reduced row echelon form, facilitating solutions to linear systems.\n- **QR Decomposition (`QRDecomposition`)**: Decompose a matrix into an orthogonal matrix Q and an upper triangular matrix R.\n- **Gram-Schmidt Orthogonalization (`GramSchmidt`)**: Generate an orthonormal basis from a set of vectors.\n- **Determinant Calculation (`Determinat`)**: Compute the determinant of a square matrix.\n- **Matrix Inversion (`Inverse`)**: Calculate the inverse of an invertible square matrix.\n- **Basis Calculation (`Basis`)**: Determine a basis for the column space of a matrix.\n- **Matrix Appending (`MatrixAppend`)**: Append two matrices either horizontally or vertically.\n- **Identity Matrix Creation (`Idn` and `FloatIdn`)**: Generate identity matrices of integer or floating-point types.\n- **Ensuring Binary Constraints (`EnsureNoTwo`)**: Ensure that binary matrices do not contain invalid entries (e.g., the number 2).\n\n### Vector Operations\n\n- **Dot Product (`VectorDot`)**: Compute the dot product of two vectors.\n- **Vector Length (`Length`)**: Calculate the Euclidean norm of a vector.\n- **Unit Vector (`UnitVector`)**: Normalize a vector to have a unit length.\n\n### Utilities\n\n- **Matrix Reshaping and Flattening**: Convert between different matrix shapes as needed for various operations.\n- **Symbolic Matrix Support**: Integrate with `sympy` to handle symbolic mathematics within matrices.\n\n## Installation\n\n1. **Clone the Repository**\n\n   ```bash\n   git clone https://github.com/yourusername/LinAlg-Practice.git\n   cd LinAlg-Practice\n   ```\n\n2. **Create a Virtual Environment (Optional but Recommended)**\n\n   ```bash\n   python -m venv venv\n   source venv/bin/activate  # On Windows: venv\\Scripts\\activate\n   ```\n\n3. **Install Dependencies**\n\n   ```bash\n   pip install numpy sympy matplotlib tqdm\n   ```\n\n## Usage\n\n### Basic Operations\n\n```python\nfrom Matrix import Matrix\nfrom MatrixAdd import MatrixAdd\nfrom MatrixSubtract import MatrixSubtract\nfrom ScalarMultiply import ScalarMultiply\nfrom Transpose import Transpose\nfrom MatrixMultiply import MatrixMultiply\n\n# Create two matrices\na = Matrix(3, 3, min_=1, max_=10)\nb = Matrix(3, 3, min_=1, max_=10)\n\nprint(f\"Matrix A:\\n{a}\")\n\nprint(f\"Matrix B:\\n{b}\")\n\n# Add matrices\nc = MatrixAdd(a, b)\nprint(f\"A + B:\\n{c}\")\n\n# Subtract matrices\nd = MatrixSubtract(a, b)\nprint(f\"A - B:\\n{d}\")\n\n# Scalar multiplication\ne = ScalarMultiply(5, a)\nprint(f\"5 * A:\\n{e}\")\n\n# Transpose\nf = Transpose(a)\nprint(f\"Transpose of A:\\n{f}\")\n\n# Matrix multiplication\ng = MatrixMultiply(a, b)\nprint(f\"A * B:\\n{g}\")\n```\n\n### Advanced Operations\n\n```python\nfrom RREF import RREF\nfrom QRDecomposition import QRDecomposition\nfrom GramSchmidt import GramSchmidt\nfrom Determinat import Determinat\nfrom Inverse import Inverse\nfrom Basis import Basis\n\n# Reduced Row Echelon Form\nrrefA = RREF(a)\nprint(f\"RREF of A:\\n{rrefA}\")\n\n# QR Decomposition\nq, r = QRDecomposition(a)\nprint(f\"QR Decomposition of A:\")\nprint(f\"Q:\\n{q}\")\nprint(f\"R:\\n{r}\")\n\n# Gram-Schmidt Orthogonalization\northonormalBasis = GramSchmidt(a)\nprint(f\"Orthonormal Basis from A:\\n{orthonormalBasis}\")\n\n# Determinant\ndetA = Determinat(a)\nprint(f\"Determinant of A:\\n{detA}\")\n\n# Inverse (if A is invertible)\ninvA = Inverse(a)\nif invA:\n    print(f\"Inverse of A:\\n{invA}\")\nelse:\n    print(\"Matrix A is singular and cannot be inverted.\")\n\n# Basis of Column Space\nbasisA = Basis(a)\nprint(f\"Basis of Column Space of A:\\n{basisA}\")\n```\n\n### Vector Operations\n\n```python\nfrom VectorDot import VectorDot\nfrom VectorLength import Length\nfrom UnitVector import UnitVector\n\n# Create two vectors\nv1 = Matrix(1, 3, min_=1, max_=5)\nv2 = Matrix(1, 3, min_=1, max_=5)\n\nprint(f\"Vector v1:\\n{v1}\")\n\nprint(f\"Vector v2:\\n{v2}\")\n\n# Dot product\ndotProduct = VectorDot(v1, v2)\nprint(f\"Dot Product of v1 and v2:\\n{dotProduct}\")\n\n# Vector length\nlengthV1 = Length(v1)\nprint(f\"Length of v1:\\n{lengthV1}\")\n\n# Unit vector\nunitV1 = UnitVector(v1)\nprint(f\"Unit Vector of v1:\\n{unitV1}\")\n```\n\n### Utilities\n\n```python\nfrom MatrixAppend import MatrixAppend\nfrom Transpose import Transpose\nfrom Matrix import Matrix, FloatMatrix\n\n# Create two matrices\na = Matrix(2, 3, min_=1, max_=5)\nb = Matrix(2, 2, min_=1, max_=5)\n\nprint(f\"Matrix A:\\n{a}\")\n\nprint(f\"Matrix B:\\n{b}\")\n\n# Append matrices horizontally\nc = MatrixAppend(a, b, horizontalStack=True)\nprint(f\"A appended with B horizontally:\\n{c}\")\n\n# Append matrices vertically\nd = MatrixAppend(a, b, horizontalStack=False)\nprint(f\"A appended with B vertically:\\n{d}\")\n\n# Transpose a matrix\ntransposedA = Transpose(a)\nprint(f\"Transposed A:\\n{transposedA}\")\n```\n\n## Testing Framework\n\nThe `Main.py` script includes a suite of tests that validate the correctness of each matrix and vector operation. It performs both deterministic and randomized testing to ensure robustness. The tests compare the custom implementations with established packages like NumPy to ensure accuracy.\n\n### Running Tests\n\nTo execute all tests, simply run the `Main.py` script:\n\n```bash\npython Main.py\n```\n\nThis will sequentially run all the defined tests, providing progress feedback through progress bars and detailed output in case of failures.\n\n### Test Descriptions\n\n- **TestMatrix**: Validates matrix creation and basic properties.\n- **TestVectorDot**: Ensures correct computation of vector dot products.\n- **TestMultiply**: Tests matrix multiplication for correctness.\n- **TestMatrixAdd** and **TestMatrixSubtract**: Verify addition and subtraction operations.\n- **TestVectorLength**: Checks the calculation of vector norms.\n- **TestTranspose**: Validates matrix transposition.\n- **TestUnitVector**: Ensures correct normalization of vectors.\n- **TestScalarMultiply**: Tests scalar multiplication accuracy.\n- **TestRREF** and **TestBase2RREF**: Validate the computation of Reduced Row Echelon Forms.\n- **TestBasis**: Ensures the correctness of basis computation.\n- **TestQRDecomposition**: Validates QR Decomposition against NumPy's implementation.\n- **TestGramSchmidt**: Ensures the Gram-Schmidt process produces orthonormal bases.\n- **TestDeterminant**: Verifies determinant calculations against NumPy.\n- **TestInverse**: Tests matrix inversion against NumPy's results.\n- **TestMatrixWithSymbols**: Ensures operations work with symbolic matrices.\n\n### Randomized Testing\n\nEach core test has a corresponding `RandomTest*` function that performs randomized testing across a range of input sizes and values. This approach helps in uncovering edge cases and ensuring the library's robustness.\n\n### Performance Measurement\n\nThe `CalculateTimeComplexity` utility measures the execution time of functions across different input sizes and plots the results. This is useful for understanding the scalability and efficiency of the implemented algorithms.\n\n**Example Usage:**\n\n```python\nfrom Main import CalculateTimeComplexity, RandomTestMultiply\n\n# Measure time complexity of Matrix Multiply\nCalculateTimeComplexity(\n    func=RandomTestMultiply,\n    minSize=-100,\n    maxSize=100,\n    maxVal=100,\n    verbose=True\n)\n```\n\nThis will generate a plot named `RandomTestMultiplyComplexity.png` showcasing how the execution time scales with input size.\n\n## Performance Analysis\n\nThe library includes utility functions to analyze the time complexity of its operations. The `CalculateTimeComplexity` function measures the execution time of a given function over varying input sizes and generates a plot to visualize performance trends.\n\n### Example Usage\n\n```python\nfrom Main import CalculateTimeComplexity, RandomTestMultiply\n\n# Measure time complexity of Matrix Multiply\nCalculateTimeComplexity(\n    func=RandomTestMultiply,\n    minSize=-100,\n    maxSize=100,\n    maxVal=100,\n    verbose=True\n)\n```\n\nThis will generate a plot named `RandomTestMultiplyComplexity.png` showcasing how the execution time scales with input size.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgruiz%2Flinalg-practice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkgruiz%2Flinalg-practice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkgruiz%2Flinalg-practice/lists"}