GraphBLAS / graphblas-api-c

Other
7 stars 3 forks source link

GrB_*_extractElement when GrB_NO_VALUE is returned. #62

Closed DrTimothyAldenDavis closed 2 years ago

DrTimothyAldenDavis commented 2 years ago

The current draft states:

• The non-opaque scalar, val, is unchanged, and GrB_NO_VALUE is returned. [Scott: is val unchanged or undefined in this case?]

I leave the non-opaque scalar unchanged if I return GrB_NO_VALUE. I think this makes most sense, but I'm OK with either strategy; I will leave my code unchanged so my "undefined behavior" will be to just leave val unchanged.

(Adding this as "To Do" since the comment needs to be removed at some point anyway).

mcmillan03 commented 2 years ago

All comments get "hidden" on final compilation. The real question is, should this comment be deleted.

DrTimothyAldenDavis commented 2 years ago

Understood. I have it documented in my user guide that if there is no entry, and the scalar is non-opaque, that val is unchanged and GrB_NO_VALUE is returned. If the spec changes to say that val is undefined in this case, then I'll leave the wording as-is but perhaps put it in a yellow box to denote that my behavior is a (very minor) extension to the spec. Either way is fine with me, and either way my code will be unchanged. At most I'll need is to tweak my user guide.

Returning val as unchanged is not the "right" thing to do. It doesn't really matter ... I just don't bother to change the value if there's nothing to assign to it.

Maybe the use case of val being left unchanged is so the user could do this:

val = (some useful value, algorithm dependent, perhaps some monoid identity value) ;
info = GrB_Matrix_extractElement (&val, A, i, j) ;

then if val is present, it has been assigned to A(i,j). Otherwise, it is equal to the pre-assigned value. Equivalently, if val is undefined if GrB_NO_VALUE is returned:

info = GrB_Matrix_extractElement (&val, A, i, j) ;
if (info == GrB_NO_VALUE) val = (some useful value, maybe some monoid identity or something) ;

Both alternatives are equally simple. The former has the advantage that a successful return (SUCCESS or NO_VALUE) could be done in LAGraph as:

val = (some useful value, algorithm dependent, perhaps some monoid identity value) ;
GrB_TRY ( GrB_Matrix_extractElement (&val, A, i, j)) ;
mcmillan03 commented 2 years ago

comment removed