{"id":15406000,"url":"https://github.com/meh/ela","last_synced_at":"2026-01-20T05:01:14.510Z","repository":{"id":66195663,"uuid":"112045718","full_name":"meh/ela","owner":"meh","description":"Embedded Linear Algebra","archived":false,"fork":false,"pushed_at":"2018-02-06T22:36:39.000Z","size":99,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-12T22:22:07.980Z","etag":null,"topics":["column-vector","cpp","cpp11","embedded","expression-template","linear-algebra","matrix","row-vector","vector"],"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/meh.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":"2017-11-26T00:57:05.000Z","updated_at":"2021-08-11T15:11:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"f1b86d0a-bb9e-4ec4-a4db-56a277957a28","html_url":"https://github.com/meh/ela","commit_stats":{"total_commits":82,"total_committers":2,"mean_commits":41.0,"dds":"0.41463414634146345","last_synced_commit":"8140ca7f189e55a80a398df69ee4836c87da2bc6"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meh%2Fela","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meh%2Fela/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meh%2Fela/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meh%2Fela/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meh","download_url":"https://codeload.github.com/meh/ela/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247510975,"owners_count":20950580,"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":["column-vector","cpp","cpp11","embedded","expression-template","linear-algebra","matrix","row-vector","vector"],"created_at":"2024-10-01T16:19:13.369Z","updated_at":"2026-01-20T05:01:14.439Z","avatar_url":"https://github.com/meh.png","language":"C++","readme":"Embedded Linear Algebra [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Build Status](https://travis-ci.org/1aim/ela.svg?branch=master)](https://travis-ci.org/1aim/ela)\n=======================\nMinimal header only linear algebra library with expression templates and low\nfootprint designed to run on embedded devices.\n\nMatrix\n======\nA `matrix` is generic over the scalar type, the number of rows and the number\nof columns, dynamically sized matrices are not supported.\n\nThe internal buffer is always allocated on the stack as a contiguous\nrow-major array and by default is set to `0`.\n\nVector\n======\nThere are three classes of vectors, two concrete and one as a view.\n\nColumn Vector\n-------------\nA `column_vector\u003cType, Size\u003e` is just a type alias for `matrix\u003cType, Size, 1\u003e`\nbut in addition to expression access it implements direct access through the\n`[]` operator.\n\nRow Vector\n----------\nA `row_vector\u003cType, Size\u003e` is just a type alias for `matrix\u003cType, 1, Size\u003e` but\nin addition to expression access it implements direct access through the `[]`\noperator.\n\nVector\n------\nA `vector` is a column or row vector view into an expression (or matrix if\nmutable access is required).\n\n### Example\n\n```cpp\nela::matrix\u003cfloat, 3, 3\u003e a{{1, 0, 3}, {4, 0, 6}, {7, 0, 9}};\n\n// Assign a column of a matrix.\na.column(1) = {2, 5, 8};\n\n// Scale a row of the matrix and save it as a column vector.\nela::column_vector\u003cfloat, 3\u003e b = ~(a.row(1) * 2);\n```\n\nBound checking\n--------------\nBound checks are used at any runtime indexing operation through a call to\n`ELA_ASSUME`.\n\nUnless `ELA_ASSUME` is defined before `ela/ela.hpp` is included its definition\nwill become an `assert` call when `NDEBUG` is not defined and a compiler\nunreachable hint when `NDEBUG` is defined.\n\nIn your custom expression implementations you're advised to call `ELA_ASSUME`\nyourself to make sure the compiler knows what's going on.\n\nExpression\n==========\nAll matrix operations are implemented as expression templates so no\nintermediary objects are created unless explictly assigned to a `matrix`.\n\nIf all your matrix values are known at compile time compilers are able to\ncompletely constant unfold the results most of the time.\n\nWhat is an `expression`?\n------------------------\nAn `expression` is any type that implements the `ela::expression::traits` and\nprovides the appropriate indexing operator.\n\n### Example\n\nWe'll implement a generic RGB type as if it were a column vector.\n\n```cpp\n/* Inheriting from `ela::expression::base` is not required but it automatically\n * implements all generic expression operators for free, it doesn't add any\n * data.\n */\ntemplate \u003ctypename Type\u003e\nstruct RGB: public ela::expression::base\u003cRGB\u003cType\u003e\u003e\n{\npublic:\n\tusing ela::expression::base\u003cRGB\u003cType\u003e\u003e::operator =;\n\npublic:\n\tType r = 0;\n\tType g = 0;\n\tType b = 0;\n\n\t/* Create an empty color.\n\t */\n\tRGB () noexcept\n\t{ }\n\n\tRGB (Type r, Type g, Type b) noexcept\n\t\t: r(r), g(g), b(b)\n\t{ }\n\n\ttemplate \u003ctypename Input, typename T = Type\u003e\n\tRGB (Input const\u0026 expr, typename std::enable_if\u003c\n\t\t3 == ela::expression::traits\u003cInput\u003e::rows \u0026\u0026\n\t\t1 == ela::expression::traits\u003cInput\u003e::columns \u0026\u0026\n\t\tstd::is_same\u003cT, typename ela::expression::traits\u003cInput\u003e::type\u003e::value\u003e::type* = 0) noexcept\n\t{\n\t\tela::expression::base\u003cRGB\u003cType\u003e\u003e::operator=(expr);\n\t}\n\n\tRGB (std::initializer_list\u003cstd::initializer_list\u003cType\u003e\u003e elements) noexcept\n\t{\n\t\tela::expression::base\u003cRGB\u003cType\u003e\u003e::operator=(elements);\n\t}\n\n\tRGB (std::initializer_list\u003cType\u003e elements) noexcept\n\t{\n\t\tela::expression::base\u003cRGB\u003cType\u003e\u003e::operator=(elements);\n\t}\n\n\t/* This is the expression access operator.\n\t */\n\tinline\n\tType const\u0026\n\toperator () (size_t row, size_t column) const noexcept\n\t{\n\t\tELA_ASSUME(row \u003c 3 \u0026\u0026 column == 0);\n\n\t\tif (row == 0) {\n\t\t\treturn r;\n\t\t}\n\t\telse if (row == 1) {\n\t\t\treturn g;\n\t\t}\n\t\telse {\n\t\t\treturn b;\n\t\t}\n\t}\n\n\t/* This is the expression access operator.\n\t */\n\tinline\n\tType\u0026\n\toperator () (size_t row, size_t column) noexcept\n\t{\n\t\tELA_ASSUME(row \u003c 3 \u0026\u0026 column == 0);\n\n\t\tif (row == 0) {\n\t\t\treturn r;\n\t\t}\n\t\telse if (row == 1) {\n\t\t\treturn g;\n\t\t}\n\t\telse {\n\t\t\treturn b;\n\t\t}\n\t}\n};\n\nnamespace ela { namespace expression {\n\t/* This defines the experssion traits for `RGB\u003cT\u003e`.\n\t */\n\ttemplate \u003ctypename Type\u003e\n\tstruct traits\u003cRGB\u003cType\u003e\u003e\n\t{\n\t\t/* This is always the scalar type.\n\t\t */\n\t\ttypedef Type type;\n\n\t\t/* This is the number of rows the expression will produce.\n\t\t */\n\t\tstatic constexpr size_t rows = 3;\n\n\t\t/* This is the number of columns the expression will produce.\n\t\t */\n\t\tstatic constexpr size_t columns = 1;\n\n\t\t/* This says the expression can return references.\n\t\t */\n\t\tstatic constexpr bool concrete = true;\n\t};\n} }\n\n```\n\nThis code will make `RGB` behave as an expression, you can look into `tests/`\nfor more examples of expressions and other stuff.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeh%2Fela","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeh%2Fela","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeh%2Fela/lists"}