{"id":20744869,"url":"https://github.com/calebzulawski/cotila","last_synced_at":"2025-04-24T05:47:59.243Z","repository":{"id":54156219,"uuid":"120155091","full_name":"calebzulawski/cotila","owner":"calebzulawski","description":"A compile-time linear algebra system for C++","archived":false,"fork":false,"pushed_at":"2021-10-11T14:10:56.000Z","size":2118,"stargazers_count":121,"open_issues_count":9,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-24T05:47:53.293Z","etag":null,"topics":["blas","compile-time","constexpr","linear-algebra"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/calebzulawski.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-04T04:38:15.000Z","updated_at":"2025-04-19T06:01:20.000Z","dependencies_parsed_at":"2022-08-13T07:50:37.585Z","dependency_job_id":null,"html_url":"https://github.com/calebzulawski/cotila","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebzulawski%2Fcotila","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebzulawski%2Fcotila/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebzulawski%2Fcotila/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebzulawski%2Fcotila/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/calebzulawski","download_url":"https://codeload.github.com/calebzulawski/cotila/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250573344,"owners_count":21452345,"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":["blas","compile-time","constexpr","linear-algebra"],"created_at":"2024-11-17T07:17:30.566Z","updated_at":"2025-04-24T05:47:59.206Z","avatar_url":"https://github.com/calebzulawski.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"logo.svg\" width=\"30%\" height=\"auto\"\u003e\n\n[![Build Status](https://github.com/calebzulawski/cotila/workflows/Test/badge.svg)](https://github.com/calebzulawski/cotila/actions)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![GitHub release](https://img.shields.io/github/release/calebzulawski/cotila.svg)](https://github.com/calebzulawski/cotila/releases)\n\n\u003c/div\u003e\n\n## Overview\n\nCotila (**co**mpile-**ti**me **l**inear **a**lgebra) is a header-only library that provides a set of linear algebra functions in C++ intended for use during compile time. \nAll functions available in Cotila are ***constexpr***, meaning they can be used at compile-time to generate constants and lookup tables in a type-safe, readable, and maintainable manner.\n\n## Installation\n\nCotila is a header-only library.  Simply point your compiler to include the `include/` directory.\n\nIf you are using CMake, you can also import the `cotila::cotila` library.\n\nCode must be compiled with at least C++17 support to use Cotila.\n\n## Documentation\n\nThe current documentaiton is [available online](https://calebzulawski.github.io/cotila/).\n\nThe documentation can also be built with CMake and Doxygen:\n```bash\ncmake -D BUILD_DOCS=ON -B build .\ncmake --build build --target doc\n```\n\n## Quickstart Guide\n\nTo use Cotila, all you need to do is `#include \u003ccotila/cotila.h\u003e`.  This header will include all of the headers provided by Cotila.\n\nThe Cotila interface is designed around operations commonly found in BLAS or MATLAB and should be simple and predictable.\n\n### Types\n\nCotila provides support for three types: **scalars**, **vectors**, and **matrices**.\n\n**Scalars** are represented by fundamental types, such as `float` or `double`, as well as `std::complex`.  Cotila provides a variety of operations that manipulate scalar types.  In some cases, such as square roots, a standard library implementation already exists but it is not `constexpr`.  A simple example below:\n\n```c++\nconstexpr double s = cotila::sqrt(4.);\nstatic_assert(s == 2.); // this evaluates and passes at compile time\n```\n\n**Vectors** are represented by the `cotila::vector` class.  The `vector` class is a container for scalar types.  Additionally, `vector` is an aggregate class containing a single array and is constructed via [aggregate initialization](http://en.cppreference.com/w/cpp/language/aggregate_initialization).  If you are confused, some notes on aggregate initialization can be found in the next section.  A simple vector example:\n```c++\nconstexpr cotila::vector\u003cdouble, 3\u003e v1 {{1., -2., 3.}}; // very explicit declaration\nconstexpr cotila::vector v2 {1., 2., 3.}; // deduces the type, omits the extra braces via uniform initialization\nstatic_assert(v2 == cotila::abs(v1));\n```\n\n**Matrices** are represented by the `cotila::matrix` class.  Like the `vector` class, `matrix` is an aggregate class containing a single 2-dimensional array.  A `matrix` is initialized like a normal 2-dimensional array in C++ (i.e. row-major order).  A simple matrix example:\n```c++\n/*  m1 contains:        m2 contains:\n *  1 2 3               1 4\n *  4 5 6               2 5\n *                      3 6\n */\nconstexpr cotila::matrix\u003cdouble, 2, 3\u003e m1 {{{1., 2., 3.}, {4., 5., 6.}}}; // very explicit declaration\nconstexpr cotila::matrix m2 {{{1., 4.}, {2., 5.}, {3., 6.}}}; // deduces the type, but the extra braces are required\nstatic_assert(m2 == cotila::transpose(m1));\n```\n\n**Complex values** are not handled any differently, other than initialization:\n```c++\n/*  m1 contains:        m2 contains:\n *  1 + 0i   2 + 1i     1 + 0i   3 + 1i\n *  3 - 1i   4 + 2i     2 - 1i   4 - 2i\n *\n */\nconstexpr cotila::matrix\u003cstd::complex\u003cdouble\u003e, 2, 2\u003e m1 {{{{1., 0.}, {2., 1.}}, {{3., -1.}, {4., 2.}}}};\nconstexpr cotila::matrix m2 {{{{1., 0.}, {3., 1.}}, {{2., -1.}, {4., -2.}}}}; // complex types can be deduced, too!\nstatic_assert(m2 = cotila::hermitian(m1));\n```\n\n### Aggregate Initialization\n\nAggregate objects can be initialized similarly to C structs by simply providing an initializer list with the values to initialize each member.  In C++, arrays can be initialized like so:\n```c++\ndouble arr[3] = {1., 2., 3.};\n```\nor\n```c++\ndouble arr[3] {1., 2., 3.};\n```\nThe `cotila::vector` class contains a single array:\n```c++\ntemplate\u003ctypename T, std::size_t N\u003e\nstruct vector {\n    T arr[N];\n};\n```\nTo initialize a `vector`, you must initialize the array member, which results in an extra set of braces:\n```c++\nvector\u003cdouble, 3\u003e v = {{1., 2., 3.}};\n```\nor\n```c++\nvector\u003cdouble, 3\u003e v {{1., 2., 3.}};\n```\n\n#### Uniform initialization\n\nAggregate objects with a single member can be initialized with uniform initialization, which allows you to omit the extra braces:\n```c++\nvector\u003cdouble, 3\u003e v {1., 2., 3.};\n```\n\nYou may omit the extra braces on `cotila::matrix`, however this can get confusing.\nYou may not use nested initializer lists for uniform initialization, so the elements must be listed in row-major order:\n```c++\nmatrix\u003cdouble, 2, 2\u003e m {1., 2., 3., 4.}; // first row contains [1, 2], second row contains [3, 4]\n```\n\n#### Class template argument deduction\n\nCotila's vectors and matrices support class template argument deduction.  This allows you to omit the template arguments entirely:\n```c++\nvector v1 {1., 2., 3.};   // uniform initialization\nvector v2 {{1., 2., 3.}}; // normal aggregate initialization\n```\n\nMatrices do not support template argument deduction for uniform initialization, since it is impossible to deduce the shape of the matrix.\nIn this case, an extra set of braces is always required:\n```c++\nmatrix m {{{1., 2.}, {3., 4.}}};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebzulawski%2Fcotila","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalebzulawski%2Fcotila","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebzulawski%2Fcotila/lists"}