{"id":41711729,"url":"https://github.com/ethanthoma/zensor","last_synced_at":"2026-01-24T21:45:13.128Z","repository":{"id":247511989,"uuid":"825604150","full_name":"ethanthoma/zensor","owner":"ethanthoma","description":"Zig tensor library","archived":false,"fork":false,"pushed_at":"2025-07-11T18:54:16.000Z","size":114,"stargazers_count":18,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-11T20:38:46.674Z","etag":null,"topics":["machine-learning","tensor","zig","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/ethanthoma.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-08T06:59:30.000Z","updated_at":"2025-07-11T18:54:20.000Z","dependencies_parsed_at":"2024-09-12T10:57:40.787Z","dependency_job_id":"612c419b-f967-4cb4-969a-69c2006b0e8b","html_url":"https://github.com/ethanthoma/zensor","commit_stats":null,"previous_names":["ethanthoma/zensor"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ethanthoma/zensor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanthoma%2Fzensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanthoma%2Fzensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanthoma%2Fzensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanthoma%2Fzensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ethanthoma","download_url":"https://codeload.github.com/ethanthoma/zensor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanthoma%2Fzensor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28737622,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T21:19:41.845Z","status":"ssl_error","status_checked_at":"2026-01-24T21:13:38.675Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["machine-learning","tensor","zig","zig-package"],"created_at":"2026-01-24T21:45:12.459Z","updated_at":"2026-01-24T21:45:13.120Z","avatar_url":"https://github.com/ethanthoma.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch3 align=\"center\"\u003e\n    Zensor, a zig tensor library\n\u003c/h3\u003e\n\nA zig tensor library. Correctness first, speed second.\n\nThis library promises compile-time type and shape checking.\n\n**Very WIP**\n\n## Example Usage:\n```zig \nconst std = @import(\"std\");\n\nconst T = u32;\nconst Tensor = @import(\"zensor\").Tensor(T);\n\npub fn main() !void {\n    var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n    const allocator = gpa.allocator();\n\n    var compiler = zensor.Compiler.init(allocator);\n    defer compiler.deinit();\n\n    const filename = \"./examples/numpy.npy\";\n\n    const a = try zensor.Tensor(.Int64, .{3}).from_numpy(\u0026compiler, filename);\n\n    const b = try zensor.Tensor(.Int64, .{3}).full(\u0026compiler, 4);\n\n    const c = try a.mul(b);\n\n    const d = try c.sum(0);\n\n    std.debug.print(\"{}\\n\", .{d});\n}\n```\n\nResults in:\n```\n❯ zig build run\nTensor(\n        type: dtypes.Int64,\n        shape: [1],\n        length: 1,\n        data: [56, ]\n)\n```\n\n## Install\n\nFetch the library:\n```bash\nzig fetch --save git+https://github.com/ethanthoma/zensor.git#main\n```\n\nAdd to your `build.zig`:\n```zig\n    const zensor = b.dependency(\"zensor\", .{\n        .target = target,\n        .optimize = optimize,\n    }).module(\"zensor\");\n    exe.root_module.addImport(\"zensor\", zensor);\n```\n\n## Examples\n\nExamples can be found in `./examples`. You can run these via:\n```bash\nzig build NAME_OF_EXAMPLE\n```\nAssuming you have cloned the source.\n\n## Tests\n\nIf you want to run the tests after cloning the source. Simply run:\n```bash\nzig build test\n```\n\n## Design\n\nLet's take an example op:\n```zig\nconst a = try zensor.Tensor(.Int64, .{3}).from_numpy(\u0026compiler, filename); // [ 1, 4, 9 ]\n\nconst b = try zensor.Tensor(.Int64, .{3}).full(\u0026compiler, 4); // [ 4, 4, 4 ]\n\nconst c = try a.mul(b); // [ 4, 16, 36 ]\n\nstd.debug.print(\"C = A.mul(B) = {}\\n\", .{c});\n```\n\nThis library converts all tensor operations into an AST:\n```\n0 Store RuntimeBuffer(ptr=@139636592083200, dtype=dtypes.Int64, shape={ 3 })\n1 ┗━Mul\n2   ┣━Load RuntimeBuffer(ptr=@139636592082944, dtype=dtypes.Int64, shape={ 3 })\n3   ┗━Const 4\n```\n\nWhen you want to execute your operations, like when you `print` the tensor or `realize` it,\nthe AST is split into schedules:\n```\nSchedule{\n        status: NotRun\n        topological sort: [4]ast.Nodes{Load, Const, Mul, Store},\n        global buffers: [(0, true), (1, false)],\n        dependencies count: 0,\n        AST:\n        0 Store RuntimeBuffer(ptr=@139636592083200, dtype=dtypes.Int64, shape={ 3 })\n        1 ┗━Mul\n        2   ┣━Load RuntimeBuffer(ptr=@139636592082944, dtype=dtypes.Int64, shape={ 3 })\n        3   ┗━Const 4\n}\n```\nThis is done so that it will generate a single kernel if you don't need intermediate results.\n\nThe current status is `NotRun`. The idea is that if the buffers and kernel are the \nsame (i.e., used in a previous step somewhere), we can just reuse the results and not rerun the kernel.\n\nWhen running, we convert the AST into IR:\n```\nstep op name          type             input            arg\n   0 DEFINE_GLOBAL    Pointer          []               (0, true)\n   1 DEFINE_GLOBAL    Pointer          []               (1, false)\n   2 CONST            Int              []               4\n   3 CONST            Int              []               0\n   4 CONST            Int              []               3\n   5 LOOP             Int              [3, 4]           None\n   6 LOAD             Int              [1, 5]           None\n   7 ALU              Int              [6, 2]           ALU.Mul\n   8 STORE                             [0, 5, 7]        None\n   9 ENDLOOP                           [5]              None\n```\nThis IR is based on the tinygrad IR (at some point) but will likely be changed into full SSA.\n\nWe convert the IR into bytecode (only x86 atm):\n```\npush Rbp\nmov Rbp, Rsp\npush { 0, 0, 0, 0 }\nlabel_0x9:\nmov R8, qword ptr [Rdi + 0x8]\nmov R9, qword ptr [Rbp + 0x-8]\nmov R8, qword ptr [R8 + R9 * 8]\nmov R10, { 4, 0, 0, 0 }\nmov R11, R8\nimul R11, R10\nmov R8, qword ptr [Rdi + 0x0]\nmov R9, qword ptr [Rbp + 0x-8]\nmov qword ptr [R8 + R9 * 8], R11\nmov R10, qword ptr [Rbp + 0x-8]\ninc R10\nmov qword ptr [Rbp + 0x-8], R10\nmov R11, R11\nmov R11, { 3, 0, 0, 0 }\ncmp R10, R11\njl 0x9\nleave\nret\n```\n\nAnd finally, executed:\n```\nTensor(\n        type: dtypes.Int64,\n        shape: [3],\n        length: 3,\n        data: [4, 16, 36, ]\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethanthoma%2Fzensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethanthoma%2Fzensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethanthoma%2Fzensor/lists"}