@@ -0,0 +1,2304 @@
+# Copyright 2014, 2015 The ODL development group%0A#%0A# This file is part of ODL.%0A#%0A# ODL is free software: you can redistribute it and/or modify%0A# it under the terms of the GNU General Public License as published by%0A# the Free Software Foundation, either version 3 of the License, or%0A# (at your option) any later version.%0A#%0A# ODL is distributed in the hope that it will be useful,%0A# but WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A# GNU General Public License for more details.%0A#%0A# You should have received a copy of the GNU General Public License%0A# along with ODL.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A%0A# Imports for common Python 2/3 codebase%0Afrom __future__ import print_function, division, absolute_import%0Afrom future import standard_library%0Astandard_library.install_aliases()%0A%0A# External%0Aimport numpy as np%0A%0A# Internal%0Afrom odl.space.base_ntuples import FnBase%0Afrom odl.set.pspace import ProductSpace%0A%0A%0Adef matrix_representation(op):%0A    %22%22%22Returns a matrix representation of a linear operator.%0A%0A    Parameters%0A    ----------%0A    op : :class:%60~odl.Operator%60%0A        The linear operator of which one wants a matrix representation.%0A%0A    Returns%0A    ----------%0A    matrix : %60numpy.ndarray%60%0A        The matrix representation of the operator.%0A%0A    Notes%0A    ----------%0A    The algorithm works by letting the operator act on all unit vectors, and%0A    stacking the output as a matrix.%0A%0A    %22%22%22%0A%0A    if not op.is_linear:%0A        print('WARNING: The operator is not linear; cannot produce matrix',%0A              'representation of it.')%0A        return%0A%0A    if not isinstance(op.domain, FnBase) or isinstance(op.domain, ProductSpace):%0A        print('WARNING: The operator domain is not discreate or produc space;',%0A              'cannot produce matrix representation of it.')%0A        return%0A%0A    if not isinstance(op.range, FnBase):%0A        print('WARNING: The operator range is not discreate; cannot produce',%0A              'matrix representation of it.')%0A        return%0A%0A    n = op.range.size%0A    m = op.domain.size%0A%0A    matrix = np.zeros(%5Bn, m%5D)%0A    v = op.domain.element()%0A    tmp = op.range.element()%0A    for i in range(m):%0A        v.set_zero()%0A        v%5Bi%5D = 1.0%0A        matrix%5B:,i%5D = op(v, out=tmp)%0A%0A    return matrix

Add a function for matrix representation.