Ejemplo n.º 1
0
	/*
		Substraction. Throw exception if their dimensions don't match.
	*/
	Mat operator -(const Mat& rhs){
		if (rhs.get_n()!=n || rhs.get_m()!=m){
			throw invalid_argument("Matrix dimensions are not consistent when trying '+' two matrices");
			return Mat();
		}
		Mat res = Mat(*this);
		for (int i=0; i<res.get_n(); i++){
			for (int j=0; j<res.get_m(); j++)
				res[i][j] -= rhs.get(i, j);
		}
		return res;
	}
Ejemplo n.º 2
0
	/*
		Return a matrix which is the elementwise square.
	*/
	Mat Sqr(){
		Mat res = Mat(*this);
		for (int i=0; i<res.get_n(); i++)
			for (int j=0; j<res.get_m(); j++)
				res[i][j] = res[i][j]*res[i][j];
		return res;
	}
Ejemplo n.º 3
0
	/*
		Multiply by a number.
	*/
	Mat operator *(const double& mult){
		Mat res = Mat(*this);
		for (int i=0; i<res.get_n(); i++){
			for (int j=0; j<res.get_m(); j++)
				res[i][j] *= mult;
		}
		return res;
	}
Ejemplo n.º 4
0
	/*
		Copy constructor. Deep copy.
	*/
	Mat(const Mat &cp){
		InitMat(cp.get_n(),cp.get_m());
		for (int i=0; i<n; i++)
			for (int j=0; j<m; j++)
				arr[i][j] = cp.get(i,j);
	}