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

Wrong array order (memory layout) #1171

Open
ohachim opened this issue Jul 26, 2022 · 0 comments · May be fixed by #1180
Open

Wrong array order (memory layout) #1171

ohachim opened this issue Jul 26, 2022 · 0 comments · May be fixed by #1180
Assignees
Labels

Comments

@ohachim
Copy link
Member

ohachim commented Jul 26, 2022

Description
When not specifying the order of an ndarray, Pyccel defaults to order C, which is correct, unless the array was created using and order F ndarray
To Reproduce

if __name__ == "__main__":
    import numpy as np
    a = np.array([[1], [2], [4]], order="F")
    c = np.array(a)
int main()
{
    t_ndarray a = {.shape = NULL};
    t_ndarray c = {.shape = NULL};
    a = array_create(2, (int64_t[]){3, 1}, nd_int64, false, order_f);
    int64_t array_dummy[] = {1, 2, 4};
    memcpy(a.nd_int64, array_dummy, a.buffer_size);
    c = array_create(2, (int64_t[]){3, 1}, nd_int64, false, order_c);
    array_copy_data(c, a, 0);
    free_array(a);
    free_array(c);
    return 0;
}

Expected behavior
The second array_create (line 8) should have order_f as a last parameter

int main()
{
    t_ndarray a = {.shape = NULL};
    t_ndarray c = {.shape = NULL};
    a = array_create(2, (int64_t[]){3, 1}, nd_int64, false, order_f);
    int64_t array_dummy[] = {1, 2, 4};
    memcpy(a.nd_int64, array_dummy, a.buffer_size);
    c = array_create(2, (int64_t[]){3, 1}, nd_int64, false, order_f);
    array_copy_data(c, a, 0);
    free_array(a);
    free_array(c);
    return 0;
}

Additional context
The problem is in the Variable classe's order attribute should be parsed as order F, because the array it was created from is order F
#1128 (comment)

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

Successfully merging a pull request may close this issue.

2 participants