Skip to content

Commit

Permalink
removed unnecessary malloc and multiplication with identity matrix in…
Browse files Browse the repository at this point in the history
… invertLsMtx2D/3D. Thank you jinnsjj
  • Loading branch information
leomccormack committed Jul 27, 2021
1 parent cc55bc9 commit d94a426
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions framework/modules/saf_vbap/saf_vbap.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,10 @@ void invertLsMtx3D
)
{
int i, j, n;
float* tempGroup;
float tempInv[9], eye3[9];
float tempGroup[9];
float tempInv[9];
void* hSinv;

for(i=0; i<3; i++)
for(j=0; j<3; j++)
eye3[i*3+j] = i==j ? 1.0f : 0.0f;
tempGroup = malloc1d(9* sizeof(float));

/* pre-calculate inversions of the loudspeaker groups and store into matrix */
(*layoutInvMtx) = malloc1d(N_group * 9 * sizeof(float));
utility_sinv_create(&hSinv, 3);
Expand All @@ -700,18 +695,13 @@ void invertLsMtx3D
tempGroup[j*3+i] = U_spkr[ls_groups[n*3+i]*3 + j];

/* get inverse of current group */
utility_sinv(hSinv, tempGroup,tempGroup,3);
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, 3, 3, 3, 1.0f,
(float*)eye3, 3,
tempGroup, 3, 0.0f,
(float*)tempInv, 3);
utility_sinv(hSinv, tempGroup, tempInv, 3);

/* store the vectorized inverse as a row the output */
for(i=0; i<3; i++)
for(j=0; j<3; j++)
(*layoutInvMtx)[n*9+(i*3+j)] = tempInv[j*3+i];
}
free(tempGroup);
utility_sinv_destroy(&hSinv);
}

Expand Down Expand Up @@ -947,15 +937,10 @@ void invertLsMtx2D
)
{
int i, j, n;
float* tempGroup;
float tempInv[4], eye2[4];
float tempGroup[4];
float tempInv[4];
void* hSinv;

for(i=0; i<2; i++)
for(j=0; j<2; j++)
eye2[i*2+j] = i==j ? 1.0f : 0.0f;
tempGroup = malloc1d(4* sizeof(float));

/* pre-calculate inversions of the loudspeaker groups and store into matrix */
(*layoutInvMtx) = malloc1d(N_pairs * 4 * sizeof(float));
utility_sinv_create(&hSinv, 2);
Expand All @@ -966,19 +951,14 @@ void invertLsMtx2D
tempGroup[j*2+i] = U_spkr[ls_pairs[n*2+i]*2 + j];

/* get inverse of current group */
utility_sinv(hSinv, tempGroup,tempGroup,2);
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, 2, 2, 2, 1.0,
eye2, 2,
tempGroup, 2, 0.0,
tempInv, 2);
utility_sinv(hSinv, tempGroup, tempInv, 2);

/* store the vectorized inverse as a row the output */
for(i=0; i<2; i++)
for(j=0; j<2; j++)
(*layoutInvMtx)[n*4+(i*2+j)] = tempInv[j*2+i];
}

free(tempGroup);
utility_sinv_destroy(&hSinv);
}

Expand Down

0 comments on commit d94a426

Please sign in to comment.