Skip to content

Commit 698545f

Browse files
GraphBLAS v10 container methods, testing
1 parent 5522fc4 commit 698545f

11 files changed

+379
-671
lines changed

GraphBLAS/Doc/GraphBLAS_UserGuide.pdf

-5.94 KB
Binary file not shown.

GraphBLAS/Doc/UserGuide/GrB_get_set_Global.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ \subsubsection{OpenMP parallelism}
256256
\begin{verbatim}
257257
bool have_openmp ;
258258
GrB_get (GrB_GLOBAL, &have_openmp, GxB_LIBRARY_OPENMP) ;
259-
if (!have_openmp) printf ("GraphBLAS not compiled with OpenMP\n") : \end{verbatim}}
259+
if (!have_openmp) printf ("GraphBLAS not compiled with OpenMP\n") ; \end{verbatim}}
260260

261261
Compiling GraphBLAS without OpenMP is not recommended for installation in a
262262
package manager (Linux, conda-forge, spack, brew, vcpkg, etc).

GraphBLAS/Doc/UserGuide/GrB_objects_Container.tex

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ \subsubsection{{\sf GxB\_Vector\_load:} load data into a vector}
106106
\verb'V' becomes \verb'n', and its type is changed to match the \verb'type'
107107
parameter.
108108

109-
After this method returns, \verb'GrB_Vector_size' and \verb'GrB_Vector_nvals'
109+
After this method returns, \verb'GrB_Vector_size' and \verb'GrB_Vector_nvals'
110110
will both return \verb'n'. That is, the vector \verb'V' is a dense vector.
111111
It is held in the \verb'GxB_FULL' data format, in \verb'GrB_COLMAJOR'
112112
orientation.
@@ -234,7 +234,7 @@ \subsubsection{{\sf GxB\_Container\_new:} create a container}
234234

235235
\begin{itemize}
236236
\item \verb'nrows': the number of rows of a matrix, or the size of a vector.
237-
\item \verb'ncols': the number of columns of a matrix, or 1 for a vector.
237+
\item \verb'ncols': the number of columns of a matrix, or 1 for a vector.
238238
\item \verb'nrows_nonempty': if known, this value must give the exact number
239239
of non-empty rows of a matrix or vector (that is, the number of
240240
rows have at least one entry). If not known, this value must be
@@ -258,7 +258,7 @@ \subsubsection{{\sf GxB\_Container\_new:} create a container}
258258
\item \verb'jumbled': if true, the indices in any given row (if in row-major
259259
orientation) or column (if column-major) may appear out of order.
260260
Otherwise, they must appear in ascending order.
261-
A jumbled matrix or vector must not have any read-only components.
261+
A jumbled matrix or vector must not have any read-only components.
262262
\end{itemize}
263263

264264
The Container holds five dense \verb'GrB_Vector' objects that hold the primary
@@ -305,6 +305,10 @@ \subsubsection{{\sf GxB\_load\_Matrix\_from\_Container:} load a matrix from a co
305305
\verb'GxB_load_Matrix_from_Container' moves all of the data from a
306306
\verb'GxB_Container' into a \verb'GrB_Matrix' in O(1) time.
307307

308+
The container vectors \verb'p', \verb'h', and \verb'i' may be any signed or
309+
unsigned integer type of size 32 or 64 bits. Any other types will result in
310+
an error.
311+
308312
%-------------------------------------------------------------------------------
309313
\subsubsection{{\sf GxB\_load\_Vector\_from\_Container:} load a vector from a container}
310314
%-------------------------------------------------------------------------------
@@ -326,6 +330,11 @@ \subsubsection{{\sf GxB\_load\_Vector\_from\_Container:} load a vector from a co
326330
\verb'GxB_load_Vector_from_Container' moves all of the data from a
327331
\verb'GxB_Container' into a \verb'GrB_Vector' in O(1) time.
328332

333+
The container format may not be \verb'GxB_HYPERSPARSE'.
334+
The container vectors \verb'p' and \verb'i' may be any signed or
335+
unsigned integer type of size 32 or 64 bits. Any other types will result in
336+
an error.
337+
329338
\newpage
330339
%-------------------------------------------------------------------------------
331340
\subsubsection{{\sf GxB\_unload\_Matrix\_into\_Container:} unload a matrix into a container}
@@ -347,6 +356,9 @@ \subsubsection{{\sf GxB\_unload\_Matrix\_into\_Container:} unload a matrix into
347356
\verb'GxB_unload_Matrix_into_Container': moves all of the data from
348357
a \verb'GrB_Matrix' into a \verb'GxB_Container' in O(1) time.
349358

359+
The container vector \verb'p' is unloaded as \verb'GrB_UINT32' or \verb'GrB_UINT64',
360+
while \verb'h', and \verb'i' are unloaded as \verb'GrB_INT32' or \verb'GrB_INT64'.
361+
350362
%-------------------------------------------------------------------------------
351363
\subsubsection{{\sf GxB\_unload\_Vector\_into\_Container:} unload a vector into a container}
352364
%-------------------------------------------------------------------------------
@@ -367,12 +379,15 @@ \subsubsection{{\sf GxB\_unload\_Vector\_into\_Container:} unload a vector into
367379
\verb'GxB_unload_Vector_into_Container': moves all of the data from
368380
a \verb'GrB_Vector' into a \verb'GxB_Container' in O(1) time.
369381

382+
The container vector \verb'p' is unloaded as \verb'GrB_UINT32' or \verb'GrB_UINT64',
383+
while \verb'i' is unloaded as \verb'GrB_INT32' or \verb'GrB_INT64'.
384+
370385
%-------------------------------------------------------------------------------
371386
\subsubsection{Container example: unloading/loading an entire matrix into C arrays}
372387
%-------------------------------------------------------------------------------
373388
\label{container_example}
374389

375-
The following example unloads a
390+
The following example unloads a
376391
\verb'GrB_Matrix A' of size \verb'nrows'-by-\verb'ncols',
377392
with \verb'nvals' entries, of type \verb'xtype'. The example takes will take O(1) time,
378393
and the only \verb'mallocs' are in \verb'GxB_Container_new' (which can be reused for
@@ -505,7 +520,7 @@ \subsubsection{Container example: unloading/loading, but not using C arrays}
505520
...
506521
GxB_unload_Vector_into_Container (Delta, Container, desc) ;
507522
GxB_Matrix_build_Vector (DeltaMatrix, Container->i, J_vector,
508-
Container->x, GrB_PLUS_FP32, NULL) :
523+
Container->x, GrB_PLUS_FP32, NULL) ;
509524
GxB_load_Vector_from_Container (Delta, Container, desc) ;
510525
}
511526
GxB_Container_free (&Container) ;

GraphBLAS/GraphBLAS/@GrB/private/util/gb_export_to_mxsparse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ mxArray *gb_export_to_mxsparse // return exported MATLAB sparse matrix S
202202

203203
// ensure the types are correct; this 'cannot' fail but check anyway
204204
CHECK_ERROR (Tp_type != GrB_UINT64, "internal error 901") ;
205-
CHECK_ERROR (Ti_type != GrB_UINT64, "internal error 902") ;
205+
CHECK_ERROR (Ti_type != GrB_INT64, "internal error 902") ;
206206
CHECK_ERROR (Tx_type != type, "internal error 903") ;
207207

208208
//----------------------------------------------------------------------

GraphBLAS/GraphBLAS/@GrB/private/util/gb_export_to_mxstruct.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ mxArray *gb_export_to_mxstruct // return exported MATLAB struct G
230230
mxSetFieldByNumber (G, 0, 3, Ap_mx) ;
231231

232232
// export the indices
233-
mxClassID Ai_class = (Ai_type == GrB_UINT32) ?
233+
mxClassID Ai_class = (Ai_type == GrB_INT32 || Ai_type == GrB_UINT32) ?
234234
mxUINT32_CLASS : mxUINT64_CLASS ;
235235
mxArray *Ai_mx = mxCreateNumericMatrix (1, 0, Ai_class, mxREAL) ;
236236
if (Ai_size > 0)
@@ -252,7 +252,7 @@ mxArray *gb_export_to_mxstruct // return exported MATLAB struct G
252252
}
253253
mxSetFieldByNumber (G, 0, 2, Ax_mx) ;
254254

255-
mxClassID Ah_class = (Ah_type == GrB_UINT32) ?
255+
mxClassID Ah_class = (Ah_type == GrB_INT32 || Ah_type == GrB_UINT32) ?
256256
mxUINT32_CLASS : mxUINT64_CLASS ;
257257

258258
if (sparsity_status == GxB_HYPERSPARSE)

GraphBLAS/Source/container/GB_load_from_container.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@
1414
#include "GB_container.h"
1515
#define GB_FREE_ALL GB_phybix_free (A) ;
1616

17+
static inline bool GB_type_ok (GrB_Type type)
18+
{
19+
return (type == GrB_INT32 || type == GrB_UINT32 ||
20+
type == GrB_INT64 || type == GrB_UINT64) ;
21+
}
22+
23+
//------------------------------------------------------------------------------
24+
// GB_load_from_container
25+
//------------------------------------------------------------------------------
26+
1727
GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
1828
(
1929
GrB_Matrix A, // matrix to load from the Container
@@ -62,7 +72,8 @@ GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
6272
GrB_Type Ap_type = NULL, Ah_type = NULL, Ab_type = NULL, Ai_type = NULL ;
6373
uint64_t Ah_size = 0, Ap_size = 0, Ai_size = 0, Ab_size = 0, Ax_size = 0 ;
6474
uint64_t nrows_times_ncols = UINT64_MAX ;
65-
bool ok = GB_uint64_multiply (&nrows_times_ncols, nrows, ncols) ;
75+
bool okb = GB_uint64_multiply (&nrows_times_ncols, nrows, ncols) ;
76+
bool ok = true ;
6677
bool jumbled = Container->jumbled ;
6778

6879
// determine the A->j_is_32 condition when Container->h is empty
@@ -103,6 +114,7 @@ GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
103114
GB_OK (GB_vector_unload (Container->p, &(A->p), &Ap_type,
104115
&plen1, &Ap_size, &(A->p_shallow), Werk)) ;
105116
A->p_size = (size_t) Ap_size ;
117+
ok = GB_type_ok (Ap_type) ;
106118

107119
// load or create A->h
108120
if (h_empty)
@@ -127,6 +139,7 @@ GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
127139
&plen, &Ah_size, &(A->h_shallow), Werk)) ;
128140
}
129141
A->h_size = (size_t) Ah_size ;
142+
ok = ok && GB_type_ok (Ah_type) ;
130143

131144
// load A->Y
132145
A->Y = Container->Y ;
@@ -139,14 +152,15 @@ GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
139152
GB_OK (GB_vector_unload (Container->i, &(A->i), &Ai_type,
140153
&Ai_len, &Ai_size, &(A->i_shallow), Werk)) ;
141154
A->i_size = (size_t) Ai_size ;
155+
ok = ok && GB_type_ok (Ai_type) ;
142156

143157
// define plen, nvec, and jumbled
144158
A->plen = plen ;
145159
A->nvec = plen ;
146160
A->jumbled = jumbled ;
147161

148162
// basic sanity checks
149-
if (plen1 != plen + 1 ||
163+
if (!ok || plen1 != plen + 1 ||
150164
!(A->nvec >= 0 && A->nvec <= A->plen && A->plen <= A->vdim))
151165
{
152166
GB_FREE_ALL ;
@@ -164,6 +178,7 @@ GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
164178
GB_OK (GB_vector_unload (Container->p, &(A->p), &Ap_type,
165179
&plen1, &Ap_size, &(A->p_shallow), Werk)) ;
166180
A->p_size = (size_t) Ap_size ;
181+
ok = GB_type_ok (Ap_type) ;
167182

168183
// clear Container->h, Y, and b
169184
GB_vector_reset (Container->h) ;
@@ -174,14 +189,15 @@ GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
174189
GB_OK (GB_vector_unload (Container->i, &(A->i), &Ai_type,
175190
&Ai_len, &Ai_size, &(A->i_shallow), Werk)) ;
176191
A->i_size = (size_t) Ai_size ;
192+
ok = ok && GB_type_ok (Ai_type) ;
177193

178194
// define plen, nvec, and jumbled
179195
A->plen = plen1 - 1 ;
180196
A->nvec = A->plen ;
181197
A->jumbled = jumbled ;
182198

183199
// basic sanity checks
184-
if (!(A->nvec == A->plen && A->plen == A->vdim))
200+
if (!ok || !(A->nvec == A->plen && A->plen == A->vdim))
185201
{
186202
GB_FREE_ALL ;
187203
return (GrB_INVALID_VALUE) ;
@@ -212,7 +228,7 @@ GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
212228
A->nvec = A->vdim ;
213229

214230
// basic sanity checks
215-
if (Ab_type != GrB_INT8 || !ok || Ab_len < nrows_times_ncols)
231+
if (Ab_type != GrB_INT8 || !okb || Ab_len < nrows_times_ncols)
216232
{
217233
GB_FREE_ALL ;
218234
return (GrB_INVALID_VALUE) ;
@@ -246,9 +262,9 @@ GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
246262
A->x_size = (size_t) Ax_size ;
247263

248264
// define the integer types
249-
A->p_is_32 = (Ap_type == GrB_UINT32) ;
250-
A->j_is_32 = (Ah_type == GrB_UINT32) ;
251-
A->i_is_32 = (Ai_type == GrB_UINT32) ;
265+
A->p_is_32 = (Ap_type == GrB_UINT32 || Ap_type == GrB_INT32) ;
266+
A->j_is_32 = (Ah_type == GrB_UINT32 || Ah_type == GrB_INT32) ;
267+
A->i_is_32 = (Ai_type == GrB_UINT32 || Ai_type == GrB_INT32) ;
252268

253269
//--------------------------------------------------------------------------
254270
// more basic sanity checks
@@ -270,14 +286,14 @@ GrB_Info GB_load_from_container // GxB_Container -> GrB_Matrix
270286
// A->x must have size >= A->nvals for non-iso sparse/hypersparse
271287
ok = (Ax_len >= A->nvals) ;
272288
}
273-
else
289+
else // A is full or bitmap
274290
{
275291
// A->x must have size >= nrows*ncols for non-iso full/bitmap
276-
ok = ok && (Ax_len >= nrows_times_ncols) ;
292+
ok = okb && (Ax_len >= nrows_times_ncols) ;
277293
}
278294

279295
// ensure Ai_len is the right size
280-
if (format == GxB_HYPERSPARSE || format == GxB_SPARSE)
296+
if (format == GxB_HYPERSPARSE || format == GxB_SPARSE && ok)
281297
{
282298
// A->i must have size >= A->nvals for sparse/hypersparse
283299
ok = ok && (Ai_len >= A->nvals) ;

GraphBLAS/Source/container/GB_unload_into_container.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ GrB_Info GB_unload_into_container // GrB_Matrix -> GxB_Container
7777
A->p_is_32 ? GrB_UINT32 : GrB_UINT64,
7878
A->nvec+1, A->p_size, A->p_shallow) ;
7979
GB_vector_load (Container->h, &(A->h),
80-
A->j_is_32 ? GrB_UINT32 : GrB_UINT64,
80+
A->j_is_32 ? GrB_INT32 : GrB_INT64,
8181
A->nvec, A->h_size, A->h_shallow) ;
8282
GB_vector_load (Container->i, &(A->i),
83-
A->i_is_32 ? GrB_UINT32 : GrB_UINT64,
83+
A->i_is_32 ? GrB_INT32 : GrB_INT64,
8484
nvals, A->i_size, A->i_shallow) ;
8585
break ;
8686

@@ -91,7 +91,7 @@ GrB_Info GB_unload_into_container // GrB_Matrix -> GxB_Container
9191
A->p_is_32 ? GrB_UINT32 : GrB_UINT64,
9292
A->plen+1, A->p_size, A->p_shallow) ;
9393
GB_vector_load (Container->i, &(A->i),
94-
A->i_is_32 ? GrB_UINT32 : GrB_UINT64,
94+
A->i_is_32 ? GrB_INT32 : GrB_INT64,
9595
nvals, A->i_size, A->i_shallow) ;
9696
break ;
9797

GraphBLAS/Source/container/GxB_Container_new.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ GrB_Info GxB_Container_new
5858
//--------------------------------------------------------------------------
5959

6060
GB_OK (GB_container_component_new (&((*Container)->p), GrB_UINT32)) ;
61-
GB_OK (GB_container_component_new (&((*Container)->h), GrB_UINT32)) ;
61+
GB_OK (GB_container_component_new (&((*Container)->h), GrB_INT32)) ;
6262
GB_OK (GB_container_component_new (&((*Container)->b), GrB_INT8)) ;
63-
GB_OK (GB_container_component_new (&((*Container)->i), GrB_UINT32)) ;
63+
GB_OK (GB_container_component_new (&((*Container)->i), GrB_INT32)) ;
6464
GB_OK (GB_container_component_new (&((*Container)->x), GrB_BOOL)) ;
6565

6666
//--------------------------------------------------------------------------

0 commit comments

Comments
 (0)