From eea6b59973df774a7d7fe6e8ce27bba47c304217 Mon Sep 17 00:00:00 2001 From: Oskar Weigl Date: Mon, 4 Mar 2019 21:32:26 -0800 Subject: [PATCH] Implement slice as copy loop --- matrix/Matrix.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/matrix/Matrix.hpp b/matrix/Matrix.hpp index 7cbc5ea753..70bcea5ef7 100644 --- a/matrix/Matrix.hpp +++ b/matrix/Matrix.hpp @@ -355,7 +355,13 @@ public: template Matrix slice(size_t x0, size_t y0) const { - Matrix res(&(_data[x0][y0])); + Matrix &self = *this; + Matrix res; //default constructed + for (size_t i = 0; i < P; i++) { + for (size_t j = 0; j < Q; j++) { + res(i, j) = self(i + x0, j + y0); + } + } return res; }