matrix_features #2

Merged
omicron merged 2 commits from matrix_features into main 2025-05-19 21:19:21 +00:00
2 changed files with 28 additions and 0 deletions
Showing only changes of commit 35e848ec43 - Show all commits

View File

@@ -283,3 +283,13 @@ func (m *Matrix[T]) HadamardMultiply(matrices ...*Matrix[T]) *Matrix[T] {
m.values = values m.values = values
return m return m
} }
// Fill sets all components of this matrix to the given value. Returns the receiver.
func (m *Matrix[T]) Fill(value T) *Matrix[T] {
for i := range m.rows {
for j := range m.cols {
m.values[i][j] = value
}
}
return m
}

View File

@@ -475,3 +475,21 @@ func TestHadamardProduct(t *testing.T) {
matrix.HadamardProduct(a, d) matrix.HadamardProduct(a, d)
}) })
} }
func TestMatrix_Fill(t *testing.T) {
a := matrix.Create[int](2, 3)
assert.Equal(t, 0, a.Get(0, 0))
assert.Equal(t, 0, a.Get(0, 1))
assert.Equal(t, 0, a.Get(0, 2))
assert.Equal(t, 0, a.Get(1, 0))
assert.Equal(t, 0, a.Get(1, 1))
assert.Equal(t, 0, a.Get(1, 2))
a.Fill(3)
assert.Equal(t, 3, a.Get(0, 0))
assert.Equal(t, 3, a.Get(0, 1))
assert.Equal(t, 3, a.Get(0, 2))
assert.Equal(t, 3, a.Get(1, 0))
assert.Equal(t, 3, a.Get(1, 1))
assert.Equal(t, 3, a.Get(1, 2))
}