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.  *      https://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. /*
  18.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */

  21. package org.hipparchus.linear;

  22. import org.hipparchus.exception.MathIllegalArgumentException;

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

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

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

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

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