Cppcheck: some fixes

This commit is contained in:
heckflosse
2016-10-17 18:49:15 +02:00
parent ed42b1239c
commit 8df2df664f
9 changed files with 40 additions and 49 deletions

View File

@@ -17,20 +17,20 @@ calculates A x where x is some vector. Stops when rms residual < RMSResidual or
Stops at n iterates if MaximumIterates = 0 since that many iterates gives exact solution. Applicable to symmetric positive
definite problems only, which is what unconstrained smooth optimization pretty much always is.
Parameter pass can be passed through, containing whatever info you like it to contain (matrix info?).
Takes less memory with OkToModify_b = true, and Preconditioner = NULL. */
Takes less memory with OkToModify_b = true, and Preconditioner = nullptr. */
float *SparseConjugateGradient(void Ax(float *Product, float *x, void *Pass), float *b, int n, bool OkToModify_b,
float *x, float RMSResidual, void *Pass, int MaximumIterates, void Preconditioner(float *Product, float *x, void *Pass))
{
int iterate, i;
char* buffer = (char*)malloc(2 * n * sizeof(float) + 128);
float *r = (float*)(buffer + 64);
float* buffer = (float*)malloc(2 * n * sizeof(float) + 128);
float *r = (buffer + 16);
//Start r and x.
if(x == NULL) {
if(x == nullptr) {
x = new float[n];
memset(x, 0, sizeof(float)*n); //Zero initial guess if x == NULL.
memset(x, 0, sizeof(float)*n); //Zero initial guess if x == nullptr.
memcpy(r, b, sizeof(float)*n);
} else {
Ax(r, x, Pass);
@@ -46,7 +46,7 @@ float *SparseConjugateGradient(void Ax(float *Product, float *x, void *Pass), fl
//s is preconditionment of r. Without, direct to r.
float *s = r, rs = 0.0f;
if(Preconditioner != NULL) {
if(Preconditioner != nullptr) {
s = new float[n];
Preconditioner(s, r, Pass);
@@ -61,7 +61,7 @@ float *SparseConjugateGradient(void Ax(float *Product, float *x, void *Pass), fl
}
//Search direction d.
float *d = (float*)(buffer + n * sizeof(float) + 128);
float *d = (buffer + n + 32);
memcpy(d, s, sizeof(float)*n);
@@ -114,7 +114,7 @@ float *SparseConjugateGradient(void Ax(float *Product, float *x, void *Pass), fl
break;
}
if(Preconditioner != NULL) {
if(Preconditioner != nullptr) {
Preconditioner(s, r, Pass);
}
@@ -185,7 +185,7 @@ MultiDiagonalSymmetricMatrix::MultiDiagonalSymmetricMatrix(int Dimension, int Nu
{
n = Dimension;
m = NumberOfDiagonalsInLowerTriangle;
IncompleteCholeskyFactorization = NULL;
IncompleteCholeskyFactorization = nullptr;
Diagonals = new float *[m];
StartRows = new int [m + 1];
@@ -196,7 +196,7 @@ MultiDiagonalSymmetricMatrix::MultiDiagonalSymmetricMatrix(int Dimension, int Nu
MultiDiagonalSymmetricMatrix::~MultiDiagonalSymmetricMatrix()
{
if(DiagBuffer != NULL) {
if(DiagBuffer != nullptr) {
free(buffer);
} else
for(int i = 0; i < m; i++) {
@@ -216,12 +216,12 @@ bool MultiDiagonalSymmetricMatrix::CreateDiagonal(int index, int StartRow)
if(index == 0) {
buffer = (char*)calloc( (n + padding) * m * sizeof(float) + (m + 16) * 64 + 63, 1);
if(buffer == NULL)
if(buffer == nullptr)
// no big memory block available => try to allocate smaller blocks
{
DiagBuffer = NULL;
DiagBuffer = nullptr;
} else {
DiagBuffer = (char*)( ( uintptr_t(buffer) + uintptr_t(63)) / 64 * 64);
DiagBuffer = (float*)( ( uintptr_t(buffer) + uintptr_t(63)) / 64 * 64);
}
}
@@ -236,12 +236,12 @@ bool MultiDiagonalSymmetricMatrix::CreateDiagonal(int index, int StartRow)
return false;
}
if(DiagBuffer != NULL) {
Diagonals[index] = (float*)(DiagBuffer + (index * (n + padding) * sizeof(float)) + ((index + 16) * 64));
if(DiagBuffer != nullptr) {
Diagonals[index] = (DiagBuffer + (index * (n + padding)) + ((index + 16) * 16));
} else {
Diagonals[index] = new float[DiagonalLength(StartRow)];
if(Diagonals[index] == NULL) {
if(Diagonals[index] == nullptr) {
printf("Error in MultiDiagonalSymmetricMatrix::CreateDiagonal: memory allocation failed. Out of memory?\n");
return false;
}
@@ -673,7 +673,7 @@ EdgePreservingDecomposition::EdgePreservingDecomposition(int width, int height)
A->CreateDiagonal(3, w) &&
A->CreateDiagonal(4, w + 1))) {
delete A;
A = NULL;
A = nullptr;
printf("Error in EdgePreservingDecomposition construction: out of memory.\n");
} else {
a0 = A->Diagonals[0];
@@ -692,7 +692,7 @@ EdgePreservingDecomposition::~EdgePreservingDecomposition()
SSEFUNCTION float *EdgePreservingDecomposition::CreateBlur(float *Source, float Scale, float EdgeStopping, int Iterates, float *Blur, bool UseBlurForEdgeStop)
{
if(Blur == NULL)
if(Blur == nullptr)
UseBlurForEdgeStop = false, //Use source if there's no supplied Blur.
Blur = new float[n];
@@ -864,7 +864,7 @@ float *EdgePreservingDecomposition::CreateIteratedBlur(float *Source, float Scal
}
//Create a blur here, initialize.
if(Blur == NULL) {
if(Blur == nullptr) {
Blur = new float[n];
}
@@ -923,7 +923,7 @@ SSEFUNCTION float *EdgePreservingDecomposition::CompressDynamicRange(float *Sour
//Blur. Also setup memory for Compressed (we can just use u since each element of u is used in one calculation).
float *u = CreateIteratedBlur(Source, Scale, EdgeStopping, Iterates, Reweightings);
if(Compressed == NULL) {
if(Compressed == nullptr) {
Compressed = u;
}