{"id":18047269,"url":"https://github.com/akabe/ppx_bigarray","last_synced_at":"2025-04-10T05:14:27.132Z","repository":{"id":76067236,"uuid":"41672184","full_name":"akabe/ppx_bigarray","owner":"akabe","description":"A PPX extension for big array literals in OCaml","archived":false,"fork":false,"pushed_at":"2018-07-18T05:08:36.000Z","size":85,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T05:14:19.382Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akabe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2015-08-31T11:39:06.000Z","updated_at":"2023-01-07T14:37:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"4dfdc11f-819e-40d9-86ec-050647b66323","html_url":"https://github.com/akabe/ppx_bigarray","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/akabe%2Fppx_bigarray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akabe%2Fppx_bigarray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akabe%2Fppx_bigarray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akabe%2Fppx_bigarray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akabe","download_url":"https://codeload.github.com/akabe/ppx_bigarray/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161277,"owners_count":21057555,"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-10-30T19:10:55.959Z","updated_at":"2025-04-10T05:14:27.114Z","avatar_url":"https://github.com/akabe.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"ppx_bigarray\n============\n\n[![Build Status](https://travis-ci.org/akabe/ppx_bigarray.svg?branch=master)](https://travis-ci.org/akabe/ppx_bigarray)\n\nThis PPX extension provides\n[big array](http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.html)\nliterals in [OCaml](http://ocaml.org).\n\nInstall\n-------\n\n```\nopam install ppx_bigarray\n```\n\nDevelopment version:\n\n```\nopam pin add ppx_deriving https://github.com/akabe/ppx_bigarray.git\n```\n\nUsage\n-----\n\n### Compiling\n\n```\nocamlfind ocamlc -package bigarray,ppx_bigarray -linkpkg foo.ml\n```\n\n`ppx_bigarray` outputs code that depends on the runtime library `ppx_bigarray.runtime` (`Ppx_bigarray_runtime` module).\n\nIf you use [Dune](https://github.com/ocaml/dune) (jbuilder), `dune` file is like\n\n``` lisp\n  (libraries  ppx_bigarray.runtime)\n  (preprocess (pps ppx_bigarray))\n```\n\n### Example\n\n`x` is a two-dimensional big array that has size 3-by-4, kind `Bigarray.int`,\nand layout `Bigarray.c_layout`.\n\n```OCaml\nlet x = [%bigarray2.int.c\n          [\n            [11; 12; 13; 14];\n            [21; 22; 23; 24];\n            [31; 32; 33; 34];\n          ]\n        ] in\nprint_int x.{1,2} (* print \"23\" *)\n```\n\nIn this code, elements of a big array are given as a list of lists, but\nyou can use an array of arrays:\n\n```OCaml\nlet x = [%bigarray2.int.c\n          [|\n            [|11; 12; 13; 14|];\n            [|21; 22; 23; 24|];\n            [|31; 32; 33; 34|];\n          |]\n        ] in\nprint_int x.{1,2} (* print \"23\" *)\n```\n\n`[%bigarray2.int.c ELEMENTS]` is a syntax of big array literals. `ELEMENTS`\nmust have a syntax of a list literal (`[...]`) or an array literal (`[|...|]`).\nYou cannot give an expression that returns a list or an array (such as\n`let x = [...] in [%bigarray2.int.c x]`) since `[%bigarray2.int.c ...]` is NOT\nthe function that converts a list or an array into a big array.\n\n### Basic syntax\n\n- `[%bigarray1.KIND.LAYOUT ELEMENTS]` is a one-dimensional big array\n  (that has type `Bigarray.Array1.t`). `ELEMENTS` is a list or an array.\n- `[%bigarray2.KIND.LAYOUT ELEMENTS]` is a two-dimensional big array\n  (that has type `Bigarray.Array2.t`). `ELEMENTS` is a list of lists or\n  an array of arrays.\n- `[%bigarray3.KIND.LAYOUT ELEMENTS]` is a three-dimensional big array\n  (that has type `Bigarray.Array3.t`). `ELEMENTS` is a list of lists of lists or\n  an array of arrays of arrays.\n- `[%bigarray.KIND.LAYOUT ELEMENTS]` is a multi-dimensional big array\n  (that has type `Bigarray.Genarray.t`). `ELEMENTS` is a nested list or\n  a nested array.\n\nYou can specify the following identifiers as `KIND` and `LAYOUT`:\n\n| `KIND`                       | Corresponding big array kind                            |\n|------------------------------|---------------------------------------------------------|\n| `int8_signed` or `sint8`     | `Bigarray.int8_signed`                                  |\n| `int8_unsigned` or `uint8`   | `Bigarray.int8_unsigned`                                |\n| `int16_signed` or `sint16`   | `Bigarray.int16_signed`                                 |\n| `int16_unsigned` or `uint16` | `Bigarray.int16_unsigned`                               |\n| `int32`                      | `Bigarray.int32`                                        |\n| `int64`                      | `Bigarray.int64`                                        |\n| `int`                        | `Bigarray.int`                                          |\n| `nativeint`                  | `Bigarray.nativeint`                                    |\n| `float32`                    | `Bigarray.float32`                                      |\n| `float64`                    | `Bigarray.float64`                                      |\n| `complex32`                  | `Bigarray.complex32`                                    |\n| `complex64`                  | `Bigarray.complex64`                                    |\n| `char`                       | `Bigarray.char`                                         |\n| otherwise                    | (to refer the variable that has a given name as a kind) |\n\n| `LAYOUT`                      | Corresponding big array layout                            |\n|-------------------------------|-----------------------------------------------------------|\n| `c` or `c_layout`             | `Bigarray.c_layout`                                       |\n| `fortran` or `fortran_layout` | `Bigarray.fortran_layout`                                 |\n| otherwise                     | (to refer the variable that has a given name as a layout) |\n\n\"otherwise\" in the above tables means that users can specify user-defined names of kinds and\nlayouts in addition to built-in names, like the following code:\n\n```OCaml\nlet f32 = Bigarray.float32\nlet f = Bigarray.fortran_layout\nlet x = [%bigarray1.f32.f [1.0; 2.0; 3.0]] (* Use `f32' and `f' instead of\n                                              float32 and fortran_layout, respectively. *)\n```\n\n### Padding\n\nBig arrays of two or more dimensions need to be rectangular.\nIf you write a non-rectangular big array literal, by default, `ppx_bigarray` warns\nit in compile time (Warning 22), and lacked elements are uninitialized.\nYou can explicitly specify padding, a value of lacked elements by\n`[@bigarray.padding EXPRESSION]`:\n\n```OCaml\nlet x = [%bigarray2.int.c\n          [\n            [11; 12; 13; 14];\n            [21; 22; 23];\n            [31; 32];\n          ] [@bigarray.padding 0]\n        ]\n```\n\nIn this case, lacked elements are initialized by `0`, i.e., the above code\nis the same as\n\n```OCaml\nlet x = [%bigarray2.int.c\n          [\n            [11; 12; 13; 14];\n            [21; 22; 23;  0];\n            [31; 32;  0;  0];\n          ]\n        ]\n```\n\n`[@bigarray.padding]` inhibits the warnings for non-rectangular big array literals.\n\n### Alias\n\n`[%bigarray.KIND.LAYOUT ...]` is slightly verbose syntax because\nwe usually use a few combinations of big array kinds and layouts.\nYou can define aliases of pairs of a kind and a layout that\nyou frequently use as follows:\n\n```OCaml\n(* `z' is an alias of complex64.fortran_layout. *)\nlet ppx_bigarray__z = Ppx_bigarray_runtime.({\n    kind = Bigarray.complex64;\n    layout = Bigarray.fortran_layout;\n  })\n\n(* %bigarray1.z is the same as %bigarray1.complex64.fortran_layout. *)\nlet x = [%bigarray1.z [...]]\n```\n\n`[%bigarray.ALIAS ...]` refers `ppx_bigarray__ALIAS.Ppx_bigarray_runtime.kind`\nas a kind, and `ppx_bigarray__ALIAS.Ppx_bigarray_runtime.layout` as a layout.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakabe%2Fppx_bigarray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakabe%2Fppx_bigarray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakabe%2Fppx_bigarray/lists"}