Discussion:
[Numba] guvectorize with fixed size output array?
j***@gmail.com
2016-04-09 18:29:05 UTC
Permalink
Hello!

I have a function that takes an n-by-n 2d array and returns a 1d array with
a fixed length 6.
Is it possible to guvectorize this?

Naively, I tried the following decorator:

@_numba.guvectorize(["void(float32[:,:], float32[:])"], "(n,n)->(6)",
nopython=True)


However, when importing the module, I get:

ValueError: bad token in signature "6"


Thanks for any help!
Joerg
--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+***@continuum.io.
To post to this group, send email to numba-***@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/765f4792-bf71-4339-bff1-65af9765f5db%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
Stanley Seibert
2016-04-10 21:36:19 UTC
Permalink
Our gufunc syntax is restricted to what NumPy supports:

http://docs.scipy.org/doc/numpy-1.10.0/reference/c-api.generalized-ufuncs.html

A constant dimension is not supported in that syntax, so you would need to
put another dimension name there, and then rely on the caller to ensure it
was of size 6. We are interested in exploring extensions to the gufunc
signature, but have not invested any major effort there yet.
Post by j***@gmail.com
Hello!
I have a function that takes an n-by-n 2d array and returns a 1d array
with a fixed length 6.
Is it possible to guvectorize this?
@_numba.guvectorize(["void(float32[:,:], float32[:])"], "(n,n)->(6)",
nopython=True)
ValueError: bad token in signature "6"
Thanks for any help!
Joerg
--
You received this message because you are subscribed to the Google Groups
"Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/a/continuum.io/d/msgid/numba-users/765f4792-bf71-4339-bff1-65af9765f5db%40continuum.io
<https://groups.google.com/a/continuum.io/d/msgid/numba-users/765f4792-bf71-4339-bff1-65af9765f5db%40continuum.io?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+***@continuum.io.
To post to this group, send email to numba-***@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/CADv3RKQjKEwtgudNy0Z%2B2oP0HfpxvFV7ToQoxW0Jq0gr7QhBOg%40mail.gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
j***@gmail.com
2016-04-11 06:28:29 UTC
Permalink
Thanks for the answer!

I found that the signature (n,n)->(p) produces an error stating that p is unkown. (I can reproduce the exact message if you are interested.)
So, it seems like any output dimension must match one of the input dimensions.

I found a workaround by calling the function with an extra dummy array of the expected output size. The signature then becomes:
(n,n),(p)->(p)
Think of p as a constant and p=6.It's a bit ugly, but works fine.

Regards,
Joerg
--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+***@continuum.io.
To post to this group, send email to numba-***@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/d3c447e4-af77-420e-933a-260226ca6b4e%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
j***@gmail.com
2016-04-11 06:37:19 UTC
Permalink
A follow up:

The numpy docs you linked suggest that it is possible to return a dimension
that is not a dimension of an input array. Hence, this might be a numba bug.

Here is the error message:

C:\Miniconda3\lib\site-packages\numba\npyufunc\sigparse.py in
parse_signature(sig)
61 diff = osym.difference(isym)
62 if diff:
---> 63 raise NameError('undefined output symbols: %s' %
','.join(sorted(diff)))
64
65 return inputs, outputs

NameError: undefined output symbols: p

Regards,
Joerg
Post by j***@gmail.com
Thanks for the answer!
I found that the signature (n,n)->(p) produces an error stating that p is
unkown. (I can reproduce the exact message if you are interested.)
So, it seems like any output dimension must match one of the input dimensions.
I found a workaround by calling the function with an extra dummy array of
(n,n),(p)->(p)
Think of p as a constant and p=6.It's a bit ugly, but works fine.
Regards,
Joerg
--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+***@continuum.io.
To post to this group, send email to numba-***@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/11603e57-7b44-4ebc-9b63-45e80e1de63d%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
Stephan Hoyer
2016-04-12 05:54:24 UTC
Permalink
A straightforward alternative is to make a wrapper to allocate the output
array and pass it as input gufunc argument. Output arguments are not
required by gufuncs in Numba.
Post by j***@gmail.com
Thanks for the answer!
I found that the signature (n,n)->(p) produces an error stating that p is
unkown. (I can reproduce the exact message if you are interested.)
So, it seems like any output dimension must match one of the input dimensions.
I found a workaround by calling the function with an extra dummy array of
(n,n),(p)->(p)
Think of p as a constant and p=6.It's a bit ugly, but works fine.
Regards,
Joerg
--
You received this message because you are subscribed to the Google Groups
"Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/a/continuum.io/d/msgid/numba-users/d3c447e4-af77-420e-933a-260226ca6b4e%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users+***@continuum.io.
To post to this group, send email to numba-***@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/CAEQ_TvcubKhZ3upj3_gqRKNhfyjFmjMjL1-LXbZvNyCs%3DwO3CQ%40mail.gmail.com.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
Loading...