Add isVector and fix isScalar function to Matrix.

This commit is contained in:
kradchen
2023-05-05 11:00:58 +08:00
parent fbb61d15d0
commit c967788302
2 changed files with 11 additions and 1 deletions

View File

@@ -255,14 +255,22 @@ namespace Aurora {
bool Matrix::isScalar() const { bool Matrix::isScalar() const {
return (getDimSize(0) == 1 && return (getDimSize(0) == 1 &&
getDimSize(1) == 1 && getDimSize(1) == 1 &&
getDimSize(1)); getDimSize(2) < 2);
} }
double Matrix::getScalar() const { double Matrix::getScalar() const {
if (isNull()) return 0.0; if (isNull()) return 0.0;
if (isNull()) return 0.0; if (isNull()) return 0.0;
return getData()[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 { int Matrix::getDims() const {
if(mInfo[2] > 1) if(mInfo[2] > 1)
{ {

View File

@@ -178,6 +178,8 @@ namespace Aurora {
*/ */
bool isNull() const; bool isNull() const;
bool isVector() const;
/** /**
* Get dimension count of the matrix * Get dimension count of the matrix
* @return dimension count * @return dimension count