Open rayegun opened 2 years ago
This would be nice to have too. I see two different approaches for this. One method would be to add a function pointer to the user-defined GrB_Type object. This might be tricky since it would affect all uses of that GrBType. Another would be to pass in a function pointer to GxB_fprint, for = Monoid, Scalar, Vector, and Matrix, which would be a more local revision. It wouldn't change the GrB_Type itself. It could even be used to print built-in types.
Maybe I could just add this as 4 new functions, like GxB_Matrix_fprintf with signature:
GrB_Info GxB_Matrix_fprintf ( GrB_Matrix A, const char *name, GxB_Print_Level pr, FILE *f, GxB_format_function *f) ;
or something, which adds the function pointer f that would define how to print a scalar.
See Source/GB_code_check.c and grep for FUTURE. I already have tagged this as a future extension that would be nice to have.
The GxB_format_function should probably have the signature:
typedef void (*GxB_format_function) (char *, const void *)
where the const void is the scalar to print, and the char would be an array of some large fixed size which is then filled with the string that should be printed. I would want to use the char instead of FILE * because I already have a way to define a printf function for SuiteSparse:GraphBLAS to use.
What size do you estimate for the char
array?
I could just create some large static-size array, say 2048 or something big, with a #define that gives the size.
A better approach would be to have a user-provided function that can do one of two things: (a) return the size of the string required to print a specific user-defined value, and (b) fill a string (provided by GraphBLAS) with the printed value itself. Then I could use a dynamically allocated array, with no limits on the size of the string.
It'd be very nice to replace
(1,1) [user-defined value]
with the actual value using a user providedprint
function of some sort. I'm not sure what signature the function pointer would have, but I'm sure it shouldn't be difficult.