Skip to content

Latest commit

 

History

History
98 lines (76 loc) · 4.16 KB

HACKING.rst

File metadata and controls

98 lines (76 loc) · 4.16 KB

node.py resolve.py

class method node.ident self.ident

HACKING

  matlab fortran python
  1. Base-one indexing
yes yes no
  1. Columns-first data layout
yes yes no
  1. Auto-expanding arrays
yes no * yes
  1. Update to create
yes no * yes
  1. Assignment as copy
yes yes no
  matlab fortran python
  1. Matrices everywhere
yes no no
  1. Single subscript implies ravel
yes    
  1. Broadcast
     
  1. Boolean indexing
     
  1. Type and rank must be known in compile time
no yes no
  matlab fortran python
  1. Garbage collection
yes no * yes
  1. All uppercase
no yes no
  1. Structs
     
  1. Interpreted
yes no yes
  1. Strings are arrays of chars
yes no yes
  1. Auto-expanding arrays

Matlab arrays are auto-magically resized on out-of-bounds update. Deprecated, this feature is widely used in legacy code. Supporting this feature is hard both in python and in fortran.

In fortran, the pattern should be somehow (how exactly?) detected in compile-time. In python __setitem__ hides try-catch, with resize called inside catch. Is try-catch in fortran?

In numpy out-of-bounds assignment is an error. In smop, out-of-bounds assignment is supported for row and column matrices and their generalizations having shape

[1 1 ... N ... 1]

These arrays may be resized along their only non-singular dimension. For other matrices, new columns can be added to F_CONTIGUOUS arrays, and new rows can be added to C_CONTIGUOUS arrays.

Finally, scalar array of any dimension, having shape

[1 1 ... 1]

can be resized along any dimension.

  1. Update to create

In matlab, arrays may be created by updating a non existent array, as in the example:

>>> clear a
>>> a(17)=42

This unique feature is not supported by smop, but can be worked around by inserting assignments into the original matlab code:

>>> a=[]
>>> a(17_=42