001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.math4.legacy.linear; 019 020import org.apache.commons.math4.legacy.exception.DimensionMismatchException; 021 022/** 023 * This class defines a linear operator operating on real ({@code double}) 024 * vector spaces. No direct access to the coefficients of the underlying matrix 025 * is provided. 026 * 027 * The motivation for such an interface is well stated by 028 * <a href="#BARR1994">Barrett et al. (1994)</a>: 029 * <blockquote> 030 * We restrict ourselves to iterative methods, which work by repeatedly 031 * improving an approximate solution until it is accurate enough. These 032 * methods access the coefficient matrix A of the linear system only via the 033 * matrix-vector product y = A · x 034 * (and perhaps z = A<sup>T</sup> · x). Thus the user need only 035 * supply a subroutine for computing y (and perhaps z) given x, which permits 036 * full exploitation of the sparsity or other special structure of A. 037 * </blockquote> 038 * <br> 039 * 040 * <dl> 041 * <dt><a id="BARR1994">Barret et al. (1994)</a></dt> 042 * <dd> 043 * R. Barrett, M. Berry, T. F. Chan, J. Demmel, J. M. Donato, J. Dongarra, 044 * V. Eijkhout, R. Pozo, C. Romine and H. Van der Vorst, 045 * <em>Templates for the Solution of Linear Systems: Building Blocks for 046 * Iterative Methods</em>, SIAM 047 * </dd> 048 * </dl> 049 * 050 * @since 3.0 051 */ 052public abstract class RealLinearOperator { 053 /** 054 * Returns the dimension of the codomain of this operator. 055 * 056 * @return the number of rows of the underlying matrix 057 */ 058 public abstract int getRowDimension(); 059 060 /** 061 * Returns the dimension of the domain of this operator. 062 * 063 * @return the number of columns of the underlying matrix 064 */ 065 public abstract int getColumnDimension(); 066 067 /** 068 * Returns the result of multiplying {@code this} by the vector {@code x}. 069 * 070 * @param x the vector to operate on 071 * @return the product of {@code this} instance with {@code x} 072 * @throws DimensionMismatchException if the column dimension does not match 073 * the size of {@code x} 074 */ 075 public abstract RealVector operate(RealVector x) 076 throws DimensionMismatchException; 077 078 /** 079 * Returns the result of multiplying the transpose of {@code this} operator 080 * by the vector {@code x} (optional operation). The default implementation 081 * throws an {@link UnsupportedOperationException}. Users overriding this 082 * method must also override {@link #isTransposable()}. 083 * 084 * @param x the vector to operate on 085 * @return the product of the transpose of {@code this} instance with 086 * {@code x} 087 * @throws org.apache.commons.math4.legacy.exception.DimensionMismatchException 088 * if the row dimension does not match the size of {@code x} 089 * @throws UnsupportedOperationException if this operation is not supported 090 * by {@code this} operator 091 */ 092 public RealVector operateTranspose(final RealVector x) 093 throws DimensionMismatchException, UnsupportedOperationException { 094 throw new UnsupportedOperationException(); 095 } 096 097 /** 098 * Returns {@code true} if this operator supports 099 * {@link #operateTranspose(RealVector)}. If {@code true} is returned, 100 * {@link #operateTranspose(RealVector)} should not throw 101 * {@code UnsupportedOperationException}. The default implementation returns 102 * {@code false}. 103 * 104 * @return {@code false} 105 */ 106 public boolean isTransposable() { 107 return false; 108 } 109}