From 763ed1aab88a83df9fd2f45d23b3705c7317da4a Mon Sep 17 00:00:00 2001 From: conrad Date: Wed, 2 Aug 2017 12:34:02 +1000 Subject: [PATCH] take into account non-square matrices --- include/armadillo_bits/SpMat_meat.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/armadillo_bits/SpMat_meat.hpp b/include/armadillo_bits/SpMat_meat.hpp index 3bcee862..914e5f73 100644 --- a/include/armadillo_bits/SpMat_meat.hpp +++ b/include/armadillo_bits/SpMat_meat.hpp @@ -3392,6 +3392,12 @@ SpMat::eye(const uword in_rows, const uword in_cols) for(uword i = 0; i <= N; ++i) { access::rw(col_ptrs[i]) = i; } + // take into account non-square matrices + for(uword i = (N+1); i <= in_cols; ++i) + { + access::rw(col_ptrs[i]) += col_ptrs[i - 1]; + } + access::rw(n_nonzero) = N; return *this;