Skip to content

Commit 7458787

Browse files
committed
[Code] Add C Vector API docs && add vector tests in test scripts
1 parent da913de commit 7458787

File tree

4 files changed

+230
-20
lines changed

4 files changed

+230
-20
lines changed

cubool/include/cubool/cubool.h

Lines changed: 215 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,16 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_New(
237237
/**
238238
* Build sparse matrix from provided pairs array. Pairs are supposed to be stored
239239
* as (rows[i],cols[i]) for pair with i-th index.
240+
* By default automatically sorts values and reduces duplicates in the input arrays.
240241
*
241-
* @note This function automatically reduces duplicates
242242
* @note Pass `CUBOOL_HINT_VALUES_SORTED` if values already in the row-col order.
243243
* @note Pass `CUBOOL_HINT_NO_DUPLICATES` if values has no duplicates
244244
*
245245
* @param matrix Matrix handle to perform operation on
246246
* @param rows Array of pairs row indices
247247
* @param cols Array of pairs column indices
248248
* @param nvals Number of the pairs passed
249-
* @param hints Hits flags for processing.
249+
* @param hints Hits flags for processing
250250
*
251251
* @return Error code on this operation
252252
*/
@@ -436,14 +436,35 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Ncols(
436436
/**
437437
* Deletes sparse matrix object.
438438
*
439-
* @param matrix Matrix handle to delete the matrix
439+
* @param matrix Matrix handle to delete
440440
*
441441
* @return Error code on this operation
442442
*/
443443
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Free(
444444
cuBool_Matrix matrix
445445
);
446446

447+
/**
448+
* Reduce the source matrix to the column vector.
449+
* Pass optionally transpose hint to transpose matrix before the reduce.
450+
* Formally: result = sum(cols of matrix M), where
451+
* M = matrix, or M = matrix^T (if passed transpose hint)
452+
*
453+
* @note Pass `CUBOOL_HINT_TRANSPOSE` hint to reduce transposed matrix
454+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
455+
*
456+
* @param[out] result Vector handle where to store result
457+
* @param matrix Source matrix to reduce
458+
* @param hints Hints for the operation
459+
*
460+
* @return Error code on this operation
461+
*/
462+
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce(
463+
cuBool_Vector result,
464+
cuBool_Matrix matrix,
465+
cuBool_Hints hints
466+
);
467+
447468
/**
448469
* Reduce the source matrix to the column matrix result (column vector).
449470
* Formally: result = sum(cols of matrix).
@@ -454,7 +475,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Free(
454475
*
455476
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
456477
*
457-
* @param result[out] Matrix hnd where to store result
478+
* @param[out] result Matrix handle where to store result
458479
* @param matrix Source matrix to reduce
459480
* @param hints Hints for the operation
460481
*
@@ -466,12 +487,6 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce2(
466487
cuBool_Hints hints
467488
);
468489

469-
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce(
470-
cuBool_Vector result,
471-
cuBool_Matrix matrix,
472-
cuBool_Hints hints
473-
);
474-
475490
/**
476491
* Performs result = left + right, where '+' is boolean semiring operation.
477492
*
@@ -482,7 +497,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce(
482497
*
483498
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
484499
*
485-
* @param result[out] Destination matrix for add-and-assign operation
500+
* @param result[out] Destination matrix to store result
486501
* @param left Source matrix to be added
487502
* @param right Source matrix to be added
488503
* @param hints Hints for the operation
@@ -496,40 +511,129 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseAdd(
496511
cuBool_Hints hints
497512
);
498513

514+
/**
515+
* Creates new sparse vector with specified size.
516+
*
517+
* @param vector Pointer where to store created vector
518+
* @param nrows Vector rows count
519+
*
520+
* @return Error code on this operation
521+
*/
499522
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_New(
500523
cuBool_Vector* vector,
501524
cuBool_Index nrows
502525
);
503526

527+
/**
528+
* Build sparse vector from provided indices array.
529+
* By default automatically sorts values and reduces duplicates in the input array.
530+
*
531+
* @note Pass `CUBOOL_HINT_VALUES_SORTED` if values already in the row-col order.
532+
* @note Pass `CUBOOL_HINT_NO_DUPLICATES` if values has no duplicates
533+
*
534+
* @param vector Vector handle to perform operation on
535+
* @param rows Array of row indices
536+
* @param nvals Number of the indices passed
537+
* @param hints Hits flags for processing
538+
*
539+
* @return Error code on this operation
540+
*/
504541
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Build(
505542
cuBool_Vector vector,
506543
const cuBool_Index* rows,
507544
cuBool_Index nvals,
508545
cuBool_Hints hints
509546
);
510547

548+
/**
549+
* Sets specified (j) value of the vector to True.
550+
*
551+
* @note This function automatically reduces duplicates
552+
*
553+
* @param vector Vector handle to perform operation on
554+
* @param i Row index
555+
*
556+
* @return Error code on this operation
557+
*/
511558
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_SetElement(
512559
cuBool_Vector vector,
513560
cuBool_Index i
514561
);
515562

563+
/**
564+
* Sets to the vector specific debug string marker.
565+
* This marker will appear in the log messages as string identifier of the vector.
566+
*
567+
* @param vector Vector handle to perform operation on
568+
* @param marker UTF-8 encoded null-terminated string marker name.
569+
*
570+
* @return Error code on this operation
571+
*/
516572
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_SetMarker(
517573
cuBool_Vector vector,
518574
const char* marker
519575
);
520576

577+
/**
578+
* Allows to get vector debug string marker.
579+
*
580+
* @note Pass null marker if you want to retrieve only the required marker buffer size.
581+
* @note After the function call the actual size of the marker is stored in the size variable.
582+
*
583+
* @note size is set to the actual marker length plus null terminator symbol.
584+
* For marker "vector" size variable will be set to 7.
585+
*
586+
* @param vector Vector handle to perform operation on
587+
* @param[in,out] marker Where to store null-terminated UTF-8 encoded marker string.
588+
* @param[in,out] size Size of the provided buffer in bytes to save marker string.
589+
*
590+
* @return Error code on this operation
591+
*/
521592
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Marker(
522593
cuBool_Vector vector,
523594
char* marker,
524595
cuBool_Index* size
525596
);
526597

598+
/**
599+
* Reads vector data to the host visible CPU buffer as an array of indices.
600+
*
601+
* The array must be provided by the user and the size of this array must
602+
* be greater or equal the values count of the vector.
603+
*
604+
* @param vector Matrix handle to perform operation on
605+
* @param[in,out] rows Buffer to store row indices
606+
* @param[in,out] nvals Total number of the indices
607+
*
608+
* @return Error code on this operation
609+
*/
527610
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_ExtractValues(
528611
cuBool_Vector vector,
529612
cuBool_Index* rows,
530613
cuBool_Index* nvals
531614
);
532615

616+
/**
617+
* Extracts sub-vector of the input vector and stores it into result vector.
618+
*
619+
* @note The result sub-vector have nrows dimension,
620+
* and includes [i;i+nrow) rows of the input vector.
621+
*
622+
* @note Result vector must have compatible size
623+
* dim(result) = nrows
624+
*
625+
* @note Provided sub-vector region must be within the input vector.
626+
*
627+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
628+
*
629+
* @param result[out] Vector handle where to store result of the operation
630+
* @param vector Input vector to extract values from
631+
* @param i First row id to extract
632+
* @param nrows Number of rows to extract
633+
* @param hints Hints for the operation
634+
*
635+
* @return Error code on this operation
636+
*/
533637
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_ExtractSubVector(
534638
cuBool_Vector result,
535639
cuBool_Vector vector,
@@ -538,31 +642,91 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_ExtractSubVector(
538642
cuBool_Hints hints
539643
);
540644

645+
/**
646+
* Creates new sparse vector, duplicates content and stores handle in the provided pointer.
647+
*
648+
* @param vector Vector handle to perform operation on
649+
* @param duplicated[out] Pointer to the vector handle where to create and store created vector
650+
*
651+
* @return Error code on this operation
652+
*/
541653
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Duplicate(
542654
cuBool_Vector vector,
543655
cuBool_Vector* duplicated
544656
);
545657

658+
/**
659+
* Query number of non-zero values of the vector.
660+
*
661+
* @param vector Vector handle to perform operation on
662+
* @param nvals[out] Pointer to the place where to store number of the non-zero elements of the vector
663+
*
664+
* @return Error code on this operation
665+
*/
546666
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Nvals(
547667
cuBool_Vector vector,
548668
cuBool_Index* nvals
549669
);
550670

671+
/**
672+
* Query number of rows in the vector.
673+
*
674+
* @param vector Vector handle to perform operation on
675+
* @param nrows[out] Pointer to the place where to store number of vector rows
676+
*
677+
* @return Error code on this operation
678+
*/
551679
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Nrows(
552680
cuBool_Vector vector,
553681
cuBool_Index* nrows
554682
);
555683

684+
/**
685+
* Deletes sparse vector object.
686+
*
687+
* @param vector Vector handle to delete
688+
*
689+
* @return Error code on this operation
690+
*/
556691
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Free(
557692
cuBool_Vector vector
558693
);
559694

695+
696+
/**
697+
* Reduces vector to single value (equals nnz of the vector for boolean case).
698+
*
699+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
700+
*
701+
* @param result Pointer to index value where to store result
702+
* @param vector Vector handle to perform operation on
703+
* @param hints Hints for the operation
704+
*
705+
* @return Error code on this operation
706+
*/
560707
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_Reduce(
561708
cuBool_Index* result,
562709
cuBool_Vector vector,
563710
cuBool_Hints hints
564711
);
565712

713+
/**
714+
* Performs result = left + right, where '+' is boolean semiring operation.
715+
*
716+
* @note Matrices must be compatible
717+
* dim(result) = M
718+
* dim(left) = M
719+
* dim(right) = M
720+
*
721+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
722+
*
723+
* @param result[out]Destination vector to store result
724+
* @param left Source vector to be added
725+
* @param right Source vector to be added
726+
* @param hints Hints for the operation
727+
*
728+
* @return Error code on this operation
729+
*/
566730
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Vector_EWiseAdd(
567731
cuBool_Vector result,
568732
cuBool_Vector left,
@@ -596,17 +760,53 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_MxM(
596760
cuBool_Hints hints
597761
);
598762

763+
/**
764+
* Performs result = left x right evaluation, where source '+' and 'x' are boolean semiring operations.
765+
* Formally: column vector `right` multiplied to the matrix `left`. The result is column vector.
766+
*
767+
* @note To perform this operation matrix and vector must be compatible
768+
* dim(left) = M x N
769+
* dim(right) = N
770+
* dim(result) = M
771+
*
772+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
773+
*
774+
* @param result[out] Vector handle where to store operation result
775+
* @param left Input left matrix
776+
* @param right Input right vector
777+
* @param hints Hints for the operation
778+
*
779+
* @return Error code on this operation
780+
*/
599781
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_MxV(
600782
cuBool_Vector result,
601-
cuBool_Matrix matrix,
602-
cuBool_Vector vector,
783+
cuBool_Matrix left,
784+
cuBool_Vector right,
603785
cuBool_Hints hints
604786
);
605787

788+
/**
789+
* Performs result = left x right evaluation, where source '+' and 'x' are boolean semiring operations.
790+
* Formally: row vector `left` multiplied to the matrix `right`. The result is row vector.
791+
*
792+
* @note To perform this operation matrix and vector must be compatible
793+
* dim(left) = M
794+
* dim(right) = M x N
795+
* dim(result) = N
796+
*
797+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
798+
*
799+
* @param result[out] Vector handle where to store operation result
800+
* @param left Input left vector
801+
* @param right Input right matrix
802+
* @param hints Hints for the operation
803+
*
804+
* @return Error code on this operation
805+
*/
606806
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_VxM(
607807
cuBool_Vector result,
608-
cuBool_Vector vector,
609-
cuBool_Matrix matrix,
808+
cuBool_Vector left,
809+
cuBool_Matrix right,
610810
cuBool_Hints hints
611811
);
612812

0 commit comments

Comments
 (0)