Merge pull request #1544 from smichr/slice

3401: fix matrix slicing error
allow submatrix assignment given top left indices

There is no need for the redundant slice when assigning a matrix
to a subregion of another matrix; it is sufficient to just give
the top left target position in the matrix and the list form (or
Matrix form) of what should be put there:

>>> i = eye(3)
>>> i[0,0] = Matrix(range(3))
>>> i
[0, 0, 0]
[1, 1, 0]
[2, 0, 1]
>>> i[0,0] = Matrix([range(3)])
>>> i
[0, 1, 2]
[1, 1, 0]
[2, 0, 1]
>>> i[0,0]=[[4,4]]
>>> i
[4, 4, 2]
[1, 1, 0]
[2, 0, 1]

Also, is_sequence(Matrix) is True so the include values were removed
from tests of is_sequence that included some sort of Matrix.

A little care needs to be used when checking types:
  Matrix, SparseMatrix derive from MatrixBase
  MatrixBase and MatrixExpr (which doesn't derive from MatrixBase)
    are all sequences -- hence the use of `ismat` when checking
    for submatrix assignment.
matrix cleanup

Add a copy method to replace M[:, :] (which requires slice calculations)

simplified tolist

simplified examples to show the salient feature being deomonstrated;
rather than using a variety of numbers, zeros and ones are now used.

SparseMatrix __setitem__ can now translate an integer to a key
S[1] = 42 will figure out the i,j location of position 1

simplified toMatrix by using the tolist method

gave SparseMatrix its own tolist method since S.mat is a dictionary
and using the default parent class tolist method did not work for
SparseMatrix

Add an efficient negation of a SparseMatrix

simplified the add method for SparseMatrix
spaces after commas added
smarter multiply and other SparseMatrix methods added

These are some of the methods that Sherjil worked on in PR #456.
The _lil_row_major is modified from what he presented there. In addition
col_join was added, too, for SparseMatrix.
matrices: add normalize and sort options to diagonalize
matrices: SparseMatrix mat -> smat

[regarding mat -> smat, see below]

minor edits

put a temporary as_int in place until this is merged with 0.7.2

MUTABLEMATRIX

since _cholesky is a parent-class function, make sure it returns
the same type as was received. (SparseMatrix doesn't have a _new
method so either one has to be added or -- as here -- the general
instantiation using the type of self must be used.)

elaborate the _handle_creation_inputs docstring and reorganize
code so there is only one error message location at the end of the
if-blocks.

__setitem__ and __getitem__ are now defined in MutableMatrix and
overridden in SparseMatrix

SPARSEMATRIX

refactored the __init__ code for SparseMatrix and removed the TODO
since it appears that the only things left to process are the
numpy array and the flat list...and I don't see any sparse-smarts
that can be applied to those.

copy is put here to override the MutableMatrix version because...
** smat ** rather than mat is used to store the sparse matrix dict;
if SparseMatrix shares the name 'mat' with MutableMatrix, it is
possible to call methods on Sparse that are only defined to work
in Mutable -- methods that operate on mat. Now, at least, an error
will be raised signaling the need to write a sparse routine for the
desired method.

TODO: change indexing and mat storage so __getitem__ always works
quickly with M[(i, j)] and then perhaps smat can be changed back to
mat.

rowdecomp is such a low-level activity that it is simply inlined
where it is needed.

a duplicate multiply was removed and _lil_row_major removed (and the
row_list is now used in-place in multiply)

all other changes involve changing mat to smat or removing obsolete tests
and editing whitespace.
Sparse gets C, T, H, D methods; upgrade reshape+copyin_matrix
add solve methods to SparseMatrix
corrections to SparseMatrix solve methods
matrices: misc changes
matrices: make norm more flexible
un-XFAIL sparse matrix tests
matrices: increase coverage
fix blockmatrix.transpose
matrices: make mat and smat private properties

Since SparseMatrix's mat is a dictionary and MAtrixBase's is a flat list
and Sparse derives from a class in which many routines are defined that
depend on .mat being a list, this disambiguation will help highlight
methods that need to have a SparseMatrix version written rather than
relying on inheritance from MatrixBase.
matrices: add .inv and docstring to blockmatrix
matrices: make sure elements are sympified even for ij-independent lambda
matrices: edit col_join/row_join; del toMatrix

The Matrix class can be used directly yo convert Sparse to Mutable:

    Matrix(SparseMatrix(...))
matrices: MatrixBase has solve and solve_least_squares methods, too

These methods default to different methods than were given to the
Sparse versions of the same, following the preferences of inversion.

In the case of linear least squares solving, the cholesky_solve was
selected as the default method rather than method GE.