{"id":20275491,"url":"https://github.com/novak-99/cpplex","last_synced_at":"2025-04-11T05:24:07.002Z","repository":{"id":251870799,"uuid":"835132661","full_name":"novak-99/cpplex","owner":"novak-99","description":"Cpplex: Complex analysis made SIMPLE!","archived":false,"fork":false,"pushed_at":"2024-08-06T06:51:47.000Z","size":129,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T03:27:32.014Z","etag":null,"topics":[],"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/novak-99.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":"2024-07-29T08:20:09.000Z","updated_at":"2025-03-17T23:29:27.000Z","dependencies_parsed_at":"2024-08-06T08:45:24.594Z","dependency_job_id":"116e3b5f-83dd-4edb-b198-c3f7a8b9e754","html_url":"https://github.com/novak-99/cpplex","commit_stats":null,"previous_names":["novak-99/cpplex"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novak-99%2Fcpplex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novak-99%2Fcpplex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novak-99%2Fcpplex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novak-99%2Fcpplex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/novak-99","download_url":"https://codeload.github.com/novak-99/cpplex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248346570,"owners_count":21088480,"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":[],"created_at":"2024-11-14T13:09:39.939Z","updated_at":"2025-04-11T05:24:06.982Z","avatar_url":"https://github.com/novak-99.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cpplex\n\n\u003cp align=\"center\"\u003e\n  \u003ckbd\u003e\u003cimg src=\"https://github.com/novak-99/cpplex/blob/main/logo.png?raw=true\"/\u003e\u003c/kbd\u003e\n\u003c/p\u003e\n\n![C++2b](https://img.shields.io/badge/C++-2023%20(2b)-blue.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Issues](https://img.shields.io/badge/issues-0%20open-red)](https://github.com/novak-99/cpplex/issues)\n[![Docs](https://img.shields.io/badge/docs-rtd-green)](https://cpplex.readthedocs.io/en/latest/)\n\nComplex analysis in C++ is slow and lacks a lot of features.\n\nCpplex makes operations with complex numbers a lot faster and adds much more functionality!\n\nWhether you need tools for scientific computing, signal processing, or numerical analysis, cpplex is the right library for you!\n\n## Usage  \n\n### The Cpplex Complex Datatype\n\nBegin by including the header files of the content you wish to use:\n\n```cpp\n#include \u003cComplex.hpp\u003e\n#include \u003cSpecial.hpp\u003e\n#include \u003ciostream\u003e\nint main() {\n\n  return 0;\n}\n```\n\nCpplex allows you to use standard C++ complex literals, as well as our own:\n\n```cpp\n#include \u003cComplex.hpp\u003e\n#include \u003cSpecial.hpp\u003e\n#include \u003ciostream\u003e\n\nusing namespace std::complex_literals; // for C++'s literals\n\nint main() {\n  Complex z = 5 + 5_j;\n  Complex w = 5 + 5i;\n\n  return 0;\n}\n```\n\nAnd you can call functions on the datatype by doing the following:\n\n```cpp\n#include \u003cComplex.hpp\u003e\n#include \u003cSpecial.hpp\u003e\n#include \u003ciostream\u003e\nint main() {\n  Complex z = 5 + 5_j;\n  Complex gammaZ = gamma(z);\n\n  return 0;\n}\n```\n\n### Functions in Cpplex\n\nVarious functions in cpplex, including the derivative, integral, and continuous entropy functions, require you to use functions of complex inputs. Here is how cpplex handles them.\n\nYou can either create complex functions by using lambdas or C++ functions:\n\n```cpp\n#include \u003cComplex.hpp\u003e\n#include \u003ciostream\u003e\n\nComplex f(Complex z) {\n    return z*z; \n}\n\nint main() {\n\n  auto g = [](Complex z) { return z*z };\n\n  return 0;\n}\n```\n\nThen you can call the relevant function by passing your complex function as a function pointer:\n\n```cpp\n#include \u003cComplex.hpp\u003e\n#include \u003cNumericalAnalysis.hpp\u003e\n#include \u003ciostream\u003e\n\nint main() {\n  Complex z = 1 + 1_j;\n  auto g = [](Complex z) { return z*z };\n  Complex dgdz = derivative(g, z); // Derivative of g evaluated at z.\n\n  return 0;\n}\n```\n\n### Complex Sequences in Cpplex\n\nOther functions, including discrete transforms and discrete entropy functions, will require complex sequences as input. \n\nComplex sequences are currently supported in cpplex by using the ```std::vector\u003cComplex\u003e``` datatype, but they will be later swapped out for a vectorized cpplex vector type. \n\nComplex sequences can be implemented in cpplex by writing the following code:\n\n```cpp\n#include \u003cComplex.hpp\u003e\n#include \u003cFFT.hpp\u003e\n#include \u003ciostream\u003e\n\nint main() {\n  std::vector\u003cComplex\u003e X = {1 + 1_j, 2, 3 + 5_j};\n  std::vector\u003cComplex\u003e Y = fft(X);\n\n  return 0;\n}\n```\n\n### Compiling Code\n\nCpplex is a header only library, meaning no source files or shared object files are required for compilation.\n\nTo compile code while using cpplex, remember to include the library's main directory and to compile with C++23:\n\n```g++ main.cpp -I cpplex -o main.o -std=c++2b```\n\n## Documentation\n\nTutorials for all cpplex modules and detailed documentation for every function are available on the Read the Docs page [here](https://cpplex.readthedocs.io/en/latest/).\n\n## Benchmarks\n\nCpplex is faster than the standard C++ complex library -- MUCH faster.\n\nFor our benchmarks, complex division and exponentiation are **9 times faster**, the complex square root is **10 times faster**, and inverse trig functions are up to **47 times faster**. The full list of benchmarks is available [here](https://cpplex.readthedocs.io/en/latest/Benchmarks/Complex.html).\n\nOne of the main reasons for this is that C++'s primitive multiplication and division operators use NaN checking. However, in most complex use cases this is unnecessary and makes programs much slower.\n\nFor example, consider the following standard C++ code and the cpplex equivalent for a large sum to approximate the Riemann zeta function at its first zero:\n```cpp\nvoid stdZetaSum(){\n    const int N = 1e+9;\n    std::complex\u003cdouble\u003e s = 0.5 + 14.1347251417346937904572519835625i;\n    std::complex\u003cdouble\u003e zetaTerm = std::complex\u003cdouble\u003e(1)/(std::complex\u003cdouble\u003e(1) - pow(2, std::complex\u003cdouble\u003e(1) - s));\n\n\n    std::complex\u003cdouble\u003e sum = 0; \n    for(int n = 1; n \u003c= N; n++){\n        std::complex\u003cdouble\u003e etaTerm = std::pow(-1, n-1) * 1 / (pow(n, s));\n\n        sum += etaTerm * zetaTerm;\n    }\n    std::cout \u003c\u003c sum \u003c\u003c \"\\n\";\n}\n\nvoid cpplexZetaSum(){\n    const int N = 1e+9;\n    Complex s = 0.5 + 14.1347251417346937904572519835625_j;\n    Complex zetaTerm = 1/(1 - pow(2, 1 - s));\n\n    Complex sum = 0; \n    for(int n = 1; n \u003c= N; n++){\n        Complex etaTerm = pow(-1, n-1) * 1 / (pow(n, s));\n\n        sum += etaTerm * zetaTerm;\n    }\n    std::cout \u003c\u003c sum \u003c\u003c \"\\n\";\n}\n```\nWhereas the former implementation takes an average of 46.788 seconds to run, the cpplex equivalent takes only **18.258 seconds**!\n\n## Future Plans \n\n### 1. Better approximations \n\nThe Lanczos approximation for the Gamma function and 15-point Gauss-Kronrod quadrature for integration are both good approximation methods, but they both could be better. I hope to swap these out in the future.\n\n### 2. Complex linear algebra module\n\nCurrently, cpplex uses the `std::vector\u003cComplex\u003e` type for vectors and does not currently support a complex matrix type. I plan to add an optimized n-d array type in the future.\n\n### 3. Bivariate distributions\n\nCpplex currently assumes independence for its complex distributions, which can be an erronous assumption. I plan to change the structure of distributions so that they can support correlation between the real and complex components, if it exists.\n\n## Acknowledgements\n\nWhile the various sources I used for each function can be found in the documentation, in this section, I would like to acknowledge both the [cppreference documentation page](https://en.cppreference.com/w/) and the [scipy documentation page](https://docs.scipy.org/doc/scipy/reference/index.html#scipy-api). Both of these pages helped me see which functions are typically implemented in complex/scientific computing libraries, sources on how to implement them, and naming conventions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovak-99%2Fcpplex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnovak-99%2Fcpplex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovak-99%2Fcpplex/lists"}