Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a print function for UDTs #143

Open
rayegun opened this issue May 17, 2022 · 5 comments
Open

Pass a print function for UDTs #143

rayegun opened this issue May 17, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@rayegun
Copy link
Contributor

rayegun commented May 17, 2022

It'd be very nice to replace (1,1) [user-defined value] with the actual value using a user provided print function of some sort. I'm not sure what signature the function pointer would have, but I'm sure it shouldn't be difficult.

@DrTimothyAldenDavis DrTimothyAldenDavis added the enhancement New feature or request label May 17, 2022
@DrTimothyAldenDavis
Copy link
Owner

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 GrB_Type. 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.

@DrTimothyAldenDavis
Copy link
Owner

DrTimothyAldenDavis commented May 17, 2022

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.

@rayegun
Copy link
Contributor Author

rayegun commented May 19, 2022

What size do you estimate for the char array?

@DrTimothyAldenDavis
Copy link
Owner

I could just create some large static-size array, say 2048 or something big, with a #define that gives the size.

@DrTimothyAldenDavis
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants