Calc fix and 2d functions.
This commit is contained in:
@@ -1,4 +1,72 @@
|
||||
#include <iostream>
|
||||
#include "Function.h"
|
||||
#include "Function2D.h"
|
||||
#include "mkl.h"
|
||||
|
||||
double Aurora::immse(const Aurora::Matrix &aImageA, const Aurora::Matrix &aImageB) {
|
||||
if (aImageA.getDims()!=2|| aImageB.getDims()!=2){
|
||||
std::cerr<<"Fail!immse args must all 2d matrix!";
|
||||
return 0.0;
|
||||
}
|
||||
if (!aImageB.compareShape(aImageA)){
|
||||
std::cerr<<"Fail!immse args must be same shape!";
|
||||
return 0.0;
|
||||
}
|
||||
if (aImageA.getValueType()!=Normal || aImageB.getValueType() != Normal) {
|
||||
std::cerr << "Fail!immse args must be normal value type!";
|
||||
return 0.0;
|
||||
}
|
||||
int size = aImageA.getDataSize();
|
||||
auto temp = malloc(size);
|
||||
vdSub(size, aImageA.getData(), aImageB.getData(), temp);
|
||||
vdSqr(size, temp, temp);
|
||||
double result = cblas_dasum(size, temp, 1) / (double) size;
|
||||
free(temp);
|
||||
return result;
|
||||
}
|
||||
|
||||
Aurora::Matrix Aurora::inv(const Aurora::Matrix &aMatrix) {
|
||||
if (aMatrix.getDims() != 2) {
|
||||
std::cerr << "Fail!inv args must be 2d matrix!";
|
||||
return aMatrix;
|
||||
}
|
||||
if (aMatrix.getDimSize(0) != aMatrix.getDimSize(1)) {
|
||||
std::cerr << "Fail!inv args must be square matrix!";
|
||||
return aMatrix;
|
||||
}
|
||||
if (aMatrix.getValueType() != Normal) {
|
||||
std::cerr << "Fail!inv args must be normal value type!";
|
||||
return aMatrix;
|
||||
}
|
||||
int size = aMatrix.getDataSize();
|
||||
int *ipiv = new int[aMatrix.getDimSize(0)];
|
||||
auto result = malloc(size);
|
||||
cblas_dcopy(size,result, 1,aMatrix.getData(), 1);
|
||||
LAPACKE_dgetrf(LAPACK_ROW_MAJOR, aMatrix.getDimSize(0), aMatrix.getDimSize(0), result, aMatrix.getDimSize(0), ipiv);
|
||||
LAPACKE_dgetri(LAPACK_ROW_MAJOR, aMatrix.getDimSize(0), result, aMatrix.getDimSize(0), ipiv);
|
||||
delete[] ipiv;
|
||||
return Matrix::New(result,aMatrix);
|
||||
}
|
||||
|
||||
Aurora::Matrix Aurora::inv(Aurora::Matrix&& aMatrix) {
|
||||
if (aMatrix.getDims() != 2) {
|
||||
std::cerr << "Fail!inv args must be 2d matrix!";
|
||||
return aMatrix;
|
||||
}
|
||||
if (aMatrix.getDimSize(0) != aMatrix.getDimSize(1)) {
|
||||
std::cerr << "Fail!inv args must be square matrix!";
|
||||
return aMatrix;
|
||||
}
|
||||
if (aMatrix.getValueType() != Normal) {
|
||||
std::cerr << "Fail!inv args must be normal value type!";
|
||||
return aMatrix;
|
||||
}
|
||||
int *ipiv = new int[aMatrix.getDimSize(0)];
|
||||
LAPACKE_dgetrf(LAPACK_ROW_MAJOR, aMatrix.getDimSize(0), aMatrix.getDimSize(0), aMatrix.getData(), aMatrix.getDimSize(0), ipiv);
|
||||
LAPACKE_dgetri(LAPACK_ROW_MAJOR, aMatrix.getDimSize(0), aMatrix.getData(), aMatrix.getDimSize(0), ipiv);
|
||||
delete[] ipiv;
|
||||
return aMatrix;
|
||||
}
|
||||
#include "Function1D.h"
|
||||
#include "Function.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user