Skip to content
Projetos

Sobre

compilable markdown for linear algebra

Linguagens e ambientes de execução

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
0
em 7 dias
0
em 15 dias
0
em 1 mês
Coletando histórico

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

I❤️LA: Compilable Markdown for Math

I❤️LA is a compilable markdown for math. It can generate working code in your favorite language (C++, Python, MATLAB, more to come) and LaTeX from snippets like this:

∑_i a_i b_i
where
a ∈ ℝ^n
b ∈ ℝ^n

or this:

A_ij = { 1 if (i,j) ∈ E
         0 otherwise
where
A ∈ ℝ^(n × n)
E ∈ { ℤ × ℤ }
n ∈ ℤ

or this:

[ t^3 t^2 t 1 ] [ -1  3 -3  1
                   3 -6  3  0
                  -3  3  0  0
                   1  0  0  0 ] P
where
t ∈ ℝ
P ∈ ℝ^(4 × d)

In other words, I❤️LA is a linear algebra domain specific language (DSL) that targets other languages. Write once, use everywhere.

For more, see the wiki or the website. Join the Discord.

Running

The easiest way to run is in the web browser. You can use the hosted version (no installation needed) or cd docs and then python3 -m http.server.

The following instructions describe running the Python code directly.

To run the desktop GUI:

python3 -m iheartla

You can also run as a command-line compiler:

python3 -m iheartla --help

Installing

You can find releases on the GitHub release page. The following instructions are for running from source.

I❤️LA depends on Python 3.10 or later and several modules, listed in pyproject.toml. The grammar needs the third-party regex module, which import iheartla substitutes for re so that TatSu uses it. TatSu is pinned to 5.15.1, the version that generates I❤️LA's parsers (see "Changing the grammar").

uv

Install uv and run:

uv run python -m iheartla --help

## with the GUI
uv run --extra gui python -m iheartla

## For development, also install the test suite's dependencies
## (see "Running the tests" below for the C++ setup the tests need):
uv sync --extra test --extra viz

Pip

python3 -m venv .venv
# activate your virtual environment via something like: source .venv/bin/activate

pip3 install -e .
## or, with the GUI
pip3 install -e '.[gui]'

## For development, also install:
pip3 install -e '.[gui,viz,test]' pyinstaller

(2023-05-10: There is a known bug with Python >= 3.10 and wxPython 4.2.0's PDF viewer. It will be fixed in the next release of wxPython. For now, either run on Python 3.9, live without PDF rendering, compile top-of-tree wxPython yourself, or change / to // in wx/lib/pdfviewer/viewer.py:354 (so that self.Ypagepixels is an int). The relevant commit is here.)

If you are developing I❤️LA, the test suite needs a working C++ compiler and, optionally, the Graphviz graph visualization software (e.g., brew install graphviz).

Running the tests

The tests compile generated C++ with cppyy, against Eigen, autodiff and LBFGSpp, which test/fetch_deps.sh fetches into test/third_party/. On macOS, cppyy-cling's wheel looks for MacPorts' zstd; test/fix_cppyy_zstd.sh points it at Homebrew's (run it again after reinstalling cppyy):

brew install zstd
sh test/fetch_deps.sh
PYTHON=.venv/bin/python sh test/fix_cppyy_zstd.sh
. .venv/bin/activate && sh run_test.sh

Without MATLAB, the MATLAB checks can run in GNU Octave (brew install octave), through a stand-in for the MATLAB engine (test/octave_engine.py):

uv sync --extra test --extra octave
IHEARTLA_OCTAVE=1 sh run_test.sh

Set IHEARTLA_OCTAVE_VERBOSE=1 too to print how many MATLAB functions ran. A few checks fail in Octave only: integrals, optimization, and ragged arrays.

.github/workflows/test.yml does the same.

cppyy on macOS 26 and later. cppyy-cling 6.32.8 (the latest, from 2024) can't parse the C++ headers of the macOS 26 SDK and later. import cppyy then fails with errors such as use of undeclared identifier '__builtin_clzg' or '__GCC_DESTRUCTIVE_SIZE'. CI avoids this by running on macos-15. Locally, download the macOS 15 SDK (only its headers are used) and point SDKROOT at it with an absolute path. The joseluisq/macosx-sdks releases have it:

mkdir -p ~/SDKs && cd ~/SDKs
curl -LO https://github.com/joseluisq/macosx-sdks/releases/download/15.5/MacOSX15.5.sdk.tar.xz
shasum -a 256 MacOSX15.5.sdk.tar.xz   # c15cf0f3f17d714d1aa5a642da8e118db53d79429eb015771ba816aa7c6c1cbd
tar -xJf MacOSX15.5.sdk.tar.xz
export SDKROOT=~/SDKs/MacOSX15.5.sdk   # must be absolute; cling passes it to -isysroot
python -c "import cppyy; cppyy.cppdef('int f() { return 3; }'); print(cppyy.gbl.f())"   # 3

Set SDKROOT the same way before sh run_test.sh. The SDK installed with Xcode or the Command Line Tools stays the default for everything else.

The viz extra installs the graphviz Python package. When it is present, compiling renders a graph with Graphviz's dot, so either install Graphviz or leave out --extra viz (uv sync --extra test), or every test fails with ExecutableNotFound: failed to execute PosixPath('dot').

Changing the grammar

The grammar is EBNF in iheartla/la_grammar/, and the parsers in iheartla/la_local_parsers/ are TatSu's output for it, unedited. After changing the EBNF, regenerate them with the pinned TatSu, 5.15.1 (other versions generate different code):

python -m iheartla --regenerate-grammar
python -m iheartla.la_grammar.update_parsers --check   # (the test suite runs this too)

The script also fixes up TatSu's object model in two ways: every node class gets all the fields its rules define, and the classes are sorted so regenerating is stable (see complete_model in iheartla/la_grammar/update_parsers.py).

What a program declares changes what parses: declared multi-letter names, function names, imported builtins and their renames, and the constant e. The rules that depend on them are overridden in iheartla/la_tools/configured_parser.py, which configures the parser before each parse. On the rust branch, run python rust/tools/gen_parser.py afterwards to translate the parsers to Rust.

Output Dependencies

To use the code output for the various backends, you will need:

  • LaTeX: A working tex distribution with xelatex and pdfcrop
  • Python: NumPy and SciPy
  • MATLAB: MATLAB or Octave
  • C++: Eigen. Code with meshes or derivatives also needs iheartla/mesh/Cpp/include/ (the mesh classes, and the support header type_helper.h) on the include path; with meshes, compile and link iheartla/mesh/Cpp/src/ (the web page downloads both as iheartla-cpp.zip); with derivatives, autodiff, which needs Eigen 3.4. On macOS with Homebrew's Eigen: c++ -std=c++17 -I$(brew --prefix eigen)/include/eigen3 output.cpp -o output
  • MATLAB: MATLAB or (untested) Octave

Unicode Fonts

DejaVu Sans Mono is a font with good Unicode support. Windows users should install it. You can download it here. The I❤️LA GUI will use it if installed.

Packaging a release

To update the browser-based compiler after changing the compiler, rebuild its wheel, docs/iheartla-0.0.1-py3-none-any.whl, and the page's download of the C++ support files, docs/iheartla-cpp.zip, and commit them:

sh docs/update_wheel.sh

It runs uv build, which builds the wheel from an sdist (uv build --wheel would build in the source tree, where a stale build/ can leak into it).

macOS: pyinstaller iheartla.spec. The output iheartla.app is placed into dist/. The parsers ship in iheartla/la_local_parsers/, so packaging doesn't regenerate them.

Explore projetos relacionados

Carregando…