Double sink checks
This commit is contained in:
parent
e5b9d89bcf
commit
ae24b87219
2 changed files with 65 additions and 13 deletions
|
|
@ -67,17 +67,17 @@ proc `[]=`*(m: var Matrix, i, j: int, s: float) =
|
|||
proc `-`*(m: sink Matrix): Matrix =
|
||||
## Unary minus
|
||||
result = m
|
||||
for i in 0 ..< m.m:
|
||||
for j in 0 ..< m.n:
|
||||
result[i, j] = -m[i, j]
|
||||
for i in 0 ..< result.m:
|
||||
for j in 0 ..< result.n:
|
||||
result[i, j] = -result[i, j]
|
||||
|
||||
proc `+`*(a: sink Matrix; b: Matrix): Matrix =
|
||||
## ``C = A + B``
|
||||
assert(b.m == a.m and b.n == a.n, "Matrix dimensions must agree.")
|
||||
result = a
|
||||
for i in 0 ..< a.m:
|
||||
for j in 0 ..< a.n:
|
||||
result[i, j] = a[i, j] + b[i, j]
|
||||
for i in 0 ..< result.m:
|
||||
for j in 0 ..< result.n:
|
||||
result[i, j] = result[i, j] + b[i, j]
|
||||
|
||||
proc `-`*(a: sink Matrix; b: Matrix): Matrix =
|
||||
## ``C = A - B``
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue