fix: cayleyTransform memory addressing problem due to int/double pointer cast.
This commit is contained in:
parent
e2034c9ff6
commit
8761407cad
|
@ -942,11 +942,16 @@ mat* cayleyTransform(mat *A, mat *B, mat *C, double *workMem) {
|
||||||
/* Allocate row permutation array used by `dgesv` */
|
/* Allocate row permutation array used by `dgesv` */
|
||||||
int *ipiv = (int*)workMem;
|
int *ipiv = (int*)workMem;
|
||||||
|
|
||||||
|
/* NOTE: workMem offset, NOT ipiv offset! There may be a bit space left out
|
||||||
|
* but the working memory is required elsewhere anyway. It's impotant to
|
||||||
|
* have an appropriate beginning cause if may occure the case that the
|
||||||
|
* memory addressing faily due to size differences between int and double
|
||||||
|
* leading to an illegal double* address. */
|
||||||
|
double *IpA = workMem + A->nrow;
|
||||||
/* Create Matrix IpA = I + A (I plus A) */
|
/* Create Matrix IpA = I + A (I plus A) */
|
||||||
double *IpA = (double*)(ipiv + A->nrow);
|
|
||||||
memcpy(IpA, A->elem, A->nrow * A->ncol * sizeof(double));
|
memcpy(IpA, A->elem, A->nrow * A->ncol * sizeof(double));
|
||||||
for (i = 0; i < pp; i += A->nrow + 1) {
|
for (i = 0; i < pp; i += A->nrow + 1) {
|
||||||
IpA[i] += 1.; // +1 to diagonal elements.
|
IpA[i] += 1.0; // +1 to diagonal elements.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create Matrix ImA = I - A (I minus A) */
|
/* Create Matrix ImA = I - A (I minus A) */
|
||||||
|
|
Loading…
Reference in New Issue