Skip to content

Conversation

eriknw
Copy link
Member

@eriknw eriknw commented Apr 18, 2020

Oops, I still need to do this for UnaryOp.

We cache the compilation of isclose based on (abs_tol, rel_tol). Overall, I don't know the performance difference of this isclose, but just as importantly this should be more memory efficient.

This is still a little rough, but I put this up for feedback.

Oops, I still need to do this for `UnaryOp`.

We cache the compilation of `isclose` based on `(abs_tol, rel_tol)`.
Overally, I don't know the performance difference of this `isclose`,
but just as importantly this should be more memory efficient.
eriknw added 2 commits April 17, 2020 23:16
Still need to add a few tests and docstrings.

I'm not sure I like `register_anonymous`.
create_anonymous, build_anonymous, create, build, compile, jit?
So far, do unary, binary, and monoid.  Semirings may come later.
This required modifying how UDFs are registered.  In particular, we are
now more relaxed about bool inputs that have non-bool outputs.

Numba has difficulty compiling functions for bools, so we upcast bool
values to int8 during the computation.  This may introduce subtle bugs
if coercions are not appropriate.  For example, bit-twidding and shifting
of bools may be incorrect!
eriknw added 5 commits April 20, 2020 17:21
…rings.

Specifically, we need to match the return type of binary functions to the type for the monoid.
It's risky to have flexible equality *and* hashability.
I think it's best to choose one; in this case, flexible equality is nicer.
v = Vector.new_from_values([0, 1, 3], [1, 2, -4], dtype=dtypes.INT32)
v << v.apply(unary.plus_one)
result = Vector.new_from_values([0, 1, 3], [2, 3, -3], dtype=dtypes.INT32)
assert v.isequal(result)


def test_unaryop_udf_bool_result():
pytest.xfail('not sure why numba has trouble compiling this')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good news! The hack to change BOOL to INT8 during computation appeared to work. Well, at least this test passes now.

@jim22k
Copy link
Member

jim22k commented Apr 21, 2020

It sure would be nice to figure out ahead-of-time compiling with numba so we don't need to JIT compile the numpy functions every time we start up.

@eriknw
Copy link
Member Author

eriknw commented Apr 22, 2020

Yeah, that would be great (assuming the binary isn't too large). One step at a time.

Copy link
Member

@jim22k jim22k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I might change is the location of _generate_isclose. It feels strange having that in vector.py, but I can't think of where else makes more sense. So I'm okay with it here for now.

This revealed that our hack to support boolean unary and binary functions
is not compatible with monoids and semirings.  Oh well.
All bool operations in `unary.numpy` and `binary.numpy` should work "as expected",
which, admittedly, is a little weird at times.
Bool to float operations go to FP32.
@eriknw
Copy link
Member Author

eriknw commented Apr 23, 2020

Whew! Tests added.

UDFs over bools works for unary and binary operations, but not monoid or semiring. Oh well. Hopefully our hack to support bool unary and binary continues to work okay with few surprises.

Shall we merge? I may eventually have op.types be a dict of {input_type: output_type} instead of just a set of input types.

@jim22k jim22k merged commit 02e61a5 into python-graphblas:master Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants