diff options
author | Andrii Riabushenko <cdome@bk.ru> | 2018-12-09 18:32:43 +0000 |
---|---|---|
committer | Andrii Riabushenko <cdome@bk.ru> | 2018-12-09 18:32:43 +0000 |
commit | dc935f2b4115332d440421485e75189d7b9c7c9e (patch) | |
tree | 12e0133c8add2824eae95775e54c03aa549594cb /tests/destructor | |
parent | a50cfbf81414db53bb3f8e0e9b8a44950a8c79e1 (diff) | |
download | Nim-dc935f2b4115332d440421485e75189d7b9c7c9e.tar.gz |
use control flow graph for sink params
Diffstat (limited to 'tests/destructor')
-rw-r--r-- | tests/destructor/tmatrix.nim | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/destructor/tmatrix.nim b/tests/destructor/tmatrix.nim index 6ae38fc29..b89b41a4c 100644 --- a/tests/destructor/tmatrix.nim +++ b/tests/destructor/tmatrix.nim @@ -52,6 +52,8 @@ proc matrix*(m, n: int, s: float): Matrix = for i in 0 ..< m * n: result.data[i] = s +proc len(m: Matrix): int = m.n * m.m + proc `[]`*(m: Matrix, i, j: int): float {.inline.} = ## Get a single element. m.data[i * m.n + j] @@ -73,7 +75,8 @@ proc `-`*(m: sink Matrix): Matrix = proc `+`*(a: sink Matrix; b: Matrix): Matrix = ## ``C = A + B`` - assert(b.m == a.m and b.n == a.n, "Matrix dimensions must agree.") + doAssert(b.m == a.m and b.n == a.n, "Matrix dimensions must agree.") + doAssert(a.len == b.len) # non destructive use before sink is ok result = a for i in 0 ..< result.m: for j in 0 ..< result.n: @@ -82,9 +85,10 @@ proc `+`*(a: sink Matrix; b: Matrix): Matrix = proc `-`*(a: sink Matrix; b: Matrix): Matrix = ## ``C = A - B`` assert(b.m == a.m and b.n == a.n, "Matrix dimensions must agree.") + doAssert(a.len == b.len) # non destructive use before sink is ok result = a - for i in 0 ..< a.m: - for j in 0 ..< a.n: + for i in 0 ..< result.m: + for j in 0 ..< result.n: result[i, j] = a[i, j] - b[i, j] proc info = |