This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # provides llvm21 deps to build zig 0.16.0-dev from source | |
| # https://github.com/ziglang/zig/wiki/Building-Zig-From-Source#dependencies | |
| # https://github.com/ziglang/zig/wiki/Building-Zig-From-Source#option-b-use-a-pre-built-zig-binary | |
| # | |
| # first build with cmake to produce 'A recent prior build of Zig', zig1, `build/stage3/bin/zig`. | |
| # and then subsequently with zig1 to quickly produce `stage3/bin/zig` | |
| # | |
| # ``` | |
| # $ cat build/build.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export fn add(a: [*]u32, b: [*]u32, out: [*]u32) void { | |
| const avec: Vec(u32, 3) = .fromArr(a[0..3].*); | |
| const bvec: Vec(u32, 3) = .fromArr(b[0..3].*); | |
| out[0..3].* = avec.add(bvec).toArr(); | |
| } | |
| export fn add_simd(a: [*]u32, b: [*]u32, out: [*]u32) void { | |
| const avec: Vec(u32, 3) = .fromArr(a[0..3].*); | |
| const bvec: Vec(u32, 3) = .fromArr(b[0..3].*); | |
| out[0..3].* = avec.addSimd(bvec).toArr(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //! | |
| //! a work in progress | |
| //! | |
| //! this lib only does multiplication so far. but can parse numpy output at | |
| //! runtime and comptime and has lots helpers including array() which | |
| //! allows multi indexing i.e `mat.array()[i][j]`. there are some working | |
| //! tests for 1d, 2d, 3d and 4d matrices w/ different shapes. | |
| //! | |
| //! Resources: | |
| //! https://ajcr.net/stride-guide-part-1/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| pub fn SharedVecMethods(comptime Self: type) type { | |
| return struct { | |
| const fields = @typeInfo(Self).Struct.fields; | |
| const T = fields[0].type; | |
| comptime { | |
| // check that all fields have the same type | |
| for (fields) |f| std.debug.assert(T == f.type); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //! | |
| //! tests written for zonny.zig | |
| //! | |
| //! there is an example of parsing a build.zig.zon file at the bottom of this file. | |
| //! | |
| const std = @import("std"); | |
| const testing = std.testing; | |
| const zonny = @import("zonny"); | |
| const talloc = testing.allocator; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| pub fn build(b: *std.Build) void { | |
| const optimize = b.standardOptimizeOption(.{}); | |
| const exe = b.addExecutable(.{ | |
| .name = "lib", | |
| .root_source_file = .{ .path = "src/lib.zig" }, | |
| .target = b.resolveTargetQuery(std.Target.Query.parse( | |
| .{ .arch_os_abi = "wasm32-freestanding" }, | |
| ) catch unreachable), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # generates valid zig multiply test case code which may used in matrix.zig | |
| import numpy as np | |
| np.random.seed(42) | |
| # A = np.empty((2, 3, 2)) | |
| # A.fill(1) | |
| # A = np.array([ | |
| # [ | |
| # [1,2,3], | |
| # [4,5,6], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //! | |
| //! updated. now without usingnamespace. see previous revisions for a version with usingnamespace. | |
| //! | |
| pub fn VecMethods(comptime Self: type) type { | |
| return struct { | |
| const info = @typeInfo(Self); | |
| pub const len = info.Struct.fields.len - 1; | |
| pub const Arr = [len]info.Struct.fields[0].type; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // zig build-obj -fstrip -OReleaseSmall /tmp/tmp.zig -femit-bin=/tmp/tmp.o && objdump -d /tmp/tmp.o | |
| const std = @import("std"); | |
| pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, start: ?usize) noreturn { | |
| _ = .{ msg, st, start }; | |
| @trap(); | |
| } | |
| pub export fn _start() callconv(.Naked) noreturn { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //! https://en.wikipedia.org/wiki/Levenshtein_distance | |
| const std = @import("std"); | |
| pub fn levRec(a: []const u8, b: []const u8) u16 { | |
| if (a.len == 0) return @truncate(b.len); | |
| if (b.len == 0) return @truncate(a.len); | |
| if (a[0] == b[0]) | |
| return levRec(a[1..], b[1..]); | |
| return @min( |
NewerOlder