{"id":50274430,"url":"https://github.com/beliavsky/array-compiler","last_synced_at":"2026-05-27T19:02:54.253Z","repository":{"id":343258243,"uuid":"1176961623","full_name":"Beliavsky/Array-Compiler","owner":"Beliavsky","description":"Translate Python/NumPy and other array languages to Fortran","archived":false,"fork":false,"pushed_at":"2026-03-09T18:32:40.000Z","size":414,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-09T19:55:18.207Z","etag":null,"topics":["array-programming","fortran","linear-algebra","modern-fortran","numpy","python","scientific-computing","transpiler"],"latest_commit_sha":null,"homepage":"","language":"Python","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/Beliavsky.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-09T14:55:46.000Z","updated_at":"2026-03-09T18:32:44.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Beliavsky/Array-Compiler","commit_stats":null,"previous_names":["beliavsky/array-compiler"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Beliavsky/Array-Compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FArray-Compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FArray-Compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FArray-Compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FArray-Compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Beliavsky","download_url":"https://codeload.github.com/Beliavsky/Array-Compiler/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FArray-Compiler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33579668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["array-programming","fortran","linear-algebra","modern-fortran","numpy","python","scientific-computing","transpiler"],"created_at":"2026-05-27T19:02:41.831Z","updated_at":"2026-05-27T19:02:54.247Z","avatar_url":"https://github.com/Beliavsky.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Array Compiler\n\nCompiler/transpiler framework for translating array-oriented scientific code into modern Fortran first, with C++ planned later as a second backend.\n\n## Status\n\nThe repository now has three practical command-line paths:\n\n- `x2f.py`: translate Python/NumPy and a restricted R subset to modern Fortran, with optional compile/run/timing support\n- `x2f_bench.py`: benchmark source runtimes against translated Fortran runtimes using repeated runs, medians, configurable slowdown thresholds, and aggregate timing summaries\n- `x2p.py`: translate a restricted R subset to Python/NumPy, either as standalone runnable Python or as the narrower typed subset used by `x2f.py`\n\nThe current architecture is still Fortran-first, but the repository now also includes:\n\n- a reusable normalized array IR\n- a Fortran runtime/helper registry\n- batch drivers for corpus testing\n- conservative source annotators and checkers for Python and R\n- an R reducer for shrinking translation/runtime mismatches\n- early support for comparing source-language output against translated output\n\nThe initial migration source is the [`Pure-Fortran`](https://github.com/beliavsky/pure-fortran) project.\n\n## Current Capabilities\n\n### `x2f.py`\n\n`x2f.py` now accepts:\n\n- `.py` for Python/NumPy input\n- `.r` and `.R` for restricted R input\n\nIt can:\n\n- emit Fortran source\n- compile the generated Fortran with `gfortran`\n- run the compiled executable\n- run source and translated code side by side with `--run-both`\n- time both sides with `--time-both`\n\nRecent `x2f.py` work includes:\n\n- initial `R -\u003e Python/NumPy -\u003e Python frontend -\u003e Fortran` support\n- stricter `gfortran` builds with `-Werror`\n- source-suffix-based Fortran outputs such as `_p.f90` for Python and `_r.f90` for R\n- argument passing from the generated Fortran driver into translated programs\n- better formatted Fortran console output for translated R scripts\n- working elapsed-time support for translated `proc.time()`-based R timer examples\n- broader shared runtime support for translated R statistical and numeric helpers\n\n### `x2p.py`\n\n`x2p.py` is a standalone R-to-Python/NumPy translator.\n\nIt supports two modes:\n\n- `--mode standalone`: emit runnable standalone Python/NumPy\n- `--mode x2f`: emit the narrower typed Python subset intended to feed `x2f.py`\n\nIt can also:\n\n- run the translated Python with `--run`\n- run R and translated Python side by side with `--run-both`\n- compare timings with `--time-both`\n- print the relevant source line, including continued R statements, on translation failures\n\nThe current R frontend covers a useful numeric subset rather than full R. It includes enough support to run and batch-translate the `Pure-Fortran` `r_examples_1` corpus through `x2p.py`, and many of those scripts now also compile through `x2f.py`.\n\n## Command-Line Tools\n\n### Translation\n\n- `x2f.py`: translate Python or restricted R to Fortran\n- `x2f_batch.py`: batch-run `x2f.py` over many `.py`, `.r`, or `.R` files, with optional CSV output\n- `x2f_bench.py`: benchmark selected cases from `benchmarks.toml` or ad hoc file/directory/glob inputs, report medians and speedups, flag baseline regressions, and flag suspicious cases where Fortran is much slower than the source program\n- `x2p.py`: translate restricted R to Python/NumPy\n- `x2p_batch.py`: batch-run `x2p.py` over many `.r` and `.R` files\n\n### Annotation and Checking\n\n- `xpyannotate.py`: add conservative Python type/rank/`Final` hints to runnable Python source\n- `xpycheck.py`: check typed/transpiler-friendly Python for consistency issues\n- `xrcheck.py`: check R source for patterns that are valid R but poor style for translation\n\n### Reduction\n\n- `xrreduce.py`: reduce an R script while preserving a differential failure such as \"R runs, translation succeeds, generated Python fails\"\n\n### Repository Workflow\n\n- `upload_to_github.bat`: stage curated project files, commit, and push without sweeping in generated `.exe`, `_p.py`, `_p.f90`, temp files, caches, or ad hoc local test artifacts\n- `upload_core_to_github.bat`: stage a curated core-project set\n- `upload_strict_source_to_github.bat`: stage only the strict compiler/runtime source whitelist, excluding tests, examples, docs, and generated files\n\n## Annotation and Checker Notes\n\n### `xpyannotate.py`\n\nThe annotator now does more than basic type hints. It can emit:\n\n- conservative type and rank annotations\n- `Final[...]` where the variable binding is not rebound\n- generated parameter-intent comments such as `# xpyannotate: intent x=in, y=local-rebind`\n- generated readonly-array comments such as `# xpyannotate: readonly-array`\n\nGenerated comments use the reserved `xpyannotate:` prefix so they can be distinguished from ordinary comments.\n\n### `xpycheck.py`\n\nThe Python checker can report:\n\n- annotation/type inconsistencies\n- conservative parameter-intent diagnostics\n- simple unstable variable-type changes\n\nIt also has a conservative `--fix-type-changes` mode for simple sequential cases where a new variable name can be introduced safely.\n\n### `xrcheck.py`\n\nThe R checker warns about translation-hostile patterns such as:\n\n- double literals used where integer values are clearer\n- `T` and `F` instead of `TRUE` and `FALSE`\n- bare `NA`\n- numeric values used as logicals\n- partial argument matching\n- obviously incompatible recycling\n- simple variable type changes\n\nIt can safely rewrite a subset of these cases with `--fix`, and it also has a conservative `--fix-type-changes` mode for simple sequential rewrites.\n\n### `xrreduce.py`\n\nThe R reducer is aimed at debugging translation/runtime mismatches. It can shrink an R script while preserving a differential failure such as:\n\n- `Rscript file.r` succeeds\n- `x2p.py file.r` succeeds\n- generated `file_p.py` fails\n\nThe current reducer starts with conservative structural passes and can optionally use slower line-based reduction.\n\n## Layout\n\n- `array_compiler/ir/`: normalized array IR and core compiler model\n- `array_compiler/frontends/`: source-language frontends\n- `array_compiler/backends/fortran/`: Fortran lowering and emission\n- `array_compiler/runtime/fortran/`: runtime/helper modules used by generated Fortran\n- `array_compiler/annotator.py`: Python annotation engine\n- `array_compiler/pychecker.py`: Python checker logic\n- `array_compiler/rchecker.py`: R checker logic\n- `array_compiler/benchmarking.py`: benchmark config loading and slowdown evaluation\n- `array_compiler/annotations.py`: runnable Python annotation aliases such as `Array1D[T]`\n- `docs/`: architecture and migration notes\n- `tests/`: regression coverage for frontends, backend, CLI tools, and helpers\n\n## Example Commands\n\nTranslate Python to Fortran:\n\n```bat\npython x2f.py xccc_garch_fit.py --compile\n```\n\nTranslate R to Fortran and run both source and translated code:\n\n```bat\npython x2f.py xbase_garch_moment_fit.r --run-both\n```\n\nTranslate R to standalone Python:\n\n```bat\npython x2p.py xbase_garch_sim.r\n```\n\nGenerate x2f-oriented Python from R:\n\n```bat\npython x2p.py xbase_garch_sim.r --mode x2f\n```\n\nBatch-translate an R corpus to x2f-oriented Python:\n\n```bat\npython x2p_batch.py c:\\python\\public_domain\\github\\Pure-Fortran-Examples\\r_examples_1 --mode x2f --out-dir c:\\python\\Array-Compiler\\tmp_r_x2f_py\n```\n\nBatch-run `x2f.py` over a directory of Python or R sources:\n\n```bat\npython x2f_batch.py c:\\python\\public_domain\\github\\Pure-Fortran-Examples\\r_examples_1 --compile --csv r_compile_results.csv\n```\n\nBenchmark selected translation cases with repeated runs, median timings, and aggregate stage totals:\n\n```bat\npython x2f_bench.py --case xoptions_pde --repeats 3 --warmups 1\n```\n\nBenchmark ad hoc Python or R sources directly, including Windows-friendly glob patterns:\n\n```bat\npython x2f_bench.py x*.py --repeats 1 --warmups 0\n```\n\nWrite a benchmark CSV report:\n\n```bat\npython x2f_bench.py --case xoptions_pde --csv bench_report.csv\n```\n\nAnnotate Python source:\n\n```bat\npython xpyannotate.py xccc_garch_fit.py\n```\n\nCheck Python source:\n\n```bat\npython xpycheck.py xccc_garch_fit_annotated.py --check-intent\n```\n\nCheck and optionally rewrite R source:\n\n```bat\npython xrcheck.py xtimer.r --fix\n```\n\nReduce an R differential failure:\n\n```bat\npython xrreduce.py xccc_garch_sim.r --output xccc_garch_sim_reduced.r --verbose\n```\n\nCurated commit/push:\n\n```bat\nupload_to_github.bat \"update r and fortran translation docs\"\n```\n\nStrict source-only commit/push:\n\n```bat\nupload_strict_source_to_github.bat \"update core compiler sources\"\n```\n\n## Near-Term Plan\n\n1. Keep widening the Python subset accepted by the Python-to-Fortran frontend, especially where generated R-to-Python code depends on it.\n2. Continue expanding the R subset with tests driven by real example corpora.\n3. Move more language semantics out of ad hoc text rewrites and toward cleaner lowering into the shared IR.\n4. Grow the shared Fortran runtime/helper modules for commonly used R statistical and numeric functions.\n5. Preserve full-program translation, but keep library/module generation, benchmarking, and helper/runtime management as first-class features.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeliavsky%2Farray-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeliavsky%2Farray-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeliavsky%2Farray-compiler/lists"}