Skip to content

Commit

Permalink
Matrix: rename setAll to initAll
Browse files Browse the repository at this point in the history
  • Loading branch information
arrufat committed Apr 15, 2024
1 parent f079cd5 commit 16368ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/matrix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn Matrix(comptime T: type, comptime rows: usize, comptime cols: usize) type
items: [rows][cols]T = undefined,

/// Sets all elements to value.
pub fn setAll(value: T) Self {
pub fn initAll(value: T) Self {
var self = Self{};
for (&self.items) |*row| {
for (row) |*col| {
Expand Down Expand Up @@ -236,7 +236,7 @@ pub fn Matrix(comptime T: type, comptime rows: usize, comptime cols: usize) type
/// Performs the dot (or internal product) of two matrices.
pub fn dot(self: Self, other: anytype) Matrix(T, self.rows, other.cols) {
comptime assert(self.cols == other.rows);
var result = Matrix(T, self.rows, other.cols).setAll(0);
var result = Matrix(T, self.rows, other.cols).initAll(0);
for (0..self.rows) |r| {
for (0..other.cols) |c| {
for (0..self.cols) |k| {
Expand Down Expand Up @@ -291,10 +291,10 @@ test "identity" {
}
}

test "setAll" {
const zeros = Matrix(f32, 3, 3).setAll(0);
test "initAll" {
const zeros = Matrix(f32, 3, 3).initAll(0);
try expectEqual(zeros.sum(), 0);
const ones = Matrix(f32, 3, 3).setAll(1);
const ones = Matrix(f32, 3, 3).initAll(1);
const shape = ones.shape();
try expectEqual(ones.sum(), @as(f32, @floatFromInt(shape[0] * shape[1])));
}
Expand Down
2 changes: 1 addition & 1 deletion src/svd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ test "svd" {
const u: *const Matrix(f64, m, m) = &res[0];
const q: *const Matrix(f64, n, 1) = &res[1];
const v: *const Matrix(f64, n, n) = &res[2];
var w = Matrix(f64, m, n).setAll(0);
var w = Matrix(f64, m, n).initAll(0);
// build the diagonal matrix from q.
for (0..q.rows) |i| {
w.items[i][i] = q.at(i, 0);
Expand Down

0 comments on commit 16368ea

Please sign in to comment.