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 19 import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException; 20 import org.apache.commons.math4.legacy.exception.util.ExceptionContext; 21 import org.apache.commons.math4.legacy.exception.util.LocalizedFormats; 22 23 /** 24 * Exception to be thrown when a positive definite matrix is expected. 25 * 26 * @since 3.0 27 */ 28 public class NonPositiveDefiniteMatrixException extends NumberIsTooSmallException { 29 /** Serializable version Id. */ 30 private static final long serialVersionUID = 1641613838113738061L; 31 /** Index (diagonal element). */ 32 private final int index; 33 /** Threshold. */ 34 private final double threshold; 35 36 /** 37 * Construct an exception. 38 * 39 * @param wrong Value that fails the positivity check. 40 * @param index Row (and column) index. 41 * @param threshold Absolute positivity threshold. 42 */ 43 public NonPositiveDefiniteMatrixException(double wrong, 44 int index, 45 double threshold) { 46 super(wrong, threshold, false); 47 this.index = index; 48 this.threshold = threshold; 49 50 final ExceptionContext context = getContext(); 51 context.addMessage(LocalizedFormats.NOT_POSITIVE_DEFINITE_MATRIX); 52 context.addMessage(LocalizedFormats.ARRAY_ELEMENT, wrong, index); 53 } 54 55 /** 56 * @return the row index. 57 */ 58 public int getRow() { 59 return index; 60 } 61 /** 62 * @return the column index. 63 */ 64 public int getColumn() { 65 return index; 66 } 67 /** 68 * @return the absolute positivity threshold. 69 */ 70 public double getThreshold() { 71 return threshold; 72 } 73 }