Ticket #3 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

Setting sparse matrix with function f(i,j) doesn't work on scipy 0.7.1

Reported by: thesamovar Owned by: thesamovar
Priority: blocker Milestone: 1.2
Component: Core Version: 1.1.3
Keywords: Cc:

Description (last modified by thesamovar) (diff)

The following code doesn't work:

Ce=Connection(Ge, G, 'ge', weight=lambda i,j: rand(),
              delay=lambda i,j: rand()*(max_delay-min_delay)+min_delay,
              sparseness=prob_conn)

The reason appears to be a bug in scipy 0.7.1 (not present in 0.7.0) sparse matrix support. If you try the following:

x = lil_matrix((5,5))
x[0,[]] = []
x[0,[0]] = [1]
x[0,[0,1]] = [1,2]

Only the last one works. The first raises a problem with shape, the second with setting an element with a sequence. All of these should work I think.

This could be fixed in Brian probably, but maybe we should consider one of:

  • changing sparse matrix library (investigate others)
  • dedicate some resources to improving scipy sparse matrix support
  • add another patch to Brian to work around this bug
  • write our own sparse matrix library from scratch (possibly with limited functionality)

Change History

Changed 3 years ago by thesamovar

  • owner set to thesamovar
  • status changed from new to assigned
  • description modified (diff)

Changed 3 years ago by thesamovar

  • version set to 1.1.3

Changed 2 years ago by thesamovar

  • status changed from assigned to closed
  • resolution set to fixed

We resolved this problem by using 'monkey patching' - that is we check which version of scipy is installed and use a custom class spmatrix derived from scipy.sparse.lil_matrix, which version of the class spmatrix is used depends on the scipy verison. This allows us to have different patches for different versions of scipy, maintain backwards compatibility, etc.

Note: See TracTickets for help on using tickets.