diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..1e25605 --- /dev/null +++ b/.clang-format @@ -0,0 +1,68 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: Consecutive +AlignConsecutiveDeclarations: Consecutive +AlignConsecutiveMacros: Consecutive +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: BeforeHash +IndentWidth: 4 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Left +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never \ No newline at end of file diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 0000000..5b4ca60 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,29 @@ +name: Clang Format + +on: + push: + branches: [ master ] + paths: + - '.github/**' + - 'cubool/**' + - '.clang-format' + pull_request: + branches: [ master ] + +jobs: + formatting-check: + name: Formatting Check + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + path: + - 'cubool' + steps: + - uses: actions/checkout@v4 + + - name: Run clang-format style check + uses: jidicula/clang-format-action@v4.15.0 + with: + clang-format-version: '20' + check-path: ${{ matrix.path }} diff --git a/cubool/include/cubool/cubool.h b/cubool/include/cubool/cubool.h index 2859542..a3c3646 100644 --- a/cubool/include/cubool/cubool.h +++ b/cubool/include/cubool/cubool.h @@ -119,12 +119,12 @@ typedef struct cuBool_DeviceCaps { char name[256]; bool cudaSupported; bool managedMem; - int major; - int minor; - int warp; - int globalMemoryKiBs; - int sharedMemoryPerMultiProcKiBs; - int sharedMemoryPerBlockKiBs; + int major; + int minor; + int warp; + int globalMemoryKiBs; + int sharedMemoryPerMultiProcKiBs; + int sharedMemoryPerBlockKiBs; } cuBool_DeviceCaps; /** @@ -133,8 +133,7 @@ typedef struct cuBool_DeviceCaps { * * @return Read-only library about info */ -CUBOOL_EXPORT CUBOOL_API const char* cuBool_GetAbout( -); +CUBOOL_EXPORT CUBOOL_API const char* cuBool_GetAbout(); /** * Query human-readable text info about the project implementation @@ -142,8 +141,7 @@ CUBOOL_EXPORT CUBOOL_API const char* cuBool_GetAbout( * @return Read-only library license info */ -CUBOOL_EXPORT CUBOOL_API const char* cuBool_GetLicenseInfo( -); +CUBOOL_EXPORT CUBOOL_API const char* cuBool_GetLicenseInfo(); /** * Query library version number in form MAJOR.MINOR @@ -156,10 +154,9 @@ CUBOOL_EXPORT CUBOOL_API const char* cuBool_GetLicenseInfo( * @return Error if failed to query version info */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_GetVersion( - int* major, - int* minor, - int* sub -); + int* major, + int* minor, + int* sub); /** * Allows to setup logging file for all operations, invoked after this function call. @@ -177,9 +174,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_GetVersion( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_SetupLogging( - const char* logFileName, - cuBool_Hints hints -); + const char* logFileName, + cuBool_Hints hints); /** * Initialize library instance object, which provides context to all library operations and primitives. @@ -193,8 +189,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_SetupLogging( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Initialize( - cuBool_Hints hints -); + cuBool_Hints hints); /** * Finalize library state and all objects, which were created on this library context. @@ -205,8 +200,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Initialize( * * @return Error code on this operation */ -CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Finalize( -); +CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Finalize(); /** * Query device capabilities/properties if cuda compatible device is present. @@ -217,8 +211,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Finalize( * @return Error if cuda device not present or if failed to query capabilities */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_GetDeviceCaps( - cuBool_DeviceCaps* deviceCaps -); + cuBool_DeviceCaps* deviceCaps); /** * Creates new sparse matrix with specified size. @@ -230,10 +223,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_GetDeviceCaps( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_New( - cuBool_Matrix* matrix, - cuBool_Index nrows, - cuBool_Index ncols -); + cuBool_Matrix* matrix, + cuBool_Index nrows, + cuBool_Index ncols); /** * Build sparse matrix from provided pairs array. Pairs are supposed to be stored @@ -252,12 +244,11 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_New( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Build( - cuBool_Matrix matrix, - const cuBool_Index* rows, - const cuBool_Index* cols, - cuBool_Index nvals, - cuBool_Hints hints -); + cuBool_Matrix matrix, + const cuBool_Index* rows, + const cuBool_Index* cols, + cuBool_Index nvals, + cuBool_Hints hints); /** * Sets specified (i, j) value of the matrix to True. @@ -271,10 +262,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Build( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_SetElement( - cuBool_Matrix matrix, - cuBool_Index i, - cuBool_Index j -); + cuBool_Matrix matrix, + cuBool_Index i, + cuBool_Index j); /** * Sets to the matrix specific debug string marker. @@ -286,9 +276,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_SetElement( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_SetMarker( - cuBool_Matrix matrix, - const char* marker -); + cuBool_Matrix matrix, + const char* marker); /** * Allows to get matrix debug string marker. @@ -306,10 +295,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_SetMarker( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Marker( - cuBool_Matrix matrix, - char* marker, - cuBool_Index* size -); + cuBool_Matrix matrix, + char* marker, + cuBool_Index* size); /** * Reads matrix data to the host visible CPU buffer as an array of values pair. @@ -325,11 +313,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Marker( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_ExtractPairs( - cuBool_Matrix matrix, - cuBool_Index* rows, - cuBool_Index* cols, - cuBool_Index* nvals -); + cuBool_Matrix matrix, + cuBool_Index* rows, + cuBool_Index* cols, + cuBool_Index* nvals); /** * Extracts sub-matrix of the input matrix and stores it into result matrix. @@ -355,14 +342,13 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_ExtractPairs( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_ExtractSubMatrix( - cuBool_Matrix result, - cuBool_Matrix matrix, - cuBool_Index i, - cuBool_Index j, - cuBool_Index nrows, - cuBool_Index ncols, - cuBool_Hints hints -); + cuBool_Matrix result, + cuBool_Matrix matrix, + cuBool_Index i, + cuBool_Index j, + cuBool_Index nrows, + cuBool_Index ncols, + cuBool_Hints hints); /** * Extract specified matrix row as vector. @@ -379,11 +365,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_ExtractSubMatrix( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_ExtractRow( - cuBool_Vector result, - cuBool_Matrix matrix, - cuBool_Index i, - cuBool_Hints hints -); + cuBool_Vector result, + cuBool_Matrix matrix, + cuBool_Index i, + cuBool_Hints hints); /** * Extract specified matrix col as vector. @@ -400,11 +385,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_ExtractRow( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_ExtractCol( - cuBool_Vector result, - cuBool_Matrix matrix, - cuBool_Index j, - cuBool_Hints hints -); + cuBool_Vector result, + cuBool_Matrix matrix, + cuBool_Index j, + cuBool_Hints hints); /** * Creates new sparse matrix, duplicates content and stores handle in the provided pointer. @@ -415,9 +399,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_ExtractCol( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Duplicate( - cuBool_Matrix matrix, - cuBool_Matrix* duplicated -); + cuBool_Matrix matrix, + cuBool_Matrix* duplicated); /** * Transpose source matrix and store result of this operation in result matrix. @@ -432,10 +415,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Duplicate( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Transpose( - cuBool_Matrix result, - cuBool_Matrix matrix, - cuBool_Hints hints -); + cuBool_Matrix result, + cuBool_Matrix matrix, + cuBool_Hints hints); /** * Query number of non-zero values of the matrix. @@ -446,9 +428,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Transpose( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Nvals( - cuBool_Matrix matrix, - cuBool_Index* nvals -); + cuBool_Matrix matrix, + cuBool_Index* nvals); /** * Query number of rows in the matrix. @@ -459,9 +440,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Nvals( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Nrows( - cuBool_Matrix matrix, - cuBool_Index* nrows -); + cuBool_Matrix matrix, + cuBool_Index* nrows); /** * Query number of columns in the matrix. @@ -472,9 +452,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Nrows( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Ncols( - cuBool_Matrix matrix, - cuBool_Index* ncols -); + cuBool_Matrix matrix, + cuBool_Index* ncols); /** * Deletes sparse matrix object. @@ -484,8 +463,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Ncols( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Free( - cuBool_Matrix matrix -); + cuBool_Matrix matrix); /** * Reduce the source matrix to the column vector. @@ -503,10 +481,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Free( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce( - cuBool_Vector result, - cuBool_Matrix matrix, - cuBool_Hints hints -); + cuBool_Vector result, + cuBool_Matrix matrix, + cuBool_Hints hints); /** * Reduce the source matrix to the column matrix result (column vector). @@ -525,10 +502,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce2( - cuBool_Matrix result, - cuBool_Matrix matrix, - cuBool_Hints hints -); + cuBool_Matrix result, + cuBool_Matrix matrix, + cuBool_Hints hints); /** * Performs result = left + right, where '+' is boolean semiring 'or' operation. @@ -548,11 +524,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce2( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseAdd( - cuBool_Matrix result, - cuBool_Matrix left, - cuBool_Matrix right, - cuBool_Hints hints -); + cuBool_Matrix result, + cuBool_Matrix left, + cuBool_Matrix right, + cuBool_Hints hints); /** * Performs result = left * right, where '*' is boolean semiring 'and' operation. @@ -572,11 +547,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseAdd( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseMult( - cuBool_Matrix result, - cuBool_Matrix left, - cuBool_Matrix right, - cuBool_Hints hints -); + cuBool_Matrix result, + cuBool_Matrix left, + cuBool_Matrix right, + cuBool_Hints hints); /** * Creates new sparse vector with specified size. @@ -587,9 +561,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseMult( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_New( - cuBool_Vector* vector, - cuBool_Index nrows -); + cuBool_Vector* vector, + cuBool_Index nrows); /** * Build sparse vector from provided indices array. @@ -606,11 +579,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_New( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Build( - cuBool_Vector vector, - const cuBool_Index* rows, - cuBool_Index nvals, - cuBool_Hints hints -); + cuBool_Vector vector, + const cuBool_Index* rows, + cuBool_Index nvals, + cuBool_Hints hints); /** * Sets specified (j) value of the vector to True. @@ -623,9 +595,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Build( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_SetElement( - cuBool_Vector vector, - cuBool_Index i -); + cuBool_Vector vector, + cuBool_Index i); /** * Sets to the vector specific debug string marker. @@ -637,9 +608,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_SetElement( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_SetMarker( - cuBool_Vector vector, - const char* marker -); + cuBool_Vector vector, + const char* marker); /** * Allows to get vector debug string marker. @@ -657,10 +627,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_SetMarker( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Marker( - cuBool_Vector vector, - char* marker, - cuBool_Index* size -); + cuBool_Vector vector, + char* marker, + cuBool_Index* size); /** * Reads vector data to the host visible CPU buffer as an array of indices. @@ -675,10 +644,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Marker( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_ExtractValues( - cuBool_Vector vector, - cuBool_Index* rows, - cuBool_Index* nvals -); + cuBool_Vector vector, + cuBool_Index* rows, + cuBool_Index* nvals); /** * Extracts sub-vector of the input vector and stores it into result vector. @@ -702,12 +670,11 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_ExtractValues( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_ExtractSubVector( - cuBool_Vector result, - cuBool_Vector vector, - cuBool_Index i, - cuBool_Index nrows, - cuBool_Hints hints -); + cuBool_Vector result, + cuBool_Vector vector, + cuBool_Index i, + cuBool_Index nrows, + cuBool_Hints hints); /** * Creates new sparse vector, duplicates content and stores handle in the provided pointer. @@ -718,9 +685,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_ExtractSubVector( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Duplicate( - cuBool_Vector vector, - cuBool_Vector* duplicated -); + cuBool_Vector vector, + cuBool_Vector* duplicated); /** * Query number of non-zero values of the vector. @@ -731,9 +697,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Duplicate( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Nvals( - cuBool_Vector vector, - cuBool_Index* nvals -); + cuBool_Vector vector, + cuBool_Index* nvals); /** * Query number of rows in the vector. @@ -744,9 +709,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Nvals( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Nrows( - cuBool_Vector vector, - cuBool_Index* nrows -); + cuBool_Vector vector, + cuBool_Index* nrows); /** * Deletes sparse vector object. @@ -756,8 +720,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Nrows( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Free( - cuBool_Vector vector -); + cuBool_Vector vector); /** @@ -772,10 +735,9 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Free( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Reduce( - cuBool_Index* result, - cuBool_Vector vector, - cuBool_Hints hints -); + cuBool_Index* result, + cuBool_Vector vector, + cuBool_Hints hints); /** * Performs result = left + right, where '+' is boolean semiring 'or' operation. @@ -795,11 +757,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Reduce( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_EWiseAdd( - cuBool_Vector result, - cuBool_Vector left, - cuBool_Vector right, - cuBool_Hints hints -); + cuBool_Vector result, + cuBool_Vector left, + cuBool_Vector right, + cuBool_Hints hints); /** * Performs result = left * right, where '*' is boolean semiring 'and' operation. @@ -819,11 +780,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_EWiseAdd( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_EWiseMult( - cuBool_Vector result, - cuBool_Vector left, - cuBool_Vector right, - cuBool_Hints hints -); + cuBool_Vector result, + cuBool_Vector left, + cuBool_Vector right, + cuBool_Hints hints); /** * Performs result (accum)= left x right evaluation, where source '+' and 'x' are boolean semiring operations. @@ -845,11 +805,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_EWiseMult( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_MxM( - cuBool_Matrix result, - cuBool_Matrix left, - cuBool_Matrix right, - cuBool_Hints hints -); + cuBool_Matrix result, + cuBool_Matrix left, + cuBool_Matrix right, + cuBool_Hints hints); /** * Performs result = left x right evaluation, where source '+' and 'x' are boolean semiring operations. @@ -870,11 +829,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_MxM( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_MxV( - cuBool_Vector result, - cuBool_Matrix left, - cuBool_Vector right, - cuBool_Hints hints -); + cuBool_Vector result, + cuBool_Matrix left, + cuBool_Vector right, + cuBool_Hints hints); /** * Performs result = left x right evaluation, where source '+' and 'x' are boolean semiring operations. @@ -895,11 +853,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_MxV( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_VxM( - cuBool_Vector result, - cuBool_Vector left, - cuBool_Matrix right, - cuBool_Hints hints -); + cuBool_Vector result, + cuBool_Vector left, + cuBool_Matrix right, + cuBool_Hints hints); /** * Performs result = left `kron` right, where `kron` is a Kronecker product for boolean semiring. @@ -919,11 +876,10 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_VxM( * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Kronecker( - cuBool_Matrix result, - cuBool_Matrix left, - cuBool_Matrix right, - cuBool_Hints hints -); + cuBool_Matrix result, + cuBool_Matrix left, + cuBool_Matrix right, + cuBool_Hints hints); /** * Performs result = left * ~right, where @@ -938,17 +894,16 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Kronecker( * @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time * * @param result[out] Destination matrix to store result - * @param left Source matrix to be multiplied - * @param right Source matrix to be inverted and multiplied + * @param matrix Source matrix to be multiplied + * @param mask Source matrix to be inverted and multiplied * @param hints Hints for the operation * * @return Error code on this operation */ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseMulInverted( - cuBool_Matrix result, - cuBool_Matrix matrix, - cuBool_Matrix mask, - cuBool_Hints hints -); + cuBool_Matrix result, + cuBool_Matrix matrix, + cuBool_Matrix mask, + cuBool_Hints hints); -#endif //CUBOOL_CUBOOL_H +#endif//CUBOOL_CUBOOL_H diff --git a/cubool/sources/backend/backend_base.hpp b/cubool/sources/backend/backend_base.hpp index b81864e..be8bed0 100644 --- a/cubool/sources/backend/backend_base.hpp +++ b/cubool/sources/backend/backend_base.hpp @@ -33,17 +33,17 @@ namespace cubool { class BackendBase { public: - virtual ~BackendBase() = default; - virtual void initialize(hints initHints) = 0; - virtual void finalize() = 0; - virtual bool isInitialized() const = 0; - virtual MatrixBase* createMatrix(size_t nrows, size_t ncols) = 0; - virtual VectorBase* createVector(size_t nrows) = 0; - virtual void releaseMatrix(MatrixBase* matrixBase) = 0; - virtual void releaseVector(VectorBase* vectorBase) = 0; - virtual void queryCapabilities(cuBool_DeviceCaps& caps) = 0; + virtual ~BackendBase() = default; + virtual void initialize(hints initHints) = 0; + virtual void finalize() = 0; + virtual bool isInitialized() const = 0; + virtual MatrixBase* createMatrix(size_t nrows, size_t ncols) = 0; + virtual VectorBase* createVector(size_t nrows) = 0; + virtual void releaseMatrix(MatrixBase* matrixBase) = 0; + virtual void releaseVector(VectorBase* vectorBase) = 0; + virtual void queryCapabilities(cuBool_DeviceCaps& caps) = 0; }; -} +}// namespace cubool -#endif //CUBOOL_BACKEND_BASE_HPP +#endif//CUBOOL_BACKEND_BASE_HPP diff --git a/cubool/sources/backend/matrix_base.hpp b/cubool/sources/backend/matrix_base.hpp index 8842eb9..e8fda05 100644 --- a/cubool/sources/backend/matrix_base.hpp +++ b/cubool/sources/backend/matrix_base.hpp @@ -36,28 +36,28 @@ namespace cubool { public: virtual ~MatrixBase() = default; - virtual void setElement(index i, index j) = 0; - virtual void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) = 0; - virtual void extract(index* rows, index* cols, size_t &nvals) = 0; - virtual void extractSubMatrix(const MatrixBase &otherBase, index i, index j, index nrows, index ncols, bool checkTime) = 0; + virtual void setElement(index i, index j) = 0; + virtual void build(const index* rows, const index* cols, size_t nvals, bool isSorted, bool noDuplicates) = 0; + virtual void extract(index* rows, index* cols, size_t& nvals) = 0; + virtual void extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols, bool checkTime) = 0; - virtual void clone(const MatrixBase& otherBase) = 0; - virtual void transpose(const MatrixBase &otherBase, bool checkTime) = 0; - virtual void reduce(const MatrixBase &otherBase, bool checkTime) = 0; + virtual void clone(const MatrixBase& otherBase) = 0; + virtual void transpose(const MatrixBase& otherBase, bool checkTime) = 0; + virtual void reduce(const MatrixBase& otherBase, bool checkTime) = 0; - virtual void multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) = 0; - virtual void kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0; - virtual void eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0; - virtual void eWiseMult(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0; - virtual void eWiseMultInverted(const MatrixBase &matrix, const MatrixBase &mask, bool checkTime) = 0; + virtual void multiply(const MatrixBase& aBase, const MatrixBase& bBase, bool accumulate, bool checkTime) = 0; + virtual void kronecker(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) = 0; + virtual void eWiseAdd(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) = 0; + virtual void eWiseMult(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) = 0; + virtual void eWiseMultInverted(const MatrixBase& matrix, const MatrixBase& mask, bool checkTime) = 0; virtual index getNrows() const = 0; virtual index getNcols() const = 0; virtual index getNvals() const = 0; - bool isZeroDim() const { return (size_t)getNrows() * (size_t)getNcols() == 0; } + bool isZeroDim() const { return (size_t) getNrows() * (size_t) getNcols() == 0; } }; -} +}// namespace cubool -#endif //CUBOOL_MATRIX_BASE_HPP +#endif//CUBOOL_MATRIX_BASE_HPP diff --git a/cubool/sources/backend/vector_base.hpp b/cubool/sources/backend/vector_base.hpp index ae95300..3755400 100644 --- a/cubool/sources/backend/vector_base.hpp +++ b/cubool/sources/backend/vector_base.hpp @@ -36,19 +36,19 @@ namespace cubool { public: virtual ~VectorBase() = default; - virtual void setElement(index i) = 0; - virtual void build(const index *rows, size_t nvals, bool isSorted, bool noDuplicates) = 0; - virtual void extract(index* rows, size_t &nvals) = 0; - virtual void extractSubVector(const VectorBase &otherBase, index i, index nrows, bool checkTime) = 0; - virtual void extractRow(const class MatrixBase& matrixBase, index i) = 0; - virtual void extractCol(const class MatrixBase& matrixBase, index j) = 0; - - virtual void clone(const VectorBase& otherBase) = 0; - virtual void reduce(index &result, bool checkTime) = 0; + virtual void setElement(index i) = 0; + virtual void build(const index* rows, size_t nvals, bool isSorted, bool noDuplicates) = 0; + virtual void extract(index* rows, size_t& nvals) = 0; + virtual void extractSubVector(const VectorBase& otherBase, index i, index nrows, bool checkTime) = 0; + virtual void extractRow(const class MatrixBase& matrixBase, index i) = 0; + virtual void extractCol(const class MatrixBase& matrixBase, index j) = 0; + + virtual void clone(const VectorBase& otherBase) = 0; + virtual void reduce(index& result, bool checkTime) = 0; virtual void reduceMatrix(const class MatrixBase& matrix, bool transpose, bool checkTime) = 0; - virtual void eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) = 0; - virtual void eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) = 0; + virtual void eWiseMult(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) = 0; + virtual void eWiseAdd(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) = 0; virtual void multiplyVxM(const VectorBase& vBase, const class MatrixBase& mBase, bool checkTime) = 0; virtual void multiplyMxV(const class MatrixBase& mBase, const VectorBase& vBase, bool checkTime) = 0; @@ -58,6 +58,6 @@ namespace cubool { bool isZeroDim() const { return getNrows() == 0; } }; -} +}// namespace cubool -#endif //CUBOOL_VECTOR_BASE_HPP +#endif//CUBOOL_VECTOR_BASE_HPP diff --git a/cubool/sources/core/config.hpp b/cubool/sources/core/config.hpp index d1987a6..4721594 100644 --- a/cubool/sources/core/config.hpp +++ b/cubool/sources/core/config.hpp @@ -25,14 +25,17 @@ #ifndef CUBOOL_CONFIG_HPP #define CUBOOL_CONFIG_HPP -#include #include #include +#include namespace cubool { using index = cuBool_Index; using hints = cuBool_Hints; - struct Pair { cuBool_Index i; cuBool_Index j; }; -} + struct Pair { + cuBool_Index i; + cuBool_Index j; + }; +}// namespace cubool -#endif //CUBOOL_CONFIG_HPP \ No newline at end of file +#endif//CUBOOL_CONFIG_HPP \ No newline at end of file diff --git a/cubool/sources/core/error.hpp b/cubool/sources/core/error.hpp index ff6e4c4..95f4799 100644 --- a/cubool/sources/core/error.hpp +++ b/cubool/sources/core/error.hpp @@ -27,8 +27,8 @@ #include #include -#include #include +#include namespace cubool { @@ -36,23 +36,21 @@ namespace cubool { * Generic library exception. * Use this one in particular backend implementations. */ - class Exception: public std::exception { + class Exception : public std::exception { public: - Exception(std::string message, std::string function, std::string file, size_t line, cuBool_Status status, bool critical) - : std::exception(), - mMessage(std::move(message)), - mFunction(std::move(function)), - mFile(std::move(file)), - mLine(line), - nStatus(status), - mCritical(critical) { - + : std::exception(), + mMessage(std::move(message)), + mFunction(std::move(function)), + mFile(std::move(file)), + mLine(line), + nStatus(status), + mCritical(critical) { } Exception(const Exception& e) noexcept = default; - Exception(Exception&& e) noexcept = default; - ~Exception() noexcept override = default; + Exception(Exception&& e) noexcept = default; + ~Exception() noexcept override = default; const char* what() const noexcept override { if (!mCached) { @@ -94,13 +92,13 @@ namespace cubool { private: mutable std::string mWhatCached; - std::string mMessage; - std::string mFunction; - std::string mFile; - size_t mLine; - cuBool_Status nStatus; - bool mCritical; - mutable bool mCached = false; + std::string mMessage; + std::string mFunction; + std::string mFile; + size_t mLine; + cuBool_Status nStatus; + bool mCritical; + mutable bool mCached = false; }; /** @@ -108,46 +106,51 @@ namespace cubool { * @tparam Type Exception error code (type) */ template - class TException: public Exception { + class TException : public Exception { public: TException(std::string message, std::string&& function, std::string&& file, size_t line, bool critical) - : Exception(std::move(message), std::move(function), std::move(file), line, Type, critical) { - + : Exception(std::move(message), std::move(function), std::move(file), line, Type, critical) { } TException(const TException& other) noexcept = default; - TException(TException&& other) noexcept = default; - ~TException() noexcept override = default; + TException(TException&& other) noexcept = default; + ~TException() noexcept override = default; }; // Errors exposed to the C API - using Error = TException; - using DeviceError = TException; + using Error = TException; + using DeviceError = TException; using DeviceNotPresent = TException; - using MemOpFailed = TException; - using InvalidArgument = TException; - using InvalidState = TException; - using BackendError = TException; - using NotImplemented = TException; + using MemOpFailed = TException; + using InvalidArgument = TException; + using InvalidState = TException; + using BackendError = TException; + using NotImplemented = TException; -} +}// namespace cubool // An error, in theory, can recover after this -#define RAISE_ERROR(type, message) \ - do { \ - throw ::cubool::type(message, __FUNCTION__, __FILE__, __LINE__, false); \ +#define RAISE_ERROR(type, message) \ + do { \ + throw ::cubool::type(message, __FUNCTION__, __FILE__, __LINE__, false); \ } while (0); -#define CHECK_RAISE_ERROR(condition, type, message) \ - if (!(condition)) { RAISE_ERROR(type, #condition ": " message); } else { } +#define CHECK_RAISE_ERROR(condition, type, message) \ + if (!(condition)) { \ + RAISE_ERROR(type, #condition ": " message); \ + } else { \ + } // Critical errors, cause library shutdown -#define RAISE_CRITICAL_ERROR(type, message) \ - do { \ - throw ::cubool::type(message, __FUNCTION__, __FILE__, __LINE__, true); \ +#define RAISE_CRITICAL_ERROR(type, message) \ + do { \ + throw ::cubool::type(message, __FUNCTION__, __FILE__, __LINE__, true); \ } while (0); -#define CHECK_RAISE_CRITICAL_ERROR(condition, type, message) \ - if (!(condition)) { RAISE_CRITICAL_ERROR(type, #condition ": " message); } else { } +#define CHECK_RAISE_CRITICAL_ERROR(condition, type, message) \ + if (!(condition)) { \ + RAISE_CRITICAL_ERROR(type, #condition ": " message); \ + } else { \ + } -#endif //CUBOOL_ERROR_HPP +#endif//CUBOOL_ERROR_HPP diff --git a/cubool/sources/core/library.cpp b/cubool/sources/core/library.cpp index 4987011..b5f5493 100644 --- a/cubool/sources/core/library.cpp +++ b/cubool/sources/core/library.cpp @@ -22,34 +22,34 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include +#include +#include #include +#include #include #include -#include -#include #include #include +#include #include #include -#include #ifdef CUBOOL_WITH_CUDA -#include + #include #endif #ifdef CUBOOL_WITH_SEQUENTIAL -#include + #include #endif namespace cubool { - std::unordered_set Library::mAllocMatrices; - std::unordered_set Library::mAllocVectors; - std::shared_ptr Library::mBackend = nullptr; - std::shared_ptr Library::mLogger = std::make_shared(); - bool Library::mRelaxedRelease = false; + std::unordered_set Library::mAllocMatrices; + std::unordered_set Library::mAllocVectors; + std::shared_ptr Library::mBackend = nullptr; + std::shared_ptr Library::mLogger = std::make_shared(); + bool Library::mRelaxedRelease = false; void Library::initialize(hints initHints) { CHECK_RAISE_CRITICAL_ERROR(mBackend == nullptr, InvalidState, "Library already initialized"); @@ -97,12 +97,12 @@ namespace cubool { LogStream stream(*getLogger()); stream << Logger::Level::Info << "Enabled relaxed library finalize" << LogStream::cmt; - for (auto m: mAllocMatrices) { + for (auto m : mAllocMatrices) { stream << Logger::Level::Warning << "Implicitly release matrix " << m->getDebugMarker() << LogStream::cmt; delete m; } - for (auto v: mAllocVectors) { + for (auto v : mAllocVectors) { stream << Logger::Level::Warning << "Implicitly release vector " << v->getDebugMarker() << LogStream::cmt; delete v; } @@ -127,7 +127,7 @@ namespace cubool { CHECK_RAISE_CRITICAL_ERROR(mBackend != nullptr || mRelaxedRelease, InvalidState, "Library is not initialized"); } - void Library::setupLogging(const char *logFileName, cuBool_Hints hints) { + void Library::setupLogging(const char* logFileName, cuBool_Hints hints) { CHECK_RAISE_ERROR(logFileName != nullptr, InvalidArgument, "Null file name is not allowed"); auto logFile = std::make_shared(); @@ -142,19 +142,19 @@ namespace cubool { auto textLogger = std::make_shared(); textLogger->addFilter([=](Logger::Level level, const std::string& message) -> bool { - bool all = hints == 0x0 || (hints & CUBOOL_HINT_LOG_ALL); - bool error = hints & CUBOOL_HINT_LOG_ERROR; + bool all = hints == 0x0 || (hints & CUBOOL_HINT_LOG_ALL); + bool error = hints & CUBOOL_HINT_LOG_ERROR; bool warning = hints & CUBOOL_HINT_LOG_WARNING; return all || - (error && level == Logger::Level::Error) || - (warning && level == Logger::Level::Warning); + (error && level == Logger::Level::Error) || + (warning && level == Logger::Level::Warning); }); textLogger->addOnLoggerAction([=](size_t id, Logger::Level level, const std::string& message) { auto& file = *logFile; - const auto idSize = 10; + const auto idSize = 10; const auto levelSize = 20; file << "[" << std::setw(idSize) << id << std::setw(-1) << "]"; @@ -187,7 +187,7 @@ namespace cubool { logDeviceInfo(); } - Matrix *Library::createMatrix(size_t nrows, size_t ncols) { + Matrix* Library::createMatrix(size_t nrows, size_t ncols) { CHECK_RAISE_ERROR(nrows > 0, InvalidArgument, "Cannot create matrix with zero dimension"); CHECK_RAISE_ERROR(ncols > 0, InvalidArgument, "Cannot create matrix with zero dimension"); @@ -201,7 +201,7 @@ namespace cubool { return m; } - class Vector * Library::createVector(size_t nrows) { + class Vector* Library::createVector(size_t nrows) { CHECK_RAISE_ERROR(nrows > 0, InvalidArgument, "Cannot create vector with zero dimension"); auto v = new Vector(nrows, *mBackend); @@ -214,7 +214,7 @@ namespace cubool { return v; } - void Library::releaseMatrix(Matrix *matrix) { + void Library::releaseMatrix(Matrix* matrix) { if (mRelaxedRelease && !mBackend) return; CHECK_RAISE_ERROR(mAllocMatrices.find(matrix) != mAllocMatrices.end(), InvalidArgument, "No such matrix was allocated"); @@ -226,7 +226,7 @@ namespace cubool { delete matrix; } - void Library::releaseVector(class Vector *vector) { + void Library::releaseVector(class Vector* vector) { if (mRelaxedRelease && !mBackend) return; CHECK_RAISE_ERROR(mAllocVectors.find(vector) != mAllocVectors.end(), InvalidArgument, "No such vector was allocated"); @@ -246,15 +246,15 @@ namespace cubool { #endif } - void Library::queryCapabilities(cuBool_DeviceCaps &caps) { - caps.name[0] = '\0'; - caps.cudaSupported = false; - caps.managedMem = false; - caps.major = 0; - caps.minor = 0; - caps.warp = 0; - caps.globalMemoryKiBs = 0; - caps.sharedMemoryPerBlockKiBs = 0; + void Library::queryCapabilities(cuBool_DeviceCaps& caps) { + caps.name[0] = '\0'; + caps.cudaSupported = false; + caps.managedMem = false; + caps.major = 0; + caps.minor = 0; + caps.warp = 0; + caps.globalMemoryKiBs = 0; + caps.sharedMemoryPerBlockKiBs = 0; caps.sharedMemoryPerMultiProcKiBs = 0; mBackend->queryCapabilities(caps); @@ -273,13 +273,12 @@ namespace cubool { << " name: " << caps.name << "," << " major: " << caps.major << "," << " minor: " << caps.minor << "," - << " mem type: " << (caps.managedMem? "managed": "default") << "," + << " mem type: " << (caps.managedMem ? "managed" : "default") << "," << " warp size: " << caps.warp << "," << " globalMemoryKiBs: " << caps.globalMemoryKiBs << "," << " sharedMemoryPerMultiProcKiBs: " << caps.sharedMemoryPerMultiProcKiBs << "," << " sharedMemoryPerBlockKiBs: " << caps.sharedMemoryPerBlockKiBs; - } - else { + } else { stream << "Cuda device is not presented (fallback to cpu backend)"; } @@ -290,8 +289,8 @@ namespace cubool { return mBackend != nullptr; } - class Logger * Library::getLogger() { + class Logger* Library::getLogger() { return mLogger.get(); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/core/library.hpp b/cubool/sources/core/library.hpp index f1d2ffc..0660da1 100644 --- a/cubool/sources/core/library.hpp +++ b/cubool/sources/core/library.hpp @@ -27,35 +27,35 @@ #include #include -#include #include +#include namespace cubool { class Library { public: - static void initialize(hints initHints); - static void finalize(); - static void validate(); - static void setupLogging(const char* logFileName, cuBool_Hints hints); - static class Matrix *createMatrix(size_t nrows, size_t ncols); - static class Vector *createVector(size_t nrows); - static void releaseMatrix(class Matrix *matrix); - static void releaseVector(class Vector *vector); - static void handleError(const std::exception& error); - static void queryCapabilities(cuBool_DeviceCaps& caps); - static void logDeviceInfo(); - static bool isBackedInitialized(); + static void initialize(hints initHints); + static void finalize(); + static void validate(); + static void setupLogging(const char* logFileName, cuBool_Hints hints); + static class Matrix* createMatrix(size_t nrows, size_t ncols); + static class Vector* createVector(size_t nrows); + static void releaseMatrix(class Matrix* matrix); + static void releaseVector(class Vector* vector); + static void handleError(const std::exception& error); + static void queryCapabilities(cuBool_DeviceCaps& caps); + static void logDeviceInfo(); + static bool isBackedInitialized(); static class Logger* getLogger(); private: - static std::unordered_set mAllocMatrices; - static std::unordered_set mAllocVectors; + static std::unordered_set mAllocMatrices; + static std::unordered_set mAllocVectors; static std::shared_ptr mBackend; - static std::shared_ptr mLogger; - static bool mRelaxedRelease; + static std::shared_ptr mLogger; + static bool mRelaxedRelease; }; -} +}// namespace cubool -#endif //CUBOOL_LIBRARY_HPP \ No newline at end of file +#endif//CUBOOL_LIBRARY_HPP \ No newline at end of file diff --git a/cubool/sources/core/matrix.cpp b/cubool/sources/core/matrix.cpp index 49e35c3..eae9618 100644 --- a/cubool/sources/core/matrix.cpp +++ b/cubool/sources/core/matrix.cpp @@ -22,30 +22,30 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include +#include #include #include +#include #include #include -#include -#define TIMER_ACTION(timer, action) \ - Timer timer; \ - timer.start(); \ - action; \ +#define TIMER_ACTION(timer, action) \ + Timer timer; \ + timer.start(); \ + action; \ timer.end() namespace cubool { - Matrix::Matrix(size_t nrows, size_t ncols, BackendBase &backend) { - mHnd = backend.createMatrix(nrows, ncols); + Matrix::Matrix(size_t nrows, size_t ncols, BackendBase& backend) { + mHnd = backend.createMatrix(nrows, ncols); mProvider = &backend; } Matrix::~Matrix() { if (mHnd) { mProvider->releaseMatrix(mHnd); - mHnd = nullptr; + mHnd = nullptr; mProvider = nullptr; } } @@ -59,7 +59,7 @@ namespace cubool { mCachedJ.push_back(j); } - void Matrix::build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) { + void Matrix::build(const index* rows, const index* cols, size_t nvals, bool isSorted, bool noDuplicates) { CHECK_RAISE_ERROR(rows != nullptr || nvals == 0, InvalidArgument, "Null ptr rows array"); CHECK_RAISE_ERROR(cols != nullptr || nvals == 0, InvalidArgument, "Null ptr cols array"); @@ -74,7 +74,7 @@ namespace cubool { mHnd->build(rows, cols, nvals, isSorted, noDuplicates); } - void Matrix::extract(index *rows, index *cols, size_t &nvals) { + void Matrix::extract(index* rows, index* cols, size_t& nvals) { CHECK_RAISE_ERROR(rows != nullptr || getNvals() == 0, InvalidArgument, "Null ptr rows array"); CHECK_RAISE_ERROR(cols != nullptr || getNvals() == 0, InvalidArgument, "Null ptr cols array"); CHECK_RAISE_ERROR(getNvals() <= nvals, InvalidArgument, "Passed arrays size must be more or equal to the nvals of the matrix"); @@ -83,7 +83,7 @@ namespace cubool { mHnd->extract(rows, cols, nvals); } - void Matrix::extractSubMatrix(const MatrixBase &otherBase, index i, index j, index nrows, index ncols, bool checkTime) { + void Matrix::extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols, bool checkTime) { const auto* other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class"); @@ -101,7 +101,7 @@ namespace cubool { CHECK_RAISE_ERROR(ncols == this->getNcols(), InvalidArgument, "Result matrix has incompatible size for extracted sub-matrix range"); other->commitCache(); - this->releaseCache(); // Values of this matrix won't be used any more + this->releaseCache();// Values of this matrix won't be used any more if (checkTime) { TIMER_ACTION(timer, mHnd->extractSubMatrix(*other->mHnd, i, j, nrows, ncols, false)); @@ -120,7 +120,7 @@ namespace cubool { mHnd->extractSubMatrix(*other->mHnd, i, j, nrows, ncols, false); } - void Matrix::clone(const MatrixBase &otherBase) { + void Matrix::clone(const MatrixBase& otherBase) { const auto* other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class"); @@ -135,12 +135,12 @@ namespace cubool { CHECK_RAISE_ERROR(N == this->getNcols(), InvalidArgument, "Cloned matrix has incompatible size"); other->commitCache(); - this->releaseCache(); // Values of this matrix won't be used any more + this->releaseCache();// Values of this matrix won't be used any more mHnd->clone(*other->mHnd); } - void Matrix::transpose(const MatrixBase &otherBase, bool checkTime) { + void Matrix::transpose(const MatrixBase& otherBase, bool checkTime) { const auto* other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class"); @@ -152,7 +152,7 @@ namespace cubool { CHECK_RAISE_ERROR(N == this->getNrows(), InvalidArgument, "Transposed matrix has incompatible size"); this->commitCache(); - this->releaseCache(); // Values of this matrix won't be used any more + this->releaseCache();// Values of this matrix won't be used any more if (checkTime) { TIMER_ACTION(timer, mHnd->transpose(*other->mHnd, false)); @@ -170,7 +170,7 @@ namespace cubool { mHnd->transpose(*other->mHnd, false); } - void Matrix::reduce(const MatrixBase &otherBase, bool checkTime) { + void Matrix::reduce(const MatrixBase& otherBase, bool checkTime) { const auto* other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class"); @@ -181,7 +181,7 @@ namespace cubool { CHECK_RAISE_ERROR(1 == this->getNcols(), InvalidArgument, "Matrix has incompatible size"); other->commitCache(); - this->releaseCache(); // Values of this matrix won't be used any more + this->releaseCache();// Values of this matrix won't be used any more if (checkTime) { TIMER_ACTION(timer, mHnd->reduce(*other->mHnd, false)); @@ -199,7 +199,7 @@ namespace cubool { mHnd->reduce(*other->mHnd, false); } - void Matrix::multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) { + void Matrix::multiply(const MatrixBase& aBase, const MatrixBase& bBase, bool accumulate, bool checkTime) { const auto* a = dynamic_cast(&aBase); const auto* b = dynamic_cast(&bBase); @@ -229,7 +229,7 @@ namespace cubool { stream << Logger::Level::Info << "Time: " << timer.getElapsedTimeMs() << " ms " << "Matrix::multiply: " - << this->getDebugMarker() << (accumulate? " += ": " = ") + << this->getDebugMarker() << (accumulate ? " += " : " = ") << a->getDebugMarker() << " x " << b->getDebugMarker() << LogStream::cmt; @@ -239,7 +239,7 @@ namespace cubool { mHnd->multiply(*a->mHnd, *b->mHnd, accumulate, false); } - void Matrix::kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void Matrix::kronecker(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { const auto* a = dynamic_cast(&aBase); const auto* b = dynamic_cast(&bBase); @@ -275,7 +275,7 @@ namespace cubool { mHnd->kronecker(*a->mHnd, *b->mHnd, false); } - void Matrix::eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void Matrix::eWiseAdd(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { const auto* a = dynamic_cast(&aBase); const auto* b = dynamic_cast(&bBase); @@ -312,7 +312,7 @@ namespace cubool { mHnd->eWiseAdd(*a->mHnd, *b->mHnd, false); } - void Matrix::eWiseMult(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void Matrix::eWiseMult(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { const auto* a = dynamic_cast(&aBase); const auto* b = dynamic_cast(&bBase); @@ -349,7 +349,7 @@ namespace cubool { mHnd->eWiseMult(*a->mHnd, *b->mHnd, false); } - void Matrix::eWiseMultInverted(const MatrixBase &matrix, const MatrixBase &mask, bool checkTime) { + void Matrix::eWiseMultInverted(const MatrixBase& matrix, const MatrixBase& mask, bool checkTime) { const auto* mat = dynamic_cast(&matrix); const auto* msk = dynamic_cast(&mask); @@ -388,7 +388,6 @@ namespace cubool { } - index Matrix::getNrows() const { return mHnd->getNrows(); } @@ -416,7 +415,7 @@ namespace cubool { if (cachedNvals == 0) return; - bool isSorted = false; + bool isSorted = false; bool noDuplicates = false; if (mHnd->getNvals() > 0) { @@ -427,8 +426,7 @@ namespace cubool { tmp->build(mCachedI.data(), mCachedJ.data(), cachedNvals, isSorted, noDuplicates); mHnd->eWiseAdd(*mHnd, *tmp, false); mProvider->releaseMatrix(tmp); - } - else { + } else { // Otherwise, new values are used to build matrix content mHnd->build(mCachedI.data(), mCachedJ.data(), cachedNvals, isSorted, noDuplicates); } @@ -436,4 +434,4 @@ namespace cubool { // Clear arrays releaseCache(); } -} +}// namespace cubool diff --git a/cubool/sources/core/matrix.hpp b/cubool/sources/core/matrix.hpp index 6c4d38b..6b3d037 100644 --- a/cubool/sources/core/matrix.hpp +++ b/cubool/sources/core/matrix.hpp @@ -25,10 +25,10 @@ #ifndef CUBOOL_MATRIX_HPP #define CUBOOL_MATRIX_HPP +#include +#include #include #include -#include -#include #include namespace cubool { @@ -37,26 +37,26 @@ namespace cubool { * Proxy matrix for the actual backend matrix implementation. * Behaves as validation/auxiliary layer. */ - class Matrix final: public MatrixBase, public Object { + class Matrix final : public MatrixBase, public Object { public: Matrix(size_t nrows, size_t ncols, BackendBase& backend); ~Matrix() override; void setElement(index i, index j) override; - void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) override; - void extract(index *rows, index *cols, size_t &nvals) override; - void extractSubMatrix(const MatrixBase &otherBase, index i, index j, index nrows, index ncols, + void build(const index* rows, const index* cols, size_t nvals, bool isSorted, bool noDuplicates) override; + void extract(index* rows, index* cols, size_t& nvals) override; + void extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols, bool checkTime) override; - void clone(const MatrixBase &otherBase) override; - void transpose(const MatrixBase &otherBase, bool checkTime) override; - void reduce(const MatrixBase &otherBase, bool checkTime) override; + void clone(const MatrixBase& otherBase) override; + void transpose(const MatrixBase& otherBase, bool checkTime) override; + void reduce(const MatrixBase& otherBase, bool checkTime) override; - void multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) override; - void kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) override; - void eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) override; - void eWiseMult(const MatrixBase &a, const MatrixBase &b, bool checkTime) override; - void eWiseMultInverted(const MatrixBase &matrix, const MatrixBase &mask, bool checkTime) override; + void multiply(const MatrixBase& aBase, const MatrixBase& bBase, bool accumulate, bool checkTime) override; + void kronecker(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) override; + void eWiseAdd(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) override; + void eWiseMult(const MatrixBase& a, const MatrixBase& b, bool checkTime) override; + void eWiseMultInverted(const MatrixBase& matrix, const MatrixBase& mask, bool checkTime) override; index getNrows() const override; index getNcols() const override; @@ -72,10 +72,10 @@ namespace cubool { mutable std::vector mCachedJ; // Implementation handle references - MatrixBase* mHnd = nullptr; + MatrixBase* mHnd = nullptr; BackendBase* mProvider = nullptr; }; -} +}// namespace cubool -#endif //CUBOOL_MATRIX_HPP +#endif//CUBOOL_MATRIX_HPP diff --git a/cubool/sources/core/object.cpp b/cubool/sources/core/object.cpp index 550d53f..a74b301 100644 --- a/cubool/sources/core/object.cpp +++ b/cubool/sources/core/object.cpp @@ -22,8 +22,8 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include #include +#include namespace cubool { @@ -34,7 +34,7 @@ namespace cubool { mMarker = s.str(); } - void Object::setDebugMarker(const char *marker) { + void Object::setDebugMarker(const char* marker) { CHECK_RAISE_ERROR(marker, InvalidArgument, "Null pointer marker string"); // Marker = "$marker (address)" @@ -51,4 +51,4 @@ namespace cubool { return mMarker.length() + 1; } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/core/object.hpp b/cubool/sources/core/object.hpp index 75f8a00..868ae2b 100644 --- a/cubool/sources/core/object.hpp +++ b/cubool/sources/core/object.hpp @@ -33,15 +33,15 @@ namespace cubool { class Object { public: Object(); - void setDebugMarker(const char* marker); + void setDebugMarker(const char* marker); const char* getDebugMarker() const; - index getDebugMarkerSizeWithNullT() const; + index getDebugMarkerSizeWithNullT() const; protected: // Marker for debugging std::string mMarker; }; -} +}// namespace cubool -#endif //CUBOOL_OBJECT_HPP +#endif//CUBOOL_OBJECT_HPP diff --git a/cubool/sources/core/vector.cpp b/cubool/sources/core/vector.cpp index ca0ce5d..d5ac0f5 100644 --- a/cubool/sources/core/vector.cpp +++ b/cubool/sources/core/vector.cpp @@ -22,30 +22,30 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include -#include #include #include -#include +#include +#include #include +#include -#define TIMER_ACTION(timer, action) \ - Timer timer; \ - timer.start(); \ - action; \ +#define TIMER_ACTION(timer, action) \ + Timer timer; \ + timer.start(); \ + action; \ timer.end() namespace cubool { - Vector::Vector(size_t nrows, BackendBase &backend) { - mHnd = backend.createVector(nrows); + Vector::Vector(size_t nrows, BackendBase& backend) { + mHnd = backend.createVector(nrows); mProvider = &backend; } Vector::~Vector() { if (mHnd) { mProvider->releaseVector(mHnd); - mHnd = nullptr; + mHnd = nullptr; mProvider = nullptr; } } @@ -57,7 +57,7 @@ namespace cubool { mCachedI.push_back(i); } - void Vector::build(const index *rows, size_t nvals, bool isSorted, bool noDuplicates) { + void Vector::build(const index* rows, size_t nvals, bool isSorted, bool noDuplicates) { CHECK_RAISE_ERROR(rows != nullptr || nvals == 0, InvalidArgument, "Null ptr rows array"); this->releaseCache(); @@ -71,7 +71,7 @@ namespace cubool { mHnd->build(rows, nvals, isSorted, noDuplicates); } - void Vector::extract(index *rows, size_t &nvals) { + void Vector::extract(index* rows, size_t& nvals) { CHECK_RAISE_ERROR(rows != nullptr || getNvals() == 0, InvalidArgument, "Null ptr rows array"); CHECK_RAISE_ERROR(getNvals() <= nvals, InvalidArgument, "Passed arrays size must be more or equal to the nvals of the vector"); @@ -79,7 +79,7 @@ namespace cubool { mHnd->extract(rows, nvals); } - void Vector::extractSubVector(const VectorBase &otherBase, index i, index nrows, bool checkTime) { + void Vector::extractSubVector(const VectorBase& otherBase, index i, index nrows, bool checkTime) { const auto* other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed vector does not belong to core vector class"); @@ -91,7 +91,7 @@ namespace cubool { CHECK_RAISE_ERROR(nrows == this->getNrows(), InvalidArgument, "Result matrix has incompatible size for extracted sub-matrix range"); other->commitCache(); - this->releaseCache(); // Values of this vector won't be used any more + this->releaseCache();// Values of this vector won't be used any more if (checkTime) { TIMER_ACTION(timer, mHnd->extractSubVector(*other->mHnd, i, nrows, false)); @@ -110,7 +110,7 @@ namespace cubool { mHnd->extractSubVector(*other->mHnd, i, nrows, false); } - void Vector::extractRow(const class MatrixBase &matrixBase, index i) { + void Vector::extractRow(const class MatrixBase& matrixBase, index i) { const auto* matrix = dynamic_cast(&matrixBase); CHECK_RAISE_ERROR(matrix != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class"); @@ -122,7 +122,7 @@ namespace cubool { mHnd->extractRow(*matrix->mHnd, i); } - void Vector::extractCol(const class MatrixBase &matrixBase, index j) { + void Vector::extractCol(const class MatrixBase& matrixBase, index j) { const auto* matrix = dynamic_cast(&matrixBase); CHECK_RAISE_ERROR(matrix != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class"); @@ -134,7 +134,7 @@ namespace cubool { mHnd->extractCol(*matrix->mHnd, j); } - void Vector::clone(const VectorBase &otherBase) { + void Vector::clone(const VectorBase& otherBase) { const auto* other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed vector does not belong to core vector class"); @@ -147,12 +147,12 @@ namespace cubool { CHECK_RAISE_ERROR(M == this->getNrows(), InvalidArgument, "Cloned vector has incompatible size"); other->commitCache(); - this->releaseCache(); // Values of this vector won't be used any more + this->releaseCache();// Values of this vector won't be used any more mHnd->clone(*other->mHnd); } - void Vector::reduce(index &result, bool checkTime) { + void Vector::reduce(index& result, bool checkTime) { this->commitCache(); if (checkTime) { @@ -172,15 +172,14 @@ namespace cubool { mHnd->reduce(result, false); } - void Vector::reduceMatrix(const MatrixBase &matrixBase, bool transpose, bool checkTime) { + void Vector::reduceMatrix(const MatrixBase& matrixBase, bool transpose, bool checkTime) { const auto* matrix = dynamic_cast(&matrixBase); CHECK_RAISE_ERROR(matrix != nullptr, InvalidArgument, "Passed matrix does not belong to core matrix class"); if (transpose) { CHECK_RAISE_ERROR(matrix->getNcols() == this->getNrows(), InvalidArgument, "Passed matrix has incompatible size"); - } - else { + } else { CHECK_RAISE_ERROR(matrix->getNrows() == this->getNrows(), InvalidArgument, "Passed matrix has incompatible size"); } @@ -203,7 +202,7 @@ namespace cubool { mHnd->reduceMatrix(*matrix->mHnd, transpose, false); } - void Vector::eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) { + void Vector::eWiseMult(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) { const auto* a = dynamic_cast(&aBase); const auto* b = dynamic_cast(&bBase); @@ -236,7 +235,7 @@ namespace cubool { mHnd->eWiseMult(*a->mHnd, *b->mHnd, false); } - void Vector::eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) { + void Vector::eWiseAdd(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) { const auto* a = dynamic_cast(&aBase); const auto* b = dynamic_cast(&bBase); @@ -269,7 +268,7 @@ namespace cubool { mHnd->eWiseAdd(*a->mHnd, *b->mHnd, false); } - void Vector::multiplyVxM(const VectorBase &vBase, const class MatrixBase &mBase, bool checkTime) { + void Vector::multiplyVxM(const VectorBase& vBase, const class MatrixBase& mBase, bool checkTime) { const auto* v = dynamic_cast(&vBase); const auto* m = dynamic_cast(&mBase); @@ -300,7 +299,7 @@ namespace cubool { mHnd->multiplyVxM(*v->mHnd, *m->mHnd, false); } - void Vector::multiplyMxV(const class MatrixBase &mBase, const VectorBase &vBase, bool checkTime) { + void Vector::multiplyMxV(const class MatrixBase& mBase, const VectorBase& vBase, bool checkTime) { const auto* v = dynamic_cast(&vBase); const auto* m = dynamic_cast(&mBase); @@ -351,7 +350,7 @@ namespace cubool { if (cachedNvals == 0) return; - bool isSorted = false; + bool isSorted = false; bool noDuplicates = false; if (mHnd->getNvals() > 0) { @@ -362,8 +361,7 @@ namespace cubool { tmp->build(mCachedI.data(), cachedNvals, isSorted, noDuplicates); mHnd->eWiseAdd(*mHnd, *tmp, false); mProvider->releaseVector(tmp); - } - else { + } else { // Otherwise, new values are used to build vector content mHnd->build(mCachedI.data(), cachedNvals, isSorted, noDuplicates); } @@ -372,4 +370,4 @@ namespace cubool { releaseCache(); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/core/vector.hpp b/cubool/sources/core/vector.hpp index f1aba19..68b05bc 100644 --- a/cubool/sources/core/vector.hpp +++ b/cubool/sources/core/vector.hpp @@ -25,33 +25,33 @@ #ifndef CUBOOL_VECTOR_HPP #define CUBOOL_VECTOR_HPP +#include +#include #include #include -#include -#include -#include #include +#include namespace cubool { - class Vector final: public VectorBase, public Object { + class Vector final : public VectorBase, public Object { public: Vector(size_t nrows, BackendBase& backendBase); ~Vector() override; void setElement(index i) override; - void build(const index *rows, size_t nvals, bool isSorted, bool noDuplicates) override; - void extract(index *rows, size_t &nvals) override; - void extractSubVector(const VectorBase &otherBase, index i, index nrows, bool checkTime) override; + void build(const index* rows, size_t nvals, bool isSorted, bool noDuplicates) override; + void extract(index* rows, size_t& nvals) override; + void extractSubVector(const VectorBase& otherBase, index i, index nrows, bool checkTime) override; void extractRow(const class MatrixBase& matrixBase, index i) override; void extractCol(const class MatrixBase& matrixBase, index j) override; - void clone(const VectorBase &otherBase) override; - void reduce(index &result, bool checkTime) override; - void reduceMatrix(const MatrixBase &matrix, bool transpose, bool checkTime) override; + void clone(const VectorBase& otherBase) override; + void reduce(index& result, bool checkTime) override; + void reduceMatrix(const MatrixBase& matrix, bool transpose, bool checkTime) override; - void eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override; - void eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override; + void eWiseMult(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) override; + void eWiseAdd(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) override; void multiplyVxM(const VectorBase& vBase, const class MatrixBase& mBase, bool checkTime) override; void multiplyMxV(const class MatrixBase& mBase, const VectorBase& vBase, bool checkTime) override; @@ -59,7 +59,6 @@ namespace cubool { index getNvals() const override; private: - void releaseCache() const; void commitCache() const; @@ -67,10 +66,10 @@ namespace cubool { mutable std::vector mCachedI; // Implementation handle references - VectorBase* mHnd = nullptr; + VectorBase* mHnd = nullptr; BackendBase* mProvider = nullptr; }; -} +}// namespace cubool -#endif //CUBOOL_VECTOR_HPP \ No newline at end of file +#endif//CUBOOL_VECTOR_HPP \ No newline at end of file diff --git a/cubool/sources/core/version.hpp b/cubool/sources/core/version.hpp index 13aec3e..9e2dd96 100644 --- a/cubool/sources/core/version.hpp +++ b/cubool/sources/core/version.hpp @@ -34,4 +34,4 @@ /** Defined in cmake */ #define CUBOOL_SUB CUBOOL_VERSION_SUB -#endif //CUBOOL_VERSION_HPP +#endif//CUBOOL_VERSION_HPP diff --git a/cubool/sources/cuBool_Common.hpp b/cubool/sources/cuBool_Common.hpp index 0da816d..38842a4 100644 --- a/cubool/sources/cuBool_Common.hpp +++ b/cubool/sources/cuBool_Common.hpp @@ -25,35 +25,36 @@ #ifndef CUBOOL_CUBOOL_COMMON_HPP #define CUBOOL_CUBOOL_COMMON_HPP -#include #include -#include #include #include #include #include +#include #include +#include // State validation -#define CUBOOL_VALIDATE_LIBRARY \ +#define CUBOOL_VALIDATE_LIBRARY \ cubool::Library::validate(); // Arguments validation -#define CUBOOL_ARG_NOT_NULL(arg) \ +#define CUBOOL_ARG_NOT_NULL(arg) \ CHECK_RAISE_ERROR(arg != nullptr, InvalidArgument, "Passed null argument") -#define CUBOOL_BEGIN_BODY \ +#define CUBOOL_BEGIN_BODY \ try { -#define CUBOOL_END_BODY } \ - catch (const cubool::Error& err) { \ - cubool::Library::handleError(err); \ - return err.getStatus(); \ - } \ - catch (const std::exception& exc) { \ - cubool::Library::handleError(exc); \ - return CUBOOL_STATUS_ERROR; \ - } \ +#define CUBOOL_END_BODY \ + } \ + catch (const cubool::Error& err) { \ + cubool::Library::handleError(err); \ + return err.getStatus(); \ + } \ + catch (const std::exception& exc) { \ + cubool::Library::handleError(exc); \ + return CUBOOL_STATUS_ERROR; \ + } \ return cuBool_Status::CUBOOL_STATUS_SUCCESS; -#endif //CUBOOL_CUBOOL_COMMON_HPP +#endif//CUBOOL_CUBOOL_COMMON_HPP diff --git a/cubool/sources/cuBool_Finalize.cpp b/cubool/sources/cuBool_Finalize.cpp index e650cf0..419206f 100644 --- a/cubool/sources/cuBool_Finalize.cpp +++ b/cubool/sources/cuBool_Finalize.cpp @@ -24,10 +24,9 @@ #include -cuBool_Status cuBool_Finalize( -) { +cuBool_Status cuBool_Finalize() { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - cubool::Library::finalize(); + CUBOOL_VALIDATE_LIBRARY + cubool::Library::finalize(); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_GetAbout.cpp b/cubool/sources/cuBool_GetAbout.cpp index 151cb3a..8f28a24 100644 --- a/cubool/sources/cuBool_GetAbout.cpp +++ b/cubool/sources/cuBool_GetAbout.cpp @@ -26,16 +26,16 @@ const char* cuBool_GetAbout() { static const char about[] = - "CuBool is a linear boolean algebra library primitives and operations for \n" - "work with dense and sparse matrices written on the NVIDIA CUDA platform. The primary \n" - "goal of the library is implementation, testing and profiling algorithms for\n" - "solving *formal-language-constrained problems*, such as *context-free* \n" - "and *recursive* path queries with various semantics for graph databases." - "" - "Contributors:" - "- Egor Orachyov (Github: https://github.com/EgorOrachyov)\n" - "- Pavel Alimov (Github : https://github.com/Krekep)\n" - "- Semyon Grigorev (Github: https://github.com/gsvgit)"; + "CuBool is a linear boolean algebra library primitives and operations for \n" + "work with dense and sparse matrices written on the NVIDIA CUDA platform. The primary \n" + "goal of the library is implementation, testing and profiling algorithms for\n" + "solving *formal-language-constrained problems*, such as *context-free* \n" + "and *recursive* path queries with various semantics for graph databases." + "" + "Contributors:" + "- Egor Orachyov (Github: https://github.com/EgorOrachyov)\n" + "- Pavel Alimov (Github : https://github.com/Krekep)\n" + "- Semyon Grigorev (Github: https://github.com/gsvgit)"; return about; } \ No newline at end of file diff --git a/cubool/sources/cuBool_GetDeviceCaps.cpp b/cubool/sources/cuBool_GetDeviceCaps.cpp index 90fb5d6..1db60db 100644 --- a/cubool/sources/cuBool_GetDeviceCaps.cpp +++ b/cubool/sources/cuBool_GetDeviceCaps.cpp @@ -25,11 +25,10 @@ #include cuBool_Status cuBool_GetDeviceCaps( - cuBool_DeviceCaps* deviceCaps -) { + cuBool_DeviceCaps* deviceCaps) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(deviceCaps) - cubool::Library::queryCapabilities(*deviceCaps); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(deviceCaps) + cubool::Library::queryCapabilities(*deviceCaps); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_GetLicenseInfo.cpp b/cubool/sources/cuBool_GetLicenseInfo.cpp index fc04105..d3f22e4 100644 --- a/cubool/sources/cuBool_GetLicenseInfo.cpp +++ b/cubool/sources/cuBool_GetLicenseInfo.cpp @@ -26,27 +26,27 @@ const char* cuBool_GetLicenseInfo() { static const char license[] = - "MIT License\n" - "\n" - "Copyright (c) 2020 JetBrains-Research\n" - "\n" - "Permission is hereby granted, free of charge, to any person obtaining a copy\n" - "of this software and associated documentation files (the \"Software\"), to deal\n" - "in the Software without restriction, including without limitation the rights\n" - "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n" - "copies of the Software, and to permit persons to whom the Software is\n" - "furnished to do so, subject to the following conditions:\n" - "\n" - "The above copyright notice and this permission notice shall be included in all\n" - "copies or substantial portions of the Software.\n" - "\n" - "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n" - "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n" - "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n" - "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n" - "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n" - "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" - "SOFTWARE."; + "MIT License\n" + "\n" + "Copyright (c) 2020 JetBrains-Research\n" + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy\n" + "of this software and associated documentation files (the \"Software\"), to deal\n" + "in the Software without restriction, including without limitation the rights\n" + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n" + "copies of the Software, and to permit persons to whom the Software is\n" + "furnished to do so, subject to the following conditions:\n" + "\n" + "The above copyright notice and this permission notice shall be included in all\n" + "copies or substantial portions of the Software.\n" + "\n" + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n" + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n" + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n" + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n" + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n" + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" + "SOFTWARE."; return license; } \ No newline at end of file diff --git a/cubool/sources/cuBool_GetVersion.cpp b/cubool/sources/cuBool_GetVersion.cpp index 8b2d288..c1617f3 100644 --- a/cubool/sources/cuBool_GetVersion.cpp +++ b/cubool/sources/cuBool_GetVersion.cpp @@ -25,13 +25,12 @@ #include cuBool_Status cuBool_GetVersion( - int *major, - int *minor, - int *sub -) { - auto MAJOR = (uint32_t)(CUBOOL_MAJOR); - auto MINOR = (uint32_t)(CUBOOL_MINOR); - auto SUB = (uint32_t)(CUBOOL_SUB); + int* major, + int* minor, + int* sub) { + auto MAJOR = (uint32_t) (CUBOOL_MAJOR); + auto MINOR = (uint32_t) (CUBOOL_MINOR); + auto SUB = (uint32_t) (CUBOOL_SUB); if (major) *major = MAJOR; diff --git a/cubool/sources/cuBool_Initialize.cpp b/cubool/sources/cuBool_Initialize.cpp index 820c065..be31c96 100644 --- a/cubool/sources/cuBool_Initialize.cpp +++ b/cubool/sources/cuBool_Initialize.cpp @@ -25,10 +25,8 @@ #include cuBool_Status cuBool_Initialize( - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - cubool::Library::initialize(hints); + cubool::Library::initialize(hints); CUBOOL_END_BODY } - diff --git a/cubool/sources/cuBool_Kronecker.cpp b/cubool/sources/cuBool_Kronecker.cpp index 4f11b64..358df8f 100644 --- a/cubool/sources/cuBool_Kronecker.cpp +++ b/cubool/sources/cuBool_Kronecker.cpp @@ -28,16 +28,15 @@ cuBool_Status cuBool_Kronecker( cuBool_Matrix result, cuBool_Matrix left, cuBool_Matrix right, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(left) - CUBOOL_ARG_NOT_NULL(right) - auto resultM = (cubool::Matrix *) result; - auto leftM = (cubool::Matrix *) left; - auto rightM = (cubool::Matrix *) right; - resultM->kronecker(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(left) + CUBOOL_ARG_NOT_NULL(right) + auto resultM = (cubool::Matrix*) result; + auto leftM = (cubool::Matrix*) left; + auto rightM = (cubool::Matrix*) right; + resultM->kronecker(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_Build.cpp b/cubool/sources/cuBool_Matrix_Build.cpp index 8ca6d3e..114527f 100644 --- a/cubool/sources/cuBool_Matrix_Build.cpp +++ b/cubool/sources/cuBool_Matrix_Build.cpp @@ -25,16 +25,15 @@ #include cuBool_Status cuBool_Matrix_Build( - cuBool_Matrix matrix, - const cuBool_Index *rows, - const cuBool_Index *cols, - cuBool_Index nvals, - cuBool_Hints hints -) { + cuBool_Matrix matrix, + const cuBool_Index* rows, + const cuBool_Index* cols, + cuBool_Index nvals, + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - auto m = (cubool::Matrix *) matrix; - m->build(rows, cols, nvals, hints & CUBOOL_HINT_VALUES_SORTED, hints & CUBOOL_HINT_NO_DUPLICATES); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + auto m = (cubool::Matrix*) matrix; + m->build(rows, cols, nvals, hints & CUBOOL_HINT_VALUES_SORTED, hints & CUBOOL_HINT_NO_DUPLICATES); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_Duplicate.cpp b/cubool/sources/cuBool_Matrix_Duplicate.cpp index de47b15..f9dc5f0 100644 --- a/cubool/sources/cuBool_Matrix_Duplicate.cpp +++ b/cubool/sources/cuBool_Matrix_Duplicate.cpp @@ -25,16 +25,15 @@ #include cuBool_Status cuBool_Matrix_Duplicate( - cuBool_Matrix matrix, - cuBool_Matrix *duplicated -) { + cuBool_Matrix matrix, + cuBool_Matrix* duplicated) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - CUBOOL_ARG_NOT_NULL(duplicated) - auto m = (cubool::Matrix *) matrix; - auto d = cubool::Library::createMatrix(m->getNrows(), m->getNcols()); - d->clone(*m); - *duplicated = (cuBool_Matrix_t *) d; + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + CUBOOL_ARG_NOT_NULL(duplicated) + auto m = (cubool::Matrix*) matrix; + auto d = cubool::Library::createMatrix(m->getNrows(), m->getNcols()); + d->clone(*m); + *duplicated = (cuBool_Matrix_t*) d; CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_EWiseAdd.cpp b/cubool/sources/cuBool_Matrix_EWiseAdd.cpp index e8fe446..cc43d12 100644 --- a/cubool/sources/cuBool_Matrix_EWiseAdd.cpp +++ b/cubool/sources/cuBool_Matrix_EWiseAdd.cpp @@ -28,16 +28,15 @@ cuBool_Status cuBool_Matrix_EWiseAdd( cuBool_Matrix result, cuBool_Matrix left, cuBool_Matrix right, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(left) - CUBOOL_ARG_NOT_NULL(right) - auto resultM = (cubool::Matrix *) result; - auto leftM = (cubool::Matrix *) left; - auto rightM = (cubool::Matrix *) right; - resultM->eWiseAdd(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(left) + CUBOOL_ARG_NOT_NULL(right) + auto resultM = (cubool::Matrix*) result; + auto leftM = (cubool::Matrix*) left; + auto rightM = (cubool::Matrix*) right; + resultM->eWiseAdd(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_EWiseMult.cpp b/cubool/sources/cuBool_Matrix_EWiseMult.cpp index bfaf194..0edbd10 100644 --- a/cubool/sources/cuBool_Matrix_EWiseMult.cpp +++ b/cubool/sources/cuBool_Matrix_EWiseMult.cpp @@ -28,16 +28,15 @@ cuBool_Status cuBool_Matrix_EWiseMult( cuBool_Matrix result, cuBool_Matrix left, cuBool_Matrix right, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(left) - CUBOOL_ARG_NOT_NULL(right) - auto resultM = (cubool::Matrix *) result; - auto leftM = (cubool::Matrix *) left; - auto rightM = (cubool::Matrix *) right; - resultM->eWiseMult(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(left) + CUBOOL_ARG_NOT_NULL(right) + auto resultM = (cubool::Matrix*) result; + auto leftM = (cubool::Matrix*) left; + auto rightM = (cubool::Matrix*) right; + resultM->eWiseMult(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_EWiseMultInverted.cpp b/cubool/sources/cuBool_Matrix_EWiseMultInverted.cpp index 37fe607..c157129 100644 --- a/cubool/sources/cuBool_Matrix_EWiseMultInverted.cpp +++ b/cubool/sources/cuBool_Matrix_EWiseMultInverted.cpp @@ -25,20 +25,19 @@ #include CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseMulInverted( - cuBool_Matrix result, - cuBool_Matrix matrix, - cuBool_Matrix mask, - cuBool_Hints hints -) { + cuBool_Matrix result, + cuBool_Matrix matrix, + cuBool_Matrix mask, + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(matrix) - CUBOOL_ARG_NOT_NULL(mask) - auto resultM = (cubool::Matrix *) result; - auto matrixM = (cubool::Matrix *) matrix; - auto maskM = (cubool::Matrix *) mask; + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(matrix) + CUBOOL_ARG_NOT_NULL(mask) + auto resultM = (cubool::Matrix*) result; + auto matrixM = (cubool::Matrix*) matrix; + auto maskM = (cubool::Matrix*) mask; - resultM->eWiseMultInverted(*matrixM, *maskM, hints & CUBOOL_HINT_TIME_CHECK); + resultM->eWiseMultInverted(*matrixM, *maskM, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } diff --git a/cubool/sources/cuBool_Matrix_ExtractCol.cpp b/cubool/sources/cuBool_Matrix_ExtractCol.cpp index 92fcf34..a90dd86 100644 --- a/cubool/sources/cuBool_Matrix_ExtractCol.cpp +++ b/cubool/sources/cuBool_Matrix_ExtractCol.cpp @@ -27,14 +27,13 @@ cuBool_Status cuBool_Matrix_ExtractCol( cuBool_Vector result, cuBool_Matrix matrix, - cuBool_Index j, - cuBool_Hints hints -) { + cuBool_Index j, + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(matrix) - auto r = (cubool::Vector*) result; - auto m = (cubool::Matrix*) matrix; - r->extractCol(*m, j); + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(matrix) + auto r = (cubool::Vector*) result; + auto m = (cubool::Matrix*) matrix; + r->extractCol(*m, j); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_ExtractPairs.cpp b/cubool/sources/cuBool_Matrix_ExtractPairs.cpp index 8a9087c..d3c2ade 100644 --- a/cubool/sources/cuBool_Matrix_ExtractPairs.cpp +++ b/cubool/sources/cuBool_Matrix_ExtractPairs.cpp @@ -26,17 +26,16 @@ cuBool_Status cuBool_Matrix_ExtractPairs( cuBool_Matrix matrix, - cuBool_Index *rows, - cuBool_Index *cols, - cuBool_Index *nvals -) { + cuBool_Index* rows, + cuBool_Index* cols, + cuBool_Index* nvals) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - CUBOOL_ARG_NOT_NULL(nvals) - auto m = (cubool::Matrix *) matrix; - size_t count = *nvals; - m->extract(rows, cols, count); - *nvals = count; + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + CUBOOL_ARG_NOT_NULL(nvals) + auto m = (cubool::Matrix*) matrix; + size_t count = *nvals; + m->extract(rows, cols, count); + *nvals = count; CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_ExtractRow.cpp b/cubool/sources/cuBool_Matrix_ExtractRow.cpp index a197570..70f0df3 100644 --- a/cubool/sources/cuBool_Matrix_ExtractRow.cpp +++ b/cubool/sources/cuBool_Matrix_ExtractRow.cpp @@ -27,14 +27,13 @@ cuBool_Status cuBool_Matrix_ExtractRow( cuBool_Vector result, cuBool_Matrix matrix, - cuBool_Index i, - cuBool_Hints hints -) { + cuBool_Index i, + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(matrix) - auto r = (cubool::Vector*) result; - auto m = (cubool::Matrix*) matrix; - r->extractRow(*m, i); + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(matrix) + auto r = (cubool::Vector*) result; + auto m = (cubool::Matrix*) matrix; + r->extractRow(*m, i); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_ExtractSubMatrix.cpp b/cubool/sources/cuBool_Matrix_ExtractSubMatrix.cpp index aa061ba..3ad5275 100644 --- a/cubool/sources/cuBool_Matrix_ExtractSubMatrix.cpp +++ b/cubool/sources/cuBool_Matrix_ExtractSubMatrix.cpp @@ -27,18 +27,17 @@ cuBool_Status cuBool_Matrix_ExtractSubMatrix( cuBool_Matrix result, cuBool_Matrix matrix, - cuBool_Index i, - cuBool_Index j, - cuBool_Index nrows, - cuBool_Index ncols, - cuBool_Hints hints -) { + cuBool_Index i, + cuBool_Index j, + cuBool_Index nrows, + cuBool_Index ncols, + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(matrix) - auto r = (cubool::Matrix*) result; - auto m = (cubool::Matrix*) matrix; - r->extractSubMatrix(*m, i, j, nrows, ncols, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(matrix) + auto r = (cubool::Matrix*) result; + auto m = (cubool::Matrix*) matrix; + r->extractSubMatrix(*m, i, j, nrows, ncols, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_Free.cpp b/cubool/sources/cuBool_Matrix_Free.cpp index 9769a9d..5e15a47 100644 --- a/cubool/sources/cuBool_Matrix_Free.cpp +++ b/cubool/sources/cuBool_Matrix_Free.cpp @@ -25,11 +25,10 @@ #include cuBool_Status cuBool_Matrix_Free( - cuBool_Matrix matrix -) { + cuBool_Matrix matrix) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - auto m = (cubool::Matrix *) matrix; - cubool::Library::releaseMatrix(m); + CUBOOL_VALIDATE_LIBRARY + auto m = (cubool::Matrix*) matrix; + cubool::Library::releaseMatrix(m); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_Marker.cpp b/cubool/sources/cuBool_Matrix_Marker.cpp index 399d17e..5125bd4 100644 --- a/cubool/sources/cuBool_Matrix_Marker.cpp +++ b/cubool/sources/cuBool_Matrix_Marker.cpp @@ -22,33 +22,32 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include -#include #include +#include +#include cuBool_Status cuBool_Matrix_Marker( cuBool_Matrix matrix, - char* marker, - cuBool_Index* size -) { + char* marker, + cuBool_Index* size) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - CUBOOL_ARG_NOT_NULL(size) + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + CUBOOL_ARG_NOT_NULL(size) - auto m = (cubool::Matrix*) matrix; - auto actualSize = m->getDebugMarkerSizeWithNullT(); - auto toCopy = std::min(*size, actualSize); + auto m = (cubool::Matrix*) matrix; + auto actualSize = m->getDebugMarkerSizeWithNullT(); + auto toCopy = std::min(*size, actualSize); - if (marker != nullptr && toCopy > 0) { - // C str (with \0) - const auto* text = m->getDebugMarker(); - std::memcpy(marker, text, toCopy); + if (marker != nullptr && toCopy > 0) { + // C str (with \0) + const auto* text = m->getDebugMarker(); + std::memcpy(marker, text, toCopy); - // Explicitly terminate (for case size < actualSize) - marker[toCopy - 1] = '\0'; - } + // Explicitly terminate (for case size < actualSize) + marker[toCopy - 1] = '\0'; + } - *size = actualSize; + *size = actualSize; CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_Ncols.cpp b/cubool/sources/cuBool_Matrix_Ncols.cpp index 617e9ee..42305fb 100644 --- a/cubool/sources/cuBool_Matrix_Ncols.cpp +++ b/cubool/sources/cuBool_Matrix_Ncols.cpp @@ -26,13 +26,12 @@ cuBool_Status cuBool_Matrix_Ncols( cuBool_Matrix matrix, - cuBool_Index *ncols -) { + cuBool_Index* ncols) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - CUBOOL_ARG_NOT_NULL(ncols) - auto m = (cubool::Matrix *) matrix; - *ncols = m->getNcols(); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + CUBOOL_ARG_NOT_NULL(ncols) + auto m = (cubool::Matrix*) matrix; + *ncols = m->getNcols(); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_New.cpp b/cubool/sources/cuBool_Matrix_New.cpp index 37897de..e947b62 100644 --- a/cubool/sources/cuBool_Matrix_New.cpp +++ b/cubool/sources/cuBool_Matrix_New.cpp @@ -25,13 +25,12 @@ #include cuBool_Status cuBool_Matrix_New( - cuBool_Matrix *matrix, - cuBool_Index nrows, - cuBool_Index ncols -) { + cuBool_Matrix* matrix, + cuBool_Index nrows, + cuBool_Index ncols) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - *matrix = (cuBool_Matrix_t *) cubool::Library::createMatrix(nrows, ncols); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + *matrix = (cuBool_Matrix_t*) cubool::Library::createMatrix(nrows, ncols); CUBOOL_END_BODY } diff --git a/cubool/sources/cuBool_Matrix_Nrows.cpp b/cubool/sources/cuBool_Matrix_Nrows.cpp index 247715c..85e7544 100644 --- a/cubool/sources/cuBool_Matrix_Nrows.cpp +++ b/cubool/sources/cuBool_Matrix_Nrows.cpp @@ -26,13 +26,12 @@ cuBool_Status cuBool_Matrix_Nrows( cuBool_Matrix matrix, - cuBool_Index *nrows -) { + cuBool_Index* nrows) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - CUBOOL_ARG_NOT_NULL(nrows) - auto m = (cubool::Matrix *) matrix; - *nrows = m->getNrows(); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + CUBOOL_ARG_NOT_NULL(nrows) + auto m = (cubool::Matrix*) matrix; + *nrows = m->getNrows(); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_Nvals.cpp b/cubool/sources/cuBool_Matrix_Nvals.cpp index 383694f..6490055 100644 --- a/cubool/sources/cuBool_Matrix_Nvals.cpp +++ b/cubool/sources/cuBool_Matrix_Nvals.cpp @@ -26,13 +26,12 @@ cuBool_Status cuBool_Matrix_Nvals( cuBool_Matrix matrix, - cuBool_Index *nvals -) { + cuBool_Index* nvals) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - CUBOOL_ARG_NOT_NULL(nvals) - auto m = (cubool::Matrix *) matrix; - *nvals = m->getNvals(); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + CUBOOL_ARG_NOT_NULL(nvals) + auto m = (cubool::Matrix*) matrix; + *nvals = m->getNvals(); CUBOOL_END_BODY } diff --git a/cubool/sources/cuBool_Matrix_Reduce.cpp b/cubool/sources/cuBool_Matrix_Reduce.cpp index 461d0e6..ca54b89 100644 --- a/cubool/sources/cuBool_Matrix_Reduce.cpp +++ b/cubool/sources/cuBool_Matrix_Reduce.cpp @@ -27,14 +27,13 @@ cuBool_Status cuBool_Matrix_Reduce( cuBool_Vector result, cuBool_Matrix matrix, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(matrix) - auto r = (cubool::Vector*) result; - auto m = (cubool::Matrix*) matrix; - r->reduceMatrix(*m, hints & CUBOOL_HINT_TRANSPOSE,hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(matrix) + auto r = (cubool::Vector*) result; + auto m = (cubool::Matrix*) matrix; + r->reduceMatrix(*m, hints & CUBOOL_HINT_TRANSPOSE, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_Reduce2.cpp b/cubool/sources/cuBool_Matrix_Reduce2.cpp index 7496e1c..bac0706 100644 --- a/cubool/sources/cuBool_Matrix_Reduce2.cpp +++ b/cubool/sources/cuBool_Matrix_Reduce2.cpp @@ -27,14 +27,13 @@ cuBool_Status cuBool_Matrix_Reduce2( cuBool_Matrix result, cuBool_Matrix matrix, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(matrix) - auto r = (cubool::Matrix*) result; - auto m = (cubool::Matrix*) matrix; - r->reduce(*m, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(matrix) + auto r = (cubool::Matrix*) result; + auto m = (cubool::Matrix*) matrix; + r->reduce(*m, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_SetElement.cpp b/cubool/sources/cuBool_Matrix_SetElement.cpp index a942f2e..b61871a 100644 --- a/cubool/sources/cuBool_Matrix_SetElement.cpp +++ b/cubool/sources/cuBool_Matrix_SetElement.cpp @@ -26,13 +26,12 @@ cuBool_Status cuBool_Matrix_SetElement( cuBool_Matrix matrix, - cuBool_Index i, - cuBool_Index j -) { + cuBool_Index i, + cuBool_Index j) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - auto m = (cubool::Matrix*) matrix; - m->setElement(i, j); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + auto m = (cubool::Matrix*) matrix; + m->setElement(i, j); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_SetMarker.cpp b/cubool/sources/cuBool_Matrix_SetMarker.cpp index 8296643..c0548ff 100644 --- a/cubool/sources/cuBool_Matrix_SetMarker.cpp +++ b/cubool/sources/cuBool_Matrix_SetMarker.cpp @@ -26,13 +26,12 @@ cuBool_Status cuBool_Matrix_SetMarker( cuBool_Matrix matrix, - const char* marker -) { + const char* marker) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(matrix) - CUBOOL_ARG_NOT_NULL(marker) - auto m = (cubool::Matrix*) matrix; - m->setDebugMarker(marker); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(matrix) + CUBOOL_ARG_NOT_NULL(marker) + auto m = (cubool::Matrix*) matrix; + m->setDebugMarker(marker); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Matrix_Transpose.cpp b/cubool/sources/cuBool_Matrix_Transpose.cpp index a7d3e4d..6832060 100644 --- a/cubool/sources/cuBool_Matrix_Transpose.cpp +++ b/cubool/sources/cuBool_Matrix_Transpose.cpp @@ -27,14 +27,13 @@ cuBool_Status cuBool_Matrix_Transpose( cuBool_Matrix result, cuBool_Matrix matrix, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(matrix) - auto r = (cubool::Matrix *) result; - auto m = (cubool::Matrix *) matrix; - r->transpose(*m, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(matrix) + auto r = (cubool::Matrix*) result; + auto m = (cubool::Matrix*) matrix; + r->transpose(*m, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_MxM.cpp b/cubool/sources/cuBool_MxM.cpp index 5bfb9e7..464bb05 100644 --- a/cubool/sources/cuBool_MxM.cpp +++ b/cubool/sources/cuBool_MxM.cpp @@ -28,16 +28,15 @@ cuBool_Status cuBool_MxM( cuBool_Matrix result, cuBool_Matrix left, cuBool_Matrix right, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(left) - CUBOOL_ARG_NOT_NULL(right) - auto resultM = (cubool::Matrix *) result; - auto leftM = (cubool::Matrix *) left; - auto rightM = (cubool::Matrix *) right; - resultM->multiply(*leftM, *rightM, hints & CUBOOL_HINT_ACCUMULATE, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(left) + CUBOOL_ARG_NOT_NULL(right) + auto resultM = (cubool::Matrix*) result; + auto leftM = (cubool::Matrix*) left; + auto rightM = (cubool::Matrix*) right; + resultM->multiply(*leftM, *rightM, hints & CUBOOL_HINT_ACCUMULATE, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_MxV.cpp b/cubool/sources/cuBool_MxV.cpp index cc97147..25e423d 100644 --- a/cubool/sources/cuBool_MxV.cpp +++ b/cubool/sources/cuBool_MxV.cpp @@ -28,16 +28,15 @@ cuBool_Status cuBool_MxV( cuBool_Vector result, cuBool_Matrix matrix, cuBool_Vector vector, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(matrix) - CUBOOL_ARG_NOT_NULL(vector) - auto resultV = (cubool::Vector *) result; - auto left = (cubool::Matrix *) matrix; - auto right = (cubool::Vector *) vector; - resultV->multiplyMxV(*left, *right, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(matrix) + CUBOOL_ARG_NOT_NULL(vector) + auto resultV = (cubool::Vector*) result; + auto left = (cubool::Matrix*) matrix; + auto right = (cubool::Vector*) vector; + resultV->multiplyMxV(*left, *right, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_SetupLogger.cpp b/cubool/sources/cuBool_SetupLogger.cpp index b149bc0..8cf21fe 100644 --- a/cubool/sources/cuBool_SetupLogger.cpp +++ b/cubool/sources/cuBool_SetupLogger.cpp @@ -25,10 +25,9 @@ #include cuBool_Status cuBool_SetupLogging( - const char* logFileName, - cuBool_Hints hints -) { + const char* logFileName, + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - cubool::Library::setupLogging(logFileName, hints); + cubool::Library::setupLogging(logFileName, hints); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_Build.cpp b/cubool/sources/cuBool_Vector_Build.cpp index 6bc3926..64fc09f 100644 --- a/cubool/sources/cuBool_Vector_Build.cpp +++ b/cubool/sources/cuBool_Vector_Build.cpp @@ -25,15 +25,14 @@ #include cuBool_Status cuBool_Vector_Build( - cuBool_Vector vector, + cuBool_Vector vector, const cuBool_Index* rows, - cuBool_Index nvals, - cuBool_Hints hints -) { + cuBool_Index nvals, + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(vector) - auto v = (cubool::Vector *) vector; - v->build(rows, nvals, hints & CUBOOL_HINT_VALUES_SORTED, hints & CUBOOL_HINT_NO_DUPLICATES); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(vector) + auto v = (cubool::Vector*) vector; + v->build(rows, nvals, hints & CUBOOL_HINT_VALUES_SORTED, hints & CUBOOL_HINT_NO_DUPLICATES); CUBOOL_END_BODY } diff --git a/cubool/sources/cuBool_Vector_Duplicate.cpp b/cubool/sources/cuBool_Vector_Duplicate.cpp index 085587e..65b5f82 100644 --- a/cubool/sources/cuBool_Vector_Duplicate.cpp +++ b/cubool/sources/cuBool_Vector_Duplicate.cpp @@ -25,16 +25,15 @@ #include cuBool_Status cuBool_Vector_Duplicate( - cuBool_Vector vector, - cuBool_Vector* duplicated -) { + cuBool_Vector vector, + cuBool_Vector* duplicated) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(vector) - CUBOOL_ARG_NOT_NULL(duplicated) - auto v = (cubool::Vector *) vector; - auto d = cubool::Library::createVector(v->getNrows()); - d->clone(*v); - *duplicated = (cuBool_Vector_t *) d; + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(vector) + CUBOOL_ARG_NOT_NULL(duplicated) + auto v = (cubool::Vector*) vector; + auto d = cubool::Library::createVector(v->getNrows()); + d->clone(*v); + *duplicated = (cuBool_Vector_t*) d; CUBOOL_END_BODY } diff --git a/cubool/sources/cuBool_Vector_EWiseAdd.cpp b/cubool/sources/cuBool_Vector_EWiseAdd.cpp index 6a9c949..816aed7 100644 --- a/cubool/sources/cuBool_Vector_EWiseAdd.cpp +++ b/cubool/sources/cuBool_Vector_EWiseAdd.cpp @@ -28,16 +28,15 @@ cuBool_Status cuBool_Vector_EWiseAdd( cuBool_Vector result, cuBool_Vector left, cuBool_Vector right, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(left) - CUBOOL_ARG_NOT_NULL(right) - auto resultM = (cubool::Vector *) result; - auto leftM = (cubool::Vector *) left; - auto rightM = (cubool::Vector *) right; - resultM->eWiseAdd(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(left) + CUBOOL_ARG_NOT_NULL(right) + auto resultM = (cubool::Vector*) result; + auto leftM = (cubool::Vector*) left; + auto rightM = (cubool::Vector*) right; + resultM->eWiseAdd(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_EWiseMult.cpp b/cubool/sources/cuBool_Vector_EWiseMult.cpp index 0777f0a..9dc6c10 100644 --- a/cubool/sources/cuBool_Vector_EWiseMult.cpp +++ b/cubool/sources/cuBool_Vector_EWiseMult.cpp @@ -28,16 +28,15 @@ cuBool_Status cuBool_Vector_EWiseMult( cuBool_Vector result, cuBool_Vector left, cuBool_Vector right, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(left) - CUBOOL_ARG_NOT_NULL(right) - auto resultM = (cubool::Vector *) result; - auto leftM = (cubool::Vector *) left; - auto rightM = (cubool::Vector *) right; - resultM->eWiseMult(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(left) + CUBOOL_ARG_NOT_NULL(right) + auto resultM = (cubool::Vector*) result; + auto leftM = (cubool::Vector*) left; + auto rightM = (cubool::Vector*) right; + resultM->eWiseMult(*leftM, *rightM, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_ExtractSubVector.cpp b/cubool/sources/cuBool_Vector_ExtractSubVector.cpp index 55cda77..824549f 100644 --- a/cubool/sources/cuBool_Vector_ExtractSubVector.cpp +++ b/cubool/sources/cuBool_Vector_ExtractSubVector.cpp @@ -27,16 +27,15 @@ cuBool_Status cuBool_Vector_ExtractSubVector( cuBool_Vector result, cuBool_Vector vector, - cuBool_Index i, - cuBool_Index nrows, - cuBool_Hints hints -) { + cuBool_Index i, + cuBool_Index nrows, + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(vector) - auto r = (cubool::Vector*) result; - auto v = (cubool::Vector*) vector; - r->extractSubVector(*v, i, nrows, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(vector) + auto r = (cubool::Vector*) result; + auto v = (cubool::Vector*) vector; + r->extractSubVector(*v, i, nrows, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } diff --git a/cubool/sources/cuBool_Vector_ExtractValues.cpp b/cubool/sources/cuBool_Vector_ExtractValues.cpp index cd885b9..acfde5a 100644 --- a/cubool/sources/cuBool_Vector_ExtractValues.cpp +++ b/cubool/sources/cuBool_Vector_ExtractValues.cpp @@ -27,15 +27,14 @@ cuBool_Status cuBool_Vector_ExtractValues( cuBool_Vector vector, cuBool_Index* rows, - cuBool_Index* nvals -) { + cuBool_Index* nvals) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(vector) - CUBOOL_ARG_NOT_NULL(nvals) - auto v = (cubool::Vector *) vector; - size_t count = *nvals; - v->extract(rows, count); - *nvals = count; + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(vector) + CUBOOL_ARG_NOT_NULL(nvals) + auto v = (cubool::Vector*) vector; + size_t count = *nvals; + v->extract(rows, count); + *nvals = count; CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_Free.cpp b/cubool/sources/cuBool_Vector_Free.cpp index 042c52c..020a35b 100644 --- a/cubool/sources/cuBool_Vector_Free.cpp +++ b/cubool/sources/cuBool_Vector_Free.cpp @@ -25,11 +25,10 @@ #include CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Free( - cuBool_Vector vector -) { + cuBool_Vector vector) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - auto v = (cubool::Vector *) vector; - cubool::Library::releaseVector(v); + CUBOOL_VALIDATE_LIBRARY + auto v = (cubool::Vector*) vector; + cubool::Library::releaseVector(v); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_Marker.cpp b/cubool/sources/cuBool_Vector_Marker.cpp index 03eb17a..5441a39 100644 --- a/cubool/sources/cuBool_Vector_Marker.cpp +++ b/cubool/sources/cuBool_Vector_Marker.cpp @@ -26,27 +26,26 @@ cuBool_Status cuBool_Vector_Marker( cuBool_Vector vector, - char* marker, - cuBool_Index* size -) { + char* marker, + cuBool_Index* size) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(vector) - CUBOOL_ARG_NOT_NULL(size) + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(vector) + CUBOOL_ARG_NOT_NULL(size) - auto v = (cubool::Vector*) vector; - auto actualSize = v->getDebugMarkerSizeWithNullT(); - auto toCopy = std::min(*size, actualSize); + auto v = (cubool::Vector*) vector; + auto actualSize = v->getDebugMarkerSizeWithNullT(); + auto toCopy = std::min(*size, actualSize); - if (marker != nullptr && toCopy > 0) { - // C str (with \0) - const auto* text = v->getDebugMarker(); - std::memcpy(marker, text, toCopy); + if (marker != nullptr && toCopy > 0) { + // C str (with \0) + const auto* text = v->getDebugMarker(); + std::memcpy(marker, text, toCopy); - // Explicitly terminate (for case size < actualSize) - marker[toCopy - 1] = '\0'; - } + // Explicitly terminate (for case size < actualSize) + marker[toCopy - 1] = '\0'; + } - *size = actualSize; + *size = actualSize; CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_New.cpp b/cubool/sources/cuBool_Vector_New.cpp index 768a6ee..113e92c 100644 --- a/cubool/sources/cuBool_Vector_New.cpp +++ b/cubool/sources/cuBool_Vector_New.cpp @@ -26,11 +26,10 @@ cuBool_Status cuBool_Vector_New( cuBool_Vector* vector, - cuBool_Index nrows -) { + cuBool_Index nrows) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(vector) - *vector = (cuBool_Vector_t *) cubool::Library::createVector(nrows); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(vector) + *vector = (cuBool_Vector_t*) cubool::Library::createVector(nrows); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_Nrows.cpp b/cubool/sources/cuBool_Vector_Nrows.cpp index ad5cd22..f9905bf 100644 --- a/cubool/sources/cuBool_Vector_Nrows.cpp +++ b/cubool/sources/cuBool_Vector_Nrows.cpp @@ -26,13 +26,12 @@ cuBool_Status cuBool_Vector_Nrows( cuBool_Vector vector, - cuBool_Index* nrows -) { + cuBool_Index* nrows) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(vector) - CUBOOL_ARG_NOT_NULL(nrows) - auto v = (cubool::Vector *) vector; - *nrows = v->getNrows(); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(vector) + CUBOOL_ARG_NOT_NULL(nrows) + auto v = (cubool::Vector*) vector; + *nrows = v->getNrows(); CUBOOL_END_BODY } diff --git a/cubool/sources/cuBool_Vector_Nvals.cpp b/cubool/sources/cuBool_Vector_Nvals.cpp index 0397304..0fbe9a5 100644 --- a/cubool/sources/cuBool_Vector_Nvals.cpp +++ b/cubool/sources/cuBool_Vector_Nvals.cpp @@ -26,13 +26,12 @@ cuBool_Status cuBool_Vector_Nvals( cuBool_Vector vector, - cuBool_Index* nvals -) { + cuBool_Index* nvals) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(vector) - CUBOOL_ARG_NOT_NULL(nvals) - auto v = (cubool::Vector *) vector; - *nvals = v->getNvals(); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(vector) + CUBOOL_ARG_NOT_NULL(nvals) + auto v = (cubool::Vector*) vector; + *nvals = v->getNvals(); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_Reduce.cpp b/cubool/sources/cuBool_Vector_Reduce.cpp index ee32c27..8b8c8bc 100644 --- a/cubool/sources/cuBool_Vector_Reduce.cpp +++ b/cubool/sources/cuBool_Vector_Reduce.cpp @@ -27,13 +27,12 @@ cuBool_Status cuBool_Vector_Reduce( cuBool_Index* result, cuBool_Vector vector, - cuBool_Hints hints -) { + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(vector) - auto v = (cubool::Vector*) vector; - v->reduce(*result, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(vector) + auto v = (cubool::Vector*) vector; + v->reduce(*result, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_SetElement.cpp b/cubool/sources/cuBool_Vector_SetElement.cpp index 39ec8e0..cbf052b 100644 --- a/cubool/sources/cuBool_Vector_SetElement.cpp +++ b/cubool/sources/cuBool_Vector_SetElement.cpp @@ -26,12 +26,11 @@ cuBool_Status cuBool_Vector_SetElement( cuBool_Vector vector, - cuBool_Index i -) { + cuBool_Index i) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(vector) - auto v = (cubool::Vector*) vector; - v->setElement(i); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(vector) + auto v = (cubool::Vector*) vector; + v->setElement(i); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_Vector_SetMarker.cpp b/cubool/sources/cuBool_Vector_SetMarker.cpp index 38c906c..418f216 100644 --- a/cubool/sources/cuBool_Vector_SetMarker.cpp +++ b/cubool/sources/cuBool_Vector_SetMarker.cpp @@ -26,13 +26,12 @@ cuBool_Status cuBool_Vector_SetMarker( cuBool_Vector vector, - const char* marker -) { + const char* marker) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(vector) - CUBOOL_ARG_NOT_NULL(marker) - auto v = (cubool::Vector*) vector; - v->setDebugMarker(marker); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(vector) + CUBOOL_ARG_NOT_NULL(marker) + auto v = (cubool::Vector*) vector; + v->setDebugMarker(marker); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuBool_VxM.cpp b/cubool/sources/cuBool_VxM.cpp index 5cda9d3..d1696fe 100644 --- a/cubool/sources/cuBool_VxM.cpp +++ b/cubool/sources/cuBool_VxM.cpp @@ -25,19 +25,18 @@ #include cuBool_Status cuBool_VxM( - cuBool_Vector result, - cuBool_Vector vector, - cuBool_Matrix matrix, - cuBool_Hints hints -) { + cuBool_Vector result, + cuBool_Vector vector, + cuBool_Matrix matrix, + cuBool_Hints hints) { CUBOOL_BEGIN_BODY - CUBOOL_VALIDATE_LIBRARY - CUBOOL_ARG_NOT_NULL(result) - CUBOOL_ARG_NOT_NULL(vector) - CUBOOL_ARG_NOT_NULL(matrix) - auto resultV = (cubool::Vector *) result; - auto left = (cubool::Vector *) vector; - auto right = (cubool::Matrix *) matrix; - resultV->multiplyVxM(*left, *right, hints & CUBOOL_HINT_TIME_CHECK); + CUBOOL_VALIDATE_LIBRARY + CUBOOL_ARG_NOT_NULL(result) + CUBOOL_ARG_NOT_NULL(vector) + CUBOOL_ARG_NOT_NULL(matrix) + auto resultV = (cubool::Vector*) result; + auto left = (cubool::Vector*) vector; + auto right = (cubool::Matrix*) matrix; + resultV->multiplyVxM(*left, *right, hints & CUBOOL_HINT_TIME_CHECK); CUBOOL_END_BODY } \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_backend.cu b/cubool/sources/cuda/cuda_backend.cu index f8d1eb4..4217f34 100644 --- a/cubool/sources/cuda/cuda_backend.cu +++ b/cubool/sources/cuda/cuda_backend.cu @@ -22,10 +22,10 @@ /* SOFTWARE. */ /**********************************************************************************/ +#include #include #include #include -#include #include #include @@ -71,7 +71,7 @@ namespace cubool { return mInstance != nullptr; } - MatrixBase *CudaBackend::createMatrix(size_t nrows, size_t ncols) { + MatrixBase* CudaBackend::createMatrix(size_t nrows, size_t ncols) { mMatCount++; return new CudaMatrix(nrows, ncols, getInstance()); } @@ -81,22 +81,22 @@ namespace cubool { return new CudaVector(nrows, getInstance()); } - void CudaBackend::releaseMatrix(MatrixBase *matrixBase) { + void CudaBackend::releaseMatrix(MatrixBase* matrixBase) { mMatCount--; delete matrixBase; } - void CudaBackend::releaseVector(VectorBase *vectorBase) { + void CudaBackend::releaseVector(VectorBase* vectorBase) { mVecCount--; delete vectorBase; } - void CudaBackend::queryCapabilities(cuBool_DeviceCaps &caps) { + void CudaBackend::queryCapabilities(cuBool_DeviceCaps& caps) { mInstance->queryDeviceCapabilities(caps); } - CudaInstance & CudaBackend::getInstance() { + CudaInstance& CudaBackend::getInstance() { return *mInstance; } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_backend.hpp b/cubool/sources/cuda/cuda_backend.hpp index 74bdf8b..59a7ea4 100644 --- a/cubool/sources/cuda/cuda_backend.hpp +++ b/cubool/sources/cuda/cuda_backend.hpp @@ -33,7 +33,7 @@ namespace cubool { /** * Main entry to cuda provided backend implementation. */ - class CudaBackend final: public BackendBase { + class CudaBackend final : public BackendBase { public: ~CudaBackend() override = default; @@ -41,20 +41,20 @@ namespace cubool { void finalize() override; bool isInitialized() const override; - MatrixBase *createMatrix(size_t nrows, size_t ncols) override; + MatrixBase* createMatrix(size_t nrows, size_t ncols) override; VectorBase* createVector(size_t nrows) override; - void releaseMatrix(MatrixBase *matrixBase) override; - void releaseVector(VectorBase* vectorBase) override; - void queryCapabilities(cuBool_DeviceCaps& caps) override; + void releaseMatrix(MatrixBase* matrixBase) override; + void releaseVector(VectorBase* vectorBase) override; + void queryCapabilities(cuBool_DeviceCaps& caps) override; CudaInstance& getInstance(); private: CudaInstance* mInstance; - size_t mMatCount = 0; - size_t mVecCount = 0; + size_t mMatCount = 0; + size_t mVecCount = 0; }; -} +}// namespace cubool -#endif //CUBOOL_CUDA_BACKEND_HPP \ No newline at end of file +#endif//CUBOOL_CUDA_BACKEND_HPP \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_instance.cu b/cubool/sources/cuda/cuda_instance.cu index 3562ff0..2301cfa 100644 --- a/cubool/sources/cuda/cuda_instance.cu +++ b/cubool/sources/cuda/cuda_instance.cu @@ -22,19 +22,19 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include -#include -#include #include +#include #include +#include +#include namespace cubool { volatile CudaInstance* CudaInstance::gInstance = nullptr; CudaInstance::CudaInstance(bool useManagedMemory) { - gInstance = this; - mMemoryType = useManagedMemory? Managed: Default; + gInstance = this; + mMemoryType = useManagedMemory ? Managed : Default; } CudaInstance::~CudaInstance() { @@ -44,7 +44,7 @@ namespace cubool { gInstance = nullptr; } - void CudaInstance::allocateOnGpu(void* &ptr, size_t size) const { + void CudaInstance::allocateOnGpu(void*& ptr, size_t size) const { cudaError error; switch (mMemoryType) { @@ -86,10 +86,10 @@ namespace cubool { } } - void CudaInstance::queryDeviceCapabilities(cuBool_DeviceCaps &deviceCaps) const { + void CudaInstance::queryDeviceCapabilities(cuBool_DeviceCaps& deviceCaps) const { const unsigned long long KiB = 1024; - int device; + int device; cudaError error = cudaGetDevice(&device); if (error == cudaSuccess) { @@ -98,14 +98,14 @@ namespace cubool { if (error == cudaSuccess) { strcpy(deviceCaps.name, deviceProp.name); - deviceCaps.cudaSupported = true; - deviceCaps.managedMem = mMemoryType == MemType::Managed; - deviceCaps.minor = deviceProp.minor; - deviceCaps.major = deviceProp.major; - deviceCaps.warp = deviceProp.warpSize; - deviceCaps.globalMemoryKiBs = deviceProp.totalGlobalMem / KiB; + deviceCaps.cudaSupported = true; + deviceCaps.managedMem = mMemoryType == MemType::Managed; + deviceCaps.minor = deviceProp.minor; + deviceCaps.major = deviceProp.major; + deviceCaps.warp = deviceProp.warpSize; + deviceCaps.globalMemoryKiBs = deviceProp.totalGlobalMem / KiB; deviceCaps.sharedMemoryPerMultiProcKiBs = deviceProp.sharedMemPerMultiprocessor / KiB; - deviceCaps.sharedMemoryPerBlockKiBs = deviceProp.sharedMemPerBlock / KiB; + deviceCaps.sharedMemoryPerBlockKiBs = deviceProp.sharedMemPerBlock / KiB; } } } @@ -115,12 +115,12 @@ namespace cubool { } bool CudaInstance::isCudaDeviceSupported() { - int device; + int device; cudaError error = cudaGetDevice(&device); return error == cudaSuccess; } - void CudaInstance::allocate(void* &ptr, size_t size) const { + void CudaInstance::allocate(void*& ptr, size_t size) const { ptr = malloc(size); CHECK_RAISE_ERROR(ptr != nullptr, MemOpFailed, "Failed to allocate memory on the CPU"); mHostAllocCount++; @@ -138,11 +138,11 @@ namespace cubool { } CudaInstance* CudaInstance::getInstancePtr() { - return (CudaInstance* ) gInstance; + return (CudaInstance*) gInstance; } bool CudaInstance::isInstancePresent() { return gInstance != nullptr; } -} +}// namespace cubool diff --git a/cubool/sources/cuda/cuda_instance.hpp b/cubool/sources/cuda/cuda_instance.hpp index 89f62da..a29e903 100644 --- a/cubool/sources/cuda/cuda_instance.hpp +++ b/cubool/sources/cuda/cuda_instance.hpp @@ -35,40 +35,39 @@ namespace cubool { */ class CudaInstance { public: - enum MemType { Default, Managed }; explicit CudaInstance(bool useManagedMemory); - CudaInstance(const CudaInstance& other) = delete; + CudaInstance(const CudaInstance& other) = delete; CudaInstance(CudaInstance&& other) noexcept = delete; ~CudaInstance(); // For custom host & device allocators - void allocate(void* &ptr, size_t s) const; - void allocateOnGpu(void* &ptr, size_t s) const; + void allocate(void*& ptr, size_t s) const; + void allocateOnGpu(void*& ptr, size_t s) const; void deallocate(void* ptr) const; void deallocateOnGpu(void* ptr) const; void queryDeviceCapabilities(cuBool_DeviceCaps& deviceCaps) const; - void syncHostDevice() const; + void syncHostDevice() const; MemType getMemoryType() const; - static bool isCudaDeviceSupported(); + static bool isCudaDeviceSupported(); static CudaInstance& getInstanceRef(); static CudaInstance* getInstancePtr(); - static bool isInstancePresent(); + static bool isInstancePresent(); private: - MemType mMemoryType = Default; - mutable size_t mHostAllocCount = 0; + MemType mMemoryType = Default; + mutable size_t mHostAllocCount = 0; mutable size_t mDeviceAllocCount = 0; static volatile CudaInstance* gInstance; }; -} +}// namespace cubool -#endif //CUBOOL_CUDA_INSTANCE_HPP \ No newline at end of file +#endif//CUBOOL_CUDA_INSTANCE_HPP \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_matrix.cu b/cubool/sources/cuda/cuda_matrix.cu index 6eec723..0b00ada 100644 --- a/cubool/sources/cuda/cuda_matrix.cu +++ b/cubool/sources/cuda/cuda_matrix.cu @@ -22,15 +22,15 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include +#include #include -#include +#include #include -#include +#include namespace cubool { - CudaMatrix::CudaMatrix(size_t nrows, size_t ncols, CudaInstance &instance) : mInstance(instance) { + CudaMatrix::CudaMatrix(size_t nrows, size_t ncols, CudaInstance& instance) : mInstance(instance) { mNrows = nrows; mNcols = ncols; } @@ -39,9 +39,9 @@ namespace cubool { RAISE_ERROR(NotImplemented, "This function is not supported for this matrix class"); } - void CudaMatrix::build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) { + void CudaMatrix::build(const index* rows, const index* cols, size_t nvals, bool isSorted, bool noDuplicates) { if (nvals == 0) { - mMatrixImpl.zero_dim(); // no content, empty matrix + mMatrixImpl.zero_dim();// no content, empty matrix return; } @@ -55,7 +55,7 @@ namespace cubool { this->transferToDevice(rowOffsets, colIndices); } - void CudaMatrix::extract(index *rows, index *cols, size_t &nvals) { + void CudaMatrix::extract(index* rows, index* cols, size_t& nvals) { assert(nvals >= getNvals()); // Set nvals to the exact number of nnz values @@ -72,7 +72,7 @@ namespace cubool { } } - void CudaMatrix::clone(const MatrixBase &otherBase) { + void CudaMatrix::clone(const MatrixBase& otherBase) { auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed matrix does not belong to csr matrix class"); @@ -125,7 +125,7 @@ namespace cubool { return mMatrixImpl.m_vals == 0; } - void CudaMatrix::transferToDevice(const std::vector &rowOffsets, const std::vector &colIndices) const { + void CudaMatrix::transferToDevice(const std::vector& rowOffsets, const std::vector& colIndices) const { // Create device buffers and copy data from the cpu side thrust::device_vector> rowsDeviceVec(rowOffsets.size()); thrust::device_vector> colsDeviceVec(colIndices.size()); @@ -137,7 +137,7 @@ namespace cubool { mMatrixImpl = std::move(MatrixImplType(std::move(colsDeviceVec), std::move(rowsDeviceVec), getNrows(), getNcols(), colIndices.size())); } - void CudaMatrix::transferFromDevice(std::vector &rowOffsets, std::vector &colIndices) const { + void CudaMatrix::transferFromDevice(std::vector& rowOffsets, std::vector& colIndices) const { rowOffsets.resize(mMatrixImpl.m_row_index.size()); colIndices.resize(mMatrixImpl.m_col_index.size()); @@ -145,4 +145,4 @@ namespace cubool { thrust::copy(mMatrixImpl.m_col_index.begin(), mMatrixImpl.m_col_index.end(), colIndices.begin()); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_matrix.hpp b/cubool/sources/cuda/cuda_matrix.hpp index 9f1b7a2..49ab555 100644 --- a/cubool/sources/cuda/cuda_matrix.hpp +++ b/cubool/sources/cuda/cuda_matrix.hpp @@ -26,37 +26,37 @@ #define CUBOOL_CUDA_MATRIX_HPP #include -#include #include +#include #include namespace cubool { - class CudaMatrix: public MatrixBase { + class CudaMatrix : public MatrixBase { public: template using DeviceAlloc = details::DeviceAllocator; template - using HostAlloc = details::HostAllocator; + using HostAlloc = details::HostAllocator; using MatrixImplType = nsparse::matrix>; CudaMatrix(size_t nrows, size_t ncols, CudaInstance& instance); ~CudaMatrix() override = default; void setElement(index i, index j) override; - void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) override; - void extract(index* rows, index* cols, size_t &nvals) override; - void extractSubMatrix(const MatrixBase &otherBase, index i, index j, index nrows, index ncols, bool checkTime) override; + void build(const index* rows, const index* cols, size_t nvals, bool isSorted, bool noDuplicates) override; + void extract(index* rows, index* cols, size_t& nvals) override; + void extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols, bool checkTime) override; - void clone(const MatrixBase &other) override; - void transpose(const MatrixBase &other, bool checkTime) override; - void reduce(const MatrixBase &other, bool checkTime) override; + void clone(const MatrixBase& other) override; + void transpose(const MatrixBase& other, bool checkTime) override; + void reduce(const MatrixBase& other, bool checkTime) override; - void multiply(const MatrixBase &a, const MatrixBase &b, bool accumulate, bool checkTime) override; - void kronecker(const MatrixBase &a, const MatrixBase &b, bool checkTime) override; - void eWiseAdd(const MatrixBase &a, const MatrixBase &b, bool checkTime) override; - void eWiseMult(const MatrixBase &a, const MatrixBase &b, bool checkTime) override; - void eWiseMultInverted(const MatrixBase &a, const MatrixBase &b, bool checkTime) override; + void multiply(const MatrixBase& a, const MatrixBase& b, bool accumulate, bool checkTime) override; + void kronecker(const MatrixBase& a, const MatrixBase& b, bool checkTime) override; + void eWiseAdd(const MatrixBase& a, const MatrixBase& b, bool checkTime) override; + void eWiseMult(const MatrixBase& a, const MatrixBase& b, bool checkTime) override; + void eWiseMultInverted(const MatrixBase& a, const MatrixBase& b, bool checkTime) override; index getNrows() const override; index getNcols() const override; @@ -68,16 +68,16 @@ namespace cubool { void resizeStorageToDim() const; void clearAndResizeStorageToDim() const; bool isMatrixEmpty() const; - void transferToDevice(const std::vector &rowOffsets, const std::vector &colIndices) const; - void transferFromDevice(std::vector &rowOffsets, std::vector &colIndices) const; + void transferToDevice(const std::vector& rowOffsets, const std::vector& colIndices) const; + void transferFromDevice(std::vector& rowOffsets, std::vector& colIndices) const; // Uses nsparse csr matrix implementation as a backend mutable MatrixImplType mMatrixImpl; - size_t mNrows = 0; - size_t mNcols = 0; + size_t mNrows = 0; + size_t mNcols = 0; CudaInstance& mInstance; }; -}; +};// namespace cubool -#endif //CUBOOL_CUDA_MATRIX_HPP +#endif//CUBOOL_CUDA_MATRIX_HPP diff --git a/cubool/sources/cuda/cuda_matrix_ewiseadd.cu b/cubool/sources/cuda/cuda_matrix_ewiseadd.cu index 1e4f140..fd819fe 100644 --- a/cubool/sources/cuda/cuda_matrix_ewiseadd.cu +++ b/cubool/sources/cuda/cuda_matrix_ewiseadd.cu @@ -27,7 +27,7 @@ namespace cubool { - void CudaMatrix::eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void CudaMatrix::eWiseAdd(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -58,10 +58,10 @@ namespace cubool { b->resizeStorageToDim(); kernels::SpMergeFunctor> spMergeFunctor; - auto result = spMergeFunctor(a->mMatrixImpl, b->mMatrixImpl); + auto result = spMergeFunctor(a->mMatrixImpl, b->mMatrixImpl); // Assign the actual impl result to this storage this->mMatrixImpl = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_matrix_ewisemult.cu b/cubool/sources/cuda/cuda_matrix_ewisemult.cu index 1708a9c..1ca180f 100644 --- a/cubool/sources/cuda/cuda_matrix_ewisemult.cu +++ b/cubool/sources/cuda/cuda_matrix_ewisemult.cu @@ -27,7 +27,7 @@ namespace cubool { - void CudaMatrix::eWiseMult(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void CudaMatrix::eWiseMult(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -53,10 +53,10 @@ namespace cubool { b->resizeStorageToDim(); kernels::SpMatrixEWiseMult> spFunctor; - auto result = spFunctor(a->mMatrixImpl, b->mMatrixImpl); + auto result = spFunctor(a->mMatrixImpl, b->mMatrixImpl); // Assign the actual impl result to this storage this->mMatrixImpl = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_matrix_ewisemult_inverted.cu b/cubool/sources/cuda/cuda_matrix_ewisemult_inverted.cu index 2e0fa87..e070409 100644 --- a/cubool/sources/cuda/cuda_matrix_ewisemult_inverted.cu +++ b/cubool/sources/cuda/cuda_matrix_ewisemult_inverted.cu @@ -27,7 +27,7 @@ namespace cubool { - void CudaMatrix::eWiseMultInverted(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void CudaMatrix::eWiseMultInverted(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -54,10 +54,10 @@ namespace cubool { b->resizeStorageToDim(); kernels::SpVectorEWiseMultInverted> spFunctor; - auto result = spFunctor(a->mMatrixImpl, b->mMatrixImpl); + auto result = spFunctor(a->mMatrixImpl, b->mMatrixImpl); // Assign the actual impl result to this storage this->mMatrixImpl = std::move(result); } -} +}// namespace cubool diff --git a/cubool/sources/cuda/cuda_matrix_extract_sub_matrix.cu b/cubool/sources/cuda/cuda_matrix_extract_sub_matrix.cu index d52f82d..f619fb2 100644 --- a/cubool/sources/cuda/cuda_matrix_extract_sub_matrix.cu +++ b/cubool/sources/cuda/cuda_matrix_extract_sub_matrix.cu @@ -27,7 +27,7 @@ namespace cubool { - void CudaMatrix::extractSubMatrix(const MatrixBase &otherBase, index i, index j, index nrows, index ncols, + void CudaMatrix::extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols, bool checkTime) { auto other = dynamic_cast(&otherBase); @@ -46,9 +46,9 @@ namespace cubool { other->resizeStorageToDim(); kernels::SpSubMatrix> spSubMatrix; - auto result = spSubMatrix(other->mMatrixImpl, i, j, nrows, ncols); + auto result = spSubMatrix(other->mMatrixImpl, i, j, nrows, ncols); mMatrixImpl = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_matrix_kronecker.cu b/cubool/sources/cuda/cuda_matrix_kronecker.cu index 1627ee1..5e21f2a 100644 --- a/cubool/sources/cuda/cuda_matrix_kronecker.cu +++ b/cubool/sources/cuda/cuda_matrix_kronecker.cu @@ -27,7 +27,7 @@ namespace cubool { - void CudaMatrix::kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void CudaMatrix::kronecker(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -53,10 +53,10 @@ namespace cubool { b->resizeStorageToDim(); kernels::SpKronFunctor> spKronFunctor; - auto result = spKronFunctor(a->mMatrixImpl, b->mMatrixImpl); + auto result = spKronFunctor(a->mMatrixImpl, b->mMatrixImpl); // Assign result to this this->mMatrixImpl = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_matrix_multiply.cu b/cubool/sources/cuda/cuda_matrix_multiply.cu index 55c880e..5401108 100644 --- a/cubool/sources/cuda/cuda_matrix_multiply.cu +++ b/cubool/sources/cuda/cuda_matrix_multiply.cu @@ -27,7 +27,7 @@ namespace cubool { - void CudaMatrix::multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) { + void CudaMatrix::multiply(const MatrixBase& aBase, const MatrixBase& bBase, bool accumulate, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -57,10 +57,10 @@ namespace cubool { // Call backend r = c + a * b implementation, as C this is passed nsparse::spgemm_functor_t> spgemmFunctor; - auto result = spgemmFunctor(mMatrixImpl, a->mMatrixImpl, b->mMatrixImpl); + auto result = spgemmFunctor(mMatrixImpl, a->mMatrixImpl, b->mMatrixImpl); // Assign result to this this->mMatrixImpl = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_matrix_reduce.cu b/cubool/sources/cuda/cuda_matrix_reduce.cu index ade3008..8094487 100644 --- a/cubool/sources/cuda/cuda_matrix_reduce.cu +++ b/cubool/sources/cuda/cuda_matrix_reduce.cu @@ -27,7 +27,7 @@ namespace cubool { - void CudaMatrix::reduce(const MatrixBase &otherBase, bool checkTime) { + void CudaMatrix::reduce(const MatrixBase& otherBase, bool checkTime) { auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed matrix does not belong to csr matrix class"); @@ -40,9 +40,9 @@ namespace cubool { other->resizeStorageToDim(); kernels::SpReduceFunctor> spReduceFunctor; - auto result = spReduceFunctor(other->mMatrixImpl); + auto result = spReduceFunctor(other->mMatrixImpl); mMatrixImpl = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_matrix_transpose.cu b/cubool/sources/cuda/cuda_matrix_transpose.cu index 3ce4c61..db7d8fc 100644 --- a/cubool/sources/cuda/cuda_matrix_transpose.cu +++ b/cubool/sources/cuda/cuda_matrix_transpose.cu @@ -28,7 +28,7 @@ namespace cubool { - void CudaMatrix::transpose(const MatrixBase &otherBase, bool checkTime) { + void CudaMatrix::transpose(const MatrixBase& otherBase, bool checkTime) { auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed matrix does not belong to csr matrix class"); @@ -40,10 +40,10 @@ namespace cubool { assert(this->getNcols() == M); kernels::SpTranspose2Functor> spTranspose2Functor; - auto result = spTranspose2Functor(other->mMatrixImpl); + auto result = spTranspose2Functor(other->mMatrixImpl); // Assign the actual impl result to this storage this->mMatrixImpl = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_vector.cu b/cubool/sources/cuda/cuda_vector.cu index f2fa9b0..c7c6ea6 100644 --- a/cubool/sources/cuda/cuda_vector.cu +++ b/cubool/sources/cuda/cuda_vector.cu @@ -22,27 +22,26 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include +#include #include +#include #include -#include -#include #include +#include #include namespace cubool { - CudaVector::CudaVector(size_t nrows, CudaInstance &instance) - : mVectorImpl(nrows), mInstance(instance) { - + CudaVector::CudaVector(size_t nrows, CudaInstance& instance) + : mVectorImpl(nrows), mInstance(instance) { } void CudaVector::setElement(index i) { RAISE_ERROR(NotImplemented, "This function is not supported for this vector class"); } - void CudaVector::build(const index *rows, size_t nvals, bool isSorted, bool noDuplicates) { + void CudaVector::build(const index* rows, size_t nvals, bool isSorted, bool noDuplicates) { if (nvals == 0) { // Empty vector, no values (but preserve dim) mVectorImpl = VectorImplType(getNrows()); @@ -61,7 +60,7 @@ namespace cubool { mVectorImpl = VectorImplType(std::move(deviceData), getNrows(), data.size()); } - void CudaVector::extract(index *rows, size_t &nvals) { + void CudaVector::extract(index* rows, size_t& nvals) { assert(nvals >= getNvals()); nvals = getNvals(); @@ -74,8 +73,8 @@ namespace cubool { } } - void CudaVector::extractSubVector(const VectorBase &otherBase, index i, index nrows, bool checkTime) { - const auto *v = dynamic_cast(&otherBase); + void CudaVector::extractSubVector(const VectorBase& otherBase, index i, index nrows, bool checkTime) { + const auto* v = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(v != nullptr, InvalidArgument, "Passed vector does not belong to cuda vector class"); @@ -96,7 +95,7 @@ namespace cubool { return; } - auto &vec = v->mVectorImpl; + auto& vec = v->mVectorImpl; thrust::device_vector> region(2); thrust::fill_n(region.begin(), 1, std::numeric_limits::max()); @@ -104,8 +103,7 @@ namespace cubool { thrust::for_each(thrust::counting_iterator(0), thrust::counting_iterator(vec.m_vals), [first = region.data(), size = region.data() + 1, - i = i, last = i + nrows, rowIndex = vec.m_rows_index.data()] - __device__(index id) { + i = i, last = i + nrows, rowIndex = vec.m_rows_index.data()] __device__(index id) { auto rowId = rowIndex[id]; if (i <= rowId && rowId < last) { @@ -126,29 +124,29 @@ namespace cubool { index firstToCopy = region.front(); VectorImplType::container_type result(resultSize); - thrust::transform(vec.m_rows_index.begin() + firstToCopy, vec.m_rows_index.begin() + firstToCopy + resultSize,result.begin(), - [i]__device__(index id) { return id - i; }); + thrust::transform(vec.m_rows_index.begin() + firstToCopy, vec.m_rows_index.begin() + firstToCopy + resultSize, result.begin(), + [i] __device__(index id) { return id - i; }); // Update this impl data mVectorImpl = std::move(VectorImplType(std::move(result), nrows, resultSize)); } - void CudaVector::extractRow(const class MatrixBase &matrixBase, index i) { - auto matrix = dynamic_cast(&matrixBase); + void CudaVector::extractRow(const class MatrixBase& matrixBase, index i) { + auto matrix = dynamic_cast(&matrixBase); CHECK_RAISE_ERROR(matrix != nullptr, InvalidArgument, "Provided matrix does not belongs to cuda matrix class"); assert(getNrows() == matrix->getNcols()); assert(i <= matrix->getNrows()); - auto &m = matrix->mMatrixImpl; + auto& m = matrix->mMatrixImpl; index beginOffset = m.m_row_index[i]; - index endOffset = m.m_row_index[i + 1]; + index endOffset = m.m_row_index[i + 1]; - auto size = endOffset - beginOffset; + auto size = endOffset - beginOffset; auto being = m.m_col_index.begin() + beginOffset; - auto end = m.m_col_index.begin() + endOffset; + auto end = m.m_col_index.begin() + endOffset; VectorImplType::container_type result(size); thrust::copy(being, end, result.begin()); @@ -156,61 +154,59 @@ namespace cubool { mVectorImpl = std::move(VectorImplType(std::move(result), m.m_cols, size)); } - void CudaVector::extractCol(const class MatrixBase &matrixBase, index j) { - auto matrix = dynamic_cast(&matrixBase); + void CudaVector::extractCol(const class MatrixBase& matrixBase, index j) { + auto matrix = dynamic_cast(&matrixBase); CHECK_RAISE_ERROR(matrix != nullptr, InvalidArgument, "Provided matrix does not belongs to cuda matrix class"); assert(getNrows() == matrix->getNrows()); assert(j <= matrix->getNcols()); - auto &m = matrix->mMatrixImpl; + auto& m = matrix->mMatrixImpl; VectorImplType::container_type nnz(1); thrust::fill(nnz.begin(), nnz.end(), (index) 0); thrust::for_each(thrust::counting_iterator(0), thrust::counting_iterator(m.m_rows), [rowOffset = m.m_row_index.data(), colIndex = m.m_col_index.data(), - j, nnz = nnz.data()]__device__(index i) { - auto size = rowOffset[i + 1] - rowOffset[i]; + j, nnz = nnz.data()] __device__(index i) { + auto size = rowOffset[i + 1] - rowOffset[i]; auto begin = colIndex + rowOffset[i]; - auto end = colIndex + rowOffset[i + 1]; + auto end = colIndex + rowOffset[i + 1]; - auto r = kernels::find(begin, end, j); + auto r = kernels::find(begin, end, j); - if (r != end && *r == j) - atomicAdd(nnz.get(), 1); - } - ); + if (r != end && *r == j) + atomicAdd(nnz.get(), 1); + }); - index size = nnz.back(); + index size = nnz.back(); VectorImplType::container_type result(size); thrust::fill(nnz.begin(), nnz.end(), (index) 0); thrust::for_each(thrust::counting_iterator(0), thrust::counting_iterator(m.m_rows), [rowOffset = m.m_row_index.data(), colIndex = m.m_col_index.data(), - j, nnz = nnz.data(), result = result.data()]__device__(index i) { - auto size = rowOffset[i + 1] - rowOffset[i]; + j, nnz = nnz.data(), result = result.data()] __device__(index i) { + auto size = rowOffset[i + 1] - rowOffset[i]; auto begin = colIndex + rowOffset[i]; - auto end = colIndex + rowOffset[i + 1]; + auto end = colIndex + rowOffset[i + 1]; auto r = kernels::find(begin, end, j); if (r != end && *r == j) { - auto order = atomicAdd(nnz.get(), 1); + auto order = atomicAdd(nnz.get(), 1); result[order] = i; } - } - ); + }); thrust::sort(result.begin(), result.end()); mVectorImpl = std::move(VectorImplType(std::move(result), m.m_rows, size)); } - void CudaVector::clone(const VectorBase &otherBase) { - auto other = dynamic_cast(&otherBase); + void CudaVector::clone(const VectorBase& otherBase) { + auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Passed vector does not belong to vector class"); CHECK_RAISE_ERROR(other != this, InvalidArgument, "Vectors must differ"); @@ -219,7 +215,7 @@ namespace cubool { this->mVectorImpl = other->mVectorImpl; } - void CudaVector::reduce(index &result, bool checkTime) { + void CudaVector::reduce(index& result, bool checkTime) { result = getNvals(); } @@ -231,4 +227,4 @@ namespace cubool { return mVectorImpl.m_vals; } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_vector.hpp b/cubool/sources/cuda/cuda_vector.hpp index 196dd73..ade6643 100644 --- a/cubool/sources/cuda/cuda_vector.hpp +++ b/cubool/sources/cuda/cuda_vector.hpp @@ -27,44 +27,44 @@ #include #include -#include #include +#include namespace cubool { - class CudaVector final: public VectorBase { + class CudaVector final : public VectorBase { public: template - using DeviceAlloc = details::DeviceAllocator; + using DeviceAlloc = details::DeviceAllocator; using VectorImplType = details::SpVector>; CudaVector(size_t nrows, CudaInstance& instance); ~CudaVector() override = default; void setElement(index i) override; - void build(const index *rows, size_t nvals, bool isSorted, bool noDuplicates) override; - void extract(index *rows, size_t &nvals) override; - void extractSubVector(const VectorBase &otherBase, index i, index nrows, bool checkTime) override; + void build(const index* rows, size_t nvals, bool isSorted, bool noDuplicates) override; + void extract(index* rows, size_t& nvals) override; + void extractSubVector(const VectorBase& otherBase, index i, index nrows, bool checkTime) override; void extractRow(const class MatrixBase& matrixBase, index i) override; void extractCol(const class MatrixBase& matrixBase, index j) override; - void clone(const VectorBase &otherBase) override; - void reduce(index &result, bool checkTime) override; - void reduceMatrix(const struct MatrixBase &matrix, bool transpose, bool checkTime) override; + void clone(const VectorBase& otherBase) override; + void reduce(index& result, bool checkTime) override; + void reduceMatrix(const struct MatrixBase& matrix, bool transpose, bool checkTime) override; - void eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override; - void eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override; - void multiplyVxM(const VectorBase &vBase, const struct MatrixBase &mBase, bool checkTime) override; - void multiplyMxV(const struct MatrixBase &mBase, const VectorBase &vBase, bool checkTime) override; + void eWiseMult(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) override; + void eWiseAdd(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) override; + void multiplyVxM(const VectorBase& vBase, const struct MatrixBase& mBase, bool checkTime) override; + void multiplyMxV(const struct MatrixBase& mBase, const VectorBase& vBase, bool checkTime) override; index getNrows() const override; index getNvals() const override; private: mutable VectorImplType mVectorImpl; - CudaInstance& mInstance; + CudaInstance& mInstance; }; -} +}// namespace cubool -#endif //CUBOOL_CUDA_VECTOR_HPP +#endif//CUBOOL_CUDA_VECTOR_HPP diff --git a/cubool/sources/cuda/cuda_vector_ewiseadd.cu b/cubool/sources/cuda/cuda_vector_ewiseadd.cu index 5401927..d921802 100644 --- a/cubool/sources/cuda/cuda_vector_ewiseadd.cu +++ b/cubool/sources/cuda/cuda_vector_ewiseadd.cu @@ -22,14 +22,14 @@ /* SOFTWARE. */ /**********************************************************************************/ +#include +#include #include #include -#include -#include namespace cubool { - void CudaVector::eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) { + void CudaVector::eWiseAdd(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) { const auto* a = dynamic_cast(&aBase); const auto* b = dynamic_cast(&bBase); @@ -39,9 +39,9 @@ namespace cubool { assert(a->getNrows() == b->getNrows()); kernels::SpVectorEWiseAdd> functor; - auto result = functor(a->mVectorImpl, b->mVectorImpl); + auto result = functor(a->mVectorImpl, b->mVectorImpl); mVectorImpl = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_vector_ewisemult.cu b/cubool/sources/cuda/cuda_vector_ewisemult.cu index a95910f..8201929 100644 --- a/cubool/sources/cuda/cuda_vector_ewisemult.cu +++ b/cubool/sources/cuda/cuda_vector_ewisemult.cu @@ -22,14 +22,14 @@ /* SOFTWARE. */ /**********************************************************************************/ +#include +#include #include #include -#include -#include namespace cubool { - void CudaVector::eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) { + void CudaVector::eWiseMult(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) { const auto* a = dynamic_cast(&aBase); const auto* b = dynamic_cast(&bBase); @@ -39,8 +39,9 @@ namespace cubool { assert(a->getNrows() == b->getNrows()); kernels::SpVectorEWiseMult> functor; - auto result = functor(a->mVectorImpl, b->mVectorImpl); + auto result = functor(a->mVectorImpl, b->mVectorImpl); - mVectorImpl = std::move(result); } + mVectorImpl = std::move(result); + } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_vector_mxv.cu b/cubool/sources/cuda/cuda_vector_mxv.cu index 36ec1b2..8278b19 100644 --- a/cubool/sources/cuda/cuda_vector_mxv.cu +++ b/cubool/sources/cuda/cuda_vector_mxv.cu @@ -22,15 +22,15 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include +#include +#include #include +#include #include -#include -#include namespace cubool { - void CudaVector::multiplyMxV(const struct MatrixBase &mBase, const VectorBase &vBase, bool checkTime) { + void CudaVector::multiplyMxV(const struct MatrixBase& mBase, const VectorBase& vBase, bool checkTime) { const auto* m = dynamic_cast(&mBase); const auto* v = dynamic_cast(&vBase); @@ -43,9 +43,9 @@ namespace cubool { m->resizeStorageToDim(); kernels::SpGEMV> functor; - auto result = functor(m->mMatrixImpl, v->mVectorImpl); + auto result = functor(m->mMatrixImpl, v->mVectorImpl); mVectorImpl = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_vector_reduce.cu b/cubool/sources/cuda/cuda_vector_reduce.cu index 86b1f04..1149f08 100644 --- a/cubool/sources/cuda/cuda_vector_reduce.cu +++ b/cubool/sources/cuda/cuda_vector_reduce.cu @@ -22,15 +22,15 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include +#include +#include #include +#include #include -#include -#include namespace cubool { - void CudaVector::reduceMatrix(const struct MatrixBase &matrixBase, bool transpose, bool checkTime) { + void CudaVector::reduceMatrix(const struct MatrixBase& matrixBase, bool transpose, bool checkTime) { auto matrix = dynamic_cast(&matrixBase); CHECK_RAISE_ERROR(matrix != nullptr, InvalidArgument, "Provided matrix does not belongs to cuda matrix class"); @@ -42,8 +42,7 @@ namespace cubool { // Reduce to row-vector kernels::SpVectorMatrixTransposedReduceFunctor> functor; mVectorImpl = std::move(functor(matrix->mMatrixImpl)); - } - else { + } else { assert(matrix->getNrows() == this->getNrows()); matrix->resizeStorageToDim(); @@ -53,4 +52,4 @@ namespace cubool { } } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/cuda/cuda_vector_vxm.cu b/cubool/sources/cuda/cuda_vector_vxm.cu index 2996f76..bae2e25 100644 --- a/cubool/sources/cuda/cuda_vector_vxm.cu +++ b/cubool/sources/cuda/cuda_vector_vxm.cu @@ -22,15 +22,15 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include +#include +#include #include +#include #include -#include -#include namespace cubool { - void CudaVector::multiplyVxM(const VectorBase &vBase, const struct MatrixBase &mBase, bool checkTime) { + void CudaVector::multiplyVxM(const VectorBase& vBase, const struct MatrixBase& mBase, bool checkTime) { const auto* v = dynamic_cast(&vBase); const auto* m = dynamic_cast(&mBase); @@ -43,11 +43,9 @@ namespace cubool { m->resizeStorageToDim(); kernels::SpGEMVT> functor; - auto result = functor(v->mVectorImpl, m->mMatrixImpl); + auto result = functor(v->mVectorImpl, m->mMatrixImpl); mVectorImpl = std::move(result); } -} - - +}// namespace cubool diff --git a/cubool/sources/cuda/details/host_allocator.hpp b/cubool/sources/cuda/details/host_allocator.hpp index 115ada2..e1529df 100644 --- a/cubool/sources/cuda/details/host_allocator.hpp +++ b/cubool/sources/cuda/details/host_allocator.hpp @@ -25,44 +25,43 @@ #ifndef CUBOOL_HOST_ALLOCATOR_HPP #define CUBOOL_HOST_ALLOCATOR_HPP -#include #include +#include namespace cubool { namespace details { - template + template class HostAllocator { public: - typedef size_t size_type; - typedef T value_type; - typedef T* pointer; + typedef size_t size_type; + typedef T value_type; + typedef T* pointer; typedef const T* const_pointer; - typedef T& reference; + typedef T& reference; typedef const T& const_reference; - template - struct rebind { typedef HostAllocator other; }; - - explicit HostAllocator(): mInstanceRef(CudaInstance::getInstanceRef()) { + template + struct rebind { + typedef HostAllocator other; + }; + explicit HostAllocator() : mInstanceRef(CudaInstance::getInstanceRef()) { } - HostAllocator(const HostAllocator &other): mInstanceRef(other.mInstanceRef) { - + HostAllocator(const HostAllocator& other) : mInstanceRef(other.mInstanceRef) { } - HostAllocator(HostAllocator &&other) noexcept: mInstanceRef(other.mInstanceRef) { - + HostAllocator(HostAllocator&& other) noexcept : mInstanceRef(other.mInstanceRef) { } ~HostAllocator() = default; - bool operator!=(const HostAllocator &other) const { + bool operator!=(const HostAllocator& other) const { return &mInstanceRef != &other.mInstanceRef; } - HostAllocator& operator=(const HostAllocator &other) { + HostAllocator& operator=(const HostAllocator& other) { this->~HostAllocator(); new (this) HostAllocator(other); return *this; @@ -75,7 +74,7 @@ namespace cubool { } void deallocate(pointer p, size_type n) { - (void)n; + (void) n; mInstanceRef.deallocate(p); } @@ -83,7 +82,7 @@ namespace cubool { CudaInstance& mInstanceRef; }; - } -} + }// namespace details +}// namespace cubool -#endif //CUBOOL_HOST_ALLOCATOR_HPP +#endif//CUBOOL_HOST_ALLOCATOR_HPP diff --git a/cubool/sources/cuda/details/meta.hpp b/cubool/sources/cuda/details/meta.hpp index 18762ae..7310737 100644 --- a/cubool/sources/cuda/details/meta.hpp +++ b/cubool/sources/cuda/details/meta.hpp @@ -25,21 +25,21 @@ #ifndef CUBOOL_META_HPP #define CUBOOL_META_HPP +#include #include #include -#include namespace cubool { - template + template struct StreamsWrapper { StreamsWrapper() { - for (auto& s: streams) + for (auto& s : streams) cudaStreamCreate(&s); } ~StreamsWrapper() { - for (auto& s: streams) + for (auto& s : streams) cudaStreamDestroy(s); } @@ -50,22 +50,21 @@ namespace cubool { struct Bin { static_assert(Threads <= BlocksSize, "Block size must be >= threads in this block"); - static constexpr size_t threads = Threads; - static constexpr size_t blockSize = BlocksSize; + static constexpr size_t threads = Threads; + static constexpr size_t blockSize = BlocksSize; static constexpr size_t dispatchRatio = BlocksSize / Threads; - static constexpr size_t min = Max; - static constexpr size_t max = Min; - static constexpr size_t id = Id; + static constexpr size_t min = Max; + static constexpr size_t max = Min; + static constexpr size_t id = Id; }; - template + template struct Config { public: - static __host__ __device__ size_t selectBin(size_t rowSize) { - static constexpr size_t mins[] = { Bins::min... }; - static constexpr size_t maxs[] = { Bins::max... }; + static constexpr size_t mins[] = {Bins::min...}; + static constexpr size_t maxs[] = {Bins::max...}; for (size_t i = 0; i < binsCount(); i++) { if (mins[i] <= rowSize && rowSize <= maxs[i]) @@ -76,7 +75,7 @@ namespace cubool { } static __host__ __device__ constexpr size_t binBlockSize(size_t id) { - constexpr size_t blockSizes[] = { Bins::blockSize... }; + constexpr size_t blockSizes[] = {Bins::blockSize...}; return blockSizes[id]; } @@ -87,9 +86,8 @@ namespace cubool { static __host__ __device__ constexpr size_t unusedBinId() { return binsCount() + 1; } - }; -} +}// namespace cubool -#endif //CUBOOL_META_HPP +#endif//CUBOOL_META_HPP diff --git a/cubool/sources/cuda/details/sp_vector.hpp b/cubool/sources/cuda/details/sp_vector.hpp index 4720ad0..bd6613f 100644 --- a/cubool/sources/cuda/details/sp_vector.hpp +++ b/cubool/sources/cuda/details/sp_vector.hpp @@ -33,29 +33,29 @@ namespace cubool { template struct SpVector { public: - typedef bool value_type; - typedef IndexType index_type; - typedef AllocType alloc_type; + typedef bool value_type; + typedef IndexType index_type; + typedef AllocType alloc_type; typedef thrust::device_vector container_type; SpVector() : m_rows_index{}, m_rows{0}, m_vals{0} {} SpVector(index_type rows) - : m_rows_index{}, m_rows (rows), m_vals{0} {} + : m_rows_index{}, m_rows(rows), m_vals{0} {} SpVector(thrust::device_vector rows_index, index_type rows, index_type vals) - : m_rows_index{ std::move(rows_index) }, m_rows{ rows }, m_vals{ vals } { + : m_rows_index{std::move(rows_index)}, m_rows{rows}, m_vals{vals} { assert(m_rows > 0); assert(m_rows_index.size() == m_vals); } public: thrust::device_vector m_rows_index; - index_type m_rows; - index_type m_vals; + index_type m_rows; + index_type m_vals; }; - } -} + }// namespace details +}// namespace cubool -#endif //CUBOOL_SP_VECTOR_HPP +#endif//CUBOOL_SP_VECTOR_HPP diff --git a/cubool/sources/io/logger.cpp b/cubool/sources/io/logger.cpp index be5604f..87d08d4 100644 --- a/cubool/sources/io/logger.cpp +++ b/cubool/sources/io/logger.cpp @@ -26,23 +26,23 @@ namespace cubool { - void Logger::logInfo(const std::string &message) { + void Logger::logInfo(const std::string& message) { this->log(Level::Info, message); } - void Logger::logWarning(const std::string &message) { + void Logger::logWarning(const std::string& message) { this->log(Level::Warning, message); } - void Logger::logError(const std::string &message) { + void Logger::logError(const std::string& message) { this->log(Level::Error, message); } - void TextLogger::log(Logger::Level level, const std::string &message) { + void TextLogger::log(Logger::Level level, const std::string& message) { bool pass = true; // If pass all filters - for (const auto& filter: mFilters) { + for (const auto& filter : mFilters) { pass = pass && filter(level, message); } @@ -51,13 +51,13 @@ namespace cubool { Entry entry; entry.message = message; - entry.level = level; - entry.id = id; + entry.level = level; + entry.id = id; mEntries.emplace_back(std::move(entry)); // Notify listeners - for (const auto& action: mOnLogged) { + for (const auto& action : mOnLogged) { action(id, level, message); } } @@ -87,7 +87,7 @@ namespace cubool { mOnLogged.clear(); } - void DummyLogger::log(Logger::Level level, const std::string &message) { + void DummyLogger::log(Logger::Level level, const std::string& message) { // no op. } @@ -98,4 +98,4 @@ namespace cubool { bool DummyLogger::isDummy() const { return true; } -} +}// namespace cubool diff --git a/cubool/sources/io/logger.hpp b/cubool/sources/io/logger.hpp index 2b2fad3..b7198fd 100644 --- a/cubool/sources/io/logger.hpp +++ b/cubool/sources/io/logger.hpp @@ -25,10 +25,10 @@ #ifndef CUBOOL_LOGGER_HPP #define CUBOOL_LOGGER_HPP -#include -#include #include #include +#include +#include namespace cubool { @@ -38,18 +38,18 @@ namespace cubool { class Logger { public: enum class Level { - Info, // Logged basic info (can be ignored) - Warning, // Logged warning (can be ignored) - Error, // Logged error (can be ignored) - Always // Logged always (cannot be ignored) + Info, // Logged basic info (can be ignored) + Warning,// Logged warning (can be ignored) + Error, // Logged error (can be ignored) + Always // Logged always (cannot be ignored) }; - virtual ~Logger() = default; - virtual void log(Level level, const std::string &message) = 0; - virtual void logInfo(const std::string &message); - virtual void logWarning(const std::string &message); - virtual void logError(const std::string &message); - virtual bool isDummy() const = 0; + virtual ~Logger() = default; + virtual void log(Level level, const std::string& message) = 0; + virtual void logInfo(const std::string& message); + virtual void logWarning(const std::string& message); + virtual void logError(const std::string& message); + virtual bool isDummy() const = 0; virtual size_t getMessagesCount() const = 0; }; @@ -60,7 +60,7 @@ namespace cubool { * Allows add filters to ignore some messages. * Allows commit messages to the output log file. */ - class TextLogger final: public Logger { + class TextLogger final : public Logger { public: /** Allows filter logged messages (before they are actually saved inside) */ using Filter = std::function; @@ -68,9 +68,9 @@ namespace cubool { using OnLogged = std::function; ~TextLogger() override = default; - void log(Level level, const std::string &message) override; + void log(Level level, const std::string& message) override; size_t getMessagesCount() const override; - bool isDummy() const override; + bool isDummy() const override; void addFilter(Filter filter); void removeAllFilters(); @@ -80,26 +80,26 @@ namespace cubool { private: struct Entry { std::string message; - Level level; - size_t id; + Level level; + size_t id; }; - std::vector mEntries; - std::vector mFilters; + std::vector mEntries; + std::vector mFilters; std::vector mOnLogged; - size_t mNextMessageId = 0; + size_t mNextMessageId = 0; }; /** * No logging logic. */ - class DummyLogger final: public Logger { + class DummyLogger final : public Logger { public: - DummyLogger() noexcept = default; + DummyLogger() noexcept = default; ~DummyLogger() override = default; - void log(Level level, const std::string &message) override; + void log(Level level, const std::string& message) override; size_t getMessagesCount() const override; - bool isDummy() const override; + bool isDummy() const override; }; /** @@ -112,10 +112,10 @@ namespace cubool { explicit LogStream(Logger& logger) : mLogger(logger), mLevel(Logger::Level::Info) { - }; + }; LogStream(LogStream&& other) noexcept = default; - ~LogStream() = default; + ~LogStream() = default; void commit() { if (!mLogger.isDummy()) { @@ -150,11 +150,11 @@ namespace cubool { } private: - Logger& mLogger; - Logger::Level mLevel; + Logger& mLogger; + Logger::Level mLevel; std::stringstream mStream; }; -} +}// namespace cubool -#endif //CUBOOL_LOGGER_HPP +#endif//CUBOOL_LOGGER_HPP diff --git a/cubool/sources/sequential/sq_backend.cpp b/cubool/sources/sequential/sq_backend.cpp index e99c5cf..53d69f1 100644 --- a/cubool/sources/sequential/sq_backend.cpp +++ b/cubool/sources/sequential/sq_backend.cpp @@ -22,12 +22,12 @@ /* SOFTWARE. */ /**********************************************************************************/ +#include +#include +#include #include #include #include -#include -#include -#include namespace cubool { @@ -56,7 +56,7 @@ namespace cubool { return true; } - MatrixBase *SqBackend::createMatrix(size_t nrows, size_t ncols) { + MatrixBase* SqBackend::createMatrix(size_t nrows, size_t ncols) { mMatCount++; return new SqMatrix(nrows, ncols); } @@ -66,18 +66,18 @@ namespace cubool { return new SqVector(nrows); } - void SqBackend::releaseMatrix(MatrixBase *matrixBase) { + void SqBackend::releaseMatrix(MatrixBase* matrixBase) { mMatCount--; delete matrixBase; } - void SqBackend::releaseVector(VectorBase *vectorBase) { + void SqBackend::releaseVector(VectorBase* vectorBase) { mVecCount--; delete vectorBase; } - void SqBackend::queryCapabilities(cuBool_DeviceCaps &caps) { + void SqBackend::queryCapabilities(cuBool_DeviceCaps& caps) { caps.cudaSupported = false; } -} +}// namespace cubool diff --git a/cubool/sources/sequential/sq_backend.hpp b/cubool/sources/sequential/sq_backend.hpp index b95e51a..1508dfb 100644 --- a/cubool/sources/sequential/sq_backend.hpp +++ b/cubool/sources/sequential/sq_backend.hpp @@ -32,7 +32,7 @@ namespace cubool { /** * Sequential backend for Cpu side computations (fallback). */ - class SqBackend final: public BackendBase { + class SqBackend final : public BackendBase { public: ~SqBackend() override = default; @@ -40,10 +40,10 @@ namespace cubool { void finalize() override; bool isInitialized() const override; - MatrixBase *createMatrix(size_t nrows, size_t ncols) override; + MatrixBase* createMatrix(size_t nrows, size_t ncols) override; VectorBase* createVector(size_t nrows) override; - void releaseMatrix(MatrixBase *matrixBase) override; - void releaseVector(VectorBase* vectorBase) override; + void releaseMatrix(MatrixBase* matrixBase) override; + void releaseVector(VectorBase* vectorBase) override; void queryCapabilities(cuBool_DeviceCaps& caps) override; @@ -52,6 +52,6 @@ namespace cubool { size_t mVecCount = 0; }; -} +}// namespace cubool -#endif //CUBOOL_SQ_BACKEND_HPP +#endif//CUBOOL_SQ_BACKEND_HPP diff --git a/cubool/sources/sequential/sq_data.hpp b/cubool/sources/sequential/sq_data.hpp index 345d707..1e9103c 100644 --- a/cubool/sources/sequential/sq_data.hpp +++ b/cubool/sources/sequential/sq_data.hpp @@ -34,18 +34,18 @@ namespace cubool { public: std::vector rowOffsets; std::vector colIndices; - index nrows = 0; - index ncols = 0; - index nvals = 0; + index nrows = 0; + index ncols = 0; + index nvals = 0; }; class VecData { public: std::vector indices; - index nrows = 0; - index nvals = 0; + index nrows = 0; + index nvals = 0; }; -} +}// namespace cubool -#endif //CUBOOL_SQ_DATA_HPP +#endif//CUBOOL_SQ_DATA_HPP diff --git a/cubool/sources/sequential/sq_ewiseadd.cpp b/cubool/sources/sequential/sq_ewiseadd.cpp index 8613a9a..acf8d69 100644 --- a/cubool/sources/sequential/sq_ewiseadd.cpp +++ b/cubool/sources/sequential/sq_ewiseadd.cpp @@ -34,13 +34,13 @@ namespace cubool { // Count nnz of the result matrix to allocate memory for (index i = 0; i < a.nrows; i++) { - index ak = a.rowOffsets[i]; - index bk = b.rowOffsets[i]; + index ak = a.rowOffsets[i]; + index bk = b.rowOffsets[i]; index asize = a.rowOffsets[i + 1] - ak; index bsize = b.rowOffsets[i + 1] - bk; - const index* ar = &a.colIndices[ak]; - const index* br = &b.colIndices[bk]; + const index* ar = &a.colIndices[ak]; + const index* br = &b.colIndices[bk]; const index* arend = ar + asize; const index* brend = br + bsize; @@ -51,19 +51,17 @@ namespace cubool { nvalsInRow++; ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { nvalsInRow++; ar++; - } - else { + } else { nvalsInRow++; br++; } } - nvalsInRow += (size_t)(arend - ar); - nvalsInRow += (size_t)(brend - br); + nvalsInRow += (size_t) (arend - ar); + nvalsInRow += (size_t) (brend - br); nvals += nvalsInRow; out.rowOffsets[i] = nvalsInRow; @@ -79,8 +77,8 @@ namespace cubool { // Fill sorted column indices size_t k = 0; for (index i = 0; i < a.nrows; i++) { - const index* ar = &a.colIndices[a.rowOffsets[i]]; - const index* br = &b.colIndices[b.rowOffsets[i]]; + const index* ar = &a.colIndices[a.rowOffsets[i]]; + const index* br = &b.colIndices[b.rowOffsets[i]]; const index* arend = &a.colIndices[a.rowOffsets[i + 1]]; const index* brend = &b.colIndices[b.rowOffsets[i + 1]]; @@ -90,13 +88,11 @@ namespace cubool { k++; ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { out.colIndices[k] = *ar; k++; ar++; - } - else { + } else { out.colIndices[k] = *br; k++; br++; @@ -131,11 +127,9 @@ namespace cubool { if (*ar == *br) { ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { ar++; - } - else { + } else { br++; } @@ -166,12 +160,10 @@ namespace cubool { out.indices.push_back(*ar); ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { out.indices.push_back(*ar); ar++; - } - else { + } else { out.indices.push_back(*br); br++; } @@ -188,4 +180,4 @@ namespace cubool { } } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/sequential/sq_ewiseadd.hpp b/cubool/sources/sequential/sq_ewiseadd.hpp index 122a2b9..488ae7c 100644 --- a/cubool/sources/sequential/sq_ewiseadd.hpp +++ b/cubool/sources/sequential/sq_ewiseadd.hpp @@ -47,6 +47,6 @@ namespace cubool { */ void sq_ewiseadd(const VecData& a, const VecData& b, VecData& out); -} +}// namespace cubool -#endif //CUBOOL_SQ_EWISEADD_HPP +#endif//CUBOOL_SQ_EWISEADD_HPP diff --git a/cubool/sources/sequential/sq_ewisemult.cpp b/cubool/sources/sequential/sq_ewisemult.cpp index 9ead01a..296059e 100644 --- a/cubool/sources/sequential/sq_ewisemult.cpp +++ b/cubool/sources/sequential/sq_ewisemult.cpp @@ -34,13 +34,13 @@ namespace cubool { // Count nnz of the result matrix to allocate memory for (index i = 0; i < a.nrows; i++) { - index ak = a.rowOffsets[i]; - index bk = b.rowOffsets[i]; + index ak = a.rowOffsets[i]; + index bk = b.rowOffsets[i]; index asize = a.rowOffsets[i + 1] - ak; index bsize = b.rowOffsets[i + 1] - bk; - const index* ar = &a.colIndices[ak]; - const index* br = &b.colIndices[bk]; + const index* ar = &a.colIndices[ak]; + const index* br = &b.colIndices[bk]; const index* arend = ar + asize; const index* brend = br + bsize; @@ -51,11 +51,9 @@ namespace cubool { nvalsInRow++; ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { ar++; - } - else { + } else { br++; } } @@ -74,8 +72,8 @@ namespace cubool { // Fill sorted column indices size_t k = 0; for (index i = 0; i < a.nrows; i++) { - const index* ar = &a.colIndices[a.rowOffsets[i]]; - const index* br = &b.colIndices[b.rowOffsets[i]]; + const index* ar = &a.colIndices[a.rowOffsets[i]]; + const index* br = &b.colIndices[b.rowOffsets[i]]; const index* arend = &a.colIndices[a.rowOffsets[i + 1]]; const index* brend = &b.colIndices[b.rowOffsets[i + 1]]; @@ -85,11 +83,9 @@ namespace cubool { k++; ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { ar++; - } - else { + } else { br++; } } @@ -110,11 +106,9 @@ namespace cubool { out.indices.push_back(*aP); aP++; bP++; - } - else if (*aP < *bP) { + } else if (*aP < *bP) { aP++; - } - else { + } else { bP++; } } @@ -122,4 +116,4 @@ namespace cubool { out.nvals = out.indices.size(); } -} +}// namespace cubool diff --git a/cubool/sources/sequential/sq_ewisemult.hpp b/cubool/sources/sequential/sq_ewisemult.hpp index 13666b4..20e9367 100644 --- a/cubool/sources/sequential/sq_ewisemult.hpp +++ b/cubool/sources/sequential/sq_ewisemult.hpp @@ -47,6 +47,6 @@ namespace cubool { */ void sq_ewisemult(const VecData& a, const VecData& b, VecData& out); -} +}// namespace cubool -#endif //CUBOOL_SQ_EWISEMULT_HPP +#endif//CUBOOL_SQ_EWISEMULT_HPP diff --git a/cubool/sources/sequential/sq_ewisemultinverted.cpp b/cubool/sources/sequential/sq_ewisemultinverted.cpp index ee810c9..1110a88 100644 --- a/cubool/sources/sequential/sq_ewisemultinverted.cpp +++ b/cubool/sources/sequential/sq_ewisemultinverted.cpp @@ -34,13 +34,13 @@ namespace cubool { // Count nnz of the result matrix to allocate memory for (index i = 0; i < a.nrows; i++) { - index ak = a.rowOffsets[i]; - index bk = b.rowOffsets[i]; + index ak = a.rowOffsets[i]; + index bk = b.rowOffsets[i]; index asize = a.rowOffsets[i + 1] - ak; index bsize = b.rowOffsets[i + 1] - bk; - const index* ar = &a.colIndices[ak]; - const index* br = &b.colIndices[bk]; + const index* ar = &a.colIndices[ak]; + const index* br = &b.colIndices[bk]; const index* arend = ar + asize; const index* brend = br + bsize; @@ -50,12 +50,10 @@ namespace cubool { if (*ar == *br) { ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { nvalsInRow++; ar++; - } - else { + } else { br++; } } @@ -75,8 +73,8 @@ namespace cubool { // Fill sorted column indices size_t k = 0; for (index i = 0; i < a.nrows; i++) { - const index* ar = &a.colIndices[a.rowOffsets[i]]; - const index* br = &b.colIndices[b.rowOffsets[i]]; + const index* ar = &a.colIndices[a.rowOffsets[i]]; + const index* br = &b.colIndices[b.rowOffsets[i]]; const index* arend = &a.colIndices[a.rowOffsets[i + 1]]; const index* brend = &b.colIndices[b.rowOffsets[i + 1]]; @@ -84,13 +82,11 @@ namespace cubool { if (*ar == *br) { ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { out.colIndices[k] = *ar; k++; ar++; - } - else { + } else { br++; } } @@ -102,4 +98,4 @@ namespace cubool { } } } -} +}// namespace cubool diff --git a/cubool/sources/sequential/sq_ewisemultinverted.hpp b/cubool/sources/sequential/sq_ewisemultinverted.hpp index 99b2615..6885549 100644 --- a/cubool/sources/sequential/sq_ewisemultinverted.hpp +++ b/cubool/sources/sequential/sq_ewisemultinverted.hpp @@ -37,6 +37,6 @@ namespace cubool { * @param[out] out Where to store the result */ void sq_ewisemultinverted(const CsrData& a, const CsrData& b, CsrData& out); -} +}// namespace cubool -#endif //CUBOOL_SQ_EWISEMULTINVERTED_HPP +#endif//CUBOOL_SQ_EWISEMULTINVERTED_HPP diff --git a/cubool/sources/sequential/sq_kronecker.cpp b/cubool/sources/sequential/sq_kronecker.cpp index f63b959..da66abd 100644 --- a/cubool/sources/sequential/sq_kronecker.cpp +++ b/cubool/sources/sequential/sq_kronecker.cpp @@ -58,4 +58,4 @@ namespace cubool { exclusive_scan(out.rowOffsets.begin(), out.rowOffsets.end(), 0); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/sequential/sq_kronecker.hpp b/cubool/sources/sequential/sq_kronecker.hpp index 1eb379e..df2d065 100644 --- a/cubool/sources/sequential/sq_kronecker.hpp +++ b/cubool/sources/sequential/sq_kronecker.hpp @@ -37,6 +37,6 @@ namespace cubool { */ void sq_kronecker(const CsrData& a, const CsrData& b, CsrData& out); -} +}// namespace cubool -#endif //CUBOOL_SP_KRONECKER_HPP +#endif//CUBOOL_SP_KRONECKER_HPP diff --git a/cubool/sources/sequential/sq_matrix.cpp b/cubool/sources/sequential/sq_matrix.cpp index 00473f1..eaad8c8 100644 --- a/cubool/sources/sequential/sq_matrix.cpp +++ b/cubool/sources/sequential/sq_matrix.cpp @@ -22,18 +22,18 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include -#include -#include -#include +#include +#include #include #include #include -#include +#include +#include #include +#include +#include +#include #include -#include -#include namespace cubool { @@ -49,7 +49,7 @@ namespace cubool { RAISE_ERROR(NotImplemented, "This function is not supported for this matrix class"); } - void SqMatrix::build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) { + void SqMatrix::build(const index* rows, const index* cols, size_t nvals, bool isSorted, bool noDuplicates) { auto nrows = mData.nrows; auto ncols = mData.ncols; @@ -62,7 +62,7 @@ namespace cubool { mData.nvals = mData.colIndices.size(); } - void SqMatrix::extract(index *rows, index *cols, size_t &nvals) { + void SqMatrix::extract(index* rows, index* cols, size_t& nvals) { assert(nvals >= getNvals()); nvals = getNvals(); @@ -71,7 +71,7 @@ namespace cubool { } } - void SqMatrix::extractSubMatrix(const MatrixBase &otherBase, index i, index j, index nrows, index ncols, + void SqMatrix::extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols, bool checkTime) { auto other = dynamic_cast(&otherBase); @@ -86,7 +86,7 @@ namespace cubool { sq_submatrix(other->mData, this->mData, i, j, nrows, ncols); } - void SqMatrix::clone(const MatrixBase &otherBase) { + void SqMatrix::clone(const MatrixBase& otherBase) { auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Provided matrix does not belongs to sequential matrix class"); @@ -98,7 +98,7 @@ namespace cubool { this->mData = other->mData; } - void SqMatrix::transpose(const MatrixBase &otherBase, bool checkTime) { + void SqMatrix::transpose(const MatrixBase& otherBase, bool checkTime) { auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Provided matrix does not belongs to sequential matrix class"); @@ -117,7 +117,7 @@ namespace cubool { this->mData = std::move(out); } - void SqMatrix::reduce(const MatrixBase &otherBase, bool checkTime) { + void SqMatrix::reduce(const MatrixBase& otherBase, bool checkTime) { auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Provided matrix does not belongs to sequential matrix class"); @@ -136,7 +136,7 @@ namespace cubool { this->mData = std::move(out); } - void SqMatrix::multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) { + void SqMatrix::multiply(const MatrixBase& aBase, const MatrixBase& bBase, bool accumulate, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -169,7 +169,7 @@ namespace cubool { this->mData = std::move(out); } - void SqMatrix::kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void SqMatrix::kronecker(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -190,7 +190,7 @@ namespace cubool { this->mData = std::move(out); } - void SqMatrix::eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void SqMatrix::eWiseAdd(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -213,7 +213,7 @@ namespace cubool { this->mData = std::move(out); } - void SqMatrix::eWiseMult(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void SqMatrix::eWiseMult(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -236,7 +236,7 @@ namespace cubool { this->mData = std::move(out); } - void SqMatrix::eWiseMultInverted(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) { + void SqMatrix::eWiseMultInverted(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -260,7 +260,6 @@ namespace cubool { } - index SqMatrix::getNrows() const { return mData.nrows; } @@ -279,4 +278,4 @@ namespace cubool { mData.rowOffsets.resize(getNrows() + 1, 0); } } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/sequential/sq_matrix.hpp b/cubool/sources/sequential/sq_matrix.hpp index d348232..064a1ed 100644 --- a/cubool/sources/sequential/sq_matrix.hpp +++ b/cubool/sources/sequential/sq_matrix.hpp @@ -33,25 +33,25 @@ namespace cubool { /** * Csr matrix for Cpu side operations in sequential backend. */ - class SqMatrix final: public MatrixBase { + class SqMatrix final : public MatrixBase { public: SqMatrix(size_t nrows, size_t ncols); ~SqMatrix() override = default; void setElement(index i, index j) override; - void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) override; - void extract(index *rows, index *cols, size_t &nvals) override; - void extractSubMatrix(const MatrixBase &otherBase, index i, index j, index nrows, index ncols, bool checkTime) override; + void build(const index* rows, const index* cols, size_t nvals, bool isSorted, bool noDuplicates) override; + void extract(index* rows, index* cols, size_t& nvals) override; + void extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols, bool checkTime) override; - void clone(const MatrixBase &otherBase) override; - void transpose(const MatrixBase &otherBase, bool checkTime) override; - void reduce(const MatrixBase &otherBase, bool checkTime) override; + void clone(const MatrixBase& otherBase) override; + void transpose(const MatrixBase& otherBase, bool checkTime) override; + void reduce(const MatrixBase& otherBase, bool checkTime) override; - void multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) override; - void kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) override; - void eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) override; - void eWiseMult(const MatrixBase &a, const MatrixBase &b, bool checkTime) override; - void eWiseMultInverted(const MatrixBase &a, const MatrixBase &b, bool checkTime) override; + void multiply(const MatrixBase& aBase, const MatrixBase& bBase, bool accumulate, bool checkTime) override; + void kronecker(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) override; + void eWiseAdd(const MatrixBase& aBase, const MatrixBase& bBase, bool checkTime) override; + void eWiseMult(const MatrixBase& a, const MatrixBase& b, bool checkTime) override; + void eWiseMultInverted(const MatrixBase& a, const MatrixBase& b, bool checkTime) override; index getNrows() const override; index getNcols() const override; @@ -64,6 +64,6 @@ namespace cubool { mutable CsrData mData; }; -} +}// namespace cubool -#endif //CUBOOL_SQ_MATRIX_HPP +#endif//CUBOOL_SQ_MATRIX_HPP diff --git a/cubool/sources/sequential/sq_reduce.cpp b/cubool/sources/sequential/sq_reduce.cpp index 0035d4d..2d0de9a 100644 --- a/cubool/sources/sequential/sq_reduce.cpp +++ b/cubool/sources/sequential/sq_reduce.cpp @@ -22,9 +22,9 @@ /* SOFTWARE. */ /**********************************************************************************/ +#include #include #include -#include namespace cubool { @@ -70,15 +70,15 @@ namespace cubool { } void sq_reduce_transposed(const CsrData& a, VecData& out) { - const auto max = std::numeric_limits::max(); + const auto max = std::numeric_limits::max(); std::vector mask(a.ncols, max); - for (auto j: a.colIndices) { + for (auto j : a.colIndices) { mask[j] = j; } size_t size = 0; - for (auto v: mask) { + for (auto v : mask) { if (v != max) { size += 1; } @@ -87,11 +87,11 @@ namespace cubool { out.indices.reserve(size); out.nvals = size; - for (auto v: mask) { + for (auto v : mask) { if (v != max) { out.indices.push_back(v); } } } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/sequential/sq_reduce.hpp b/cubool/sources/sequential/sq_reduce.hpp index 02f3534..e029f2d 100644 --- a/cubool/sources/sequential/sq_reduce.hpp +++ b/cubool/sources/sequential/sq_reduce.hpp @@ -52,6 +52,6 @@ namespace cubool { * @param[out] out Where to store result */ void sq_reduce_transposed(const CsrData& a, VecData& out); -} +}// namespace cubool -#endif //CUBOOL_SP_REDUCE_HPP +#endif//CUBOOL_SP_REDUCE_HPP diff --git a/cubool/sources/sequential/sq_spgemm.cpp b/cubool/sources/sequential/sq_spgemm.cpp index db2a821..8406eb7 100644 --- a/cubool/sources/sequential/sq_spgemm.cpp +++ b/cubool/sources/sequential/sq_spgemm.cpp @@ -22,10 +22,10 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include -#include #include #include +#include +#include namespace cubool { @@ -69,9 +69,9 @@ namespace cubool { mask.resize(b.ncols, max); for (index i = 0; i < a.nrows; i++) { - size_t id = 0; + size_t id = 0; size_t first = out.rowOffsets[i]; - size_t last = out.rowOffsets[i + 1]; + size_t last = out.rowOffsets[i + 1]; for (index ak = a.rowOffsets[i]; ak < a.rowOffsets[i + 1]; ak++) { index k = a.colIndices[ak]; @@ -81,7 +81,7 @@ namespace cubool { // Do not compute col nnz twice if (mask[j] != i) { - mask[j] = i; + mask[j] = i; out.colIndices[first + id] = j; id += 1; } @@ -93,4 +93,4 @@ namespace cubool { } } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/sequential/sq_spgemm.hpp b/cubool/sources/sequential/sq_spgemm.hpp index 66ce098..b58a8ec 100644 --- a/cubool/sources/sequential/sq_spgemm.hpp +++ b/cubool/sources/sequential/sq_spgemm.hpp @@ -38,6 +38,6 @@ namespace cubool { */ void sq_spgemm(const CsrData& a, const CsrData& b, CsrData& out); -} +}// namespace cubool -#endif //CUBOOL_SQ_SPGEMM_HPP +#endif//CUBOOL_SQ_SPGEMM_HPP diff --git a/cubool/sources/sequential/sq_spgemv.cpp b/cubool/sources/sequential/sq_spgemv.cpp index cb9c3e7..b4cc9bc 100644 --- a/cubool/sources/sequential/sq_spgemv.cpp +++ b/cubool/sources/sequential/sq_spgemv.cpp @@ -42,11 +42,9 @@ namespace cubool { if (*ar == *vr) { nonZero = true; break; - } - else if (*ar < *vr) { + } else if (*ar < *vr) { ar++; - } - else { + } else { vr++; } } @@ -56,14 +54,14 @@ namespace cubool { } } - out.nvals = result.size(); + out.nvals = result.size(); out.indices = std::move(result); } void sq_spgemv_transposed(const CsrData& a, const VecData& b, VecData& out) { std::vector mask(a.ncols, false); - for (index i: b.indices) { + for (index i : b.indices) { for (index k = a.rowOffsets[i]; k < a.rowOffsets[i + 1]; k++) { mask[a.colIndices[k]] = true; } @@ -76,8 +74,8 @@ namespace cubool { result.push_back(i); } - out.nvals = result.size(); + out.nvals = result.size(); out.indices = std::move(result); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/sequential/sq_spgemv.hpp b/cubool/sources/sequential/sq_spgemv.hpp index 6975fa9..1c6af0b 100644 --- a/cubool/sources/sequential/sq_spgemv.hpp +++ b/cubool/sources/sequential/sq_spgemv.hpp @@ -47,6 +47,6 @@ namespace cubool { */ void sq_spgemv_transposed(const CsrData& a, const VecData& b, VecData& out); -} +}// namespace cubool -#endif //CUBOOL_SQ_SPGEMV_HPP +#endif//CUBOOL_SQ_SPGEMV_HPP diff --git a/cubool/sources/sequential/sq_submatrix.cpp b/cubool/sources/sequential/sq_submatrix.cpp index 0e28442..5e63362 100644 --- a/cubool/sources/sequential/sq_submatrix.cpp +++ b/cubool/sources/sequential/sq_submatrix.cpp @@ -28,8 +28,8 @@ namespace cubool { void sq_submatrix(const CsrData& a, CsrData& sub, index i, index j, index nrows, index ncols) { - index first = i; - index last = i + nrows; + index first = i; + index last = i + nrows; size_t nvals = 0; for (index ai = first; ai < last; ai++) { @@ -67,4 +67,4 @@ namespace cubool { exclusive_scan(sub.rowOffsets.begin(), sub.rowOffsets.end(), 0); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/sequential/sq_submatrix.hpp b/cubool/sources/sequential/sq_submatrix.hpp index d4b6a8e..cd66b4a 100644 --- a/cubool/sources/sequential/sq_submatrix.hpp +++ b/cubool/sources/sequential/sq_submatrix.hpp @@ -41,6 +41,6 @@ namespace cubool { */ void sq_submatrix(const CsrData& a, CsrData& sub, index i, index j, index nrows, index ncols); -} +}// namespace cubool -#endif //CUBOOL_SQ_SUBMATRIX_HPP +#endif//CUBOOL_SQ_SUBMATRIX_HPP diff --git a/cubool/sources/sequential/sq_subvector.cpp b/cubool/sources/sequential/sq_subvector.cpp index 51a4b93..c2f1496 100644 --- a/cubool/sources/sequential/sq_subvector.cpp +++ b/cubool/sources/sequential/sq_subvector.cpp @@ -32,11 +32,11 @@ namespace cubool { } index first = i; - index last = i + nrows; + index last = i + nrows; size_t size = 0; - for (auto v: a.indices) { + for (auto v : a.indices) { if (first <= v && v < last) { size += 1; } @@ -46,11 +46,11 @@ namespace cubool { out.indices.reserve(size); out.nvals = size; - for (auto v: a.indices) { + for (auto v : a.indices) { if (first <= v && v < last) { out.indices.push_back(v - i); } } } -} +}// namespace cubool diff --git a/cubool/sources/sequential/sq_subvector.hpp b/cubool/sources/sequential/sq_subvector.hpp index 9882416..768a3c0 100644 --- a/cubool/sources/sequential/sq_subvector.hpp +++ b/cubool/sources/sequential/sq_subvector.hpp @@ -39,6 +39,6 @@ namespace cubool { */ void sq_subvector(const VecData& a, index i, index nrows, VecData& out); -} +}// namespace cubool -#endif //CUBOOL_SQ_SUBVECTOR_HPP +#endif//CUBOOL_SQ_SUBVECTOR_HPP diff --git a/cubool/sources/sequential/sq_transpose.cpp b/cubool/sources/sequential/sq_transpose.cpp index 1c2540b..75ad13e 100644 --- a/cubool/sources/sequential/sq_transpose.cpp +++ b/cubool/sources/sequential/sq_transpose.cpp @@ -55,4 +55,4 @@ namespace cubool { exclusive_scan(at.rowOffsets.begin(), at.rowOffsets.end(), 0); } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/sequential/sq_transpose.hpp b/cubool/sources/sequential/sq_transpose.hpp index bcfee2a..1a05220 100644 --- a/cubool/sources/sequential/sq_transpose.hpp +++ b/cubool/sources/sequential/sq_transpose.hpp @@ -36,6 +36,6 @@ namespace cubool { */ void sq_transpose(const CsrData& a, CsrData& at); -} +}// namespace cubool -#endif //CUBOOL_SQ_TRANSPOSE_HPP +#endif//CUBOOL_SQ_TRANSPOSE_HPP diff --git a/cubool/sources/sequential/sq_vector.cpp b/cubool/sources/sequential/sq_vector.cpp index 4af67e8..2f54a64 100644 --- a/cubool/sources/sequential/sq_vector.cpp +++ b/cubool/sources/sequential/sq_vector.cpp @@ -22,17 +22,17 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include -#include -#include +#include +#include +#include #include #include -#include +#include +#include #include +#include +#include #include -#include -#include -#include namespace cubool { @@ -46,14 +46,14 @@ namespace cubool { RAISE_ERROR(NotImplemented, "This function is not implemented"); } - void SqVector::build(const index *rows, size_t nvals, bool isSorted, bool noDuplicates) { + void SqVector::build(const index* rows, size_t nvals, bool isSorted, bool noDuplicates) { // Utility used to reduce duplicates and sort values if needed DataUtils::buildVectorFromData(mData.nrows, rows, nvals, mData.indices, isSorted, noDuplicates); mData.nvals = mData.indices.size(); } - void SqVector::extract(index *rows, size_t &nvals) { + void SqVector::extract(index* rows, size_t& nvals) { assert(nvals >= getNvals()); nvals = mData.nvals; @@ -62,7 +62,7 @@ namespace cubool { } } - void SqVector::extractSubVector(const VectorBase &otherBase, index i, index nrows, bool checkTime) { + void SqVector::extractSubVector(const VectorBase& otherBase, index i, index nrows, bool checkTime) { auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Provided vector does not belongs to sequential vector class"); @@ -72,7 +72,7 @@ namespace cubool { sq_subvector(other->mData, i, nrows, this->mData); } - void SqVector::extractRow(const class MatrixBase &matrixBase, index i) { + void SqVector::extractRow(const class MatrixBase& matrixBase, index i) { auto matrix = dynamic_cast(&matrixBase); CHECK_RAISE_ERROR(matrix != nullptr, InvalidArgument, "Provided matrix does not belongs to sequential matrix class"); @@ -83,7 +83,7 @@ namespace cubool { auto& m = matrix->mData; auto begin = m.rowOffsets[i]; - auto end = m.rowOffsets[i + 1]; + auto end = m.rowOffsets[i + 1]; VecData r; r.nrows = m.ncols; @@ -95,7 +95,7 @@ namespace cubool { mData = std::move(r); } - void SqVector::extractCol(const class MatrixBase &matrixBase, index j) { + void SqVector::extractCol(const class MatrixBase& matrixBase, index j) { auto matrix = dynamic_cast(&matrixBase); CHECK_RAISE_ERROR(matrix != nullptr, InvalidArgument, "Provided matrix does not belongs to sequential matrix class"); @@ -110,10 +110,10 @@ namespace cubool { for (index i = 0; i < m.nrows; i++) { auto beginOffset = m.rowOffsets[i]; - auto endOffset = m.rowOffsets[i + 1]; + auto endOffset = m.rowOffsets[i + 1]; auto begin = m.colIndices.begin() + beginOffset; - auto end = m.colIndices.begin() + endOffset; + auto end = m.colIndices.begin() + endOffset; auto res = std::lower_bound(begin, end, j); @@ -126,7 +126,7 @@ namespace cubool { mData = std::move(r); } - void SqVector::clone(const VectorBase &otherBase) { + void SqVector::clone(const VectorBase& otherBase) { auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Provided vector does not belongs to sequential vector class"); @@ -137,11 +137,11 @@ namespace cubool { mData = other->mData; } - void SqVector::reduce(index &result, bool checkTime) { + void SqVector::reduce(index& result, bool checkTime) { result = getNvals(); } - void SqVector::reduceMatrix(const MatrixBase &otherBase, bool transpose, bool checkTime) { + void SqVector::reduceMatrix(const MatrixBase& otherBase, bool transpose, bool checkTime) { auto other = dynamic_cast(&otherBase); CHECK_RAISE_ERROR(other != nullptr, InvalidArgument, "Provided matrix does not belongs to sequential matrix class"); @@ -164,7 +164,7 @@ namespace cubool { mData = std::move(out); } - void SqVector::eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) { + void SqVector::eWiseMult(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -182,7 +182,7 @@ namespace cubool { mData = std::move(out); } - void SqVector::eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) { + void SqVector::eWiseAdd(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) { auto a = dynamic_cast(&aBase); auto b = dynamic_cast(&bBase); @@ -200,7 +200,7 @@ namespace cubool { mData = std::move(out); } - void SqVector::multiplyVxM(const VectorBase &vBase, const class MatrixBase &mBase, bool checkTime) { + void SqVector::multiplyVxM(const VectorBase& vBase, const class MatrixBase& mBase, bool checkTime) { auto v = dynamic_cast(&vBase); auto m = dynamic_cast(&mBase); @@ -218,7 +218,7 @@ namespace cubool { mData = std::move(out); } - void SqVector::multiplyMxV(const class MatrixBase &mBase, const VectorBase &vBase, bool checkTime) { + void SqVector::multiplyMxV(const class MatrixBase& mBase, const VectorBase& vBase, bool checkTime) { auto v = dynamic_cast(&vBase); auto m = dynamic_cast(&mBase); @@ -244,4 +244,4 @@ namespace cubool { return mData.nvals; } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/sequential/sq_vector.hpp b/cubool/sources/sequential/sq_vector.hpp index 8f9c5e9..8cad495 100644 --- a/cubool/sources/sequential/sq_vector.hpp +++ b/cubool/sources/sequential/sq_vector.hpp @@ -30,24 +30,24 @@ namespace cubool { - class SqVector final: public VectorBase { + class SqVector final : public VectorBase { public: explicit SqVector(size_t nrows); ~SqVector() override = default; void setElement(index i) override; - void build(const index *rows, size_t nvals, bool isSorted, bool noDuplicates) override; - void extract(index *rows, size_t &nvals) override; - void extractSubVector(const VectorBase &otherBase, index i, index nrows, bool checkTime) override; + void build(const index* rows, size_t nvals, bool isSorted, bool noDuplicates) override; + void extract(index* rows, size_t& nvals) override; + void extractSubVector(const VectorBase& otherBase, index i, index nrows, bool checkTime) override; void extractRow(const class MatrixBase& matrixBase, index i) override; void extractCol(const class MatrixBase& matrixBase, index j) override; - void clone(const VectorBase &otherBase) override; - void reduce(index &result, bool checkTime) override; - void reduceMatrix(const class MatrixBase &matrix, bool transpose, bool checkTime) override; + void clone(const VectorBase& otherBase) override; + void reduce(index& result, bool checkTime) override; + void reduceMatrix(const class MatrixBase& matrix, bool transpose, bool checkTime) override; - void eWiseMult(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override; - void eWiseAdd(const VectorBase &aBase, const VectorBase &bBase, bool checkTime) override; + void eWiseMult(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) override; + void eWiseAdd(const VectorBase& aBase, const VectorBase& bBase, bool checkTime) override; void multiplyVxM(const VectorBase& vBase, const class MatrixBase& mBase, bool checkTime) override; void multiplyMxV(const class MatrixBase& mBase, const VectorBase& vBase, bool checkTime) override; @@ -55,10 +55,9 @@ namespace cubool { index getNvals() const override; private: - mutable VecData mData; }; -} +}// namespace cubool -#endif //CUBOOL_SQ_VECTOR_HPP +#endif//CUBOOL_SQ_VECTOR_HPP diff --git a/cubool/sources/utils/algo_utils.hpp b/cubool/sources/utils/algo_utils.hpp index ceb7aed..5977867 100644 --- a/cubool/sources/utils/algo_utils.hpp +++ b/cubool/sources/utils/algo_utils.hpp @@ -27,17 +27,17 @@ namespace cubool { - template + template void exclusive_scan(FirstT firstT, LastT lastT, T initial) { T sum = initial; while (firstT != lastT) { - T next = sum + *firstT; + T next = sum + *firstT; *firstT = sum; - sum = next; + sum = next; firstT++; } } -} +}// namespace cubool -#endif //CUBOOL_ALGO_UTILS_HPP +#endif//CUBOOL_ALGO_UTILS_HPP diff --git a/cubool/sources/utils/data_utils.cpp b/cubool/sources/utils/data_utils.cpp index fab1ffa..46a6c8d 100644 --- a/cubool/sources/utils/data_utils.cpp +++ b/cubool/sources/utils/data_utils.cpp @@ -22,17 +22,17 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include -#include -#include #include #include +#include +#include +#include namespace cubool { void DataUtils::buildFromData(size_t nrows, size_t ncols, - const index *rows, const index *cols, size_t nvals, - std::vector &rowOffsets, std::vector &colIndices, + const index* rows, const index* cols, size_t nvals, + std::vector& rowOffsets, std::vector& colIndices, bool isSorted, bool noDuplicates) { rowOffsets.resize(nrows + 1, 0); @@ -70,7 +70,7 @@ namespace cubool { if (!isSorted) { for (size_t i = 0; i < nrows; i++) { auto begin = rowOffsets[i]; - auto end = rowOffsets[i + 1]; + auto end = rowOffsets[i + 1]; // Sort col values within row std::sort(colIndices.begin() + begin, colIndices.begin() + end, [](const index& a, const index& b) { @@ -122,8 +122,8 @@ namespace cubool { } void DataUtils::extractData(size_t nrows, size_t ncols, - index *rows, index *cols, size_t nvals, - const std::vector &rowOffsets, const std::vector &colIndices) { + index* rows, index* cols, size_t nvals, + const std::vector& rowOffsets, const std::vector& colIndices) { assert(rows); assert(cols); @@ -137,15 +137,15 @@ namespace cubool { } } - bool checkBounds(const std::vector &values, index left, index right) { - for (auto v: values) { + bool checkBounds(const std::vector& values, index left, index right) { + for (auto v : values) { CHECK_RAISE_ERROR(left <= v && v < right, InvalidArgument, "Index out of vector bounds"); } return true; } - void DataUtils::buildVectorFromData(size_t nrows, const index *rows, size_t nvals, std::vector &values, + void DataUtils::buildVectorFromData(size_t nrows, const index* rows, size_t nvals, std::vector& values, bool isSorted, bool noDuplicates) { values.resize(nvals); std::copy(rows, rows + nvals, values.begin()); @@ -165,7 +165,7 @@ namespace cubool { if (!noDuplicates) { size_t unique = 0; - index prev = std::numeric_limits::max(); + index prev = std::numeric_limits::max(); for (auto value : values) { if (prev != value) { @@ -191,4 +191,4 @@ namespace cubool { } } -} \ No newline at end of file +}// namespace cubool \ No newline at end of file diff --git a/cubool/sources/utils/data_utils.hpp b/cubool/sources/utils/data_utils.hpp index b7863b3..ccf76fb 100644 --- a/cubool/sources/utils/data_utils.hpp +++ b/cubool/sources/utils/data_utils.hpp @@ -26,8 +26,8 @@ #define CUBOOL_DATA_UTILS_HPP #include -#include #include +#include namespace cubool { @@ -47,6 +47,6 @@ namespace cubool { bool isSorted, bool noDuplicates); }; -} +}// namespace cubool -#endif //CUBOOL_DATA_UTILS_HPP +#endif//CUBOOL_DATA_UTILS_HPP diff --git a/cubool/sources/utils/timer.hpp b/cubool/sources/utils/timer.hpp index e9c8032..90ad673 100644 --- a/cubool/sources/utils/timer.hpp +++ b/cubool/sources/utils/timer.hpp @@ -50,12 +50,12 @@ namespace cubool { } private: - using clock = std::chrono::high_resolution_clock; + using clock = std::chrono::high_resolution_clock; using timepoint = clock::time_point; timepoint mStart; timepoint mEnd; }; -} +}// namespace cubool -#endif //CUBOOL_TIMER_HPP +#endif//CUBOOL_TIMER_HPP diff --git a/cubool/tests/test_library_api.cpp b/cubool/tests/test_library_api.cpp index 084abe3..0701d19 100644 --- a/cubool/tests/test_library_api.cpp +++ b/cubool/tests/test_library_api.cpp @@ -60,16 +60,16 @@ TEST(cuBool, Setup) { * @return Status on this operation */ cuBool_Status TransitiveClosure(cuBool_Matrix A, cuBool_Matrix* T) { - cuBool_Matrix_Duplicate(A, T); /* Duplicate A to result T */ + cuBool_Matrix_Duplicate(A, T); /* Duplicate A to result T */ cuBool_Index total = 0; cuBool_Index current; - cuBool_Matrix_Nvals(*T, ¤t); /* Query current nvals value */ + cuBool_Matrix_Nvals(*T, ¤t); /* Query current nvals value */ - while (current != total) { /* Iterate, while new values are added */ + while (current != total) { /* Iterate, while new values are added */ total = current; - cuBool_MxM(*T, *T, *T, CUBOOL_HINT_ACCUMULATE); /* T += T x T */ + cuBool_MxM(*T, *T, *T, CUBOOL_HINT_ACCUMULATE); /* T += T x T */ cuBool_Matrix_Nvals(*T, ¤t); } @@ -85,22 +85,21 @@ TEST(cuBool, TsExample) { cuBool_Initialize(CUBOOL_HINT_NO); cuBool_Matrix_New(&A, n, n); - testing::Matrix ta = testing::Matrix::generateSparse(n , n, 0.2); + testing::Matrix ta = testing::Matrix::generateSparse(n, n, 0.2); cuBool_Matrix_Build(A, ta.rowsIndex.data(), ta.colsIndex.data(), ta.nvals, CUBOOL_HINT_VALUES_SORTED); TransitiveClosure(A, &T); testing::Matrix tr = ta; - size_t total; + size_t total; do { total = tr.nvals; testing::MatrixMultiplyFunctor functor; tr = std::move(functor(tr, tr, tr, true)); - } - while (tr.nvals != total); + } while (tr.nvals != total); ASSERT_TRUE(tr.areEqual(T)); @@ -128,10 +127,10 @@ TEST(cuBool, DeviceCaps) { ASSERT_EQ(cuBool_GetDeviceCaps(&caps), CUBOOL_STATUS_SUCCESS); std::cout - << "name: " << caps.name << std::endl - << "major: " << caps.major << std::endl - << "minor: " << caps.minor << std::endl - << "cuda supported: " << caps.cudaSupported << std::endl; + << "name: " << caps.name << std::endl + << "major: " << caps.major << std::endl + << "minor: " << caps.minor << std::endl + << "cuda supported: " << caps.cudaSupported << std::endl; ASSERT_EQ(cuBool_Finalize(), CUBOOL_STATUS_SUCCESS); } diff --git a/cubool/tests/test_matrix_element.cpp b/cubool/tests/test_matrix_element.cpp index e383b69..e9c3d92 100644 --- a/cubool/tests/test_matrix_element.cpp +++ b/cubool/tests/test_matrix_element.cpp @@ -30,18 +30,18 @@ void testMatrixSetElement(cuBool_Index m, cuBool_Index n, float density) { testing::Matrix tmatrix = std::move(testing::Matrix::generateSparse(m, n, density)); - auto I = tmatrix.rowsIndex; - auto J = tmatrix.colsIndex; + auto I = tmatrix.rowsIndex; + auto J = tmatrix.colsIndex; size_t nvals = tmatrix.nvals; - size_t dups = nvals * 0.10; + size_t dups = nvals * 0.10; std::default_random_engine engine(std::chrono::system_clock::now().time_since_epoch().count()); - auto dist = std::uniform_real_distribution(0.0, 1.0); + auto dist = std::uniform_real_distribution(0.0, 1.0); if (nvals > 0) { for (size_t k = 0; k < dups; k++) { size_t id = std::min(dist(engine) * nvals, nvals - 1); - auto i = I[id], j = J[id]; + auto i = I[id], j = J[id]; I.push_back(i); J.push_back(j); } @@ -71,16 +71,16 @@ void testMatrixAppendElement(cuBool_Index m, cuBool_Index n, float density) { std::vector I; std::vector J; - size_t nvals = tmatrix.nvals; - size_t dups = nvals * 0.20; + size_t nvals = tmatrix.nvals; + size_t dups = nvals * 0.20; std::default_random_engine engine(std::chrono::system_clock::now().time_since_epoch().count()); - auto dist = std::uniform_real_distribution(0.0, 1.0); + auto dist = std::uniform_real_distribution(0.0, 1.0); if (nvals > 0) { for (size_t k = 0; k < dups; k++) { size_t id = std::min(dist(engine) * nvals, nvals - 1); - auto i = tmatrix.rowsIndex[id], j = tmatrix.colsIndex[id]; + auto i = tmatrix.rowsIndex[id], j = tmatrix.colsIndex[id]; I.push_back(i); J.push_back(j); } @@ -99,7 +99,7 @@ void testMatrixAppendElement(cuBool_Index m, cuBool_Index n, float density) { } void testMatrixPostAppendElement(cuBool_Index m, cuBool_Index n, float density) { - cuBool_Matrix matrix = nullptr; + cuBool_Matrix matrix = nullptr; cuBool_Matrix duplicated = nullptr; testing::Matrix tmatrix = std::move(testing::Matrix::generateSparse(m, n, density)); diff --git a/cubool/tests/test_matrix_ewiseadd.cpp b/cubool/tests/test_matrix_ewiseadd.cpp index 1fd9ca7..9bbca0b 100644 --- a/cubool/tests/test_matrix_ewiseadd.cpp +++ b/cubool/tests/test_matrix_ewiseadd.cpp @@ -44,7 +44,7 @@ void testMatrixAdd(cuBool_Index m, cuBool_Index n, float density, cuBool_Hints f // Evaluate naive r += a on the cpu to compare results testing::MatrixEWiseAddFunctor functor; - auto tr = std::move(functor(ta, tb)); + auto tr = std::move(functor(ta, tb)); // Compare results ASSERT_EQ(tr.areEqual(r), true); diff --git a/cubool/tests/test_matrix_ewisemult.cpp b/cubool/tests/test_matrix_ewisemult.cpp index a556d8e..a1479f2 100644 --- a/cubool/tests/test_matrix_ewisemult.cpp +++ b/cubool/tests/test_matrix_ewisemult.cpp @@ -44,7 +44,7 @@ void testMatrixMult(cuBool_Index m, cuBool_Index n, float density, cuBool_Hints // Evaluate naive r += a on the cpu to compare results testing::MatrixEWiseMultFunctor functor; - auto tr = std::move(functor(ta, tb)); + auto tr = std::move(functor(ta, tb)); // Compare results ASSERT_EQ(tr.areEqual(r), true); diff --git a/cubool/tests/test_matrix_ewisemult_inverted.cpp b/cubool/tests/test_matrix_ewisemult_inverted.cpp index 250ba55..f29430b 100644 --- a/cubool/tests/test_matrix_ewisemult_inverted.cpp +++ b/cubool/tests/test_matrix_ewisemult_inverted.cpp @@ -1,19 +1,19 @@ #include "cubool/cubool.h" -#include #include +#include using DataMatrix = std::vector>; -void testApplyNotMask(const DataMatrix &matrix_data, const DataMatrix &mask_data) { +void testApplyNotMask(const DataMatrix& matrix_data, const DataMatrix& mask_data) { cuBool_Index nrows, ncols; - nrows = matrix_data.size(); - ncols = matrix_data[0].size(); + nrows = matrix_data.size(); + ncols = matrix_data[0].size(); testing::Matrix test_matrix = testing::Matrix::generatet(nrows, ncols, - [&matrix_data](cuBool_Index i, cuBool_Index j) { return matrix_data[i][j]; }); - nrows = mask_data.size(); - ncols = mask_data[0].size(); - testing::Matrix test_mask = testing::Matrix::generatet(nrows, ncols, - [&mask_data](cuBool_Index i, cuBool_Index j) { return mask_data[i][j]; }); + [&matrix_data](cuBool_Index i, cuBool_Index j) { return matrix_data[i][j]; }); + nrows = mask_data.size(); + ncols = mask_data[0].size(); + testing::Matrix test_mask = testing::Matrix::generatet(nrows, ncols, + [&mask_data](cuBool_Index i, cuBool_Index j) { return mask_data[i][j]; }); cuBool_Matrix matrix, mask, result; ASSERT_EQ(cuBool_Matrix_New(&matrix, test_matrix.nrows, test_matrix.ncols), CUBOOL_STATUS_SUCCESS); @@ -21,9 +21,11 @@ void testApplyNotMask(const DataMatrix &matrix_data, const DataMatrix &mask_data ASSERT_EQ(cuBool_Matrix_New(&result, test_matrix.nrows, test_matrix.ncols), CUBOOL_STATUS_SUCCESS); ASSERT_EQ(cuBool_Matrix_Build(matrix, test_matrix.rowsIndex.data(), test_matrix.colsIndex.data(), test_matrix.nvals, - CUBOOL_HINT_VALUES_SORTED & CUBOOL_HINT_NO_DUPLICATES), CUBOOL_STATUS_SUCCESS); + CUBOOL_HINT_VALUES_SORTED & CUBOOL_HINT_NO_DUPLICATES), + CUBOOL_STATUS_SUCCESS); ASSERT_EQ(cuBool_Matrix_Build(mask, test_mask.rowsIndex.data(), test_mask.colsIndex.data(), test_mask.nvals, - CUBOOL_HINT_VALUES_SORTED & CUBOOL_HINT_NO_DUPLICATES), CUBOOL_STATUS_SUCCESS); + CUBOOL_HINT_VALUES_SORTED & CUBOOL_HINT_NO_DUPLICATES), + CUBOOL_STATUS_SUCCESS); cuBool_Matrix_EWiseMulInverted(result, matrix, mask, CUBOOL_HINT_NO); @@ -38,8 +40,8 @@ void testApplyNotMask(const DataMatrix &matrix_data, const DataMatrix &mask_data cuBool_Matrix_Free(result); auto mask_data_inverted = mask_data; - for (auto &row : mask_data_inverted) { - for (int &value : row) { + for (auto& row : mask_data_inverted) { + for (int& value : row) { value = !value; } } @@ -54,22 +56,21 @@ void testApplyNotMask(const DataMatrix &matrix_data, const DataMatrix &mask_data ASSERT_EQ(matrix_data[i][j] * mask_data_inverted[i][j], result_data[i][j]); } } - } TEST(cuBool_Matrix, ApplyMatrix) { ASSERT_EQ(cuBool_Initialize(CUBOOL_HINT_NO), CUBOOL_STATUS_SUCCESS); - DataMatrix matrix { - {1, 0, 0}, - {0, 0, 0}, - {0, 1, 0}, + DataMatrix matrix{ + {1, 0, 0}, + {0, 0, 0}, + {0, 1, 0}, }; - DataMatrix mask { - {0, 1, 1}, - {1, 0, 1}, - {0, 1, 1}, + DataMatrix mask{ + {0, 1, 1}, + {1, 0, 1}, + {0, 1, 1}, }; // iverted is // 1 0 0 @@ -95,7 +96,7 @@ TEST(cuBool_Matrix, ApplyMatrixRandom) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { matrix[i][j] = rand() & 1; - mask[i][j] = rand() & 1; + mask[i][j] = rand() & 1; } } diff --git a/cubool/tests/test_matrix_extract_vector.cpp b/cubool/tests/test_matrix_extract_vector.cpp index c7686d6..1c4891e 100644 --- a/cubool/tests/test_matrix_extract_vector.cpp +++ b/cubool/tests/test_matrix_extract_vector.cpp @@ -50,7 +50,7 @@ void testMatrixExtractRow(cuBool_Index m, cuBool_Index n, float density, cuBool_ void testMatrixExtractCol(cuBool_Index m, cuBool_Index n, float density, cuBool_Hints flags) { cuBool_Matrix a; - auto ta = testing::Matrix::generateSparse(m, n, density); + auto ta = testing::Matrix::generateSparse(m, n, density); auto taT = ta.transpose(); ASSERT_EQ(cuBool_Matrix_New(&a, m, n), CUBOOL_STATUS_SUCCESS); diff --git a/cubool/tests/test_matrix_kronecker.cpp b/cubool/tests/test_matrix_kronecker.cpp index 7ec41cd..974b000 100644 --- a/cubool/tests/test_matrix_kronecker.cpp +++ b/cubool/tests/test_matrix_kronecker.cpp @@ -44,7 +44,7 @@ void testMatrixKronecker(cuBool_Index m, cuBool_Index n, cuBool_Index k, cuBool_ // Evaluate naive r = a `kron` b on the cpu to compare results testing::MatrixKroneckerFunctor functor; - testing::Matrix tr = std::move(functor(ta, tb)); + testing::Matrix tr = std::move(functor(ta, tb)); // Compare results EXPECT_EQ(tr.areEqual(r), true); @@ -70,63 +70,63 @@ void testRun(cuBool_Index m, cuBool_Index n, cuBool_Index k, cuBool_Index t, flo TEST(cuBool_Matrix, KroneckerSmall) { cuBool_Index m = 10, n = 20; cuBool_Index k = 5, t = 15; - float step = 0.05f; + float step = 0.05f; testRun(m, n, k, t, step, CUBOOL_HINT_NO); } TEST(cuBool_Matrix, KroneckerMedium) { cuBool_Index m = 100, n = 40; cuBool_Index k = 30, t = 80; - float step = 0.02f; + float step = 0.02f; testRun(m, n, k, t, step, CUBOOL_HINT_NO); } TEST(cuBool_Matrix, KroneckerLarge) { cuBool_Index m = 1000, n = 400; cuBool_Index k = 300, t = 800; - float step = 0.001f; + float step = 0.001f; testRun(m, n, k, t, step, CUBOOL_HINT_NO); } TEST(cuBool_Matrix, KroneckerSmallFallback) { cuBool_Index m = 10, n = 20; cuBool_Index k = 5, t = 15; - float step = 0.05f; + float step = 0.05f; testRun(m, n, k, t, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Matrix, KroneckerMediumFallback) { cuBool_Index m = 100, n = 40; cuBool_Index k = 30, t = 80; - float step = 0.02f; + float step = 0.02f; testRun(m, n, k, t, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Matrix, KroneckerLargeFallback) { cuBool_Index m = 1000, n = 400; cuBool_Index k = 300, t = 800; - float step = 0.001f; + float step = 0.001f; testRun(m, n, k, t, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Matrix, KroneckerSmallManaged) { cuBool_Index m = 10, n = 20; cuBool_Index k = 5, t = 15; - float step = 0.05f; + float step = 0.05f; testRun(m, n, k, t, step, CUBOOL_HINT_GPU_MEM_MANAGED); } TEST(cuBool_Matrix, KroneckerMediumManaged) { cuBool_Index m = 100, n = 40; cuBool_Index k = 30, t = 80; - float step = 0.02f; + float step = 0.02f; testRun(m, n, k, t, step, CUBOOL_HINT_GPU_MEM_MANAGED); } TEST(cuBool_Matrix, KroneckerLargeManaged) { cuBool_Index m = 1000, n = 400; cuBool_Index k = 300, t = 800; - float step = 0.001f; + float step = 0.001f; testRun(m, n, k, t, step, CUBOOL_HINT_GPU_MEM_MANAGED); } diff --git a/cubool/tests/test_matrix_misc.cpp b/cubool/tests/test_matrix_misc.cpp index cc12f24..a7c3e94 100644 --- a/cubool/tests/test_matrix_misc.cpp +++ b/cubool/tests/test_matrix_misc.cpp @@ -22,13 +22,13 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include #include +#include TEST(cuBool_Matrix, Duplicate) { cuBool_Matrix matrix = nullptr, duplicated = nullptr; - cuBool_Index m = 900, n = 600; - float density = 0.31; + cuBool_Index m = 900, n = 600; + float density = 0.31; testing::Matrix tmatrix = std::move(testing::Matrix::generateSparse(m, n, density)); @@ -49,8 +49,8 @@ TEST(cuBool_Matrix, Duplicate) { TEST(cuBool_Matrix, PropertyQuery) { cuBool_Matrix matrix = nullptr; - cuBool_Index m = 900, n = 600; - float density = 0.21; + cuBool_Index m = 900, n = 600; + float density = 0.21; testing::Matrix tmatrix = std::move(testing::Matrix::generateSparse(m, n, density)); @@ -78,8 +78,8 @@ TEST(cuBool_Matrix, PropertyQuery) { TEST(cuBool_Matrix, ExtractPairs) { cuBool_Matrix matrix = nullptr; - cuBool_Index m = 900, n = 600; - float density = 0.21; + cuBool_Index m = 900, n = 600; + float density = 0.21; testing::Matrix tmatrix = std::move(testing::Matrix::generateSparse(m, n, density)); @@ -88,7 +88,7 @@ TEST(cuBool_Matrix, ExtractPairs) { ASSERT_EQ(cuBool_Matrix_New(&matrix, m, n), CUBOOL_STATUS_SUCCESS); ASSERT_EQ(cuBool_Matrix_Build(matrix, tmatrix.rowsIndex.data(), tmatrix.colsIndex.data(), tmatrix.nvals, CUBOOL_HINT_VALUES_SORTED), CUBOOL_STATUS_SUCCESS); - cuBool_Index nvals = tmatrix.nvals; + cuBool_Index nvals = tmatrix.nvals; std::vector rows(tmatrix.nvals); std::vector cols(tmatrix.nvals); @@ -101,14 +101,14 @@ TEST(cuBool_Matrix, ExtractPairs) { TEST(cuBool_Matrix, Marker) { cuBool_Matrix matrix = nullptr; - cuBool_Index m, n; + cuBool_Index m, n; m = n = 100; const cuBool_Index BUFFER_SIZE = 100; - const char* marker = "Test Matrix Marker"; - cuBool_Index size = 0; - char buffer[BUFFER_SIZE]; + const char* marker = "Test Matrix Marker"; + cuBool_Index size = 0; + char buffer[BUFFER_SIZE]; ASSERT_EQ(cuBool_Initialize(CUBOOL_HINT_NO), CUBOOL_STATUS_SUCCESS); ASSERT_EQ(cuBool_Matrix_New(&matrix, m, n), CUBOOL_STATUS_SUCCESS); @@ -128,14 +128,14 @@ TEST(cuBool_Matrix, Marker) { TEST(cuBool_Matrix, MarkerShort) { cuBool_Matrix matrix = nullptr; - cuBool_Index m, n; + cuBool_Index m, n; m = n = 100; const cuBool_Index BUFFER_SIZE = 10; - const char* marker = "Test Matrix Marker"; - cuBool_Index size = BUFFER_SIZE; - char buffer[BUFFER_SIZE]; + const char* marker = "Test Matrix Marker"; + cuBool_Index size = BUFFER_SIZE; + char buffer[BUFFER_SIZE]; ASSERT_EQ(cuBool_Initialize(CUBOOL_HINT_NO), CUBOOL_STATUS_SUCCESS); ASSERT_EQ(cuBool_Matrix_New(&matrix, m, n), CUBOOL_STATUS_SUCCESS); diff --git a/cubool/tests/test_matrix_reduce.cpp b/cubool/tests/test_matrix_reduce.cpp index 4e2e952..63cbb73 100644 --- a/cubool/tests/test_matrix_reduce.cpp +++ b/cubool/tests/test_matrix_reduce.cpp @@ -108,55 +108,55 @@ void testRun(cuBool_Index m, cuBool_Index n, float step, cuBool_Hints setup) { TEST(cuBool_Matrix, ReduceSmall) { cuBool_Index m = 100, n = 200; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_NO); } TEST(cuBool_Matrix, ReduceMedium) { cuBool_Index m = 400, n = 700; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_NO); } TEST(cuBool_Matrix, ReduceLarge) { cuBool_Index m = 2000, n = 4000; - float step = 0.01f; + float step = 0.01f; testRun(m, n, step, CUBOOL_HINT_NO); } TEST(cuBool_Matrix, ReduceSmallFallback) { cuBool_Index m = 100, n = 200; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Matrix, ReduceMediumFallback) { cuBool_Index m = 400, n = 700; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Matrix, ReduceLargeFallback) { cuBool_Index m = 2000, n = 4000; - float step = 0.01f; + float step = 0.01f; testRun(m, n, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Matrix, ReduceSmallManaged) { cuBool_Index m = 100, n = 200; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED); } TEST(cuBool_Matrix, ReduceMediumManaged) { cuBool_Index m = 400, n = 700; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED); } TEST(cuBool_Matrix, ReduceLargeManaged) { cuBool_Index m = 2000, n = 4000; - float step = 0.01f; + float step = 0.01f; testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED); } diff --git a/cubool/tests/test_matrix_sub_matrix.cpp b/cubool/tests/test_matrix_sub_matrix.cpp index 72bc7d1..e17a5e9 100644 --- a/cubool/tests/test_matrix_sub_matrix.cpp +++ b/cubool/tests/test_matrix_sub_matrix.cpp @@ -66,55 +66,55 @@ void testRun(cuBool_Index m, cuBool_Index n, float step, cuBool_Hints setup) { TEST(cuBool_Matrix, SubMatrixExtractSmall) { cuBool_Index m = 100, n = 200; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_NO); } TEST(cuBool_Matrix, SubMatrixExtractMedium) { cuBool_Index m = 400, n = 700; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_NO); } TEST(cuBool_Matrix, SubMatrixExtractLarge) { cuBool_Index m = 2000, n = 4000; - float step = 0.01f; + float step = 0.01f; testRun(m, n, step, CUBOOL_HINT_NO); } TEST(cuBool_Matrix, SubMatrixExtractSmallFallback) { cuBool_Index m = 100, n = 200; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Matrix, SubMatrixExtractMediumFallback) { cuBool_Index m = 400, n = 700; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Matrix, SubMatrixExtractLargeFallback) { cuBool_Index m = 2000, n = 4000; - float step = 0.01f; + float step = 0.01f; testRun(m, n, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Matrix, SubMatrixExtractSmallManaged) { cuBool_Index m = 100, n = 200; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED); } TEST(cuBool_Matrix, SubMatrixExtractMediumManaged) { cuBool_Index m = 400, n = 700; - float step = 0.05f; + float step = 0.05f; testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED); } TEST(cuBool_Matrix, SubMatrixExtractLargeManaged) { cuBool_Index m = 2000, n = 4000; - float step = 0.01f; + float step = 0.01f; testRun(m, n, step, CUBOOL_HINT_GPU_MEM_MANAGED); } diff --git a/cubool/tests/test_vector_element.cpp b/cubool/tests/test_vector_element.cpp index 7daf3fc..b2f8341 100644 --- a/cubool/tests/test_vector_element.cpp +++ b/cubool/tests/test_vector_element.cpp @@ -30,17 +30,17 @@ void testVectorSetElement(cuBool_Index m, float density) { testing::Vector tvector = testing::Vector::generateSparse(m, density); - auto I = tvector.index; + auto I = tvector.index; size_t nvals = tvector.nvals; - size_t dups = nvals * 0.10; + size_t dups = nvals * 0.10; std::default_random_engine engine(std::chrono::system_clock::now().time_since_epoch().count()); - auto dist = std::uniform_real_distribution(0.0, 1.0); + auto dist = std::uniform_real_distribution(0.0, 1.0); if (nvals > 0) { for (size_t k = 0; k < dups; k++) { size_t id = std::min(dist(engine) * nvals, nvals - 1); - auto i = I[id]; + auto i = I[id]; I.push_back(i); } } @@ -68,16 +68,16 @@ void testVectorAppendElement(cuBool_Index m, float density) { ASSERT_EQ(cuBool_Vector_Build(vector, tvector.index.data(), (cuBool_Index) tvector.nvals, CUBOOL_HINT_VALUES_SORTED | CUBOOL_HINT_NO_DUPLICATES), CUBOOL_STATUS_SUCCESS); std::vector I; - size_t nvals = tvector.nvals; - size_t dups = nvals * 0.20; + size_t nvals = tvector.nvals; + size_t dups = nvals * 0.20; std::default_random_engine engine(std::chrono::system_clock::now().time_since_epoch().count()); - auto dist = std::uniform_real_distribution(0.0, 1.0); + auto dist = std::uniform_real_distribution(0.0, 1.0); if (nvals > 0) { for (size_t k = 0; k < dups; k++) { size_t id = std::min(dist(engine) * nvals, nvals - 1); - auto i = tvector.index[id]; + auto i = tvector.index[id]; I.push_back(i); } } @@ -95,7 +95,7 @@ void testVectorAppendElement(cuBool_Index m, float density) { } void testVectorPostAppendElement(cuBool_Index m, float density) { - cuBool_Vector vector = nullptr; + cuBool_Vector vector = nullptr; cuBool_Vector duplicated = nullptr; testing::Vector tvector = std::move(testing::Vector::generateSparse(m, density)); diff --git a/cubool/tests/test_vector_ewiseadd.cpp b/cubool/tests/test_vector_ewiseadd.cpp index dc671ff..10d0b98 100644 --- a/cubool/tests/test_vector_ewiseadd.cpp +++ b/cubool/tests/test_vector_ewiseadd.cpp @@ -44,7 +44,7 @@ void testVectorAdd(cuBool_Index m, float density, cuBool_Hints flags) { // Evaluate naive r += a on the cpu to compare results testing::VectorEWiseAddFunctor functor; - auto tr = std::move(functor(ta, tb)); + auto tr = std::move(functor(ta, tb)); // Compare results ASSERT_EQ(tr.areEqual(r), true); diff --git a/cubool/tests/test_vector_ewisemult.cpp b/cubool/tests/test_vector_ewisemult.cpp index 2cc7b90..fae1cca 100644 --- a/cubool/tests/test_vector_ewisemult.cpp +++ b/cubool/tests/test_vector_ewisemult.cpp @@ -44,7 +44,7 @@ void testVectorMult(cuBool_Index m, float density, cuBool_Hints flags) { // Evaluate naive r += a on the cpu to compare results testing::VectorEWiseMultFunctor functor; - auto tr = std::move(functor(ta, tb)); + auto tr = std::move(functor(ta, tb)); // Compare results ASSERT_EQ(tr.areEqual(r), true); diff --git a/cubool/tests/test_vector_misc.cpp b/cubool/tests/test_vector_misc.cpp index 5c32723..90a7c2a 100644 --- a/cubool/tests/test_vector_misc.cpp +++ b/cubool/tests/test_vector_misc.cpp @@ -22,13 +22,13 @@ /* SOFTWARE. */ /**********************************************************************************/ -#include #include +#include TEST(cuBool_Vector, Duplicate) { cuBool_Vector vector = nullptr, duplicated = nullptr; - cuBool_Index m = 900; - float density = 0.31; + cuBool_Index m = 900; + float density = 0.31; testing::Vector tvector = testing::Vector::generateSparse(m, density); @@ -48,9 +48,9 @@ TEST(cuBool_Vector, Duplicate) { } TEST(cuBool_Vector, PropertyQuery) { - cuBool_Vector vector = nullptr; - cuBool_Index m = 900; - float density = 0.21; + cuBool_Vector vector = nullptr; + cuBool_Index m = 900; + float density = 0.21; testing::Vector tvector = std::move(testing::Vector::generateSparse(m, density)); @@ -74,9 +74,9 @@ TEST(cuBool_Vector, PropertyQuery) { } TEST(cuBool_Vector, ExtractValues) { - cuBool_Vector vector = nullptr; - cuBool_Index m = 900; - float density = 0.21; + cuBool_Vector vector = nullptr; + cuBool_Index m = 900; + float density = 0.21; testing::Vector tvector = std::move(testing::Vector::generateSparse(m, density)); @@ -85,7 +85,7 @@ TEST(cuBool_Vector, ExtractValues) { ASSERT_EQ(cuBool_Vector_New(&vector, m), CUBOOL_STATUS_SUCCESS); ASSERT_EQ(cuBool_Vector_Build(vector, tvector.index.data(), tvector.nvals, CUBOOL_HINT_VALUES_SORTED), CUBOOL_STATUS_SUCCESS); - cuBool_Index nvals = tvector.nvals; + cuBool_Index nvals = tvector.nvals; std::vector rows(tvector.nvals); ASSERT_EQ(cuBool_Vector_ExtractValues(vector, rows.data(), &nvals), CUBOOL_STATUS_SUCCESS); @@ -98,14 +98,14 @@ TEST(cuBool_Vector, ExtractValues) { TEST(cuBool_Vector, Marker) { cuBool_Vector vector = nullptr; - cuBool_Index m; + cuBool_Index m; m = 100; const cuBool_Index BUFFER_SIZE = 100; - const char* marker = "Test Vector Marker"; - cuBool_Index size = 0; - char buffer[BUFFER_SIZE]; + const char* marker = "Test Vector Marker"; + cuBool_Index size = 0; + char buffer[BUFFER_SIZE]; ASSERT_EQ(cuBool_Initialize(CUBOOL_HINT_NO), CUBOOL_STATUS_SUCCESS); ASSERT_EQ(cuBool_Vector_New(&vector, m), CUBOOL_STATUS_SUCCESS); @@ -131,14 +131,14 @@ TEST(cuBool_Vector, Marker) { TEST(cuBool_Vector, MarkerShort) { cuBool_Vector vector = nullptr; - cuBool_Index m; + cuBool_Index m; m = 100; const cuBool_Index BUFFER_SIZE = 10; - const char* marker = "Test Vector Marker"; - cuBool_Index size = BUFFER_SIZE; - char buffer[BUFFER_SIZE]; + const char* marker = "Test Vector Marker"; + cuBool_Index size = BUFFER_SIZE; + char buffer[BUFFER_SIZE]; ASSERT_EQ(cuBool_Initialize(CUBOOL_HINT_NO), CUBOOL_STATUS_SUCCESS); ASSERT_EQ(cuBool_Vector_New(&vector, m), CUBOOL_STATUS_SUCCESS); diff --git a/cubool/tests/test_vector_mxv.cpp b/cubool/tests/test_vector_mxv.cpp index 6386cb2..5c5852f 100644 --- a/cubool/tests/test_vector_mxv.cpp +++ b/cubool/tests/test_vector_mxv.cpp @@ -43,7 +43,7 @@ void testMatrixVectorMultiplyAdd(cuBool_Index m, cuBool_Index n, float density) // Evaluate naive on the cpu to compare results testing::MatrixVectorMultiplyFunctor functor; - testing::Vector tr = functor(ta, tv); + testing::Vector tr = functor(ta, tv); // Evaluate r = M x v ASSERT_EQ(cuBool_MxV(r, a, v, CUBOOL_HINT_NO), CUBOOL_STATUS_SUCCESS); diff --git a/cubool/tests/test_vector_sub_vector.cpp b/cubool/tests/test_vector_sub_vector.cpp index a899618..b5982c5 100644 --- a/cubool/tests/test_vector_sub_vector.cpp +++ b/cubool/tests/test_vector_sub_vector.cpp @@ -62,56 +62,56 @@ void testRun(cuBool_Index m, float step, cuBool_Hints setup) { } TEST(cuBool_Vector, SubVectorExtractSmall) { - cuBool_Index m = 10000; - float step = 0.05f; + cuBool_Index m = 10000; + float step = 0.05f; testRun(m, step, CUBOOL_HINT_NO); } TEST(cuBool_Vector, SubVectorExtractMedium) { - cuBool_Index m = 50000; - float step = 0.05f; + cuBool_Index m = 50000; + float step = 0.05f; testRun(m, step, CUBOOL_HINT_NO); } TEST(cuBool_Vector, SubVectorExtractLarge) { - cuBool_Index m = 100000; - float step = 0.05f; + cuBool_Index m = 100000; + float step = 0.05f; testRun(m, step, CUBOOL_HINT_NO); } TEST(cuBool_Vector, SubVectorExtractSmallFallback) { - cuBool_Index m = 10000; - float step = 0.05f; + cuBool_Index m = 10000; + float step = 0.05f; testRun(m, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Vector, SubVectorExtractMediumFallback) { - cuBool_Index m = 50000; - float step = 0.05f; + cuBool_Index m = 50000; + float step = 0.05f; testRun(m, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Vector, SubVectorExtractLargeFallback) { - cuBool_Index m = 100000; - float step = 0.05f; + cuBool_Index m = 100000; + float step = 0.05f; testRun(m, step, CUBOOL_HINT_CPU_BACKEND); } TEST(cuBool_Vector, SubVectorExtractSmallManaged) { - cuBool_Index m = 10000; - float step = 0.05f; + cuBool_Index m = 10000; + float step = 0.05f; testRun(m, step, CUBOOL_HINT_GPU_MEM_MANAGED); } TEST(cuBool_Vector, SubVectorExtractMediumManaged) { - cuBool_Index m = 50000; - float step = 0.05f; + cuBool_Index m = 50000; + float step = 0.05f; testRun(m, step, CUBOOL_HINT_GPU_MEM_MANAGED); } TEST(cuBool_Vector, SubVectorExtractLargeManaged) { - cuBool_Index m = 100000; - float step = 0.05f; + cuBool_Index m = 100000; + float step = 0.05f; testRun(m, step, CUBOOL_HINT_GPU_MEM_MANAGED); } diff --git a/cubool/tests/test_vector_vxm.cpp b/cubool/tests/test_vector_vxm.cpp index 76b2489..e81ca49 100644 --- a/cubool/tests/test_vector_vxm.cpp +++ b/cubool/tests/test_vector_vxm.cpp @@ -43,7 +43,7 @@ void testVectorMatrixMultiplyAdd(cuBool_Index m, cuBool_Index n, float density) // Evaluate naive on the cpu to compare results testing::VectorMatrixMultiplyFunctor functor; - testing::Vector tr = functor(tv, ta); + testing::Vector tr = functor(tv, ta); // Evaluate r = v x M ASSERT_EQ(cuBool_VxM(r, v, a, CUBOOL_HINT_NO), CUBOOL_STATUS_SUCCESS); diff --git a/cubool/utils/testing/matrix.hpp b/cubool/utils/testing/matrix.hpp index 1404a30..121827f 100644 --- a/cubool/utils/testing/matrix.hpp +++ b/cubool/utils/testing/matrix.hpp @@ -25,25 +25,25 @@ #ifndef CUBOOL_TESTING_MATRIX_HPP #define CUBOOL_TESTING_MATRIX_HPP +#include +#include +#include #include +#include #include #include -#include -#include -#include -#include namespace testing { struct Matrix { mutable std::vector rowOffsets; - mutable bool hasRowOffsets = false; + mutable bool hasRowOffsets = false; std::vector rowsIndex; std::vector colsIndex; - size_t nvals = 0; - size_t nrows = 0; - size_t ncols = 0; + size_t nvals = 0; + size_t nrows = 0; + size_t ncols = 0; void computeRowOffsets() const { if (!hasRowOffsets) { @@ -54,10 +54,10 @@ namespace testing { } cuBool_Index sum = 0; - for (auto& rowOffset: rowOffsets) { + for (auto& rowOffset : rowOffsets) { cuBool_Index next = sum + rowOffset; - rowOffset = sum; - sum = next; + rowOffset = sum; + sum = next; } hasRowOffsets = true; @@ -83,7 +83,7 @@ namespace testing { std::sort(vals.begin(), vals.end(), PairCmp{}); - for (auto& p: vals) { + for (auto& p : vals) { result.rowsIndex.push_back(p.i); result.colsIndex.push_back(p.j); } @@ -102,7 +102,7 @@ namespace testing { rows[rowsIndex[i]] |= 0x1u; } - for (auto i: rows) { + for (auto i : rows) { result.nvals += i; } @@ -124,7 +124,7 @@ namespace testing { std::vector mask(nrows, 0); - for (auto r: rowsIndex) { + for (auto r : rowsIndex) { mask[r] |= 0x1u; } @@ -237,7 +237,7 @@ namespace testing { auto dist = std::uniform_real_distribution(0.0, 1.0); - std::unordered_set indices; + std::unordered_set indices; for (size_t id = 0; id < valsToGen; id++) { auto pr = dist(engine); @@ -246,8 +246,8 @@ namespace testing { auto r = (cuBool_Index) (pr * (float) nrows); auto c = (cuBool_Index) (pc * (float) ncols); - r = std::min(r, (cuBool_Index)nrows - 1); - c = std::min(c, (cuBool_Index)ncols - 1); + r = std::min(r, (cuBool_Index) nrows - 1); + c = std::min(c, (cuBool_Index) ncols - 1); indices.emplace(Pair{r, c}); } @@ -260,7 +260,7 @@ namespace testing { matrix.rowsIndex.reserve(matrix.nvals); matrix.colsIndex.reserve(matrix.nvals); - for (auto& p: toSort) { + for (auto& p : toSort) { matrix.rowsIndex.push_back(p.i); matrix.colsIndex.push_back(p.j); } @@ -274,9 +274,8 @@ namespace testing { out.ncols = ncols; return out; } - }; - -} -#endif //CUBOOL_TESTING_MATRIX_HPP \ No newline at end of file +}// namespace testing + +#endif//CUBOOL_TESTING_MATRIX_HPP \ No newline at end of file diff --git a/cubool/utils/testing/matrix_ewiseadd.hpp b/cubool/utils/testing/matrix_ewiseadd.hpp index 5bf6947..1565640 100644 --- a/cubool/utils/testing/matrix_ewiseadd.hpp +++ b/cubool/utils/testing/matrix_ewiseadd.hpp @@ -47,13 +47,13 @@ namespace testing { // Count nnz of the result matrix to allocate memory for (cuBool_Index i = 0; i < a.nrows; i++) { - cuBool_Index ak = a.rowOffsets[i]; - cuBool_Index bk = b.rowOffsets[i]; + cuBool_Index ak = a.rowOffsets[i]; + cuBool_Index bk = b.rowOffsets[i]; cuBool_Index asize = a.rowOffsets[i + 1] - ak; cuBool_Index bsize = b.rowOffsets[i + 1] - bk; - const cuBool_Index* ar = &a.colsIndex[ak]; - const cuBool_Index* br = &b.colsIndex[bk]; + const cuBool_Index* ar = &a.colsIndex[ak]; + const cuBool_Index* br = &b.colsIndex[bk]; const cuBool_Index* arend = ar + asize; const cuBool_Index* brend = br + bsize; @@ -64,19 +64,17 @@ namespace testing { nvalsInRow++; ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { nvalsInRow++; ar++; - } - else { + } else { nvalsInRow++; br++; } } - nvalsInRow += (size_t)(arend - ar); - nvalsInRow += (size_t)(brend - br); + nvalsInRow += (size_t) (arend - ar); + nvalsInRow += (size_t) (brend - br); nvals += nvalsInRow; out.rowOffsets[i] = nvalsInRow; @@ -84,10 +82,10 @@ namespace testing { // Eval row offsets cuBool_Index sum = 0; - for (auto& rowOffset: out.rowOffsets) { + for (auto& rowOffset : out.rowOffsets) { cuBool_Index next = sum + rowOffset; - rowOffset = sum; - sum = next; + rowOffset = sum; + sum = next; } out.hasRowOffsets = true; @@ -99,8 +97,8 @@ namespace testing { // Fill sorted column indices size_t k = 0; for (cuBool_Index i = 0; i < a.nrows; i++) { - const cuBool_Index* ar = &a.colsIndex[a.rowOffsets[i]]; - const cuBool_Index* br = &b.colsIndex[b.rowOffsets[i]]; + const cuBool_Index* ar = &a.colsIndex[a.rowOffsets[i]]; + const cuBool_Index* br = &b.colsIndex[b.rowOffsets[i]]; const cuBool_Index* arend = &a.colsIndex[a.rowOffsets[i + 1]]; const cuBool_Index* brend = &b.colsIndex[b.rowOffsets[i + 1]]; @@ -111,14 +109,12 @@ namespace testing { k++; ar++; br++; - } - else if (*ar < *br) { + } else if (*ar < *br) { out.rowsIndex[k] = i; out.colsIndex[k] = *ar; k++; ar++; - } - else { + } else { out.rowsIndex[k] = i; out.colsIndex[k] = *br; k++; @@ -145,6 +141,6 @@ namespace testing { } }; -} +}// namespace testing -#endif //CUBOOL_TESTING_MATRIXEWISEADD_HPP +#endif//CUBOOL_TESTING_MATRIXEWISEADD_HPP diff --git a/cubool/utils/testing/matrix_ewisemult.hpp b/cubool/utils/testing/matrix_ewisemult.hpp index 4ff39f4..36be443 100644 --- a/cubool/utils/testing/matrix_ewisemult.hpp +++ b/cubool/utils/testing/matrix_ewisemult.hpp @@ -37,8 +37,8 @@ namespace testing { std::unordered_set values; for (size_t i = 0; i < a.nvals; i++) { - uint64_t row = a.rowsIndex[i]; - uint64_t col = a.colsIndex[i]; + uint64_t row = a.rowsIndex[i]; + uint64_t col = a.colsIndex[i]; uint64_t index = row * a.ncols + col; values.insert(index); @@ -49,8 +49,8 @@ namespace testing { out.ncols = a.ncols; for (size_t i = 0; i < b.nvals; i++) { - uint64_t row = b.rowsIndex[i]; - uint64_t col = b.colsIndex[i]; + uint64_t row = b.rowsIndex[i]; + uint64_t col = b.colsIndex[i]; uint64_t index = row * b.ncols + col; if (values.find(index) != values.end()) { @@ -65,6 +65,6 @@ namespace testing { } }; -} +}// namespace testing -#endif //CUBOOL_MATRIX_EWISEMULT_HPP +#endif//CUBOOL_MATRIX_EWISEMULT_HPP diff --git a/cubool/utils/testing/matrix_generator.hpp b/cubool/utils/testing/matrix_generator.hpp index 3ed2a72..38ba559 100644 --- a/cubool/utils/testing/matrix_generator.hpp +++ b/cubool/utils/testing/matrix_generator.hpp @@ -25,10 +25,10 @@ #ifndef CUBOOL_TESTING_MATRIXGENERATOR_HPP #define CUBOOL_TESTING_MATRIXGENERATOR_HPP +#include +#include #include #include -#include -#include namespace testing { @@ -46,19 +46,20 @@ namespace testing { struct Condition3 { public: - explicit Condition3(float density): mDensity(density) { + explicit Condition3(float density) : mDensity(density) { mRandomEngine.seed(std::time(0)); } bool operator()(cuBool_Index i, cuBool_Index j) { return std::uniform_real_distribution(0.0f, 1.0f)(mRandomEngine) <= mDensity; } + private: std::default_random_engine mRandomEngine; - float mDensity = 1.0f; + float mDensity = 1.0f; }; template - static void generateTestData(size_t rows, size_t columns, std::vector &values, Condition&& condition) { + static void generateTestData(size_t rows, size_t columns, std::vector& values, Condition&& condition) { for (cuBool_Index i = 0; i < rows; i++) { for (cuBool_Index j = 0; j < columns; j++) { // is i and j power of two or 0 @@ -70,7 +71,7 @@ namespace testing { } template - static void generateTestData(size_t nrows, size_t ncols, std::vector &rows, std::vector &cols, size_t& nvals, Condition&& condition) { + static void generateTestData(size_t nrows, size_t ncols, std::vector& rows, std::vector& cols, size_t& nvals, Condition&& condition) { nvals = 0; for (cuBool_Index i = 0; i < nrows; i++) { for (cuBool_Index j = 0; j < ncols; j++) { @@ -83,7 +84,7 @@ namespace testing { } } } - -} -#endif //CUBOOL_TESTING_MATRIXGENERATOR_HPP +}// namespace testing + +#endif//CUBOOL_TESTING_MATRIXGENERATOR_HPP diff --git a/cubool/utils/testing/matrix_kronecker.hpp b/cubool/utils/testing/matrix_kronecker.hpp index 96258b9..bf0c592 100644 --- a/cubool/utils/testing/matrix_kronecker.hpp +++ b/cubool/utils/testing/matrix_kronecker.hpp @@ -63,7 +63,7 @@ namespace testing { std::sort(vals.begin(), vals.end(), PairCmp{}); - for (auto& p: vals) { + for (auto& p : vals) { result.rowsIndex.push_back(p.i); result.colsIndex.push_back(p.j); } @@ -72,6 +72,6 @@ namespace testing { } }; -} +}// namespace testing -#endif //CUBOOL_TESTING_MATRIXKRONECKER_HPP +#endif//CUBOOL_TESTING_MATRIXKRONECKER_HPP diff --git a/cubool/utils/testing/matrix_mxm.hpp b/cubool/utils/testing/matrix_mxm.hpp index d92ccfb..3837dd4 100644 --- a/cubool/utils/testing/matrix_mxm.hpp +++ b/cubool/utils/testing/matrix_mxm.hpp @@ -25,10 +25,10 @@ #ifndef CUBOOL_TESTING_MATRIXMXM_HPP #define CUBOOL_TESTING_MATRIXMXM_HPP -#include -#include #include #include +#include +#include namespace testing { @@ -75,10 +75,10 @@ namespace testing { // Row offsets cuBool_Index sum = 0; - for (auto& rowOffset: out.rowOffsets) { + for (auto& rowOffset : out.rowOffsets) { cuBool_Index next = sum + rowOffset; - rowOffset = sum; - sum = next; + rowOffset = sum; + sum = next; } out.hasRowOffsets = true; @@ -91,9 +91,9 @@ namespace testing { mask.resize(b.ncols, max); for (cuBool_Index i = 0; i < a.nrows; i++) { - size_t id = 0; + size_t id = 0; size_t first = out.rowOffsets[i]; - size_t last = out.rowOffsets[i + 1]; + size_t last = out.rowOffsets[i + 1]; for (cuBool_Index ak = a.rowOffsets[i]; ak < a.rowOffsets[i + 1]; ak++) { cuBool_Index k = a.colsIndex[ak]; @@ -103,7 +103,7 @@ namespace testing { // Do not compute col nnz twice if (mask[j] != i) { - mask[j] = i; + mask[j] = i; out.rowsIndex[first + id] = i; out.colsIndex[first + id] = j; id += 1; @@ -124,6 +124,6 @@ namespace testing { } }; -} +}// namespace testing -#endif //CUBOOL_TESTING_MATRIXMXM_HPP +#endif//CUBOOL_TESTING_MATRIXMXM_HPP diff --git a/cubool/utils/testing/matrix_printing.hpp b/cubool/utils/testing/matrix_printing.hpp index d55ba5e..c4dcd77 100644 --- a/cubool/utils/testing/matrix_printing.hpp +++ b/cubool/utils/testing/matrix_printing.hpp @@ -29,11 +29,11 @@ namespace testing { - template + template void printMatrix(Stream& stream, const cuBool_Index* rowsIndex, const cuBool_Index* colsIndex, cuBool_Index nrows, cuBool_Index ncols, cuBool_Index nvals) { cuBool_Index currentRow = 0; cuBool_Index currentCol = 0; - cuBool_Index currentId = 0; + cuBool_Index currentId = 0; while (currentId < nvals) { auto i = rowsIndex[currentId]; @@ -76,8 +76,8 @@ namespace testing { cuBool_Matrix matrix; }; - template - Stream& operator <<(Stream& stream, Print p) { + template + Stream& operator<<(Stream& stream, Print p) { cuBool_Matrix matrix = p.matrix; assert(matrix); @@ -99,12 +99,12 @@ namespace testing { return stream; } - template - Stream& operator <<(Stream& stream, const Matrix& a) { + template + Stream& operator<<(Stream& stream, const Matrix& a) { printMatrix(stream, a.rowsIndex.data(), a.colsIndex.data(), a.nrows, a.ncols, a.nvals); return stream; } - -} -#endif //CUBOOL_TESTING_MATRIXPRINTING_HPP +}// namespace testing + +#endif//CUBOOL_TESTING_MATRIXPRINTING_HPP diff --git a/cubool/utils/testing/pair.hpp b/cubool/utils/testing/pair.hpp index b5fcec9..e7767ed 100644 --- a/cubool/utils/testing/pair.hpp +++ b/cubool/utils/testing/pair.hpp @@ -37,30 +37,30 @@ namespace testing { struct PairHash { public: - std::size_t operator()(const Pair &x) const { + std::size_t operator()(const Pair& x) const { return std::hash()(x.i) ^ std::hash()(x.j); } }; struct PairCmp { public: - bool operator()(const Pair &a, const Pair& b) const { + bool operator()(const Pair& a, const Pair& b) const { return a.i < b.i || (a.i == b.i && a.j < b.j); } }; struct PairEq { public: - bool operator()(const Pair &a, const Pair& b) const { + bool operator()(const Pair& a, const Pair& b) const { return a.i == b.i && a.j == b.j; } }; - bool operator ==(const Pair& a, const Pair& b) { + bool operator==(const Pair& a, const Pair& b) { PairEq pairEq; return pairEq(a, b); } -} +}// namespace testing -#endif //CUBOOL_TESTING_PAIR_HPP +#endif//CUBOOL_TESTING_PAIR_HPP diff --git a/cubool/utils/testing/testing.hpp b/cubool/utils/testing/testing.hpp index c658d65..704d365 100644 --- a/cubool/utils/testing/testing.hpp +++ b/cubool/utils/testing/testing.hpp @@ -26,23 +26,23 @@ #define CUBOOL_TESTING_TESTING_HPP #include -#include -#include #include -#include -#include #include #include -#include +#include #include +#include +#include +#include +#include #include #include // Put in the end of the unit test file -#define CUBOOL_GTEST_MAIN \ - int main(int argc, char *argv[]) { \ - ::testing::InitGoogleTest(&argc, argv); \ - return RUN_ALL_TESTS(); \ +#define CUBOOL_GTEST_MAIN \ + int main(int argc, char* argv[]) { \ + ::testing::InitGoogleTest(&argc, argv); \ + return RUN_ALL_TESTS(); \ } -#endif //CUBOOL_TESTING_TESTING_HPP +#endif//CUBOOL_TESTING_TESTING_HPP diff --git a/cubool/utils/testing/timer.hpp b/cubool/utils/testing/timer.hpp index 6c1d781..33c700d 100644 --- a/cubool/utils/testing/timer.hpp +++ b/cubool/utils/testing/timer.hpp @@ -45,7 +45,7 @@ namespace testing { } private: - using clock = std::chrono::high_resolution_clock; + using clock = std::chrono::high_resolution_clock; using timepoint = clock::time_point; timepoint mStart; timepoint mEnd; @@ -63,13 +63,13 @@ namespace testing { } private: - double mTimeSumMS = 0.0f; - int mSamplesCount = 0; + double mTimeSumMS = 0.0f; + int mSamplesCount = 0; }; struct TimeScope { public: - explicit TimeScope(TimeQuery &query) : mTimeQuery(query) { + explicit TimeScope(TimeQuery& query) : mTimeQuery(query) { mTimer.start(); } @@ -79,10 +79,10 @@ namespace testing { } private: - Timer mTimer; - TimeQuery &mTimeQuery; + Timer mTimer; + TimeQuery& mTimeQuery; }; -} +}// namespace testing -#endif //CUBOOL_TESTING_TIMER_HPP +#endif//CUBOOL_TESTING_TIMER_HPP diff --git a/cubool/utils/testing/vector.hpp b/cubool/utils/testing/vector.hpp index 2d03395..000f543 100644 --- a/cubool/utils/testing/vector.hpp +++ b/cubool/utils/testing/vector.hpp @@ -25,26 +25,26 @@ #ifndef CUBOOL_VECTOR_HPP #define CUBOOL_VECTOR_HPP -#include -#include -#include #include -#include #include +#include +#include +#include +#include namespace testing { struct Vector { std::vector index; - size_t nvals = 0; - size_t nrows = 0; + size_t nvals = 0; + size_t nrows = 0; Vector subVector(cuBool_Index i, cuBool_Index m) const { assert(i + m <= nrows); Vector out; - for (auto v: index) { + for (auto v : index) { if (i <= v && v < (i + m)) out.index.push_back(v - i); } @@ -90,14 +90,14 @@ namespace testing { auto r = (cuBool_Index) (pr * (float) nrows); - r = std::min(r, (cuBool_Index)nrows - 1); + r = std::min(r, (cuBool_Index) nrows - 1); indices.emplace(r); } std::vector toSort(indices.size()); std::copy(indices.begin(), indices.end(), toSort.begin()); - std::sort(toSort.begin(), toSort.end(), [](cuBool_Index a, cuBool_Index b){ return a < b; }); + std::sort(toSort.begin(), toSort.end(), [](cuBool_Index a, cuBool_Index b) { return a < b; }); vec.nvals = toSort.size(); vec.index = std::move(toSort); @@ -112,6 +112,6 @@ namespace testing { } }; -} +}// namespace testing -#endif //CUBOOL_VECTOR_HPP +#endif//CUBOOL_VECTOR_HPP diff --git a/cubool/utils/testing/vector_functors.hpp b/cubool/utils/testing/vector_functors.hpp index d8f59c6..4317a35 100644 --- a/cubool/utils/testing/vector_functors.hpp +++ b/cubool/utils/testing/vector_functors.hpp @@ -25,8 +25,8 @@ #ifndef CUBOOL_VECTOR_FUNCTORS_HPP #define CUBOOL_VECTOR_FUNCTORS_HPP -#include #include +#include namespace testing { @@ -35,10 +35,10 @@ namespace testing { Vector operator()(const Vector& a, const Vector& b) { std::unordered_set values; - for (auto v: a.index) + for (auto v : a.index) values.emplace(v); - for (auto v: b.index) + for (auto v : b.index) values.emplace(v); std::vector sorted(values.size()); @@ -59,12 +59,12 @@ namespace testing { public: Vector operator()(const Vector& a, const Vector& b) { std::unordered_set values; - std::vector result; + std::vector result; - for (auto v: a.index) + for (auto v : a.index) values.emplace(v); - for (auto v: b.index) { + for (auto v : b.index) { if (values.find(v) != values.end()) result.push_back(v); } @@ -85,20 +85,20 @@ namespace testing { std::unordered_set buffer; - for (auto i: v.index) + for (auto i : v.index) buffer.emplace(i); std::vector result; for (cuBool_Index i = 0; i < m.nrows; i++) { - for (cuBool_Index k = m.rowOffsets[i]; k < m.rowOffsets[i + 1]; k++) { - cuBool_Index j = m.colsIndex[k]; - - if (buffer.find(j) != buffer.end()) { - result.push_back(i); - break; - } - } + for (cuBool_Index k = m.rowOffsets[i]; k < m.rowOffsets[i + 1]; k++) { + cuBool_Index j = m.colsIndex[k]; + + if (buffer.find(j) != buffer.end()) { + result.push_back(i); + break; + } + } } Vector r; @@ -116,7 +116,7 @@ namespace testing { std::unordered_set result; - for (cuBool_Index i: v.index) { + for (cuBool_Index i : v.index) { for (cuBool_Index k = m.rowOffsets[i]; k < m.rowOffsets[i + 1]; k++) { result.emplace(m.colsIndex[k]); } @@ -133,6 +133,6 @@ namespace testing { } }; -} +}// namespace testing -#endif //CUBOOL_VECTOR_FUNCTORS_HPP +#endif//CUBOOL_VECTOR_FUNCTORS_HPP