{"id":20294126,"url":"https://github.com/sumukus/sparse-matrix-addition","last_synced_at":"2025-03-04T05:25:25.298Z","repository":{"id":118771273,"uuid":"403385497","full_name":"sumukus/sparse-matrix-addition","owner":"sumukus","description":"Sparse Matrix Addition in C++","archived":false,"fork":false,"pushed_at":"2021-09-05T19:11:02.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-14T09:35:35.077Z","etag":null,"topics":["matrix-addition","sparse-matrix-addition"],"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/sumukus.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":"2021-09-05T18:35:56.000Z","updated_at":"2021-09-05T19:11:04.000Z","dependencies_parsed_at":"2023-07-22T21:02:22.095Z","dependency_job_id":null,"html_url":"https://github.com/sumukus/sparse-matrix-addition","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/sumukus%2Fsparse-matrix-addition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumukus%2Fsparse-matrix-addition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumukus%2Fsparse-matrix-addition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumukus%2Fsparse-matrix-addition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sumukus","download_url":"https://codeload.github.com/sumukus/sparse-matrix-addition/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241789285,"owners_count":20020441,"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":["matrix-addition","sparse-matrix-addition"],"created_at":"2024-11-14T15:27:47.822Z","updated_at":"2025-03-04T05:25:25.278Z","avatar_url":"https://github.com/sumukus.png","language":"C++","readme":"# Spares Matrix Addition\n\nI have used the triplet representation for sparse matrix. It will have row, col and value.\nIn our code the sparsity value represents the total number of non zero elements.\nIf sparsity value is 0.1 and total matrix size is 10, then 0.1 *10 = 1. There will be 1 non zero elements present in the matrix.\n\nI have used struct type to represent a matrix value. Then I have uesed vector of type struct to store all the matrix elements.\n\u003cpre\u003e\ntype struct{\n  int row;\n  int col;\n  int value;\n};\n\nvector \u003c struct \u003e matrix;\n\u003c/pre\u003e\n\n## Sparse Matrix Addition Result\nThe table given below shows the run time required to add two matrix of dimension 200*200 with different sparsity value. The same data will be stored in **runtime.txt** file when you execute the sparseMatrixAddition.cpp code file.\n\n| Sparsity Value(sp)|Runtime(seconds)|\n------------------------|-----------------| \n0.1 | 0.00047 |  \n0.2 | 0.00095 |  \n0.3 | 0.001555 |  \n0.4 | 0.002 |  \n0.5 | 0.002589 |  \n0.6 | 0.002999 |  \n0.7 | 0.003481 |  \n0.8 | 0.003996 |  \n0.9 | 0.004717 |   \n\nThe normal matrix addition of same dimension(200*200) took  **0.001687 seconds** to complete its execution.\n\n## Conclusions\nwe can see that the matrix with less number of sparsity value takes less amount of time to complete its execution. As the sparsity increases the execution time also increases. So it is good to use the triplet representation of matrix to do the addition when the sparsity value is less and matrix size is big. As it takes less amount of time to complete its execution.\n\nIt is not a good idea to use the triplet representation of martix to do addition when the sparsity value is high or matrix size is less. As it might take more time to complete its execution as compared to normal/usual way of martix addition.\n\n## Drawbacks of the Above Code\n* When we use builtin rand() functions, there are chances to overlap the rows and columns values. So I have use custom method to check. It makes the code slow to generate the random matrix.\n* Improvements can be done on the logic/algorithm.\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumukus%2Fsparse-matrix-addition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsumukus%2Fsparse-matrix-addition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumukus%2Fsparse-matrix-addition/lists"}