On Wed, Mar 5, 2008 at 10:21 AM, Dan Christensen <[EMAIL PROTECTED]> wrote: > > "didier deshommes" <[EMAIL PROTECTED]> writes: > > > SAGE now tries to support numpy (and matlab)-style indexing, by poking > > at its underlying __getitem__ and __getslice__ (thanks to a suggestion > > by William): > > Great! > > Another nice feature of numpy is *assigning* using numpy-style indexing. > For example, to add a multiple of column j to column i, you can do > > A[:,i] += m*A[:,j] > > And you can zero out a region with > > A[2:4, 3:8] = 0 (broadcasting used here)
This is currently not supported, I've opened a ticket: http://trac.sagemath.org/sage_trac/ticket/2396 > > About the efficiency concern raised by William, does it work to first > assume the indices are not fancy, and if that fails, then catch an > exception and try to interpret them as numpy-style indices? We check first if both indices are Integers and return immediately. If not, we check if each argument is either a list, a slice or an integer and pass that result to matrix_from_rows_and_columns. The new method turns out to be faster in most cases for element-by-element retrieval on large matrices (all timings done on sage.math): {{ #old sage: M = random_matrix(ZZ,1500,600) sage: %timeit M[29,300] 10000 loops, best of 3: 70.7 µs per loop #new sage: M = random_matrix(ZZ,1500,600) sage: %timeit M[29,300] 10000 loops, best of 3: 68.3 µs per loop ######################### #old sage: M = random_matrix(ZZ,1500,1500) sage: %timeit M[1000,1000] 10000 loops, best of 3: 70.3 µs per loop #new sage: M = random_matrix(ZZ,1500,1500) sage: %timeit M[1000,1000] 10000 loops, best of 3: 68 µs per loop }}} In this case, I think it's cython being smarter about optimizing stuff. For whole row retrieval, it is still slower: {{{ #old sage: M = random_matrix(ZZ,4000) sage: %timeit M[3000] 1000 loops, best of 3: 1.05 ms per loop #new sage: M = random_matrix(ZZ,4000) sage: %timeit M[3000] 1000 loops, best of 3: 1.12 ms per loop }}} This depends on matrix_from_rows, so optimizing that will yield results faster. didier --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---