<commit_before>/*
 * Carrot2 Project
 * Copyright (C) 2002-2004, <NAME>
 * Portions (C) Contributors listed in carrot2.CONTRIBUTORS file.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the CVS checkout or at:
 * http://www.cs.put.poznan.pl/dweiss/carrot2.LICENSE
 */
package com.stachoodev.matrix;

import java.util.*;

import junit.framework.*;
import junitx.framework.*;
import cern.colt.matrix.*;
import cern.colt.matrix.impl.*;
import cern.colt.matrix.linalg.*;

/**
 * @author <NAME>
 * @version $Revision$
 */
public class EigenvalueCalculatorTest extends TestCase
{
    /** The test input matrix */
    private DoubleMatrix2D A = NNIDoubleFactory2D.nni.make(new double [] []
    {
    { 1.00, 7.00, 0.00, 1.00, 0.00 },
    { 4.00, 2.00, 0.00, 0.00, 0.00 },
    { 0.00, 2.00, 3.00, 7.00, 9.00 },
    { 1.00, 5.00, 4.00, 4.00, 3.00 },
    { 0.00, 0.00, 6.00, 3.00, 5.00 } });

    /**
     *  
     */
    public void testSymmetrical()
    {
        DoubleMatrix2D Asym = A.zMult(A, null, 1, 0, true, false);
        double [] expectedEigenvalues = new EigenvalueDecomposition(Asym)
            .getRealEigenvalues().toArray();
        Arrays.sort(expectedEigenvalues);

        double [] eigenvalues = EigenvalueCalculator
            .computeEigenvaluesSymmetricalNNI((DenseDoubleMatrix2D) Asym);
        Arrays.sort(eigenvalues);

        ArrayAssert.assertEquals("Equal real eigenvalues", expectedEigenvalues,
            eigenvalues, 1e-6);
    }

    /**
     *  
     */
    public void testAsymmetrical()
    {
        double [] eigenvalues = EigenvalueCalculator
            .computeEigenvaluesNNI((DenseDoubleMatrix2D) A);
        Arrays.sort(eigenvalues);

        double [] expectedEigenvalues = new EigenvalueDecomposition(A)
            .getRealEigenvalues().toArray();
        Arrays.sort(expectedEigenvalues);

        ArrayAssert.assertEquals("Equal real eigenvalues", expectedEigenvalues,
            eigenvalues, 1e-6);
    }
}<commit_msg>Test case was unconditionally dependent on NNI availability. Made it NNI-safe (one test will _not_ be executed if NNI is not available).<commit_after>/*
 * Carrot2 Project
 * Copyright (C) 2002-2004, <NAME>
 * Portions (C) Contributors listed in carrot2.CONTRIBUTORS file.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the CVS checkout or at:
 * http://www.cs.put.poznan.pl/dweiss/carrot2.LICENSE
 */
package com.stachoodev.matrix;

import java.util.*;

import junit.framework.*;
import junitx.framework.*;
import cern.colt.matrix.*;
import cern.colt.matrix.impl.*;
import cern.colt.matrix.linalg.*;

/**
 * @author <NAME>
 * @version $Revision$
 */
public class EigenvalueCalculatorTest extends TestCase
{
    /** The test input matrix */
    private DoubleMatrix2D A = NNIDoubleFactory2D.nni.make(new double [] []
    {
    { 1.00, 7.00, 0.00, 1.00, 0.00 },
    { 4.00, 2.00, 0.00, 0.00, 0.00 },
    { 0.00, 2.00, 3.00, 7.00, 9.00 },
    { 1.00, 5.00, 4.00, 4.00, 3.00 },
    { 0.00, 0.00, 6.00, 3.00, 5.00 } });

    /**
     *  
     */
    public void testSymmetrical()
    {
        DoubleMatrix2D Asym = A.zMult(A, null, 1, 0, true, false);
        double [] expectedEigenvalues = new EigenvalueDecomposition(Asym)
            .getRealEigenvalues().toArray();
        Arrays.sort(expectedEigenvalues);

        double [] eigenvalues = EigenvalueCalculator
            .computeEigenvaluesSymmetrical((DenseDoubleMatrix2D) Asym);
        Arrays.sort(eigenvalues);

        ArrayAssert.assertEquals("Equal real eigenvalues", expectedEigenvalues,
            eigenvalues, 1e-6);
    }

    /**
     *  
     */
    public void testAsymmetrical()
    {
	    if (NNIInterface.isNativeLapackAvailable()==false) {
		    // IF NNI is not available, skip this test.
		    return;
	    }

        double [] eigenvalues = EigenvalueCalculator
            .computeEigenvaluesNNI((DenseDoubleMatrix2D) A);
        Arrays.sort(eigenvalues);

        double [] expectedEigenvalues = new EigenvalueDecomposition(A)
            .getRealEigenvalues().toArray();
        Arrays.sort(expectedEigenvalues);

        ArrayAssert.assertEquals("Equal real eigenvalues", expectedEigenvalues,
            eigenvalues, 1e-6);
    }
}
{'fraction_non_alphanumeric': 0.13076923076923078, 'fraction_numerical': 0.04568764568764569, 'mean_word_length': 2.7055267702936097, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3408556', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1402, 'n_words': 316}