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

np_to_af_array copy #172

Open
selimyoussry opened this issue Jan 18, 2018 · 1 comment
Open

np_to_af_array copy #172

selimyoussry opened this issue Jan 18, 2018 · 1 comment

Comments

@selimyoussry
Copy link

@selimyoussry selimyoussry commented Jan 18, 2018

Hi everyone, the source code for "np_to_af_array" seems guaranteed to raise a RuntimeError("Copy can not be False for numpy arrays"), shouldn't it only be present in the "else" statement?

I'm thinking of this:

def np_to_af_array(np_arr, copy=True):
        in_shape = np_arr.shape
        in_ptr = np_arr.ctypes.data_as(c_void_ptr_t)
        in_dtype = _nptype_to_aftype[np_arr.dtype.str[1:]]

        if (np_arr.flags['F_CONTIGUOUS']):
            return _fc_to_af_array(in_ptr, in_shape, in_dtype)
        elif (np_arr.flags['C_CONTIGUOUS']):
            return _cc_to_af_array(in_ptr, np_arr.ndim, in_shape, in_dtype)
        else:
            if not copy:
                raise RuntimeError("Copy cannot be false if the data is not a single, Fortran-style (F_CONTIGUOUS flag) or C-style (C_CONTIGUOUS flag) contiguous segment")
            return np_to_af_array(np_arr.copy())

instead of the current code

What do you think?

Thanks!

@pavanky
Copy link
Member

@pavanky pavanky commented Jan 18, 2018

@selimyoussry copy should never be false. You can send in a PR to remove that option if you want to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.