{"id":37081528,"url":"https://github.com/nishbo/timed_sparse_matrix","last_synced_at":"2026-01-14T09:54:11.415Z","repository":{"id":163795509,"uuid":"547449714","full_name":"nishbo/timed_sparse_matrix","owner":"nishbo","description":"Save timed sparse matrices and tensors to readable files from Python, MATLAB, and C++.","archived":false,"fork":false,"pushed_at":"2024-09-10T20:56:21.000Z","size":398,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-10T23:17:51.458Z","etag":null,"topics":["cpp","matlab","multi-language","python","sparse-matrix"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nishbo.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-10-07T17:51:41.000Z","updated_at":"2024-09-10T20:56:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"c624b7f1-ad5e-41f8-a662-2ceccd529369","html_url":"https://github.com/nishbo/timed_sparse_matrix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nishbo/timed_sparse_matrix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nishbo%2Ftimed_sparse_matrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nishbo%2Ftimed_sparse_matrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nishbo%2Ftimed_sparse_matrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nishbo%2Ftimed_sparse_matrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nishbo","download_url":"https://codeload.github.com/nishbo/timed_sparse_matrix/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nishbo%2Ftimed_sparse_matrix/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28416127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:38:59.149Z","status":"ssl_error","status_checked_at":"2026-01-14T08:38:43.588Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["cpp","matlab","multi-language","python","sparse-matrix"],"created_at":"2026-01-14T09:54:10.902Z","updated_at":"2026-01-14T09:54:11.406Z","avatar_url":"https://github.com/nishbo.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Timed Sparse Matrices\n\nSave timed sparse matrices and tensors to readable files from Python, MATLAB, and C++.\n\n\n## File Format\n\nThe file starts with meta information, which describes the format of the data.\n\n\n### Meta-information fields\n\n* `dims` -- dimensionality (shape) of matrices. E.g., `dims=5` means that the data are vectors of five elements; `dims=3,4` -- 3 by 4 matrices; `dims=3,4,5` -- tensors of 3x4x5 shape, and so on. The loaded data is then of format [time index][first data axis index][second data axis index], etc. For more detail, see specific language implementation descriptions.\n\n* `default_value` -- the default value used for all omitted elements, e.g., `default_value=0` or `default_value=NaN`.\n\n* `time` -- how time point of each matrix is calculated.\n\n    - `stamps` means that each line starts with a value for time. If there is a time point with all values equal to `default_values`, then the line is empty after the time stamp. [Example](./example_stamps_file.tsm).\n\n    - `period` means that the data was sampled regularly from a specific time with a specified period. Needs two additional definitions: `time_start` and `time_period`. The first column is then an index of the timestamp, and time is reconstructed from those definitions. Indexing start at 0, and if an index is omitted, that matrix is filled with `default_value`. [Example](./example_period_file.tsm).\n\n* `N` is an optional parameter to define the maximum number of time points expected. For example, if in `time=period` the last time-index is 7, but `N=10`, the functions will return 2 additional timepoints filled with default_value.\n\n### Data\n\nEverything below the 4 dashes (`----`) is stored data. On each line, after the time-index, the data points are separated with semicolons (e.g., `0.4;0,2,3.5;2,3,2.2`, where `0.4` is the time stamp, `0,2,3.5` and `2,3,2.2` are the two non-zero elements). First values separated by commas describe the index of the element, and the last one -- its value (from previous example, matrix at that time point will have 3.5 in the element with index [0][2] and 2.2 in element [2][3]).\n\n### Example files\n\n#### [Stamps](./example_stamps_file.tsm)\n\n```\ndims=3,4\ndefault_value=0\ntime=stamps\n----\n0\n0.1\n0.2;1,1,1\n0.4;0,2,3.5;2,3,2.2\n0.5\n0.75;2,3,4.5\n```\n\nThis file describes explicitly timestamped matrices. The time vector will be [0, 0.1, 0.2, 0.4, 0.5, 0.75]. The values of the matrices will be 0, except for: matrix corresponding to the third timestamp (0.2), where the element in the second row second column will be 1, etc.\n\n#### [Period](./example_period_file.tsm)\n\n```\ndims=3,4\ndefault_value=0\ntime=period\ntime_start=0\ntime_period=0.1\nN=10\n----\n0;0,1,12\n2;1,1,1\n4;0,2,3.5;2,3,2.2\n7;2,3,4.5\n```\n\nThis file describes ten 3x4 matrices timestamped periodically from 0. Time vector will be [0, 0.1, 0.2, ..., 0.9]. The values of the matrices will be 0, except for the: matrix corresponding to the first time point will have 12 in the first row second column, third time point -- 1 in the second row second column, etc.\n\n\n## Functions\n\nLoad functions usually accept a filename, and returns 2 arrays: one array with timepoints, and one array with matrices created according to the description in the file.\n\nSave function accepts a filename, keyword for `time`, data matrices, array with timepoints, and default value. NaN and Inf currently are not supported.\n\n### C++\n\nThe [header file](./src/tsm.h) defines `Tsm` class, an instance of which can be created from data or from a filename:\n\n```\nTsm::Tsm(const std::string filename);\nTsm::Tsm(const std::vector\u003cdouble\u003e time, const std::vector\u003cdouble\u003e data, const std::vector\u003csize_t\u003e dims);\n```\n\nThere are two additional convenience functions that accept vectors of vectors and vectors of matrices:\n\n```\nTsm::Tsm(const std::vector\u003cdouble\u003e time, const std::vector\u003cstd::vector\u003cdouble\u003e\u003e vecs);\nTsm::Tsm(const std::vector\u003cdouble\u003e time, const std::vector\u003cstd::vector\u003cstd::vector\u003cdouble\u003e\u003e\u003e matrices);\n```\n\nThe matrices within the object can be exported to a file using functions:\n\n```\nint Tsm::save_stamps(const std::string filename, const double default_value = 0.);\nint Tsm::save_period(const std::string filename, const double default_value = 0.);\nint Tsm::save(const std::string filename, const std::string type, const double default_value = 0.);\n```\n\nFor example of use, see [CPP Project](./CPP_Project/TSM_CPP_Windows.sln) and its [main file](./CPP_Project/TSM_CPP_Windows/TSM_CPP_Windows.cpp).\n\n### DLL\n\nAnother option is to use [DLL](./DLL/TSMDLL.dll). It's [header](./DLL/TSMDLL/TSMDLL/TsmLibrary.h) describes generic load and save functions. It has been compiled for Windows x64 use, but retargeting a solution should be trivial. It is also used to provide a Python interface.\n\n### Python\n\nPython works through a DLL and associated simplified API installed as a Python module. Examples of use are in the end of [timed_sparse_matrix.py](./Python/timed_sparse_matrix/timed_sparse_matrix.py):\n\n```\ntimes, formatted_tensor_data = load(os.path.join('..', 'example_period_file.tsm'))\nprint(times)\nprint(formatted_tensor_data)\nprint(formatted_tensor_data[0][0][1])\n\nsave(os.path.join('..', 'example_period_file_po.tsm'), 'period', times, formatted_tensor_data)\n\ntimes, formatted_tensor_data = load(os.path.join('..', 'example_stamps_file.tsm'))\nsave(os.path.join('..', 'example_stamps_file_po.tsm'), 'stamps', times, formatted_tensor_data)\n```\n\nTODO: a separate example of use.\n\n### MATLAB\n\nThe API provides a save and a load function:\n\n```\ntsm_save(filename, type, times, formatted_tensors, default_value)\n[times, formatted_tensors] = tsm_load(filename)\n```\n\n[Example](./MATLAB/Examples.m) of use.\n\n\n## Installation\n\n### C++\n\nIt is recommended to directly include [source code](./src) in your project. Another option is to link to [DLL](./DLL/TSMDLL.dll).\n\n### Python\n\nCan be installed from PyPi:\n\n```\npy -m pip install timed_sparse_matrix\n```\n\nReplace `python` with any python that you are going to use TSM with. Then you can `include timed_sparse_matrix as tsm` in your code. Alternatively, it can be installed from local source, see Python folder.\n\nBeware, we had experienced that sometimes the DLL is not updated after update to the source code, so it is recommended to uninstall the module and install it again when updating.\n\n### MATLAB\n\nOpen `MATLAB` folder of the project in your MATLAB and run `install.m`, which will include the `bin` folder in your MATLAB PATH.\n\n\n## Authors\n\n- [**Anton Sobinov**](https://github.com/nishbo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnishbo%2Ftimed_sparse_matrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnishbo%2Ftimed_sparse_matrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnishbo%2Ftimed_sparse_matrix/lists"}