first trial of obilandmark

Former-commit-id: 00a50bdbf407b03dfdc385a848a536559f5966a5
This commit is contained in:
2023-08-25 23:23:23 +02:00
parent 2a11adb346
commit 077f3b5bb5
5 changed files with 388 additions and 0 deletions

View File

@ -22,6 +22,17 @@ func Make2DArray[T any](rows, cols int) Matrix[T] {
return matrix
}
// Init initializes the Matrix with the given value.
//
// value: the value to initialize the Matrix elements with.
func (matrix *Matrix[T]) Init(value T) {
data := (*matrix)[0]
data = data[0:cap(data)]
for i := range data {
data[i] = value
}
}
// Row returns the i-th row of the matrix.
//
// Parameters:
@ -38,3 +49,11 @@ func (matrix *Matrix[T]) Column(i int) []T {
}
return r
}
// Dim returns the dimensions of the Matrix.
//
// It takes no parameters.
// It returns two integers: the number of rows and the number of columns.
func (matrix *Matrix[T]) Dim() (int, int) {
return len(*matrix), len((*matrix)[0])
}