[SciPy-Dev] fwrap refactor: Emulating f2py array shape handling?

Dag Sverre Seljebotn dagss at student.matnat.uio.no
Wed Dec 8 08:26:55 EST 2010


In the ongoing fwrap refactor I'm trying hard to emulate f2py 
completely. Still it'd be good to know whether you consider the 
behaviour of f2py a feature or a mis-feature. If the latter, it'd be 
trivial to, e.g., include a flag that would allow people to experiment 
with fwrap vs. f2py behaviour, and change to the former at some point if 
the fwrap refactor is pulled upstream.

The question is how functions should deal with arrays of a different 
rank than what they expect. Possibilities:

f2py behaviour: Go to very great lengths to convert array shapes. Assume 
the function to be called wants a 2D array, then:

  - Array of shape (1, 1, 3, 1, 1, 4, 1) is treated as (3, 4) # ignore 
1-length
  - (1, 1, 3, 1, 5, 6) => (3, 30) # flatten trailing dimensions
  - (3) -> (3, 1) # pad with 1-length dims on right side
  - I think there's more...

fwrap behaviour: Simply raise exception if the rank and dimension does 
not match.

My opinion: I think f2py is going too far, and would prefer something 
that is closer to the simpler broadcasting rules of NumPy ("Explicit is 
better than implicit"). Perhaps allow (3,) -> (3, 1), but not the others...

Dag Sverre



More information about the SciPy-Dev mailing list