{"id":13711799,"url":"https://github.com/andrewCodeDev/ZEIN","last_synced_at":"2025-05-06T21:32:12.987Z","repository":{"id":171830164,"uuid":"648466221","full_name":"andrewCodeDev/ZEIN","owner":"andrewCodeDev","description":"Zig-based implementation of tensors","archived":false,"fork":false,"pushed_at":"2024-10-29T02:01:40.000Z","size":127,"stargazers_count":52,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-26T16:07:47.742Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/andrewCodeDev.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}},"created_at":"2023-06-02T03:21:43.000Z","updated_at":"2025-02-28T14:15:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"648c4795-0eb7-4c90-b85c-4f75b609aa86","html_url":"https://github.com/andrewCodeDev/ZEIN","commit_stats":null,"previous_names":["andrewcodedev/zein"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewCodeDev%2FZEIN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewCodeDev%2FZEIN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewCodeDev%2FZEIN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewCodeDev%2FZEIN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewCodeDev","download_url":"https://codeload.github.com/andrewCodeDev/ZEIN/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252772138,"owners_count":21801861,"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-08-02T23:01:11.729Z","updated_at":"2025-05-06T21:32:12.627Z","avatar_url":"https://github.com/andrewCodeDev.png","language":"Zig","readme":"# ZEIN\n\nZig-based implementation of general-rank tensors! [1, 64)\n\n## Importing ZEIN\n\n1. Fetch ZEIN:\n\n`zig fetch --save git+https://github.com/andrewCodeDev/ZEIN#main`\n\n2. Add the module in your `build.zig`:\n\n```zig\nconst zein = b.dependency(\"ZEIN\", .{\n    .target = target,\n    .optimize = optimize,\n});\n\nexe.root_module.addImport(\"zein\", zein.module(\"ZEIN\"));\n```\nYou can now add `const zein = @import(\"zein\");` to your file.\n\n## Using Tensor Objects\n\nTensors can be created in the following way:\n\n```zig\n// initialize underlying tensor memory:\nvar data = [9]i32{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n\n// create a rank 2, 3x3, Rowwise tensor of i32 from data:\nvar X = zein.Tensor(i32, 2, Rowwise).init(\u0026data, .{ 3, 3 });    \n\nconst x = X.getValue(.{0, 2}); // access value 3...\n```\n\n## Allocating Tensor Data\n\nThe TensorFactory offers the ability to track and free allocations:\n\n```zig\nvar factory = zein.TensorFactory(f32).init(.{\n  .system_allocator = your_allocator, // for TensorFactory components\n  .tensor_allocator = your_allocator, // for TensorFactory value data\n});\n\n// Begin tracking tensor allocations (default is no-tracking):\nfactory.tracking(.start);\n\n// Stop tracking tensor allocations (does not free tensors):\nfactory.tracking(.stop);\n\n// Free tracked tensor allocations (no-op if no tensors are tracked):\nfactory.tracking(.free);\n\n// Deinit will free the allocator and currently tracked tensors:\nfactory.deinit();\n````\n\n```zig\n// Assign a new tensor from allocator:\nvar Y = try factory.allocTensor(2, Rowwise, .{ 10, 10 });\n```\n\n```zig\n// Assign memory into existing tensor:\nvar X = Tensor(f32, 2, Rowwise).init(null, .{ 10, 10 });\ntry factory.allocToTensor(\u0026X); // alloc 100 elements...\n````\n\n## Tensor Operations\n\nTensor operations are are in the form of either _Free Functions_ or _Factory Functions_:\n\n- Free Functions require operands and the destination tensor.\n\n- Factory Functions use operands to create the destination tensor.\n\nThe operations use compile time strings as einsum notation:\n\n```zig\n// Collapse tensor values using contraction:\nzein.contraction(\"ijk-\u003eji\", \u0026x, \u0026y); // free function - assign to existing memory\nvar y = factory.contraction(\"ijk-\u003eji\", \u0026x); // factory function - allocate new memory\n```\n\n```zig\n// Elementary binary functions (add, multiply):\nzein.add(\u0026x, \u0026y, \u0026z); // free function - assign to existing memory\nvar x = factory.add(\u0026x, \u0026y); // factory function - allocate new memory\n```\n\n```zig\n// Transpose/permutate tensor views (does not modify underlying data).\nvar y = x.permutate(\"ijk-\u003ekji\");\n```\n\n```zig\n// Elementary vectorized reduction functions (sum, product, min, max):\nconst a = zein.sum(\u0026x);\nconst b = zein.product(\u0026x);\nconst c = zein.max(\u0026x);\nconst d = zein.min(\u0026x);\n```\n\n## Using the Zein library\n\nThe main ZEIN/Zein.zig file provides an interface for the library implementation.\n\n## Memory Ownership and Viewership\n\nCurrently, tensor permutations only change the indexing of a tensor - they do not\ninvalidate underlying memory. If the user chooses to use the TensorFactory,\nit will track allocations and delete them automatically when calling deinit.\nV1 is only tested on single thread environments - thread safety with allocators\nwill be coming in a later version!\n\n## Additonal functionality coming soon.\n\nThis library is still in the beginning phases. If you want to contribute, please\ncontact me! This is a big job and I'll take the help!\n","funding_links":[],"categories":["Zig","Data \u0026 Science"],"sub_categories":["Machine Learning Framework"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FandrewCodeDev%2FZEIN","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FandrewCodeDev%2FZEIN","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FandrewCodeDev%2FZEIN/lists"}