Ejemplo n.º 1
0
inline lapack_int sym_eigen_factor(lapack_int n, T a[], T vectors[], lapack_complex_double values[], T d[], SYEV syev)
{
	try
	{
		auto clone_a = array_clone(n * n, a);
		auto w = array_new<R>(n);

		lapack_int info = syev(LAPACK_COL_MAJOR, 'V', 'U', n, clone_a.get(), n, w.get());
		if (info != 0)
		{
			return info;
		}

		memcpy(vectors, clone_a.get(), n*n*sizeof(T));

		for (auto index = 0; index < n; ++index)
		{
			values[index] = lapack_complex_double(w.get()[index]);
		}

		for (auto j = 0; j < n; ++j)
		{
			auto jn = j*n;

			for (auto i = 0; i < n; ++i)
			{
				if (i == j)
				{
					d[jn + i] = w.get()[i];
				}
			}
		}

		return info;
	}
	catch (std::bad_alloc&)
	{
		return INSUFFICIENT_MEMORY;
	}
}
Ejemplo n.º 2
0
inline lapack_int sym_eigen_factor(lapack_int n, T a[], T vectors[], lapack_complex_double values[], T d[], SYEV syev)
{
    T* clone_a = Clone(n, n, a);
    R* w = new R[n];

    lapack_int info = syev(LAPACK_COL_MAJOR, 'V', 'U', n, clone_a, n, w);
    if (info != 0)
    {
        delete[] clone_a;
        delete[] w;
        return info;
    }

    memcpy(vectors, clone_a, n*n*sizeof(T));

    for (lapack_int index = 0; index < n; ++index)
    {
        values[index] = lapack_complex_double(w[index]);
    }

    for (lapack_int j = 0; j < n; ++j)
    {
        lapack_int jn = j*n;

        for (lapack_int i = 0; i < n; ++i)
        {
            if (i == j)
            {
                d[jn + i] = w[i];
            }
        }
    }

    delete[] clone_a;
    delete[] w;
    return info;
}