Zig utility library
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add integer/float check for matrices and vectors

IamPyu 72303629 3e4518dc

+13 -27
+2 -9
src/SparseSet.zig
··· 123 123 _ = try list.insert(9); 124 124 try std.testing.expectEqual(2, v); 125 125 try std.testing.expectEqual(3, list.get(g).?.*); 126 - 127 - std.debug.print("{any}, {any}\n", .{ 128 - list.sparse.items, 129 - list.dense.items, 130 - }); 131 126 } 132 127 133 128 test "iter" { ··· 143 138 144 139 var iter = SliceIterator([]const u8).init(list.asSlice()); 145 140 146 - while (iter.next()) |item| { 147 - std.debug.print("{s} ", .{item}); 148 - } 149 - std.debug.print("\n", .{}); 141 + try std.testing.expectEqual("hello world", iter.next().?); 142 + try std.testing.expectEqual("it's a beautiful day", iter.next().?); 150 143 }
+11 -18
src/la.zig
··· 6 6 std.debug.assert(rows > 0); 7 7 std.debug.assert(columns > 0); 8 8 9 - // TODO: assert `T` is a number 10 - // const scalar_type_info = @typeInfo(T); 9 + { 10 + const t = @typeInfo(T); 11 + 12 + switch (t) { 13 + .int, .float => {}, 14 + else => @compileError("`T` should be float or int"), 15 + } 16 + } 11 17 12 18 return struct { 13 19 const Self = @This(); ··· 295 301 /// 4x4 matrix of `f64` 296 302 pub const Mat4D = Matrix(f64, 4, 4); 297 303 298 - // idk how the fuck i will, but add quaternions eventually. 304 + // TODO: idk how the fuck i will, but add quaternions eventually. 299 305 300 306 test "mul" { 301 307 const x = Matrix(f32, 3, 5).init(.{ ··· 347 353 } 348 354 349 355 test "large" { 350 - var timer = try std.time.Timer.start(); 351 356 const m = Matrix(f32, 10, 5).init(.{ 352 357 .{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 353 358 .{ 14, 13, 43, 5, 6, 8, 1, 9, 3, 4 }, ··· 359 364 for (0..1000000) |_| { 360 365 _ = m.mul(5); 361 366 } 362 - 363 - std.debug.print("{d}ms\n", .{timer.lap() / std.time.ns_per_ms}); 364 - } 365 - 366 - test "3x3" { 367 - const m = Matrix(f32, 3, 3).init(.{ 368 - .{ 1, 4, 7 }, 369 - .{ 2, 5, 8 }, 370 - .{ 3, 6, 9 }, 371 - }); 372 - 373 - std.debug.print("{any}\n", .{m.flatten()}); 374 - std.debug.print("{any}\n", .{m.mul(5.0).inner}); 375 367 } 376 368 377 369 test "unit" { ··· 417 409 418 410 const rm = m1.mul2(&m2); 419 411 420 - std.debug.print("{any}\n", .{rm.inner}); 412 + try std.testing.expectEqual(rm.inner[0], .{ 27, 30 }); 413 + try std.testing.expectEqual(rm.inner[1], .{ -35, 36 }); 421 414 }