Unable to include bitset.pxi

52 views
Skip to first unread message

Chin-Hung Lin

unread,
Jan 29, 2020, 9:11:04 AM1/29/20
to sage-support
Hello,

Sage version: 9.0, Release Date 2020-01-01
installed through arch linux package manager

I tried to run the code below in Jupyter

%%cython
include "sage/data_structures/bitset.pxi"

but then it returns a long list of error and I believe the most relevant one is as below.  
(If necessary, I can provide the full error message.)

Could someone help and give me some advice?  

PS I have checked that the bitset.pxi on my machine is the same as the lastest version on the develop branch.


RuntimeError: Error compiling Cython file:
------------------------------------------------------------
...
    """
    if size <= 0:
        raise ValueError("bitset capacity must be greater than 0")

    bits.size = size
    bits.limbs = (size - 1) / (8 * sizeof(mp_limb_t)) + 1
                                                     ^
------------------------------------------------------------

/usr/lib/python3.8/site-packages/sage/data_structures/bitset.pxi:84:54: Cannot assign type 'double' to 'mp_size_t'

Chin-Hung Lin

unread,
Feb 2, 2020, 12:51:04 AM2/2/20
to sage-support
I am able to resolve the issue by modifying 
bits.limbs = (size - 1) / (8 * sizeof(mp_limb_t)) + 1
to integer division
bits.limbs = (size - 1) // (8 * sizeof(mp_limb_t)) + 1

However, I doubt that this is the correct way to fix it?  
1. If this is correct, should I send initiate a ticket to correct th code on SageMath?
2. If not, what is the better way to avoid this error?

Dima Pasechnik

unread,
Feb 2, 2020, 6:50:53 AM2/2/20
to sage-support, sage-devel
On Sun, Feb 2, 2020 at 5:51 AM Chin-Hung Lin <jephi...@gmail.com> wrote:
>
> I am able to resolve the issue by modifying
>
> bits.limbs = (size - 1) / (8 * sizeof(mp_limb_t)) + 1
>
> to integer division
>
> bits.limbs = (size - 1) // (8 * sizeof(mp_limb_t)) + 1
>
>
> However, I doubt that this is the correct way to fix it?
> 1. If this is correct, should I send initiate a ticket to correct th code on SageMath?

this appears to be a kind of bug in the %%cython magic, which fails to
take into account
that in Python 3 '/' is no longer integer division.

I've opened a ticket - probably we need to make sure that *.pxi files
do not contain Python2-only code.
https://trac.sagemath.org/ticket/29139



> 2. If not, what is the better way to avoid this error?
>
> --
> You received this message because you are subscribed to the Google Groups "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/3d097abf-b27d-4d61-904b-3d55a82de578%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages