{"id":15286790,"url":"https://github.com/kubetrail/julia","last_synced_at":"2026-05-02T05:35:59.498Z","repository":{"id":42685161,"uuid":"472095798","full_name":"kubetrail/julia","owner":"kubetrail","description":"lib: Go interface to julia runtime","archived":false,"fork":false,"pushed_at":"2022-03-29T20:34:31.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-29T05:17:51.662Z","etag":null,"topics":["cgo-bindings","foreign-function-interface","generics","golang-library","julia","julia-language"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kubetrail.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-20T20:32:19.000Z","updated_at":"2022-07-19T16:08:47.000Z","dependencies_parsed_at":"2022-08-26T08:10:57.849Z","dependency_job_id":null,"html_url":"https://github.com/kubetrail/julia","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubetrail%2Fjulia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubetrail%2Fjulia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubetrail%2Fjulia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubetrail%2Fjulia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kubetrail","download_url":"https://codeload.github.com/kubetrail/julia/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245175343,"owners_count":20572781,"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":["cgo-bindings","foreign-function-interface","generics","golang-library","julia","julia-language"],"created_at":"2024-09-30T15:18:32.661Z","updated_at":"2026-05-02T05:35:59.457Z","avatar_url":"https://github.com/kubetrail.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# julia\nThis is a `go` interface to `julia` runtime intended for single threaded\nand lightweight use for simple code execution.\n\nPlease start with [embedding](https://docs.julialang.org/en/v1/manual/embedding/)\ndocs, which is the basic design on which this library is built.\n\n# disclaimer\n\u003e The use of this tool does not guarantee security or usability for any\n\u003e particular purpose. Please review the code and use at your own risk.\n\u003e \n\u003e Please also see known limitations at the end of this doc.\n\n## installation\nThis step assumes you have [Go compiler toolchain](https://go.dev/dl/)\ninstalled on your system with version at least Go 1.18. The library\nmakes use of `go` generics.\n\nYou will also need to have `julia` installed at `/usr/local/julia` which\nis dynamically linked using `cgo`.\n\n\u003e Please note that this library is experimental and should not be used for\n\u003e production settings requiring multithreading and large volumes of data i/o\n\u003e to/from julia runtime.\n\u003e \n\u003e It is meant for simple julia invocation from Go interface. Use with caution.\n\nDownload this repo to a folder and cd to it.\n```bash\ngo test\n```\n\n## usage\nIn the example below we create a random matrix in `julia` and fetch that in `go`.\nThen pass that matrix back to `julia` runtime and compute its inverse.\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/kubetrail/julia\"\n)\n\nfunc main() {\n\tjulia.Initialize()\n\tdefer julia.Finalize()\n\n\t// testing inv(5,5)\n\tn := 5\n\n\t// create an argument to pass to julia function in the form\n\t// of a scalar value of int64 data type\n\targ, err := julia.Marshal(int64(n))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// get response from julia after evaluating a function called randn\n\t// in base module and passing two arguments to it of same value\n\t// created in the previous step\n\tresp, err := julia.EvalFunc(\"randn\", julia.ModuleBase, arg, arg)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// initialize a new matrix to populate it with response received above.\n\t// create a float64 matrix since output from randn is a float64 data type\n\tmat, err := julia.NewMat(make([]float64, n*n), n, n)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// unmarshal response into matrix. it is important to unmarshal into\n\t// types that match exactly those returned by julia, otherwise you will\n\t// get segfaults\n\tif err := julia.Unmarshal(resp, mat); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// print matrix elements\n\tfmt.Println(\"rand mat:\", mat.Elms)\n\n\t// now pass this matrix back to julia to compute its inverse.\n\t// marshaling is required to pass any data to julia runtime\n\tdata, err := julia.Marshal(mat)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// obtain response from julia runtime\n\tresp, err = julia.EvalFunc(\"inv\", julia.ModuleBase, data)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// unmrshal response back into the matrix since it fits perfect\n\t// for the data type and size\n\tif err := julia.Unmarshal(resp, mat); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// print elements of inverted matrix\n\tfmt.Println(\"inv mat:\", mat.Elms)\n}\n```\n\nHere is another example of matrix multiplication:\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/kubetrail/julia\"\n)\n\nfunc main() {\n\tjulia.Initialize()\n\tdefer julia.Finalize()\n\n\t// marshal out a data type that can be passed to julia runtime\n\t// as an argument to a function call\n\tn, err := julia.Marshal(int64(5))\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// evaluate randn with arguments created above to create a\n\t// random matrix\n\tx, err := julia.EvalFunc(\"randn\", julia.ModuleBase, n, n)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// find inverse of the matrix\n\ty, err := julia.EvalFunc(\"inv\", julia.ModuleBase, x)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// then multiply matrix by its inverse and the result should\n\t// be very close to an identity matrix\n\tz, err := julia.EvalFunc(\"*\", julia.ModuleBase, x, y)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// prepare a matrix to collect the values from julia runtime\n\tmat, err := julia.NewMat(make([]float64, 25), 5, 5)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// unmarshal julia runtime data into matrix\n\tif err := julia.Unmarshal(z, mat); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// print output\n\tfmt.Println(\"matrix multiplied by its inverse is an identity matrix:\")\n\tfmt.Println(mat.Elms)\n}\n```\n## dockerfile\nA `dockerfile` can be used to build these [examples](./examples)\n```bash\ndocker build -t go-julia ./\n```\n\nRun an example in the container:\n```bash\ndocker run --rm -it go-julia /go-julia/matrix-inversion\nrand mat: [1.017768642481323 0.18851208555752758 -0.3488466841230449 0.4406143439802128 -0.9871042912008214 -2.3784718350906355 -1.8453603181415057 -0.09313474878433725 1.3359835582412696 -0.2341551927011799 0.7564688157590539 0.6625939970160911 1.7330849839849714 -1.0073081834684647 0.9176323073548744 -0.19748061907540335 1.0518872982633893 1.3556630206573586 -0.41537427531113674 1.8618622495593484 -0.08692220378171413 0.15844308568914403 1.961931713197817 -0.9674542403020966 0.6027724685356741]\ninv mat: [0.017579422927962773 0.33640304238850627 2.0600006052967696 -0.4904229824862231 -1.4617453088048453 0.7276869478620276 -0.6639410803972795 -2.6019577734205965 1.0419842754172768 1.676332344686367 0.6160516767647928 0.20485388151853834 -0.06754593530676123 0.20961519218300062 0.5437915468222431 0.9668365082102905 0.510424584895026 0.3884752124354898 0.557668509045042 -0.5323606068080747 -0.642116529077303 0.3754996808917087 1.8243608863358483 -0.13181720095132604 -1.6168253384478684]\n```\n\n```bash\ndocker run --rm -it go-julia /go-julia/matrix-multiplication\nmatrix multiplied by its inverse is an identity matrix:\n[0.9999999999999994 2.393094211668032e-16 -1.0471181754244775e-15 7.021075814654354e-16 3.076390399372395e-16 8.757211127093011e-17 0.9999999999999989 2.7294181293716953e-16 3.5320707519199396e-16 -3.2696702378511e-16 1.7145691212372143e-16 5.635048558235537e-17 1 -1.706945437414341e-16 -2.3262142907258317e-17 9.85627416443657e-17 -3.884989330059967e-16 2.2894671093460267e-16 0.9999999999999999 -3.7378253110592907e-16 -1.1418060527744768e-16 9.42406854610802e-16 -2.2780738535360076e-16 -8.110240689058509e-16 1.0000000000000002]\n```\n\n## architecture\nThe library is not intended to cover all possible `julia` execution scenarios and meant for \nsimple use cases where `go` front end is required on top of `julia` backend runtime.\n\nA type-parametrized `matrix` type is defined:\n```go\n// Mat represents the matrix for supported data types\n// parameterized by primitive types\ntype Mat[T PrimitiveTypes] struct {\n\telms []T\n\tdims []int\n}\n```\n\nThis is the main data structure to send and receive values between `go` and `julia` runtimes.\n\nFurthermore, `Marshal` and `Unmarshal` functions are defined to work with `Mat` data\nstructure to pack/unpack data into a `julia` native generic data type.\n\n## known issues\nForeign function interface to `julia` via its `C-API` should be used with\ncaution and preferably run in a single threaded mode. Considering `go` allows\nconcurrency very easily, extra care needs to be taken to ensure that `julia`\ndoes not run as part of multiple goroutines.\n\n* https://discourse.julialang.org/t/problems-scaling-jl-alloc-array-2d-c-api/63341\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubetrail%2Fjulia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkubetrail%2Fjulia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubetrail%2Fjulia/lists"}