{"id":18583328,"url":"https://github.com/alexpreynolds/rts","last_synced_at":"2025-05-16T05:08:23.046Z","repository":{"id":75267994,"uuid":"133562551","full_name":"alexpreynolds/rts","owner":"alexpreynolds","description":"Random triangular matrix sampler","archived":false,"fork":false,"pushed_at":"2018-05-17T10:16:36.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-17T16:39:44.988Z","etag":null,"topics":["cplusplus-14","matrix","matrix-calculations","matrix-sampling","sample","sampling"],"latest_commit_sha":null,"homepage":null,"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/alexpreynolds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2018-05-15T19:18:33.000Z","updated_at":"2018-05-17T10:16:37.000Z","dependencies_parsed_at":"2023-06-05T23:15:35.525Z","dependency_job_id":null,"html_url":"https://github.com/alexpreynolds/rts","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/alexpreynolds%2Frts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpreynolds%2Frts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpreynolds%2Frts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexpreynolds%2Frts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexpreynolds","download_url":"https://codeload.github.com/alexpreynolds/rts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471057,"owners_count":22076585,"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":["cplusplus-14","matrix","matrix-calculations","matrix-sampling","sample","sampling"],"created_at":"2024-11-07T00:21:55.683Z","updated_at":"2025-05-16T05:08:20.714Z","avatar_url":"https://github.com/alexpreynolds.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rts\nRandom triangular matrix sampler\n\nThis program samples an input matrix of binary values, building a square matrix from a random sample of row and column indices. \n\nThe resulting square matrix is tested to determine if it is an upper- or lower-triangular matrix. \n\nA square matrix is called lower-triangular if all the entries above the diagonal are zero, or called upper-triangular if all the entries below the diagonal are zero.\n\nIf it an upper- or lower-triangular matrix, it is printed to standard output. \n\nIf the `--preserve-metadata` option is used, the row and column names from the original input matrix are included in the output.\n\n## Example\n\nWe start with the following example matrix `test.mtx`:\n\n```\n$ less test.mtx\n        feature01       feature02       feature03       feature04       feature05       feature06       feature07       feature08       feature09       feature10       feature11\nelementA        1       0       0       1       1       1       0       0       0       0       0\nelementB        0       0       1       1       1       0       1       0       0       0       1\nelementC        0       0       1       1       0       0       1       0       1       1       1\nelementD        0       0       0       0       1       1       1       1       0       0       1\nelementE        1       0       1       1       0       0       1       1       0       0       0\nelementF        0       0       0       0       0       0       0       0       0       0       0\n```\n\nWe can sample this test matrix for any 3x3 lower-triangular matrices we can find within, from a random selection of rows and columns:\n\n```\n$ make clean \u0026\u0026 make \u0026\u0026 make test-lower\nrm -rf *~\nrm -rf rts\nrm -rf rts.o\nclang++ -g -Wall -Wextra -std=c++14 -D__STDC_CONSTANT_MACROS -D__STDINT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1 -O3 -c rts.cpp -o rts.o\nclang++ -g -Wall -Wextra -std=c++14 -D__STDC_CONSTANT_MACROS -D__STDINT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1 -O3 -I/usr/include rts.o -o rts\nset -e; \\\n        ROWS=$(wc -l ./test.mtx | awk '{print ($1-1)}'); \\\n        COLS=$(tail -1 ./test.mtx | awk '{print NF-1}'); \\\n        ./rts --rows ${ROWS} --cols ${COLS} --samples 20 --order 3 --rng-seed 123 --lower --preserve-metadata \u003c ./test.mtx\n        feature03       feature08       feature05\nelementC        1       0       0\nelementE        1       1       0\nelementD        0       1       1\n        feature02       feature07       feature05\nelementF        0       0       0\nelementE        0       1       0\nelementD        0       1       1\n        feature11       feature03       feature02\nelementA        0       0       0\nelementE        0       1       0\nelementC        1       1       0\n        feature06       feature01       feature02\nelementF        0       0       0\nelementE        0       1       0\nelementD        1       0       0\n        feature04       feature01       feature02\nelementD        0       0       0\nelementF        0       0       0\nelementA        1       1       0\n```\n\nLikewise, we can sample the input matrix for 4x4 upper-triangular matrices:\n\n```\n$ make clean \u0026\u0026 make \u0026\u0026 make test-upper\nrm -rf *~\nrm -rf rts\nrm -rf rts.o\nclang++ -g -Wall -Wextra -std=c++14 -D__STDC_CONSTANT_MACROS -D__STDINT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1 -O3 -c rts.cpp -o rts.o\nclang++ -g -Wall -Wextra -std=c++14 -D__STDC_CONSTANT_MACROS -D__STDINT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE=1 -O3 -I/usr/include rts.o -o rts\nset -e; \\\n        ROWS=$(wc -l ./test.mtx | awk '{print ($1-1)}'); \\\n        COLS=$(tail -1 ./test.mtx | awk '{print NF-1}'); \\\n        ./rts --rows ${ROWS} --cols ${COLS} --samples 50 --order 4 --rng-seed 123 --upper --preserve-metadata \u003c ./test.mtx\n        feature08       feature02       feature09       feature04\nelementF        0       0       0       0\nelementA        0       0       0       1\nelementC        0       0       1       1\nelementB        0       0       0       1\n        feature08       feature07       feature02       feature04\nelementD        1       1       0       0\nelementB        0       1       0       1\nelementF        0       0       0       0\nelementA        0       0       0       1\n```\n\n## Performance characteristics\n\n### Memory usage\n\nThe input matrix of binary values is read into a bit array in single-byte increments. Using a bit array reduces storage overhead considerably, which is an issue for very large input matrices. The memory usage of the bit array is `ceil((rows * cols)/8)` bytes.\n\n### Sampling\n\nDepending on the specified type of matrix we are interested in, we only search the upper or lower triangle for disqualifying bits. If one is found, we immediately drop the sample and try the next, instead of searching through the rest of the matrix. This reduces overall lookup time.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexpreynolds%2Frts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexpreynolds%2Frts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexpreynolds%2Frts/lists"}