import math, sequtils, strutils type Matrix = seq[seq[float]] template rows(m: Matrix): Positive = m.len template cols(m: Matrix): Positive = m[0].len func `+`(m1, m2: Matrix): Matrix = doAssert m1.rows == m2.rows and m1.cols == m2.cols, "Matrices must have the same dimensions." result = newSeqWith(m1.rows, newSeq[float](m1.cols)) for i in 0..