Skip to content

Commit 5d8b30b

Browse files
author
Adrià Arrufat
committed
Matrix: simplify seed and enforce square trace
1 parent 5a9cba5 commit 5d8b30b

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/matrix.zig

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ pub fn Matrix(comptime T: type, comptime rows: usize, comptime cols: usize) type
4141

4242
/// Returns a matrix filled with random numbers.
4343
pub fn random(seed: ?u64) Self {
44-
const s: u64 = blk: {
45-
if (seed) |value| {
46-
break :blk value;
47-
} else {
48-
break :blk @truncate(@as(u128, @bitCast(std.time.nanoTimestamp())));
49-
}
50-
};
44+
const s: u64 = seed orelse @truncate(@as(u128, @bitCast(std.time.nanoTimestamp())));
5145
var prng = std.rand.DefaultPrng.init(s);
5246
var rand = prng.random();
5347
var self = Self{};
@@ -112,7 +106,7 @@ pub fn Matrix(comptime T: type, comptime rows: usize, comptime cols: usize) type
112106

113107
/// Computes the trace (i.e. sum of the diagonal elements).
114108
pub fn trace(self: Self) T {
115-
assert(self.cols == self.rows);
109+
comptime assert(self.cols == self.rows);
116110
var val: T = 0;
117111
for (0..self.cols) |i| {
118112
val += self.items[i][i];

0 commit comments

Comments
 (0)