From c96778830211d99cab44c60126a91ac91c47b905 Mon Sep 17 00:00:00 2001 From: kradchen Date: Fri, 5 May 2023 11:00:58 +0800 Subject: [PATCH] Add isVector and fix isScalar function to Matrix. --- src/Matrix.cpp | 10 +++++++++- src/Matrix.h | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Matrix.cpp b/src/Matrix.cpp index 2afd276..1bcfb04 100644 --- a/src/Matrix.cpp +++ b/src/Matrix.cpp @@ -255,14 +255,22 @@ namespace Aurora { bool Matrix::isScalar() const { return (getDimSize(0) == 1 && getDimSize(1) == 1 && - getDimSize(1)); + getDimSize(2) < 2); } + double Matrix::getScalar() const { if (isNull()) return 0.0; if (isNull()) return 0.0; return getData()[0]; } + bool Matrix::isVector() const{ + if (getDimSize(2)>1) return false; + if (isScalar) return false; + return getDimSize(0) == 1 || + getDimSize(1) == 1; + } + int Matrix::getDims() const { if(mInfo[2] > 1) { diff --git a/src/Matrix.h b/src/Matrix.h index 9d4d1e1..3edf183 100644 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -178,6 +178,8 @@ namespace Aurora { */ bool isNull() const; + bool isVector() const; + /** * Get dimension count of the matrix * @return dimension count