Matrix is a Swift package that provides a flexible and efficient way to work with matrices. It offers a range of matrix operations, including creation, manipulation, and arithmetic operations.
- Matrix Creation: Easily create matrices of various dimensions and data types.
- Matrix Arithmetic: Perform matrix arithmetic operations, including addition, subtraction, multiplication, and more.
- Matrix Transposition: Transpose matrices to switch rows and columns.
- Element Access: Access individual elements, rows, and columns of a matrix.
- Error Handling: Handle matrix-related errors gracefully with custom error types.
To use Matrix in your Swift project, add it as a dependency in your Package.swift
file:
dependencies: [
.package(url: "https://github.com/tplaymeow/swift-matrix.git", branch: "main")
]
Then, import the library wherever you use it in your Swift code:
import Matrix
Here are some common use cases for working with matrices using Matrix:
let matrix = Matrix<Double>(rows: 3, columns: 3, repeating: 0.0)
let matrixA = Matrix(rows: 2, columns: 2, data: [1, 2, 3, 4])
let matrixB = Matrix(rows: 2, columns: 2, data: [5, 6, 7, 8])
let result = try? matrixA + matrixB
let matrix = Matrix(rows: 3, columns: 2, data: [1, 2, 3, 4, 5, 6])
let transposedMatrix = matrix.transposed()
let matrix = Matrix(rows: 3, columns: 3, data: [1, 2, 3, 4, 5, 6, 7, 8, 9])
let element = matrix[1, 2] // Access element at row 1, column 2
let row = matrix[row: 1] // Access the second row
let column = matrix[column: 2] // Access the third column
For detailed documentation, please refer to the documentation.
Contributions are welcome! If you find a bug or have an enhancement in mind, please open an issue or submit a pull request on the GitHub repository.
MatrixSwift is released under the MIT License.