{"id":18773144,"url":"https://github.com/raideno/matrix","last_synced_at":"2026-04-26T22:31:11.194Z","repository":{"id":64611754,"uuid":"571710619","full_name":"raideno/Matrix","owner":"raideno","description":"C / Cpp program to make it easier to work with matrices and do operations on matrices","archived":false,"fork":false,"pushed_at":"2023-12-27T18:01:46.000Z","size":748,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-21T02:09:35.875Z","etag":null,"topics":["c","cpp","math","mathematics","matrix"],"latest_commit_sha":null,"homepage":"","language":"C++","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/raideno.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":"2022-11-28T18:13:20.000Z","updated_at":"2023-12-21T21:14:51.000Z","dependencies_parsed_at":"2023-12-27T21:00:17.348Z","dependency_job_id":"e9e2e005-bded-4676-a9ff-12e460409d3f","html_url":"https://github.com/raideno/Matrix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/raideno/Matrix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raideno%2FMatrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raideno%2FMatrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raideno%2FMatrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raideno%2FMatrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raideno","download_url":"https://codeload.github.com/raideno/Matrix/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raideno%2FMatrix/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32315711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T21:09:39.134Z","status":"ssl_error","status_checked_at":"2026-04-26T21:09:21.240Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["c","cpp","math","mathematics","matrix"],"created_at":"2024-11-07T19:33:03.859Z","updated_at":"2026-04-26T22:31:11.186Z","avatar_url":"https://github.com/raideno.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Matrix functions for C++\r\n\r\n## Build and run\r\n\r\n```sh\r\nmake\r\n./program\r\n```\r\n\r\n## Quick start\r\n\r\n```cpp\r\n#include \"lib/matrix/matrix.hpp\"\r\n#include \"lib/matrix/matrix-double-value.hpp\"\r\n\r\nint main() {\r\n\tMatrixClass\u003cMatrixDoubleValue\u003e::srand(1234);\r\n\r\n\tauto *A = MatrixClass\u003cMatrixDoubleValue\u003e::create_matrix(MatrixType::NORMAL, 2, 2);\r\n\tA-\u003eset(0, 0, MatrixDoubleValue(1.0));\r\n\tA-\u003eset(0, 1, MatrixDoubleValue(2.0));\r\n\tA-\u003eset(1, 0, MatrixDoubleValue(3.0));\r\n\tA-\u003eset(1, 1, MatrixDoubleValue(4.0));\r\n\r\n\tA-\u003eprint();\r\n\r\n\tauto det = A-\u003edeterminent();\r\n\tdet.print();\r\n\tprintf(\"\\n\");\r\n\r\n\tA-\u003einverse()-\u003eprint()-\u003edestroy();\r\n\tA-\u003edestroy();\r\n}\r\n```\r\n\r\n## Create and fill\r\n\r\n```cpp\r\n#include \"lib/matrix/matrix.hpp\"\r\n#include \"lib/matrix/matrix-int-value.hpp\"\r\n\r\n// Empty matrix then set values\r\nauto *M = MatrixClass\u003cMatrixIntValue\u003e::create_matrix(MatrixType::NORMAL, 3, 3);\r\nfor (size_t i = 0; i \u003c 3; ++i)\r\n  for (size_t j = 0; j \u003c 3; ++j)\r\n\tM-\u003eset(i, j, MatrixIntValue((int)(i*3 + j)));\r\n\r\n// Matrix filled with a constant\r\nauto *K = MatrixClass\u003cMatrixIntValue\u003e::create_matrix_with(MatrixType::NORMAL, 3, 3, MatrixIntValue(7));\r\n\r\n// Random matrix\r\nMatrixClass\u003cMatrixIntValue\u003e::srand(42);\r\nauto *R = MatrixClass\u003cMatrixIntValue\u003e::create_matrix_random(MatrixType::NORMAL, 3, 3);\r\n\r\nM-\u003eprint();\r\nK-\u003eprint();\r\nR-\u003eprint();\r\n\r\nM-\u003edestroy();\r\nK-\u003edestroy();\r\nR-\u003edestroy();\r\n```\r\n\r\n## Basic operations\r\n\r\n```cpp\r\n#include \"lib/matrix/matrix.hpp\"\r\n#include \"lib/matrix/matrix-double-value.hpp\"\r\n\r\nauto *A = MatrixClass\u003cMatrixDoubleValue\u003e::create_matrix_with(MatrixType::NORMAL, 2, 2, MatrixDoubleValue(2.0));\r\nauto *B = MatrixClass\u003cMatrixDoubleValue\u003e::create_matrix_with(MatrixType::NORMAL, 2, 2, MatrixDoubleValue(3.0));\r\n\r\n// Element-wise operations\r\nA-\u003eoperator+(B)-\u003eprint()-\u003edestroy();\r\nA-\u003eoperator-(B)-\u003eprint()-\u003edestroy();\r\nA-\u003eoperator*(B)-\u003eprint()-\u003edestroy();\r\nA-\u003eoperator/(B)-\u003eprint()-\u003edestroy();\r\n\r\n// With a scalar value (use the value type)\r\nA-\u003eoperator+(MatrixDoubleValue(1.5))-\u003eprint()-\u003edestroy();\r\nA-\u003eoperator*(MatrixDoubleValue(10.0))-\u003eprint()-\u003edestroy();\r\n\r\n// Transpose and inverse\r\nA-\u003etranspose()-\u003eprint()-\u003edestroy();\r\nA-\u003einverse()-\u003eprint()-\u003edestroy();\r\n\r\n// Determinant and trace\r\nauto det = A-\u003edeterminent();\r\ndet.print();\r\nprintf(\"\\n\");\r\n\r\nauto tr = A-\u003etrace();\r\ntr.print();\r\nprintf(\"\\n\");\r\n\r\n// Matrix multiplication (dot)\r\nauto *C = MatrixClass\u003cMatrixDoubleValue\u003e::matrix_multiplication(A, B);\r\nC-\u003eprint();\r\n\r\nA-\u003edestroy();\r\nB-\u003edestroy();\r\nC-\u003edestroy();\r\n```\r\n\r\n## Map and reduce\r\n\r\n```cpp\r\n#include \"lib/matrix/matrix.hpp\"\r\n#include \"lib/matrix/matrix-double-value.hpp\"\r\n\r\nauto *M = MatrixClass\u003cMatrixDoubleValue\u003e::create_matrix_random(MatrixType::NORMAL, 2, 3);\r\n\r\n// Map: add 1.0 to every element\r\nM-\u003emap(MatrixType::NORMAL, [](size_t i, size_t j, MatrixDoubleValue v) {\r\n\treturn MatrixDoubleValue(v.data + 1.0);\r\n}, true /* inplace */)-\u003eprint();\r\n\r\n// Reduce: sum of all elements (Reducer returns float)\r\nfloat sum = M-\u003ereduce(MatrixType::NORMAL, [](float acc, size_t i, size_t j, MatrixDoubleValue v) {\r\n\treturn acc + (float)v.data;\r\n}, 0.0f);\r\nprintf(\"sum=%f\\n\", sum);\r\n\r\nM-\u003edestroy();\r\n```\r\n\r\n## Convolution (1D/2D)\r\n\r\n```cpp\r\n#include \"lib/matrix/matrix.hpp\"\r\n#include \"lib/math/math.hpp\"\r\n#include \"lib/matrix/matrix-double-value.hpp\"\r\n\r\n// 2D convolution example\r\nauto *img = MatrixClass\u003cMatrixDoubleValue\u003e::create_matrix(MatrixType::NORMAL, 3, 3);\r\nimg-\u003eset(0,0, {1}); img-\u003eset(0,1, {2}); img-\u003eset(0,2, {3});\r\nimg-\u003eset(1,0, {4}); img-\u003eset(1,1, {5}); img-\u003eset(1,2, {6});\r\nimg-\u003eset(2,0, {7}); img-\u003eset(2,1, {8}); img-\u003eset(2,2, {9});\r\n\r\nauto *kernel = MatrixClass\u003cMatrixDoubleValue\u003e::create_matrix(MatrixType::NORMAL, 3, 3);\r\nkernel-\u003eset(0,0, {0}); kernel-\u003eset(0,1, {-1}); kernel-\u003eset(0,2, {0});\r\nkernel-\u003eset(1,0, {-1}); kernel-\u003eset(1,1, {5}); kernel-\u003eset(1,2, {-1});\r\nkernel-\u003eset(2,0, {0}); kernel-\u003eset(2,1, {-1}); kernel-\u003eset(2,2, {0});\r\n\r\nauto *out = matrix_convolution\u003cMatrixDoubleValue\u003e(img, kernel);\r\nout-\u003eprint();\r\n\r\nimg-\u003edestroy();\r\nkernel-\u003edestroy();\r\nout-\u003edestroy();\r\n```\r\n\r\n## Memory management\r\n\r\n```cpp\r\nauto *M = MatrixClass\u003cMatrixDoubleValue\u003e::create_matrix_random(MatrixType::NORMAL, 2, 2);\r\n// ... use M ...\r\nM-\u003edestroy();\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraideno%2Fmatrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraideno%2Fmatrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraideno%2Fmatrix/lists"}