Skip to content

Commit

Permalink
solves #393, clean up for newton-eigenLibraryInterface, modified #384
Browse files Browse the repository at this point in the history
…(after #383 and #372) to suit dimensionalMatrixKernelPrinter

Addresses #388.
  • Loading branch information
Siegfriedchao committed Jan 10, 2019
1 parent 4d5fa11 commit 4d31150
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/common/common-data-structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ struct Invariant
char *** canonicallyReorderedLabels;
int kernelColumnCount;
int numberOfUniqueKernels;
int numberOfUniqueKernelsReplace; // when #372 is done, rename numberOfUniqueKernels to numberOfTotalKernels, and rename this to numberOfUniqueKernels
int numberOfTotalKernels; // when #372 is done, rename numberOfUniqueKernels to numberOfTotalKernels, and rename this to numberOfUniqueKernels
int * permutedIndexArrayPointer;
int ** uniquePiGroup;
Invariant * next;
Expand Down
28 changes: 18 additions & 10 deletions src/newton/newton-eigenLibraryInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@ extern "C"
tempString = canonicallyReorderedLabels[countKernel][i];
canonicallyReorderedLabels[countKernel][i] = canonicallyReorderedLabels[countKernel][j];
canonicallyReorderedLabels[countKernel][j] = tempString;

int tempIndex;
tempIndex = permutedIndexArrayPointer[countKernel * dimensionalMatrixColumnCount + i];
permutedIndexArrayPointer[countKernel * dimensionalMatrixColumnCount + i]
= permutedIndexArrayPointer[countKernel * dimensionalMatrixColumnCount + j];
permutedIndexArrayPointer[countKernel * dimensionalMatrixColumnCount + j] = tempIndex;
}
}
}
Expand All @@ -684,7 +690,7 @@ extern "C"
{
/*
* NOTE: invariant->nullspace is stored as [kernel][row][column], whereas
* reorderedNullSpace and all that follow are [kernel][column][row]
* reorderedNullSpace and all that follows are [kernel][column][row]
*/
reorderedNullSpace[countKernel][countColumn][countRow] = nullSpace[countKernel][tmpPosition[countKernel][countRow]][countColumn];
}
Expand Down Expand Up @@ -738,8 +744,7 @@ extern "C"
newtonEigenLibraryInterfaceSortedCanonicallyReorderedPiGroups(double *** nullSpaceRowReordered,
char *** canonicallyReorderedLabels,
int kernelColumnCount, int dimensionalMatrixColumnCount,
int * numberOfUniqueKernels,
int * permutedIndexArrayPointer)
int * numberOfUniqueKernels)
{
/*
* We create the matrices in Eigen by mapping the elements
Expand Down Expand Up @@ -830,6 +835,7 @@ extern "C"
tempString = string[countKernel][i];
string[countKernel][i] = string[countKernel][j];
string[countKernel][j] = tempString;

}
}
}
Expand Down Expand Up @@ -861,7 +867,8 @@ extern "C"
newtonEigenLibraryInterfaceWeedOutDuplicatePiGroups(double *** nullSpaceCanonicallyReordered,
int kernelColumnCount,
int dimensionalMatrixColumnCount,
int * numberOfUniqueKernels)
int * numberOfUniqueKernels,
int * numberOfTotalKernels)
{
/*
* We create the matrices in Eigen by mapping the elements
Expand All @@ -882,20 +889,21 @@ extern "C"
eigenInterfaceReorderKernels[countKernel] = temp;
}

*numberOfTotalKernels = *numberOfUniqueKernels;

int kernelToBeDeprecatedCount = 0;
int totalNumberOfKernelsCount = *numberOfUniqueKernels;
int * kernelToBeDeprecated = (int *)calloc(totalNumberOfKernelsCount, sizeof(int));
int * kernelToBeDeprecated = (int *)calloc(*numberOfTotalKernels, sizeof(int));
bool isSearchedPreviously = false;

for (int k = 0; k < totalNumberOfKernelsCount; k++)
for (int k = 0; k < *numberOfTotalKernels; k++)
{
/*
* Initiate the kernelToBeDeprecated array
*/
kernelToBeDeprecated[k] = -1;
}

for (int i = 0; i < (totalNumberOfKernelsCount - 1); i++)
for (int i = 0; i < (*numberOfTotalKernels - 1); i++)
{
if(i > 0 && kernelToBeDeprecatedCount > 0)
{
Expand All @@ -914,7 +922,7 @@ extern "C"
}
}

for (int j = i + 1; j < totalNumberOfKernelsCount; j++)
for (int j = i + 1; j < *numberOfTotalKernels; j++)
{
/*
* We subtract the two kernels, element-wise, to see
Expand All @@ -939,7 +947,7 @@ extern "C"
int reorderedKernelCount = 0;
kernelToBeDeprecatedCount = 0;

for (int countKernel = 0; countKernel < totalNumberOfKernelsCount; countKernel++)
for (int countKernel = 0; countKernel < *numberOfTotalKernels; countKernel++)
{
if(countKernel == kernelToBeDeprecated[kernelToBeDeprecatedCount])
{
Expand Down
6 changes: 3 additions & 3 deletions src/newton/newton-eigenLibraryInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ double *** newtonEigenLibraryInterfaceSortedCanonicallyReorderedPiGroups(double
char *** canonicallyReorderedLabels,
int kernelColumnCount,
int dimensionalMatrixColumnCount,
int * numberOfUniqueKernels,
int ** permutedIndexArrayPointer);
int * numberOfUniqueKernels);
double *** newtonEigenLibraryInterfaceWeedOutDuplicatePiGroups(double *** sortedCanonicallyReorderedNullSpace,
int kernelColumnCount,
int dimensionalMatrixColumnCount,
int * numberOfUniqueKernels);
int * numberOfUniqueKernels,
int * numberOfTotalKernels);

# ifdef __cplusplus
} /* extern "C" */
Expand Down
3 changes: 1 addition & 2 deletions src/newton/newton-irPass-dimensionalMatrixPiGroupSorted.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ irPassDimensionalMatrixPiGroupSorted(State * N)
invariant->canonicallyReorderedLabels,
invariant->kernelColumnCount,
invariant->dimensionalMatrixColumnCount,
&invariant->numberOfUniqueKernels,
&invariant->permutedIndexArrayPointer);
&invariant->numberOfUniqueKernels);
invariant = invariant->next;
}
}
24 changes: 23 additions & 1 deletion src/newton/newton-irPass-dimensionalMatrixPiGroupWeedOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,29 @@ irPassDimensionalMatrixPiGroupsWeedOutDuplicates(State * N)
invariant->nullSpaceWithoutDuplicates = newtonEigenLibraryInterfaceWeedOutDuplicatePiGroups(invariant->nullSpaceCanonicallyReordered,
invariant->kernelColumnCount,
invariant->dimensionalMatrixColumnCount,
&invariant->numberOfUniqueKernels);
&invariant->numberOfUniqueKernels,
&invariant->numberOfTotalKernels);

/*
* In order to reuse irPass-dimensionalMatrixKernelPrinter
* the following changes need to be made accordingly:
* (1) Reset invariant->nullSpace
*/

for (int countKernel = 0; countKernel < invariant->numberOfUniqueKernels; countKernel++)
{
for (int countRow = 0; countRow < invariant->dimensionalMatrixColumnCount; countRow++)
{
for (int countColumn = 0; countColumn < invariant->kernelColumnCount; countColumn++)
{
/*
* NOTE: invariant->nullspace is stored as [kernel][row][column], whereas
* reorderedNullSpace and all that follows are [kernel][column][row]
*/
invariant->nullSpace[countKernel][countRow][countColumn] = invariant->nullSpaceWithoutDuplicates[countKernel][countColumn][countRow];
}
}
}

invariant = invariant->next;
}
Expand Down
2 changes: 1 addition & 1 deletion src/newton/newton.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ processNewtonFile(State * N, char * filename)
{
irPassDimensionalMatrixAnnotation(N);
irPassDimensionalMatrixPiGroups(N);
irPassDimensionalMatrixKernelPrinter(N);
irPassDimensionalMatrixKernelRowCanonicalization(N);
irPassDimensionalMatrixPiGroupSorted(N);
irPassDimensionalMatrixPiGroupsWeedOutDuplicates(N);
irPassDimensionalMatrixKernelPrinter(N);
irPassDimensionalMatrixConvertToList(N);
}

Expand Down

0 comments on commit 4d31150

Please sign in to comment.