diff --git a/CMakeLists.txt b/CMakeLists.txt index 9061aec..5e154ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,5 @@ +cmake_minimum_required(VERSION 3.20) + set(LinAlgebra_Sources Linalg.h LUDecomp.cpp @@ -6,18 +8,29 @@ set(LinAlgebra_Sources Mtx.h Range.h Vect.cpp - Vect.h) + Vect.h +) -#set(LinAlgebra_Required_Libs -# debug MSVCRTD.LIB -# debug MSVCPRTD.LIB -# optimized MSVCRT.LIB -# optimized MSVCPRT.LIB) +set(LinAlgebra_Required_Libs +) +if (APPLE) + find_library(ACCELERATE_FRAMEWORK Accelerate) + if (ACCELERATE_FRAMEWORK) + message(STATUS "Accelerate framework found") + add_compile_definitions(LINALG_USE_ACCELERATE ACCELERATE_LAPACK_ILP64=1) + add_compile_options(-DACCELERATE_NEW_LAPACK) + else() + message(WARNING "Accelerate framework not found") + endif() +endif() -add_library(LinAlgebra ${LinAlgebra_Sources}) -# libraries that needs to be linked to the present library -#target_link_libraries(LinAlgebra ${LinAlgebra_Required_Libs}) +find_package(BLAS REQUIRED) +include_directories(${BLAS_INCLUDE_DIRS}) +set(LinAlgebra_Required_Libs ${LinAlgebra_Required_Libs} ${BLAS_LIBRARIES}) +add_library(LinAlgebra ${LinAlgebra_Sources}) +# libraries that needs to be linked to the present library +target_link_libraries(LinAlgebra ${LinAlgebra_Required_Libs}) diff --git a/Linalg.h b/Linalg.h index b3bfdeb..aa0d2aa 100644 --- a/Linalg.h +++ b/Linalg.h @@ -74,6 +74,11 @@ inline void CLin_assert(bool a) { _ASSERT(a); } inline void CLin_assert(bool ) { } #endif +#if defined(LINALG_USE_ACCELERATE) +# include +#else +# include +#endif #endif // LINALG_H diff --git a/Mtx.h b/Mtx.h index b228c87..43caf12 100644 --- a/Mtx.h +++ b/Mtx.h @@ -88,6 +88,9 @@ class CLin_Matrix inline CLin_subscript size() const { return m_iMN; } + inline double *array() { return m_pV; } + + inline const double *array() const { return m_pV; } // returns # of rows or cols according to parameter d (1=rows, 2=cols, other=0) inline CLin_subscript dim(CLin_subscript d) { @@ -365,90 +368,94 @@ inline CLin_Vector matmult(const CLin_Matrix &A, const CLin_Vector &x) #endif CLin_subscript M, N; - CLin_subscript i, j; M = A.num_rows(); N = A.num_cols(); CLin_Vector tmp(M); - double sum; - - for (i=0; i