Skip to content

How to use select? #10

Open
Open
@szarnyasg

Description

@szarnyasg

An alternative solution to implement the algorithm in #9 would be to use select. However, I could not get select working after studying the examples in dnn.py and K-Truss.ipynb. So, the question in this issue is twofold.

(1) How can I use basic select operators on vectors/matrices?

Weirdly, select on vectors work but does not work on matrices:

A[3].select(lib.GxB_NONZERO) # works
A.select(lib.GxB_NONZERO)    # fails
The error ---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/.local/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

~/.local/lib/python3.6/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    397                         if cls is not object \
    398                                 and callable(cls.__dict__.get('__repr__')):
--> 399                             return _repr_pprint(obj, self, cycle)
    400 
    401             return _default_pprint(obj, self, cycle)

~/.local/lib/python3.6/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    687     """A pprint that just redirects to the normal repr function."""
    688     # Find newlines and replace them with p.break_()
--> 689     output = repr(obj)
    690     for idx,output_line in enumerate(output.splitlines()):
    691         if idx:

/usr/local/lib/python3.6/dist-packages/pygraphblas-0.0.1-py3.6-linux-x86_64.egg/pygraphblas/matrix.py in __repr__(self)
   1024             self.ncols,
   1025             self.nvals,

Maybe something's wrong with my setup? I'm running Python 3.6 which might be an issue.

(2) How can I use a UDT to define a selection function that selects the first/second half of a vector? The vector is split based on a position defined in the thunk value - see e.g. this C code that returns the first half of the vector:

// definition

static bool select_index_smaller_than (GrB_Index i, GrB_Index j, GrB_Index nrows, GrB_Index ncols, const void *x, const void *thunk)
{
    return i < *((uint64_t*) thunk);
}
GxB_SelectOp s;
GxB_SelectOp_new (&s, select_index_smaller_than, GrB_UINT64, GrB_UINT64);

// usage

GxB_Scalar thunk;
GxB_Scalar_new (&thunk, GrB_UINT64);
GxB_Scalar_setElement (thunk, i);

GxB_select (a21T, GrB_NULL, GrB_NULL, s, a1, thunk, GrB_NULL);

Many thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions