MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / IsValid

Function IsValid

math/matrix/isvalid.go:6–17  ·  view source on GitHub ↗

IsValid checks if the input matrix has consistent row lengths.

(elements [][]T)

Source from the content-addressed store, hash-verified

4
5// IsValid checks if the input matrix has consistent row lengths.
6func IsValid[T constraints.Integer](elements [][]T) bool {
7 if len(elements) == 0 {
8 return true
9 }
10 columns := len(elements[0])
11 for _, row := range elements {
12 if len(row) != columns {
13 return false
14 }
15 }
16 return true
17}

Callers 3

TestIsValidFunction · 0.92
BenchmarkIsValidFunction · 0.92
NewFromElementsFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestIsValidFunction · 0.74
BenchmarkIsValidFunction · 0.74