RealLinearOperator.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.apache.commons.math4.legacy.linear;

  18. import org.apache.commons.math4.legacy.exception.DimensionMismatchException;

  19. /**
  20.  * This class defines a linear operator operating on real ({@code double})
  21.  * vector spaces. No direct access to the coefficients of the underlying matrix
  22.  * is provided.
  23.  *
  24.  * The motivation for such an interface is well stated by
  25.  * <a href="#BARR1994">Barrett et al. (1994)</a>:
  26.  * <blockquote>
  27.  *  We restrict ourselves to iterative methods, which work by repeatedly
  28.  *  improving an approximate solution until it is accurate enough. These
  29.  *  methods access the coefficient matrix A of the linear system only via the
  30.  *  matrix-vector product y = A &middot; x
  31.  *  (and perhaps z = A<sup>T</sup> &middot; x). Thus the user need only
  32.  *  supply a subroutine for computing y (and perhaps z) given x, which permits
  33.  *  full exploitation of the sparsity or other special structure of A.
  34.  * </blockquote>
  35.  * <br>
  36.  *
  37.  * <dl>
  38.  *  <dt><a id="BARR1994">Barret et al. (1994)</a></dt>
  39.  *  <dd>
  40.  *   R. Barrett, M. Berry, T. F. Chan, J. Demmel, J. M. Donato, J. Dongarra,
  41.  *   V. Eijkhout, R. Pozo, C. Romine and H. Van der Vorst,
  42.  *   <em>Templates for the Solution of Linear Systems: Building Blocks for
  43.  *   Iterative Methods</em>, SIAM
  44.  *  </dd>
  45.  * </dl>
  46.  *
  47.  * @since 3.0
  48.  */
  49. public abstract class RealLinearOperator {
  50.     /**
  51.      * Returns the dimension of the codomain of this operator.
  52.      *
  53.      * @return the number of rows of the underlying matrix
  54.      */
  55.     public abstract int getRowDimension();

  56.     /**
  57.      * Returns the dimension of the domain of this operator.
  58.      *
  59.      * @return the number of columns of the underlying matrix
  60.      */
  61.     public abstract int getColumnDimension();

  62.     /**
  63.      * Returns the result of multiplying {@code this} by the vector {@code x}.
  64.      *
  65.      * @param x the vector to operate on
  66.      * @return the product of {@code this} instance with {@code x}
  67.      * @throws DimensionMismatchException if the column dimension does not match
  68.      * the size of {@code x}
  69.      */
  70.     public abstract RealVector operate(RealVector x)
  71.         throws DimensionMismatchException;

  72.     /**
  73.      * Returns the result of multiplying the transpose of {@code this} operator
  74.      * by the vector {@code x} (optional operation). The default implementation
  75.      * throws an {@link UnsupportedOperationException}. Users overriding this
  76.      * method must also override {@link #isTransposable()}.
  77.      *
  78.      * @param x the vector to operate on
  79.      * @return the product of the transpose of {@code this} instance with
  80.      * {@code x}
  81.      * @throws org.apache.commons.math4.legacy.exception.DimensionMismatchException
  82.      * if the row dimension does not match the size of {@code x}
  83.      * @throws UnsupportedOperationException if this operation is not supported
  84.      * by {@code this} operator
  85.      */
  86.     public RealVector operateTranspose(final RealVector x)
  87.         throws DimensionMismatchException, UnsupportedOperationException {
  88.         throw new UnsupportedOperationException();
  89.     }

  90.     /**
  91.      * Returns {@code true} if this operator supports
  92.      * {@link #operateTranspose(RealVector)}. If {@code true} is returned,
  93.      * {@link #operateTranspose(RealVector)} should not throw
  94.      * {@code UnsupportedOperationException}. The default implementation returns
  95.      * {@code false}.
  96.      *
  97.      * @return {@code false}
  98.      */
  99.     public boolean isTransposable() {
  100.         return false;
  101.     }
  102. }