{"id":21036689,"url":"https://github.com/maksasj/matrix","last_synced_at":"2025-08-13T01:34:23.374Z","repository":{"id":111461803,"uuid":"498863902","full_name":"Maksasj/matrix","owner":"Maksasj","description":"Simple single-header matrix library written in C++, intended for simple projects, tests.","archived":false,"fork":false,"pushed_at":"2023-05-18T17:09:05.000Z","size":25,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T10:43:52.651Z","etag":null,"topics":["cpp","header-only","library","matrix-calculations","matrix-library"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Maksasj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-06-01T18:59:58.000Z","updated_at":"2023-09-06T19:25:17.000Z","dependencies_parsed_at":"2024-11-19T23:30:33.563Z","dependency_job_id":"81abec7f-09dc-4f15-895b-cd7d4b15a618","html_url":"https://github.com/Maksasj/matrix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maksasj%2Fmatrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maksasj%2Fmatrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maksasj%2Fmatrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maksasj%2Fmatrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Maksasj","download_url":"https://codeload.github.com/Maksasj/matrix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254358849,"owners_count":22057997,"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":["cpp","header-only","library","matrix-calculations","matrix-library"],"created_at":"2024-11-19T13:21:36.846Z","updated_at":"2025-05-15T14:31:58.481Z","avatar_url":"https://github.com/Maksasj.png","language":"C++","readme":"# Matrix\n\nSimple single-header [matrix](\u003chttps://en.wikipedia.org/wiki/Matrix_(mathematics)\u003e) library written in C++, intended for simple projects and tests.\n\n### Provides simple way to interact wiht:\n\n-   Matrix type\n-   Matrix algebra\n-   Simple way to save \u0026 load matrix from files.\n\n# Todo\n\n-   [ ] CPU Parallel mode, for some functions\n-   [ ] Fix all bugs (almost impossible, but still...)\n-   [ ] GPU matrix computation\n\n# Docs\n\n## Matix type\n\n```c++\ntemplate\u003cclass T\u003e struct matrix {\n      int column;\n      int row;\n      T** data;\n};\n```\n\nUsually matrix you will pass around using pointers, `matrix* mat`, also theres a shorter writing version `mat* mat1`.\n\nIf you want get access to the specific element you can do that like that `mat-\u003edata[x][y]`, but be carefully be cause _x_ and _y_ can't be more then column and row correspondently, or less then 0. Another way how to get access specific cell from matrix is using `getElement(mat, row, column)` , there mat is yours matrix, row and column is just regular ints like `x` and `y` as stated above.\n\n## CreateMatrix\n\n`matrix* createMatrix\u003cT\u003e(int row, int column)`\n\nReturns pointer to the created matrix, also can be written like this.\n\n`matrix* createMatrix\u003cT\u003e(int row, int column, float value)`\n\nThese both methods have save meaning, second will just fill matrix with default value. Regularly this value will be 0.\n\n```c++\nmatrix\u003cfloat\u003e* mat1 = createMatrix\u003cfloat\u003e(69, 420); //Will be initialized with 0\nmatrix\u003cint\u003e* mat2 = createMatrix\u003cint\u003e(69, 420, 228); //Will be initialized with 228\n```\n\n## fillMatrix\n\n`void fillMatrix(matrix *mat\u003cT\u003e, T value)`\n\nJust fills entire matrix with specific value\n\n```c++\nfillMatrix(mat, 69); // Will fill entire 'mat matrix' with 69\n```\n\n## scaleMatrix\n\n`void scaleMatrix(matrix *mat\u003cT\u003e, float value)`\n\nWill multiply each element of matrix by provided value.\n\n```c++\nscaleMatrix(mat, 69); // Will multiply each element of matrix 'mat' by specific value, in this case 69.\n```\n\n## addScalarMatrix\n\n`void addScalarMatrix(matrix\u003cT\u003e *mat, float value)`\n\nAdds provided value to the each element of the provided matrix\n\n```c++\nscaleMatrix(mat, 69); // In this case, will add 69 to the each element of the matrix 'mat'\n```\n\n## sumMatrix\n\n`matrix\u003cT\u003e* sumMatrix(matrix\u003cT\u003e *mat_a, matrix\u003cT\u003e *mat_b)`\n\nSimply will sum up each element of first matrix with same element from th second matrix. As a result will create a new matrix.\nBe very careful, different matrix dimensions can cause errors.\n\n```c++\nmatrix\u003cT\u003e* result = sumMatrix(mat1, mat2);\n/*\nWill sum up each element of matrix 'mat1' with same element from 'mat2'.\n*/\n```\n\n## substractMatrix\n\n`matrix\u003cT\u003e* substractMatrix(matrix\u003cT\u003e *mat_a, matrix\u003cT\u003e *mat_b)`\n\nSimply will substract each element of first matrix with same element from th second matrix. As a result will create a new matrix.\nBe very careful, different matrix dimensions can cause errors.\n\n```c++\nmatrix\u003cT\u003e* result = substractMatrix(mat1, mat2);\n/*\nWill subtract each element of matrix 'mat1' with same element from 'mat2'.\n*/\n```\n\n## multiplyMatrix\n\n`matrix\u003cT\u003e* multiplyMatrix(matrix\u003cT\u003e *mat_a, matrix\u003cT\u003e *mat_b)`\n\nSimply will multiply each element of first matrix with same element from th second matrix. As a result will create a new matrix.\nBe very careful, different matrix dimensions can cause errors.\n\n```c++\nmatrix\u003cT\u003e* result = multiplyMatrix(mat1, mat2);\n/*\nWill multiply each element of matrix 'mat1' with same element from 'mat2'.\n*/\n```\n\n## transposMatrix\n\n`matrix\u003cT\u003e* transposMatrix(matrix\u003cT\u003e *tmp_mat)`\n\nWill do matrix 'flip', it switches the row and column indices of the matrix A by producing another matrix.\n\n```c++\nmatrix\u003cT\u003e* result = transposMatrix(mat);\n/*\nFor example\ninput:\n2 3\n1 2 6\n9 8 1\n\nresult:\n3 2\n9 1\n8 2\n1 6\n\n*/\n```\n\n## dotProductMatrix\n\n`matrix\u003cT\u003e* dotProductMatrix(matrix\u003cT\u003e *mat_a, matrix\u003cT\u003e *mat_b)`\n\nReturns dot products between rows of first matrix and columns of the second matrix. More about _dot product_ you can read in this [article](https://en.wikipedia.org/wiki/Dot_product).\n\n```c++\nmatrix\u003cT\u003e* result = dotProductMatrix(mat1, mat2);\n```\n\n## loadFileMatrix\n\n`matrix* loadFileMatrix(std::string file_name)`\n\nReturns matrix stored in text file, be careful because there I using custom matrix format. To lear more check out test folder of the repository.\n\n```c++\nmatrix\u003cT\u003e* result = loadFileMatrix(\"matrix.txt\");\n\n/*\n\nExample(matrix.txt):\n3 3\n4 3 3\n1 2 9\n0 3 7\n\n*/\n```\n\n## saveFileMatrix\n\n`void saveFileMatrix(matrix\u003cT\u003e *mat, std::string file_name)`\n\nSame with loadFileMatrix but , this allows to save matrix in txt file.\n\n```c++\nsaveFileMatrix(mat,\"matrix.txt\");\n```\n\n## copyMatrix\n\n`matrix\u003cT\u003e* copyMatrix(matrix\u003cT\u003e *tmp_mat)`\n\nCopies provided matrix , and created new unique one, with unique pointer.\n\n```c++\nmatrix\u003cT\u003e* result = copyMatrix(mat);\n```\n\n## applyFunction\n\n`void applyFunction(matrix\u003cT\u003e *mat, T (*func)(T))`\n\nAllows to apply specific function for every element of provided matrix. Regularly provided matrix should accept single float variable as input, and return just 'T' type. But if you want to do somethink more, do that on your own risk :).\n\n```c++\nT func(T x) {\n      return x*69 - 0.420;\n}\n\napplyFunction(mat, \u0026func);\n\n/*\nFor example there, for each element of 'mat' matrix will be applied function 'func'\n*/\n```\n\n## deleteMatrix\n\n`void deleteMatrix(matrix\u003cT\u003e *mat)`\n\nDelets entire matrix, and free the memory.\n\n```c++\ndeleteMatrix(mat);\n```\n\n## printMatrix\n\n`void printMatrix(matrix\u003cT\u003e *mat)`\n\nJust prints entire matrix in terminal.\n\n```c++\nprintMatrix(mat);\n```\n\n## elementSum\n\n`float elementSum(matrix\u003cT\u003e *mat)`\n\nReturns sum of all elements of the provided matrix.\n\n```c++\nT sum = elementSum(mat);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksasj%2Fmatrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaksasj%2Fmatrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksasj%2Fmatrix/lists"}