{"id":19512311,"url":"https://github.com/vmchale/apple","last_synced_at":"2025-04-26T04:31:33.239Z","repository":{"id":59125082,"uuid":"529690220","full_name":"vmchale/apple","owner":"vmchale","description":"Apple array system","archived":false,"fork":false,"pushed_at":"2025-04-20T10:34:58.000Z","size":12636,"stargazers_count":66,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"canon","last_synced_at":"2025-04-20T12:03:07.294Z","etag":null,"topics":["array","haskell"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/vmchale.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"COPYING","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":"2022-08-27T20:29:16.000Z","updated_at":"2025-04-20T10:35:04.000Z","dependencies_parsed_at":"2024-01-12T02:25:51.193Z","dependency_job_id":"86e42e1d-2386-438a-9ce2-806b6e9b35bc","html_url":"https://github.com/vmchale/apple","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmchale%2Fapple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmchale%2Fapple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmchale%2Fapple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmchale%2Fapple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vmchale","download_url":"https://codeload.github.com/vmchale/apple/tar.gz/refs/heads/canon","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250931020,"owners_count":21509801,"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":["array","haskell"],"created_at":"2024-11-10T23:25:25.005Z","updated_at":"2025-04-26T04:31:33.231Z","avatar_url":"https://github.com/vmchale.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apple Array System\n\nThis is an experimental compiler for an array domain-specific language (DSL) targeting Aarch64.\n\nSee [Apple by Example](https://vmchale.github.io/apple/) for a tour of the\nlanguage.\n\nThe compiler will bail out with arcane error messages rather than\nproduce an incorrect result (some cases are not implemented), except that the Python/R extension modules do not\nenforce type safety and thus may mysteriously segfault or produce unpredictable corrupt results.\n\n## Compiler-As-a-Library\n\nRather than an environment-based interpreter or a compiler invoked on the\ncommand line and generating object files, one calls a library function which\nreturns assembly or machine code from a source string.\n\nThus the same implementation can be used interpreted, compiled, or called from\nanother language.\n\n```\n \u003e [(+)/x%ℝ(:x)]\\`7 (frange 1 10 10)\nArr (4) [4.0, 5.0, 6.0, 7.0]\n```\n\n```python\n\u003e\u003e\u003e import apple\n\u003e\u003e\u003e import numpy as np\n\u003e\u003e\u003e sliding_mean=apple.jit('([(+)/x%ℝ(:x)]\\`7)')\n\u003e\u003e\u003e sliding_mean(np.arange(0,10,dtype=np.float64))\narray([3., 4., 5., 6.])\n```\n\n```janet\nrepl:1:\u003e (import apple)\n@{_ @{:value \u003ccycle 0\u003e} apple/jit @{:private true} apple/tyof @{:private true}}\nrepl:2:\u003e (def sliding-mean (apple/jit ``([(+)/x%ℝ(:x)]\\`7)``))\n\u003cjit Vec (i + 7) float → Vec i float\u003e\nrepl:3:\u003e (sliding-mean @[0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0])\n@[3 4 5 6 7]\n```\n\n```R\n\u003e source(\"R/apple.R\")\n\u003e sliding_mean\u003c-jit(\"([(+)/x%ℝ(:x)]\\\\`7)\")\n\u003e run(sliding_mean,seq(0,10,1.0))\n[1] 3 4 5 6 7\n```\n\nApple [tends to be faster than R](http://blog.vmchale.com/article/r-perf) but\nlags NumPy.\n\n### JIT'ed Calculator\n\nThere are no imports.\n\nRecursive functions are not allowed. The DSL is still useful in that it compiles array\nconstructs for the host languages.\n\n## Dimension As a Functor\n\nThis is based on J (and APL?). Looping is replaced by functoriality (rerank).\n\nTo supply a zero-cells (scalars) as the first argument to `⊲` (cons) and 1-cells as the second:\n\n```\n(⊲)`{0,1}\n```\n\nWe can further specify that the cells should be selected along some axis, e.g.\nto get vector-matrix multiplication:\n\n```\nλA.λx.\n{\n  λA.λx. (x⋅)`{1∘[2]} (A::Arr (i × j) float)\n}\n```\n\nThe `2` means \"iterate over the second axis\" i.e. columns.\n\n## Array QuickCheck\n\n```\n \u003e :qc \\x. [(+)/(*)`x y] x x \u003e= 0.0\nPassed, 100.\n \u003e :qc \\x. [(+)/(*)`x y] x x \u003e 2.0\nProposition failed!\n[ Arr (5) [ 0.6213045301664751\n          , 0.6599381241699802\n          , 0.762478867048601\n          , 6.026206825450409e-3\n          , 0.5633419282435523 ] ]\n```\n\n## Installation\n\nUse [ghcup](https://www.haskell.org/ghcup/) to install [cabal](https://www.haskell.org/cabal/) and GHC. Then:\n\n```\nmake install\n```\n\nto install `arepl` (the REPL).\n\nRun\n\n```\nmake\nsudo make install-lib\n```\n\nTo install the shared library (requires [jq](https://jqlang.github.io/jq/)).\n\n### Python\n\nTo install the Python module:\n\n```\nmake install-py\n```\n\n### R\n\nInstall `libappler.so` on your system like so:\n\n```\nmake -C Rc\nsudo make install-r\n```\n\nThen:\n\n```\nsource(\"R/apple.R\")\n```\n\nto access the functions.\n\n### Janet\n\nUses [jpm](https://janet-lang.org/docs/jpm.html).\n\n```\nmake -C janet install\n```\n\n## Documentation\n\nType `\\l` in the REPL to show the reference card:\n\n```\n \u003e \\l\nΛ             scan                     √             sqrt\n⋉             max                      ⋊             min\n⍳             integer range            ⌊, ⌈          floor, ceiling\ne:            exp                      ⨳ {m,n}       convolve\n\\~            successive application   \\`n           infix\n_.            log                      '             map\n`             zip                      `{i,j∘[k,l]}  rank\n𝒻             range (real)             𝜋             pi\n_             negate                   :             size\n𝓉             dimension                {x⟜y;z}       no inline\n-\u003en           select                   **            power\n⊂             scatter                  }.            last\n⊲             cons                     ⊳             snoc\n^:            iterate                  %.            matmul\n⊗             outer product            ⍉, |:         transpose\n{.            head                     }:            typesafe init\n⟨z,w⟩         array literal            ?p,.e1,.e2    conditional\n...\n```\n\nEnter `:help` in REPL:\n\n```\n \u003e :help\n:help, :h                    Show this help\n:yank, :y      \u003cfn\u003e \u003cfile\u003e   Read file\n:store, :st    \u003cname\u003e \u003cexpresAdd to environment\n:ty            \u003cexpression\u003e  Display the type of an expression\n:ann           \u003cexpression\u003e  Annotate with types\n...\n```\n\n### Vim Plugin\n\n`:h apple` lists potentially useful digraphs, viz.\n\n```\n←   \u003c-\n⟜   o-\n𝒻   ff\n⊲   \u003c\\\n⊳   \\\u003e\n⋮\n```\n\n### Python Module\n\nTo display module documentation:\n\n```python\n\u003e\u003e\u003e import apple\n\u003e\u003e\u003e help(apple)\n```\n\n```\nCLASSES\n    builtins.object\n        AppleJIT\n\n    class AppleJIT(builtins.object)\n     |  JIT-compiled function in-memory\n     |\n     |  Methods defined here:\n     |\n     |  __call__(self, /, *args, **kwargs)\n     |      Call self as a function.\n     |\n     |  ----------------------------------------------------------------------\n\nFUNCTIONS\n    asm(...)\n        Dump assembly\n\n    ir(...)\n        Dump IR (debug)\n\n    jit(...)\n        Compile an expressoin into a callable object\n\n    typeof(...)\n        Display type of expression\n```\n\n### Janet\n\n```janet\nrepl:2:\u003e (import apple)\n@{_ @{:value \u003ccycle 0\u003e} apple/jit @{:private true} apple/tyof @{:private true}}\nrepl:4:\u003e (doc apple/jit)\n\n\n    cfunction\n\n    Compile source string into Janet callable\n\n\nnil\nrepl:5:\u003e (doc apple/tyof)\n\n\n    cfunction\n\n    type of expression\n\n\nnil\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmchale%2Fapple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmchale%2Fapple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmchale%2Fapple/lists"}