question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

1d array, column of fortran array, with F and C contiguity, raises error for not being C-contiguous.

See original GitHub issue

Thank you for this great and useful library 😃

I have noticed that functions like the following foo do not compile:

from numba import njit
import numpy as np


@njit('f8[::1](f8[::1])')
def foo2(b):
    return b

@njit('f8[::1](f8[::1,:])')
def foo(a):
    return foo2(a[:, 0])

The following error is raised:

TypingError: Invalid use of type(CPUDispatcher(<function foo2 at 0x000001759D4C7550>)) with parameters (array(float64, 1d, F))
Known signatures:
 * (array(float64, 1d, C),) -> array(float64, 1d, C)
During: resolving callee type: type(CPUDispatcher(<function foo2 at 0x000001759D4C7550>))

It indicates that the input argument given to function foo2 is not C-contiguous.

However, by checking the flags of fortran-arrays columns, we can see that they present both contiguities, e.g.:

arr = np.array([[1.0, 2.0], [3.0, 4.0]], order='F')
print(f'{arr[:, 0].flags}\n{arr[:, 1].flags}')
C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False

C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False

I think this is related to #5967. There a similiar problem appeared when using empty arrays with F-order.

Numba version: 0.56.3 (latest as of today).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
stuartarchibaldcommented, Nov 4, 2022

That’s really helpful, thanks again!, and my bad for not realising that I could have used that kind of type signature.

No problem. Typically signatures are not needed as type inference just “works it out”, but those options above present the methods of describing just about anything within the type system if needed.

0reactions
javierttggcommented, Nov 4, 2022

That’s really helpful, thanks again!, and my bad for not realising that I could have used that kind of type signature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: When changing to a larger dtype, its size must be ...
When you try to change the dtype of a Fortran-order array, a warning is raised: DeprecationWarning: Changing the shape of an F-contiguous ......
Read more >
Using Arrays Efficiently
The array temporary is created because the passed array may not be contiguous and the receiving (explicit-shape) array requires a contiguous array. When...
Read more >
Using F2PY bindings in Python — NumPy v1.12 Manual
Fortran -contiguous arrays when data is stored column-wise, i.e. indexing of data as stored in memory starts from the lowest dimension; · C-contiguous...
Read more >
Using F2PY bindings in Python — NumPy v1.9 Manual
Fortran -contiguous arrays when data is stored column-wise, i.e. indexing of data as stored in memory starts from the lowest dimension;; C-contiguous or...
Read more >
2. Creating Numpy Arrays | Numerical Programming
NumPy tutorial: Creating basic array structures and manipulating arrays. ... 'F' if the object 'obj' is Fortran contiguous, 'C' otherwise.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found