Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the boolean copy from data #3561

Closed

Conversation

akahard2dj
Copy link

closes #2921

Hello,
I am very pleased with contributing to numba project.
This PR is first job for me.
Please reviewing my PR.

I fixed the bug for taking a numpy boolean array to memory.
In my opion, there is no problem for copying from disk by using 1bit size.

I have also tested in llvmlite using ir.
There is no problem when boolean copy to 1 bit size.

import numpy as np
from llvmlite import ir

a = np.bool(True)
print(a)

int8 = ir.IntType(8)
int1 = ir.IntType(1)

bit_bool = int1(a)
byte_bool = int8(a)
print(bit_bool)
print(byte_bool)
True
i1 true
i8 true

If there any problems in my PR, I welcome valuable comments.

@stuartarchibald
Copy link
Contributor

Many thanks for the patch. Unfortunately this does not fix the problem presented and many unit tests fail because there are now multiple occurrences of invalid store of i8* to i1* that occur when trying to lower the Numba IR to LLVM IR. I think #2921 (comment) was alluding to something along the lines of:

    def from_data(self, builder, value):
        ty = self.get_value_type()
        resalloca = cgutils.alloca_once(builder, ty)
        cond = builder.icmp_unsigned('==', value, value.type(0))
        with builder.if_else(cond) as (then, otherwise):
            with then:
                builder.store(ty(0), resalloca)
            with otherwise:
                builder.store(ty(1), resalloca)
        return builder.load(resalloca)

in place of:

def from_data(self, builder, value):
return builder.trunc(value, self.get_value_type())

@akahard2dj
Copy link
Author

That too bad.
I will re-fix this feature.
Thanks! for your valuable comments!

@stuartarchibald
Copy link
Contributor

Closing as #3862 fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Active
In Progress
Development

Successfully merging this pull request may close these issues.

numpy booleans that aren't 0/1 in memory are treated differently to numpy
2 participants