armadillo-6.500.5/0000777000000000000000000000000012656572547012360 5ustar rootrootarmadillo-6.500.5/examples/0000777000000000000000000000000012656572551014171 5ustar rootrootarmadillo-6.500.5/examples/example1.cpp0000666000000000000000000001034112620275316016376 0ustar rootroot#include #include using namespace std; using namespace arma; // Armadillo documentation is available at: // http://arma.sourceforge.net/docs.html int main(int argc, char** argv) { cout << "Armadillo version: " << arma_version::as_string() << endl; mat A(2,3); // directly specify the matrix size (elements are uninitialised) cout << "A.n_rows: " << A.n_rows << endl; // .n_rows and .n_cols are read only cout << "A.n_cols: " << A.n_cols << endl; A(1,2) = 456.0; // directly access an element (indexing starts at 0) A.print("A:"); A = 5.0; // scalars are treated as a 1x1 matrix A.print("A:"); A.set_size(4,5); // change the size (data is not preserved) A.fill(5.0); // set all elements to a particular value A.print("A:"); // endr indicates "end of row" A << 0.165300 << 0.454037 << 0.995795 << 0.124098 << 0.047084 << endr << 0.688782 << 0.036549 << 0.552848 << 0.937664 << 0.866401 << endr << 0.348740 << 0.479388 << 0.506228 << 0.145673 << 0.491547 << endr << 0.148678 << 0.682258 << 0.571154 << 0.874724 << 0.444632 << endr << 0.245726 << 0.595218 << 0.409327 << 0.367827 << 0.385736 << endr; A.print("A:"); // determinant cout << "det(A): " << det(A) << endl; // inverse cout << "inv(A): " << endl << inv(A) << endl; // save matrix as a text file A.save("A.txt", raw_ascii); // load from file mat B; B.load("A.txt"); // submatrices cout << "B( span(0,2), span(3,4) ):" << endl << B( span(0,2), span(3,4) ) << endl; cout << "B( 0,3, size(3,2) ):" << endl << B( 0,3, size(3,2) ) << endl; cout << "B.row(0): " << endl << B.row(0) << endl; cout << "B.col(1): " << endl << B.col(1) << endl; // transpose cout << "B.t(): " << endl << B.t() << endl; // maximum from each column (traverse along rows) cout << "max(B): " << endl << max(B) << endl; // maximum from each row (traverse along columns) cout << "max(B,1): " << endl << max(B,1) << endl; // maximum value in B cout << "max(max(B)) = " << max(max(B)) << endl; // sum of each column (traverse along rows) cout << "sum(B): " << endl << sum(B) << endl; // sum of each row (traverse along columns) cout << "sum(B,1) =" << endl << sum(B,1) << endl; // sum of all elements cout << "accu(B): " << accu(B) << endl; // trace = sum along diagonal cout << "trace(B): " << trace(B) << endl; // generate the identity matrix mat C = eye(4,4); // random matrix with values uniformly distributed in the [0,1] interval mat D = randu(4,4); D.print("D:"); // row vectors are treated like a matrix with one row rowvec r; r << 0.59119 << 0.77321 << 0.60275 << 0.35887 << 0.51683; r.print("r:"); // column vectors are treated like a matrix with one column vec q; q << 0.14333 << 0.59478 << 0.14481 << 0.58558 << 0.60809; q.print("q:"); // convert matrix to vector; data in matrices is stored column-by-column vec v = vectorise(A); v.print("v:"); // dot or inner product cout << "as_scalar(r*q): " << as_scalar(r*q) << endl; // outer product cout << "q*r: " << endl << q*r << endl; // multiply-and-accumulate operation (no temporary matrices are created) cout << "accu(A % B) = " << accu(A % B) << endl; // example of a compound operation B += 2.0 * A.t(); B.print("B:"); // imat specifies an integer matrix imat AA; imat BB; AA << 1 << 2 << 3 << endr << 4 << 5 << 6 << endr << 7 << 8 << 9; BB << 3 << 2 << 1 << endr << 6 << 5 << 4 << endr << 9 << 8 << 7; // comparison of matrices (element-wise); output of a relational operator is a umat umat ZZ = (AA >= BB); ZZ.print("ZZ:"); // cubes ("3D matrices") cube Q( B.n_rows, B.n_cols, 2 ); Q.slice(0) = B; Q.slice(1) = 2.0 * B; Q.print("Q:"); // 2D field of matrices; 3D fields are also supported field F(4,3); for(uword col=0; col < F.n_cols; ++col) for(uword row=0; row < F.n_rows; ++row) { F(row,col) = randu(2,3); // each element in field is a matrix } F.print("F:"); return 0; } armadillo-6.500.5/examples/Makefile0000666000000000000000000000370312620272703015617 0ustar rootroot# You may need to edit this file to reflect the type and capabilities of your system. # The defaults are for a Linux system and may need to be changed for other systems (eg. Mac OS X). CXX=g++ #CXX=CC ## When using the Sun Studio compiler ARMA_INCLUDE_FLAG = -I ../include ## If you've installed Armadillo's headers manually, you may need to tell the compiler where they are. ## For example, change ../include to /usr/local/include LIB_FLAGS = -lblas -llapack #LIB_FLAGS = -lopenblas -llapack #LIB_FLAGS = -framework Accelerate #LIB_FLAGS = -library=sunperf ## NOTE: on Ubuntu and Debian based systems you may need to add -lgfortran to LIB_FLAGS ## NOTE: if you're using Mac OS, use the line with -framework Accelerate ## NOTE: if you're using the Sun Studio compiler, use the line with -library=sunperf OPT = -O2 ## As the Armadillo library uses recursive templates, compilation times depend on the level of optimisation: ## ## -O0: quick compilation, but the resulting program will be slow ## -O1: good trade-off between compilation time and execution speed ## -O2: produces programs which have almost all possible speedups, but compilation takes longer ## -O3: enables auto vectorisation when using gcc #OPT = -xO4 -xannotate=no ## When using the Sun Studio compiler #EXTRA_OPT = -fwhole-program ## Uncomment the above line if you're compiling all source files into one program in a single hit #DEBUG = -DARMA_EXTRA_DEBUG ## Uncomment the above line to enable low-level debugging. ## Lots of debugging information will be printed when a compiled program is run. ## Please enable this option when reporting bugs. #FINAL = -DARMA_NO_DEBUG ## Uncomment the above line to disable Armadillo's checks. ## Not recommended unless your code has been first thoroughly tested! CXXFLAGS = $(ARMA_INCLUDE_FLAG) $(DEBUG) $(FINAL) $(OPT) $(EXTRA_OPT) all: example1 example1: example1.cpp $(CXX) $(CXXFLAGS) -o $@ $< $(LIB_FLAGS) .PHONY: clean clean: rm -f example1 armadillo-6.500.5/examples/Makefile.cmake0000666000000000000000000000324212620272703016674 0ustar rootroot# You may need to edit this file to reflect the type and capabilities of your system. # The defaults are for a Linux system and may need to be changed for other systems (eg. Mac OS X). CXX=g++ #CXX=CC ## When using the Sun Studio compiler # flags configured by CMake ifeq (${ARMA_OS},macos) LIB_FLAGS = -larmadillo -framework Accelerate else LIB_FLAGS = -larmadillo ## NOTE: on Ubuntu and Debian based systems you may need to add -lgfortran #LIB_FLAGS = -larmadillo -library=sunperf ## When using the Sun Studio compiler endif OPT = -O2 ## As the Armadillo library uses recursive templates, compilation times depend on the level of optimisation: ## ## -O0: quick compilation, but the resulting program will be slow ## -O1: good trade-off between compilation time and execution speed ## -O2: produces programs which have almost all possible speedups, but compilation takes longer ## -O3: enables auto vectorisation when using gcc #OPT = -xO4 -xannotate=no ## When using the Sun Studio compiler #EXTRA_OPT = -fwhole-program ## Uncomment the above line if you're compiling all source files into one program in a single hit #DEBUG = -DARMA_EXTRA_DEBUG ## Uncomment the above line to enable low-level debugging. ## Lots of debugging information will be printed when a compiled program is run. ## Please enable this option when reporting bugs. #FINAL = -DARMA_NO_DEBUG ## Uncomment the above line to disable Armadillo's checks. ## Not recommended unless your code has been first thoroughly tested! CXXFLAGS = $(DEBUG) $(FINAL) $(OPT) $(EXTRA_OPT) all: example1 example1: example1.cpp $(CXX) $(CXXFLAGS) -o $@ $< $(LIB_FLAGS) .PHONY: clean clean: rm -f example1 armadillo-6.500.5/cmake_aux/0000777000000000000000000000000012656572547014315 5ustar rootrootarmadillo-6.500.5/cmake_aux/InstallFiles/0000777000000000000000000000000012656572547016706 5ustar rootrootarmadillo-6.500.5/cmake_aux/InstallFiles/ArmadilloConfig.cmake.in0000666000000000000000000000126212620272703023326 0ustar rootroot# - Config file for the Armadillo package # It defines the following variables # ARMADILLO_INCLUDE_DIRS - include directories for Armadillo # ARMADILLO_LIBRARY_DIRS - library directories for Armadillo (normally not used!) # ARMADILLO_LIBRARIES - libraries to link against # Tell the user project where to find our headers and libraries set(ARMADILLO_INCLUDE_DIRS "@ARMADILLO_INCLUDE_DIRS@") set(ARMADILLO_LIBRARY_DIRS "@ARMADILLO_LIB_DIR@") # Our library dependencies (contains definitions for IMPORTED targets) include("@ARMADILLO_CMAKE_DIR@/ArmadilloLibraryDepends.cmake") # These are IMPORTED targets created by ArmadilloLibraryDepends.cmake set(ARMADILLO_LIBRARIES armadillo) armadillo-6.500.5/cmake_aux/InstallFiles/ArmadilloConfigVersion.cmake.in0000666000000000000000000000057512620272703024702 0ustar rootrootset(PACKAGE_VERSION "@ARMADILLO_VERSION@") # Check whether the requested PACKAGE_FIND_VERSION is compatible if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") set(PACKAGE_VERSION_COMPATIBLE FALSE) else() set(PACKAGE_VERSION_COMPATIBLE TRUE) if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") set(PACKAGE_VERSION_EXACT TRUE) endif() endif() armadillo-6.500.5/cmake_aux/Modules/0000777000000000000000000000000012656572547015725 5ustar rootrootarmadillo-6.500.5/cmake_aux/Modules/ARMA_FindACML.cmake0000666000000000000000000000222612620272703021024 0ustar rootroot# - Find AMD's ACML library (no includes) which provides optimised BLAS and LAPACK functions # This module defines # ACML_LIBRARIES, the libraries needed to use ACML. # ACML_FOUND, If false, do not try to use ACML. # also defined, but not for general use are # ACML_LIBRARY, where to find the ACML library. SET(ACML_NAMES ${ACML_NAMES} acml) FIND_LIBRARY(ACML_LIBRARY NAMES ${ACML_NAMES} PATHS /usr/lib64 /usr/lib /usr/*/lib64 /usr/*/lib /usr/*/gfortran64/lib/ /usr/*/gfortran32/lib/ /usr/local/lib64 /usr/local/lib /opt/lib64 /opt/lib /opt/*/lib64 /opt/*/lib /opt/*/gfortran64/lib/ /opt/*/gfortran32/lib/ ) IF (ACML_LIBRARY) SET(ACML_LIBRARIES ${ACML_LIBRARY}) SET(ACML_FOUND "YES") ELSE (ACML_LIBRARY) SET(ACML_FOUND "NO") ENDIF (ACML_LIBRARY) IF (ACML_FOUND) IF (NOT ACML_FIND_QUIETLY) MESSAGE(STATUS "Found ACML: ${ACML_LIBRARIES}") ENDIF (NOT ACML_FIND_QUIETLY) ELSE (ACML_FOUND) IF (ACML_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find ACML") ENDIF (ACML_FIND_REQUIRED) ENDIF (ACML_FOUND) # Deprecated declarations. GET_FILENAME_COMPONENT (NATIVE_ACML_LIB_PATH ${ACML_LIBRARY} PATH) MARK_AS_ADVANCED( ACML_LIBRARY ) armadillo-6.500.5/cmake_aux/Modules/ARMA_FindLAPACK.cmake0000666000000000000000000000203712620272703021243 0ustar rootroot# - Find a LAPACK library (no includes) # This module defines # LAPACK_LIBRARIES, the libraries needed to use LAPACK. # LAPACK_FOUND, If false, do not try to use LAPACK. # also defined, but not for general use are # LAPACK_LIBRARY, where to find the LAPACK library. SET(LAPACK_NAMES ${LAPACK_NAMES} lapack) FIND_LIBRARY(LAPACK_LIBRARY NAMES ${LAPACK_NAMES} PATHS /usr/lib64/atlas /usr/lib/atlas /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib ) IF (LAPACK_LIBRARY) SET(LAPACK_LIBRARIES ${LAPACK_LIBRARY}) SET(LAPACK_FOUND "YES") ELSE (LAPACK_LIBRARY) SET(LAPACK_FOUND "NO") ENDIF (LAPACK_LIBRARY) IF (LAPACK_FOUND) IF (NOT LAPACK_FIND_QUIETLY) MESSAGE(STATUS "Found LAPACK: ${LAPACK_LIBRARIES}") ENDIF (NOT LAPACK_FIND_QUIETLY) ELSE (LAPACK_FOUND) IF (LAPACK_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find LAPACK") ENDIF (LAPACK_FIND_REQUIRED) ENDIF (LAPACK_FOUND) # Deprecated declarations. GET_FILENAME_COMPONENT (NATIVE_LAPACK_LIB_PATH ${LAPACK_LIBRARY} PATH) MARK_AS_ADVANCED( LAPACK_LIBRARY ) armadillo-6.500.5/cmake_aux/Modules/ARMA_FindACMLMP.cmake0000666000000000000000000000236412620272703021264 0ustar rootroot# - Find AMD's ACMLMP library (no includes) which provides optimised and parallelised BLAS and LAPACK functions # This module defines # ACMLMP_LIBRARIES, the libraries needed to use ACMLMP. # ACMLMP_FOUND, If false, do not try to use ACMLMP. # also defined, but not for general use are # ACMLMP_LIBRARY, where to find the ACMLMP library. SET(ACMLMP_NAMES ${ACMLMP_NAMES} acml_mp) FIND_LIBRARY(ACMLMP_LIBRARY NAMES ${ACMLMP_NAMES} PATHS /usr/lib64 /usr/lib /usr/*/lib64 /usr/*/lib /usr/*/gfortran64_mp/lib/ /usr/*/gfortran32_mp/lib/ /usr/local/lib64 /usr/local/lib /opt/lib64 /opt/lib /opt/*/lib64 /opt/*/lib /opt/*/gfortran64_mp/lib/ /opt/*/gfortran32_mp/lib/ ) IF (ACMLMP_LIBRARY) SET(ACMLMP_LIBRARIES ${ACMLMP_LIBRARY}) SET(ACMLMP_FOUND "YES") ELSE (ACMLMP_LIBRARY) SET(ACMLMP_FOUND "NO") ENDIF (ACMLMP_LIBRARY) IF (ACMLMP_FOUND) IF (NOT ACMLMP_FIND_QUIETLY) MESSAGE(STATUS "Found ACMLMP: ${ACMLMP_LIBRARIES}") ENDIF (NOT ACMLMP_FIND_QUIETLY) ELSE (ACMLMP_FOUND) IF (ACMLMP_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find ACMLMP") ENDIF (ACMLMP_FIND_REQUIRED) ENDIF (ACMLMP_FOUND) # Deprecated declarations. GET_FILENAME_COMPONENT (NATIVE_ACMLMP_LIB_PATH ${ACMLMP_LIBRARY} PATH) MARK_AS_ADVANCED( ACMLMP_LIBRARY ) armadillo-6.500.5/cmake_aux/Modules/ARMA_FindATLAS.cmake0000666000000000000000000000312712620272703021155 0ustar rootrootfind_path(ATLAS_CBLAS_INCLUDE_DIR NAMES cblas.h PATHS /usr/include/atlas/ /usr/include/ /usr/local/include/atlas/ /usr/local/include/ ) find_path(ATLAS_CLAPACK_INCLUDE_DIR NAMES clapack.h PATHS /usr/include/atlas/ /usr/include/ /usr/local/include/atlas/ /usr/local/include/ ) if(ATLAS_CBLAS_INCLUDE_DIR AND ATLAS_CLAPACK_INCLUDE_DIR) if(ATLAS_CBLAS_INCLUDE_DIR STREQUAL ATLAS_CLAPACK_INCLUDE_DIR) set(ATLAS_INCLUDE_DIR ${ATLAS_CBLAS_INCLUDE_DIR}) endif() endif() set(ATLAS_NAMES) set(ATLAS_NAMES ${ATLAS_NAMES} tatlas) set(ATLAS_NAMES ${ATLAS_NAMES} satlas) set(ATLAS_NAMES ${ATLAS_NAMES} atlas ) set(ATLAS_TMP_LIBRARY) set(ATLAS_TMP_LIBRARIES) foreach (ATLAS_NAME ${ATLAS_NAMES}) find_library(${ATLAS_NAME}_LIBRARY NAMES ${ATLAS_NAME} PATHS ${CMAKE_SYSTEM_LIBRARY_PATH} /usr/lib64/atlas /usr/lib64/ /usr/local/lib64/atlas /usr/local/lib64 /usr/lib/atlas /usr/lib /usr/local/lib/atlas /usr/local/lib ) set(ATLAS_TMP_LIBRARY ${${ATLAS_NAME}_LIBRARY}) if(ATLAS_TMP_LIBRARY) set(ATLAS_TMP_LIBRARIES ${ATLAS_TMP_LIBRARIES} ${ATLAS_TMP_LIBRARY}) endif() endforeach() # use only one library if(ATLAS_TMP_LIBRARIES) list(GET ATLAS_TMP_LIBRARIES 0 ATLAS_LIBRARY) endif() if(ATLAS_LIBRARY AND ATLAS_INCLUDE_DIR) set(ATLAS_LIBRARIES ${ATLAS_LIBRARY}) set(ATLAS_FOUND "YES") else() set(ATLAS_FOUND "NO") endif() if(ATLAS_FOUND) if(NOT ATLAS_FIND_QUIETLY) message(STATUS "Found ATLAS: ${ATLAS_LIBRARIES}") endif() else() if(ATLAS_FIND_REQUIRED) message(FATAL_ERROR "Could not find ATLAS") endif() endif() # mark_as_advanced(ATLAS_LIBRARY ATLAS_INCLUDE_DIR) armadillo-6.500.5/cmake_aux/Modules/ARMA_FindOpenBLAS.cmake0000666000000000000000000000224312642372714021661 0ustar rootrootset(OpenBLAS_NAMES) set(OpenBLAS_NAMES ${OpenBLAS_NAMES} openblaso) set(OpenBLAS_NAMES ${OpenBLAS_NAMES} openblasp) set(OpenBLAS_NAMES ${OpenBLAS_NAMES} openblas ) set(OpenBLAS_TMP_LIBRARY) set(OpenBLAS_TMP_LIBRARIES) foreach (OpenBLAS_NAME ${OpenBLAS_NAMES}) find_library(${OpenBLAS_NAME}_LIBRARY NAMES ${OpenBLAS_NAME} PATHS ${CMAKE_SYSTEM_LIBRARY_PATH} /lib64 /lib /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /opt/local/lib64 /opt/local/lib ) set(OpenBLAS_TMP_LIBRARY ${${OpenBLAS_NAME}_LIBRARY}) if(OpenBLAS_TMP_LIBRARY) set(OpenBLAS_TMP_LIBRARIES ${OpenBLAS_TMP_LIBRARIES} ${OpenBLAS_TMP_LIBRARY}) endif() endforeach() # use only one library if(OpenBLAS_TMP_LIBRARIES) list(GET OpenBLAS_TMP_LIBRARIES 0 OpenBLAS_LIBRARY) endif() if(OpenBLAS_LIBRARY) set(OpenBLAS_LIBRARIES ${OpenBLAS_LIBRARY}) set(OpenBLAS_FOUND "YES") else() set(OpenBLAS_FOUND "NO") endif() if(OpenBLAS_FOUND) if (NOT OpenBLAS_FIND_QUIETLY) message(STATUS "Found OpenBLAS: ${OpenBLAS_LIBRARIES}") endif() else() if(OpenBLAS_FIND_REQUIRED) message(FATAL_ERROR "Could not find OpenBLAS") endif() endif() # mark_as_advanced(OpenBLAS_LIBRARY) armadillo-6.500.5/cmake_aux/Modules/ARMA_FindMKL.cmake0000666000000000000000000000727312620272703020742 0ustar rootroot# - Find the MKL libraries (no includes) # This module defines # MKL_LIBRARIES, the libraries needed to use Intel's implementation of BLAS & LAPACK. # MKL_FOUND, If false, do not try to use MKL. ## the link below explains why we're linking only with mkl_rt ## https://software.intel.com/en-us/articles/a-new-linking-model-single-dynamic-library-mkl_rt-since-intel-mkl-103 set(MKL_NAMES ${MKL_NAMES} mkl_rt) #set(MKL_NAMES ${MKL_NAMES} mkl_lapack) #set(MKL_NAMES ${MKL_NAMES} mkl_intel_thread) #set(MKL_NAMES ${MKL_NAMES} mkl_core) #set(MKL_NAMES ${MKL_NAMES} guide) #set(MKL_NAMES ${MKL_NAMES} mkl) #set(MKL_NAMES ${MKL_NAMES} iomp5) #set(MKL_NAMES ${MKL_NAMES} pthread) if(CMAKE_SIZEOF_VOID_P EQUAL 8) #set(MKL_NAMES ${MKL_NAMES} mkl_intel_lp64) set(MKL_ARCH intel64) else() #set(MKL_NAMES ${MKL_NAMES} mkl_intel) set(MKL_ARCH ia32) endif() set(MKL_ROOT $ENV{MKLROOT} CACHE TYPE STRING) if(NOT MKL_ROOT) set(MKL_ROOT "/opt/intel/mkl") endif() foreach (MKL_NAME ${MKL_NAMES}) find_library(${MKL_NAME}_LIBRARY NAMES ${MKL_NAME} PATHS ${CMAKE_SYSTEM_LIBRARY_PATH} ${MKL_ROOT}/lib/${MKL_ARCH} /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /opt/intel/composerxe/lib/intel64 /opt/intel/composerxe/lib/ia32 /opt/intel/composerxe/lib/mkl/lib/intel64 /opt/intel/composerxe/lib/mkl/lib/ia32 /usr/local/intel/composerxe/lib/intel64 /usr/local/intel/composerxe/lib/ia32 /usr/local/intel/composerxe/lib/mkl/lib/intel64 /usr/local/intel/composerxe/lib/mkl/lib/ia32 /opt/intel/lib /opt/intel/lib/intel64 /opt/intel/lib/em64t /opt/intel/lib/lib64 /opt/intel/lib/ia32 /opt/intel/mkl/lib /opt/intel/mkl/lib/intel64 /opt/intel/mkl/lib/em64t /opt/intel/mkl/lib/lib64 /opt/intel/mkl/lib/ia32 /opt/intel/mkl/*/lib /opt/intel/mkl/*/lib/intel64 /opt/intel/mkl/*/lib/em64t /opt/intel/mkl/*/lib/lib64 /opt/intel/mkl/*/lib/32 /opt/intel/*/mkl/lib /opt/intel/*/mkl/lib/intel64 /opt/intel/*/mkl/lib/em64t /opt/intel/*/mkl/lib/lib64 /opt/intel/*/mkl/lib/ia32 /opt/mkl/lib /opt/mkl/lib/intel64 /opt/mkl/lib/em64t /opt/mkl/lib/lib64 /opt/mkl/lib/ia32 /opt/mkl/*/lib /opt/mkl/*/lib/intel64 /opt/mkl/*/lib/em64t /opt/mkl/*/lib/lib64 /opt/mkl/*/lib/32 /usr/local/intel/lib /usr/local/intel/lib/intel64 /usr/local/intel/lib/em64t /usr/local/intel/lib/lib64 /usr/local/intel/lib/ia32 /usr/local/intel/mkl/lib /usr/local/intel/mkl/lib/intel64 /usr/local/intel/mkl/lib/em64t /usr/local/intel/mkl/lib/lib64 /usr/local/intel/mkl/lib/ia32 /usr/local/intel/mkl/*/lib /usr/local/intel/mkl/*/lib/intel64 /usr/local/intel/mkl/*/lib/em64t /usr/local/intel/mkl/*/lib/lib64 /usr/local/intel/mkl/*/lib/32 /usr/local/intel/*/mkl/lib /usr/local/intel/*/mkl/lib/intel64 /usr/local/intel/*/mkl/lib/em64t /usr/local/intel/*/mkl/lib/lib64 /usr/local/intel/*/mkl/lib/ia32 /usr/local/mkl/lib /usr/local/mkl/lib/intel64 /usr/local/mkl/lib/em64t /usr/local/mkl/lib/lib64 /usr/local/mkl/lib/ia32 /usr/local/mkl/*/lib /usr/local/mkl/*/lib/intel64 /usr/local/mkl/*/lib/em64t /usr/local/mkl/*/lib/lib64 /usr/local/mkl/*/lib/32 ) set(TMP_LIBRARY ${${MKL_NAME}_LIBRARY}) if(TMP_LIBRARY) set(MKL_LIBRARIES ${MKL_LIBRARIES} ${TMP_LIBRARY}) endif() endforeach() if(MKL_LIBRARIES) set(MKL_FOUND "YES") else() set(MKL_FOUND "NO") endif() if(MKL_FOUND) if(NOT MKL_FIND_QUIETLY) message(STATUS "Found MKL libraries: ${MKL_LIBRARIES}") endif() else() if(MKL_FIND_REQUIRED) message(FATAL_ERROR "Could not find MKL libraries") endif() endif() # mark_as_advanced(MKL_LIBRARY) armadillo-6.500.5/cmake_aux/Modules/ARMA_FindBLAS.cmake0000666000000000000000000000173712620272703021037 0ustar rootroot# - Find a BLAS library (no includes) # This module defines # BLAS_LIBRARIES, the libraries needed to use BLAS. # BLAS_FOUND, If false, do not try to use BLAS. # also defined, but not for general use are # BLAS_LIBRARY, where to find the BLAS library. SET(BLAS_NAMES ${BLAS_NAMES} blas) FIND_LIBRARY(BLAS_LIBRARY NAMES ${BLAS_NAMES} PATHS /usr/lib64/atlas /usr/lib/atlas /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib ) IF (BLAS_LIBRARY) SET(BLAS_LIBRARIES ${BLAS_LIBRARY}) SET(BLAS_FOUND "YES") ELSE (BLAS_LIBRARY) SET(BLAS_FOUND "NO") ENDIF (BLAS_LIBRARY) IF (BLAS_FOUND) IF (NOT BLAS_FIND_QUIETLY) MESSAGE(STATUS "Found BLAS: ${BLAS_LIBRARIES}") ENDIF (NOT BLAS_FIND_QUIETLY) ELSE (BLAS_FOUND) IF (BLAS_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find BLAS") ENDIF (BLAS_FIND_REQUIRED) ENDIF (BLAS_FOUND) # Deprecated declarations. GET_FILENAME_COMPONENT (NATIVE_BLAS_LIB_PATH ${BLAS_LIBRARY} PATH) MARK_AS_ADVANCED( BLAS_LIBRARY ) armadillo-6.500.5/cmake_aux/Modules/ARMA_FindARPACK.cmake0000666000000000000000000000132112642372714021253 0ustar rootroot# - Try to find ARPACK # Once done this will define # # ARPACK_FOUND - system has ARPACK # ARPACK_LIBRARY - Link this to use ARPACK find_library(ARPACK_LIBRARY NAMES arpack PATHS ${CMAKE_SYSTEM_LIBRARY_PATH} /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /opt/local/lib64 /opt/local/lib ) IF (ARPACK_LIBRARY) SET(ARPACK_FOUND YES) ELSE () SET(ARPACK_FOUND NO) ENDIF () IF (ARPACK_FOUND) IF (NOT ARPACK_FIND_QUIETLY) MESSAGE(STATUS "Found ARPACK: ${ARPACK_LIBRARY}") ENDIF (NOT ARPACK_FIND_QUIETLY) ELSE (ARPACK_FOUND) IF (ARPACK_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find ARPACK") ENDIF (ARPACK_FIND_REQUIRED) ENDIF (ARPACK_FOUND) armadillo-6.500.5/cmake_aux/Modules/ARMA_FindSuperLU.cmake0000666000000000000000000000334612642372714021662 0ustar rootroot# Try to find SuperLU 4.x # Once done, this will define # # SuperLU_FOUND - system has SuperLU # SuperLU_LIBRARY - Link this to use SuperLU # SuperLU_INCLUDE_DIR - directory of SuperLU headers find_path(SuperLU_INCLUDE_DIR slu_cdefs.h /usr/include/superlu/ /usr/include/SuperLU/ /usr/include/ /usr/local/include/superlu/ /usr/local/include/SuperLU/ /usr/local/include/ /opt/local/include/superlu/ /opt/local/include/SuperLU/ /opt/local/include/ ) find_library(SuperLU_LIBRARY NAMES superlu PATHS ${CMAKE_SYSTEM_LIBRARY_PATH} /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/lib /opt/local/lib64 /opt/local/lib ) SET(SuperLU_FOUND NO) IF (SuperLU_LIBRARY AND SuperLU_INCLUDE_DIR) # Now determine if the version is version 4. IF (EXISTS "${SuperLU_INCLUDE_DIR}/slu_cdefs.h") FILE(READ "${SuperLU_INCLUDE_DIR}/slu_cdefs.h" _slu_HEADER_CONTENTS) STRING(REGEX REPLACE ".*version ([0-9]).*" "\\1" SLU_VERSION_MAJOR "${_slu_HEADER_CONTENTS}") IF ("${SLU_VERSION_MAJOR}" EQUAL "4") SET(SuperLU_FOUND YES) ELSE () IF (NOT SuperLU_FIND_QUIETLY) MESSAGE(STATUS "Found SuperLU version ${SLU_VERSION_MAJOR}, but version 4 is required") ENDIF () ENDIF () ELSE () IF (NOT SuperLU_FIND_QUIETLY) MESSAGE(STATUS "Found SuperLU and headers, but could not verify version 4") ENDIF () ENDIF () ENDIF() IF (SuperLU_LIBRARY AND NOT SuperLU_INCLUDE_DIR) IF (NOT SuperLU_FIND_QUIETLY) MESSAGE(STATUS "Incomplete installation of SuperLU: no SuperLU headers found") ENDIF() ENDIF() IF(NOT SuperLU_FOUND) IF (NOT SuperLU_FIND_QUIETLY) MESSAGE(STATUS "Could not find SuperLU") ENDIF() ELSE() MESSAGE(STATUS "Found SuperLU: ${SuperLU_LIBRARY}") ENDIF() armadillo-6.500.5/CMakeLists.txt0000666000000000000000000004137712656373513015124 0ustar rootroot # Copyright (C) 2008-2015 National ICT Australia (NICTA) # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # ------------------------------------------------------------------- # # Written by Conrad Sanderson - http://conradsanderson.id.au # Written by Ryan Curtin # Written by Clement Creusot cmake_minimum_required(VERSION 2.8 FATAL_ERROR) set(ARMA_MAJOR 6) set(ARMA_MINOR 500) set(ARMA_PATCH 5) set(ARMADILLO_VERSION ${ARMA_MAJOR}.${ARMA_MINOR}.${ARMA_PATCH}) message(STATUS "Configuring Armadillo ${ARMADILLO_VERSION}") ## Set ARMA_USE_WRAPPER to false if you're getting linking errors when compiling your programs, ## or if you prefer to directly link with BLAS and/or LAPACK. ## You will then need to link your programs with -lblas -llapack instead of -larmadillo ## If you're using OpenBLAS, link your programs with -lopenblas -llapack instead of -larmadillo set(ARMA_USE_WRAPPER true) # the settings below will be automatically configured by the rest of this script set(ARMA_USE_LAPACK false) set(ARMA_USE_BLAS false) set(ARMA_USE_ATLAS false) set(ARMA_USE_HDF5_ALT false) set(ARMA_USE_ARPACK false) set(ARMA_USE_EXTERN_CXX11_RNG false) set(ARMA_USE_SUPERLU false) # Caveat: only SuperLU version 4.3 can be used! project(armadillo CXX) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake_aux/Modules/") include(CheckIncludeFileCXX) include(CheckLibraryExists) option(BUILD_SHARED_LIBS "build shared library" ON) option(DETECT_HDF5 "Detect HDF5 and include HDF5 support, if found" OFF) message(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}" ) message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}" ) message(STATUS "CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}") message(STATUS "CMAKE_COMPILER_IS_GNUCXX = ${CMAKE_COMPILER_IS_GNUCXX}" ) if(WIN32) message(STATUS "") message(STATUS "WARNING:") message(STATUS "Automatic installation is currently not available for this platform.") message(STATUS "Please use the manual installation, as described in the README.txt file.") message(STATUS "You can also use the 'include' folder directly, but you may want to edit") message(STATUS "'include/armadillo_bits/config.hpp' if you have LAPACK installed.") message(STATUS "") endif() ## ## Find LAPACK and BLAS libraries, or their optimised versions ## if(APPLE) set(ARMA_OS macos) set(ARMA_USE_LAPACK true) set(ARMA_USE_BLAS true) set(ARMA_LIBS ${ARMA_LIBS} "-framework Accelerate") # or "-framework accelerate" ? message(STATUS "MacOS X detected. Added '-framework Accelerate' to compiler flags") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") message(STATUS "Clang compiler on MacOS X detected. Added '-stdlib=libc++' to compiler flags") endif() else() set(ARMA_OS unix) include(ARMA_FindMKL) include(ARMA_FindACMLMP) include(ARMA_FindACML) include(ARMA_FindOpenBLAS) include(ARMA_FindATLAS) include(ARMA_FindBLAS) include(ARMA_FindLAPACK) message(STATUS " MKL_FOUND = ${MKL_FOUND}" ) message(STATUS " ACMLMP_FOUND = ${ACMLMP_FOUND}" ) message(STATUS " ACML_FOUND = ${ACML_FOUND}" ) message(STATUS "OpenBLAS_FOUND = ${OpenBLAS_FOUND}") message(STATUS " ATLAS_FOUND = ${ATLAS_FOUND}" ) message(STATUS " BLAS_FOUND = ${BLAS_FOUND}" ) message(STATUS " LAPACK_FOUND = ${LAPACK_FOUND}" ) if(MKL_FOUND OR ACMLMP_FOUND OR ACML_FOUND) set(ARMA_USE_LAPACK true) set(ARMA_USE_BLAS true) message(STATUS "") message(STATUS "*** If the MKL or ACML libraries are installed in non-standard locations such as") message(STATUS "*** /opt/intel/mkl, /opt/intel/composerxe/, /usr/local/intel/mkl") message(STATUS "*** make sure the run-time linker can find them.") message(STATUS "*** On Linux systems this can be done by editing /etc/ld.so.conf") message(STATUS "*** or modifying the LD_LIBRARY_PATH environment variable.") message(STATUS "") message(STATUS "*** On systems with SELinux enabled (eg. Fedora, RHEL),") message(STATUS "*** you may need to change the SELinux type of all MKL/ACML libraries") message(STATUS "*** to fix permission problems that may occur during run-time.") message(STATUS "*** See README.txt for more information") message(STATUS "") if(MKL_FOUND) set(ARMA_LIBS ${ARMA_LIBS} ${MKL_LIBRARIES}) if(ACMLMP_FOUND OR ACML_FOUND) message(STATUS "*** Intel MKL as well as AMD ACML libraries were found.") message(STATUS "*** Using only the MKL library to avoid linking conflicts.") message(STATUS "*** If you wish to use ACML instead, please link manually with") message(STATUS "*** acml or acml_mp instead of the armadillo wrapper library.") message(STATUS "*** Alternatively, remove MKL from your system and rerun") message(STATUS "*** Armadillo's configuration using ./configure") endif() else() if(ACMLMP_FOUND) set(ARMA_LIBS ${ARMA_LIBS} ${ACMLMP_LIBRARIES}) message(STATUS "*** Both single-core and multi-core ACML libraries were found.") message(STATUS "*** Using only the multi-core library to avoid linking conflicts.") else() if(ACML_FOUND) set(ARMA_LIBS ${ARMA_LIBS} ${ACML_LIBRARIES}) endif() endif() endif() else() if(OpenBLAS_FOUND AND ATLAS_FOUND) message(STATUS "") message(STATUS "*** WARNING: found both OpenBLAS and ATLAS; ATLAS will not be used") endif() if(OpenBLAS_FOUND AND BLAS_FOUND) message(STATUS "") message(STATUS "*** WARNING: found both OpenBLAS and BLAS; BLAS will not be used") endif() if(OpenBLAS_FOUND) set(ARMA_USE_BLAS true) set(ARMA_LIBS ${ARMA_LIBS} ${OpenBLAS_LIBRARIES}) message(STATUS "") message(STATUS "*** If the OpenBLAS library is installed in") message(STATUS "*** /usr/local/lib or /usr/local/lib64") message(STATUS "*** make sure the run-time linker can find it.") message(STATUS "*** On Linux systems this can be done by editing /etc/ld.so.conf") message(STATUS "*** or modifying the LD_LIBRARY_PATH environment variable.") message(STATUS "") else() if(ATLAS_FOUND) set(ARMA_USE_ATLAS true) set(ARMA_ATLAS_INCLUDE_DIR ${ATLAS_INCLUDE_DIR}) set(ARMA_LIBS ${ARMA_LIBS} ${ATLAS_LIBRARIES}) message(STATUS "ATLAS_INCLUDE_DIR = ${ATLAS_INCLUDE_DIR}") endif() if(BLAS_FOUND) set(ARMA_USE_BLAS true) set(ARMA_LIBS ${ARMA_LIBS} ${BLAS_LIBRARIES}) endif() endif() if(LAPACK_FOUND) set(ARMA_USE_LAPACK true) set(ARMA_LIBS ${ARMA_LIBS} ${LAPACK_LIBRARIES}) endif() endif() endif() # set(DETECT_HDF5 true) ## uncomment the above line to enable the detection of the HDF5 library; ## you can also enable HDF5 detection directly on the command line: ## cmake -D DETECT_HDF5=true . if(DETECT_HDF5) find_package(HDF5 QUIET) if(NOT HDF5_FOUND) # On Debian systems, the HDF5 package has been split into multiple packages # so that it is co-installable. But this may mean that the include files # are hidden somewhere very odd that the FindHDF5.cmake script will not # find. Thus, we'll also quickly check pkgconfig to see if there is # information on what to use there. find_package(PkgConfig) if (PKG_CONFIG_FOUND) pkg_check_modules(HDF5 hdf5) # But using pkgconfig is a little weird because HDF5_LIBRARIES won't be # filled with exact library paths, like the other scripts. So instead # what we get is HDF5_LIBRARY_DIRS which is the equivalent of what we'd # pass to -L. So we have to add those... if (HDF5_FOUND) link_directories("${HDF5_LIBRARY_DIRS}") endif() endif() endif() message(STATUS "HDF5_FOUND = ${HDF5_FOUND}") if(HDF5_FOUND) set(ARMA_USE_HDF5_ALT true) set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${HDF5_INCLUDE_DIRS}) set(ARMA_LIBS ${ARMA_LIBS} ${HDF5_LIBRARIES}) # Since we called HDF5 with no arguments, the script will find only the C # bindings. So HDF5_INCLUDE_DIRS may now contain one or two elements; if it # contains two, the first is what the user passed as HDF5_INCLUDE_DIR and we # should use that as ARMA_HDF5_INCLUDE_DIR. Otherwise, the one entry in # HDF5_INCLUDE_DIRS is the correct include directory. So, in either case we # can use the first element in the list. Issue a status message, too, just # for good measure. list(GET HDF5_INCLUDE_DIRS 0 ARMA_HDF5_INCLUDE_DIR) message(STATUS "Set ARMA_HDF5_INCLUDE_DIR to ${ARMA_HDF5_INCLUDE_DIR}") endif() endif() include(ARMA_FindARPACK) message(STATUS "ARPACK_FOUND = ${ARPACK_FOUND}") if(ARPACK_FOUND) set(ARMA_USE_ARPACK true) set(ARMA_LIBS ${ARMA_LIBS} ${ARPACK_LIBRARY}) endif() include(ARMA_FindSuperLU) message(STATUS "SuperLU_FOUND = ${SuperLU_FOUND}") if(SuperLU_FOUND) message(STATUS "SuperLU_INCLUDE_DIR = ${SuperLU_INCLUDE_DIR}") set(ARMA_USE_SUPERLU true) set(ARMA_LIBS ${ARMA_LIBS} ${SuperLU_LIBRARY}) set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${SuperLU_INCLUDE_DIR}) set(ARMA_SUPERLU_INCLUDE_DIR ${SuperLU_INCLUDE_DIR}) endif() message(STATUS "") message(STATUS "*** Armadillo wrapper library will use the following libraries:") message(STATUS "*** ARMA_LIBS = ${ARMA_LIBS}") message(STATUS "") if(DEFINED CMAKE_CXX_COMPILER_ID AND DEFINED CMAKE_CXX_COMPILER_VERSION) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.8.3) set(ARMA_USE_EXTERN_CXX11_RNG true) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") message(STATUS "Detected gcc 4.8.3 or later. Added '-std=c++11' to compiler flags") endif() endif() message(STATUS "Copying ${PROJECT_SOURCE_DIR}/include/ to ${PROJECT_BINARY_DIR}/tmp/include/") file(COPY ${PROJECT_SOURCE_DIR}/include/ DESTINATION ${PROJECT_BINARY_DIR}/tmp/include/) message(STATUS "Generating ${PROJECT_BINARY_DIR}/tmp/include/config.hpp") configure_file(${PROJECT_BINARY_DIR}/tmp/include/armadillo_bits/config.hpp.cmake ${PROJECT_BINARY_DIR}/tmp/include/armadillo_bits/config.hpp) message(STATUS "Generating ${PROJECT_SOURCE_DIR}/examples/Makefile") configure_file(${PROJECT_SOURCE_DIR}/examples/Makefile.cmake ${PROJECT_SOURCE_DIR}/examples/Makefile) include_directories(${PROJECT_BINARY_DIR}/tmp/include/ ${CMAKE_REQUIRED_INCLUDES}) ## work around a silly limitation in Mac OS X if(APPLE) if(${ARMA_MINOR} GREATER 99) math(EXPR ARMA_MINOR_ALT "${ARMA_MINOR} / 10") else() set(ARMA_MINOR_ALT ${ARMA_MINOR}) endif() else() set(ARMA_MINOR_ALT ${ARMA_MINOR}) endif() ## necessary when linking with Intel MKL on Linux systems if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed") endif() if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") endif() message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}" ) message(STATUS "CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}") message(STATUS "CMAKE_REQUIRED_INCLUDES = ${CMAKE_REQUIRED_INCLUDES}" ) add_library( armadillo ${PROJECT_SOURCE_DIR}/src/wrapper.cpp ) target_link_libraries( armadillo ${ARMA_LIBS} ) set_target_properties(armadillo PROPERTIES VERSION ${ARMA_MAJOR}.${ARMA_MINOR_ALT}.${ARMA_PATCH} SOVERSION ${ARMA_MAJOR}) ################################################################################ # INSTALL CONFIGURATION # As Red Hat Enterprise Linux (and related systems such as Fedora) # does not search /usr/local/lib by default, we need to place the # library in either /usr/lib or /usr/lib64 if(NOT APPLE) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) message(STATUS "*** CMAKE_INSTALL_PREFIX was initalised by cmake to the default value of ${CMAKE_INSTALL_PREFIX}") message(STATUS "*** CMAKE_INSTALL_PREFIX changed to /usr") unset(CMAKE_INSTALL_PREFIX) set(CMAKE_INSTALL_PREFIX "/usr") #set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "install prefix" FORCE) endif() endif() # Allow for the "lib" directory to be specified on the command line if(NOT INSTALL_LIB_DIR) set(INSTALL_LIB_DIR "lib") if(UNIX AND NOT APPLE) # I don't know how Mac OS handles 64 bit systems if(CMAKE_SIZEOF_VOID_P EQUAL 8) message(STATUS "*** Detected 64 bit system") # use "lib64" only on systems that have it (eg. Fedora, Red Hat). # if installing in /usr/local/, the use of lib64 might be unreliable on systems which have /usr/local/lib64 but don't use it if(IS_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib64") unset(INSTALL_LIB_DIR) set(INSTALL_LIB_DIR "lib64") message(STATUS "*** ${CMAKE_INSTALL_PREFIX}/lib64/ exists, so destination directory for the run-time library changed to ${CMAKE_INSTALL_PREFIX}/lib64/") message(STATUS "*** Your system and/or compiler must search ${CMAKE_INSTALL_PREFIX}/lib64/ during linking") endif() endif() endif() endif() # Allow for the "include" directory to be specified on the command line if(NOT INSTALL_INCLUDE_DIR) set(INSTALL_INCLUDE_DIR "include") endif() # We use data dir to store files shared with other programs # like the ArmadilloConfig.cmake file. if(NOT INSTALL_DATA_DIR) set(INSTALL_DATA_DIR "share") endif() # executables destination if(NOT INSTALL_BIN_DIR) set(INSTALL_BIN_DIR "bin") endif() # Make relative paths absolute so we can write them in Config.cmake files foreach(p LIB INCLUDE DATA BIN) set(var INSTALL_${p}_DIR) if(NOT IS_ABSOLUTE "${${var}}") set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") endif() endforeach() message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") message(STATUS "INSTALL_LIB_DIR = ${INSTALL_LIB_DIR}" ) message(STATUS "INSTALL_INCLUDE_DIR = ${INSTALL_INCLUDE_DIR}" ) message(STATUS "INSTALL_DATA_DIR = ${INSTALL_DATA_DIR}" ) message(STATUS "INSTALL_BIN_DIR = ${INSTALL_BIN_DIR}" ) # Note that the trailing / character in "include/" is critical install(DIRECTORY ${PROJECT_BINARY_DIR}/tmp/include/ DESTINATION ${INSTALL_INCLUDE_DIR} PATTERN ".svn" EXCLUDE PATTERN "*.cmake" EXCLUDE PATTERN "*~" EXCLUDE PATTERN "*orig" EXCLUDE ) install(TARGETS armadillo EXPORT ArmadilloLibraryDepends ARCHIVE DESTINATION ${INSTALL_LIB_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} RUNTIME DESTINATION ${INSTALL_BIN_DIR}) # Export the package for use from the build-tree # (this registers the build-tree with a global CMake-registry) export(PACKAGE armadillo) ## LOCAL FILES # Create ArmadilloConfig.cmake file for the use from the build tree set(ARMADILLO_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}") set(ARMADILLO_LIB_DIR "${PROJECT_BINARY_DIR}") set(ARMADILLO_CMAKE_DIR "${PROJECT_BINARY_DIR}") message(STATUS "Generating '${PROJECT_BINARY_DIR}/ArmadilloConfig.cmake'") # copy/change config and configVersion file (modify only the @xyz@ variables) configure_file(${PROJECT_SOURCE_DIR}/cmake_aux/InstallFiles/ArmadilloConfig.cmake.in "${PROJECT_BINARY_DIR}/ArmadilloConfig.cmake" @ONLY) message(STATUS "Generating '${PROJECT_BINARY_DIR}/ArmadilloConfigVersion.cmake'") configure_file(${PROJECT_SOURCE_DIR}/cmake_aux/InstallFiles/ArmadilloConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/ArmadilloConfigVersion.cmake" @ONLY) # Install the export set for use with the install-tree install(EXPORT ArmadilloLibraryDepends DESTINATION "${INSTALL_DATA_DIR}/Armadillo/CMake" COMPONENT dev) ## GLOBAL INSTALL FILES # Create ArmadilloConfig.cmake file for the use from the install tree # and install it set(ARMADILLO_INCLUDE_DIRS "${INSTALL_INCLUDE_DIR}") set(ARMADILLO_LIB_DIR "${INSTALL_LIB_DIR}") set(ARMADILLO_CMAKE_DIR "${INSTALL_DATA_DIR}/Armadillo/CMake") message(STATUS "Generating '${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfig.cmake'") # copy/change config and configVersion file (modify only the @xyz@ variables) configure_file(${PROJECT_SOURCE_DIR}/cmake_aux/InstallFiles/ArmadilloConfig.cmake.in "${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfig.cmake" @ONLY) message(STATUS "Generating '${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfigVersion.cmake'") configure_file(${PROJECT_SOURCE_DIR}/cmake_aux/InstallFiles/ArmadilloConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfigVersion.cmake" @ONLY) # Install files to be found by cmake users with find_package() install(FILES "${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfig.cmake" "${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfigVersion.cmake" DESTINATION "${ARMADILLO_CMAKE_DIR}" COMPONENT dev) armadillo-6.500.5/misc/0000777000000000000000000000000012656572547013313 5ustar rootrootarmadillo-6.500.5/misc/armadillo.spec0000666000000000000000000000524612620272703016120 0ustar rootrootName: armadillo Version: 5.000.1 Release: 1%{?dist} Summary: Fast C++ matrix library with interfaces to LAPACK and ATLAS Group: Development/Libraries License: MPLv2.0 URL: http://arma.sourceforge.net/ Source: http://sourceforge.net/projects/arma/files/%{name}-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: cmake, blas-devel, lapack-devel, atlas-devel, arpack-devel, hdf5-devel, libstdc++-devel, SuperLU-devel %description Armadillo is a C++ linear algebra library (matrix maths) aiming towards a good balance between speed and ease of use. Integer, floating point and complex numbers are supported, as well as a subset of trigonometric and statistics functions. Various matrix decompositions are provided through optional integration with LAPACK and ATLAS libraries. A delayed evaluation approach is employed (during compile time) to combine several operations into one and reduce (or eliminate) the need for temporaries. This is accomplished through recursive templates and template meta-programming. This library is useful if C++ has been decided as the language of choice (due to speed and/or integration capabilities), rather than another language like Matlab or Octave. %package devel Summary: Development headers and documentation for the Armadillo C++ library Group: Development/Libraries Requires: %{name} = %{version}-%{release} Requires: blas-devel, lapack-devel, atlas-devel, arpack-devel, hdf5-devel, libstdc++-devel, SuperLU-devel %description devel This package contains files necessary for development using the Armadillo C++ library. It contains header files, example programs, and user documentation (API reference guide). %prep %setup -q # convert DOS end-of-line to UNIX end-of-line for file in README.txt; do sed 's/\r//' $file >$file.new && \ touch -r $file $file.new && \ mv $file.new $file done %build %{cmake} %{__make} VERBOSE=1 %{?_smp_mflags} %install rm -rf $RPM_BUILD_ROOT %{__make} install DESTDIR=$RPM_BUILD_ROOT rm -f examples/Makefile.cmake rm -f examples/example1_win64.sln rm -f examples/example1_win64.vcxproj rm -f examples/example1_win64.README.txt rm -rf examples/lib_win64 %clean rm -rf $RPM_BUILD_ROOT %post -p /sbin/ldconfig %postun -p /sbin/ldconfig %files %defattr(-,root,root,-) %{_libdir}/*.so.* %doc LICENSE.txt %files devel %defattr(-,root,root,-) %{_libdir}/*.so %{_includedir}/armadillo %{_includedir}/armadillo_bits/ %{_datadir}/Armadillo/ %doc README.txt index.html docs.html %doc examples armadillo_icon.png %doc armadillo_nicta_2010.pdf rcpp_armadillo_csda_2014.pdf %doc mex_interface armadillo-6.500.5/misc/blank_footer.html0000666000000000000000000000002012620272703016614 0ustar rootroot armadillo-6.500.5/misc/main.doxy0000666000000000000000000000063112620272703015122 0ustar rootroot/*! \mainpage \htmlonly
See the associated technical report for an overview of the internal architecture:
    Conrad Sanderson.
    Armadillo: An Open Source C++ Linear Algebra Library for Fast Prototyping and Computationally Intensive Experiments.
    Technical Report, NICTA, 2010.

    online PDF
\endhtmlonly */ armadillo-6.500.5/misc/doxygen.config0000666000000000000000000002254712620272703016147 0ustar rootroot# Doxyfile 1.5.8 #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = "Armadillo Technical" PROJECT_NUMBER = "" OUTPUT_DIRECTORY = CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = YES ABBREVIATE_BRIEF = ALWAYS_DETAILED_SEC = YES INLINE_INHERITED_MEMB = NO FULL_PATH_NAMES = NO STRIP_FROM_PATH = STRIP_FROM_INC_PATH = SHORT_NAMES = YES JAVADOC_AUTOBRIEF = NO QT_AUTOBRIEF = NO MULTILINE_CPP_IS_BRIEF = YES INHERIT_DOCS = YES SEPARATE_MEMBER_PAGES = NO TAB_SIZE = 2 ALIASES = OPTIMIZE_OUTPUT_FOR_C = NO OPTIMIZE_OUTPUT_JAVA = NO OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO EXTENSION_MAPPING = BUILTIN_STL_SUPPORT = YES CPP_CLI_SUPPORT = NO SIP_SUPPORT = NO IDL_PROPERTY_SUPPORT = YES DISTRIBUTE_GROUP_DOC = NO SUBGROUPING = YES TYPEDEF_HIDES_STRUCT = NO SYMBOL_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = YES EXTRACT_PRIVATE = YES EXTRACT_STATIC = YES EXTRACT_LOCAL_CLASSES = YES EXTRACT_LOCAL_METHODS = NO EXTRACT_ANON_NSPACES = YES HIDE_UNDOC_MEMBERS = NO HIDE_UNDOC_CLASSES = NO HIDE_FRIEND_COMPOUNDS = NO HIDE_IN_BODY_DOCS = NO INTERNAL_DOCS = NO CASE_SENSE_NAMES = NO HIDE_SCOPE_NAMES = NO SHOW_INCLUDE_FILES = YES INLINE_INFO = YES SORT_MEMBER_DOCS = NO SORT_BRIEF_DOCS = NO SORT_GROUP_NAMES = NO SORT_BY_SCOPE_NAME = NO GENERATE_TODOLIST = YES GENERATE_TESTLIST = YES GENERATE_BUGLIST = YES GENERATE_DEPRECATEDLIST= YES ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 SHOW_USED_FILES = NO SHOW_DIRECTORIES = YES SHOW_FILES = YES SHOW_NAMESPACES = YES FILE_VERSION_FILTER = LAYOUT_FILE = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- QUIET = YES WARNINGS = NO WARN_IF_UNDOCUMENTED = YES WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = NO WARN_FORMAT = "$file:$line: $text" WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- INPUT = build_aux/doxygen/ \ include/ \ include/armadillo_bits INPUT_ENCODING = UTF-8 FILE_PATTERNS = armadillo \ *.hpp \ *.doxy RECURSIVE = NO EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = EXCLUDE_SYMBOLS = EXAMPLE_PATH = EXAMPLE_PATTERNS = EXAMPLE_RECURSIVE = NO IMAGE_PATH = INPUT_FILTER = FILTER_PATTERNS = FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- SOURCE_BROWSER = YES INLINE_SOURCES = YES STRIP_CODE_COMMENTS = NO REFERENCED_BY_RELATION = YES REFERENCES_RELATION = YES REFERENCES_LINK_SOURCE = YES USE_HTAGS = NO VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- ALPHABETICAL_INDEX = YES COLS_IN_ALPHA_INDEX = 5 IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- GENERATE_HTML = YES HTML_OUTPUT = docs_tech HTML_FILE_EXTENSION = .html HTML_HEADER = HTML_FOOTER = build_aux/doxygen/blank_footer.html HTML_STYLESHEET = HTML_ALIGN_MEMBERS = YES HTML_DYNAMIC_SECTIONS = NO GENERATE_DOCSET = NO DOCSET_FEEDNAME = "Doxygen generated docs" DOCSET_BUNDLE_ID = org.doxygen.Project GENERATE_HTMLHELP = NO CHM_FILE = HHC_LOCATION = GENERATE_CHI = NO CHM_INDEX_ENCODING = BINARY_TOC = NO TOC_EXPAND = NO GENERATE_QHP = NO QCH_FILE = QHP_NAMESPACE = QHP_VIRTUAL_FOLDER = doc QHP_CUST_FILTER_NAME = QHP_CUST_FILTER_ATTRS = QHP_SECT_FILTER_ATTRS = QHG_LOCATION = DISABLE_INDEX = NO ENUM_VALUES_PER_LINE = 4 GENERATE_TREEVIEW = YES TREEVIEW_WIDTH = 250 FORMULA_FONTSIZE = 10 #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- GENERATE_LATEX = NO LATEX_OUTPUT = latex LATEX_CMD_NAME = latex MAKEINDEX_CMD_NAME = makeindex COMPACT_LATEX = NO PAPER_TYPE = a4wide EXTRA_PACKAGES = LATEX_HEADER = PDF_HYPERLINKS = NO USE_PDFLATEX = NO LATEX_BATCHMODE = NO LATEX_HIDE_INDICES = NO #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- GENERATE_RTF = NO RTF_OUTPUT = rtf COMPACT_RTF = NO RTF_HYPERLINKS = NO RTF_STYLESHEET_FILE = RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- GENERATE_MAN = NO MAN_OUTPUT = man MAN_EXTENSION = .3 MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- GENERATE_XML = NO XML_OUTPUT = xml XML_SCHEMA = XML_DTD = XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- GENERATE_PERLMOD = NO PERLMOD_LATEX = NO PERLMOD_PRETTY = YES PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- ENABLE_PREPROCESSING = NO MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES SEARCH_INCLUDES = YES INCLUDE_PATH = INCLUDE_FILE_PATTERNS = PREDEFINED = EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = NO #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- TAGFILES = GENERATE_TAGFILE = ALLEXTERNALS = NO EXTERNAL_GROUPS = YES PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- CLASS_DIAGRAMS = YES MSCGEN_PATH = HIDE_UNDOC_RELATIONS = NO HAVE_DOT = NO DOT_FONTNAME = FreeSans DOT_FONTSIZE = 10 DOT_FONTPATH = CLASS_GRAPH = YES COLLABORATION_GRAPH = YES GROUP_GRAPHS = YES UML_LOOK = NO TEMPLATE_RELATIONS = YES INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES CALL_GRAPH = NO CALLER_GRAPH = NO GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES DOT_IMAGE_FORMAT = png DOT_PATH = DOTFILE_DIRS = DOT_GRAPH_MAX_NODES = 50 MAX_DOT_GRAPH_DEPTH = 0 DOT_TRANSPARENT = YES DOT_MULTI_TARGETS = NO GENERATE_LEGEND = YES DOT_CLEANUP = YES #--------------------------------------------------------------------------- # Options related to the search engine #--------------------------------------------------------------------------- SEARCHENGINE = NO armadillo-6.500.5/docs.html0000666000000000000000000156764012656564341014212 0ustar rootroot Armadillo: API Documentation
[top] API Documentation for Armadillo 6.500


Preamble

 


Overview
Matrix, Vector, Cube and Field Classes
Member Functions & Variables
Generated Vectors/Matrices/Cubes
    eye generate identity matrix
    linspace generate vector with linearly increasing elements
    ones generate object filled with ones
    randi generate object with random integer values in specified interval
    randu / randn generate object with random values (uniform and normal distributions)
    randg generate object with random values (gamma distribution)
    speye generate sparse identity matrix
    spones generate sparse matrix with non-zero elements set to one
    sprandu / sprandn generate sparse matrix with non-zero elements set to random values
    toeplitz generate Toeplitz matrix
    zeros generate object filled with zeros

Functions of Vectors/Matrices/Cubes
    abs obtain magnitude of each element
    accu accumulate (sum) all elements
    all check whether all elements are non-zero, or satisfy a relational condition
    any check whether any element is non-zero, or satisfies a relational condition
    as_scalar convert 1x1 matrix to pure scalar
    clamp obtain clamped elements according to given limits
    cond condition number of matrix
    conj obtain complex conjugate of each element
    conv_to convert between matrix types
    cross cross product
    cumsum cumulative sum
    cumprod cumulative product
    det / log_det determinant
    diagmat generate diagonal matrix from given matrix or vector
    diagvec extract specified diagonal
    diff differences between adjacent elements
    dot/cdot/norm_dot dot product
    eps obtain distance of each element to next largest floating point representation
    expmat matrix exponential
    find find indices of non-zero elements, or elements satisfying a relational condition
    find_finite find indices of finite elements
    find_nonfinite find indices of non-finite elements
    find_unique find indices of unique elements
    fliplr / flipud reverse order of columns or rows
    imag / real extract imaginary/real part
    ind2sub convert linear index to subscripts
    inplace_trans in-place transpose
    is_finite check whether all elements are finite
    join_rows / join_cols concatenation of matrices
    join_slices concatenation of cubes
    kron Kronecker tensor product
    min / max return extremum values
    nonzeros return non-zero values
    norm various norms of vectors and matrices
    normalise normalise vectors to unit p-norm
    prod product of elements
    rank rank of matrix
    rcond reciprocal of condition number
    repmat replicate matrix in block-like fashion
    reshape change size while keeping elements
    resize change size while keeping elements and preserving layout
    shuffle randomly shuffle elements
    size obtain dimensions of given object
    sort sort elements
    sort_index vector describing sorted order of elements
    sum sum of elements
    sub2ind convert subscripts to linear index
    symmatu / symmatl generate symmetric matrix from given matrix
    trace sum of diagonal elements of square matrix
    trans transpose of matrix
    trimatu / trimatl generate triangular matrix from given matrix
    unique return unique elements
    vectorise convert matrix to vector
    misc functions miscellaneous element-wise functions: exp, log, pow, sqrt, round, sign, ...
    trig functions trigonometric element-wise functions: cos, sin, ...

Decompositions, Factorisations, Inverses and Equation Solvers (Dense Matrices)
    chol Cholesky decomposition
    eig_sym eigen decomposition of dense symmetric/hermitian matrix
    eig_gen eigen decomposition of dense general square matrix
    eig_pair eigen decomposition for pair of general dense square matrices
    inv inverse of general square matrix
    inv_sympd inverse of symmetric positive definite matrix
    lu   lower-upper decomposition
    null orthonormal basis of null space
    orth orthonormal basis of range space
    pinv pseudo-inverse
    qr   QR decomposition
    qr_econ economical QR decomposition
    qz   generalised Schur decomposition
    schur Schur decomposition
    solve solve systems of linear equations
    svd singular value decomposition
    svd_econ economical singular value decomposition
    syl Sylvester equation solver

Decompositions, Factorisations and Equation Solvers (Sparse Matrices)
    eigs_sym limited number of eigenvalues & eigenvectors of sparse symmetric real matrix
    eigs_gen limited number of eigenvalues & eigenvectors of sparse general square matrix
    spsolve solve sparse systems of linear equations
    svds limited number of singular values & singular vectors of sparse matrix

Signal & Image Processing
Statistics & Clustering
    stats functions mean, median, standard deviation, variance
    cov covariance
    cor correlation
    hist histogram of counts
    histc histogram of counts with user specified edges
    princomp principal component analysis
    running_stat running statistics of one dimensional process/signal
    running_stat_vec running statistics of multi-dimensional process/signal
    kmeans cluster data using k-means algorithm
    gmm_diag model data as a Gaussian Mixture Model (GMM)

Miscellaneous




Matrix, Vector, Cube and Field Classes



Mat<type>
mat
cx_mat
  • The root matrix class is Mat<type>, where type is one of:
    • float, double, std::complex<float>, std::complex<double>, short, int, long, and unsigned versions of short, int, long

  • For convenience the following typedefs have been defined:
      mat  =  Mat<double>
      fmat  =  Mat<float>
      cx_mat  =  Mat<cx_double>
      cx_fmat  =  Mat<cx_float>
      umat  =  Mat<uword>
      imat  =  Mat<sword>

  • In this documentation the mat type is used for convenience; it is possible to use other types instead, eg. fmat

  • Functions which use LAPACK or ATLAS (generally matrix decompositions) are only valid for the following types: mat, fmat, cx_mat, cx_fmat

  • Elements are stored with column-major ordering (ie. column by column)

  • Constructors:
      mat()
      mat(n_rows, n_cols)
      mat(n_rows, n_cols, fill_type)
      mat(size(X))
      mat(size(X), fill_type)
      mat(mat)
      mat(sp_mat)
      mat(vec)
      mat(rowvec)
      mat(initializer_list)
      mat(string)
      mat(std::vector)   (treated as a column vector)
      cx_mat(mat,mat)   (for constructing a complex matrix out of two real matrices)

  • When specifying the size with n_rows and n_cols, by default the memory is uninitialised; memory can be initialised by specifying the fill_type, which is one of: fill::zeros, fill::ones, fill::eye, fill::randu, fill::randn, fill::none, with the following meanings:
      fill::zeros = set all elements to 0
      fill::ones = set all elements to 1
      fill::eye = set the elements along the main diagonal to 1 and off-diagonal elements to 0
      fill::randu = set each element to a random value from a uniform distribution in the [0,1] interval
      fill::randn = set each element to a random value from a normal/Gaussian distribution with zero mean and unit variance
      fill::none = do not modify the elements

  • The string format for the constructor is elements separated by spaces, and rows denoted by semicolons. For example, the 2x2 identity matrix can be created using "1 0; 0 1".
    Caveat: string based initialisation is slower than directly setting the elements or using element initialisation.

  • Advanced constructors:

      mat(ptr_aux_mem, n_rows, n_cols, copy_aux_mem = true, strict = false)

        Create a matrix using data from writable auxiliary (external) memory, where ptr_aux_mem is a pointer to the memory. By default the matrix allocates its own memory and copies data from the auxiliary memory (for safety). However, if copy_aux_mem is set to false, the matrix will instead directly use the auxiliary memory (ie. no copying); this is faster, but can be dangerous unless you know what you are doing!

        The strict parameter comes into effect only when copy_aux_mem is set to false (ie. the matrix is directly using auxiliary memory)
        • when strict is set to false, the matrix will use the auxiliary memory until a size change
        • when strict is set to true, the matrix will be bound to the auxiliary memory for its lifetime; the number of elements in the matrix can't be changed
        • the default setting of strict in versions 6.000+ is false
        • the default setting of strict in versions 5.600 and earlier is true

      mat(const ptr_aux_mem, n_rows, n_cols)

        Create a matrix by copying data from read-only auxiliary memory, where ptr_aux_mem is a pointer to the memory

      mat::fixed<n_rows, n_cols>

        Create a fixed size matrix, with the size specified via template arguments. Memory for the matrix is allocated at compile time. This is generally faster than dynamic memory allocation, but the size of the matrix can't be changed afterwards (directly or indirectly).

        For convenience, there are several pre-defined typedefs for each matrix type (where the types are: umat, imat, fmat, mat, cx_fmat, cx_mat). The typedefs specify a square matrix size, ranging from 2x2 to 9x9. The typedefs were defined by simply appending a two digit form of the size to the matrix type -- for example, mat33 is equivalent to mat::fixed<3,3>, while cx_mat44 is equivalent to cx_mat::fixed<4,4>.

      mat::fixed<n_rows, n_cols>(const ptr_aux_mem)

        Create a fixed size matrix, with the size specified via template arguments; data is copied from auxiliary memory, where ptr_aux_mem is a pointer to the memory


  • Examples:
      mat A(5, 5, fill::randu);
      double x = A(1,2);
      
      mat B = A + A;
      mat C = A * B;
      mat D = A % B;
      
      cx_mat X(A,B);
      
      B.zeros();
      B.set_size(10,10);
      B.ones(5,6);
      
      B.print("B:");
      
      mat::fixed<5,6> F;
      
      double aux_mem[24];
      mat H(&aux_mem[0], 4, 6, false);  // use auxiliary memory
      

  • Caveat: For mathematical correctness, scalars are treated as 1x1 matrices during initialisation. As such, the code below will not generate a 5x5 matrix with every element equal to 123.0:
      mat A(5,5);  A = 123.0;
      
    Use the following code instead:
      mat A(5,5);  A.fill(123.0);
      

  • See also:



Col<type>
vec
cx_vec
  • Classes for column vectors (matrices with one column)

  • The Col<type> class is derived from the Mat<type> class and inherits most of the member functions

  • For convenience the following typedefs have been defined:
      vec  =  colvec  =  Col<double>
      fvec  =  fcolvec  =  Col<float>
      cx_vec  =  cx_colvec  =  Col<cx_double>
      cx_fvec  =  cx_fcolvec  =  Col<cx_float>
      uvec  =  ucolvec  =  Col<uword>
      ivec  =  icolvec  =  Col<sword>

  • In this documentation, the vec and colvec types have the same meaning and are used interchangeably

  • In this documentation, the types vec or colvec are used for convenience; it is possible to use other types instead, eg. fvec, fcolvec

  • Functions which take Mat as input can generally also take Col as input. Main exceptions are functions which require square matrices

  • Constructors
      vec()
      vec(n_elem)
      vec(n_elem, fill_type)
      vec(size(X))
      vec(size(X), fill_type)
      vec(vec)
      vec(mat)   (a std::logic_error exception is thrown if the given matrix has more than one column)
      vec(initializer_list)
      vec(string)   (elements separated by spaces)
      vec(std::vector)
      cx_vec(vec,vec)   (for constructing a complex vector out of two real vectors)

  • When specifying the size with n_elem, by default the memory is uninitialised; memory can be initialised by specifying the fill_type, as per the Mat class

  • Advanced constructors:

      vec(ptr_aux_mem, number_of_elements, copy_aux_mem = true, strict = false)

        Create a column vector using data from writable auxiliary (external) memory, where ptr_aux_mem is a pointer to the memory. By default the vector allocates its own memory and copies data from the auxiliary memory (for safety). However, if copy_aux_mem is set to false, the vector will instead directly use the auxiliary memory (ie. no copying); this is faster, but can be dangerous unless you know what you are doing!

        The strict parameter comes into effect only when copy_aux_mem is set to false (ie. the vector is directly using auxiliary memory)
        • when strict is set to false, the vector will use the auxiliary memory until a size change
        • when strict is set to true, the vector will be bound to the auxiliary memory for its lifetime; the number of elements in the vector can't be changed
        • the default setting of strict in versions 6.000+ is false
        • the default setting of strict in versions 5.600 and earlier is true

      vec(const ptr_aux_mem, number_of_elements)

        Create a column vector by copying data from read-only auxiliary memory, where ptr_aux_mem is a pointer to the memory

      vec::fixed<number_of_elements>

        Create a fixed size column vector, with the size specified via the template argument. Memory for the vector is allocated at compile time. This is generally faster than dynamic memory allocation, but the size of the vector can't be changed afterwards (directly or indirectly).

        For convenience, there are several pre-defined typedefs for each vector type (where the types are: uvec, ivec, fvec, vec, cx_fvec, cx_vec as well as the corresponding colvec versions). The pre-defined typedefs specify vector sizes ranging from 2 to 9. The typedefs were defined by simply appending a single digit form of the size to the vector type -- for example, vec3 is equivalent to vec::fixed<3>, while cx_vec4 is equivalent to cx_vec::fixed<4>.

      vec::fixed<number_of_elements>(const ptr_aux_mem)

        Create a fixed size column vector, with the size specified via the template argument; data is copied from auxiliary memory, where ptr_aux_mem is a pointer to the memory


  • Examples:
      vec x(10);
      vec y = zeros<vec>(10);
      
      mat A = randu<mat>(10,10);
      vec z = A.col(5); // extract a column vector
      

  • Caveat: For mathematical correctness, scalars are treated as 1x1 matrices during initialisation. As such, the code below will not generate a column vector with every element equal to 123.0:
      vec a(5);  a = 123.0;
      
    Use the following code instead:
      vec a(5);  a.fill(123.0);
      

  • See also:



Row<type>
rowvec
cx_rowvec
  • Classes for row vectors (matrices with one row)

  • The template Row<type> class is derived from the Mat<type> class and inherits most of the member functions

  • For convenience the following typedefs have been defined:
      rowvec  =  Row<double>
      frowvec  =  Row<float>
      cx_rowvec  =  Row<cx_double>
      cx_frowvec  =  Row<cx_float>
      urowvec  =  Row<uword>
      irowvec  =  Row<sword>

  • In this documentation, the rowvec type is used for convenience; it is possible to use other types instead, eg. frowvec

  • Functions which take Mat as input can generally also take Row as input. Main exceptions are functions which require square matrices

  • Constructors
      rowvec()
      rowvec(n_elem)
      rowvec(n_elem, fill_type)
      rowvec(size(X))
      rowvec(size(X), fill_type)
      rowvec(rowvec)
      rowvec(mat)   (a std::logic_error exception is thrown if the given matrix has more than one row)
      rowvec(initializer_list)
      rowvec(string)   (elements separated by spaces)
      rowvec(std::vector)
      cx_rowvec(rowvec,rowvec)   (for constructing a complex row vector out of two real row vectors)

  • When specifying the size with n_elem, by default the memory is uninitialised; memory can be initialised by specifying the fill_type, as per the Mat class

  • Advanced constructors:

      rowvec(ptr_aux_mem, number_of_elements, copy_aux_mem = true, strict = false)

        Create a row vector using data from writable auxiliary (external) memory, where ptr_aux_mem is a pointer to the memory. By default the vector allocates its own memory and copies data from the auxiliary memory (for safety). However, if copy_aux_mem is set to false, the vector will instead directly use the auxiliary memory (ie. no copying); this is faster, but can be dangerous unless you know what you are doing!

        The strict parameter comes into effect only when copy_aux_mem is set to false (ie. the vector is directly using auxiliary memory)
        • when strict is set to false, the vector will use the auxiliary memory until a size change
        • when strict is set to true, the vector will be bound to the auxiliary memory for its lifetime; the number of elements in the vector can't be changed
        • the default setting of strict in versions 6.000+ is false
        • the default setting of strict in versions 5.600 and earlier is true

      rowvec(const ptr_aux_mem, number_of_elements)

        Create a row vector by copying data from read-only auxiliary memory, where ptr_aux_mem is a pointer to the memory

      rowvec::fixed<number_of_elements>

        Create a fixed size row vector, with the size specified via the template argument. Memory for the vector is allocated at compile time. This is generally faster than dynamic memory allocation, but the size of the vector can't be changed afterwards (directly or indirectly).

        For convenience, there are several pre-defined typedefs for each vector type (where the types are: urowvec, irowvec, frowvec, rowvec, cx_frowvec, cx_rowvec). The pre-defined typedefs specify vector sizes ranging from 2 to 9. The typedefs were defined by simply appending a single digit form of the size to the vector type -- for example, rowvec3 is equivalent to rowvec::fixed<3>, while cx_rowvec4 is equivalent to cx_rowvec::fixed<4>.

      rowvec::fixed<number_of_elements>(const ptr_aux_mem)

        Create a fixed size row vector, with the size specified via the template argument; data is copied from auxiliary memory, where ptr_aux_mem is a pointer to the memory


  • Examples:
      rowvec x(10);
      rowvec y = zeros<rowvec>(10);
      
      mat    A = randu<mat>(10,10);
      rowvec z = A.row(5); // extract a row vector
      

  • Caveat: For mathematical correctness, scalars are treated as 1x1 matrices during initialisation. As such, the code below will not generate a row vector with every element equal to 123.0:
      rowvec r(5);  r = 123.0;
      
    Use the following code instead:
      rowvec r(5);  r.fill(123.0);
      

  • See also:



Cube<type>
cube
cx_cube
  • Classes for cubes, also known as "3D matrices" or 3rd order tensors

  • The cube class is Cube<type>, where type is one of:
    • float, double, std::complex<float>, std::complex<double>, short, int, long and unsigned versions of short, int, long

  • For convenience the following typedefs have been defined:
      cube  =  Cube<double>
      fcube  =  Cube<float>
      cx_cube  =  Cube<cx_double>
      cx_fcube  =  Cube<cx_float>
      ucube  =  Cube<uword>
      icube  =  Cube<sword>

  • In this documentation the cube type is used for convenience; it is possible to use other types instead, eg. fcube

  • Cube data is stored as a set of slices (matrices) stored contiguously within memory. Within each slice, elements are stored with column-major ordering (ie. column by column)

  • Each slice can be interpreted as a matrix, hence functions which take Mat as input can generally also take cube slices as input

  • Constructors:
      cube()
      cube(n_rows, n_cols, n_slices)
      cube(n_rows, n_cols, n_slices, fill_type)
      cube(size(X))
      cube(size(X), fill_type)
      cube(cube)
      cx_cube(cube, cube)   (for constructing a complex cube out of two real cubes)

  • When specifying the cube size with n_rows, n_cols and n_slices, by default the memory is uninitialised; memory can be initialised by specifying the fill_type, as per the Mat class (except for fill::eye)

  • Advanced constructors:

      cube::fixed<n_rows, n_cols, n_slices>

        Create a fixed size cube, with the size specified via template arguments. Memory for the cube is allocated at compile time. This is generally faster than dynamic memory allocation, but the size of the cube can't be changed afterwards (directly or indirectly).

      cube(ptr_aux_mem, n_rows, n_cols, n_slices, copy_aux_mem = true, strict = false)

        Create a cube using data from writable auxiliary (external) memory, where ptr_aux_mem is a pointer to the memory. By default the cube allocates its own memory and copies data from the auxiliary memory (for safety). However, if copy_aux_mem is set to false, the cube will instead directly use the auxiliary memory (ie. no copying); this is faster, but can be dangerous unless you know what you are doing!

        The strict parameter comes into effect only when copy_aux_mem is set to false (ie. the cube is directly using auxiliary memory)
        • when strict is set to false, the cube will use the auxiliary memory until a size change
        • when strict is set to true, the cube will be bound to the auxiliary memory for its lifetime; the number of elements in the cube can't be changed
        • the default setting of strict in versions 6.000+ is false
        • the default setting of strict in versions 5.600 and earlier is true

      cube(const ptr_aux_mem, n_rows, n_cols, n_slices)

        Create a cube by copying data from read-only auxiliary memory, where ptr_aux_mem is a pointer to the memory


  • Examples:
      cube x(1,2,3);
      cube y = randu<cube>(4,5,6);
      
      mat A = y.slice(1);  // extract a slice from the cube
                           // (each slice is a matrix)
      
      mat B = randu<mat>(4,5);
      y.slice(2) = B;     // set a slice in the cube
      
      cube q = y + y;     // cube addition
      cube r = y % y;     // element-wise cube multiplication
      
      cube::fixed<4,5,6> f;
      f.ones();
      

  • Caveats:

    • The size of individual slices can't be changed. For example, the following will not work:
        cube c(5,6,7);
        c.slice(0) = randu<mat>(10,20); // wrong size
        
    • For mathematical correctness, scalars are treated as 1x1x1 cubes during initialisation. As such, the code below will not generate a cube with every element equal to 123.0:
        cube c(5,6,7);  c = 123.0;
        
      Use the following code instead:
        cube c(5,6,7);  c.fill(123.0);
        

  • See also:



field<object_type>
  • Class for storing arbitrary objects in matrix-like or cube-like layouts

  • Somewhat similar to a matrix or cube, but instead of each element being a scalar, each element can be a vector, or matrix, or cube

  • Each element can have an arbitrary size (eg. in a field of matrices, each matrix can have a different size)

  • Constructors, where object_type is another class, eg. vec, mat, std::string, etc:
      field<object_type>()
      field<object_type>(n_elem)
      field<object_type>(n_rows, n_cols)
      field<object_type>(n_rows, n_cols, n_slices)
      field<object_type>(size(X))
      field<object_type>(field<object_type>)

  • Caveat: to store a set of matrices of the same size, the Cube class is more efficient

  • Examples:
      mat A = randn(2,3);
      mat B = randn(4,5);
      
      field<mat> F(2,1);
      F(0,0) = A;
      F(1,0) = B; 
      
      F.print("F:");
      
      F.save("mat_field");
      

  • See also:



SpMat<type>
sp_mat
sp_cx_mat
  • The root sparse matrix class is SpMat<type>, where type is one of:
    • float, double, std::complex<float>, std::complex<double>, short, int, long and unsigned versions of short, int, long

  • For convenience the following typedefs have been defined:
      sp_mat  =  SpMat<double>
      sp_fmat  =  SpMat<float>
      sp_cx_mat  =  SpMat<cx_double>
      sp_cx_fmat  =  SpMat<cx_float>
      sp_umat  =  SpMat<uword>
      sp_imat  =  SpMat<sword>

  • In this documentation the sp_mat type is used for convenience; it is possible to use other types instead, eg. sp_fmat

  • Constructors:
      sp_mat()
      sp_mat(n_rows, n_cols)
      sp_mat(size(X))
      sp_mat(sp_mat)
      sp_mat(mat)
      sp_mat(string)
      sp_cx_mat(sp_mat,sp_mat)   (for constructing a complex matrix out of two real matrices)

  • Elements are stored in the compressed sparse column (CSC) format

  • All elements are treated as zero by default (ie. the matrix is initialised to contain zeros)

  • This class behaves in a similar manner to the Mat class, however, member functions which set all elements to non-zero values (and hence do not make sense for sparse matrices) have been deliberately omitted; examples of omitted functions: .fill(), .ones(), += scalar, etc.

  • Batch insertion constructors:
    • form 1: sp_mat(locations, values, sort_locations = true)
    • form 2: sp_mat(locations, values, n_rows, n_cols, sort_locations = true, check_for_zeros = true)
    • form 3: sp_mat(add_values, locations, values, n_rows, n_cols, sort_locations = true, check_for_zeros = true)
    • form 4: sp_mat(rowind, colptr, values, n_rows, n_cols)

      • Using batch insertion constructors is generally much faster than consecutively inserting values using element access operators

      • For forms 1, 2, 3, locations is a dense matrix of type umat, with a size of 2 x N, where N is the number of values to be inserted; the location of the i-th element is specified by the contents of the i-th column of the locations matrix, where the row is in locations(0,i), and the column is in locations(1,i)

      • For form 4, rowind is a dense column vector of type uvec containing the row indices of the values to be inserted, and colptr is a dense column vector of type uvec (with length n_cols + 1) containing indices of values corresponding to the start of new columns; the vectors correspond to the arrays used by the compressed sparse column format; this form is useful for copying data from other CSC sparse matrix containers

      • For all forms, values is a dense column vector containing the values to be inserted; it must have the same element type as the sparse matrix. For forms 1 and 2, the value in values[i] will be inserted at the location specified by the i-th column of the locations matrix.

      • For form 3, add_values is either true or false; when set to true, identical locations are allowed, and the values at identical locations are added

      • The size of the constructed matrix is either automatically determined from the maximal locations in the locations matrix (form 1), or manually specified via n_rows and n_cols (forms 2, 3, 4)

      • If sort_locations is set to false, the locations matrix is assumed to contain locations that are already sorted according to column-major ordering

      • If check_for_zeros is set to false, the values vector is assumed to contain no zero values

  • Caveats:

  • Examples:
      sp_mat A(5,6);
      sp_mat B(6,5);
      
      A(0,0) = 1;
      A(1,0) = 2;
      
      B(0,0) = 3;
      B(0,1) = 4;
      
      sp_mat C = 2*B;
      
      sp_mat D = A*C;
      
      
      // batch insertion of two values at (5, 6) and (9, 9)
      umat locations;
      locations << 5 << 9 << endr
                << 6 << 9 << endr;
      
      vec values;
      values << 1.5 << 3.2 << endr;
      
      sp_mat X(locations, values);
      

  • See also:



operators:  +  -  *  /  %  ==  !=  <=  >=  <  >
  • Overloaded operators for Mat, Col, Row and Cube classes

  • Meanings:

      +    
      Addition of two objects
      -
      Subtraction of one object from another or negation of an object
           
      /
      Element-wise division of an object by another object or a scalar
      *
      Matrix multiplication of two objects; not applicable to the Cube class unless multiplying a cube by a scalar
           
      %
      Schur product: element-wise multiplication of two objects
           
      ==
      Element-wise equality evaluation of two objects; generates a matrix of type umat with entries that indicate whether at a given position the two elements from the two objects are equal (1) or not equal (0)
      !=
      Element-wise non-equality evaluation of two objects
           
      >=
      As for ==, but the check is for "greater than or equal to"
      <=
      As for ==, but the check is for "less than or equal to"
           
      >
      As for ==, but the check is for "greater than"
      <
      As for ==, but the check is for "less than"

  • Caveat: operators involving an equality comparison (ie. ==, !=, >=, <=) may not work as expected for floating point element types (ie. float, double) due to the necessarily limited precision of these types; these operators are (in general) not recommended for matrices of type mat or fmat

  • A std::logic_error exception is thrown if incompatible object sizes are used

  • If the +, - and % operators are chained, Armadillo will try to avoid the generation of temporaries; no temporaries are generated if all given objects are of the same type and size

  • If the * operator is chained, Armadillo will try to find an efficient ordering of the matrix multiplications

  • Examples:
      mat A = randu<mat>(5,10);
      mat B = randu<mat>(5,10);
      mat C = randu<mat>(10,5);
      
      mat P = A + B;
      mat Q = A - B;
      mat R = -B;
      mat S = A / 123.0;
      mat T = A % B;
      mat U = A * C;
      
      // V is constructed without temporaries
      mat V = A + B + A + B;
      
      imat AA = "1 2 3; 4 5 6; 7 8 9;";
      imat BB = "3 2 1; 6 5 4; 9 8 7;";
      
      // compare elements
      umat ZZ = (AA >= BB);
      

  • See also:





Member Functions & Variables



attributes
    .n_rows     number of rows; present in Mat, Col, Row, Cube, field and SpMat
    .n_cols     number of columns; present in Mat, Col, Row, Cube, field and SpMat
    .n_elem     total number of elements; present in Mat, Col, Row, Cube, field and SpMat
    .n_slices     number of slices; present in Cube
    .n_nonzero     number of non-zero elements; present in SpMat


element/object access via (), [] and .at()
  • Provide access to individual elements or objects stored in a container object (ie. Mat, Col, Row, Cube, field)

      (n)  
      For vec and rowvec, access the n-th element. For mat, cube and field, access the n-th element/object under the assumption of a flat layout, with column-major ordering of data (ie. column by column). A std::logic_error exception is thrown if the requested element is out of bounds. The bounds check can be optionally disabled at compile-time to get more speed.
           
      .at(n)  or  [n] 
      As for (n), but without a bounds check. Not recommended for use unless your code has been thoroughly debugged.
           
      (i,j)
      For mat and 2D field classes, access the element/object stored at the i-th row and j-th column. A std::logic_error exception is thrown if the requested element is out of bounds. The bounds check can be optionally disabled at compile-time to get more speed.
           
      .at(i,j)
      As for (i,j), but without a bounds check. Not recommended for use unless your code has been thoroughly debugged.
           
      (i,j,k)
      For cube and 3D field classes, access the element/object stored at the i-th row, j-th column and k-th slice. A std::logic_error exception is thrown if the requested element is out of bounds. The bounds check can be optionally disabled at compile-time to get more speed.
           
      .at(i,j,k)
      As for (i,j,k), but without a bounds check. Not recommended for use unless your code has been thoroughly debugged.

  • The bounds checks used by the (n), (i,j) and (i,j,k) access forms can be disabled by defining the ARMA_NO_DEBUG macro before including the armadillo header file (eg. #define ARMA_NO_DEBUG). Disabling the bounds checks is not recommended until your code has been thoroughly debugged -- it's better to write correct code first, and then maximise its speed.

  • The indices of elements are specified via the uword type, which is a typedef for an unsigned integer type. When using loops to access elements, it's best to use uword instead of int. For example: for(uword i=0; i<X.n_elem; ++i) { X(i) = ... }

  • Caveat: for sparse matrices, using element access operators to insert values via loops can be inefficient; you may wish to use batch insertion constructors instead

  • Examples:
      mat A = randu<mat>(10,10);
      A(9,9) = 123.0;
      double x = A.at(9,9);
      double y = A[99];
      
      vec p = randu<vec>(10,1);
      p(9) = 123.0;
      double z = p[9];
      

  • See also:



element initialisation
  • When using the C++11 standard, elements in Mat, Col, Row can be set via initialiser lists

  • When using the old C++98 standard, elements can be set via the << operator; special element endr indicates "end of row" (conceptually similar to std::endl)

  • Caveat: using the << operator is slower than using initialiser lists

  • Examples:
      // C++11
      
      vec v = { 1, 2, 3 };
      
      mat A = { {1, 3, 5},
                {2, 4, 6} };
      
      
      // C++98
      
      mat B;
      
      B << 1 << 3 << 5 << endr
        << 2 << 4 << 6 << endr;
      

  • See also:



.zeros()
  (member function of Mat, Col, Row, SpMat, Cube)
.zeros( n_elem )
  (member function of Col and Row)
.zeros( n_rows, n_cols )
  (member function of Mat and SpMat)
.zeros( n_rows, n_cols, n_slices )
  (member function of Cube)
.zeros( size(X) )
  (member function of Mat, Col, Row, Cube, SpMat)
  • Set the elements of an object to zero, optionally first changing the size to specified dimensions

  • Examples:
      mat A(5,10);  A.zeros();   // or:  mat A(5,10,fill::zeros);
      
      mat B;  B.zeros(10,20);
      
      mat C;  C.zeros( size(B) );
      

  • See also:



.ones()
  (member function of Mat, Col, Row, Cube)
.ones( n_elem )
  (member function of Col and Row)
.ones( n_rows, n_cols )
  (member function of Mat)
.ones( n_rows, n_cols, n_slices )
  (member function of Cube)
.ones( size(X) )
  (member function of Mat, Col, Row, Cube)
  • Set all the elements of an object to one, optionally first changing the size to specified dimensions

  • Examples:
      mat A(5,10);  A.ones();   // or:  mat A(5,10,fill::ones);
      
      mat B;  B.ones(10,20);
      
      mat C;  C.ones( size(B) );
      

  • See also:



.eye()
.eye( n_rows, n_cols )
.eye( size(X) )
  • Member functions of Mat and SpMat

  • Set the elements along the main diagonal to one and off-diagonal elements to zero, optionally first changing the size to specified dimensions

  • An identity matrix is generated when n_rows = n_cols

  • Examples:
      mat A(5,5);  A.eye();  // or:  mat A(5,5,fill::eye);
      
      mat B;  B.eye(5,5);
      
      mat C;  C.eye( size(B) );
      

  • See also:



.randu()
  (member function of Mat, Col, Row, Cube)
.randu( n_elem )
  (member function of Col and Row)
.randu( n_rows, n_cols )
  (member function of Mat)
.randu( n_rows, n_cols, n_slices )
  (member function of Cube)
.randu( size(X) )
  (member function of Mat, Col, Row, Cube)

.randn()
  (member function of Mat, Col, Row, Cube)
.randn( n_elem )
  (member function of Col and Row)
.randn( n_rows, n_cols )
  (member function of Mat)
.randn( n_rows, n_cols, n_slices )
  (member function of Cube)
.randn( size(X) )
  (member function of Mat, Col, Row, Cube)
  • Set all the elements to random values, optionally first changing the size to specified dimensions

  • .randu() uses a uniform distribution in the [0,1] interval

  • .randn() uses a normal/Gaussian distribution with zero mean and unit variance

  • To change the RNG seed, use arma_rng::set_seed(value) or arma_rng::set_seed_random() functions

  • Examples:
      mat A(5,10);  A.randu();   // or:  mat A(5,10,fill::randu);
      
      mat B;  B.randu(10,20);
      
      mat C;  C.randu( size(B) );
      
      arma_rng::set_seed_random();  // set the seed to a random value
      

  • See also:



.fill( value )


.imbue( functor )
.imbue( lambda_function )   (C++11 only)
  • Member functions of Mat, Col, Row and Cube

  • Imbue (fill) with values provided by a functor or lambda function

  • For matrices, filling is done column-by-column (ie. column 0 is filled, then column 1, ...)

  • For cubes, filling is done slice-by-slice, with each slice treated as a matrix

  • Examples:
      // C++11 only example
      // need to include <random>
      
      std::mt19937 engine;  // Mersenne twister random number engine
      
      std::uniform_real_distribution<double> distr(0.0, 1.0);
        
      mat A(4,5);
        
      A.imbue( [&]() { return distr(engine); } );
      

  • See also:



.transform( functor )
.transform( lambda_function )   (C++11 only)
  • Member functions of Mat, Col, Row and Cube

  • Transform each element using a functor or lambda function

  • For matrices, transformation is done column-by-column (ie. column 0 is transformed, then column 1, ...)

  • For cubes, transformation is done slice-by-slice, with each slice treated as a matrix

  • Examples:
      // C++11 only example
      
      mat A = ones<mat>(4,5);
      
      // add 123 to every element
      A.transform( [](double val) { return (val + 123.0); } );
      

  • See also:



.for_each( functor )
.for_each( lambda_function )   (C++11 only)
  • Member functions of Mat, Col, Row, Cube and field

  • For each element, pass its reference to a functor or lambda function

  • For matrices, the processing is done column-by-column

  • For cubes, processing is done slice-by-slice, with each slice treated as a matrix

  • Examples:
      // C++11 only examples
      
      mat A = ones<mat>(4,5);
      
      // add 123 to each element
      A.for_each( [](mat::elem_type& val) { val += 123.0; } );  // NOTE: the '&' is crucial!
      
      
      field<mat> F(2,3);
      
      // set the size of all matrices in field F
      F.for_each( [](mat& X) { X.zeros(4,5); } );  // NOTE: the '&' is crucial!
      

  • See also:



.set_size( n_elem )
  (member function of Col, Row, field)
.set_size( n_rows, n_cols )
  (member function of Mat, SpMat, field)
.set_size( n_rows, n_cols, n_slices )
  (member function of Cube and field)
.set_size( size(X) )
  (member function of Mat, Col, Row, Cube, SpMat, field)
  • Change the size of an object, without explicitly preserving data and without initialising the elements

  • If you need to initialise the elements to zero while changing the size, use .zeros() instead

  • If you need to explicitly preserve data while changing the size, use .reshape() or .resize() instead;
    caveat: .reshape() and .resize() are considerably slower than .set_size()

  • Examples:
      mat A;  A.set_size(5,10);       // or:  mat A(5,10);
      
      mat B;  B.set_size( size(A) );  // or:  mat B( size(A) );
      
      vec v;  v.set_size(100);        // or:  vec v(100);
      

  • See also:



.reshape( n_rows, n_cols )
  (member function of Mat and SpMat)
.reshape( n_rows, n_cols, n_slices )
  (member function of Cube)
.reshape( size(X) )
  (member function of Mat, Cube, SpMat)
  • Recreate the object according to given size specifications, with the elements taken from the previous version of the object in a column-wise manner; the elements in the generated object are placed column-wise (ie. the first column is filled up before filling the second column)

  • The layout of the elements in the recreated object will be different to the layout in the previous version of the object

  • If the total number of elements in the previous version of the object is less than the specified size, the extra elements in the recreated object are set to zero

  • If the total number of elements in the previous version of the object is greater than the specified size, only a subset of the elements is taken

  • Caveats:
    • do not use .reshape() if you simply want to change the size without preserving data; use .set_size() instead, which is much faster
    • to grow/shrink the object while preserving the elements as well as the layout of the elements, use .resize() instead
    • to create a vector representation of a matrix (ie. concatenate all the columns or rows), use vectorise() instead

  • Examples:
      mat A = randu<mat>(4,5);
      
      A.reshape(5,4);
      

  • See also:



.resize( n_elem )
  (member function of Col, Row)
.resize( n_rows, n_cols )
  (member function of Mat and SpMat)
.resize( n_rows, n_cols, n_slices )
  (member function of Cube)
.resize( size(X) )
  (member function of Mat, Col, Row, Cube, SpMat)


.copy_size( A )
  • Set the size to be the same as object A

  • Object A must be of the same root type as the object being modified (eg. you can't set the size of a matrix by providing a cube)

  • Examples:
      mat A = randu<mat>(5,6);
      mat B;
      B.copy_size(A);
      
      cout << B.n_rows << endl;
      cout << B.n_cols << endl;
      

  • See also:



.reset()


submatrix views
  • A collection of member functions of Mat, Col and Row classes that provide read/write access to submatrix views

  • contiguous views for matrix X:

      X.col( col_number )
      X.row( row_number )

      X.cols( first_col, last_col )
      X.rows( first_row, last_row )

      X.submat( first_row, first_col, last_row, last_col )

      X( span(first_row, last_row), span(first_col, last_col) )

      Xfirst_row, first_col, size(n_rowsn_cols) )
      Xfirst_row, first_col, size(Y) )    (Y is a mat)

      X( span(first_row, last_row), col_number )
      X( row_number, span(first_col, last_col) )

      X.head_cols( number_of_cols )
      X.head_rows( number_of_rows )

      X.tail_cols( number_of_cols )
      X.tail_rows( number_of_rows )

      X.unsafe_col( col_number )

  • contiguous views for vector V:

      V( span(first_index, last_index) )
      V.subvec( first_index, last_index )

      V.head( number_of_elements )
      V.tail( number_of_elements )
  •           
  • non-contiguous views for matrix or vector X:

      X.elem( vector_of_indices )
      X( vector_of_indices )

      X.cols( vector_of_column_indices )
      X.rows( vector_of_row_indices )

      X.submat( vector_of_row_indices, vector_of_column_indices )
      X( vector_of_row_indices, vector_of_column_indices )


  • related views (documented separately)

  • Instances of span(start,end) can be replaced by span::all to indicate the entire range

  • For functions requiring one or more vector of indices, eg. X.submat(vector_of_row_indices, vector_of_column_indices), each vector of indices must be of type uvec

  • In the function X.elem(vector_of_indices), elements specified in vector_of_indices are accessed. X is interpreted as one long vector, with column-by-column ordering of the elements of X. The vector_of_indices must evaluate to a vector of type uvec (eg. generated by the find() function). The aggregate set of the specified elements is treated as a column vector (ie. the output of X.elem() is always a column vector).

  • The function .unsafe_col() is provided for speed reasons and should be used only if you know what you are doing. It creates a seemingly independent Col vector object (eg. vec), but uses memory from the existing matrix object. As such, the created vector is not alias safe, and does not take into account that the underlying matrix memory could be freed (eg. due to any operation involving a size change of the matrix).

  • Examples:
      mat A = zeros<mat>(5,10);
      
      A.submat( 0,1, 2,3 )      = randu<mat>(3,3);
      A( span(0,2), span(1,3) ) = randu<mat>(3,3);
      A( 0,1, size(3,3) )       = randu<mat>(3,3);
      
      mat B = A.submat( 0,1, 2,3 );
      mat C = A( span(0,2), span(1,3) );
      mat D = A( 0,1, size(3,3) );
      
      A.col(1)        = randu<mat>(5,1);
      A(span::all, 1) = randu<mat>(5,1);
      
      mat X = randu<mat>(5,5);
      
      // get all elements of X that are greater than 0.5
      vec q = X.elem( find(X > 0.5) );
      
      // add 123 to all elements of X greater than 0.5
      X.elem( find(X > 0.5) ) += 123.0;
      
      // set four specific elements of X to 1
      uvec indices;
      indices << 2 << 3 << 6 << 8;
      
      X.elem(indices) = ones<vec>(4);
      
      // add 123 to the last 5 elements of vector a
      vec a(10, fill::randu);
      a.tail(5) += 123.0;
      
      // add 123 to the first 3 elements of column 2 of X
      X.col(2).head(3) += 123;
      

  • See also:



subcube views and slices
  • A collection of member functions of the Cube class that provide subcube views

  • contiguous views for cube Q:

      Q.slice( slice_number )
      Q.slices( first_slice, last_slice )

      Q.subcube( first_row, first_col, first_slice, last_row, last_col, last_slice )

      Q( span(first_row, last_row), span(first_col, last_col), span(first_slice, last_slice) )

      Qfirst_row, first_col, first_slice, size(n_rows, n_cols, n_slices) )
      Qfirst_row, first_col, first_slice, size(R) )      (R is a cube)

      Q.tube( row, col )
      Q.tube( first_row, first_col, last_row, last_col )
      Q.tube( span(first_row, last_row), span(first_col, last_col) )
      Q.tube( first_row, first_col, size(n_rows, n_cols) )
  •           
  • non-contiguous views for cube Q:

      Q.elem( vector_of_indices )
      Q( vector_of_indices )

  • related views (documented separately)

  • Instances of span(a,b) can be replaced by:
    • span() or span::all, to indicate the entire range
    • span(a), to indicate a particular row, column or slice

  • An individual slice, accessed via .slice(), is an instance of the Mat class (a reference to a matrix is provided)

  • All .tube() forms are variants of .subcube(), using first_slice = 0 and last_slice = Q.n_slices-1

  • The .tube(row,col) form uses row = first_row = last_row, and col = first_col = last_col

  • In the function Q.elem(vector_of_indices), elements specified in vector_of_indices are accessed. Q is interpreted as one long vector, with slice-by-slice and column-by-column ordering of the elements of Q. The vector_of_indices must evaluate to a vector of type uvec (eg. generated by the find() function). The aggregate set of the specified elements is treated as a column vector (ie. the output of Q.elem() is always a column vector).

  • Examples:
      cube A = randu<cube>(2,3,4);
      
      mat B = A.slice(1);
      
      A.slice(0) = randu<mat>(2,3);
      A.slice(0)(1,2) = 99.0;
      
      A.subcube(0,0,1,  1,1,2)             = randu<cube>(2,2,2);
      A( span(0,1), span(0,1), span(1,2) ) = randu<cube>(2,2,2);
      A( 0,0,1, size(2,2,2) )              = randu<cube>(2,2,2);
      
      // add 123 to all elements of A greater than 0.5
      A.elem( find(A > 0.5) ) += 123.0;
      

  • See also:



subfield views
  • A collection of member functions of the field class that provide subfield views

  • For a 2D field F, the subfields are accessed as:

    • F.row( row_number )
      F.col( col_number )

      F.rows( first_row, last_row )
      F.cols( first_col, last_col )

      F.subfield( first_row, first_col, last_row, last_col )

      F( span(first_row, last_row), span(first_col, last_col) )

      Ffirst_row, first_col, size(G) )    (G is a 2D field)
      Ffirst_row, first_col, size(n_rows, n_cols) )

  • For a 3D field F, the subfields are accessed as:

    • F.slice( slice_number )

      F.slices( first_slice, last_slice )

      F.subfield( first_row, first_col, first_slice, last_row, last_col, last_slice )

      F( span(first_row, last_row), span(first_col, last_col), span(first_slice, last_slice) )

      Ffirst_row, first_col, first_slice, size(G) )    (G is a 3D field)
      Ffirst_row, first_col, first_slice, size(n_rows, n_cols, n_slices) )

  • Instances of span(a,b) can be replaced by:
    • span() or span::all, to indicate the entire range
    • span(a), to indicate a particular row or column

  • See also:



.diag()
.diag( k )
  • Member function of Mat and SpMat

  • Read/write access to a diagonal in a matrix

  • The argument k is optional; by default the main diagonal is accessed (k=0)

  • For k > 0, the k-th super-diagonal is accessed (top-right corner)

  • For k < 0, the k-th sub-diagonal is accessed (bottom-left corner)

  • The diagonal is interpreted as a dense column vector within expressions

  • Examples:
      mat X = randu<mat>(5,5);
      
      vec a = X.diag();
      vec b = X.diag(1);
      vec c = X.diag(-2);
      
      X.diag()  = randu<vec>(5);
      X.diag() += 6;
      X.diag().ones();
      

  • See also:



.each_col()
.each_row()

.each_col( vector_of_indices )
.each_row( vector_of_indices )

.each_col( lambda_function )   (C++11 only)
.each_row( lambda_function )   (C++11 only)
  • Member functions of Mat

  • Repeat a vector operation on each column or row of a matrix

  • Supported operations for .each_col() / .each_row() and .each_col(vector_of_indices) / .each_row(vector_of_indices) forms:

      + addition      += in-place addition
      - subtraction      -= in-place subtraction
      % element-wise multiplication      %= in-place element-wise multiplication
      / element-wise division      /= in-place element-wise division
      = assignment (copy)         

  • The argument vector_of_indices is optional; by default all columns or rows are used

  • If the argument vector_of_indices is specified, it must evaluate to a vector of type uvec; the vector contains a list of indices of the columns or rows to be used

  • If the lambda_function is specified, the function must accept a reference to a Col or Row object with the same element type as the underlying matrix

  • Examples:
      mat X = ones<mat>(6,5);
      vec v = linspace<vec>(10,15,6);
      
      X.each_col() += v;         // in-place addition of v to each column vector of X
      
      mat Y = X.each_col() + v;  // generate Y by adding v to each column vector of X
      
      // subtract v from columns 0 through to 3 in X
      X.cols(0,3).each_col() -= v;
      
      
      uvec indices(2);
      indices(0) = 2;
      indices(1) = 4;
      
      X.each_col(indices) = v;   // copy v to columns 2 and 4 in X
      
      
      X.each_col( [](vec& a){ a.print(); } );     // lambda function with non-const vector
      
      const mat& XX = X;
      XX.each_col( [](const vec& b){ b.print(); } );  // lambda function with const vector
      

  • See also:



.each_slice()
.each_slice( vector_of_indices )
.each_slice( lambda_function )   (C++11 only)
  • Member function of Cube

  • Repeat a matrix operation on each slice of a cube

  • Supported operations for .each_slice() and .each_slice(vector_of_indices) forms:

      + addition      += in-place addition
      - subtraction      -= in-place subtraction
      % element-wise multiplication      %= in-place element-wise multiplication
      / element-wise division      /= in-place element-wise division
      = assignment (copy)         

  • The argument vector_of_indices is optional; by default all slices are used

  • If the argument vector_of_indices is specified, it must evaluate to a vector of type uvec; the vector contains a list of indices of the slices to be used

  • If the lambda_function is specified, the function must accept a reference to a Mat object with the same element type as the underlying cube

  • Examples:
      cube C(4,5,6, fill::randu);
      
      mat M = repmat(linspace<vec>(1,4,4), 1, 5);
      
      C.each_slice() += M;          // in-place addition of M to each slice of C
      
      cube D = C.each_slice() + M;  // generate D by adding M to each slice of C
      
      
      uvec indices(2);
      indices(0) = 2;
      indices(1) = 4;
      
      C.each_slice(indices) = M;    // copy M to slices 2 and 4 in C
      
      
      C.each_slice( [](mat& X){ X.print(); } );     // lambda function with non-const matrix
      
      const cube& CC = C;
      CC.each_slice( [](const mat& X){ X.print(); } );  // lambda function with const matrix
      

  • See also:



.set_imag( X )
.set_real( X )
  • Set the imaginary/real part of an object

  • X must have the same size as the recipient object

  • Examples:
         mat A = randu<mat>(4,5);
         mat B = randu<mat>(4,5);
      
      cx_mat C = zeros<cx_mat>(4,5);
      
      C.set_real(A);
      C.set_imag(B);
      

  • Caveat: to directly construct a complex matrix out of two real matrices, the following code is faster:
         mat A = randu<mat>(4,5);
         mat B = randu<mat>(4,5);
      
      cx_mat C = cx_mat(A,B);
      

  • See also:



.insert_rows( row_number, X )
.insert_rows( row_number, number_of_rows )
.insert_rows( row_number, number_of_rows, set_to_zero )
  (member functions of Mat and Col)
 
.insert_cols( col_number, X )
.insert_cols( col_number, number_of_cols )
.insert_cols( col_number, number_of_cols, set_to_zero )
  (member functions of Mat and Row)
 
.insert_slices( slice_number, X )
.insert_slices( slice_number, number_of_slices )
.insert_slices( slice_number, number_of_slices, set_to_zero )
  (member functions of Cube)
  • Functions with the X argument: insert a copy of X at the specified row/column/slice
    • if inserting rows, X must have the same number of columns as the recipient object
    • if inserting columns, X must have the same number of rows as the recipient object
    • if inserting slices, X must have the same number of rows and columns as the recipient object (ie. all slices must have the same size)

  • Functions with the number_of_... argument: expand the object by creating new rows/columns/slices. By default, the new rows/columns/slices are set to zero. If set_to_zero is false, the memory used by the new rows/columns/slices will not be initialised.

  • Examples:
      mat A = randu<mat>(5,10);
      mat B = ones<mat>(5,2);
      
      // at column 2, insert a copy of B;
      // A will now have 12 columns
      A.insert_cols(2, B);
      
      // at column 1, insert 5 zeroed columns;
      // B will now have 7 columns
      B.insert_cols(1, 5);
      

  • See also:



.shed_row( row_number )
.shed_rows( first_row, last_row )
  (member functions of Mat, Col and SpMat)
 
.shed_col( column_number )
.shed_cols( first_column, last_column )
  (member functions of Mat, Row and SpMat)
 
.shed_slice( slice_number )
.shed_slices( first_slice, last_slice )
  (member functions of Cube)


.swap_rows( row1, row2 )
.swap_cols( col1, col2 )
  • Member functions of Mat, Col, Row and SpMat

  • Swap the contents of specified rows or columns

  • Examples:
      mat X = randu<mat>(5,5);
      X.swap_rows(0,4);
      

  • See also:



.swap( X )
  • Member function of Mat, Col, Row and Cube

  • Swap contents with object X

  • Examples:
      mat A = zeros<mat>(4,5);
      mat B =  ones<mat>(6,7);
      
      A.swap(B);
      

  • See also:



.memptr()
  • Member function of Mat, Col, Row and Cube

  • Obtain a raw pointer to the memory used for storing elements

  • The function can be used for interfacing with libraries such as FFTW

  • Data for matrices is stored in a column-by-column order

  • Data for cubes is stored in a slice-by-slice (matrix-by-matrix) order

  • Caveat: the pointer becomes invalid after any operation involving a size change or aliasing

  • Caveat: this function is not recommended for use unless you know what you are doing!

  • Examples:
            mat A = randu<mat>(5,5);
      const mat B = randu<mat>(5,5);
      
            double* A_mem = A.memptr();
      const double* B_mem = B.memptr();
      

  • See also:



.colptr( col_number )


iterators (matrices & vectors)
  • STL-style iterators and associated member functions of Mat, Col, Row and SpMat

  • Member functions:

      .begin()  
      iterator referring to the first element
      .end()  
      iterator referring to the past-the-end element
       
      .begin_row( row_number )  
      iterator referring to the first element of the specified row
      .end_row( row_number )  
      iterator referring to the past-the-end element of the specified row
       
      .begin_col( col_number )  
      iterator referring to the first element of the specified column
      .end_col( col_number )  
      iterator referring to the past-the-end element of the specified column

  • Iterator types:

      mat::iterator
      vec::iterator
      rowvec::iterator
      sp_mat::iterator
       
      random access iterators, for read/write access to elements (which are stored column by column)
         
       
      mat::const_iterator
      vec::const_iterator
      rowvec::const_iterator
      sp_mat::const_iterator
       
      random access iterators, for read-only access to elements (which are stored column by column)
         
       
      mat::col_iterator
      vec::col_iterator
      rowvec::col_iterator
       
      random access iterators, for read/write access to the elements of a specific column
         
       
      mat::const_col_iterator
      vec::const_col_iterator
      rowvec::const_col_iterator
       
      random access iterators, for read-only access to the elements of a specific column
         
       
      mat::row_iterator
      sp_mat::row_iterator
       
      rudimentary forward iterator, for read/write access to the elements of a specific row
         
       
      mat::const_row_iterator
      sp_mat::const_row_iterator
       
      rudimentary forward iterator, for read-only access to the elements of a specific row
         
       
      vec::row_iterator
      rowvec::row_iterator
       
      random access iterators, for read/write access to the elements of a specific row
         
       
      vec::const_row_iterator
      rowvec::const_row_iterator
       
      random access iterators, for read-only access to the elements of a specific row

  • Examples:
      mat X = randu<mat>(5,5);
      
      
      mat::iterator a = X.begin();
      mat::iterator b = X.end();
      
      for(mat::iterator i=a; i!=b; ++i)
        {
        cout << *i << endl;
        }
      
      
      mat::col_iterator c = X.begin_col(1);  // start of column 1
      mat::col_iterator d = X.end_col(3);    // end of column 3
      
      for(mat::col_iterator i=c; i!=d; ++i)
        {
        cout << *i << endl;
        (*i) = 123.0;
        }
      

  • See also:



iterators (cubes)
  • STL-style iterators and associated member functions of Cube

  • Member functions:

      .begin()  
      iterator referring to the first element
      .end()  
      iterator referring to the past-the-end element
       
      .begin_slice( slice_number )  
      iterator referring to the first element of the specified slice
      .end_slice( slice_number )  
      iterator referring to the past-the-end element of the specified slice

  • Iterator types:

      cube::iterator  
      random access iterator, for read/write access to elements; the elements are ordered slice by slice; the elements within each slice are ordered column by column
         
       
      cube::const_iterator  
      random access iterators, for read-only access to elements
         
       
      cube::slice_iterator  
      random access iterator, for read/write access to the elements of a particular slice; the elements are ordered column by column
         
       
      cube::const_slice_iterator  
      random access iterators, for read-only access to the elements of a particular slice

  • Examples:
      cube X = randu<cube>(2,3,4);
      
      
      cube::iterator a = X.begin();
      cube::iterator b = X.end();
      
      for(cube::iterator i=a; i!=b; ++i)
        {
        cout << *i << endl;
        }
      
      
      cube::slice_iterator c = X.begin_slice(1);  // start of slice 1
      cube::slice_iterator d = X.end_slice(2);    // end of slice 2
      
      for(cube::slice_iterator i=c; i!=d; ++i)
        {
        cout << *i << endl;
        (*i) = 123.0;
        }
      

  • See also:



STL-style container functions
  • Member functions that mimic the containers in the C++ Standard Template Library:

    .clear()  
    causes an object to have no elements
    .empty()  
    returns true if the object has no elements; returns false if the object has one or more elements
    .size()  
    returns the total number of elements

  • Examples:
      mat A = randu<mat>(5,5);
      cout << A.size() << endl;
      
      A.clear();
      cout << A.empty() << endl;
      

  • See also:



.t()
.st()
  • Member functions of any matrix or vector expression

  • For real (non-complex) matrix:
    • .t() provides a transposed copy of the matrix
    • .st() not applicable

  • For complex matrix:
    • .t() provides a Hermitian transpose (ie. the conjugate of the elements is taken during the transpose)
    • .st() provides a transposed copy without taking the conjugate of the elements

  • Examples:
      mat A = randu<mat>(4,5);
      mat B = A.t();
      

  • See also:



.i()
  • Member function of any matrix expression

  • Provides an inverse of the matrix expression

  • If the matrix expression is not square sized, a std::logic_error exception is thrown

  • If the matrix expression appears to be singular, the output matrix is reset and a std::runtime_error exception is thrown

  • Caveats:
    • if matrix A is know to be symmetric positive definite, it's faster to use inv_sympd() instead
    • to solve a system of linear equations, such as Z = inv(X)*Y, it is faster and more accurate to use solve() instead

  • Examples:
      mat A = randu<mat>(4,4);
      mat B = randu<mat>(4,1);
      
      mat X = A.i();
      
      mat Y = (A+A).i();
      
  • See also:



.min()
  (member functions of Mat, Col, Row, SpMat, Cube)
.max()
   
 
   
.min( index_of_min_val )
  (member functions of Mat, Col, Row, SpMat, Cube)
.max( index_of_max_val )
   
 
   
.min( row_of_min_val, col_of_min_val )
  (member functions of Mat and SpMat)
.max( row_of_max_val, col_of_max_val )
   
 
   
.min( row_of_min_val, col_of_min_val, slice_of_min_val )
  (member functions of Cube)
.max( row_of_max_val, col_of_max_val, slice_of_max_val )
   
  • Without arguments: return the extremum value of an object

  • With one or more arguments: return the extremum value of an object and store the location of the extremum value in the provided variable(s)

  • The provided variables must be of type uword

  • Examples:
      vec v = randu<vec>(10);
      
      cout << "min value is " << v.min() << endl;
      
      
      uword  index;
      double min_val = v.min(index);
      
      cout << "index of min value is " << index << endl;
      
      
      mat A = randu<mat>(5,5);
      
      uword  row;
      uword  col;
      double min_val2 = A.max(row,col);
      
      cout << "max value is at " << row << ',' << col << endl;
      

  • See also:



.eval()
  • Member function of any matrix or vector expression

  • Explicitly forces the evaluation of a delayed expression and outputs a matrix

  • This function should be used sparingly and only in cases where it is absolutely necessary; indiscriminate use can cause slow downs

  • Examples:
      cx_mat A( randu<mat>(4,4), randu<mat>(4,4) );
      
      real(A).eval().save("A_real.dat", raw_ascii);
      imag(A).eval().save("A_imag.dat", raw_ascii);
      

  • See also:



.in_range( i )
  (member of Mat, Col, Row, Cube, SpMat, field)
.in_range( span(start, end) )
  (member of Mat, Col, Row, Cube, SpMat, field)
 
.in_range( row, col )
  (member of Mat, Col, Row, SpMat, field)
.in_range( span(start_row, end_row), span(start_col, end_col) )
  (member of Mat, Col, Row, SpMat, field)
 
.in_range( row, col, slice )
  (member of Cube and field)
.in_range( span(start_row, end_row), span(start_col, end_col), span(start_slice, end_slice) )
  (member of Cube and field)
 
.in_range( first_row, first_col, size(X) )   (X is a matrix or field)
  (member of Mat, Col, Row, SpMat, field)
.in_range( first_row, first_col, size(n_rows, n_cols) )
  (member of Mat, Col, Row, SpMat, field)
 
.in_range( first_row, first_col, first_slice, size(Q) )   (Q is a cube or field)
  (member of Cube and field)
.in_range( first_row, first_col, first_slice, size(n_rows, n_cols n_slices) )
  (member of Cube and field)
  • Returns true if the given location or span is currently valid

  • Returns false if the object is empty, the location is out of bounds, or the span is out of bounds

  • Instances of span(a,b) can be replaced by:
    • span() or span::all, to indicate the entire range
    • span(a), to indicate a particular row, column or slice

  • Examples:
      mat A = randu<mat>(4,5);
      
      cout << A.in_range(0,0) << endl;  // true
      cout << A.in_range(3,4) << endl;  // true
      cout << A.in_range(4,5) << endl;  // false
      

  • See also:



.is_empty()
  • Returns true if the object has no elements

  • Returns false if the object has one or more elements

  • Examples:
      mat A = randu<mat>(5,5);
      cout << A.is_empty() << endl;
      
      A.reset();
      cout << A.is_empty() << endl;
      

  • See also:



.is_square()
  • Member function of Mat and SpMat

  • Returns true if the matrix is square, ie. number of rows is equal to the number of columns

  • Returns false if the matrix is not square

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = randu<mat>(6,7);
      
      cout << A.is_square() << endl;
      cout << B.is_square() << endl;
      

  • See also:



.is_vec()
.is_colvec()
.is_rowvec()
  • Member functions of Mat and SpMat

  • .is_vec():
    • returns true if the matrix can be interpreted as a vector (either column or row vector)
    • returns false if the matrix does not have exactly one column or one row

  • .is_colvec():
    • returns true if the matrix can be interpreted as a column vector
    • returns false if the matrix does not have exactly one column

  • .is_rowvec():
    • returns true if the matrix can be interpreted as a row vector
    • returns false if the matrix does not have exactly one row

  • Caveat: do not assume that the vector has elements if these functions return true; it is possible to have an empty vector (eg. 0x1)

  • Examples:
      mat A = randu<mat>(1,5);
      mat B = randu<mat>(5,1);
      mat C = randu<mat>(5,5);
      
      cout << A.is_vec() << endl;
      cout << B.is_vec() << endl;
      cout << C.is_vec() << endl;
      

  • See also:



.is_sorted()
.is_sorted( sort_direction )
.is_sorted( sort_direction, dim )
  • Member function of Mat, Row and Col

  • If the object is a vector, return a bool indicating whether the elements are sorted

  • If the object is a matrix, return a bool indicating whether the elements in each column (dim=0) or each row (dim=1) are sorted

  • The sort_direction argument is optional; sort_direction is either "ascend" or "descend"; by default "ascend" is used

  • The dim argument is optional; by default dim=0 is used

  • For matrices and vectors with complex numbers, order is checked via absolute values

  • Examples:
      vec a = randu<vec>(10);
      vec b = sort(a);
      
      bool check1 = a.is_sorted();
      bool check2 = b.is_sorted();
      
      
      mat A = randu<mat>(10,10);
      
      // check whether each column is sorted in descending manner
      cout << A.is_sorted("descend") << endl;
      
      // check whether each row is sorted in ascending manner
      cout << A.is_sorted("ascend", 1) << endl;
      

  • See also:



.is_finite()
  • Member function of Mat, Col, Row, Cube, SpMat

  • Returns true if all elements of the object are finite

  • Returns false if at least one of the elements of the object is non-finite (±infinity or NaN)

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = randu<mat>(5,5);
      
      B(1,1) = datum::inf;
      
      cout << A.is_finite() << endl;
      cout << B.is_finite() << endl;
      

  • See also:



.has_inf()
  • Member function of Mat, Col, Row, Cube, SpMat

  • Returns true if at least one of the elements of the object is ±infinity

  • Returns false otherwise

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = randu<mat>(5,5);
      
      B(1,1) = datum::inf;
      
      cout << A.has_inf() << endl;
      cout << B.has_inf() << endl;
      

  • See also:



.has_nan()
  • Member function of Mat, Col, Row, Cube, SpMat

  • Returns true if at least one of the elements of the object is NaN (not-a-number)

  • Returns false otherwise

  • Caveat: NaN is not equal to anything, even itself

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = randu<mat>(5,5);
      
      B(1,1) = datum::nan;
      
      cout << A.has_nan() << endl;
      cout << B.has_nan() << endl;
      

  • See also:



.print()
.print( header )

.print( stream )
.print( stream, header )
  • Member functions of Mat, Col, Row, SpMat, Cube and field

  • Print the contents of an object to the std::cout stream (default), or a user specified stream, with an optional header string

  • Objects can also be printed using the << stream operator

  • Elements of a field can only be printed if there is an associated operator<< function defined

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = randu<mat>(6,6);
      
      A.print();
      
      // print a transposed version of A
      A.t().print();
      
      // "B:" is the optional header line
      B.print("B:");
      
      cout << A << endl;
      
      cout << "B:" << endl;
      cout << B << endl;
      

  • See also:



.raw_print()
.raw_print( header )

.raw_print( stream )
.raw_print( stream, header )
  • Member functions of Mat, Col, Row, SpMat and Cube

  • Similar to the .print() member function, with the difference that no formatting of the output is done -- ie. the user can set the stream's parameters such as precision, cell width, etc.

  • If the cell width is set to zero, a space is printed between the elements

  • Examples:
      mat A = randu<mat>(5,5);
      
      cout.precision(11);
      cout.setf(ios::fixed);
      
      A.raw_print(cout, "A =");
      



saving/loading matrices & cubes

.save( name )
.save( name, file_type )

.save( stream )
.save( stream, file_type )

.load( name )
.load( name, file_type )

.load( stream )
.load( stream, file_type )
  • Member functions of Mat, Col, Row and Cube

  • Store/retrieve data in a file or stream
    • caveat: the stream must be opened in binary mode

  • The default file_type for .save() is arma_binary (see below)

  • The default file_type for .load() is auto_detect (see below)

  • On success, .save() and .load() will return a bool set to true

  • .save() will return a bool set to false if the saving process fails

  • .load() will return a bool set to false if the loading process fails; additionally, the object will be reset so it has no elements

  • file_type can be one of the following:

      auto_detect
      Used by .load() only: try to automatically detect the file type as one of the formats described below. This is the default operation.

      raw_ascii
      Numerical data stored in raw ASCII format, without a header. The numbers are separated by whitespace. The number of columns must be the same in each row. Cubes are loaded as one slice. Data which was saved in Matlab/Octave using the -ascii option can be read in Armadillo, except for complex numbers. Complex numbers are stored in standard C++ notation, which is a tuple surrounded by brackets: eg. (1.23,4.56) indicates 1.24 + 4.56i.

      raw_binary
      Numerical data stored in machine dependent raw binary format, without a header. Matrices are loaded to have one column, while cubes are loaded to have one slice with one column. The .reshape() function can be used to alter the size of the loaded matrix/cube without losing data.

      arma_ascii
      Numerical data stored in human readable text format, with a simple header to speed up loading. The header indicates the type of matrix as well as the number of rows and columns. For cubes, the header additionally specifies the number of slices.

      arma_binary
      Numerical data stored in machine dependent binary format, with a simple header to speed up loading. The header indicates the type of matrix as well as the number of rows and columns. For cubes, the header additionally specifies the number of slices. arma_binary is the default file_type for .save()

      csv_ascii
      Numerical data stored in comma separated value (CSV) text format, without a header. Applicable to Mat only.

      hdf5_binary
      Numerical data stored in portable HDF5 binary format.
      Caveat: support for HDF5 must be enabled within Armadillo's configuration; the hdf5.h header file must be available on your system and you will need to link with the hdf5 library (eg. -lhdf5)

      pgm_binary
      Image data stored in Portable Gray Map (PGM) format. Applicable to Mat only. Saving int, float or double matrices is a lossy operation, as each element is copied and converted to an 8 bit representation. As such the matrix should have values in the [0,255] interval, otherwise the resulting image may not display correctly.

      ppm_binary
      Image data stored in Portable Pixel Map (PPM) format. Applicable to Cube only. Saving int, float or double matrices is a lossy operation, as each element is copied and converted to an 8 bit representation. As such the cube/field should have values in the [0,255] interval, otherwise the resulting image may not display correctly.


  • Examples:
      mat A = randu<mat>(5,5);
      
      A.save("A1.mat");  // default save format is arma_binary
      
      A.save("A2.mat", arma_ascii);  // force saving in arma_ascii format
      
      mat B;
      B.load("A1.mat");  // automatically detect format type
      
      mat C;
      C.load("A2.mat", arma_ascii);  // force loading in arma_ascii format
      
      
      // example of testing for success
      mat D;
      bool status = D.load("A2.mat");
      
      if(status == true)
        {
        cout << "loaded okay" << endl;
        }
      else
        {
        cout << "problem with loading" << endl;
        }
      

  • See also:



saving/loading fields

.save( name )
.save( name, file_type )

.save( stream )
.save( stream, file_type )

.load( name )
.load( name, file_type )

.load( stream )
.load( stream, file_type )
  • Member functions of field

  • Store/retrieve data in a file or stream
    • caveat: the stream must be opened in binary mode

  • On success, .save() and .load() will return a bool set to true

  • .save() will return a bool set to false if the saving process fails

  • .load() will return a bool set to false if the loading process fails; additionally, the field will be reset so it has no elements

  • Fields with objects of type std::string are saved and loaded as raw text files. The text files do not have a header. Each string is separated by a whitespace. load() will only accept text files that have the same number of strings on each line. The strings can have variable lengths.

  • Other than storing string fields as text files, the following file formats are supported:

      auto_detect

    • .load(): try to automatically detect the field format type as one of the formats described below; this is the default operation.

    • arma_binary

    • Objects are stored in machine dependent binary format
    • Default type for fields of type Mat, Col, Row or Cube
    • Only applicable to fields of type Mat, Col, Row or Cube

    • ppm_binary

    • Image data stored in Portable Pixmap Map (PPM) format.
    • Only applicable to fields of type Mat, Col or Row
    • .load(): loads the specified image and stores the red, green and blue components as three separate matrices; the resulting field is comprised of the three matrices, with the red, green and blue components in the first, second and third matrix, respectively
    • .save(): saves a field with exactly three matrices of equal size as an image; it is assumed that the red, green and blue components are stored in the first, second and third matrix, respectively; saving int, float or double matrices is a lossy operation, as each matrix element is copied and converted to an 8 bit representation

  • See also:





Generated Vectors/Matrices



eye( n_rows, n_cols )
eye( size(X) )
  • Generate a matrix with the elements along the main diagonal set to one and off-diagonal elements set to zero

  • An identity matrix is generated when n_rows = n_cols

  • Usage:
    • matrix_type X = eye<matrix_type>( n_rows, n_cols )
    • matrix_type Y = eye<matrix_type>( size(X) )

  • Examples:
      mat A = eye<mat>(5,5);  // or:  mat A(5,5,fill::eye);
      
      mat B = 123.0 * eye<mat>(5,5);
      
      mat C = eye<mat>( size(B) );
      

  • See also:



linspace( start, end )
linspace( start, end, N )
  • Generate a vector with N elements; the values of the elements linearly increase from start to (and including) end

  • By default N = 100

  • Usage:
    • vector_type v = linspace<vector_type>(start, end, N)
    • matrix_type X = linspace<matrix_type>(start, end, N)

  • If a matrix_type is specified, the resultant matrix will have one column

  • Examples:
      vec v = linspace<vec>(10, 20, 5);
      mat X = linspace<mat>(10, 20, 5);
      

  • See also:



ones( n_elem )
ones( n_rows, n_cols )
ones( n_rows, n_cols, n_slices )
ones( size(X) )
  • Generate a vector, matrix or cube with all elements set to one

  • Usage:
    • vector_type v = ones<vector_type>( n_elem )
    • matrix_type X = ones<matrix_type>( n_rows, n_cols )
    • matrix_type Y = ones<matrix_type>( size(X) )
    • cube_type Q = ones<cube_type>( n_rows, n_cols, n_slices )
    • cube_type R = ones<cube_type>( size(Q) )

  • Examples:
      vec  v = ones<vec>(10);
      uvec u = ones<uvec>(11);
      mat  A = ones<mat>(5,6);
      cube Q = ones<cube>(5,6,7);
      
      mat  B = 123.0 * ones<mat>(5,6);
      

  • See also:



randi( n_elem )
randi( n_elem, distr_param(a,b) )

randi( n_rows, n_cols )
randi( n_rows, n_cols, distr_param(a,b) )

randi( n_rows, n_cols, n_slices )
randi( n_rows, n_cols, n_slices, distr_param(a,b) )

randi( size(X) )
randi( size(X), distr_param(a,b) )
  • Generate a vector, matrix or cube with the elements set to random integer values in the [a,b] interval

  • The default distribution parameters are a=0 and b=maximum_int

  • Usage:
    • vector_type v = randi<vector_type>( n_elem)
    • vector_type v = randi<vector_type>( n_elem, distr_param(a,b) )

    • matrix_type X = randi<matrix_type>( n_rows, n_cols )
    • matrix_type X = randi<matrix_type>( n_rows, n_cols, distr_param(a,b) )
    • matrix_type Y = randi<matrix_type>( size(X) )
    • matrix_type Y = randi<matrix_type>( size(X), distr_param(a,b) )

    • cube_type Q = randi<cube_type>( n_rows, n_cols, n_slices )
    • cube_type Q = randi<cube_type>( n_rows, n_cols, n_slices, distr_param(a,b) )
    • cube_type R = randi<cube_type>( size(Q) )
    • cube_type R = randi<cube_type>( size(Q), distr_param(a,b) )

  • To change the RNG seed, use arma_rng::set_seed(value) or arma_rng::set_seed_random() functions

  • Caveat: to generate a continuous distribution with floating point values (ie. float or double), use randu() or randn() instead

  • Examples:
      imat A = randi<imat>(5, 6);
      
      imat A = randi<imat>(6, 7, distr_param(-10, +20));
      
      arma_rng::set_seed_random();  // set the seed to a random value
      
  • See also:



randu( n_elem )
randu( n_rows, n_cols )
randu( n_rows, n_cols, n_slices )
randu( size(X) )

randn( n_elem )
randn( n_rows, n_cols )
randn( n_rows, n_cols, n_slices )
randn( size(X) )
  • Generate a vector, matrix or cube with the elements set to random floating point values

  • randu() uses a uniform distribution in the [0,1] interval

  • randn() uses a normal/Gaussian distribution with zero mean and unit variance

  • Usage:
    • vector_type v = randu<vector_type>( n_elem )
    • matrix_type X = randu<matrix_type>( n_rows, n_cols )
    • matrix_type Y = randu<matrix_type>( size(X) )
    • cube_type Q = randu<cube_type>( n_rows, n_cols, n_slices )
    • cube_type R = randu<cube_type>( size(Q) )

  • To change the RNG seed, use arma_rng::set_seed(value) or arma_rng::set_seed_random() functions

  • Caveat: to generate a matrix with random integer values instead of floating point values, use randi() instead

  • Examples:
      vec  v = randu<vec>(5);
      mat  A = randu<mat>(5,6);
      cube Q = randu<cube>(5,6,7);
      
      arma_rng::set_seed_random();  // set the seed to a random value
      
  • See also:



randg( n_elem )
randg( n_elem, distr_param(a,b) )

randg( n_rows, n_cols )
randg( n_rows, n_cols, distr_param(a,b) )

randg( n_rows, n_cols, n_slices )
randg( n_rows, n_cols, n_slices, distr_param(a,b) )

randg( size(X) )
randg( size(X), distr_param(a,b) )
  • Generate a vector, matrix or cube with the elements set to random values from a gamma distribution:
        x a-1 exp( -x / b )
      p(x|a,b) = 
        b a Γ(a)

  • The default distribution parameters are a=1 and b=1

  • Usage:
    • vector_type v = randg<vector_type>( n_elem)
    • vector_type v = randg<vector_type>( n_elem, distr_param(a,b) )

    • matrix_type X = randg<matrix_type>( n_rows, n_cols )
    • matrix_type X = randg<matrix_type>( n_rows, n_cols, distr_param(a,b) )
    • matrix_type Y = randg<matrix_type>( size(X) )
    • matrix_type Y = randg<matrix_type>( size(X), distr_param(a,b) )

    • cube_type Q = randg<cube_type>( n_rows, n_cols, n_slices )
    • cube_type Q = randg<cube_type>( n_rows, n_cols, n_slices, distr_param(a,b) )
    • cube_type R = randg<cube_type>( size(Q) )
    • cube_type R = randg<cube_type>( size(Q), distr_param(a,b) )

  • Caveat: randg() is available only when using a C++11 compiler

  • To change the RNG seed, use arma_rng::set_seed(value) or arma_rng::set_seed_random() functions

  • Examples:
      vec v = randg<vec>(100, distr_param(2,1));
      
      mat X = randg<mat>(10, 10, distr_param(2,1));
      
  • See also:



speye( n_rows, n_cols )
speye( size(X) )
  • Generate a sparse matrix with the elements along the main diagonal set to one and off-diagonal elements set to zero

  • An identity matrix is generated when n_rows = n_cols

  • Usage:
    • sparse_matrix_type X = speye<sparse_matrix_type>( n_rows, n_cols )
    • sparse_matrix_type Y = speye<sparse_matrix_type>( size(X) )

  • Examples:
      sp_mat A = speye<sp_mat>(5,5);
      

  • See also:



spones( A )
  • Generate a sparse matrix with the same structure as sparse matrix A, but with the non-zero elements set to one

  • Examples:
      sp_mat A = sprandu<sp_mat>(100, 200, 0.1);
      
      sp_mat B = spones(A);
      
  • See also:



sprandu( n_rows, n_cols, density )
sprandn( n_rows, n_cols, density )

sprandu( size(X), density )
sprandn( size(X), density )
  • Generate a sparse matrix with the non-zero elements set to random values

  • The density argument specifies the percentage of non-zero elements; it must be in the [0,1] interval

  • sprandu() uses a uniform distribution in the [0,1] interval

  • sprandn() uses a normal/Gaussian distribution with zero mean and unit variance

  • Usage:
    • sparse_matrix_type X = sprandu<sparse_matrix_type>( n_rows, n_cols, density )
    • sparse_matrix_type Y = sprandu<sparse_matrix_type>( size(X), density )

  • To change the RNG seed, use arma_rng::set_seed(value) or arma_rng::set_seed_random() functions

  • Examples:
      sp_mat A = sprandu<sp_mat>(100, 200, 0.1);
      
  • See also:



toeplitz( A )
toeplitz( A, B )
circ_toeplitz( A )


zeros( n_elem )
zeros( n_rows, n_cols )
zeros( n_rows, n_cols, n_slices )
zeros( size(X) )
  • Generate a vector, matrix or cube with the elements set to zero

  • Usage:
    • vector_type v = zeros<vector_type>( n_elem )
    • matrix_type X = zeros<matrix_type>( n_rows, n_cols )
    • matrix_type Y = zeros<matrix_type>( size(X) )
    • cube_type Q = zeros<cube_type>( n_rows, n_cols, n_slices )
    • cube_type R = zeros<cube_type>( size(Q) )

  • Examples:
      vec  v = zeros<vec>(10);
      uvec u = zeros<uvec>(11);
      mat  A = zeros<mat>(5,6);
      cube Q = zeros<cube>(5,6,7);
      

  • See also:





Functions of Vectors/Matrices/Cubes



abs( X )
  • Obtain the magnitude of each element

  • Usage for non-complex matrices and cubes:
    • matrix_type Y = abs(X)
    • cube_type Y = abs(X)
    • X and Y must have the same matrix_type / cube_type

  • Usage for complex matrices and cubes:
    • non_complex_matrix_type Y = abs(X)
    • non_complex_cube_type Y = abs(X)
    • X must be a have complex matrix / cube type, eg. cx_mat or cx_cube
    • The type of Y must be related to the type of X, eg. if X has the type cx_mat, then the type of Y must be mat

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = abs(A); 
      
      cx_mat X = randu<cx_mat>(5,5);
      mat    Y = abs(X);
      
  • See also:



accu( X )
  • Accumulate (sum) all elements of a vector, matrix or cube

  • Examples:
      mat A(5, 6, fill::randu);
      mat B(5, 6, fill::randu);
      
      double x = accu(A);
      
      double y = accu(A % B);
      
      // accu(A % B) is a "multiply-and-accumulate" operation
      // as operator % performs element-wise multiplication
      

  • See also:



all( V )
all( X )
all( X, dim )
  • For vector V, return true if all elements of the vector are non-zero or satisfy a relational condition

  • For matrix X and
    • dim=0, return a row vector (of type urowvec or umat), with each element (0 or 1) indicating whether the corresponding column of X has all non-zero elements

    • dim=1, return a column vector (of type ucolvec or umat), with each element (0 or 1) indicating whether the corresponding row of X has all non-zero elements

  • The dim argument is optional; by default dim=0 is used

  • Relational operators can be used instead of V or X, eg. A > 0.5

  • Examples:
      vec V = randu<vec>(10);
      mat X = randu<mat>(5,5);
      
      
      // status1 will be set to true if vector V has all non-zero elements
      bool status1 = all(V);
      
      // status2 will be set to true if vector V has all elements greater than 0.5
      bool status2 = all(V > 0.5);
      
      // status3 will be set to true if matrix X has all elements greater than 0.6;
      // note the use of vectorise()
      bool status3 = all(vectorise(X) > 0.6);
      
      // generate a row vector indicating which columns of X have all elements greater than 0.7
      umat A = all(X > 0.7);
      
      

  • See also:



any( V )
any( X )
any( X, dim )
  • For vector V, return true if any element of the vector is non-zero or satisfies a relational condition

  • For matrix X and
    • dim=0, return a row vector (of type urowvec or umat), with each element (0 or 1) indicating whether the corresponding column of X has any non-zero elements

    • dim=1, return a column vector (of type ucolvec or umat), with each element (0 or 1) indicating whether the corresponding row of X has any non-zero elements

  • The dim argument is optional; by default dim=0 is used

  • Relational operators can be used instead of V or X, eg. A > 0.9

  • Examples:
      vec V = randu<vec>(10);
      mat X = randu<mat>(5,5);
      
      
      // status1 will be set to true if vector V has any non-zero elements
      bool status1 = any(V);
      
      // status2 will be set to true if vector V has any elements greater than 0.5
      bool status2 = any(V > 0.5);
      
      // status3 will be set to true if matrix X has any elements greater than 0.6;
      // note the use of vectorise()
      bool status3 = any(vectorise(X) > 0.6);
      
      // generate a row vector indicating which columns of X have elements greater than 0.7
      umat A = any(X > 0.7);
      
      

  • See also:



as_scalar( expression )
  • Evaluate an expression that results in a 1x1 matrix, followed by converting the 1x1 matrix to a pure scalar

  • If a binary or trinary expression is given (ie. 2 or 3 terms), the function will try to exploit the fact that the result is a 1x1 matrix by using optimised expression evaluations

  • Examples:
      rowvec r = randu<rowvec>(5);
      colvec q = randu<colvec>(5);
      mat    X = randu<mat>(5,5);
      
      // examples of some expressions
      // for which optimised implementations exist
      
      double a = as_scalar(r*q);
      double b = as_scalar(r*X*q);
      double c = as_scalar(r*diagmat(X)*q);
      double d = as_scalar(r*inv(diagmat(X))*q);
      

  • See also:



clamp( X, min_val, max_val )
  • Create a copy of X with each element clamped to be between min_val and max_val

  • Examples:
      mat A = randu<mat>(5,5);
      
      mat B = clamp(A, 0.2, 0.8); 
      
      mat C = clamp(A, A.min(), 0.8); 
      
      mat D = clamp(A, 0.2, A.max()); 
      
  • See also:



cond( A )
  • Return the condition number of matrix A (the ratio of the largest singular value to the smallest)

  • Large condition numbers suggest that matrix A is nearly singular

  • The computation is based on singular value decomposition; if the decomposition fails, a std::runtime_error exception is thrown

  • Caveat: the rcond() function is faster for providing an estimate of the reciprocal of the condition number

  • Examples:
      mat    A = randu<mat>(5,5);
      double c = cond(A);
      

  • See also:



conj( X )
  • Obtain the complex conjugate of each element in a complex matrix or cube

  • Examples:
      cx_mat X = randu<cx_mat>(5,5);
      cx_mat Y = conj(X);
      

  • See also:



conv_to< type >::from( X )
  • Convert from one matrix type to another (eg. mat to imat), or one cube type to another (eg. cube to icube)

  • Conversion between std::vector and Armadillo matrices/vectors is also possible

  • Conversion of a mat object into colvec, rowvec or std::vector is possible if the object can be interpreted as a vector

  • Examples:
      mat  A = randu<mat>(5,5);
      fmat B = conv_to<fmat>::from(A);
      
      typedef std::vector<double> stdvec;
      
      stdvec x(3);
      x[0] = 0.0; x[1] = 1.0;  x[2] = 2.0;
      
      colvec y = conv_to< colvec >::from(x);
      stdvec z = conv_to< stdvec >::from(y); 
      

  • See also:



cross( A, B )


cumsum( V )
cumsum( X )
cumsum( X, dim )
  • For vector V, return a vector of the same orientation, containing the cumulative sum of elements

  • For matrix X, return a matrix containing the cumulative sum of elements in each column (dim=0), or each row (dim=1)

  • The dim argument is optional; by default dim=0 is used

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = cumsum(A);
      mat C = cumsum(A, 1);
      
      vec x = randu<vec>(10);
      vec y = cumsum(x);
      

  • See also:



cumprod( V )
cumprod( X )
cumprod( X, dim )
  • For vector V, return a vector of the same orientation, containing the cumulative product of elements

  • For matrix X, return a matrix containing the cumulative product of elements in each column (dim=0), or each row (dim=1)

  • The dim argument is optional; by default dim=0 is used

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = cumprod(A);
      mat C = cumprod(A, 1);
      
      vec x = randu<vec>(10);
      vec y = cumprod(x);
      

  • See also:



det( A )
log_det( val, sign, A )
  • Determinant of square matrix A

  • If A is not square sized, a std::logic_error exception is thrown

  • log_det(): find the log determinant, such that the determinant is equal to exp(val)*sign

  • Caveat: for large matrices log_det() is more precise than det()

  • Examples:
      mat    A = randu<mat>(5,5);
      double x = det(A);
      
      double val;
      double sign;
      
      log_det(val, sign, A);
      

  • See also:



diagmat( V )
diagmat( V, k )
diagmat( X )
diagmat( X, k )
  • Generate a diagonal matrix from vector V or matrix X

  • Given vector V, generate a square matrix with the k-th diagonal containing a copy of the vector; all other elements are set to zero

  • Given matrix X, generate a matrix with the k-th diagonal containing a copy of the k-th diagonal of X; all other elements are set to zero

  • The argument k is optional; by default the main diagonal is used (k=0)

  • For k > 0, the k-th super-diagonal is used (top-right corner)

  • For k < 0, the k-th sub-diagonal is used (bottom-left corner)

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = diagmat(A);
      mat C = diagmat(A,1);
      
      vec v = randu<vec>(5);
      mat D = diagmat(v);
      mat E = diagmat(v,1);
      

  • See also:



diagvec( A )
diagvec( A, k )
  • Extract the k-th diagonal from matrix A

  • The argument k is optional; by default the main diagonal is extracted (k=0)

  • For k > 0, the k-th super-diagonal is extracted (top-right corner)

  • For k < 0, the k-th sub-diagonal is extracted (bottom-left corner)

  • The extracted diagonal is interpreted as a column vector

  • Examples:
      mat A = randu<mat>(5,5);
      
      vec d = diagvec(A);
      

  • See also:



diff( V )
diff( V, k )

diff( X )
diff( X, k )
diff( X, k, dim )
  • For vector V, return a vector of the same orientation, containing the differences between consecutive elements

  • For matrix X, return a matrix containing the differences between consecutive elements in each column (dim=0), or each row (dim=1)

  • The optional argument k indicates that the differences are calculated recursively k times; by default k=1 is used

  • The resulting number of differences is n - k, where n is the number of elements; if n ≤ k, the number of differences is zero (ie. an empty vector/matrix is returned)

  • The argument dim is optional; by default dim=0

  • Examples:
      vec a = linspace<vec>(1,10,10);
      
      vec b = diff(a);
      

  • See also:



dot( A, B )
cdot( A, B )
norm_dot( A, B )
  • dot(A,B): dot product of A and B, treating A and B as vectors

  • cdot(A,B): as per dot(A,B), but the complex conjugate of A is used

  • norm_dot(A,B): equivalent to dot(A,B) / (∥A∥•∥B∥)

  • Caveat: to calculate the norm, the norm() function is more robust

  • Examples:
      vec a = randu<vec>(10);
      vec b = randu<vec>(10);
      
      double x = dot(a,b);
      

  • See also:



eps( X )


expmat( X )


find( X )
find( X, k )
find( X, k, s )
  • Return a column vector containing the indices of elements of X that are non-zero or satisfy a relational condition

  • The output vector must have the type uvec (ie. the indices are stored as unsigned integers of type uword)

  • X is interpreted as a vector, with column-by-column ordering of the elements of X

  • Relational operators can be used instead of X, eg. A > 0.5

  • If k=0 (default), return the indices of all non-zero elements, otherwise return at most k of their indices

  • If s="first" (default), return at most the first k indices of the non-zero elements

  • If s="last", return at most the last k indices of the non-zero elements

  • Examples:
      mat  A  = randu<mat>(5,5);
      mat  B  = randu<mat>(5,5);
      
      uvec q1 = find(A > B);
      uvec q2 = find(A > 0.5);
      uvec q3 = find(A > 0.5, 3, "last");
      
      // change elements of A greater than 0.5 to 1
      A.elem( find(A > 0.5) ).ones();
      

  • See also:



find_finite( X )
  • Return a column vector containing the indices of elements of X that are finite (ie. not ±Inf and not NaN)

  • The output vector must have the type uvec (ie. the indices are stored as unsigned integers of type uword)

  • X is interpreted as a vector, with column-by-column ordering of the elements of X

  • Examples:
      mat A = randu<mat>(5,5);
      
      A(1,1) = datum::inf;
      
      // accumulate only finite elements
      double val = accu( A.elem( find_finite(A) ) );
      

  • See also:



find_nonfinite( X )
  • Return a column vector containing the indices of elements of X that are non-finite (ie. ±Inf or NaN)

  • The output vector must have the type uvec (ie. the indices are stored as unsigned integers of type uword)

  • X is interpreted as a vector, with column-by-column ordering of the elements of X

  • Examples:
      mat A = randu<mat>(5,5);
      
      A(1,1) = datum::inf;
      
      // change non-finite elements to zero
      A.elem( find_nonfinite(A) ).zeros();
      

  • See also:



find_unique( X )
find_unique( X, ascending_indices )
  • Return a column vector containing the indices of unique elements of X

  • The output vector must have the type uvec (ie. the indices are stored as unsigned integers of type uword)

  • X is interpreted as a vector, with column-by-column ordering of the elements of X

  • The ascending_indices argument is optional; it is one of:
      true = the returned indices are sorted to be ascending (default setting)
      false = the returned indices are in arbitrary order (faster operation)

  • Examples:
      mat A;
      
      A << 2 << 2 << 4 << endr
        << 4 << 6 << 6 << endr;
      
      uvec indices = find_unique(A);
      

  • See also:



fliplr( X )
flipud( X )
  • fliplr(): generate a copy of matrix X, with the order of the columns reversed

  • flipud(): generate a copy of matrix X, with the order of the rows reversed

  • Examples:
      mat A = randu<mat>(5,5);
      
      mat B = fliplr(A);
      mat C = flipud(A);
      

  • See also:



imag( X )
real( X )
  • Extract the imaginary/real part of a complex matrix or cube

  • Examples:
      cx_mat C = randu<cx_mat>(5,5);
      
      mat    A = imag(C);
      mat    B = real(C);
      

  • Caveat: versions 4.4, 4.5 and 4.6 of the GCC C++ compiler have a bug when using the -std=c++0x compiler option (ie. experimental support for C++11); to work around this bug, preface Armadillo's imag() and real() with the arma namespace qualification, eg. arma::imag(C)

  • See also:



sub = ind2sub( size(n_rows, n_cols), index )

sub = ind2sub( size(n_rows, n_cols, n_slices), index )
  • Convert a linear index to subscript notation

  • std::logic_error exception is thrown if the index is out of range

  • The subscripts are returned in a vector of type uvec; the length of the vector is the same as the number of arguments given to the size() function (ie. either 2 or 3)

  • Examples:
      uvec s = ind2sub( size(4, 5), 6 );
      
      cout << "row: " << s(0) << endl;
      cout << "col: " << s(1) << endl;
      

  • See also:



inplace_trans( X )
inplace_trans( X, method )

inplace_strans( X )
inplace_strans( X, method )
  • In-place / in-situ transpose of matrix X

  • For real (non-complex) matrix:
    • inplace_trans() performs a normal transpose
    • inplace_strans() not applicable

  • For complex matrix:
    • inplace_trans() performs a Hermitian transpose (ie. the conjugate of the elements is taken during the transpose)
    • inplace_strans() provides a transposed copy without taking the conjugate of the elements

  • The argument method is optional

  • By default, a greedy transposition algorithm is used; a low-memory algorithm can be used instead by explicitly setting method to "lowmem"

  • The low-memory algorithm is considerably slower than the greedy algorithm; using the low-memory algorithm is only recommended for cases where X takes up more than half of available memory (ie. very large X)

  • Examples:
      mat X = randu<mat>(4,5);
      mat Y = randu<mat>(20000,30000);
      
      inplace_trans(X);            // use greedy algorithm by default
      
      inplace_trans(Y, "lowmem");  // use low-memory (and slow) algorithm
      

  • See also:



is_finite( X )
  • Returns true if all elements in X are finite

  • Returns false if at least one element in X is non-finite (±infinity or NaN)

  • X can be a scalar (eg. double), vector, matrix or cube

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = randu<mat>(5,5);
      
      B(1,1) = datum::inf;
      
      cout << is_finite(A) << endl;
      cout << is_finite(B) << endl;
      
      cout << is_finite( 0.123456789 ) << endl;
      cout << is_finite( datum::nan  ) << endl;
      cout << is_finite( datum::inf  ) << endl;
      

  • See also:



join_rows( A, B )
join_horiz( A, B )

join_cols( A, B )
join_vert( A, B )
  • join_rows() and join_horiz(): horizontal concatenation; for two matrices A and B, join each row of A with the corresponding row of B; matrices A and B must have the same number of rows

  • join_cols() and join_vert(): vertical concatenation; for two matrices A and B, join each column of A with the corresponding column of B; matrices A and B must have the same number of columns

  • Examples:
      mat A = randu<mat>(4,5);
      mat B = randu<mat>(4,6);
      mat C = randu<mat>(6,5);
      
      mat X = join_rows(A,B);
      mat Y = join_cols(A,C);
      

  • See also:



join_slices( cube C, cube D )
join_slices( mat M, mat N )

join_slices( mat M, cube C )
join_slices( cube C, mat M )
  • for two cubes C and D: join the slices of C with the slices of D; cubes C and D must have the same number of rows and columns (ie. all slices must have the same size)

  • for two matrices M and N: treat M and N as cube slices and join them to form a cube with 2 slices; matrices M and N must have the same number of rows and columns

  • for matrix M and cube C: treat M as a cube slice and join it with the slices of C; matrix M and cube C must have the same number of rows and columns

  • Examples:
      cube C(5, 10, 3, fill::randu);
      cube D(5, 10, 4, fill::randu);
      
      cube E = join_slices(C,D);
      
      mat M(10, 20, fill::randu);
      mat N(10, 20, fill::randu);
      
      cube Q = join_slices(M,N);
      
      cube R = join_slices(Q,M);
      
      cube S = join_slices(M,Q);
      

  • See also:



kron( A, B )
  • Kronecker tensor product

  • Given matrix A (with n rows and p columns) and matrix B (with m rows and q columns), generate a matrix (with nm rows and pq columns) that denotes the tensor product of A and B

  • Examples:
      mat A = randu<mat>(4,5);
      mat B = randu<mat>(5,4);
      
      mat K = kron(A,B);
      

  • See also:



min( V )
min( X )
min( X, dim )
min( A, B )

max( V )
max( X )
max( X, dim )
max( A, B )
  • For vector V, return the extremum value

  • For matrix X, return the extremum value for each column (dim=0), or each row (dim=1)

  • The dim argument is optional; by default dim=0 is used

  • For two matrices A and B, return a matrix containing element-wise extremum values

  • Examples:
      colvec v   = randu<colvec>(10,1);
      double val = max(v);
      
      mat    X = randu<mat>(10,10);
      rowvec r = max(X);
      
      // same result as max(X)
      // the 0 explicitly indicates "traverse across rows"
      rowvec s = max(X,0); 
      
      // the 1 explicitly indicates "traverse across columns"
      colvec t = max(X,1);
      
      // find the overall maximum value
      double y = max(max(X));
      
      // element-wise maximum
      mat A = randu<mat>(5,6);
      mat B = randu<mat>(5,6);
      mat C = arma::max(A,B);  // use arma:: prefix to distinguish from std::max()
      

  • See also:



nonzeros(X)
  • Return a column vector containing the non-zero values of X

  • X can be a sparse or dense matrix

  • Examples:
      sp_mat A = sprandu<sp_mat>(100, 100, 0.1);
         vec a = nonzeros(A);
      
      mat B(100, 100, fill::eye);
      vec b = nonzeros(B);
      

  • See also:



norm( X )
norm( X, p )
  • Compute the p-norm of X, where X can be a vector or matrix

  • For vectors, p is an integer ≥1, or one of: "-inf", "inf", "fro"

  • For matrices, p is one of: 1, 2, "inf", "fro"; the calculated norm is the induced norm (not entrywise norm)

  • "-inf" is the minimum norm, "inf" is the maximum norm, while "fro" is the Frobenius norm

  • The argument p is optional; by default p=2 is used

  • For vector norm with p=2 and matrix norm with p="fro", a robust algorithm is used to reduce the likelihood of underflows and overflows

  • To obtain the zero norm or Hamming norm (ie. the number of non-zero elements), use this expression: accu(X != 0)

  • Examples:
      vec    q = randu<vec>(5);
      
      double x = norm(q, 2);
      double y = norm(q, "inf");
      

  • See also:



normalise( V )
normalise( V, p )

normalise( X )
normalise( X, p )
normalise( X, p, dim )
  • For vector V, return its normalised version (ie. having unit p-norm)

  • For matrix X, return its normalised version, where each column (dim=0) or row (dim=1) has been normalised to have unit p-norm

  • The p argument is optional; by default p=2 is used

  • The dim argument is optional; by default dim=0 is used

  • Examples:
      vec A = randu<vec>(10);
      vec B = normalise(A);
      vec C = normalise(A, 1);
      
      mat X = randu<mat>(5,6);
      mat Y = normalise(X);
      mat Z = normalise(X, 2, 1);
      

  • See also:



prod( V )
prod( X )
prod( X, dim )
  • For vector V, return the product of all elements

  • For matrix X, return the product of elements in each column (dim=0), or each row (dim=1)

  • The dim argument is optional; by default dim=0 is used

  • Examples:
      colvec q = randu<colvec>(10,1);
      double x = prod(q);
      
      mat    A = randu<mat>(10,10);
      rowvec b = prod(A);
      
      // same result as prod(A)
      // the 0 explicitly indicates
      // "traverse across rows"
      rowvec c = prod(A,0);
      
      // the 1 explicitly indicates
      // "traverse across columns"
      colvec d = prod(A,1);
      
      // find the overall product
      double y = prod(prod(A));
      

  • See also:



rank( X )
rank( X, tolerance )
  • Return the rank of matrix X

  • Any singular values less than tolerance are treated as zero

  • The tolerance argument is optional; by default tolerance is max(m,n)*max_sv*datum::eps, where:
    • m = number of rows and n = number of columns in X
    • max_sv = maximal singular value of X
    • datum::eps = difference between 1 and the least value greater than 1 that is representable

  • The computation is based on singular value decomposition; if the decomposition fails, a std::runtime_error exception is thrown

  • Caveat: to confirm whether a matrix is singular, use rcond() or cond()

  • Examples:
      mat   A = randu<mat>(4,5);
      
      uword r = rank(A);
      

  • See also:



rcond( A )
  • Return an estimate of the reciprocal of the condition number of square matrix A

  • Values close to 1 suggest that A is well-conditioned

  • Values close to 0 suggest that A is badly conditioned

  • If A is not square sized, a std::logic_error exception is thrown

  • Examples:
      mat    A = randu<mat>(5,5);
      double r = rcond(A);
      

  • See also:



repmat( A, num_copies_per_row, num_copies_per_col )
  • Generate a matrix by replicating matrix A in a block-like fashion

  • The generated matrix has the following size:
      rows = num_copies_per_row*A.n_rows
      cols = num_copies_per_col*A.n_cols

  • Examples:
      mat A = randu<mat>(2, 3);
      
      mat B = repmat(A, 4, 5);
      
  • See also:



reshape( mat, n_rows, n_cols )
reshape( mat, size(X) )

reshape( cube, n_rows, n_cols, n_slices )
reshape( cube, size(X) )
  • Generate a matrix or cube sized according to given size specifications, whose elements are taken from the given matrix/cube in a column-wise manner; the elements in the generated object are placed column-wise (ie. the first column is filled up before filling the second column)

  • The layout of the elements in the generated object will be different to the layout in the given object

  • If the total number of elements in the given object is less than the specified size, the remaining elements in the generated object are set to zero

  • If the total number of elements in the given object is greater than the specified size, only a subset of elements is taken from the given object

  • Caveats:
    • do not use reshape() if you simply want to change the size without preserving data; use .set_size() instead, which is much faster
    • to grow/shrink a matrix while preserving the elements as well as the layout of the elements, use resize() instead
    • to create a vector representation of a matrix (ie. concatenate all the columns or rows), use vectorise() instead

  • Examples:
      mat A = randu<mat>(10, 5);
      mat B = reshape(A, 5, 10);
      

  • See also:



resize( mat, n_rows, n_cols )
resize( mat, size(X) )

resize( cube, n_rows, n_cols, n_slices )
resize( cube, size(X) )
  • Generate a matrix or cube sized according to given size specifications, whose elements as well as the layout of the elements are taken from the given matrix/cube

  • Caveat: do not use resize() if you simply want to change the size without preserving data; use .set_size() instead, which is much faster

  • Examples:
      mat A = randu<mat>(4, 5);
      mat B = resize(A, 7, 6);
      

  • See also:



shuffle( V )
shuffle( X )
shuffle( X, dim )
  • For vector V, generate a copy of the vector with the elements shuffled

  • For matrix X, generate a copy of the matrix with the rows (dim=0) or columns (dim=1) shuffled

  • The dim argument is optional; by default dim=0 is used

  • Examples:
      mat A = randu<mat>(4,5);
      mat B = shuffle(A);
      

  • See also:



size( X )
size( n_rows, n_cols )
size( n_rows, n_cols, n_slices )
  • Obtain the dimensions of object X, or explicitly specify the dimensions

  • The dimensions can be used in conjunction with:

  • The dimensions support simple arithmetic operations; they can also be printed and compared for equality/inequality

  • Examples:
      mat A(5,6);
      
      mat B(size(A), fill::zeros);
      
      mat C; C.randu(size(A));
      
      mat D = ones<mat>(size(A));
      
      mat E(10,20, fill::ones);
      E(3,4,size(C)) = C;    // access submatrix of E
      
      mat F( size(A) + size(E) );
      
      mat G( size(A) * 2 );
      
      cout << "size of A: " << size(A) << endl;
      
      bool is_same_size = (size(A) == size(E));
      

  • See also:



sort( V )
sort( V, sort_direction )

sort( X )
sort( X, sort_direction )
sort( X, sort_direction, dim )
  • For vector V, return a vector which is a sorted version of the input vector

  • For matrix X, return a matrix with the elements of the input matrix sorted in each column (dim=0), or each row (dim=1)

  • The dim argument is optional; by default dim=0 is used

  • The sort_direction argument is optional; sort_direction is either "ascend" or "descend"; by default "ascend" is used

  • For matrices and vectors with complex numbers, sorting is via absolute values

  • Examples:
      mat A = randu<mat>(10,10);
      mat B = sort(A);
      
  • See also:



sort_index( X )
sort_index( X, sort_direction )

stable_sort_index( X )
stable_sort_index( X, sort_direction )
  • Return a vector which describes the sorted order of the elements of X (ie. it contains the indices of the elements of X)

  • The output vector must have the type uvec (ie. the indices are stored as unsigned integers of type uword)

  • X is interpreted as a vector, with column-by-column ordering of the elements of X

  • The sort_direction argument is optional; sort_direction is either "ascend" or "descend"; by default "ascend" is used

  • The stable_sort_index() variant preserves the relative order of elements with equivalent values

  • For matrices and vectors with complex numbers, sorting is via absolute values

  • Examples:
      vec  q       = randu<vec>(10);
      uvec indices = sort_index(q);
      

  • See also:



sum( V )
sum( X )
sum( X, dim )
  • For vector V, return the sum of all elements

  • For matrix X, return the sum of elements in each column (dim=0), or each row (dim=1)

  • The dim argument is optional; by default dim=0 is used

  • To get a sum of all the elements regardless of the argument type (ie. matrix or vector), use accu() instead

  • Examples:
      colvec q = randu<colvec>(10,1);
      double x = sum(q);
      
      mat    A = randu<mat>(10,10);
      rowvec b = sum(A);
      
      // same result as sum(A)
      // the 0 explicitly indicates "traverse across rows"
      rowvec c = sum(A,0);
      
      // the 1 explicitly indicates "traverse across columns"
      colvec d = sum(A,1);
      
      // find the overall sum
      double y = accu(A);
      

  • See also:



index = sub2ind( size(n_rows, n_cols), row, col )

index = sub2ind( size(n_rows, n_cols, n_slices), row, col, slice )
  • Convert subscripts to a linear index

  • std::logic_error exception is thrown if a subscript is out of range

  • Examples:
      uword i = sub2ind( size(4, 5), 2, 3 );
      
      uword j = sub2ind( size(4, 5, 6), 2, 3, 4 );
      

  • See also:



symmatu( A )
symmatu( A, do_conj )

symmatl( A )
symmatl( A, do_conj )
  • symmatu(A): generate symmetric matrix from square matrix A, by reflecting the upper triangle to the lower triangle

  • symmatl(A): generate symmetric matrix from square matrix A, by reflecting the lower triangle to the upper triangle

  • If A is a complex matrix, the reflection uses the complex conjugate of the elements; to disable the complex conjugate, set do_conj to false

  • If A is non-square, a std::logic_error exception is thrown

  • Examples:
      mat A = randu<mat>(5,5);
      
      mat B = symmatu(A);
      mat C = symmatl(A);
      

  • See also:



trace( X )
  • Sum of the elements on the main diagonal of matrix X

  • If X is an expression, the function will try to use optimised expression evaluations to calculate only the diagonal elements

  • Examples:
      mat    A = randu<mat>(5,5);
      
      double x = trace(A);
      

  • See also:



trans( A )
strans( A )
  • For real (non-complex) matrix:
    • trans() provides a transposed copy of the matrix
    • strans() not applicable

  • For complex matrix:
    • trans() provides a Hermitian transpose (ie. the conjugate of the elements is taken during the transpose)
    • strans() provides a transposed copy without taking the conjugate of the elements

  • Examples:
      mat A = randu<mat>(5,10);
      
      mat B = trans(A);
      mat C = A.t();    // equivalent to trans(A), but more compact
      

  • See also:



trimatu( A )
trimatl( A )


unique( A )
  • Return the unique elements of A, sorted in ascending order

  • If A is a vector, the output is also a vector with the same orientation (row or column) as A; if A is a matrix, the output is always a column vector

  • Examples:
      mat X;
      X << 1 << 2 << endr
        << 2 << 3 << endr;
      
      mat Y = unique(X);
      

  • See also:



vectorise( A )
vectorise( A, dim )
  • Generate a column vector (dim=0) or row vector (dim=1) from matrix A

  • The argument dim is optional; by default dim=0 is used

  • For dim=0, the elements are copied from X column-wise; equivalent to concatenating all the columns of A

  • For dim=1, the elements are copied from X row-wise; equivalent to concatenating all the rows of A

  • Concatenating columns is faster than concatenating rows

  • Examples:
      mat A = randu<mat>(4, 5);
      
      vec v = vectorise(A);
      

  • See also:



miscellaneous element-wise functions:
    exp    exp2    exp10    trunc_exp
    log    log2    log10    trunc_log
    pow    square   sqrt     
    floor   ceil    round    trunc
    sign             
  • Apply a function to each element

  • Usage:
    • matrix_type B = fn(A)
    • cube_type B = fn(A)
    • A and B must have the same matrix_type/cube_type
    • fn(A) is one of:

      exp(A)    base-e exponential: e x
      exp2(A)    base-2 exponential: 2 x
      exp10(A)    base-10 exponential: 10 x
      trunc_exp(A)   base-e exponential, truncated to avoid infinity   (only for float and double elements)
      log(A)    natural log: loge x
      log2(A)    base-2 log: log2 x
      log10(A)    base-10 log: log10 x
      trunc_log(A)   natural log, truncated to avoid ±infinity   (only for float and double elements)
      pow(A, p)    raise to the power of p: x p
      square(A)    square: x 2
      sqrt(A)    square root: x ½
      floor(A)   largest integral value that is not greater than the input value
      ceil(A)   smallest integral value that is not less than the input value
      round(A)   round to nearest integer, with halfway cases rounded away from zero
      trunc(A)   round to nearest integer, towards zero
      sign(A)   signum function; for each element a in A, the corresponding element b in B is:
        ⎧ −1 if a < 0
        b = ⎨  0 if a = 0
        ⎩  +1 if a > 0
      if a is complex and non-zero, then b = a / abs(a)

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = exp(A);
      

  • See also:



trigonometric element-wise functions (cos, sin, tan, ...)
  • Apply a trigonometric function to each element

  • Usage:
    • matrix_type Y = trig_fn(X)
    • cube_type Y = trig_fn(X)
    • X and Y must have the same matrix_type/cube_type
    • trig_fn is one of:
      • cos family: cos, acos, cosh, acosh
      • sin family: sin, asin, sinh, asinh
      • tan family: tan, atan, tanh, atanh

  • Examples:
      mat X = randu<mat>(5,5);
      mat Y = cos(X);
      
  • See also:





Decompositions, Factorisations, Inverses and Equation Solvers (Dense Matrices)



R = chol( X )
R = chol( X, layout )

chol( R, X )
chol( R, X, layout )
  • Cholesky decomposition of matrix X

  • Matrix X must be symmetric and positive-definite

  • By default, R is upper triangular, such that R.t()*R = X

  • The argument layout is optional; layout is either "upper" or "lower", which specifies whether R is upper or lower triangular

  • If the decomposition fails:
    • R = chol(X) resets R and throws a std::runtime_error exception
    • chol(R,X) resets R and returns a bool set to false (exception is not thrown)

  • Examples:
      mat X = randu<mat>(5,5);
      mat Y = X.t()*X;
      
      mat R1 = chol(Y);
      mat R2 = chol(Y, "lower");
      

  • See also:



vec eigval = eig_sym( X )

eig_sym( eigval, X )

eig_sym( eigval, eigvec, X )
eig_sym( eigval, eigvec, X, method )
  • Eigen decomposition of dense symmetric/hermitian matrix X

  • The eigenvalues and corresponding eigenvectors are stored in eigval and eigvec, respectively

  • The eigenvalues are in ascending order

  • If X is not square sized, a std::logic_error exception is thrown

  • The method argument is optional; method is either "dc" or "std"
    • "dc" indicates divide-and-conquer method (default setting)
    • "std" indicates standard method
    • the divide-and-conquer method provides slightly different results than the standard method, but is considerably faster for large matrices

  • If the decomposition fails:
    • eigval = eig_sym(X) resets eigval and throws a std::runtime_error exception
    • eig_sym(eigval,X) resets eigval and returns a bool set to false (exception is not thrown)
    • eig_sym(eigval,eigvec,X) resets eigval & eigvec and returns a bool set to false (exception is not thrown)

  • There is currently no check whether X is symmetric

  • Examples:
      // for matrices with real elements
      
      mat A = randu<mat>(50,50);
      mat B = A.t()*A;  // generate a symmetric matrix
      
      vec eigval;
      mat eigvec;
      
      eig_sym(eigval, eigvec, B);
      
      
      // for matrices with complex elements
      
      cx_mat C = randu<cx_mat>(50,50);
      cx_mat D = C.t()*C;
      
         vec eigval2;
      cx_mat eigvec2;
      
      eig_sym(eigval2, eigvec2, D);
      

  • See also:



cx_vec eigval = eig_gen( X )

eig_gen( eigval, X )

eig_gen( eigval, eigvec, X )
  • Eigen decomposition of dense general (non-symmetric/non-hermitian) square matrix X

  • The eigenvalues and corresponding eigenvectors are stored in eigval and eigvec, respectively

  • If X is not square sized, a std::logic_error exception is thrown

  • If the decomposition fails:
    • eigval = eig_gen(X) resets eigval and throws a std::runtime_error exception
    • eig_gen(eigval,X) resets eigval and returns a bool set to false (exception is not thrown)
    • eig_gen(eigval,eigvec,X) resets eigval & eigvec and returns a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(10,10);
      
      cx_vec eigval;
      cx_mat eigvec;
      
      eig_gen(eigval, eigvec, A);
      

  • See also:



cx_vec eigval = eig_pair( A, B )

eig_pair( eigval, A, B )

eig_pair( eigval, eigvec, A, B )
  • Eigen decomposition for pair of general dense square matrices A and B of the same size, such that A*eigvec = B*eigvec*diagmat(eigval)

  • The eigenvalues and corresponding eigenvectors are stored in eigval and eigvec, respectively

  • If A or B is not square sized, a std::logic_error exception is thrown

  • If the decomposition fails:
    • eigval = eig_pair(A,B) resets eigval and throws a std::runtime_error exception
    • eig_pair(eigval,A,B) resets eigval and returns a bool set to false (exception is not thrown)
    • eig_pair(eigval,eigvec,A,B) resets eigval & eigvec and returns a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(10,10);
      mat B = randu<mat>(10,10);
      
      cx_vec eigval;
      cx_mat eigvec;
      
      eig_pair(eigval, eigvec, A, B);
      

  • See also:



B = inv( A )

inv( B, A )
  • Inverse of square matrix A

  • If A is not square sized, a std::logic_error exception is thrown

  • If A appears to be singular:
    • B = inv(A) resets B and throws a std::runtime_error exception
    • inv(B,A) resets B and returns a bool set to false (exception is not thrown)

  • Caveats:
    • if matrix A is know to be symmetric positive definite, it's faster to use inv_sympd() instead
    • if matrix A is know to be diagonal, use inv( diagmat(A) )
    • to solve a system of linear equations, such as Z = inv(X)*Y, it is faster and more accurate to use solve() instead

  • Examples:
      mat A = randu<mat>(5,5);
      
      mat B = inv(A);
      

  • See also:



B = inv_sympd( A )
inv_sympd( B, A )


lu( L, U, P, X )
lu( L, U, X )
  • Lower-upper decomposition (with partial pivoting) of matrix X

  • The first form provides a lower-triangular matrix L, an upper-triangular matrix U, and a permutation matrix P, such that P.t()*L*U = X

  • The second form provides permuted L and U, such that L*U = X; note that in this case L is generally not lower-triangular

  • If the decomposition fails:
    • lu(L,U,P,X) resets L, U, P and returns a bool set to false (exception is not thrown)
    • lu(L,U,X) resets L, U and returns a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(5,5);
      
      mat L, U, P;
      
      lu(L, U, P, A);
      
      mat B = P.t()*L*U;
      

  • See also:



B = null( A )
B = null( A, tolerance )

null( B, A )
null( B, A, tolerance )
  • Find the orthonormal basis of the null space of matrix A

  • The dimension of the range space is the number of singular values of A not greater than tolerance

  • The tolerance argument is optional; by default tolerance is max(m,n)*max_sv*datum::eps, where:
    • m = number of rows and n = number of columns in A
    • max_sv = maximal singular value of A
    • datum::eps = difference between 1 and the least value greater than 1 that is representable

  • The computation is based on singular value decomposition; if the decomposition fails:
    • B = null(A) resets B and throws a std::runtime_error exception
    • null(B,A) resets B and returns a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(5,6);
      
      A.row(0).zeros();
      A.col(0).zeros();
      
      mat B = null(A);
      

  • See also:



B = orth( A )
B = orth( A, tolerance )

orth( B, A )
orth( B, A, tolerance )
  • Find the orthonormal basis of the range space of matrix A, so that B.t()*B ≈ eye(r,r), where r = rank(A)

  • The dimension of the range space is the number of singular values of A greater than tolerance

  • The tolerance argument is optional; by default tolerance is max(m,n)*max_sv*datum::eps, where:
    • m = number of rows and n = number of columns in A
    • max_sv = maximal singular value of A
    • datum::eps = difference between 1 and the least value greater than 1 that is representable

  • The computation is based on singular value decomposition; if the decomposition fails:
    • B = orth(A) resets B and throws a std::runtime_error exception
    • orth(B,A) resets B and returns a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(5,6);
      
      mat B = orth(A);
      

  • See also:



B = pinv( A )
B = pinv( A, tolerance )
B = pinv( A, tolerance, method )

pinv( B, A )
pinv( B, A, tolerance )
pinv( B, A, tolerance, method )
  • Moore-Penrose pseudo-inverse of matrix A

  • The computation is based on singular value decomposition

  • The tolerance argument is optional

  • The default tolerance is max(m,n)*max_sv*datum::eps, where:
    • m = number of rows and n = number of columns in A
    • max_sv = maximal singular value of A
    • datum::eps = difference between 1 and the least value greater than 1 that is representable

  • Any singular values less than tolerance are treated as zero

  • The method argument is optional; method is either "dc" or "std"
    • "dc" indicates divide-and-conquer method (default setting)
    • "std" indicates standard method
    • the divide-and-conquer method provides slightly different results than the standard method, but is considerably faster for large matrices

  • If the decomposition fails:
    • B = pinv(A) resets B and throws a std::runtime_error exception
    • pinv(B,A) resets B and returns a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(4,5);
      
      mat B = pinv(A);        // use default tolerance
      
      mat C = pinv(A, 0.01);  // set tolerance to 0.01
      

  • See also:



qr( Q, R, X )


qr_econ( Q, R, X )
  • Economical decomposition of X (with size m x n) into an orthogonal matrix Q and a right triangular matrix R, such that Q*R = X

  • If m > n, only the first n rows of R and the first n columns of Q are calculated (ie. the zero rows of R and the corresponding columns of Q are omitted)

  • If the decomposition fails, Q and R are reset and the function returns a bool set to false (exception is not thrown)

  • Examples:
      mat X = randu<mat>(6,5);
      mat Q, R;
      
      qr_econ(Q,R,X);
      

  • See also:



qz( AA, BB, Q, Z, A, B )
  • Generalised Schur decomposition for pair of general square matrices A and B of the same size,
    such that A = Q.t()*AA*Z.t() and B = Q.t()*BB*Z.t()

  • The left and right Schur vectors are stored in Q and Z, respectively

  • In the complex-valued problem, the generalised eigenvalues are found in diagvec(AA) / diagvec(BB)

  • If A or B is not square sized, a std::logic_error exception is thrown

  • If the decomposition fails, AA, BB, Q and Z are reset, and the function returns a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(10,10);
      mat B = randu<mat>(10,10);
      
      mat AA;
      mat BB;
      mat Q;
      mat Z; 
      
      qz(AA, BB, Q, Z, A, B);
      

  • See also:



S = schur( X )

schur( S, X )

schur( U, S, X )
  • Schur decomposition of square matrix X, such that X = U*S*U.t()

  • U is a unitary matrix containing the Schur vectors

  • S is an upper triangular matrix, called the Schur form of X

  • If X is not square sized, a std::logic_error exception is thrown

  • If the decomposition fails:
    • S = schur(X) resets S and throws a std::runtime_error exception
    • schur(S,X) resets S and returns a bool set to false (exception is not thrown)
    • schur(U,S,X) resets U & S and returns a bool set to false (exception is not thrown)

  • Caveat: in general, Schur decomposition is not unique

  • Examples:
      mat X(20,20, fill::randu);
      
      mat U;
      mat S;
      
      schur(U, S, X);
      

  • See also:



X = solve( A, B )
X = solve( A, B, options )     (version 6.300+)

solve( X, A, B )
solve( X, A, B, options )     (version 6.300+)
  • Solve a dense system of linear equations, A*X = B, where X is unknown; similar functionality to the \ operator in Matlab/Octave, ie. X = A \ B

  • A can be square (critically determined system), or non-square (under/over-determined system)

  • B can be a vector or matrix

  • The number of rows in A and B must be the same

  • The options argument is optional; it is one or a combination of the following:

      solve_opts::fast   do not apply iterative refinement and/or equilibration
      solve_opts::equilibrate   equilibrate the system before solving   (matrix A must be square)
      solve_opts::no_approx   do not find approximate solutions for rank deficient systems

    • Options can be combined using the + operator; for example: solve_opts::fast + solve_opts::no_approx

    • Caveat: solve_opts::fast is recommended only for well-conditioned systems

  • If A is known to be a triangular matrix, the solution can be computed faster by explicitly indicating that A is triangular through trimatu() or trimatl();
    indicating a triangular matrix also implies that solve_opts::fast is enabled

  • If no solution is found:
    • X = solve(A,B) resets X and throws a std::runtime_error exception
    • solve(X,A,B) resets X and returns a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(5,5);
      vec b = randu<vec>(5);
      mat B = randu<mat>(5,5);
      
      vec x1 = solve(A, b);
      
      vec x2;
      bool status = solve(x2, A, b);
      
      mat X1 = solve(A, B);
      
      mat X2 = solve(A, B, solve_opts::fast);
      
      mat X3 = solve(A, trimatu(B));  // indicate that B is triangular
      

  • See also:



vec s = svd( X )

svd( vec s, X )

svd( mat U, vec s, mat V, mat X )
svd( mat U, vec s, mat V, mat X, method )

svd( cx_mat U, vec s, cx_mat V, cx_mat X )
svd( cx_mat U, vec s, cx_mat V, cx_mat X, method )
  • Singular value decomposition of dense matrix X

  • If X is square, it can be reconstructed using X = U*diagmat(s)*V.t()

  • The singular values are in descending order

  • The method argument is optional; method is either "dc" or "std"
    • "dc" indicates divide-and-conquer method (default setting)
    • "std" indicates standard method
    • the divide-and-conquer method provides slightly different results than the standard method, but is considerably faster for large matrices

  • If the decomposition fails, the output objects are reset and:
    • s = svd(X) resets s and throws a std::runtime_error exception
    • svd(s,X) resets s and returns a bool set to false (exception is not thrown)
    • svd(U,s,V,X) resets U, s, V and returns a bool set to false (exception is not thrown)

  • Examples:
      mat X = randu<mat>(5,5);
      
      mat U;
      vec s;
      mat V;
      
      svd(U,s,V,X);
      

  • See also:



svd_econ( mat U, vec s, mat V, mat X )
svd_econ( mat U, vec s, mat V, mat X, mode )
svd_econ( mat U, vec s, mat V, mat X, mode, method )

svd_econ( cx_mat U, vec s, cx_mat V, cx_mat X )
svd_econ( cx_mat U, vec s, cx_mat V, cx_mat X, mode )
svd_econ( cx_mat U, vec s, cx_mat V, cx_mat X, mode, method )
  • Economical singular value decomposition of dense matrix X

  • The singular values are in descending order

  • The mode argument is optional; mode is one of:
      "both" = compute both left and right singular vectors (default operation)
      "left" = compute only left singular vectors
      "right" = compute only right singular vectors

  • The method argument is optional; method is either "dc" or "std"
    • "dc" indicates divide-and-conquer method (default setting)
    • "std" indicates standard method
    • the divide-and-conquer method provides slightly different results than the standard method, but is considerably faster for large matrices

  • If the decomposition fails, U, s, V are reset and a bool set to false is returned (exception is not thrown)

  • Examples:
      mat X = randu<mat>(4,5);
      
      mat U;
      vec s;
      mat V;
      
      svd_econ(U, s, V, X);
      

  • See also:



X = syl( A, B, C )
syl( X, A, B, C )
  • Solve the Sylvester equation, ie. AX + XB + C = 0, where X is unknown

  • Matrices A, B and C must be square sized

  • If no solution is found:
    • syl(A,B,C) resets X and throws a std::runtime_error exception
    • syl(X,A,B,C) resets X and returns a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(5,5);
      mat B = randu<mat>(5,5);
      mat C = randu<mat>(5,5);
      
      mat X1 = syl(A, B, C);
      
      mat X2;
      syl(X2, A, B, C);
      

  • See also:





Decompositions, Factorisations and Equation Solvers (Sparse Matrices)



vec eigval = eigs_sym( X, k )
vec eigval = eigs_sym( X, k, form )
vec eigval = eigs_sym( X, k, form, tol )

eigs_sym( eigval, X, k )
eigs_sym( eigval, X, k, form )
eigs_sym( eigval, X, k, form, tol )

eigs_sym( eigval, eigvec, X, k )
eigs_sym( eigval, eigvec, X, k, form )
eigs_sym( eigval, eigvec, X, k, form, tol )
  • Obtain a limited number of eigenvalues and eigenvectors of sparse symmetric real matrix X

  • k specifies the number of eigenvalues and eigenvectors

  • The argument form is optional; form is one of:
      "lm" = obtain eigenvalues with largest magnitude (default operation)
      "sm" = obtain eigenvalues with smallest magnitude
      "la" = obtain eigenvalues with largest algebraic value
      "sa" = obtain eigenvalues with smallest algebraic value

  • The argument tol is optional; it specifies the tolerance for convergence

  • The eigenvalues and corresponding eigenvectors are stored in eigval and eigvec, respectively

  • If X is not square sized, a std::logic_error exception is thrown

  • If the decomposition fails:
    • eigval = eigs_sym(X,k) resets eigval and throws a std::runtime_error exception
    • eigs_sym(eigval,X,k) resets eigval and returns a bool set to false (exception is not thrown)
    • eigs_sym(eigval,eigvec,X,k) resets eigval & eigvec and returns a bool set to false (exception is not thrown)

  • There is currently no check whether X is symmetric

  • Examples:
      // generate sparse matrix
      sp_mat A = sprandu<sp_mat>(1000, 1000, 0.1);
      sp_mat B = A.t()*A;
      
      vec eigval;
      mat eigvec;
      
      eigs_sym(eigval, eigvec, B, 5);  // find 5 eigenvalues/eigenvectors
      

  • See also:



cx_vec eigval = eigs_gen( X, k )
cx_vec eigval = eigs_gen( X, k, form )
cx_vec eigval = eigs_gen( X, k, form, tol )

eigs_gen( eigval, X, k )
eigs_gen( eigval, X, k, form )
eigs_gen( eigval, X, k, form, tol )

eigs_gen( eigval, eigvec, X, k )
eigs_gen( eigval, eigvec, X, k, form )
eigs_gen( eigval, eigvec, X, k, form, tol )
  • Obtain a limited number of eigenvalues and eigenvectors of sparse general (non-symmetric/non-hermitian) square matrix X

  • k specifies the number of eigenvalues and eigenvectors

  • The argument form is optional; form is one of:
      "lm" = obtain eigenvalues with largest magnitude (default operation)
      "sm" = obtain eigenvalues with smallest magnitude
      "lr" = obtain eigenvalues with largest real part
      "sr" = obtain eigenvalues with smallest real part
      "li" = obtain eigenvalues with largest imaginary part
      "si" = obtain eigenvalues with smallest imaginary part

  • The argument tol is optional; it specifies the tolerance for convergence

  • The eigenvalues and corresponding eigenvectors are stored in eigval and eigvec, respectively

  • If X is not square sized, a std::logic_error exception is thrown

  • If the decomposition fails:
    • eigval = eigs_gen(X,k) resets eigval and throws a std::runtime_error exception
    • eigs_gen(eigval,X,k) resets eigval and returns a bool set to false (exception is not thrown)
    • eigs_gen(eigval,eigvec,X,k) resets eigval & eigvec and returns a bool set to false (exception is not thrown)

  • Examples:
      // generate sparse matrix
      sp_mat A = sprandu<sp_mat>(1000, 1000, 0.1);  
      
      cx_vec eigval;
      cx_mat eigvec;
      
      eigs_gen(eigval, eigvec, A, 5);  // find 5 eigenvalues/eigenvectors
      

  • See also:



X = spsolve( A, B )
X = spsolve( A, B, solver )
X = spsolve( A, B, solver, settings )

spsolve( X, A, B )
spsolve( X, A, B, solver )
spsolve( X, A, B, solver, settings )
  • Solve a sparse system of linear equations, A*X = B, where A is a sparse matrix, B is a dense matrix or vector, and X is unknown

  • The number of rows in A and B must be the same

  • If no solution is found:
    • X = spsolve(A, B) resets X and throws a std::runtime_error exception
    • spsolve(X, A, B) resets X and returns a bool set to false (no exception is thrown)

  • The solver argument is optional; solver is either "superlu" or "lapack"; by default "superlu" is used
    • For "superlu", ARMA_USE_SUPERLU must be enabled in config.hpp
    • For "lapack", sparse matrix A is converted to a dense matrix before using the LAPACK solver; this considerably increases memory usage

  • The settings argument is optional

    • when solver is "superlu", settings is an instance of the superlu_opts structure:
      struct superlu_opts
        {
        bool             equilibrate;  // default: false
        bool             symmetric;    // default: false
        double           pivot_thresh; // default: 1.0
        permutation_type permutation;  // default: superlu_opts::COLAMD
        refine_type      refine;       // default: superlu_opts::REF_DOUBLE
        };
      
    • equilibrate is either true or false; it indicates whether to equilibrate the system (scale the rows and columns of A to have unit norm)

    • symmetric is either true or false; it indicates whether to use SuperLU symmetric mode, which gives preference to diagonal pivots

    • pivot_threshold is in the range [0.0, 1.0], used for determining whether a diagonal entry is an acceptable pivot (details in SuperLU documentation)

    • permutation specifies the type of column permutation; it is one of:

      superlu_opts::NATURAL  natural ordering
      superlu_opts::MMD_ATA  minimum degree ordering on structure of A.t() * A
      superlu_opts::MMD_AT_PLUS_A  minimum degree ordering on structure of A.t() + A
      superlu_opts::COLAMD  approximate minimum degree column ordering

    • refine specifies the type of iterative refinement; it is one of:

      superlu_opts::REF_NONE   no refinement
      superlu_opts::REF_SINGLE   iterative refinement in single precision
      superlu_opts::REF_DOUBLE   iterative refinement in double precision
      superlu_opts::REF_EXTRA   iterative refinement in extra precision

  • Examples:
      sp_mat A = sprandu<sp_mat>(1000, 1000, 0.1);
      
      vec b = randu<vec>(1000);
      mat B = randu<mat>(1000, 5);
      
      vec x = spsolve(A, b);  // solve one system
      mat X = spsolve(A, B);  // solve several systems
      
      bool status = spsolve(x, A, b);  // use default solver
      if(status == false)  { cout << "no solution" << endl; }
      
      spsolve(x, A, b, "lapack");   // use LAPACK  solver
      spsolve(x, A, b, "superlu");  // use SuperLU solver
      
      superlu_opts settings;
      
      settings.permutation = superlu_opts::NATURAL;
      settings.refine      = superlu_opts::REF_NONE;
      
      spsolve(x, A, b, "superlu", settings);
      

  • See also:



vec s = svds( X, k )
vec s = svds( X, k, tol )

svds( vec s, X, k )
svds( vec s, X, k, tol )

svds( mat U, vec s, mat V, sp_mat X, k )
svds( mat U, vec s, mat V, sp_mat X, k, tol )

svds( cx_mat U, vec s, cx_mat V, sp_cx_mat X, k )
svds( cx_mat U, vec s, cx_mat V, sp_cx_mat X, k, tol )
  • Obtain a limited number of singular values and singular vectors of sparse matrix X

  • k specifies the number of singular values and singular vectors

  • The argument tol is optional; it specifies the tolerance for convergence

  • The singular values are calculated via sparse eigen decomposition of:
    ⎡ zeros(X.n_rows, X.n_rows)  X ⎤
    ⎣ X.t() zeros(X.n_cols, X.n_cols) ⎦

  • The singular values are in descending order

  • If the decomposition fails, the output objects are reset and:
    • s = svds(X,k) resets s and throws a std::runtime_error exception
    • svds(s,X,k) resets s and returns a bool set to false (exception is not thrown)
    • svds(U,s,V,X,k) resets U, s, V and returns a bool set to false (exception is not thrown)

  • Caveat: svds() is intended only for finding a few singular values from a large sparse matrix; to find all singular values, use svd() instead

  • Examples:
      sp_mat X = sprandu<sp_mat>(100, 200, 0.1);
      
      mat U;
      vec s;
      mat V;
      
      svds(U, s, V, X, 10);
      

  • See also:





Signal & Image Processing



conv( A, B )
conv( A, B, shape )
  • 1D convolution of vectors A and B

  • The orientation of the result vector is the same as the orientation of A (ie. either column or row vector)

  • The shape argument is optional; it is one of:
        "full" = return the full convolution (default setting), with the size equal to A.n_elem + B.n_elem - 1
        "same" = return the central part of the convolution, with the same size as vector A

  • The convolution operation is also equivalent to FIR filtering

  • Examples:
      vec A(256, fill::randu);
      
      vec B(16, fill::randu);
      
      vec C = conv(A, B);
      
      vec D = conv(A, B, "same");
      

  • See also:



conv2( A, B )
conv2( A, B, shape )
  • 2D convolution of matrices A and B

  • The shape argument is optional; it is one of:
        "full" = return the full convolution (default setting), with the size equal to size(A) + size(B) - 1
        "same" = return the central part of the convolution, with the same size as matrix A

  • Examples:
      mat A(256, 256, fill::randu);
      
      mat B(16, 16, fill::randu);
      
      mat C = conv2(A, B);
      
      mat D = conv2(A, B, "same");
      

  • See also:



cx_mat Y =  fft( X )
cx_mat Y =  fft( X, n )

cx_mat Z = ifft( cx_mat Y )
cx_mat Z = ifft( cx_mat Y, n )
  • fft(): fast Fourier transform of a vector or matrix (real or complex)

  • ifft(): inverse fast Fourier transform of a vector or matrix (complex only)

  • If given a matrix, the transform is done on each column vector of the matrix

  • The optional n argument specifies the transform length:
    • if n is larger than the length of the input vector, a zero-padded version of the vector is used
    • if n is smaller than the length of the input vector, only the first n elements of the vector are used

  • If n is not specified, the transform length is the same as the length of the input vector

  • Caveat: the transform is fastest when the transform length is a power of 2, eg. 64, 128, 256, 512, 1024, ...

  • The implementation of the transform in this version is preliminary; it is not yet fully optimised

  • Examples:
         vec X = randu<vec>(100);
      cx_vec Y = fft(X, 128);
      

  • See also:



cx_mat Y =  fft2( X )
cx_mat Y =  fft2( X, n_rows, n_cols )

cx_mat Z = ifft2( cx_mat Y )
cx_mat Z = ifft2( cx_mat Y, n_rows, n_cols )
  • fft2(): 2D fast Fourier transform of a matrix (real or complex)

  • ifft2(): 2D inverse fast Fourier transform of a matrix (complex only)

  • The optional arguments n_rows and n_cols specify the size of the transform; a truncated and/or zero-padded version of the input matrix is used

  • Caveat: the transform is fastest when both n_rows and n_cols are a power of 2, eg. 64, 128, 256, 512, 1024, ...

  • The implementation of the transform in this version is preliminary; it is not yet fully optimised

  • Examples:
         mat A = randu<mat>(100,100);
      cx_mat B = fft2(A);
      cx_mat C = fft2(A, 128, 128);
      

  • See also:



interp1( X, Y, XI, YI )
interp1( X, Y, XI, YI, method )
interp1( X, Y, XI, YI, method, extrapolation_value )
  • 1D data interpolation

  • Given a 1D function specified in vectors X and Y (where X specifies locations and Y specifies the corresponding values),
    generate vector YI which contains interpolated values at locations XI

  • The method argument is optional; it is one of:
      "nearest" = interpolate using single nearest neighbour
      "*nearest" = as per "nearest", but faster by assuming that X and XI are monotonically increasing
      "linear" = linear interpolation between two nearest neighbours (default setting)
      "*linear" = as per "linear", but faster by assuming that X and XI are monotonically increasing

  • If a location in XI is outside the domain of X, the corresponding value in YI is set to extrapolation_value

  • The extrapolation_value argument is optional; by default it is datum::nan (not-a-number)

  • Examples:
      vec x = linspace<vec>(0, 3, 20);
      vec y = square(x);
      
      vec xx = linspace<vec>(0, 3, 100);
      
      vec yy;
      
      interp1(x, y, xx, yy);  // use linear interpolation by default
      
      interp1(x, y, xx, yy, "*linear");  // faster than "linear"
      
      interp1(x, y, xx, yy, "nearest");
      

  • See also:





Statistics & Clustering



mean, median, stddev, var
    mean( V )
    mean( X )
    mean( X, dim )

        mean (average value)
    median( V )
    median( X )
    median( X, dim )

        median
    stddev( V )
    stddev( V, norm_type )
    stddev( X )
    stddev( X, norm_type )
    stddev( X, norm_type, dim )

        standard deviation
    var( V )
    var( V, norm_type )
    var( X )
    var( X, norm_type )
    var( X, norm_type, dim )

        variance
  • For vector V, return a particular statistic calculated using all the elements of the vector

  • For matrix X, find a particular statistic for each column (dim=0), or each row (dim=1)

  • The dim argument is optional; by default dim=0 is used

  • The norm_type argument is optional; by default norm_type=0 is used

  • For the var() and stddev() functions:
    • the default norm_type=0 performs normalisation using N-1 (where N is the number of samples), providing the best unbiased estimator
    • using norm_type=1 performs normalisation using N, which provides the second moment around the mean

  • Examples:
      mat A    = randu<mat>(5,5);
      mat B    = mean(A);
      mat C    = var(A);
      double m = mean(mean(A));
      
      vec    q = randu<vec>(5);
      double v = var(q);
      

  • See also:



cov( X, Y )
cov( X, Y, norm_type )

cov( X )
cov( X, norm_type )
  • For two matrix arguments X and Y, if each row of X and Y is an observation and each column is a variable, the (i,j)-th entry of cov(X,Y) is the covariance between the i-th variable in X and the j-th variable in Y

  • For vector arguments, the type of vector is ignored and each element in the vector is treated as an observation

  • For matrices, X and Y must have the same dimensions

  • For vectors, X and Y must have the same number of elements

  • cov(X) is equivalent to cov(X, X)

  • The default norm_type=0 performs normalisation using N-1 (where N is the number of observations), providing the best unbiased estimation of the covariance matrix (if the observations are from a normal distribution). Using norm_type=1 causes normalisation to be done using N, which provides the second moment matrix of the observations about their mean

  • Examples:
      mat X = randu<mat>(4,5);
      mat Y = randu<mat>(4,5);
      
      mat C = cov(X,Y);
      mat D = cov(X,Y, 1);
      

  • See also:



cor( X, Y )
cor( X, Y, norm_type )

cor( X )
cor( X, norm_type )
  • For two matrix arguments X and Y, if each row of X and Y is an observation and each column is a variable, the (i,j)-th entry of cor(X,Y) is the correlation coefficient between the i-th variable in X and the j-th variable in Y

  • For vector arguments, the type of vector is ignored and each element in the vector is treated as an observation

  • For matrices, X and Y must have the same dimensions

  • For vectors, X and Y must have the same number of elements

  • cor(X) is equivalent to cor(X, X)

  • The default norm_type=0 performs normalisation of the correlation matrix using N-1 (where N is the number of observations). Using norm_type=1 causes normalisation to be done using N

  • Examples:
      mat X = randu<mat>(4,5);
      mat Y = randu<mat>(4,5);
      
      mat R = cor(X,Y);
      mat S = cor(X,Y, 1);
      

  • See also:



hist( V )
hist( V, n_bins )
hist( V, centers )

hist( X, centers )
hist( X, centers, dim )
  • For vector V, produce an unsigned vector of the same orientation as V (ie. either uvec or urowvec) that represents a histogram of counts

  • For matrix X, produce a umat matrix containing either column histogram counts (for dim=0, default), or row histogram counts (for dim=1)

  • The bin centers can be automatically determined from the data, with the number of bins specified via n_bins (default is 10); the range of the bins is determined by the range of the data

  • The bin centers can also be explicitly specified via the centers vector; the vector must contain monotonically increasing values (eg. 0.1, 0.2, 0.3, ...)

  • Examples:
      vec  v  = randn<vec>(1000); // Gaussian distribution
      
      uvec h1 = hist(v, 11);
      uvec h2 = hist(v, linspace<vec>(-2,2,11));
      

  • See also:



histc( V, edges )
histc( X, edges )
histc( X, edges, dim )
  • For vector V, produce an unsigned vector of the same orientation as V (ie. either uvec or urowvec) that contains the counts of the number of values that fall between the elements in the edges vector

  • For matrix X, produce a umat matrix containing either column histogram counts (for dim=0, default), or row histogram counts (for dim=1)

  • The edges vector must contain monotonically increasing values (eg. 0.1, 0.2, 0.3, ...)

  • Examples:
      vec  v = randn<vec>(1000);  // Gaussian distribution
      
      uvec h = histc(v, linspace<vec>(-2,2,11));
      

  • See also:



mat coeff = princomp( mat X )
cx_mat coeff = princomp( cx_mat X )

princomp( mat coeff, mat X )
princomp( cx_mat coeff, cx_mat X )

princomp( mat coeff, mat score, mat X )
princomp( cx_mat coeff, cx_mat score, cx_mat X )

princomp( mat coeff, mat score, vec latent, mat X )
princomp( cx_mat coeff, cx_mat score, vec latent, cx_mat X )

princomp( mat coeff, mat score, vec latent, vec tsquared, mat X )
princomp( cx_mat coeff, cx_mat score, vec latent, cx_vec tsquared, cx_mat X )
  • Principal component analysis of matrix X

  • Each row of X is an observation and each column is a variable

  • output objects:
    • coeff: principal component coefficients
    • score: projected data
    • latent: eigenvalues of the covariance matrix of X
    • tsquared: Hotteling's statistic for each sample

  • The computation is based on singular value decomposition

  • If the decomposition fails:
    • coeff = princomp(X) resets coeff and throws a std::runtime_error exception
    • remaining forms of princomp() reset all output matrices and return a bool set to false (exception is not thrown)

  • Examples:
      mat A = randu<mat>(5,4);
      
      mat coeff;
      mat score;
      vec latent;
      vec tsquared;
      
      princomp(coeff, score, latent, tsquared, A);
      

  • See also:



running_stat<type>
  • Class for keeping the running statistics of a continuously sampled one dimensional process/signal

  • Useful if the storage of individual samples (scalars) is not required, or the number of samples is not known beforehand

  • type is one of: float, double, cx_float, cx_double

  • For an instance of running_stat named as X, the member functions are:

      X(scalar)  
      update the statistics so far using the given scalar
      X.min()  
      get the minimum value so far
      X.max()  
      get the maximum value so far
      X.mean()  
      get the mean or average value so far
      X.var()  and  X.var(norm_type)  
      get the variance so far
      X.stddev()  and  X.stddev(norm_type)  
      get the standard deviation so far
      X.reset()  
      reset all statistics and set the number of samples to zero
      X.count()  
      get the number of samples so far

  • The norm_type argument is optional; by default norm_type=0 is used

  • For the .var() and .stddev() functions, the default norm_type=0 performs normalisation using N-1 (where N is the number of samples so far), providing the best unbiased estimator; using norm_type=1 causes normalisation to be done using N, which provides the second moment around the mean

  • The return type of .count() depends on the underlying form of type: it is either float or double

  • Examples:
      running_stat<double> stats;
      
      for(uword i=0; i<10000; ++i)
        {
        double sample = randn();
        stats(sample);
        }
      
      cout << "mean = " << stats.mean() << endl;
      cout << "var  = " << stats.var()  << endl;
      cout << "min  = " << stats.min()  << endl;
      cout << "max  = " << stats.max()  << endl;
      

  • See also:



running_stat_vec<vec_type>
running_stat_vec<vec_type>(calc_cov)
  • Class for keeping the running statistics of a continuously sampled multi-dimensional process/signal

  • Useful if the storage of individual samples (vectors) is not required, or if the number of samples is not known beforehand

  • This class is similar to running_stat, with the difference that vectors are processed instead of scalars

  • vec_type is the vector type of the samples; for example: vec, cx_vec, rowvec, ...

  • For an instance of running_stat_vec named as X, the member functions are:

      X(vector)  
      update the statistics so far using the given vector
      X.min()  
      get the vector of minimum values so far
      X.max()  
      get the vector of maximum values so far
      X.mean()  
      get the mean vector so far
      X.var()  and  X.var(norm_type)  
      get the vector of variances so far
      X.stddev()  and  X.stddev(norm_type)  
      get the vector of standard deviations so far
      X.cov()  and  X.cov(norm_type)  
      get the covariance matrix so far; valid if calc_cov=true during construction of running_stat_vec
      X.reset()  
      reset all statistics and set the number of samples to zero
      X.count()  
      get the number of samples so far

  • The calc_cov argument is optional; by default calc_cov=false, indicating that the covariance matrix will not be calculated; to enable the covariance matrix, use calc_cov=true during construction; for example: running_stat_vec<vec> X(true);

  • The norm_type argument is optional; by default norm_type=0 is used

  • For the .var() and .stddev() functions, the default norm_type=0 performs normalisation using N-1 (where N is the number of samples so far), providing the best unbiased estimator; using norm_type=1 causes normalisation to be done using N, which provides the second moment around the mean

  • The return type of .count() depends on the underlying form of vec_type: it is either float or double

  • Examples:
      running_stat_vec<vec> stats;
      
      vec sample;
      
      for(uword i=0; i<10000; ++i)
        {
        sample = randu<vec>(5);
        stats(sample);
        }
      
      cout << "mean = " << endl << stats.mean() << endl;
      cout << "var  = " << endl << stats.var()  << endl;
      cout << "max  = " << endl << stats.max()  << endl;
      
      //
      //
      
      running_stat_vec<rowvec> more_stats(true);
      
      for(uword i=0; i<20; ++i)
        {
        sample = randu<rowvec>(3);
        
        sample(1) -= sample(0);
        sample(2) += sample(1);
        
        more_stats(sample);
        }
      
      cout << "covariance matrix = " << endl;
      cout << more_stats.cov() << endl;
      
      rowvec sd = more_stats.stddev();
      
      cout << "correlations = " << endl;
      cout << more_stats.cov() / (sd.t() * sd);
      

  • See also:



kmeans( means, data, k, seed_mode, n_iter, print_mode )
  • Cluster given data using the k-means algorithm

  • The means parameter is the output matrix containing the resulting means, with each mean stored as a column vector

  • The data parameter is the input data matrix, with each sample stored as a column vector

  • The k parameter indicates the number of means

  • The seed_mode parameter specifies how the initial means are seeded prior to running k-means; it is one of:
      keep_existing   use the means specified in the means matrix as the starting point
      static_subset   use a subset of the data vectors (repeatable)
      random_subset   use a subset of the data vectors (random)
      static_spread   use a maximally spread subset of data vectors (repeatable)
      random_spread   use a maximally spread subset of data vectors (random start)

  • The n_iter parameter specifies the number of iterations of the k-means algorithm; a sufficient number of iterations is typically about 10

  • The print_mode parameter is either true or false, indicating whether progress is printed during clustering

  • If the k-means algorithm fails, the means matrix is reset and a bool set to false is returned

  • The k-means algorithm will run faster on multi-core machines when OpenMP is enabled in your compiler (eg. -fopenmp in GCC)

  • Caveats:

    • the number of data vectors (number of columns in the data matrix) should be much larger than k  (number of means)

    • seeding the initial means with static_spread and random_spread can be much more time consuming than with static_subset and random_subset

  • Examples:
      uword d = 5;       // dimensionality
      uword N = 10000;   // number of vectors
      
      mat data(d, N, fill::randu);
      
      mat means;
      
      bool status = kmeans(means, data, 2, random_subset, 10, true);
      
      if(status == false)
        {
        cout << "k-means failed" << endl;
        }
      
      means.print("means:");
      

  • See also:



gmm_diag
  • Class for modelling data as a Gaussian Mixture Model (GMM), under the assumption of diagonal covariance matrices

  • Can also be used for clustering and vector quantisation (VQ)

  • Provides associated parameter estimation algorithms: k-means clustering and Expectation-Maximisation (EM)

  • The k-means and EM algorithms are parallelised (multi-threaded) when compiling with OpenMP enabled (eg. the -fopenmp option in gcc)

  • Data is modelled as:
      n_gaus-1 
    p(x) =  hg  N( x | mg Cg )
      g=0 
    where:
    • n_gaus is the number of Gaussians
    • N( x | mg Cg ) represents a Gaussian (normal) distribution
    • for each Gaussian g:
      • hg is the heft (weight), with hg ≥ 0 and ∑hg = 1
      • mg is the mean (centroid) vector with dimensionality n_dims
      • Cg is the diagonal covariance matrix

  • For an instance of gmm_diag named as M, the member functions and variables are:

      M.log_p(V)  
      return a scalar representing the log-likelihood of vector V
      M.log_p(V, g)  
      return a scalar representing the log-likelihood of vector V, according to Gaussian g
       
       
       
      M.log_p(X)  
      return a row vector (of type rowvec) containing log-likelihoods of each column vector in matrix X
      M.log_p(X, g)  
      return a row vector (of type rowvec) containing log-likelihoods of each column vector in matrix X, according to Gaussian g
       
       
       
      M.avg_log_p(X)  
      return a scalar representing the average log-likelihood of all column vectors in matrix X
      M.avg_log_p(X, g)  
      return a scalar representing the average log-likelihood of all column vectors in matrix X, according to Gaussian g
       
       
       
      M.assign(V, dist_mode)  
      return the index of the closest mean (or Gaussian) to vector V;
      dist_mode is one of:
      eucl_dist   Euclidean distance (takes only means into account)
      prob_dist   probabilistic "distance", defined as the inverse likelihood (takes into account means, covariances and hefts)
      M.assign(X, dist_mode)  
      return a row vector containing the indices of the closest means (or Gaussians) to each column vector in matrix X
       
       
       
      M.raw_hist(X, dist_mode)  
      return a row vector (of type urowvec) representing the raw histogram of counts; each entry is the number of counts corresponding to a Gaussian; each count is the number times the corresponding Gaussian was the closest to each column vector in matrix X; parameter dist_mode is either eucl_dist or prob_dist (as per the .assign() function above)
      M.norm_hist(X, dist_mode)  
      return a row vector (of type rowvec) containing normalised counts; the vector sums to one
       
       
       
      M.generate()  
      return a column vector representing a random sample generated according to the model's parameters
      M.generate(N)  
      return a matrix containing N column vectors, with each vector representing a random sample generated according to the model's parameters
       
       
       
      M.save(filename)  
      save the model to the given filename
      M.load(filename)  
      load the model from the given filename
       
       
       
      M.n_gaus()  
      return the number of means/Gaussians in the model
      M.n_dims()  
      return the dimensionality of the means/Gaussians in the model
       
       
       
      M.reset(n_dims, n_gaus)  
      set the model to have dimensionality n_dims, with n_gaus number of Gaussians;
      all the means are set to zero, all diagonal covariances are set to one, and all the hefts (weights) are set to be uniform
       
       
       
      M.means  
      read-only matrix containing the means (centroids), stored as column vectors
      M.dcovs  
      read-only matrix containing the diagonal covariance matrices, stored as column vectors
      M.hefts  
      read-only row vector containing the hefts (weights)
       
       
       
      M.set_means(X)  
      set the means to be as specified in matrix X;
      the number of means and their dimensionality must match the existing model
      M.set_dcovs(X)  
      set the diagonal covariances matrices to be as specified in matrix X;
      the number of diagonal covariance matrices and their dimensionality must match the existing model
      M.set_hefts(V)  
      set the hefts (weights) of the model to be as specified in row vector V;
      the number of hefts must match the existing model
       
       
       
      M.set_params(meansdcovshefts)  
      set all the parameters in one hit;
      the number of Gaussians and dimensionality can be different from the existing model
       
       
       
      M.learn(data, n_gaus, dist_mode, seed_mode, km_iter, em_iter, var_floor, print_mode)
       
       
      learn the model parameters via the k-means and/or EM algorithms,
      and return a bool variable, with true indicating success, and false indicating failure

  • Parameters for the .learn() member function:
           
      data   matrix containing training samples; each sample is stored as a column vector
           
      n_gaus   set the number of Gaussians to n_gaus
           
      dist_mode   specifies the distance used during the seeding of initial means and k-means clustering:
      eucl_dist   Euclidean distance
      maha_dist   Mahalanobis distance, which uses a global diagonal covariance matrix estimated from the training samples
           
      seed_mode   specifies how the initial means are seeded prior to running k-means and/or EM algorithms:
      keep_existing   keep the existing model (do not modify the means, covariances and hefts)
      static_subset   a subset of the training samples (repeatable)
      random_subset   a subset of the training samples (random)
      static_spread   a maximally spread subset of training samples (repeatable)
      random_spread   a maximally spread subset of training samples (random start)
           
      km_iter   the number of iterations of the k-means algorithm
           
      em_iter   the number of iterations of the EM algorithm
           
      var_floor   the variance floor (smallest allowed value) for the diagonal covariances
           
      print_mode   either true or false; enable or disable printing of progress during the k-means and EM algorithms


  • Notes:

    • for probabilistic applications, better model parameters are typically learned with dist_mode set to maha_dist

    • for vector quantisation applications, model parameters should be learned with dist_mode set to eucl_dist, and the number of EM iterations set to zero

    • in general, a sufficient number of k-means and EM iterations is typically about 10

    • the number of training samples should be much larger than the number of Gaussians

    • seeding the initial means with static_spread and random_spread can be much more time consuming than with static_subset and random_subset

    • the k-means and EM algorithms will run faster on multi-core machines when OpenMP is enabled in your compiler (eg. -fopenmp in GCC)

  • Examples:
      // create synthetic data with 2 Gaussians
      
      uword d = 5;       // dimensionality
      uword N = 10000;   // number of vectors
      
      mat data(d, N, fill::zeros);
      
      vec mean0 = linspace<vec>(1,d,d);
      vec mean1 = mean0 + 2;
      
      uword i = 0;
      
      while(i < N)
        {
        if(i < N)  { data.col(i) = mean0 + randn<vec>(d); ++i; }
        if(i < N)  { data.col(i) = mean0 + randn<vec>(d); ++i; }
        if(i < N)  { data.col(i) = mean1 + randn<vec>(d); ++i; }
        }
      
      
      // model the data as a GMM with 2 Gaussians
      
      gmm_diag model;
      
      bool status = model.learn(data, 2, maha_dist, random_subset, 10, 5, 1e-10, true);
      
      if(status == false)
        {
        cout << "learning failed" << endl;
        }
      
      model.means.print("means:");
      
      double  scalar_likelihood = model.log_p( data.col(0)    );
      rowvec     set_likelihood = model.log_p( data.cols(0,9) );
      
      double overall_likelihood = model.avg_log_p(data);
      
      uword   gaus_id  = model.assign( data.col(0),    eucl_dist );
      urowvec gaus_ids = model.assign( data.cols(0,9), prob_dist );
      
      urowvec hist1 = model.raw_hist (data, prob_dist);
       rowvec hist2 = model.norm_hist(data, eucl_dist);
      
      model.save("my_model.gmm");
      

  • See also:





Miscellaneous



constants (pi, inf, speed of light, ...)
    datum::pi   π, the ratio of any circle's circumference to its diameter
    datum::inf   ∞, infinity
    datum::nan   “not a number” (NaN); caveat: NaN is not equal to anything, even itself
         
    datum::e   base of the natural logarithm
    datum::sqrt2   square root of 2
    datum::eps   the difference between 1 and the least value greater than 1 that is representable (type and machine dependent)
         
    datum::log_min   log of minimum non-zero value (type and machine dependent)
    datum::log_max   log of maximum value (type and machine dependent)
    datum::euler   Euler's constant, aka Euler-Mascheroni constant
         
    datum::gratio   golden ratio
    datum::m_u   atomic mass constant (in kg)
    datum::N_A   Avogadro constant
         
    datum::k   Boltzmann constant (in joules per kelvin)
    datum::k_evk   Boltzmann constant (in eV/K)
    datum::a_0   Bohr radius (in meters)
         
    datum::mu_B   Bohr magneton
    datum::Z_0   characteristic impedance of vacuum (in ohms)
    datum::G_0   conductance quantum (in siemens)
         
    datum::k_e   Coulomb's constant (in meters per farad)
    datum::eps_0   electric constant (in farads per meter)
    datum::m_e   electron mass (in kg)
         
    datum::eV   electron volt (in joules)
    datum::ec   elementary charge (in coulombs)
    datum::F   Faraday constant (in coulombs)
         
    datum::alpha   fine-structure constant
    datum::alpha_inv   inverse fine-structure constant
    datum::K_J   Josephson constant
         
    datum::mu_0   magnetic constant (in henries per meter)
    datum::phi_0   magnetic flux quantum (in webers)
    datum::R   molar gas constant (in joules per mole kelvin)
         
    datum::G   Newtonian constant of gravitation (in newton square meters per kilogram squared)
    datum::h   Planck constant (in joule seconds)
    datum::h_bar   Planck constant over 2 pi, aka reduced Planck constant (in joule seconds)
         
    datum::m_p   proton mass (in kg)
    datum::R_inf   Rydberg constant (in reciprocal meters)
    datum::c_0   speed of light in vacuum (in meters per second)
         
    datum::sigma   Stefan-Boltzmann constant
    datum::R_k   von Klitzing constant (in ohms)
    datum::b   Wien wavelength displacement law constant

  • Caveat: datum::nan is not equal to anything, even itself; to check whether a given number x is finite, use is_finite(x)

  • The constants are stored in the Datum<type> class, where type is either float or double

  • For convenience, Datum<double> has been typedefed as datum while Datum<float> has been typedefed as fdatum

  • The physical constants were mainly taken from NIST 2014 CODATA values, and some from WolframAlpha (as of 2009-06-23)

  • Examples:
      cout << "2.0 * pi = " << 2.0 * datum::pi << endl;
      
      cout << "speed of light = " << datum::c_0 << endl;
      
      cout << "log_max for floats = ";
      cout << fdatum::log_max << endl;
      
      cout << "log_max for doubles = ";
      cout << datum::log_max << endl;
      
  • See also:



wall_clock
  • Simple wall clock timer class for measuring the number of elapsed seconds

  • Examples:
      wall_clock timer;
      
      mat A = randu<mat>(100,100);
      mat B = randu<mat>(100,100);
      mat C;
      
      timer.tic();
      
      for(uword i=0; i<100000; ++i)
        {
        C = A + B + A + B;
        }
      
      double n = timer.toc();
      
      cout << "number of seconds: " << n << endl;
      



logging of warnings and errors

set_stream_err1( user_stream )
set_stream_err2( user_stream )

std::ostream& x = get_stream_err1()
std::ostream& x = get_stream_err2()
  • By default, warnings and messages associated with exceptions are printed to the std::cout stream
    • the printing can be disabled by defining ARMA_DONT_PRINT_ERRORS before including the armadillo header
    • detailed information about errors is always reported via the base std::exception class

  • set_stream_err1(): change the stream for messages associated with std::logic_error exceptions (eg. out of bounds accesses)

  • set_stream_err2(): change the stream for warnings and messages associated with std::runtime_error and std::bad_alloc exceptions (eg. failed decompositions, out of memory)

  • get_stream_err1(): get a reference to the stream for messages associated with std::logic_error exceptions

  • get_stream_err2(): get a reference to the stream for warnings and messages associated with std::runtime_error exceptions

  • Examples:
      // print "hello" to the current err1 stream
      get_stream_err1() << "hello" << endl;
      
      // change the err2 stream to be a file
      ofstream f("my_log.txt");
      set_stream_err2(f);
      
      // trying to invert a singular matrix
      // will print a message to the err2 stream
      // and throw an exception
      mat X = zeros<mat>(5,5);
      mat Y = inv(X);
      
      // disable messages being printed to the err2 stream
      std::ostream nullstream(0);
      set_stream_err2(nullstream);
      

  • Caveat: set_stream_err1() and set_stream_err2() will not change the stream used by .print()

  • See also:



uword, sword
  • uword is a typedef for an unsigned integer type; it is used for matrix indices as well as all internal counters and loops

  • sword is a typedef for a signed integer type

  • The minimum width of both uword and sword is either 32 or 64 bits:
    • when using the old C++98 / C++03 standards, the default width is 32 bits
    • when using the new C++11 / C++14 standards, the default width is 64 bits on 64-bit platforms (as of Armadillo 5.000)

  • The width can also be forcefully set to 64 bits by enabling ARMA_64BIT_WORD via editing include/armadillo_bits/config.hpp

  • See also:



cx_double, cx_float


Examples of Matlab/Octave syntax and conceptually corresponding Armadillo syntax

    Matlab/Octave   Armadillo   Notes
             
    A(1, 1)   A(0, 0)   indexing in Armadillo starts at 0
    A(k, k)   A(k-1, k-1)    
             
    size(A,1)   A.n_rows   read only
    size(A,2)   A.n_cols    
    size(Q,3)   Q.n_slices   Q is a cube (3D array)
    numel(A)   A.n_elem    
             
    A(:, k)   A.col(k)   this is a conceptual example only; exact conversion from Matlab/Octave to Armadillo syntax will require taking into account that indexing starts at 0
    A(k, :)   A.row(k)    
    A(:, p:q)   A.cols(p, q)    
    A(p:q, :)   A.rows(p, q)    
    A(p:q, r:s)   A( span(p,q), span(r,s) )   A( span(first_row, last_row), span(first_col, last_col) )
             
    Q(:, :, k)   Q.slice(k)   Q is a cube (3D array)
    Q(:, :, t:u)   Q.slices(t, u)    
    Q(p:q, r:s, t:u)   Q( span(p,q), span(r,s), span(t,u) )    
             
    A'   A.t() or trans(A)   matrix transpose / Hermitian transpose
    (for complex matrices, the conjugate of each element is taken)
             
    A = zeros(size(A))   A.zeros()    
    A = ones(size(A))   A.ones()    
    A = zeros(k)   A = zeros<mat>(k,k)    
    A = ones(k)   A = ones<mat>(k,k)    
             
    C = complex(A,B)   cx_mat C = cx_mat(A,B)    
             
    A .* B   A % B   element-wise multiplication
    A ./ B   A / B   element-wise division
    A \ B   solve(A,B)   conceptually similar to inv(A)*B, but more efficient
    A = A + 1;   A++    
    A = A - 1;   A--    
             
    A = [ 1 2; 3 4; ]   << 1 << 2 << endr
       << 3 << 4 << endr;
      element initialisation, with special element endr indicating end of row
             
    X = A(:)   X = vectorise(A)    
    X = [ A  B ]   X = join_horiz(A,B)    
    X = [ A; B ]   X = join_vert(A,B)    
             
    A   cout << A << endl;
    or
    A.print("A =");
       
             
    save ‑ascii 'A.dat' A   A.save("A.dat", raw_ascii);   Matlab/Octave matrices saved as ascii are readable by Armadillo (and vice-versa)
    load ‑ascii 'A.dat'   A.load("A.dat", raw_ascii);    
             
    A = randn(2,3);
    B = randn(4,5);
    F = { A; B }
      mat A = randn(2,3);
    mat B = randn(4,5);
    field<mat> F(2,1);
    F(0,0) = A;
    F(1,0) = B;
      fields store arbitrary objects, such as matrices



example program
    #include <iostream>
    #include <armadillo>
    
    using namespace std;
    using namespace arma;
    
    int main()
      {
      mat A = randu<mat>(4,5);
      mat B = randu<mat>(4,5);
      
      cout << A*B.t() << endl;
      
      return 0;
      }
    
  • If you save the above program as example.cpp, under Linux and Mac OS X it can be compiled using:
    g++ example.cpp -o example -O2 -larmadillo

  • As Armadillo is a template library, we strongly recommend to enable optimisation when compiling programs (eg. when compiling with GCC or clang, use the -O2 or -O3 options)

  • See also the example program that comes with the Armadillo archive



config.hpp
  • Armadillo can be configured via editing the file include/armadillo_bits/config.hpp. Specific functionality can be enabled or disabled by uncommenting or commenting out a particular #define, listed below.

    ARMA_USE_LAPACK   Enable the use of LAPACK, or a high-speed replacement for LAPACK (eg. Intel MKL, AMD ACML or the Accelerate framework). Armadillo requires LAPACK for functions such as svd(), inv(), eig_sym(), solve(), etc.
         
    ARMA_DONT_USE_LAPACK   Disable use of LAPACK. Overrides ARMA_USE_LAPACK
         
    ARMA_USE_BLAS   Enable the use of BLAS, or a high-speed replacement for BLAS (eg. OpenBLAS, Intel MKL, AMD ACML or the Accelerate framework). BLAS is used for matrix multiplication. Without BLAS, Armadillo will use a built-in matrix multiplication routine, which might be slower for large matrices.
         
    ARMA_DONT_USE_BLAS   Disable use of BLAS. Overrides ARMA_USE_BLAS
         
    ARMA_USE_ARPACK   Enable the use of ARPACK, or a high-speed replacement for ARPACK. Armadillo requires ARPACK for the eigen decomposition of sparse matrices, ie. eigs_gen(), eigs_sym() and svds()
         
    ARMA_DONT_USE_ARPACK   Disable use of ARPACK. Overrides ARMA_USE_ARPACK
         
    ARMA_USE_SUPERLU   Enable the use of SuperLU, which is used by spsolve() for finding the solutions of sparse systems. Only SuperLU versions 4.x are supported. You will need to link with the superlu library (eg. -lsuperlu)
         
    ARMA_DONT_USE_SUPERLU   Disable use of SuperLU. Overrides ARMA_USE_SUPERLU
         
    ARMA_USE_HDF5   Enable the ability to save and load matrices stored in the HDF5 format; the hdf5.h header file must be available on your system and you will need to link with the hdf5 library (eg. -lhdf5)
         
    ARMA_DONT_USE_HDF5   Disable the use of the HDF5 library. Overrides ARMA_USE_HDF5
         
    ARMA_DONT_USE_WRAPPER   Disable going through the run-time Armadillo wrapper library (libarmadillo.so) when calling LAPACK, BLAS, ARPACK, SuperLU and HDF5 functions. You will need to directly link with LAPACK, BLAS, etc (eg. -llapack -lblas)
         
    ARMA_USE_CXX11   Use C++11 features, such as initialiser lists; automatically enabled when using a compiler in C++11 mode, for example, g++ -std=c++11
         
    ARMA_DONT_USE_CXX11   Disable use of C++11 features. Overrides ARMA_USE_CXX11
         
    ARMA_BLAS_CAPITALS   Use capitalised (uppercase) BLAS and LAPACK function names (eg. DGEMM vs dgemm)
         
    ARMA_BLAS_UNDERSCORE   Append an underscore to BLAS and LAPACK function names (eg. dgemm_ vs dgemm). Enabled by default.
         
    ARMA_BLAS_LONG   Use "long" instead of "int" when calling BLAS and LAPACK functions
         
    ARMA_BLAS_LONG_LONG   Use "long long" instead of "int" when calling BLAS and LAPACK functions
         
    ARMA_USE_TBB_ALLOC   Use Intel TBB scalable_malloc() and scalable_free() instead of standard malloc() and free() for managing matrix memory
         
    ARMA_USE_MKL_ALLOC   Use Intel MKL mkl_malloc() and mkl_free() instead of standard malloc() and free() for managing matrix memory
         
    ARMA_64BIT_WORD   Use 64 bit integers. Automatically enabled when using a C++11 compiler (as of Armadillo 5.000). Useful if you require matrices/vectors capable of holding more than 4 billion elements. Your machine and compiler must have support for 64 bit integers (eg. via "long" or "long long"). This can also be enabled by adding #define ARMA_64BIT_WORD before each instance of #include <armadillo>
         
    ARMA_NO_DEBUG   Disable all run-time checks, such as bounds checking. This will result in faster code, but you first need to make sure that your code runs correctly! We strongly recommend to have the run-time checks enabled during development, as this greatly aids in finding mistakes in your code, and hence speeds up development. We recommend that run-time checks be disabled only for the shipped version of your program (ie. final release build).
         
    ARMA_EXTRA_DEBUG   Print out the trace of internal functions used for evaluating expressions. Not recommended for normal use. This is mainly useful for debugging the library.
         
    ARMA_MAT_PREALLOC   The number of pre-allocated elements used by matrices and vectors. Must be always enabled and set to an integer that is at least 1. By default set to 16. If you mainly use lots of very small vectors (eg. ≤ 4 elements), change the number to the size of your vectors.
         
    ARMA_DEFAULT_OSTREAM   The default stream used for printing error messages and by .print(). Must be always enabled. By default defined to std::cout
         
    ARMA_PRINT_ERRORS   Print errors and warnings encountered during program execution
         
    ARMA_DONT_PRINT_ERRORS   Do not print errors or warnings. Overrides ARMA_PRINT_ERRORS
         

  • See also:



History of API Additions, Changes and Deprecations

  • API Version Policy
    • Armadillo's version number is A.B.C, where A is a major version, B is a minor version, and C is the patch level (indicating bug fixes)

    • Within each major version (eg. 4.x), minor versions are backwards compatible with earlier minor versions. For example, code written for version 4.000 will work with version 4.100, 4.120, 4.200, etc. However, as each minor version may have more features (ie. API extensions) than earlier versions, code specifically written for version 4.100 doesn't necessarily work with 4.000

    • We don't like changes to existing APIs and strongly prefer not to break any user software. However, to allow evolution, we reserve the right to alter the APIs in future major versions of Armadillo while remaining backwards compatible in as many cases as possible (eg. version 5.x may have slightly different APIs than 4.x). In a rare instance the user API may need to be tweaked if a bug fix absolutely requires it

    • This policy is applicable to the APIs described in this documentation; it is not applicable to internal functions (ie. the underlying internal implementation details may change across consecutive minor versions)


  • List of additions and changes for each version:

    • Version 6.500:
      • added conv2() for 2D convolution
      • added stand-alone kmeans() function for clustering data
      • added trunc()
      • extended conv() to optionally provide central convolution
      • faster handling of multiply-and-accumulate by accu() when using Intel MKL, ATLAS or OpenBLAS

    • Version 6.400:

    • Version 6.300:

    • Version 6.200:
      • expanded diagmat() to handle non-square matrices and arbitrary diagonals
      • expanded trace() to handle non-square matrices

    • Version 6.100:
      • faster norm() and normalise() when using Intel MKL, ATLAS or OpenBLAS
      • added Schur decomposition: schur()
      • stricter handling of matrix objects by hist() and histc()
      • advanced constructors for using auxiliary memory by Mat, Col, Row and Cube now have the default of strict = false
      • Cube class now delays allocation of .slice() related structures until needed
      • expanded join_slices() to handle joining cubes with matrices

    • Version 5.600:

    • Version 5.500:
      • expanded object constructors and generators to handle size() based specification of dimensions

    • Version 5.400:
      • added find_unique() for finding indices of unique values
      • added diff() for calculating differences between consecutive elements
      • added cumprod() for calculating cumulative product
      • added null() for finding the orthonormal basis of null space
      • expanded interp1() to handle repeated locations
      • expanded unique() to handle complex numbers
      • faster flipud()
      • faster row-wise cumsum()

    • Version 5.300:

    • Version 5.200:
      • added orth() for finding the orthonormal basis of the range space of a matrix
      • expanded element initialisation to handle nested initialiser lists (C++11)

    • Version 5.100:

    • Version 5.000:

    • Version 4.650:
      • added randg() for generating random values from gamma distributions (C++11 only)
      • added .head_rows() and .tail_rows() to submatrix views
      • added .head_cols() and .tail_cols() to submatrix views
      • expanded eigs_sym() to optionally calculate eigenvalues with smallest/largest algebraic values

    • Version 4.600:
      • added .head() and .tail() to submatrix views
      • faster matrix transposes within compound expressions
      • faster in-place matrix multiplication
      • faster accu() and norm() when compiling with -O3 -ffast-math -march=native (gcc and clang)

    • Version 4.550:
      • added matrix exponential function: expmat()
      • faster .log_p() and .avg_log_p() functions in the gmm_diag class when compiling with OpenMP enabled
      • faster handling of in-place addition/subtraction of expressions with an outer product

    • Version 4.500:
      • faster handling of complex vectors by norm()
      • expanded chol() to optionally specify output matrix as upper or lower triangular
      • better handling of non-finite values when saving matrices as text files

    • Version 4.450:
      • faster handling of matrix transposes within compound expressions
      • expanded symmatu()/symmatl() to optionally disable taking the complex conjugate of elements
      • expanded sort_index() to handle complex vectors
      • expanded the gmm_diag class with functions to generate random samples

    • Version 4.400:
      • faster handling of subvectors by dot()
      • faster handling of aliasing by submatrix views
      • added clamp() for clamping values to be between lower and upper limits
      • added gmm_diag class for statistical modelling of data using Gaussian Mixture Models
      • expanded batch insertion constructors for sparse matrices to add values at repeated locations

    • Version 4.320:
      • expanded eigs_sym() and eigs_gen() to use an optional tolerance parameter
      • expanded eig_sym() to automatically fall back to standard decomposition method if divide-and-conquer fails
      • cmake-based installer enables use of C++11 random number generator when using gcc 4.8.3+ in C++11 mode

    • Version 4.300:

    • Version 4.200:
      • faster transpose of sparse matrices
      • more efficient handling of aliasing during matrix multiplication
      • faster inverse of matrices marked as diagonal

    • Version 4.100:
      • added normalise() for normalising vectors to unit p-norm
      • extended the field class to handle 3D layout
      • extended eigs_sym() and eigs_gen() to obtain eigenvalues of various forms (eg. largest or smallest magnitude)
      • automatic SIMD vectorisation of elementary expressions (eg. matrix addition) when using Clang 3.4+ with -O3 optimisation
      • faster handling of sparse submatrix views

    • Version 4.000:

    • Version 3.930:

    • Version 3.920:
      • faster .zeros()
      • faster round(), exp2() and log2() when using C++11
      • added signum function: sign()
      • added move constructors when using C++11
      • added 2D fast Fourier transform: fft2()
      • added .tube() for easier extraction of vectors and subcubes from cubes
      • added specification of a fill type during construction of Mat, Col, Row and Cube classes, eg. mat X(4, 5, fill::zeros)

    • Version 3.910:
      • faster multiplication of a matrix with a transpose of itself, ie. X*X.t() and X.t()*X
      • added vectorise() for reshaping matrices into vectors
      • added all() and any() for indicating presence of elements satisfying a relational condition

    • Version 3.900:
      • added automatic SSE2 vectorisation of elementary expressions (eg. matrix addition) when using GCC 4.7+ with -O3 optimisation
      • faster median()
      • faster handling of compound expressions with transposes of submatrix rows
      • faster handling of compound expressions with transposes of complex vectors
      • added support for saving & loading of cubes in HDF5 format

    • Version 3.820:
      • faster as_scalar() for compound expressions
      • faster transpose of small vectors
      • faster matrix-vector product for small vectors
      • faster multiplication of small fixed size matrices

    • Version 3.810:

    • Version 3.800:
    • Version 3.6:
      • faster handling of compound expressions with submatrices and subcubes
      • faster trace()
      • added support for loading matrices as text files with NaN and Inf elements
      • added stable_sort_index(), which preserves the relative order of elements with equivalent values
      • added handling of sparse matrices by mean(), var(), norm(), abs(), square(), sqrt()
      • added saving and loading of sparse matrices in arma_binary format

    • Version 3.4:
    • Version 3.2:
      • added unique(), for finding unique elements of a matrix
      • added .eval(), for forcing the evaluation of delayed expressions
      • faster eigen decomposition via optional use of divide-and-conquer algorithm
      • faster transpose of vectors and compound expressions
      • faster handling of diagonal views
      • faster handling of tiny fixed size vectors (≤ 4 elements)

    • Version 3.0:
    • Version 2.4:
      • added shorter forms of transposes: .t() and .st()
      • added .resize() and resize()
      • added optional use of 64 bit indices (allowing matrices to have more than 4 billion elements), enabled via ARMA_64BIT_WORD in include/armadillo_bits/config.hpp
      • added experimental support for C++11 initialiser lists, enabled via ARMA_USE_CXX11 in include/armadillo_bits/config.hpp
      • refactored code to eliminate warnings when using the Clang C++ compiler
      • umat, uvec, .min() and .max() have been changed to use the uword type instead of the u32 type; by default the uword and u32 types are equivalent (ie. unsigned integer type with a minimum width 32 bits); however, when the use of 64 bit indices is enabled via ARMA_64BIT_WORD in include/armadillo_bits/config.hpp, the uword type then has a minimum width of 64 bits

    • Version 2.2:
    • Version 2.0:
    • Version 1.2:
      • added .min() & .max() member functions of Mat and Cube
      • added floor() and ceil()
      • added representation of “not a number”: math::nan()
      • added representation of infinity: math::inf()
      • added standalone is_finite()
      • .in_range() expanded to use span() arguments
      • fixed size matrices and vectors can use auxiliary (external) memory
      • submatrices and subfields can be accessed via X( span(a,b)span(c,d) )
      • subcubes can be accessed via X( span(a,b)span(c,d)span(e,f) )
      • the two argument version of span can be replaced by span::all or span(), to indicate an entire range
      • for cubes, the two argument version of span can be replaced by a single argument version, span(a), to indicate a single column, row or slice
      • arbitrary "flat" subcubes can be interpreted as matrices; for example:
          cube Q = randu<cube>(5,3,4);
          mat  A = Q( span(1), span(1,2), span::all );
          // A has a size of 2x4
          
          vec v = ones<vec>(4);
          Q( span(1), span(1), span::all ) = v;
          
      • added interpretation of matrices as triangular through trimatu() / trimatl()
      • added explicit handling of triangular matrices by solve() and inv()
      • extended syntax for submatrices, including access to elements whose indices are specified in a vector
      • added ability to change the stream used for logging of errors and warnings
      • added ability to save/load matrices in raw binary format
      • added cumulative sum function: cumsum()

    • Changed in 1.0 (compared to earlier 0.x development versions):
      • the 3 argument version of lu(), eg. lu(L,U,X), provides L and U which should be the same as produced by Octave 3.2 (this was not the case in versions prior to 0.9.90)

      • rand() has been replaced by randu(); this has been done to avoid confusion with std::rand(), which generates random numbers in a different interval

      • In versions earlier than 0.9.0, some multiplication operations directly converted result matrices with a size of 1x1 into scalars. This is no longer the case. If you know the result of an expression will be a 1x1 matrix and wish to treat it as a pure scalar, use the as_scalar() wrapping function

      • Almost all functions have been placed in the delayed operations framework (for speed purposes). This may affect code which assumed that the output of some functions was a pure matrix. The solution is easy, as explained below.

        In general, Armadillo queues operations before executing them. As such, the direct output of an operation or function cannot be assumed to be a directly accessible matrix. The queued operations are executed when the output needs to be stored in a matrix, eg. mat B = trans(A) or mat B(trans(A)). If you need to force the execution of the delayed operations, place the operation or function inside the corresponding Mat constructor. For example, if your code assumed that the output of some functions was a pure matrix, eg. chol(m).diag(), change the code to mat(chol(m)).diag(). Similarly, if you need to pass the result of an operation such as A+B to one of your own functions, use my_function( mat(A+B) ).




  • armadillo-6.500.5/README.txt0000666000000000000000000003564412656563706014067 0ustar rootrootArmadillo C++ Linear Algebra Library http://arma.sourceforge.net Contents ======== 1: Introduction 2: Citation Details 3: Licenses 4: Technical Support 5: Requirements 6: Linux and Mac OS X: Installation 7: Linux and Mac OS X: Compiling & Linking 8: Windows: Installation 9: Windows: Compiling & Linking 10: Support for OpenBLAS, Intel MKL and AMD ACML 11: Support for ATLAS 12: API Documentation 13: MEX Interface to Octave/Matlab 14: Bug Reports and Frequently Asked Questions 15: Related Software 1: Introduction =============== Armadillo is a high quality C++ linear algebra library, aiming towards a good balance between speed and ease of use. It's useful for algorithm development directly in C++, and/or quick conversion of research code into production environments. The syntax (API) is deliberately similar to Matlab. The library provides efficient classes for vectors, matrices and cubes, as well as 150+ associated functions (eg. contiguous and non-contiguous submatrix views). Various matrix decompositions are provided through integration with LAPACK, or one of its high performance drop-in replacements (eg. OpenBLAS, Intel MKL, AMD ACML, Apple Accelerate framework, etc). An automatic expression evaluator (via C++ template meta-programming) combines several operations (at compile time) to increase efficiency. The library can be used for machine learning, pattern recognition, signal processing, bioinformatics, statistics, econometrics, etc. Armadillo is primarily developed at Data61 / NICTA (Australia). For information about Data61 see http://data61.csiro.au Main developers: Conrad Sanderson - http://conradsanderson.id.au Ryan Curtin - http://ratml.org 2: Citation Details =================== Please cite the following tech report if you use Armadillo in your research and/or software. Citations are useful for the continued development and maintenance of the library. Conrad Sanderson. Armadillo: An Open Source C++ Linear Algebra Library for Fast Prototyping and Computationally Intensive Experiments. Technical Report, NICTA, 2010. 3: Licenses =========== Armadillo is available under 2 licenses: - Open source, using the Mozilla Public License (MPL) 2.0. See the "LICENSE.txt" file for details. - Non-open source (commercial) license, available for purchase. Please contact Conrad Sanderson for more information: http://conradsanderson.id.au 4: Technical Support ==================== You can purchase technical support on a commercial basis. Please contact Conrad Sanderson for more information: http://conradsanderson.id.au 5: Requirements =============== Armadillo makes extensive use of template meta-programming, recursive templates and template based function overloading. As such, C++ compilers which do not fully implement the C++ standard may not work correctly. The functionality of Armadillo is partly dependent on other libraries: LAPACK, BLAS, ARPACK and SuperLU. The LAPACK and BLAS libraries are used for dense matrices, while the ARPACK and SuperLU libraries are used for sparse matrices. Armadillo can work without these libraries, but its functionality will be reduced. In particular, basic functionality will be available (eg. matrix addition and multiplication), but things like eigen decomposition or matrix inversion will not be. Matrix multiplication (mainly for big matrices) may not be as fast. As Armadillo is a template library, we recommended that optimisation is enabled during compilation of programs that use Armadillo. For example, for GCC and Clang compilers use -O2 or -O3 6: Linux and Mac OS X: Installation =================================== * Step 1: Ensure a C++ compiler is installed on your system. Caveat: on Mac OS X you will need to install Xcode and then type the following command in a terminal window: xcode-select --install * Step 2: Ensure the CMake tool is installed on your system. You can download it from http://www.cmake.org or (preferably) install it using your package manager. On Linux-based systems, you can get CMake using yum, dnf, apt, aptitude, ... On Mac OS X systems, you can get CMake through MacPorts or Homebrew. * Step 3: Ensure LAPACK and BLAS are installed on your system. On Mac OS X this is not necessary. For better performance, we recommend installing the OpenBLAS library. See http://xianyi.github.com/OpenBLAS/ If you are using sparse matrices, also install ARPACK and SuperLU. Caveat: only SuperLU version 4.3 can be used! On Linux-based systems, the following libraries are recommended to be present: OpenBLAS, LAPACK, SuperLU and ARPACK. It is also necessary to install the corresponding development files for each library. For example, when installing the "lapack" package, also install the "lapack-devel" or "lapack-dev" package. * Step 4: Open a terminal window, change into the directory that was created by unpacking the armadillo archive, and type the following commands: cmake . make The full stop separated from "cmake" by a space is important. CMake will detect which relevant libraries are installed on your system (eg. OpenBLAS, LAPACK, SuperLU, ARPACK, etc) and will modify Armadillo's configuration correspondingly. CMake will also generate a run-time armadillo library, which is a wrapper for all the detected libraries. If you need to re-run cmake, it's a good idea to first delete the "CMakeCache.txt" file (not "CMakeLists.txt"). Caveat: out-of-tree builds are currently not fully supported; eg, creating a sub-directory called "build" and running cmake .. from within "build" is currently not supported. * Step 5: If you have access to root/administrator/superuser privileges (ie. able to use "sudo"), type the following command: sudo make install If you don't have root/administrator/superuser privileges, type the following command: make install DESTDIR=my_usr_dir where "my_usr_dir" is for storing C++ headers and library files. Caveat: make sure your C++ compiler is configured to use the "lib" and "include" sub-directories present within this directory. 7: Linux and Mac OS X: Compiling & Linking ========================================== The "examples" directory contains several quick example programs that use the Armadillo library. In general, programs which use Armadillo are compiled along these lines: g++ example1.cpp -o example1 -O2 -larmadillo If you want to use Armadillo without installation (not recommended), compile along these lines: g++ example1.cpp -o example1 -O2 -I /home/blah/armadillo-6.500.5/include -DARMA_DONT_USE_WRAPPER -lblas -llapack The above command line assumes that you have unpacked the armadillo archive into /home/blah/ You will need to adjust this for later versions of Armadillo, and/or if you have unpacked the armadillo archive into a different directory. Replace -lblas with -lopenblas if you have OpenBLAS. On Mac OS X, replace -lblas -llapack with -framework Accelerate 8: Windows: Installation ======================== The installation is comprised of 3 steps: * Step 1: Copy the entire "include" folder to a convenient location and tell your compiler to use that location for header files (in addition to the locations it uses already). Alternatively, you can use the "include" folder directly. * Step 2: Modify "include/armadillo_bits/config.hpp" to indicate which libraries are currently available on your system. For example, if you have LAPACK, BLAS (or OpenBLAS), ARPACK and SuperLU present, uncomment the following lines: #define ARMA_USE_LAPACK #define ARMA_USE_BLAS #define ARMA_USE_ARPACK #define ARMA_USE_SUPERLU If you don't need sparse matrices, don't worry about ARPACK or SuperLU. * Step 3: Configure your compiler to link with LAPACK and BLAS (and optionally ARPACK and SuperLU). 9: Windows: Compiling & Linking =============================== Within the "examples" folder, we have included an MSVC project named "example1_win64" which can be used to compile "example1.cpp". The project needs to be compiled as a 64 bit program: the active solution platform must be set to x64, instead of win32. The MSCV project was tested on 64 bit Windows 7 with Visual C++ 2012. You may need to make adaptations for 32 bit systems, later versions of Windows and/or the compiler. For example, you may have to enable or disable ARMA_BLAS_LONG and ARMA_BLAS_UNDERSCORE macros in "armadillo_bits/config.hpp". The folder "examples/lib_win64" contains standard LAPACK and BLAS libraries compiled for 64 bit Windows. The compilation was done by a third party. USE AT YOUR OWN RISK. The compiled versions of LAPACK and BLAS were obtained from: http://ylzhao.blogspot.com.au/2013/10/blas-lapack-precompiled-binaries-for.html You can find the original sources for standard BLAS and LAPACK at: http://www.netlib.org/blas/ http://www.netlib.org/lapack/ Faster and/or alternative implementations of BLAS and LAPACK are available: http://xianyi.github.com/OpenBLAS/ http://software.intel.com/en-us/intel-mkl/ http://developer.amd.com/tools-and-sdks/cpu-development/amd-core-math-library-acml/ http://icl.cs.utk.edu/lapack-for-windows/lapack/ The OpenBLAS, MKL and ACML libraries are generally the fastest. For better performance, we recommend the following high-quality C++ compilers: GCC from MinGW: http://www.mingw.org/ GCC from CygWin: http://www.cygwin.com/ Intel C++ compiler: http://software.intel.com/en-us/intel-compilers/ For the GCC compiler, use version 4.2 or later. For the Intel compiler, use version 11.0 or later. For best results we also recommend using an operating system that's more reliable and more suitable for heavy duty work, such as Mac OS X, or various Linux-based systems: Ubuntu http://www.ubuntu.com/ Debian http://www.debian.org/ OpenSUSE http://www.opensuse.org/ Fedora http://fedoraproject.org/ Scientific Linux http://www.scientificlinux.org/ CentOS http://centos.org/ Red Hat Enterprise Linux http://www.redhat.com/ 10: Support for OpenBLAS, Intel MKL and AMD ACML ================================================ Armadillo can use OpenBLAS, or Intel Math Kernel Library (MKL), or the AMD Core Math Library (ACML) as high-speed replacements for BLAS and LAPACK. Generally this just involves linking with the replacement libraries instead of BLAS and LAPACK. You may need to make minor modifications to "include/armadillo_bits/config.hpp" in order to make sure Armadillo uses the same style of function names as used by MKL or ACML. For example, the function names might be in capitals. On Linux systems, MKL and ACML might be installed in a non-standard location, such as /opt, which can cause problems during linking. Before installing Armadillo, the system should know where the MKL or ACML libraries are located. For example, "/opt/intel/mkl/lib/intel64/". This can be achieved by setting the LD_LIBRARY_PATH environment variable, or for a more permanent solution, adding the directory locations to "/etc/ld.so.conf". It may also be possible to store a text file with the locations in the "/etc/ld.so.conf.d" directory. For example, "/etc/ld.so.conf.d/mkl.conf". If you modify "/etc/ld.so.conf" or create "/etc/ld.so.conf.d/mkl.conf", you will need to run "/sbin/ldconfig" afterwards. Example of the contents of "/etc/ld.so.conf.d/mkl.conf" on a RHEL 6 system, where Intel MKL version 11.0.3 is installed in "/opt/intel": /opt/intel/lib/intel64 /opt/intel/mkl/lib/intel64 The default installations of ACML 4.4.0 and MKL 10.2.2.025 are known to have issues with SELinux, which is turned on by default in Fedora (and possibly RHEL). The problem may manifest itself during run-time, where the run-time linker reports permission problems. It is possible to work around the problem by applying an appropriate SELinux type to all ACML and MKL libraries. If you have ACML or MKL installed and they are persistently giving you problems during linking, you can disable the support for them by editing the "CMakeLists.txt" file, deleting "CMakeCache.txt" and re-running the CMake based installation. Specifically, comment out the lines containing: INCLUDE(ARMA_FindMKL) INCLUDE(ARMA_FindACMLMP) INCLUDE(ARMA_FindACML) 11: Support for ATLAS ===================== Armadillo can use the ATLAS library for faster versions of certain LAPACK and BLAS functions. Not all ATLAS functions are currently used, and as such LAPACK should still be installed. The minimum recommended version of ATLAS is 3.8. Old versions (eg. 3.6) can produce incorrect results as well as corrupting memory, leading to random crashes. Users of older Ubuntu and Debian based systems should explicitly check that ATLAS 3.6 is not installed. It's better to remove the old version and use the standard LAPACK library. 12: API Documentation ===================== Documentation of functions and classes is available at: http://arma.sourceforge.net/docs.html The documentation is also in the "docs.html" file in this archive, which can be viewed with a web browser. 13: MEX Interface to Octave/Matlab ================================== The "mex_interface" folder contains examples of how to interface Octave/Matlab with C++ code that uses Armadillo matrices. 14: Bug Reports and Frequently Asked Questions ============================================== Answers to frequently asked questions can be found at: http://arma.sourceforge.net/faq.html This library has gone through extensive testing and has been successfully used in production environments. However, as with almost all software, it's impossible to guarantee 100% correct functionality. If you find a bug in the library (or the documentation), we are interested in hearing about it. Please make a _small_ and _self-contained_ program which exposes the bug, and then send the program source (as well as the bug description) to the developers. The developers' contact details are at: http://arma.sourceforge.net/contact.html 15: Related Software ==================== * MLPACK: C++ library for machine learning and pattern recognition, built on top of Armadillo. http://mlpack.org * Mantella: C++ library for analysing and solving optimisation problems https://github.com/SebastianNiemann/Mantella * libpca: C++ library for principal component analysis http://sourceforge.net/projects/libpca/ * ArmaNpy: interfaces Armadillo matrices with Python http://sourceforge.net/projects/armanpy/ * matlab2cpp: conversion of Matlab code to Armadillo based C++ code https://github.com/jonathf/matlab2cpp armadillo-6.500.5/index.html0000666000000000000000000000152112620272703014332 0ustar rootroot
    armadillo-6.500.5/mex_interface/0000777000000000000000000000000012656572547015171 5ustar rootrootarmadillo-6.500.5/mex_interface/readMatTest.cpp0000666000000000000000000000160212620272703020067 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by George Yammine // Demonstration of how to connect Armadillo with Matlab mex functions. // Version 0.5 #include "armaMex.hpp" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Read the matrix from the file inData.mat mat fromFile = armaReadMatFromFile("inData.mat"); fromFile.print(); mat tmp(4,6); tmp.randu(); // Write the matrix tmp as outData in the file outData.mat armaWriteMatToFile("outData.mat", tmp, "outData"); } armadillo-6.500.5/mex_interface/README.txt0000666000000000000000000000027512620272703016651 0ustar rootroot IMPORTANT! ---------- All mex objects need to be linked _statically_ with BLAS and LAPACK (or high-performance versions such as OpenBLAS) in order to work correctly with Matlab. armadillo-6.500.5/mex_interface/run_demo.m0000666000000000000000000000031412656116504017140 0ustar rootroot % Compile the demo as a mex file mex -larmadillo -lgfortran armaMex_demo.cpp % Generate two random matrices X = rand(4,5); Y = rand(4,5); % Run the demo using X and Y Z = armaMex_demo(X,Y) armadillo-6.500.5/mex_interface/armaMex.hpp0000666000000000000000000006144712620272703017266 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by George Yammine // Connector for Mex files to use Armadillo for calculation // Version 0.5 #include #include #include #include using namespace std; using namespace arma; // Get scalar value from Matlab/Octave template inline Type armaGetScalar(const mxArray *matlabScalar) { if(mxGetData(matlabScalar) != NULL) { return (Type)mxGetScalar(matlabScalar); } else { mexErrMsgTxt("No data available."); return 0; } } // To keep with Matlab/Octave mex functions since functions for double are usually defined in conjunction with the general functions. inline double armaGetDouble(const mxArray *matlabScalar) { return armaGetScalar(matlabScalar); } // Get non-double real matrix from Matlab/Octave. Type should be case according to input. // Use mxGetClassID inside main program to test for type. template inline Mat armaGetData(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if(mxGetData(matlabMatrix) != NULL) { const mwSize n_dim = mxGetNumberOfDimensions(matlabMatrix); if(n_dim == 2) { return Mat((Type *)mxGetData(matlabMatrix), mxGetM(matlabMatrix), mxGetN(matlabMatrix), copy_aux_mem, strict); } else { mexErrMsgTxt("Number of dimensions must be 2."); return Mat(); } } else { mexErrMsgTxt("No data available."); return Mat(); } } // Get double real matrix from Matlab/Octave. inline Mat armaGetPr(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if(mxGetData(matlabMatrix) != NULL) { const mwSize n_dim = mxGetNumberOfDimensions(matlabMatrix); if(n_dim == 2) { return Mat(mxGetPr(matlabMatrix), mxGetM(matlabMatrix), mxGetN(matlabMatrix), copy_aux_mem, strict); } else { mexErrMsgTxt("Number of dimensions must be 2."); return Mat(); } } else { mexErrMsgTxt("No data available."); return Mat(); } } // Get non-double imaginary matrix from Matlab/Octave. Type should be case according to input. // Use mxGetClassID inside main program to test for type. template inline Mat armaGetImagData(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if(mxGetImagData(matlabMatrix) != NULL) { const mwSize n_dim = mxGetNumberOfDimensions(matlabMatrix); if(n_dim == 2) { return Mat((Type *)mxGetImagData(matlabMatrix), mxGetM(matlabMatrix), mxGetN(matlabMatrix), copy_aux_mem, strict); } else { mexErrMsgTxt("Number of dimensions must be 2."); return Mat(); } } else { mexErrMsgTxt("No data available."); return Mat(); } } // Get double imaginary matrix from Matlab/Octave. inline Mat armaGetPi(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if(mxGetImagData(matlabMatrix) != NULL) { const mwSize n_dim = mxGetNumberOfDimensions(matlabMatrix); if(n_dim == 2) { return Mat(mxGetPi(matlabMatrix), mxGetM(matlabMatrix), mxGetN(matlabMatrix), copy_aux_mem, strict); } else { mexErrMsgTxt("Number of dimensions must be 2."); return Mat(); } } else { mexErrMsgTxt("No data available."); return Mat(); } } // Get complex matrix from Matlab/Octave inline cx_mat armaGetCx(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if( (mxGetPr(matlabMatrix) != NULL) && (mxGetPi(matlabMatrix) != NULL) ) { return cx_mat(armaGetPr(matlabMatrix, copy_aux_mem, strict), armaGetPi(matlabMatrix, copy_aux_mem, strict)); } else if( (mxGetPr(matlabMatrix) != NULL) && (mxGetPi(matlabMatrix) == NULL) ) { return cx_mat(armaGetPr(matlabMatrix, copy_aux_mem, strict), zeros(mxGetM(matlabMatrix),mxGetN(matlabMatrix))); } else if( (mxGetPr(matlabMatrix) == NULL) && (mxGetPi(matlabMatrix) != NULL) ) { return cx_mat(zeros(mxGetM(matlabMatrix), mxGetN(matlabMatrix)), armaGetPi(matlabMatrix, copy_aux_mem, strict)); } else { mexErrMsgTxt("No data available."); return cx_mat(); } } // Return non-double real valued matrix to Matlab/Octave template inline void armaSetData(mxArray *matlabMatrix, const Mat& armaMatrix) { Type *dst_pointer = (Type*)mxGetData(matlabMatrix); const Type *src_pointer = (Type*)armaMatrix.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(Type)*armaMatrix.n_elem); } // Return double real valued matrix to Matlab/Octave inline void armaSetPr(mxArray *matlabMatrix, const Mat& armaMatrix) { double *dst_pointer = mxGetPr(matlabMatrix); const double *src_pointer = armaMatrix.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(double)*armaMatrix.n_elem); } // Return imaginary valued matrix to Matlab/Octave. template inline void armaSetImagData(mxArray *matlabMatrix, const Mat& armaMatrix) { Type *dst_pointer = (Type*)mxGetImagData(matlabMatrix); const Type *src_pointer = (Type*)armaMatrix.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(Type)*armaMatrix.n_elem); } // Return double complex valued matrix to Matlab/Octave inline void armaSetPi(mxArray *matlabMatrix, const Mat& armaMatrix) { double *dst_pointer = mxGetPi(matlabMatrix); const double *src_pointer = armaMatrix.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(double)*armaMatrix.n_elem); } // Return complex matrix to Matlab/Octave. Requires Matlab/Octave matrix to be mxCOMPLEX inline void armaSetCx(mxArray *matlabMatrix, const cx_mat& armaMatrix) { armaSetPr(matlabMatrix, real(armaMatrix)); armaSetPi(matlabMatrix, imag(armaMatrix)); } // Cube functions // Get non-double real cube from Matlab/Octave. Type should be case according to input. // Use mxGetClassID inside main program to test for type. template inline Cube armaGetCubeData(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if(mxGetData(matlabMatrix) != NULL) { const mwSize n_dim = mxGetNumberOfDimensions(matlabMatrix); if(n_dim == 3) { const mwSize *dims = mxGetDimensions(matlabMatrix); return Cube((Type *)mxGetData(matlabMatrix), dims[0], dims[1], dims[2], copy_aux_mem, strict); } else { mexErrMsgTxt("Number of dimensions must be 3."); return Cube(); } } else { mexErrMsgTxt("No data available."); return Cube(); } } // Get double cube from Matlab/Octave. inline Cube armaGetCubePr(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if(mxGetData(matlabMatrix) != NULL) { const mwSize n_dim = mxGetNumberOfDimensions(matlabMatrix); if(n_dim == 3) { const mwSize *dims = mxGetDimensions(matlabMatrix); return Cube(mxGetPr(matlabMatrix), dims[0], dims[1], dims[2], copy_aux_mem, strict); } else { mexErrMsgTxt("Number of dimensions must be 3."); return Cube(); } } else { mexErrMsgTxt("No data available."); return Cube(); } } // Get non-double imaginary cube from Matlab/Octave. Type should be case according to input. // Use mxGetClassID inside main program to test for type. template inline Cube armaGetCubeImagData(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if(mxGetImagData(matlabMatrix) != NULL) { const mwSize n_dim = mxGetNumberOfDimensions(matlabMatrix); if(n_dim == 3) { const mwSize *dims = mxGetDimensions(matlabMatrix); return Cube((Type *)mxGetImagData(matlabMatrix), dims[0], dims[1], dims[2], copy_aux_mem, strict); } else { mexErrMsgTxt("Number of dimensions must be 3."); return Cube(); } } else { mexErrMsgTxt("No data available."); return Cube(); } } // Get double cube from Matlab/Octave. inline Cube armaGetCubePi(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if(mxGetImagData(matlabMatrix) != NULL) { const mwSize n_dim = mxGetNumberOfDimensions(matlabMatrix); if(n_dim == 3) { const mwSize *dims = mxGetDimensions(matlabMatrix); return Cube(mxGetPi(matlabMatrix), dims[0], dims[1], dims[2], copy_aux_mem, strict); } else { mexErrMsgTxt("Number of dimensions must be 3."); return Cube(); } } else { mexErrMsgTxt("No data available."); return Cube(); } } // Get complex cube from Matlab/Octave inline cx_cube armaGetCubeCx(const mxArray *matlabMatrix, bool copy_aux_mem = false, bool strict = true) { if( (mxGetPr(matlabMatrix) != NULL) && (mxGetPi(matlabMatrix) != NULL) ) { return cx_cube(armaGetCubePr(matlabMatrix, copy_aux_mem, strict), armaGetCubePi(matlabMatrix, copy_aux_mem, strict)); } else if( (mxGetPr(matlabMatrix) != NULL) && (mxGetPi(matlabMatrix) == NULL) ) { const mwSize *dims = mxGetDimensions(matlabMatrix); return cx_cube(armaGetCubePr(matlabMatrix, copy_aux_mem, strict), zeros(dims[0], dims[1], dims[2])); } else if( (mxGetPr(matlabMatrix) == NULL) && (mxGetPi(matlabMatrix) != NULL) ) { const mwSize *dims = mxGetDimensions(matlabMatrix); return cx_cube(zeros(dims[0], dims[1], dims[2]), armaGetCubePi(matlabMatrix, copy_aux_mem, strict)); } else { mexErrMsgTxt("No data available."); return cx_cube(); } } // return real valued cube to Matlab/Octave template inline void armaSetCubeData(mxArray *matlabMatrix, const Cube& armaCube) { Type *dst_pointer = (Type*)mxGetData(matlabMatrix); const Type *src_pointer = (Type*)armaCube.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(Type)*armaCube.n_elem); } // Return double real valued cube to Matlab/Octave inline void armaSetCubePr(mxArray *matlabMatrix, const Cube& armaCube) { double *dst_pointer = mxGetPr(matlabMatrix); const double *src_pointer = armaCube.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(double)*armaCube.n_elem); } // Return imaginary valued cube to Matlab/Octave. template inline void armaSetImagCubeData(mxArray *matlabMatrix, const Cube& armaCube) { Type *dst_pointer = (Type*)mxGetImagData(matlabMatrix); const Type *src_pointer = (Type*)armaCube.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(Type)*armaCube.n_elem); } // Return double imaginary valued matrix to Matlab/Octave inline void armaSetCubePi(mxArray *matlabMatrix, const Cube& armaCube) { double *dst_pointer = mxGetPi(matlabMatrix); const double *src_pointer = armaCube.memptr(); std::memcpy(dst_pointer, src_pointer, sizeof(double)*armaCube.n_elem); } // Return double complex cube to Matlab/Octave. void armaSetCubeCx(mxArray *matlabMatrix, const cx_cube& armaCube) { armaSetCubePr(matlabMatrix, real(armaCube)); armaSetCubePi(matlabMatrix, imag(armaCube)); } // Sparse matrices // Get sparse matrix from Matlab/Octave. template inline SpMat armaGetSparseData(const mxArray *matlabMatrix, bool sort_locations = false) { if(!mxIsSparse(matlabMatrix)) { mexErrMsgTxt("Matrix is not sparse."); return SpMat(); } else { Type *pr = (Type *)mxGetData(matlabMatrix); if(pr == NULL) { mexErrMsgTxt("No data available."); return SpMat(); } mwIndex *jc = mxGetJc(matlabMatrix); mwIndex *ir = mxGetIr(matlabMatrix); mwSize m = mxGetM(matlabMatrix); mwSize n = mxGetN(matlabMatrix); mwSize non_zero = mxGetNzmax(matlabMatrix); umat locations = zeros(2,non_zero); Col values = zeros< Col >(non_zero); mwSize row = 0; for(mwSize col = 0; col < n ; col++) { mwIndex starting_row_index = jc[col]; mwIndex stopping_row_index = jc[col+1]; if (starting_row_index == stopping_row_index) { // End of matrix when jc[col] == jc[col+1] continue; } else { for (mwIndex current_row_index = starting_row_index; current_row_index < stopping_row_index; current_row_index++) { values[row]=pr[row]; locations.at(0,row)=ir[current_row_index]; locations.at(1,row)=col; row++; } } } return SpMat(locations, values, m, n, sort_locations); } } // Get double valued sparse matrix from Matlab/Octave. inline SpMat armaGetSparseMatrix(const mxArray *matlabMatrix, bool sort_locations = false) { if(!mxIsSparse(matlabMatrix)) { mexErrMsgTxt("Matrix is not sparse."); return SpMat(); } else { double *pr = mxGetPr(matlabMatrix); if(pr == NULL) { mexErrMsgTxt("No data available."); return SpMat(); } mwIndex *jc = mxGetJc(matlabMatrix); mwIndex *ir = mxGetIr(matlabMatrix); mwSize m = mxGetM(matlabMatrix); mwSize n = mxGetN(matlabMatrix); mwSize non_zero = mxGetNzmax(matlabMatrix); umat locations = zeros(2,non_zero); Col values = zeros< Col >(non_zero); mwSize row = 0; for(mwSize col = 0; col < n ; col++) { mwIndex starting_row_index = jc[col]; mwIndex stopping_row_index = jc[col+1]; if (starting_row_index == stopping_row_index) { // End of matrix when jc[col] == jc[col+1] continue; } else { for (mwIndex current_row_index = starting_row_index; current_row_index < stopping_row_index ; current_row_index++) { values[row]=pr[row]; locations.at(0,row)=ir[current_row_index]; locations.at(1,row)=col; row++; } } } return SpMat(locations, values, m, n, sort_locations); } } // Get imaginary sparse matrix from Matlab/Octave. template inline SpMat armaGetSparseImagData(const mxArray *matlabMatrix, bool sort_locations = false) { if(!mxIsSparse(matlabMatrix)) { mexErrMsgTxt("Matrix is not sparse."); return SpMat(); } else { Type *pi = (Type *)mxGetImagData(matlabMatrix); if(pi == NULL) { mexErrMsgTxt("No data available."); return SpMat(); } mwIndex *jc = mxGetJc(matlabMatrix); mwIndex *ir = mxGetIr(matlabMatrix); mwSize m = mxGetM(matlabMatrix); mwSize n = mxGetN(matlabMatrix); mwSize non_zero = mxGetNzmax(matlabMatrix); umat locations = zeros(2,non_zero); Col values = zeros< Col >(non_zero); mwSize row = 0; for(mwSize col = 0; col < n ; col++) { mwIndex starting_row_index = jc[col]; mwIndex stopping_row_index = jc[col+1]; if (starting_row_index == stopping_row_index) { // End of matrix when jc[col] == jc[col+1] continue; } else { for (mwIndex current_row_index = starting_row_index; current_row_index < stopping_row_index; current_row_index++) { values[row]=pi[row]; locations.at(0,row)=ir[current_row_index]; locations.at(1,row)=col; row++; } } } return SpMat(locations, values, m, n, sort_locations); } } // Get imaginary double valued sparse matrix from Matlab/Octave. inline SpMat armaGetSparseImagMatrix(const mxArray *matlabMatrix, bool sort_locations = false) { if(!mxIsSparse(matlabMatrix)) { mexErrMsgTxt("Matrix is not sparse."); return SpMat(); } else { double *pi = mxGetPi(matlabMatrix); if(pi == NULL) { mexErrMsgTxt("No data available."); return SpMat(); } mwIndex *jc = mxGetJc(matlabMatrix); mwIndex *ir = mxGetIr(matlabMatrix); mwSize m = mxGetM(matlabMatrix); mwSize n = mxGetN(matlabMatrix); mwSize non_zero = mxGetNzmax(matlabMatrix); umat locations = zeros(2,non_zero); Col values = zeros< Col >(non_zero); mwSize row = 0; for(mwSize col = 0; col < n ; col++) { mwIndex starting_row_index = jc[col]; mwIndex stopping_row_index = jc[col+1]; if (starting_row_index == stopping_row_index) { // End of matrix when jc[col] == jc[col+1] continue; } else { for (mwIndex current_row_index = starting_row_index; current_row_index < stopping_row_index; current_row_index++) { values[row]=pi[row]; locations.at(0,row)=ir[current_row_index]; locations.at(1,row)=col; row++; } } } return SpMat(locations, values, m, n, sort_locations); } } // Return sparse matrix to matlab inline void armaSetSparsePr(mxArray *matlabMatrix, const SpMat& armaMatrix) { double *sr = mxGetPr(matlabMatrix); mwIndex *irs = mxGetIr(matlabMatrix); mwIndex *jcs = mxGetJc(matlabMatrix); mwSize n_nonzero = armaMatrix.n_nonzero; mwSize n_cols = armaMatrix.n_cols; for (mwIndex j = 0; j < n_nonzero; j++) { sr[j] = armaMatrix.values[j]; irs[j] = armaMatrix.row_indices[j]; } for (mwIndex j = 0; j <= n_cols; j++) { jcs[j] = armaMatrix.col_ptrs[j]; } } // Return sparse matrix to matlab as imaginary part inline void armaSetSparsePi(mxArray *matlabMatrix, const SpMat& armaMatrix) { double *si = mxGetPi(matlabMatrix); mwIndex *irs = mxGetIr(matlabMatrix); mwIndex *jcs = mxGetJc(matlabMatrix); mwSize n_nonzero = armaMatrix.n_nonzero; mwSize n_cols = armaMatrix.n_cols; for (mwIndex j = 0; j < n_nonzero; j++) { si[j] = armaMatrix.values[j]; irs[j] = armaMatrix.row_indices[j]; } for (mwIndex j = 0; j <= n_cols; j++) { jcs[j] = armaMatrix.col_ptrs[j]; } } // Create matlab side matrices // Create 2-D Matlab/Octave matrix inline mxArray* armaCreateMxMatrix(const mwSize n_rows, const mwSize n_cols, const mxClassID mx_type = mxDOUBLE_CLASS, const mxComplexity mx_complexity = mxREAL) { mxArray *temp = mxCreateNumericMatrix(n_rows, n_cols, mx_type, mx_complexity); if(temp == NULL) { mexErrMsgTxt("Could not create array."); return NULL; } else { return temp; } } // Create 3-D Matlab/Octave matrix (cube) inline mxArray* armaCreateMxMatrix(const mwSize n_rows, const mwSize n_cols, const mwSize n_slices, const mxClassID mx_type = mxDOUBLE_CLASS, const mxComplexity mx_complexity = mxREAL) { mwSize dims[3] = { n_rows, n_cols, n_slices }; const mwSize n_dim = 3; mxArray *temp = mxCreateNumericArray(n_dim, dims, mx_type, mx_complexity); if(temp == NULL) { mexErrMsgTxt("Could not create array."); return NULL; } else { return temp; } } inline mxArray* armaCreateMxSparseMatrix(const mwSize n_rows,const mwSize n_cols,const mwSize n_nonzero,const mxComplexity mx_complexity = mxREAL) { mxArray *temp = mxCreateSparse(n_rows, n_cols, n_nonzero, mx_complexity); if(temp == NULL) { mexErrMsgTxt("Could not create array."); return NULL; } else { return temp; } } //Functions to write MAT files inline int armaWriteMatToFile(const char *filename, mat &armaMatrix, const char *name) { MATFile *file; file = matOpen(filename,"wz"); int result; if(file == NULL) { mexErrMsgTxt("Could not create MAT file."); return 0; } else { mxArray *temp = mxCreateDoubleMatrix(armaMatrix.n_rows, armaMatrix.n_cols, mxREAL); armaSetPr(temp, armaMatrix); result = matPutVariable(file, name, temp); mxDestroyArray(temp); //Cleanup after writing MAT file } matClose(file); return result; } inline int armaWriteCxMatToFile(const char *filename, cx_mat &armaMatrix, const char *name) { MATFile *file; file = matOpen(filename,"wz"); int result; if(file == NULL) { mexErrMsgTxt("Could not create MAT file."); return 0; } else { mxArray *temp = mxCreateDoubleMatrix(armaMatrix.n_rows, armaMatrix.n_cols, mxCOMPLEX); armaSetCx(temp, armaMatrix); result = matPutVariable(file, name, temp); mxDestroyArray(temp); //Cleanup after writing MAT file } matClose(file); return result; } inline int armaWriteCubeToFile(const char *filename, cube &armaCube, const char *name) { MATFile *file; file = matOpen(filename,"wz"); int result; if(file == NULL) { mexErrMsgTxt("Could not create MAT file."); return 0; } else { mxArray *temp = armaCreateMxMatrix(armaCube.n_rows, armaCube.n_cols, armaCube.n_slices, mxDOUBLE_CLASS, mxREAL); armaSetCubePr(temp, armaCube); result = matPutVariable(file, name, temp); mxDestroyArray(temp); //Cleanup after writing MAT file } matClose(file); return result; } inline int armaWriteCxCubeToFile(const char *filename, cx_cube &armaCube, const char *name) { MATFile *file; file = matOpen(filename,"wz"); int result; if(file == NULL) { mexErrMsgTxt("Could not create MAT file."); return 0; } else { mxArray *temp = armaCreateMxMatrix(armaCube.n_rows, armaCube.n_cols, armaCube.n_slices, mxDOUBLE_CLASS, mxCOMPLEX); armaSetCubeCx(temp, armaCube); result = matPutVariable(file, name, temp); mxDestroyArray(temp); //Cleanup after writing MAT file } matClose(file); return result; } //Functions to read and write matrices and cubes in MAT file format inline mat armaReadMatFromFile(const char *filename) { MATFile *file; file = matOpen(filename,"r"); char buffer[64]; const char *name; name = buffer; if(file == NULL) { mexErrMsgTxt("Could not open MAT file."); return mat(); } else { mat tmp = armaGetPr(matGetNextVariable(file,&name)); matClose(file); return tmp; } } inline cx_mat armaReadCxMatFromFile(const char *filename) { MATFile *file; file = matOpen(filename,"r"); char buffer[64]; const char *name; name = buffer; if(file == NULL) { mexErrMsgTxt("Could not open MAT file."); return cx_mat(); } else { cx_mat tmp = armaGetCx(matGetNextVariable(file, &name)); matClose(file); return tmp; } } inline cube armaReadCubeFromFile(const char *filename) { MATFile *file; file = matOpen(filename,"r"); char buffer[64]; const char *name; name = buffer; if(file == NULL) { mexErrMsgTxt("Could not open MAT file."); return cube(); } else { cube tmp = armaGetCubePr(matGetNextVariable(file,&name)); matClose(file); return tmp; } } inline cx_cube armaReadCxCubeFromFile(const char *filename) { MATFile *file; file = matOpen(filename,"r"); char buffer[64]; const char *name; name = buffer; if(file == NULL) { mexErrMsgTxt("Could not open MAT file."); return cx_cube(); } else { cx_cube tmp = armaGetCubeCx(matGetNextVariable(file,&name)); matClose(file); return tmp; } } armadillo-6.500.5/mex_interface/armaMex_demo.cpp0000666000000000000000000000346612620272703020262 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by George Yammine // Demonstration of how to connect Armadillo with Matlab mex functions. // Version 0.2 #include "armaMex.hpp" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Check the number of input arguments. if (nrhs != 2) mexErrMsgTxt("Incorrect number of input arguments."); // Check type of input. if ( (mxGetClassID(prhs[0]) != mxDOUBLE_CLASS) || (mxGetClassID(prhs[1]) != mxDOUBLE_CLASS) ) mexErrMsgTxt("Input must me of type double."); // Check if input is real. if ( (mxIsComplex(prhs[0])) || (mxIsComplex(prhs[1])) ) mexErrMsgTxt("Input must be real."); // Create matrices X and Y from the first and second argument. mat X = armaGetPr(prhs[0]); mat Y = armaGetPr(prhs[1]); // Our calculations require that matrices must be of the same size if ( size(X) != size(Y) ) mexErrMsgTxt("Matrices should be of same size."); // Perform calculations mat A = X + Y; mat B = X % Y; // % means element-wise multiplication in Armadillo // Create cube C with A and B as slices. cube C(A.n_rows, A.n_cols, 2); C.slice(0) = A; C.slice(1) = B; // Create the output argument plhs[0] to return cube C plhs[0] = armaCreateMxMatrix(C.n_rows, C.n_cols, C.n_slices); // Return the cube C as plhs[0] in Matlab/Octave armaSetCubePr(plhs[0], C); return; } armadillo-6.500.5/src/0000777000000000000000000000000012656572547013147 5ustar rootrootarmadillo-6.500.5/src/wrapper.cpp0000666000000000000000000017253612627353757015347 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin #include #include #include #if (__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__) #undef ARMA_USE_CXX11 #define ARMA_USE_CXX11 #endif #include "armadillo_bits/config.hpp" #undef ARMA_USE_WRAPPER #include "armadillo_bits/compiler_setup.hpp" #include "armadillo_bits/typedef_elem.hpp" #include "armadillo_bits/include_atlas.hpp" #include "armadillo_bits/include_superlu.hpp" #if defined(ARMA_USE_EXTERN_CXX11_RNG) #include #include #if defined(ARMA_HAVE_GETTIMEOFDAY) #include #endif namespace arma { #include "armadillo_bits/arma_rng_cxx11.hpp" thread_local arma_rng_cxx11 arma_rng_cxx11_instance; } #endif #if defined(ARMA_USE_HDF5_ALT) #include #if defined(H5_USE_16_API_DEFAULT) || defined(H5_USE_16_API) // #pragma message ("disabling use of HDF5 due to its incompatible configuration") #undef ARMA_USE_HDF5_ALT #endif #endif namespace arma { #include "armadillo_bits/def_blas.hpp" #include "armadillo_bits/def_lapack.hpp" #include "armadillo_bits/def_arpack.hpp" #include "armadillo_bits/def_superlu.hpp" // no need to include def_hdf5.hpp -- it only contains #defines for when ARMA_USE_HDF5_ALT is not defined. #if defined(ARMA_USE_HDF5_ALT) // Wrapper functions: arma::H5open() and arma::H5check_version() to hijack calls to H5open() and H5check_version() herr_t H5open() { return ::H5open(); } herr_t H5check_version(unsigned majnum, unsigned minnum, unsigned relnum) { return ::H5check_version(majnum, minnum, relnum); } #endif // at this stage we have prototypes for the real blas, lapack and atlas functions // now we make the wrapper functions extern "C" { #if defined(ARMA_USE_BLAS) float arma_fortran_prefix(arma_sasum)(blas_int* n, const float* x, blas_int* incx) { return arma_fortran_noprefix(arma_sasum)(n, x, incx); } double arma_fortran_prefix(arma_dasum)(blas_int* n, const double* x, blas_int* incx) { return arma_fortran_noprefix(arma_dasum)(n, x, incx); } float arma_fortran_prefix(arma_snrm2)(blas_int* n, const float* x, blas_int* incx) { return arma_fortran_noprefix(arma_snrm2)(n, x, incx); } double arma_fortran_prefix(arma_dnrm2)(blas_int* n, const double* x, blas_int* incx) { return arma_fortran_noprefix(arma_dnrm2)(n, x, incx); } float arma_fortran_prefix(arma_sdot)(blas_int* n, const float* x, blas_int* incx, const float* y, blas_int* incy) { return arma_fortran_noprefix(arma_sdot)(n, x, incx, y, incy); } double arma_fortran_prefix(arma_ddot)(blas_int* n, const double* x, blas_int* incx, const double* y, blas_int* incy) { return arma_fortran_noprefix(arma_ddot)(n, x, incx, y, incy); } void arma_fortran_prefix(arma_sgemv)(const char* transA, const blas_int* m, const blas_int* n, const float* alpha, const float* A, const blas_int* ldA, const float* x, const blas_int* incx, const float* beta, float* y, const blas_int* incy) { arma_fortran_noprefix(arma_sgemv)(transA, m, n, alpha, A, ldA, x, incx, beta, y, incy); } void arma_fortran_prefix(arma_dgemv)(const char* transA, const blas_int* m, const blas_int* n, const double* alpha, const double* A, const blas_int* ldA, const double* x, const blas_int* incx, const double* beta, double* y, const blas_int* incy) { arma_fortran_noprefix(arma_dgemv)(transA, m, n, alpha, A, ldA, x, incx, beta, y, incy); } void arma_fortran_prefix(arma_cgemv)(const char* transA, const blas_int* m, const blas_int* n, const void* alpha, const void* A, const blas_int* ldA, const void* x, const blas_int* incx, const void* beta, void* y, const blas_int* incy) { arma_fortran_noprefix(arma_cgemv)(transA, m, n, alpha, A, ldA, x, incx, beta, y, incy); } void arma_fortran_prefix(arma_zgemv)(const char* transA, const blas_int* m, const blas_int* n, const void* alpha, const void* A, const blas_int* ldA, const void* x, const blas_int* incx, const void* beta, void* y, const blas_int* incy) { arma_fortran_noprefix(arma_zgemv)(transA, m, n, alpha, A, ldA, x, incx, beta, y, incy); } void arma_fortran_prefix(arma_sgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const float* alpha, const float* A, const blas_int* ldA, const float* B, const blas_int* ldB, const float* beta, float* C, const blas_int* ldC) { arma_fortran_noprefix(arma_sgemm)(transA, transB, m, n, k, alpha, A, ldA, B, ldB, beta, C, ldC); } void arma_fortran_prefix(arma_dgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const double* alpha, const double* A, const blas_int* ldA, const double* B, const blas_int* ldB, const double* beta, double* C, const blas_int* ldC) { arma_fortran_noprefix(arma_dgemm)(transA, transB, m, n, k, alpha, A, ldA, B, ldB, beta, C, ldC); } void arma_fortran_prefix(arma_cgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const void* alpha, const void* A, const blas_int* ldA, const void* B, const blas_int* ldB, const void* beta, void* C, const blas_int* ldC) { arma_fortran_noprefix(arma_cgemm)(transA, transB, m, n, k, alpha, A, ldA, B, ldB, beta, C, ldC); } void arma_fortran_prefix(arma_zgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const void* alpha, const void* A, const blas_int* ldA, const void* B, const blas_int* ldB, const void* beta, void* C, const blas_int* ldC) { arma_fortran_noprefix(arma_zgemm)(transA, transB, m, n, k, alpha, A, ldA, B, ldB, beta, C, ldC); } void arma_fortran_prefix(arma_ssyrk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const float* alpha, const float* A, const blas_int* ldA, const float* beta, float* C, const blas_int* ldC) { arma_fortran_noprefix(arma_ssyrk)(uplo, transA, n, k, alpha, A, ldA, beta, C, ldC); } void arma_fortran_prefix(arma_dsyrk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const double* alpha, const double* A, const blas_int* ldA, const double* beta, double* C, const blas_int* ldC) { arma_fortran_noprefix(arma_dsyrk)(uplo, transA, n, k, alpha, A, ldA, beta, C, ldC); } void arma_fortran_prefix(arma_cherk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const float* alpha, const void* A, const blas_int* ldA, const float* beta, void* C, const blas_int* ldC) { arma_fortran_noprefix(arma_cherk)(uplo, transA, n, k, alpha, A, ldA, beta, C, ldC); } void arma_fortran_prefix(arma_zherk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const double* alpha, const void* A, const blas_int* ldA, const double* beta, void* C, const blas_int* ldC) { arma_fortran_noprefix(arma_zherk)(uplo, transA, n, k, alpha, A, ldA, beta, C, ldC); } #endif #if defined(ARMA_USE_LAPACK) void arma_fortran_prefix(arma_sgetrf)(blas_int* m, blas_int* n, float* a, blas_int* lda, blas_int* ipiv, blas_int* info) { arma_fortran_noprefix(arma_sgetrf)(m, n, a, lda, ipiv, info); } void arma_fortran_prefix(arma_dgetrf)(blas_int* m, blas_int* n, double* a, blas_int* lda, blas_int* ipiv, blas_int* info) { arma_fortran_noprefix(arma_dgetrf)(m, n, a, lda, ipiv, info); } void arma_fortran_prefix(arma_cgetrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, blas_int* info) { arma_fortran_noprefix(arma_cgetrf)(m, n, a, lda, ipiv, info); } void arma_fortran_prefix(arma_zgetrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, blas_int* info) { arma_fortran_noprefix(arma_zgetrf)(m, n, a, lda, ipiv, info); } void arma_fortran_prefix(arma_sgetri)(blas_int* n, float* a, blas_int* lda, blas_int* ipiv, float* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_sgetri)(n, a, lda, ipiv, work, lwork, info); } void arma_fortran_prefix(arma_dgetri)(blas_int* n, double* a, blas_int* lda, blas_int* ipiv, double* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_dgetri)(n, a, lda, ipiv, work, lwork, info); } void arma_fortran_prefix(arma_cgetri)(blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_cgetri)(n, a, lda, ipiv, work, lwork, info); } void arma_fortran_prefix(arma_zgetri)(blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_zgetri)(n, a, lda, ipiv, work, lwork, info); } void arma_fortran_prefix(arma_strtri)(char* uplo, char* diag, blas_int* n, float* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_strtri)(uplo, diag, n, a, lda, info); } void arma_fortran_prefix(arma_dtrtri)(char* uplo, char* diag, blas_int* n, double* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_dtrtri)(uplo, diag, n, a, lda, info); } void arma_fortran_prefix(arma_ctrtri)(char* uplo, char* diag, blas_int* n, void* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_ctrtri)(uplo, diag, n, a, lda, info); } void arma_fortran_prefix(arma_ztrtri)(char* uplo, char* diag, blas_int* n, void* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_ztrtri)(uplo, diag, n, a, lda, info); } void arma_fortran_prefix(arma_ssyev)(char* jobz, char* uplo, blas_int* n, float* a, blas_int* lda, float* w, float* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_ssyev)(jobz, uplo, n, a, lda, w, work, lwork, info); } void arma_fortran_prefix(arma_dsyev)(char* jobz, char* uplo, blas_int* n, double* a, blas_int* lda, double* w, double* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_dsyev)(jobz, uplo, n, a, lda, w, work, lwork, info); } void arma_fortran_prefix(arma_cheev)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, float* w, void* work, blas_int* lwork, float* rwork, blas_int* info) { arma_fortran_noprefix(arma_cheev)(jobz, uplo, n, a, lda, w, work, lwork, rwork, info); } void arma_fortran_prefix(arma_zheev)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, double* w, void* work, blas_int* lwork, double* rwork, blas_int* info) { arma_fortran_noprefix(arma_zheev)(jobz, uplo, n, a, lda, w, work, lwork, rwork, info); } void arma_fortran_prefix(arma_ssyevd)(char* jobz, char* uplo, blas_int* n, float* a, blas_int* lda, float* w, float* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info) { arma_fortran_noprefix(arma_ssyevd)(jobz, uplo, n, a, lda, w, work, lwork, iwork, liwork, info); } void arma_fortran_prefix(arma_dsyevd)(char* jobz, char* uplo, blas_int* n, double* a, blas_int* lda, double* w, double* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info) { arma_fortran_noprefix(arma_dsyevd)(jobz, uplo, n, a, lda, w, work, lwork, iwork, liwork, info); } void arma_fortran_prefix(arma_cheevd)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, float* w, void* work, blas_int* lwork, float* rwork, blas_int* lrwork, blas_int* iwork, blas_int* liwork, blas_int* info) { arma_fortran_noprefix(arma_cheevd)(jobz, uplo, n, a, lda, w, work, lwork, rwork, lrwork, iwork, liwork, info); } void arma_fortran_prefix(arma_zheevd)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, double* w, void* work, blas_int* lwork, double* rwork, blas_int* lrwork, blas_int* iwork, blas_int* liwork, blas_int* info) { arma_fortran_noprefix(arma_zheevd)(jobz, uplo, n, a, lda, w, work, lwork, rwork, lrwork, iwork, liwork, info); } void arma_fortran_prefix(arma_sgeev)(char* jobvl, char* jobvr, blas_int* n, float* a, blas_int* lda, float* wr, float* wi, float* vl, blas_int* ldvl, float* vr, blas_int* ldvr, float* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_sgeev)(jobvl, jobvr, n, a, lda, wr, wi, vl, ldvl, vr, ldvr, work, lwork, info); } void arma_fortran_prefix(arma_dgeev)(char* jobvl, char* jobvr, blas_int* n, double* a, blas_int* lda, double* wr, double* wi, double* vl, blas_int* ldvl, double* vr, blas_int* ldvr, double* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_dgeev)(jobvl, jobvr, n, a, lda, wr, wi, vl, ldvl, vr, ldvr, work, lwork, info); } void arma_fortran_prefix(arma_cgeev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* w, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, float* rwork, blas_int* info) { arma_fortran_noprefix(arma_cgeev)(jobvl, jobvr, n, a, lda, w, vl, ldvl, vr, ldvr, work, lwork, rwork, info); } void arma_fortran_prefix(arma_zgeev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* w, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, double* rwork, blas_int* info) { arma_fortran_noprefix(arma_zgeev)(jobvl, jobvr, n, a, lda, w, vl, ldvl, vr, ldvr, work, lwork, rwork, info); } void arma_fortran_prefix(arma_sggev)(char* jobvl, char* jobvr, blas_int* n, float* a, blas_int* lda, float* b, blas_int* ldb, float* alphar, float* alphai, float* beta, float* vl, blas_int* ldvl, float* vr, blas_int* ldvr, float* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_sggev)(jobvl, jobvr, n, a, lda, b, ldb, alphar, alphai, beta, vl, ldvl, vr, ldvr, work, lwork, info); } void arma_fortran_prefix(arma_dggev)(char* jobvl, char* jobvr, blas_int* n, double* a, blas_int* lda, double* b, blas_int* ldb, double* alphar, double* alphai, double* beta, double* vl, blas_int* ldvl, double* vr, blas_int* ldvr, double* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_dggev)(jobvl, jobvr, n, a, lda, b, ldb, alphar, alphai, beta, vl, ldvl, vr, ldvr, work, lwork, info); } void arma_fortran_prefix(arma_cggev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, void* alpha, void* beta, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, float* rwork, blas_int* info) { arma_fortran_noprefix(arma_cggev)(jobvl, jobvr, n, a, lda, b, ldb, alpha, beta, vl, ldvl, vr, ldvr, work, lwork, rwork, info); } void arma_fortran_prefix(arma_zggev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, void* alpha, void* beta, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, double* rwork, blas_int* info) { arma_fortran_noprefix(arma_zggev)(jobvl, jobvr, n, a, lda, b, ldb, alpha, beta, vl, ldvl, vr, ldvr, work, lwork, rwork, info); } void arma_fortran_prefix(arma_spotrf)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_spotrf)(uplo, n, a, lda, info); } void arma_fortran_prefix(arma_dpotrf)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_dpotrf)(uplo, n, a, lda, info); } void arma_fortran_prefix(arma_cpotrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_cpotrf)(uplo, n, a, lda, info); } void arma_fortran_prefix(arma_zpotrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_zpotrf)(uplo, n, a, lda, info); } void arma_fortran_prefix(arma_spotri)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_spotri)(uplo, n, a, lda, info); } void arma_fortran_prefix(arma_dpotri)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_dpotri)(uplo, n, a, lda, info); } void arma_fortran_prefix(arma_cpotri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_cpotri)(uplo, n, a, lda, info); } void arma_fortran_prefix(arma_zpotri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info) { arma_fortran_noprefix(arma_zpotri)(uplo, n, a, lda, info); } void arma_fortran_prefix(arma_sgeqrf)(blas_int* m, blas_int* n, float* a, blas_int* lda, float* tau, float* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_sgeqrf)(m, n, a, lda, tau, work, lwork, info); } void arma_fortran_prefix(arma_dgeqrf)(blas_int* m, blas_int* n, double* a, blas_int* lda, double* tau, double* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_dgeqrf)(m, n, a, lda, tau, work, lwork, info); } void arma_fortran_prefix(arma_cgeqrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_cgeqrf)(m, n, a, lda, tau, work, lwork, info); } void arma_fortran_prefix(arma_zgeqrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_zgeqrf)(m, n, a, lda, tau, work, lwork, info); } void arma_fortran_prefix(arma_sorgqr)(blas_int* m, blas_int* n, blas_int* k, float* a, blas_int* lda, float* tau, float* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_sorgqr)(m, n, k, a, lda, tau, work, lwork, info); } void arma_fortran_prefix(arma_dorgqr)(blas_int* m, blas_int* n, blas_int* k, double* a, blas_int* lda, double* tau, double* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_dorgqr)(m, n, k, a, lda, tau, work, lwork, info); } void arma_fortran_prefix(arma_cungqr)(blas_int* m, blas_int* n, blas_int* k, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_cungqr)(m, n, k, a, lda, tau, work, lwork, info); } void arma_fortran_prefix(arma_zungqr)(blas_int* m, blas_int* n, blas_int* k, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_zungqr)(m, n, k, a, lda, tau, work, lwork, info); } void arma_fortran_prefix(arma_sgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, float* a, blas_int* lda, float* s, float* u, blas_int* ldu, float* vt, blas_int* ldvt, float* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_sgesvd)(jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, info); } void arma_fortran_prefix(arma_dgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, double* a, blas_int* lda, double* s, double* u, blas_int* ldu, double* vt, blas_int* ldvt, double* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_dgesvd)(jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, info); } void arma_fortran_prefix(arma_cgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, void* a, blas_int* lda, float* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, float* rwork, blas_int* info) { arma_fortran_noprefix(arma_cgesvd)(jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, rwork, info); } void arma_fortran_prefix(arma_zgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, void* a, blas_int* lda, double* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, double* rwork, blas_int* info) { arma_fortran_noprefix(arma_zgesvd)(jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, rwork, info); } void arma_fortran_prefix(arma_sgesdd)(char* jobz, blas_int* m, blas_int* n, float* a, blas_int* lda, float* s, float* u, blas_int* ldu, float* vt, blas_int* ldvt, float* work, blas_int* lwork, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_sgesdd)(jobz, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, iwork, info); } void arma_fortran_prefix(arma_dgesdd)(char* jobz, blas_int* m, blas_int* n, double* a, blas_int* lda, double* s, double* u, blas_int* ldu, double* vt, blas_int* ldvt, double* work, blas_int* lwork, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_dgesdd)(jobz, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, iwork, info); } void arma_fortran_prefix(arma_cgesdd)(char* jobz, blas_int* m, blas_int* n, void* a, blas_int* lda, float* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, float* rwork, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_cgesdd)(jobz, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, rwork, iwork, info); } void arma_fortran_prefix(arma_zgesdd)(char* jobz, blas_int* m, blas_int* n, void* a, blas_int* lda, double* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, double* rwork, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_zgesdd)(jobz, m, n, a, lda, s, u, ldu, vt, ldvt, work, lwork, rwork, iwork, info); } void arma_fortran_prefix(arma_sgesv)(blas_int* n, blas_int* nrhs, float* a, blas_int* lda, blas_int* ipiv, float* b, blas_int* ldb, blas_int* info) { arma_fortran_noprefix(arma_sgesv)(n, nrhs, a, lda, ipiv, b, ldb, info); } void arma_fortran_prefix(arma_dgesv)(blas_int* n, blas_int* nrhs, double* a, blas_int* lda, blas_int* ipiv, double* b, blas_int* ldb, blas_int* info) { arma_fortran_noprefix(arma_dgesv)(n, nrhs, a, lda, ipiv, b, ldb, info); } void arma_fortran_prefix(arma_cgesv)(blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info) { arma_fortran_noprefix(arma_cgesv)(n, nrhs, a, lda, ipiv, b, ldb, info); } void arma_fortran_prefix(arma_zgesv)(blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info) { arma_fortran_noprefix(arma_zgesv)(n, nrhs, a, lda, ipiv, b, ldb, info); } void arma_fortran_prefix(arma_sgesvx)(char* fact, char* trans, blas_int* n, blas_int* nrhs, float* a, blas_int* lda, float* af, blas_int* ldaf, blas_int* ipiv, char* equed, float* r, float* c, float* b, blas_int* ldb, float* x, blas_int* ldx, float* rcond, float* ferr, float* berr, float* work, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_sgesvx)(fact, trans, n, nrhs, a, lda, af, ldaf, ipiv, equed, r, c, b, ldb, x, ldx, rcond, ferr, berr, work, iwork, info); } void arma_fortran_prefix(arma_dgesvx)(char* fact, char* trans, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, double* af, blas_int* ldaf, blas_int* ipiv, char* equed, double* r, double* c, double* b, blas_int* ldb, double* x, blas_int* ldx, double* rcond, double* ferr, double* berr, double* work, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_dgesvx)(fact, trans, n, nrhs, a, lda, af, ldaf, ipiv, equed, r, c, b, ldb, x, ldx, rcond, ferr, berr, work, iwork, info); } void arma_fortran_prefix(arma_cgesvx)(char* fact, char* trans, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* af, blas_int* ldaf, blas_int* ipiv, char* equed, float* r, float* c, void* b, blas_int* ldb, void* x, blas_int* ldx, float* rcond, float* ferr, float* berr, void* work, float* rwork, blas_int* info) { arma_fortran_noprefix(arma_cgesvx)(fact, trans, n, nrhs, a, lda, af, ldaf, ipiv, equed, r, c, b, ldb, x, ldx, rcond, ferr, berr, work, rwork, info); } void arma_fortran_prefix(arma_zgesvx)(char* fact, char* trans, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* af, blas_int* ldaf, blas_int* ipiv, char* equed, double* r, double* c, void* b, blas_int* ldb, void* x, blas_int* ldx, double* rcond, double* ferr, double* berr, void* work, double* rwork, blas_int* info) { arma_fortran_noprefix(arma_zgesvx)(fact, trans, n, nrhs, a, lda, af, ldaf, ipiv, equed, r, c, b, ldb, x, ldx, rcond, ferr, berr, work, rwork, info); } void arma_fortran_prefix(arma_sgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, float* a, blas_int* lda, float* b, blas_int* ldb, float* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_sgels)(trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info); } void arma_fortran_prefix(arma_dgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, double* b, blas_int* ldb, double* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_dgels)(trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info); } void arma_fortran_prefix(arma_cgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_cgels)(trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info); } void arma_fortran_prefix(arma_zgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_zgels)(trans, m, n, nrhs, a, lda, b, ldb, work, lwork, info); } void arma_fortran_prefix(arma_sgelsd)(blas_int* m, blas_int* n, blas_int* nrhs, float* a, blas_int* lda, float* b, blas_int* ldb, float* S, float* rcond, blas_int* rank, float* work, blas_int* lwork, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_sgelsd)(m, n, nrhs, a, lda, b, ldb, S, rcond, rank, work, lwork, iwork, info); } void arma_fortran_prefix(arma_dgelsd)(blas_int* m, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, double* b, blas_int* ldb, double* S, double* rcond, blas_int* rank, double* work, blas_int* lwork, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_dgelsd)(m, n, nrhs, a, lda, b, ldb, S, rcond, rank, work, lwork, iwork, info); } void arma_fortran_prefix(arma_cgelsd)(blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, float* S, float* rcond, blas_int* rank, void* work, blas_int* lwork, float* rwork, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_cgelsd)(m, n, nrhs, a, lda, b, ldb, S, rcond, rank, work, lwork, rwork, iwork, info); } void arma_fortran_prefix(arma_zgelsd)(blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, double* S, double* rcond, blas_int* rank, void* work, blas_int* lwork, double* rwork, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_zgelsd)(m, n, nrhs, a, lda, b, ldb, S, rcond, rank, work, lwork, rwork, iwork, info); } void arma_fortran_prefix(arma_strtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const float* a, blas_int* lda, float* b, blas_int* ldb, blas_int* info) { arma_fortran_noprefix(arma_strtrs)(uplo, trans, diag, n, nrhs, a, lda, b, ldb, info); } void arma_fortran_prefix(arma_dtrtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const double* a, blas_int* lda, double* b, blas_int* ldb, blas_int* info) { arma_fortran_noprefix(arma_dtrtrs)(uplo, trans, diag, n, nrhs, a, lda, b, ldb, info); } void arma_fortran_prefix(arma_ctrtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* info) { arma_fortran_noprefix(arma_ctrtrs)(uplo, trans, diag, n, nrhs, a, lda, b, ldb, info); } void arma_fortran_prefix(arma_ztrtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* info) { arma_fortran_noprefix(arma_ztrtrs)(uplo, trans, diag, n, nrhs, a, lda, b, ldb, info); } void arma_fortran_prefix(arma_sgees)(char* jobvs, char* sort, void* select, blas_int* n, float* a, blas_int* lda, blas_int* sdim, float* wr, float* wi, float* vs, blas_int* ldvs, float* work, blas_int* lwork, blas_int* bwork, blas_int* info) { arma_fortran_noprefix(arma_sgees)(jobvs, sort, select, n, a, lda, sdim, wr, wi, vs, ldvs, work, lwork, bwork, info); } void arma_fortran_prefix(arma_dgees)(char* jobvs, char* sort, void* select, blas_int* n, double* a, blas_int* lda, blas_int* sdim, double* wr, double* wi, double* vs, blas_int* ldvs, double* work, blas_int* lwork, blas_int* bwork, blas_int* info) { arma_fortran_noprefix(arma_dgees)(jobvs, sort, select, n, a, lda, sdim, wr, wi, vs, ldvs, work, lwork, bwork, info); } void arma_fortran_prefix(arma_cgees)(char* jobvs, char* sort, void* select, blas_int* n, void* a, blas_int* lda, blas_int* sdim, void* w, void* vs, blas_int* ldvs, void* work, blas_int* lwork, float* rwork, blas_int* bwork, blas_int* info) { arma_fortran_noprefix(arma_cgees)(jobvs, sort, select, n, a, lda, sdim, w, vs, ldvs, work, lwork, rwork, bwork, info); } void arma_fortran_prefix(arma_zgees)(char* jobvs, char* sort, void* select, blas_int* n, void* a, blas_int* lda, blas_int* sdim, void* w, void* vs, blas_int* ldvs, void* work, blas_int* lwork, double* rwork, blas_int* bwork, blas_int* info) { arma_fortran_noprefix(arma_zgees)(jobvs, sort, select, n, a, lda, sdim, w, vs, ldvs, work, lwork, rwork, bwork, info); } void arma_fortran_prefix(arma_strsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const float* a, blas_int* lda, const float* b, blas_int* ldb, float* c, blas_int* ldc, float* scale, blas_int* info) { arma_fortran_noprefix(arma_strsyl)(transa, transb, isgn, m, n, a, lda, b, ldb, c, ldc, scale, info); } void arma_fortran_prefix(arma_dtrsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const double* a, blas_int* lda, const double* b, blas_int* ldb, double* c, blas_int* ldc, double* scale, blas_int* info) { arma_fortran_noprefix(arma_dtrsyl)(transa, transb, isgn, m, n, a, lda, b, ldb, c, ldc, scale, info); } void arma_fortran_prefix(arma_ctrsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const void* a, blas_int* lda, const void* b, blas_int* ldb, void* c, blas_int* ldc, float* scale, blas_int* info) { arma_fortran_noprefix(arma_ctrsyl)(transa, transb, isgn, m, n, a, lda, b, ldb, c, ldc, scale, info); } void arma_fortran_prefix(arma_ztrsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const void* a, blas_int* lda, const void* b, blas_int* ldb, void* c, blas_int* ldc, double* scale, blas_int* info) { arma_fortran_noprefix(arma_ztrsyl)(transa, transb, isgn, m, n, a, lda, b, ldb, c, ldc, scale, info); } void arma_fortran_prefix(arma_ssytrf)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* ipiv, float* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_ssytrf)(uplo, n, a, lda, ipiv, work, lwork, info); } void arma_fortran_prefix(arma_dsytrf)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* ipiv, double* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_dsytrf)(uplo, n, a, lda, ipiv, work, lwork, info); } void arma_fortran_prefix(arma_csytrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_csytrf)(uplo, n, a, lda, ipiv, work, lwork, info); } void arma_fortran_prefix(arma_zsytrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info) { arma_fortran_noprefix(arma_zsytrf)(uplo, n, a, lda, ipiv, work, lwork, info); } void arma_fortran_prefix(arma_ssytri)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* ipiv, float* work, blas_int* info) { arma_fortran_noprefix(arma_ssytri)(uplo, n, a, lda, ipiv, work, info); } void arma_fortran_prefix(arma_dsytri)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* ipiv, double* work, blas_int* info) { arma_fortran_noprefix(arma_dsytri)(uplo, n, a, lda, ipiv, work, info); } void arma_fortran_prefix(arma_csytri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* info) { arma_fortran_noprefix(arma_csytri)(uplo, n, a, lda, ipiv, work, info); } void arma_fortran_prefix(arma_zsytri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* info) { arma_fortran_noprefix(arma_zsytri)(uplo, n, a, lda, ipiv, work, info); } void arma_fortran_prefix(arma_sgges)(char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, float* a, blas_int* lda, float* b, blas_int* ldb, blas_int* sdim, float* alphar, float* alphai, float* beta, float* vsl, blas_int* ldvsl, float* vsr, blas_int* ldvsr, float* work, blas_int* lwork, float* bwork, blas_int* info) { arma_fortran_noprefix(arma_sgges)(jobvsl, jobvsr, sort, selctg, n, a, lda, b, ldb, sdim, alphar, alphai, beta, vsl, ldvsl, vsr, ldvsr, work, lwork, bwork, info); } void arma_fortran_prefix(arma_dgges)(char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, double* a, blas_int* lda, double* b, blas_int* ldb, blas_int* sdim, double* alphar, double* alphai, double* beta, double* vsl, blas_int* ldvsl, double* vsr, blas_int* ldvsr, double* work, blas_int* lwork, double* bwork, blas_int* info) { arma_fortran_noprefix(arma_dgges)(jobvsl, jobvsr, sort, selctg, n, a, lda, b, ldb, sdim, alphar, alphai, beta, vsl, ldvsl, vsr, ldvsr, work, lwork, bwork, info); } void arma_fortran_prefix(arma_cgges)(char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* sdim, void* alpha, void* beta, void* vsl, blas_int* ldvsl, void* vsr, blas_int* ldvsr, void* work, blas_int* lwork, float* rwork, float* bwork, blas_int* info) { arma_fortran_noprefix(arma_cgges)(jobvsl, jobvsr, sort, selctg, n, a, lda, b, ldb, sdim, alpha, beta, vsl, ldvsl, vsr, ldvsr, work, lwork, rwork, bwork, info); } void arma_fortran_prefix(arma_zgges)(char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* sdim, void* alpha, void* beta, void* vsl, blas_int* ldvsl, void* vsr, blas_int* ldvsr, void* work, blas_int* lwork, double* rwork, double* bwork, blas_int* info) { arma_fortran_noprefix(arma_zgges)(jobvsl, jobvsr, sort, selctg, n, a, lda, b, ldb, sdim, alpha, beta, vsl, ldvsl, vsr, ldvsr, work, lwork, rwork, bwork, info); } float arma_fortran_prefix(arma_slange)(char* norm, blas_int* m, blas_int* n, float* a, blas_int* lda, float* work) { return arma_fortran_noprefix(arma_slange)(norm, m, n, a, lda, work); } double arma_fortran_prefix(arma_dlange)(char* norm, blas_int* m, blas_int* n, double* a, blas_int* lda, double* work) { return arma_fortran_noprefix(arma_dlange)(norm, m, n, a, lda, work); } float arma_fortran_prefix(arma_clange)(char* norm, blas_int* m, blas_int* n, void* a, blas_int* lda, float* work) { return arma_fortran_noprefix(arma_clange)(norm, m, n, a, lda, work); } double arma_fortran_prefix(arma_zlange)(char* norm, blas_int* m, blas_int* n, void* a, blas_int* lda, double* work) { return arma_fortran_noprefix(arma_zlange)(norm, m, n, a, lda, work); } void arma_fortran_prefix(arma_sgecon)(char* norm, blas_int* n, float* a, blas_int* lda, float* anorm, float* rcond, float* work, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_sgecon)(norm, n, a, lda, anorm, rcond, work, iwork, info); } void arma_fortran_prefix(arma_dgecon)(char* norm, blas_int* n, double* a, blas_int* lda, double* anorm, double* rcond, double* work, blas_int* iwork, blas_int* info) { arma_fortran_noprefix(arma_dgecon)(norm, n, a, lda, anorm, rcond, work, iwork, info); } void arma_fortran_prefix(arma_cgecon)(char* norm, blas_int* n, void* a, blas_int* lda, float* anorm, float* rcond, void* work, float* rwork, blas_int* info) { arma_fortran_noprefix(arma_cgecon)(norm, n, a, lda, anorm, rcond, work, rwork, info); } void arma_fortran_prefix(arma_zgecon)(char* norm, blas_int* n, void* a, blas_int* lda, double* anorm, double* rcond, void* work, double* rwork, blas_int* info) { arma_fortran_noprefix(arma_zgecon)(norm, n, a, lda, anorm, rcond, work, rwork, info); } blas_int arma_fortran_prefix(arma_ilaenv)(blas_int* ispec, char* name, char* opts, blas_int* n1, blas_int* n2, blas_int* n3, blas_int* n4) { return arma_fortran_noprefix(arma_ilaenv)(ispec, name, opts, n1, n2, n3, n4); } #endif #if defined(ARMA_USE_ATLAS) float wrapper_cblas_sasum(const int N, const float *X, const int incX) { return cblas_sasum(N, X, incX); } double wrapper_cblas_dasum(const int N, const double *X, const int incX) { return cblas_dasum(N, X, incX); } float wrapper_cblas_snrm2(const int N, const float *X, const int incX) { return cblas_snrm2(N, X, incX); } double wrapper_cblas_dnrm2(const int N, const double *X, const int incX) { return cblas_dnrm2(N, X, incX); } float wrapper_cblas_sdot(const int N, const float *X, const int incX, const float *Y, const int incY) { return cblas_sdot(N, X, incX, Y, incY); } double wrapper_cblas_ddot(const int N, const double *X, const int incX, const double *Y, const int incY) { return cblas_ddot(N, X, incX, Y, incY); } void wrapper_cblas_cdotu_sub(const int N, const void *X, const int incX, const void *Y, const int incY, void *dotu) { cblas_cdotu_sub(N, X, incX, Y, incY, dotu); } void wrapper_cblas_zdotu_sub(const int N, const void *X, const int incX, const void *Y, const int incY, void *dotu) { cblas_zdotu_sub(N, X, incX, Y, incY, dotu); } void wrapper_cblas_sgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const float alpha, const float *A, const int lda, const float *X, const int incX, const float beta, float *Y, const int incY) { cblas_sgemv(Order, TransA, M, N, alpha, A, lda, X, incX, beta, Y, incY); } void wrapper_cblas_dgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const double alpha, const double *A, const int lda, const double *X, const int incX, const double beta, double *Y, const int incY) { cblas_dgemv(Order, TransA, M, N, alpha, A, lda, X, incX, beta, Y, incY); } void wrapper_cblas_cgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const void *alpha, const void *A, const int lda, const void *X, const int incX, const void *beta, void *Y, const int incY) { cblas_cgemv(Order, TransA, M, N, alpha, A, lda, X, incX, beta, Y, incY); } void wrapper_cblas_zgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const void *alpha, const void *A, const int lda, const void *X, const int incX, const void *beta, void *Y, const int incY) { cblas_zgemv(Order, TransA, M, N, alpha, A, lda, X, incX, beta, Y, incY); } void wrapper_cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const float alpha, const float *A, const int lda, const float *B, const int ldb, const float beta, float *C, const int ldc) { cblas_sgemm(Order, TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc); } void wrapper_cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const double alpha, const double *A, const int lda, const double *B, const int ldb, const double beta, double *C, const int ldc) { cblas_dgemm(Order, TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc); } void wrapper_cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const void *alpha, const void *A, const int lda, const void *B, const int ldb, const void *beta, void *C, const int ldc) { cblas_cgemm(Order, TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc); } void wrapper_cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const void *alpha, const void *A, const int lda, const void *B, const int ldb, const void *beta, void *C, const int ldc) { cblas_zgemm(Order, TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc); } void wrapper_cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const float alpha, const float *A, const int lda, const float beta, float *C, const int ldc) { cblas_ssyrk(Order, Uplo, Trans, N, K, alpha, A, lda, beta, C, ldc); } void wrapper_cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const double alpha, const double *A, const int lda, const double beta, double *C, const int ldc) { cblas_dsyrk(Order, Uplo, Trans, N, K, alpha, A, lda, beta, C, ldc); } void wrapper_cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const float alpha, const void *A, const int lda, const float beta, void *C, const int ldc) { cblas_cherk(Order, Uplo, Trans, N, K, alpha, A, lda, beta, C, ldc); } void wrapper_cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const double alpha, const void *A, const int lda, const double beta, void *C, const int ldc) { cblas_zherk(Order, Uplo, Trans, N, K, alpha, A, lda, beta, C, ldc); } int wrapper_clapack_sgetrf(const enum CBLAS_ORDER Order, const int M, const int N, float *A, const int lda, int *ipiv) { return clapack_sgetrf(Order, M, N, A, lda, ipiv); } int wrapper_clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N, double *A, const int lda, int *ipiv) { return clapack_dgetrf(Order, M, N, A, lda, ipiv); } int wrapper_clapack_cgetrf(const enum CBLAS_ORDER Order, const int M, const int N, void *A, const int lda, int *ipiv) { return clapack_cgetrf(Order, M, N, A, lda, ipiv); } int wrapper_clapack_zgetrf(const enum CBLAS_ORDER Order, const int M, const int N, void *A, const int lda, int *ipiv) { return clapack_zgetrf(Order, M, N, A, lda, ipiv); } int wrapper_clapack_sgetri(const enum CBLAS_ORDER Order, const int N, float *A, const int lda, const int *ipiv) { return clapack_sgetri(Order, N, A, lda, ipiv); } int wrapper_clapack_dgetri(const enum CBLAS_ORDER Order, const int N, double *A, const int lda, const int *ipiv) { return clapack_dgetri(Order, N, A, lda, ipiv); } int wrapper_clapack_cgetri(const enum CBLAS_ORDER Order, const int N, void *A, const int lda, const int *ipiv) { return clapack_cgetri(Order, N, A, lda, ipiv); } int wrapper_clapack_zgetri(const enum CBLAS_ORDER Order, const int N, void *A, const int lda, const int *ipiv) { return clapack_zgetri(Order, N, A, lda, ipiv); } int wrapper_clapack_sgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, float *A, const int lda, int *ipiv, float *B, const int ldb) { return clapack_sgesv(Order, N, NRHS, A, lda, ipiv, B, ldb); } int wrapper_clapack_dgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, double *A, const int lda, int *ipiv, double *B, const int ldb) { return clapack_dgesv(Order, N, NRHS, A, lda, ipiv, B, ldb); } int wrapper_clapack_cgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, void *A, const int lda, int *ipiv, void *B, const int ldb) { return clapack_cgesv(Order, N, NRHS, A, lda, ipiv, B, ldb); } int wrapper_clapack_zgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, void *A, const int lda, int *ipiv, void *B, const int ldb) { return clapack_zgesv(Order, N, NRHS, A, lda, ipiv, B, ldb); } #endif #if defined(ARMA_USE_ARPACK) void arma_fortran_prefix(arma_snaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info) { arma_fortran_noprefix(arma_snaupd)(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); } void arma_fortran_prefix(arma_dnaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info) { arma_fortran_noprefix(arma_dnaupd)(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); } void arma_fortran_prefix(arma_cnaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, float* rwork, blas_int* info) { arma_fortran_noprefix(arma_cnaupd)(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); } void arma_fortran_prefix(arma_znaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, double* rwork, blas_int* info) { arma_fortran_noprefix(arma_znaupd)(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); } void arma_fortran_prefix(arma_sneupd)(blas_int* rvec, char* howmny, blas_int* select, float* dr, float* di, float* z, blas_int* ldz, float* sigmar, float* sigmai, float* workev, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info) { arma_fortran_noprefix(arma_sneupd)(rvec, howmny, select, dr, di, z, ldz, sigmar, sigmai, workev, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); } void arma_fortran_prefix(arma_dneupd)(blas_int* rvec, char* howmny, blas_int* select, double* dr, double* di, double* z, blas_int* ldz, double* sigmar, double* sigmai, double* workev, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info) { arma_fortran_noprefix(arma_dneupd)(rvec, howmny, select, dr, di, z, ldz, sigmar, sigmai, workev, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); } void arma_fortran_prefix(arma_cneupd)(blas_int* rvec, char* howmny, blas_int* select, void* d, void* z, blas_int* ldz, void* sigma, void* workev, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, float* rwork, blas_int* info) { arma_fortran_noprefix(arma_cneupd)(rvec, howmny, select, d, z, ldz, sigma, workev, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); } void arma_fortran_prefix(arma_zneupd)(blas_int* rvec, char* howmny, blas_int* select, void* d, void* z, blas_int* ldz, void* sigma, void* workev, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, double* rwork, blas_int* info) { arma_fortran_noprefix(arma_zneupd)(rvec, howmny, select, d, z, ldz, sigma, workev, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); } void arma_fortran_prefix(arma_ssaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info) { arma_fortran_noprefix(arma_ssaupd)(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); } void arma_fortran_prefix(arma_dsaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info) { arma_fortran_noprefix(arma_dsaupd)(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); } void arma_fortran_prefix(arma_sseupd)(blas_int* rvec, char* howmny, blas_int* select, float* d, float* z, blas_int* ldz, float* sigma, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info) { arma_fortran_noprefix(arma_sseupd)(rvec, howmny, select, d, z, ldz, sigma, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); } void arma_fortran_prefix(arma_dseupd)(blas_int* rvec, char* howmny, blas_int* select, double* d, double* z, blas_int* ldz, double* sigma, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info) { arma_fortran_noprefix(arma_dseupd)(rvec, howmny, select, d, z, ldz, sigma, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info); } #endif #if defined(ARMA_USE_SUPERLU) void wrapper_sgssv(superlu::superlu_options_t* a, superlu::SuperMatrix* b, int* c, int* d, superlu::SuperMatrix* e, superlu::SuperMatrix* f, superlu::SuperMatrix* g, superlu::SuperLUStat_t* h, int* i) { sgssv(a,b,c,d,e,f,g,h,i); } void wrapper_dgssv(superlu::superlu_options_t* a, superlu::SuperMatrix* b, int* c, int* d, superlu::SuperMatrix* e, superlu::SuperMatrix* f, superlu::SuperMatrix* g, superlu::SuperLUStat_t* h, int* i) { dgssv(a,b,c,d,e,f,g,h,i); } void wrapper_cgssv(superlu::superlu_options_t* a, superlu::SuperMatrix* b, int* c, int* d, superlu::SuperMatrix* e, superlu::SuperMatrix* f, superlu::SuperMatrix* g, superlu::SuperLUStat_t* h, int* i) { cgssv(a,b,c,d,e,f,g,h,i); } void wrapper_zgssv(superlu::superlu_options_t* a, superlu::SuperMatrix* b, int* c, int* d, superlu::SuperMatrix* e, superlu::SuperMatrix* f, superlu::SuperMatrix* g, superlu::SuperLUStat_t* h, int* i) { zgssv(a,b,c,d,e,f,g,h,i); } void wrapper_sgssvx(superlu::superlu_options_t* a, superlu::SuperMatrix* b, int* c, int* d, int* e, char* f, float* g, float* h, superlu::SuperMatrix* i, superlu::SuperMatrix* j, void* k, int l, superlu::SuperMatrix* m, superlu::SuperMatrix* n, float* o, float* p, float* q, float* r, superlu::mem_usage_t* s, superlu::SuperLUStat_t* t, int* u) { sgssvx(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u); } void wrapper_dgssvx(superlu::superlu_options_t* a, superlu::SuperMatrix* b, int* c, int* d, int* e, char* f, double* g, double* h, superlu::SuperMatrix* i, superlu::SuperMatrix* j, void* k, int l, superlu::SuperMatrix* m, superlu::SuperMatrix* n, double* o, double* p, double* q, double* r, superlu::mem_usage_t* s, superlu::SuperLUStat_t* t, int* u) { dgssvx(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u); } void wrapper_cgssvx(superlu::superlu_options_t* a, superlu::SuperMatrix* b, int* c, int* d, int* e, char* f, float* g, float* h, superlu::SuperMatrix* i, superlu::SuperMatrix* j, void* k, int l, superlu::SuperMatrix* m, superlu::SuperMatrix* n, float* o, float* p, float* q, float* r, superlu::mem_usage_t* s, superlu::SuperLUStat_t* t, int* u) { cgssvx(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u); } void wrapper_zgssvx(superlu::superlu_options_t* a, superlu::SuperMatrix* b, int* c, int* d, int* e, char* f, double* g, double* h, superlu::SuperMatrix* i, superlu::SuperMatrix* j, void* k, int l, superlu::SuperMatrix* m, superlu::SuperMatrix* n, double* o, double* p, double* q, double* r, superlu::mem_usage_t* s, superlu::SuperLUStat_t* t, int* u) { zgssvx(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u); } void wrapper_StatInit(superlu::SuperLUStat_t* a) { StatInit(a); } void wrapper_StatFree(superlu::SuperLUStat_t* a) { StatFree(a); } void wrapper_set_default_options(superlu::superlu_options_t* a) { set_default_options(a); } void wrapper_Destroy_SuperNode_Matrix(superlu::SuperMatrix* a) { Destroy_SuperNode_Matrix(a); } void wrapper_Destroy_CompCol_Matrix(superlu::SuperMatrix* a) { Destroy_CompCol_Matrix(a); } void wrapper_Destroy_SuperMatrix_Store(superlu::SuperMatrix* a) { Destroy_SuperMatrix_Store(a); } void* wrapper_superlu_malloc(size_t a) { return superlu_malloc(a); } void wrapper_superlu_free(void* a) { superlu_free(a); } #endif #if defined(ARMA_USE_HDF5_ALT) hid_t arma_H5Tcopy(hid_t dtype_id) { return H5Tcopy(dtype_id); } hid_t arma_H5Tcreate(H5T_class_t cl, size_t size) { return H5Tcreate(cl, size); } herr_t arma_H5Tinsert(hid_t dtype_id, const char* name, size_t offset, hid_t field_id) { return H5Tinsert(dtype_id, name, offset, field_id); } htri_t arma_H5Tequal(hid_t dtype_id1, hid_t dtype_id2) { return H5Tequal(dtype_id1, dtype_id2); } herr_t arma_H5Tclose(hid_t dtype_id) { return H5Tclose(dtype_id); } hid_t arma_H5Dopen(hid_t loc_id, const char* name, hid_t dapl_id) { return H5Dopen(loc_id, name, dapl_id); } hid_t arma_H5Dget_type(hid_t dataset_id) { return H5Dget_type(dataset_id); } hid_t arma_H5Dcreate(hid_t loc_id, const char* name, hid_t dtype_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id) { return H5Dcreate(loc_id, name, dtype_id, space_id, lcpl_id, dcpl_id, dapl_id); } herr_t arma_H5Dwrite(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, const void* buf) { return H5Dwrite(dataset_id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, buf); } herr_t arma_H5Dclose(hid_t dataset_id) { return H5Dclose(dataset_id); } hid_t arma_H5Dget_space(hid_t dataset_id) { return H5Dget_space(dataset_id); } herr_t arma_H5Dread(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, void* buf) { return H5Dread(dataset_id, mem_type_id, mem_space_id, file_space_id, xfer_plist_id, buf); } int arma_H5Sget_simple_extent_ndims(hid_t space_id) { return H5Sget_simple_extent_ndims(space_id); } int arma_H5Sget_simple_extent_dims(hid_t space_id, hsize_t* dims, hsize_t* maxdims) { return H5Sget_simple_extent_dims(space_id, dims, maxdims); } herr_t arma_H5Sclose(hid_t space_id) { return H5Sclose(space_id); } hid_t arma_H5Screate_simple(int rank, const hsize_t* current_dims, const hsize_t* maximum_dims) { return H5Screate_simple(rank, current_dims, maximum_dims); } herr_t arma_H5Ovisit(hid_t object_id, H5_index_t index_type, H5_iter_order_t order, H5O_iterate_t op, void* op_data) { return H5Ovisit(object_id, index_type, order, op, op_data); } herr_t arma_H5Eset_auto(hid_t estack_id, H5E_auto_t func, void* client_data) { return H5Eset_auto(estack_id, func, client_data); } herr_t arma_H5Eget_auto(hid_t estack_id, H5E_auto_t* func, void** client_data) { return H5Eget_auto(estack_id, func, client_data); } hid_t arma_H5Fopen(const char* name, unsigned flags, hid_t fapl_id) { return H5Fopen(name, flags, fapl_id); } hid_t arma_H5Fcreate(const char* name, unsigned flags, hid_t fcpl_id, hid_t fapl_id) { return H5Fcreate(name, flags, fcpl_id, fapl_id); } herr_t arma_H5Fclose(hid_t file_id) { return H5Fclose(file_id); } htri_t arma_H5Fis_hdf5(const char* name) { return H5Fis_hdf5(name); } // H5T_NATIVE_* types. The rhs here expands to some macros. hid_t arma_H5T_NATIVE_UCHAR = H5T_NATIVE_UCHAR; hid_t arma_H5T_NATIVE_CHAR = H5T_NATIVE_CHAR; hid_t arma_H5T_NATIVE_SHORT = H5T_NATIVE_SHORT; hid_t arma_H5T_NATIVE_USHORT = H5T_NATIVE_USHORT; hid_t arma_H5T_NATIVE_INT = H5T_NATIVE_INT; hid_t arma_H5T_NATIVE_UINT = H5T_NATIVE_UINT; hid_t arma_H5T_NATIVE_LONG = H5T_NATIVE_LONG; hid_t arma_H5T_NATIVE_ULONG = H5T_NATIVE_ULONG; hid_t arma_H5T_NATIVE_LLONG = H5T_NATIVE_LLONG; hid_t arma_H5T_NATIVE_ULLONG = H5T_NATIVE_ULLONG; hid_t arma_H5T_NATIVE_FLOAT = H5T_NATIVE_FLOAT; hid_t arma_H5T_NATIVE_DOUBLE = H5T_NATIVE_DOUBLE; #endif } // end of extern "C" } // end of namespace arma armadillo-6.500.5/include/0000777000000000000000000000000012656572546014002 5ustar rootrootarmadillo-6.500.5/include/armadillo_bits/0000777000000000000000000000000012656572547016770 5ustar rootrootarmadillo-6.500.5/include/armadillo_bits/spglue_plus_bones.hpp0000666000000000000000000000173012620272703023210 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spglue_plus //! @{ class spglue_plus { public: template arma_hot inline static void apply(SpMat& out, const SpGlue& X); template arma_hot inline static void apply_noalias(SpMat& out, const SpProxy& pa, const SpProxy& pb); }; class spglue_plus2 { public: template arma_hot inline static void apply(SpMat& out, const SpGlue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_trig.hpp0000666000000000000000000001252512620272703021114 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_trig //! @{ // // trigonometric functions: // cos family: cos, acos, cosh, acosh // sin family: sin, asin, sinh, asinh // tan family: tan, atan, tanh, atanh // // cos template arma_inline const eOp cos(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube cos(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // acos template arma_inline const eOp acos(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube acos(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // cosh template arma_inline const eOp cosh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube cosh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // acosh template arma_inline const eOp acosh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube acosh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // sin template arma_inline const eOp sin(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube sin(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // asin template arma_inline const eOp asin(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube asin(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // sinh template arma_inline const eOp sinh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube sinh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // asinh template arma_inline const eOp asinh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube asinh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // tan template arma_inline const eOp tan(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube tan(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // atan template arma_inline const eOp atan(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube atan(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // tanh template arma_inline const eOp tanh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube tanh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // atanh template arma_inline const eOp atanh(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube atanh(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } //! @} armadillo-6.500.5/include/armadillo_bits/glue_conv_meat.hpp0000666000000000000000000001313712647123053022455 0ustar rootroot// Copyright (C) 2010-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_conv //! @{ template inline void glue_conv::apply(Mat& out, const Mat& A, const Mat& B, const bool A_is_col) { arma_extra_debug_sigprint(); const Mat& h = (A.n_elem <= B.n_elem) ? A : B; const Mat& x = (A.n_elem <= B.n_elem) ? B : A; const uword h_n_elem = h.n_elem; const uword h_n_elem_m1 = h_n_elem - 1; const uword x_n_elem = x.n_elem; const uword out_n_elem = ((h_n_elem + x_n_elem) > 0) ? (h_n_elem + x_n_elem - 1) : uword(0); (A_is_col) ? out.set_size(out_n_elem, 1) : out.set_size(1, out_n_elem); if( (h_n_elem == 0) || (x_n_elem == 0) ) { out.zeros(); return; } Col hh(h_n_elem); // flipped version of h const eT* h_mem = h.memptr(); eT* hh_mem = hh.memptr(); for(uword i=0; i < h_n_elem; ++i) { hh_mem[h_n_elem_m1-i] = h_mem[i]; } Col xx( (x_n_elem + 2*h_n_elem_m1), fill::zeros ); // zero padded version of x const eT* x_mem = x.memptr(); eT* xx_mem = xx.memptr(); arrayops::copy( &(xx_mem[h_n_elem_m1]), x_mem, x_n_elem ); eT* out_mem = out.memptr(); for(uword i=0; i < out_n_elem; ++i) { // out_mem[i] = dot( hh, xx.subvec(i, (i + h_n_elem_m1)) ); out_mem[i] = op_dot::direct_dot( h_n_elem, hh_mem, &(xx_mem[i]) ); } } template inline void glue_conv::apply(Mat& out, const Glue& expr) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const quasi_unwrap UA(expr.A); const quasi_unwrap UB(expr.B); const Mat& A = UA.M; const Mat& B = UB.M; arma_debug_check ( ( ((A.is_vec() == false) && (A.is_empty() == false)) || ((B.is_vec() == false) && (B.is_empty() == false)) ), "conv(): given object is not a vector" ); const bool A_is_col = ((T1::is_col) || (A.n_cols == 1)); const uword mode = expr.aux_uword; if(mode == 0) // full convolution { glue_conv::apply(out, A, B, A_is_col); } else if(mode == 1) // same size as A { Mat tmp; glue_conv::apply(tmp, A, B, A_is_col); if( (tmp.is_empty() == false) && (A.is_empty() == false) && (B.is_empty() == false) ) { const uword start = uword( std::floor( double(B.n_elem) / double(2) ) ); out = (A_is_col) ? tmp(start, 0, size(A)) : tmp(0, start, size(A)); } else { out.zeros( size(A) ); } } } /// template inline void glue_conv2::apply(Mat& out, const Mat& A, const Mat& B) { arma_extra_debug_sigprint(); const Mat& G = (A.n_elem <= B.n_elem) ? A : B; // unflipped filter coefficients const Mat& W = (A.n_elem <= B.n_elem) ? B : A; // original 2D image const uword out_n_rows = ((W.n_rows + G.n_rows) > 0) ? (W.n_rows + G.n_rows - 1) : uword(0); const uword out_n_cols = ((W.n_cols + G.n_cols) > 0) ? (W.n_cols + G.n_cols - 1) : uword(0); out.set_size( out_n_rows, out_n_cols ); if(G.is_empty() || W.is_empty()) { out.zeros(); return; } Mat H(G.n_rows, G.n_cols); // flipped filter coefficients const uword H_n_rows = H.n_rows; const uword H_n_cols = H.n_cols; const uword H_n_rows_m1 = H_n_rows - 1; const uword H_n_cols_m1 = H_n_cols - 1; for(uword col=0; col < H_n_cols; ++col) { eT* H_colptr = H.colptr(H_n_cols_m1 - col); const eT* G_colptr = G.colptr(col); for(uword row=0; row < H_n_rows; ++row) { H_colptr[H_n_rows_m1 - row] = G_colptr[row]; } } Mat X( (W.n_rows + 2*H_n_rows_m1), (W.n_cols + 2*H_n_cols_m1), fill::zeros ); X( H_n_rows_m1, H_n_cols_m1, size(W) ) = W; // zero padded version of 2D image for(uword col=0; col < out_n_cols; ++col) { eT* out_colptr = out.colptr(col); for(uword row=0; row < out_n_rows; ++row) { // out.at(row, col) = accu( H % X(row, col, size(H)) ); eT acc = eT(0); for(uword H_col = 0; H_col < H_n_cols; ++H_col) { const eT* X_colptr = X.colptr(col + H_col); acc += op_dot::direct_dot( H_n_rows, H.colptr(H_col), &(X_colptr[row]) ); } out_colptr[row] = acc; } } } template inline void glue_conv2::apply(Mat& out, const Glue& expr) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const quasi_unwrap UA(expr.A); const quasi_unwrap UB(expr.B); const Mat& A = UA.M; const Mat& B = UB.M; const uword mode = expr.aux_uword; if(mode == 0) // full convolution { glue_conv2::apply(out, A, B); } else if(mode == 1) // same size as A { Mat tmp; glue_conv2::apply(tmp, A, B); if( (tmp.is_empty() == false) && (A.is_empty() == false) && (B.is_empty() == false) ) { const uword start_row = uword( std::floor( double(B.n_rows) / double(2) ) ); const uword start_col = uword( std::floor( double(B.n_cols) / double(2) ) ); out = tmp(start_row, start_col, size(A)); } else { out.zeros( size(A) ); } } } //! @} armadillo-6.500.5/include/armadillo_bits/spop_htrans_bones.hpp0000666000000000000000000000165612620272703023215 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spop_htrans //! @{ //! hermitian transpose operation for sparse matrices class spop_htrans { public: template arma_hot inline static void apply(SpMat& out, const SpOp& in, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply(SpMat& out, const SpOp& in, const typename arma_cx_only::result* junk = 0); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_eig_gen.hpp0000666000000000000000000000452312650152164021544 0ustar rootroot// Copyright (C) 2015-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_eig_gen //! @{ template inline typename enable_if2< is_supported_blas_type::value, Col< std::complex > >::result eig_gen ( const Base& expr ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; typedef typename std::complex eT; Col eigvals; Mat eigvecs; const bool status = auxlib::eig_gen(eigvals, eigvecs, false, expr.get_ref()); if(status == false) { eigvals.reset(); arma_bad("eig_gen(): decomposition failed"); } return eigvals; } template inline typename enable_if2< is_supported_blas_type::value, bool >::result eig_gen ( Col< std::complex >& eigvals, const Base< typename T1::elem_type, T1>& expr ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; typedef typename std::complex eT; Mat eigvecs; const bool status = auxlib::eig_gen(eigvals, eigvecs, false, expr.get_ref()); if(status == false) { eigvals.reset(); arma_debug_warn("eig_gen(): decomposition failed"); } return status; } template inline typename enable_if2< is_supported_blas_type::value, bool >::result eig_gen ( Col< std::complex >& eigvals, Mat< std::complex >& eigvecs, const Base& expr ) { arma_extra_debug_sigprint(); arma_debug_check( (void_ptr(&eigvals) == void_ptr(&eigvecs)), "eig_gen(): parameter 'eigval' is an alias of parameter 'eigvec'" ); const bool status = auxlib::eig_gen(eigvals, eigvecs, true, expr.get_ref()); if(status == false) { eigvals.reset(); eigvecs.reset(); arma_debug_warn("eig_gen(): decomposition failed"); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/ProxyCube.hpp0000666000000000000000000004116212620272703021403 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup ProxyCube //! @{ template class ProxyCube { public: inline ProxyCube(const T1&) { arma_type_check(( is_arma_cube_type::value == false )); } }; // ea_type is the "element accessor" type, // which can provide access to elements via operator[] template class ProxyCube< Cube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const eT* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube& Q; inline explicit ProxyCube(const Cube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class ProxyCube< GenCube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef GenCube stored_type; typedef const GenCube& ea_type; typedef const GenCube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const GenCube& Q; inline explicit ProxyCube(const GenCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_rows*Q.n_cols; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_rows*Q.n_cols*Q.n_slices; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return GenCube::is_simple; } }; template class ProxyCube< OpCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const elem_type* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube Q; inline explicit ProxyCube(const OpCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class ProxyCube< GlueCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const elem_type* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube Q; inline explicit ProxyCube(const GlueCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class ProxyCube< subview_cube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_cube stored_type; typedef const subview_cube& ea_type; typedef const subview_cube& aligned_ea_type; static const bool prefer_at_accessor = true; static const bool has_subview = true; arma_aligned const subview_cube& Q; inline explicit ProxyCube(const subview_cube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class ProxyCube< eOpCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eOpCube stored_type; typedef const eOpCube& ea_type; typedef const eOpCube& aligned_ea_type; static const bool prefer_at_accessor = eOpCube::prefer_at_accessor; static const bool has_subview = eOpCube::has_subview; arma_aligned const eOpCube& Q; inline explicit ProxyCube(const eOpCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.get_n_rows(); } arma_inline uword get_n_cols() const { return Q.get_n_cols(); } arma_inline uword get_n_elem_slice() const { return Q.get_n_elem_slice(); } arma_inline uword get_n_slices() const { return Q.get_n_slices(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube& X) const { return Q.P.is_alias(X); } arma_inline bool is_aligned() const { return Q.P.is_aligned(); } }; template class ProxyCube< eGlueCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eGlueCube stored_type; typedef const eGlueCube& ea_type; typedef const eGlueCube& aligned_ea_type; static const bool prefer_at_accessor = eGlueCube::prefer_at_accessor; static const bool has_subview = eGlueCube::has_subview; arma_aligned const eGlueCube& Q; inline explicit ProxyCube(const eGlueCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.get_n_rows(); } arma_inline uword get_n_cols() const { return Q.get_n_cols(); } arma_inline uword get_n_elem_slice() const { return Q.get_n_elem_slice(); } arma_inline uword get_n_slices() const { return Q.get_n_slices(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube& X) const { return (Q.P1.is_alias(X) || Q.P2.is_alias(X)); } arma_inline bool is_aligned() const { return Q.P1.is_aligned() && Q.P2.is_aligned(); } }; template class ProxyCube< mtOpCube > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const elem_type* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube Q; inline explicit ProxyCube(const mtOpCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class ProxyCube< mtGlueCube > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef Cube stored_type; typedef const elem_type* ea_type; typedef const Cube& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; arma_aligned const Cube Q; inline explicit ProxyCube(const mtGlueCube& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem_slice() const { return Q.n_elem_slice; } arma_inline uword get_n_slices() const { return Q.n_slices; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col, const uword slice) const { return Q.at(row, col, slice); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Cube&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; //! @} armadillo-6.500.5/include/armadillo_bits/op_misc_bones.hpp0000666000000000000000000000326012620272703022277 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_misc //! @{ class op_real { public: template inline static void apply( Mat& out, const mtOp& X); template inline static void apply( Cube& out, const mtOpCube& X); }; class op_imag { public: template inline static void apply( Mat& out, const mtOp& X); template inline static void apply( Cube& out, const mtOpCube& X); }; class op_abs { public: template inline static void apply( Mat& out, const mtOp& X); template inline static void apply( Cube& out, const mtOpCube& X); }; class op_orth { public: template inline static void apply(Mat& out, const Op& expr); }; class op_null { public: template inline static void apply(Mat& out, const Op& expr); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_randg.hpp0000666000000000000000000001304412620272703021237 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_randg //! @{ template inline obj_type randg(const uword n_rows, const uword n_cols, const distr_param& param = distr_param(), const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); #if defined(ARMA_USE_CXX11) { if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "randg(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "randg(): incompatible size" ); } obj_type out(n_rows, n_cols); double a; double b; if(param.state == 0) { a = double(1); b = double(1); } else if(param.state == 1) { a = double(param.a_int); b = double(param.b_int); } else { a = param.a_double; b = param.b_double; } arma_debug_check( ((a <= double(0)) || (b <= double(0))), "randg(): a and b must be greater than zero" ); #if defined(ARMA_USE_EXTERN_CXX11_RNG) { arma_rng_cxx11_instance.randg_fill(out.memptr(), out.n_elem, a, b); } #else { arma_rng_cxx11 local_arma_rng_cxx11_instance; typedef typename arma_rng_cxx11::seed_type seed_type; local_arma_rng_cxx11_instance.set_seed( seed_type(arma_rng::randi()) ); local_arma_rng_cxx11_instance.randg_fill(out.memptr(), out.n_elem, a, b); } #endif return out; } #else { arma_ignore(n_rows); arma_ignore(n_cols); arma_ignore(param); arma_stop("randg(): C++11 compiler required"); return obj_type(); } #endif } template inline obj_type randg(const SizeMat& s, const distr_param& param = distr_param(), const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return randg(s.n_rows, s.n_cols, param); } template inline obj_type randg(const uword n_elem, const distr_param& param = distr_param(), const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value == true) { return randg(1, n_elem, param); } else { return randg(n_elem, 1, param); } } inline mat randg(const uword n_rows, const uword n_cols, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randg(n_rows, n_cols, param); } inline mat randg(const SizeMat& s, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randg(s.n_rows, s.n_cols, param); } inline vec randg(const uword n_elem, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randg(n_elem, param); } template inline cube_type randg(const uword n_rows, const uword n_cols, const uword n_slices, const distr_param& param = distr_param(), const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); #if defined(ARMA_USE_CXX11) { cube_type out(n_rows, n_cols, n_slices); double a; double b; if(param.state == 0) { a = double(1); b = double(1); } else if(param.state == 1) { a = double(param.a_int); b = double(param.b_int); } else { a = param.a_double; b = param.b_double; } arma_debug_check( ((a <= double(0)) || (b <= double(0))), "randg(): a and b must be greater than zero" ); #if defined(ARMA_USE_EXTERN_CXX11_RNG) { arma_rng_cxx11_instance.randg_fill(out.memptr(), out.n_elem, a, b); } #else { arma_rng_cxx11 local_arma_rng_cxx11_instance; typedef typename arma_rng_cxx11::seed_type seed_type; local_arma_rng_cxx11_instance.set_seed( seed_type(arma_rng::randi()) ); local_arma_rng_cxx11_instance.randg_fill(out.memptr(), out.n_elem, a, b); } #endif return out; } #else { arma_ignore(n_rows); arma_ignore(n_cols); arma_ignore(n_slices); arma_ignore(param); arma_stop("randg(): C++11 compiler required"); return cube_type(); } #endif } template inline cube_type randg(const SizeCube& s, const distr_param& param = distr_param(), const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return randg(s.n_rows, s.n_cols, s.n_slices, param); } inline cube randg(const uword n_rows, const uword n_cols, const uword n_slices, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randg(n_rows, n_cols, n_slices, param); } inline cube randg(const SizeCube& s, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randg(s.n_rows, s.n_cols, s.n_slices, param); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_qz.hpp0000666000000000000000000000235012620272703020574 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Keith O'Hara //! \addtogroup fn_qz //! @{ //! QZ decomposition for pair of N-by-N general matrices A and B template inline typename enable_if2 < is_supported_blas_type::value, bool >::result qz ( Mat& AA, Mat& BB, Mat& Q, Mat& Z, const Base& A_expr, const Base& B_expr ) { arma_extra_debug_sigprint(); const bool status = auxlib::qz(AA, BB, Q, Z, A_expr.get_ref(), B_expr.get_ref()); if(status == false) { AA.reset(); BB.reset(); Q.reset(); Z.reset(); arma_debug_warn("qz(): decomposition failed"); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/constants.hpp0000666000000000000000000002412112620272703021473 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup constants //! @{ namespace priv { class Datum_helper { public: template static typename arma_real_only::result nan(typename arma_real_only::result* junk = 0) { arma_ignore(junk); if(std::numeric_limits::has_quiet_NaN) { return std::numeric_limits::quiet_NaN(); } else { return eT(0); } } template static typename arma_cx_only::result nan(typename arma_cx_only::result* junk = 0) { arma_ignore(junk); typedef typename get_pod_type::result T; return eT( Datum_helper::nan(), Datum_helper::nan() ); } template static typename arma_integral_only::result nan(typename arma_integral_only::result* junk = 0) { arma_ignore(junk); return eT(0); } template static typename arma_real_only::result inf(typename arma_real_only::result* junk = 0) { arma_ignore(junk); if(std::numeric_limits::has_infinity) { return std::numeric_limits::infinity(); } else { return std::numeric_limits::max(); } } template static typename arma_cx_only::result inf(typename arma_cx_only::result* junk = 0) { arma_ignore(junk); typedef typename get_pod_type::result T; return eT( Datum_helper::inf(), Datum_helper::inf() ); } template static typename arma_integral_only::result inf(typename arma_integral_only::result* junk = 0) { arma_ignore(junk); return std::numeric_limits::max(); } }; } //! various constants. //! Physical constants taken from NIST 2010 CODATA values, and some from WolframAlpha (values provided as of 2009-06-23) //! http://physics.nist.gov/cuu/Constants //! http://www.wolframalpha.com //! See also http://en.wikipedia.org/wiki/Physical_constant template class Datum { public: static const eT pi; //!< ratio of any circle's circumference to its diameter static const eT e; //!< base of the natural logarithm static const eT euler; //!< Euler's constant, aka Euler-Mascheroni constant static const eT gratio; //!< golden ratio static const eT sqrt2; //!< square root of 2 static const eT eps; //!< the difference between 1 and the least value greater than 1 that is representable static const eT log_min; //!< log of the minimum representable value static const eT log_max; //!< log of the maximum representable value static const eT nan; //!< "not a number" static const eT inf; //!< infinity // static const eT m_u; //!< atomic mass constant (in kg) static const eT N_A; //!< Avogadro constant static const eT k; //!< Boltzmann constant (in joules per kelvin) static const eT k_evk; //!< Boltzmann constant (in eV/K) static const eT a_0; //!< Bohr radius (in meters) static const eT mu_B; //!< Bohr magneton static const eT Z_0; //!< characteristic impedance of vacuum (in ohms) static const eT G_0; //!< conductance quantum (in siemens) static const eT k_e; //!< Coulomb's constant (in meters per farad) static const eT eps_0; //!< electric constant (in farads per meter) static const eT m_e; //!< electron mass (in kg) static const eT eV; //!< electron volt (in joules) static const eT ec; //!< elementary charge (in coulombs) static const eT F; //!< Faraday constant (in coulombs) static const eT alpha; //!< fine-structure constant static const eT alpha_inv; //!< inverse fine-structure constant static const eT K_J; //!< Josephson constant static const eT mu_0; //!< magnetic constant (in henries per meter) static const eT phi_0; //!< magnetic flux quantum (in webers) static const eT R; //!< molar gas constant (in joules per mole kelvin) static const eT G; //!< Newtonian constant of gravitation (in newton square meters per kilogram squared) static const eT h; //!< Planck constant (in joule seconds) static const eT h_bar; //!< Planck constant over 2 pi, aka reduced Planck constant (in joule seconds) static const eT m_p; //!< proton mass (in kg) static const eT R_inf; //!< Rydberg constant (in reciprocal meters) static const eT c_0; //!< speed of light in vacuum (in meters per second) static const eT sigma; //!< Stefan-Boltzmann constant static const eT R_k; //!< von Klitzing constant (in ohms) static const eT b; //!< Wien wavelength displacement law constant }; // the long lengths of the constants are for future support of "long double" // and any smart compiler that does high-precision computation at compile-time template const eT Datum::pi = eT(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679); template const eT Datum::e = eT(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274); template const eT Datum::euler = eT(0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495); template const eT Datum::gratio = eT(1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374); template const eT Datum::sqrt2 = eT(1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727); template const eT Datum::eps = std::numeric_limits::epsilon(); template const eT Datum::log_min = std::log(std::numeric_limits::min()); template const eT Datum::log_max = std::log(std::numeric_limits::max()); template const eT Datum::nan = priv::Datum_helper::nan(); template const eT Datum::inf = priv::Datum_helper::inf(); template const eT Datum::m_u = eT(1.660539040e-27); template const eT Datum::N_A = eT(6.022140857e23); template const eT Datum::k = eT(1.38064852e-23); template const eT Datum::k_evk = eT(8.6173303e-5); template const eT Datum::a_0 = eT(0.52917721067e-10); template const eT Datum::mu_B = eT(927.4009994e-26); template const eT Datum::Z_0 = eT(376.730313461771); template const eT Datum::G_0 = eT(7.7480917310e-5); template const eT Datum::k_e = eT(8.9875517873681764e9); template const eT Datum::eps_0 = eT(8.85418781762039e-12); template const eT Datum::m_e = eT(9.10938356e-31); template const eT Datum::eV = eT(1.6021766208e-19); template const eT Datum::ec = eT(1.6021766208e-19); template const eT Datum::F = eT(96485.33289); template const eT Datum::alpha = eT(7.2973525664e-3); template const eT Datum::alpha_inv = eT(137.035999139); template const eT Datum::K_J = eT(483597.8525e9); template const eT Datum::mu_0 = eT(1.25663706143592e-06); template const eT Datum::phi_0 = eT(2.067833667e-15); template const eT Datum::R = eT(8.3144598); template const eT Datum::G = eT(6.67408e-11); template const eT Datum::h = eT(6.626070040e-34); template const eT Datum::h_bar = eT(1.054571800e-34); template const eT Datum::m_p = eT(1.672621898e-27); template const eT Datum::R_inf = eT(10973731.568508); template const eT Datum::c_0 = eT(299792458.0); template const eT Datum::sigma = eT(5.670367e-8); template const eT Datum::R_k = eT(25812.8074555); template const eT Datum::b = eT(2.8977729e-3); typedef Datum fdatum; typedef Datum datum; namespace priv { template static arma_inline arma_hot typename arma_real_only::result most_neg(typename arma_real_only::result* junk = 0) { arma_ignore(junk); if(std::numeric_limits::has_infinity) { return -(std::numeric_limits::infinity()); } else { return -(std::numeric_limits::max()); } } template static arma_inline arma_hot typename arma_integral_only::result most_neg(typename arma_integral_only::result* junk = 0) { arma_ignore(junk); return std::numeric_limits::min(); } template static arma_inline arma_hot typename arma_real_only::result most_pos(typename arma_real_only::result* junk = 0) { arma_ignore(junk); if(std::numeric_limits::has_infinity) { return std::numeric_limits::infinity(); } else { return std::numeric_limits::max(); } } template static arma_inline arma_hot typename arma_integral_only::result most_pos(typename arma_integral_only::result* junk = 0) { arma_ignore(junk); return std::numeric_limits::max(); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_cov_bones.hpp0000666000000000000000000000161112620272703022131 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_cov //! @{ class op_cov { public: template inline static void direct_cov(Mat& out, const Mat& X, const uword norm_type); template inline static void direct_cov(Mat< std::complex >& out, const Mat< std::complex >& X, const uword norm_type); template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_as_scalar.hpp0000666000000000000000000002667712650111756022117 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_as_scalar //! @{ template struct as_scalar_redirect { template inline static typename T1::elem_type apply(const T1& X); }; template<> struct as_scalar_redirect<2> { template inline static typename T1::elem_type apply(const Glue& X); }; template<> struct as_scalar_redirect<3> { template inline static typename T1::elem_type apply(const Glue< Glue, T3, glue_times>& X); }; template template inline typename T1::elem_type as_scalar_redirect::apply(const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); if(P.get_n_elem() != 1) { arma_debug_check(true, "as_scalar(): expression doesn't evaluate to exactly one element"); return Datum::nan; } return (Proxy::prefer_at_accessor) ? P.at(0,0) : P[0]; } template inline typename T1::elem_type as_scalar_redirect<2>::apply(const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // T1 must result in a matrix with one row // T2 must result in a matrix with one column const bool has_all_mat = (is_Mat::value || is_Mat_trans::value) && (is_Mat::value || is_Mat_trans::value); const bool prefer_at_accessor = Proxy::prefer_at_accessor || Proxy::prefer_at_accessor; const bool do_partial_unwrap = has_all_mat || prefer_at_accessor; if(do_partial_unwrap == true) { const partial_unwrap tmp1(X.A); const partial_unwrap tmp2(X.B); typedef typename partial_unwrap::stored_type TA; typedef typename partial_unwrap::stored_type TB; const TA& A = tmp1.M; const TB& B = tmp2.M; const uword A_n_rows = (tmp1.do_trans == false) ? (TA::is_row ? 1 : A.n_rows) : (TA::is_col ? 1 : A.n_cols); const uword A_n_cols = (tmp1.do_trans == false) ? (TA::is_col ? 1 : A.n_cols) : (TA::is_row ? 1 : A.n_rows); const uword B_n_rows = (tmp2.do_trans == false) ? (TB::is_row ? 1 : B.n_rows) : (TB::is_col ? 1 : B.n_cols); const uword B_n_cols = (tmp2.do_trans == false) ? (TB::is_col ? 1 : B.n_cols) : (TB::is_row ? 1 : B.n_rows); arma_debug_check( (A_n_rows != 1) || (B_n_cols != 1) || (A_n_cols != B_n_rows), "as_scalar(): incompatible dimensions" ); const eT val = op_dot::direct_dot(A.n_elem, A.memptr(), B.memptr()); return (tmp1.do_times || tmp2.do_times) ? (val * tmp1.get_val() * tmp2.get_val()) : val; } else { const Proxy PA(X.A); const Proxy PB(X.B); arma_debug_check ( (PA.get_n_rows() != 1) || (PB.get_n_cols() != 1) || (PA.get_n_cols() != PB.get_n_rows()), "as_scalar(): incompatible dimensions" ); return op_dot::apply_proxy(PA,PB); } } template inline typename T1::elem_type as_scalar_redirect<3>::apply(const Glue< Glue, T3, glue_times >& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // T1 * T2 must result in a matrix with one row // T3 must result in a matrix with one column typedef typename strip_inv ::stored_type T2_stripped_1; typedef typename strip_diagmat::stored_type T2_stripped_2; const strip_inv strip1(X.A.B); const strip_diagmat strip2(strip1.M); const bool tmp2_do_inv = strip1.do_inv; const bool tmp2_do_diagmat = strip2.do_diagmat; if(tmp2_do_diagmat == false) { const Mat tmp(X); if(tmp.n_elem != 1) { arma_debug_check(true, "as_scalar(): expression doesn't evaluate to exactly one element"); return Datum::nan; } return tmp[0]; } else { const partial_unwrap tmp1(X.A.A); const partial_unwrap tmp2(strip2.M); const partial_unwrap tmp3(X.B); const Mat& A = tmp1.M; const Mat& B = tmp2.M; const Mat& C = tmp3.M; const uword A_n_rows = (tmp1.do_trans == false) ? A.n_rows : A.n_cols; const uword A_n_cols = (tmp1.do_trans == false) ? A.n_cols : A.n_rows; const bool B_is_vec = B.is_vec(); const uword B_n_rows = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans == false) ? B.n_rows : B.n_cols ); const uword B_n_cols = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans == false) ? B.n_cols : B.n_rows ); const uword C_n_rows = (tmp3.do_trans == false) ? C.n_rows : C.n_cols; const uword C_n_cols = (tmp3.do_trans == false) ? C.n_cols : C.n_rows; const eT val = tmp1.get_val() * tmp2.get_val() * tmp3.get_val(); arma_debug_check ( (A_n_rows != 1) || (C_n_cols != 1) || (A_n_cols != B_n_rows) || (B_n_cols != C_n_rows) , "as_scalar(): incompatible dimensions" ); if(B_is_vec == true) { if(tmp2_do_inv == true) { return val * op_dotext::direct_rowvec_invdiagvec_colvec(A.mem, B, C.mem); } else { return val * op_dot::direct_dot(A.n_elem, A.mem, B.mem, C.mem); } } else { if(tmp2_do_inv == true) { return val * op_dotext::direct_rowvec_invdiagmat_colvec(A.mem, B, C.mem); } else { return val * op_dotext::direct_rowvec_diagmat_colvec(A.mem, B, C.mem); } } } } template inline typename T1::elem_type as_scalar_diag(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; if(A.n_elem != 1) { arma_debug_check(true, "as_scalar(): expression doesn't evaluate to exactly one element"); return Datum::nan; } return A.mem[0]; } template inline typename T1::elem_type as_scalar_diag(const Glue< Glue, T3, glue_times >& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // T1 * T2 must result in a matrix with one row // T3 must result in a matrix with one column typedef typename strip_diagmat::stored_type T2_stripped; const strip_diagmat strip(X.A.B); const partial_unwrap tmp1(X.A.A); const partial_unwrap tmp2(strip.M); const partial_unwrap tmp3(X.B); const Mat& A = tmp1.M; const Mat& B = tmp2.M; const Mat& C = tmp3.M; const uword A_n_rows = (tmp1.do_trans == false) ? A.n_rows : A.n_cols; const uword A_n_cols = (tmp1.do_trans == false) ? A.n_cols : A.n_rows; const bool B_is_vec = B.is_vec(); const uword B_n_rows = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans == false) ? B.n_rows : B.n_cols ); const uword B_n_cols = (B_is_vec == true) ? B.n_elem : ( (tmp2.do_trans == false) ? B.n_cols : B.n_rows ); const uword C_n_rows = (tmp3.do_trans == false) ? C.n_rows : C.n_cols; const uword C_n_cols = (tmp3.do_trans == false) ? C.n_cols : C.n_rows; const eT val = tmp1.get_val() * tmp2.get_val() * tmp3.get_val(); arma_debug_check ( (A_n_rows != 1) || (C_n_cols != 1) || (A_n_cols != B_n_rows) || (B_n_cols != C_n_rows) , "as_scalar(): incompatible dimensions" ); if(B_is_vec == true) { return val * op_dot::direct_dot(A.n_elem, A.mem, B.mem, C.mem); } else { return val * op_dotext::direct_rowvec_diagmat_colvec(A.mem, B, C.mem); } } template arma_inline arma_warn_unused typename T1::elem_type as_scalar(const Glue& X, const typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_glue_times_diag::value == false) { const sword N_mat = 1 + depth_lhs< glue_times, Glue >::num; arma_extra_debug_print(arma_str::format("N_mat = %d") % N_mat); return as_scalar_redirect::apply(X); } else { return as_scalar_diag(X); } } template inline arma_warn_unused typename T1::elem_type as_scalar(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); if(P.get_n_elem() != 1) { arma_debug_check(true, "as_scalar(): expression doesn't evaluate to exactly one element"); return Datum::nan; } return (Proxy::prefer_at_accessor) ? P.at(0,0) : P[0]; } // ensure the following two functions are aware of each other template inline arma_warn_unused typename T1::elem_type as_scalar(const eOp& X); template inline arma_warn_unused typename T1::elem_type as_scalar(const eGlue& X); template inline arma_warn_unused typename T1::elem_type as_scalar(const eOp& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const eT val = as_scalar(X.P.Q); return eop_core::process(val, X.aux); } template inline arma_warn_unused typename T1::elem_type as_scalar(const eGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const eT a = as_scalar(X.P1.Q); const eT b = as_scalar(X.P2.Q); // the optimiser will keep only one return statement if(is_same_type::yes) { return a + b; } else if(is_same_type::yes) { return a - b; } else if(is_same_type::yes) { return a / b; } else if(is_same_type::yes) { return a * b; } } template inline arma_warn_unused typename T1::elem_type as_scalar(const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const ProxyCube P(X.get_ref()); if(P.get_n_elem() != 1) { arma_debug_check(true, "as_scalar(): expression doesn't evaluate to exactly one element"); return Datum::nan; } return (ProxyCube::prefer_at_accessor) ? P.at(0,0,0) : P[0]; } template arma_inline arma_warn_unused const typename arma_scalar_only::result & as_scalar(const T& x) { return x; } template inline arma_warn_unused typename T1::elem_type as_scalar(const SpBase& X) { typedef typename T1::elem_type eT; const unwrap_spmat tmp(X.get_ref()); const SpMat& A = tmp.M; if(A.n_elem != 1) { arma_debug_check(true, "as_scalar(): expression doesn't evaluate to exactly one element"); return Datum::nan; } return A.at(0,0); } //! @} armadillo-6.500.5/include/armadillo_bits/glue_kron_bones.hpp0000666000000000000000000000212112620272703022626 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup glue_kron //! @{ class glue_kron { public: template inline static void direct_kron(Mat& out, const Mat& A, const Mat& B); template inline static void direct_kron(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat& B); template inline static void direct_kron(Mat< std::complex >& out, const Mat& A, const Mat< std::complex >& B); template inline static void apply(Mat& out, const Glue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/spop_min_bones.hpp0000666000000000000000000000370712620272703022500 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_min //! @{ class spop_min { public: template inline static void apply(SpMat& out, const SpOp& in); // template inline static void apply_proxy(SpMat& out, const SpProxy& p, const uword dim, const typename arma_not_cx::result* junk = 0); template inline static typename T1::elem_type vector_min(const T1& X, const typename arma_not_cx::result* junk = 0); template inline static typename arma_not_cx::result min(const SpBase& X); template inline static typename arma_not_cx::result min_with_index(const SpProxy& P, uword& index_of_min_val); // template inline static void apply_proxy(SpMat& out, const SpProxy& p, const uword dim, const typename arma_cx_only::result* junk = 0); template inline static typename T1::elem_type vector_min(const T1& X, const typename arma_cx_only::result* junk = 0); template inline static typename arma_cx_only::result min(const SpBase& X); template inline static typename arma_cx_only::result min_with_index(const SpProxy& P, uword& index_of_min_val); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_chol_bones.hpp0000666000000000000000000000112312620272703022265 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_chol //! @{ class op_chol { public: template inline static void apply(Mat& out, const Op& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/spdiagview_meat.hpp0000666000000000000000000004615712620272703022644 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spdiagview //! @{ template inline spdiagview::~spdiagview() { arma_extra_debug_sigprint(); } template arma_inline spdiagview::spdiagview(const SpMat& in_m, const uword in_row_offset, const uword in_col_offset, const uword in_len) : m(in_m) , row_offset(in_row_offset) , col_offset(in_col_offset) , n_rows(in_len) , n_elem(in_len) { arma_extra_debug_sigprint(); } //! set a diagonal of our matrix using a diagonal from a foreign matrix template inline void spdiagview::operator= (const spdiagview& x) { arma_extra_debug_sigprint(); spdiagview& d = *this; arma_debug_check( (d.n_elem != x.n_elem), "spdiagview: diagonals have incompatible lengths"); SpMat& d_m = const_cast< SpMat& >(d.m); const SpMat& x_m = x.m; if(&d_m != &x_m) { const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const uword x_row_offset = x.row_offset; const uword x_col_offset = x.col_offset; for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) = x_m.at(i + x_row_offset, i + x_col_offset); } } else { const Mat tmp = x; (*this).operator=(tmp); } } template inline void spdiagview::operator+=(const eT val) { arma_extra_debug_sigprint(); SpMat& t_m = const_cast< SpMat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword i=0; i < t_n_elem; ++i) { t_m.at(i + t_row_offset, i + t_col_offset) += val; } } template inline void spdiagview::operator-=(const eT val) { arma_extra_debug_sigprint(); SpMat& t_m = const_cast< SpMat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword i=0; i < t_n_elem; ++i) { t_m.at(i + t_row_offset, i + t_col_offset) -= val; } } template inline void spdiagview::operator*=(const eT val) { arma_extra_debug_sigprint(); SpMat& t_m = const_cast< SpMat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword i=0; i < t_n_elem; ++i) { t_m.at(i + t_row_offset, i + t_col_offset) *= val; } } template inline void spdiagview::operator/=(const eT val) { arma_extra_debug_sigprint(); SpMat& t_m = const_cast< SpMat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword i=0; i < t_n_elem; ++i) { t_m.at(i + t_row_offset, i + t_col_offset) /= val; } } //! set a diagonal of our matrix using data from a foreign object template template inline void spdiagview::operator= (const Base& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) ) { const unwrap::stored_type> tmp(P.Q); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) = x_mem[i]; } } else { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) = Pea[i]; } } } template template inline void spdiagview::operator+=(const Base& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) ) { const unwrap::stored_type> tmp(P.Q); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) += x_mem[i]; } } else { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) += Pea[i]; } } } template template inline void spdiagview::operator-=(const Base& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) ) { const unwrap::stored_type> tmp(P.Q); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) -= x_mem[i]; } } else { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) -= Pea[i]; } } } template template inline void spdiagview::operator%=(const Base& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) ) { const unwrap::stored_type> tmp(P.Q); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) *= x_mem[i]; } } else { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) *= Pea[i]; } } } template template inline void spdiagview::operator/=(const Base& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) ) { const unwrap::stored_type> tmp(P.Q); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) /= x_mem[i]; } } else { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) /= Pea[i]; } } } //! set a diagonal of our matrix using data from a foreign object template template inline void spdiagview::operator= (const SpBase& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const SpProxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( SpProxy::must_use_iterator || P.is_alias(d_m) ) { const SpMat tmp(P.Q); if(tmp.n_cols == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) = tmp.at(i,0); } } else if(tmp.n_rows == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) = tmp.at(0,i); } } } else { if(P.get_n_cols() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) = P.at(i,0); } } else if(P.get_n_rows() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) = P.at(0,i); } } } } template template inline void spdiagview::operator+=(const SpBase& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const SpProxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( SpProxy::must_use_iterator || P.is_alias(d_m) ) { const SpMat tmp(P.Q); if(tmp.n_cols == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) += tmp.at(i,0); } } else if(tmp.n_rows == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) += tmp.at(0,i); } } } else { if(P.get_n_cols() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) += P.at(i,0); } } else if(P.get_n_rows() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) += P.at(0,i); } } } } template template inline void spdiagview::operator-=(const SpBase& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const SpProxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( SpProxy::must_use_iterator || P.is_alias(d_m) ) { const SpMat tmp(P.Q); if(tmp.n_cols == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) -= tmp.at(i,0); } } else if(tmp.n_rows == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) -= tmp.at(0,i); } } } else { if(P.get_n_cols() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) -= P.at(i,0); } } else if(P.get_n_rows() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) -= P.at(0,i); } } } } template template inline void spdiagview::operator%=(const SpBase& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const SpProxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( SpProxy::must_use_iterator || P.is_alias(d_m) ) { const SpMat tmp(P.Q); if(tmp.n_cols == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) *= tmp.at(i,0); } } else if(tmp.n_rows == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) *= tmp.at(0,i); } } } else { if(P.get_n_cols() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) *= P.at(i,0); } } else if(P.get_n_rows() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) *= P.at(0,i); } } } } template template inline void spdiagview::operator/=(const SpBase& o) { arma_extra_debug_sigprint(); spdiagview& d = *this; SpMat& d_m = const_cast< SpMat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const SpProxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "spdiagview: given object has incompatible size" ); if( SpProxy::must_use_iterator || P.is_alias(d_m) ) { const SpMat tmp(P.Q); if(tmp.n_cols == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) /= tmp.at(i,0); } } else if(tmp.n_rows == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) /= tmp.at(0,i); } } } else { if(P.get_n_cols() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) /= P.at(i,0); } } else if(P.get_n_rows() == 1) { for(uword i=0; i < d_n_elem; ++i) { d_m.at(i + d_row_offset, i + d_col_offset) /= P.at(0,i); } } } } //! extract a diagonal and store it as a dense column vector template inline void spdiagview::extract(Mat& out, const spdiagview& in) { arma_extra_debug_sigprint(); // NOTE: we're assuming that the 'out' matrix has already been set to the correct size; // size setting is done by either the Mat contructor or Mat::operator=() const SpMat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); for(uword i=0; i < in_n_elem; ++i) { out_mem[i] = in_m.at(i + in_row_offset, i + in_col_offset ); } } template inline eT spdiagview::at_alt(const uword i) const { return m.at(i+row_offset, i+col_offset); } template inline SpValProxy< SpMat > spdiagview::operator[](const uword i) { return (const_cast< SpMat& >(m)).at(i+row_offset, i+col_offset); } template inline eT spdiagview::operator[](const uword i) const { return m.at(i+row_offset, i+col_offset); } template inline SpValProxy< SpMat > spdiagview::at(const uword i) { return (const_cast< SpMat& >(m)).at(i+row_offset, i+col_offset); } template inline eT spdiagview::at(const uword i) const { return m.at(i+row_offset, i+col_offset); } template inline SpValProxy< SpMat > spdiagview::operator()(const uword i) { arma_debug_check( (i >= n_elem), "spdiagview::operator(): out of bounds" ); return (const_cast< SpMat& >(m)).at(i+row_offset, i+col_offset); } template inline eT spdiagview::operator()(const uword i) const { arma_debug_check( (i >= n_elem), "spdiagview::operator(): out of bounds" ); return m.at(i+row_offset, i+col_offset); } template inline SpValProxy< SpMat > spdiagview::at(const uword row, const uword) { return (const_cast< SpMat& >(m)).at(row+row_offset, row+col_offset); } template inline eT spdiagview::at(const uword row, const uword) const { return m.at(row+row_offset, row+col_offset); } template inline SpValProxy< SpMat > spdiagview::operator()(const uword row, const uword col) { arma_debug_check( ((row >= n_elem) || (col > 0)), "spdiagview::operator(): out of bounds" ); return (const_cast< SpMat& >(m)).at(row+row_offset, row+col_offset); } template inline eT spdiagview::operator()(const uword row, const uword col) const { arma_debug_check( ((row >= n_elem) || (col > 0)), "spdiagview::operator(): out of bounds" ); return m.at(row+row_offset, row+col_offset); } template inline void spdiagview::fill(const eT val) { arma_extra_debug_sigprint(); SpMat& x = const_cast< SpMat& >(m); const uword local_n_elem = n_elem; for(uword i=0; i < local_n_elem; ++i) { x.at(i+row_offset, i+col_offset) = val; } } template inline void spdiagview::zeros() { arma_extra_debug_sigprint(); (*this).fill(eT(0)); } template inline void spdiagview::ones() { arma_extra_debug_sigprint(); (*this).fill(eT(1)); } template inline void spdiagview::randu() { arma_extra_debug_sigprint(); SpMat& x = const_cast< SpMat& >(m); const uword local_n_elem = n_elem; for(uword i=0; i < local_n_elem; ++i) { x.at(i+row_offset, i+col_offset) = eT(arma_rng::randu()); } } template inline void spdiagview::randn() { arma_extra_debug_sigprint(); SpMat& x = const_cast< SpMat& >(m); const uword local_n_elem = n_elem; for(uword i=0; i < local_n_elem; ++i) { x.at(i+row_offset, i+col_offset) = eT(arma_rng::randn()); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_resize_meat.hpp0000666000000000000000000000617112620272703022471 0ustar rootroot// Copyright (C) 2011-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_resize //! @{ template inline void op_resize::apply(Mat& actual_out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword out_n_rows = in.aux_uword_a; const uword out_n_cols = in.aux_uword_b; const unwrap tmp(in.m); const Mat& A = tmp.M; const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const bool alias = (&actual_out == &A); if(alias) { if( (A_n_rows == out_n_rows) && (A_n_cols == out_n_cols) ) { return; } if(actual_out.is_empty()) { actual_out.zeros(out_n_rows, out_n_cols); return; } } Mat B; Mat& out = alias ? B : actual_out; out.set_size(out_n_rows, out_n_cols); if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) ) { out.zeros(); } if( (out.n_elem > 0) && (A.n_elem > 0) ) { const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1; const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1; out.submat(0, 0, end_row, end_col) = A.submat(0, 0, end_row, end_col); } if(alias) { actual_out.steal_mem(B); } } template inline void op_resize::apply(Cube& actual_out, const OpCube& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword out_n_rows = in.aux_uword_a; const uword out_n_cols = in.aux_uword_b; const uword out_n_slices = in.aux_uword_c; const unwrap_cube tmp(in.m); const Cube& A = tmp.M; const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword A_n_slices = A.n_slices; const bool alias = (&actual_out == &A); if(alias) { if( (A_n_rows == out_n_rows) && (A_n_cols == out_n_cols) && (A_n_slices == out_n_slices) ) { return; } if(actual_out.is_empty()) { actual_out.zeros(out_n_rows, out_n_cols, out_n_slices); return; } } Cube B; Cube& out = alias ? B : actual_out; out.set_size(out_n_rows, out_n_cols, out_n_slices); if( (out_n_rows > A_n_rows) || (out_n_cols > A_n_cols) || (out_n_slices > A_n_slices) ) { out.zeros(); } if( (out.n_elem > 0) && (A.n_elem > 0) ) { const uword end_row = (std::min)(out_n_rows, A_n_rows) - 1; const uword end_col = (std::min)(out_n_cols, A_n_cols) - 1; const uword end_slice = (std::min)(out_n_slices, A_n_slices) - 1; out.subcube(0, 0, 0, end_row, end_col, end_slice) = A.subcube(0, 0, 0, end_row, end_col, end_slice); } if(alias) { actual_out.steal_mem(B); } } //! @} armadillo-6.500.5/include/armadillo_bits/SpGlue_meat.hpp0000666000000000000000000000200712620272703021663 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup SpGlue //! @{ template inline SpGlue::SpGlue(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { arma_extra_debug_sigprint(); } template inline SpGlue::SpGlue(const T1& in_A, const T2& in_B, const typename T1::elem_type in_aux) : A(in_A) , B(in_B) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline SpGlue::~SpGlue() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_qr.hpp0000666000000000000000000000320312620272703020562 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_qr //! @{ //! QR decomposition template inline bool qr ( Mat& Q, Mat& R, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( (&Q == &R), "qr(): Q and R are the same object"); const bool status = auxlib::qr(Q, R, X); if(status == false) { Q.reset(); R.reset(); arma_debug_warn("qr(): decomposition failed"); } return status; } //! economical QR decomposition template inline bool qr_econ ( Mat& Q, Mat& R, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( (&Q == &R), "qr_econ(): Q and R are the same object"); const bool status = auxlib::qr_econ(Q, R, X); if(status == false) { Q.reset(); R.reset(); arma_debug_warn("qr_econ(): decomposition failed"); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/spglue_join_bones.hpp0000666000000000000000000000204512620272703023164 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spglue_join //! @{ class spglue_join_cols { public: template inline static void apply(SpMat& out, const SpGlue& X); template inline static void apply_noalias(SpMat& out, const SpMat& A, const SpMat& B); }; class spglue_join_rows { public: template inline static void apply(SpMat& out, const SpGlue& X); template inline static void apply_noalias(SpMat& out, const SpMat& A, const SpMat& B); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_numel.hpp0000666000000000000000000000247112620272703021266 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_numel //! @{ template inline typename enable_if2< is_arma_type::value, uword >::result numel(const T1& X) { arma_extra_debug_sigprint(); const Proxy P(X); return P.get_n_elem(); } template inline typename enable_if2< is_arma_cube_type::value, uword >::result numel(const T1& X) { arma_extra_debug_sigprint(); const ProxyCube P(X); return P.get_n_elem(); } template inline typename enable_if2< is_arma_sparse_type::value, uword >::result numel(const T1& X) { arma_extra_debug_sigprint(); const SpProxy P(X); return P.get_n_elem(); } template inline uword numel(const field& X) { arma_extra_debug_sigprint(); return X.n_elem; } template inline uword numel(const subview_field& X) { arma_extra_debug_sigprint(); return X.n_elem; } //! @} armadillo-6.500.5/include/armadillo_bits/Glue_meat.hpp0000666000000000000000000000175612620272703021372 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Glue //! @{ template inline Glue::Glue(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { arma_extra_debug_sigprint(); } template inline Glue::Glue(const T1& in_A, const T2& in_B, const uword in_aux_uword) : A(in_A) , B(in_B) , aux_uword(in_aux_uword) { arma_extra_debug_sigprint(); } template inline Glue::~Glue() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/typedef_mat.hpp0000666000000000000000000000567312620272703021773 0ustar rootroot// Copyright (C) 2008-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup typedef_mat //! @{ typedef Mat uchar_mat; typedef Col uchar_vec; typedef Col uchar_colvec; typedef Row uchar_rowvec; typedef Cube uchar_cube; typedef Mat u32_mat; typedef Col u32_vec; typedef Col u32_colvec; typedef Row u32_rowvec; typedef Cube u32_cube; typedef Mat s32_mat; typedef Col s32_vec; typedef Col s32_colvec; typedef Row s32_rowvec; typedef Cube s32_cube; #if defined(ARMA_USE_U64S64) typedef Mat u64_mat; typedef Col u64_vec; typedef Col u64_colvec; typedef Row u64_rowvec; typedef Cube u64_cube; typedef Mat s64_mat; typedef Col s64_vec; typedef Col s64_colvec; typedef Row s64_rowvec; typedef Cube s64_cube; #endif typedef Mat umat; typedef Col uvec; typedef Col ucolvec; typedef Row urowvec; typedef Cube ucube; typedef Mat imat; typedef Col ivec; typedef Col icolvec; typedef Row irowvec; typedef Cube icube; typedef Mat fmat; typedef Col fvec; typedef Col fcolvec; typedef Row frowvec; typedef Cube fcube; typedef Mat mat; typedef Col vec; typedef Col colvec; typedef Row rowvec; typedef Cube cube; typedef Mat cx_fmat; typedef Col cx_fvec; typedef Col cx_fcolvec; typedef Row cx_frowvec; typedef Cube cx_fcube; typedef Mat cx_mat; typedef Col cx_vec; typedef Col cx_colvec; typedef Row cx_rowvec; typedef Cube cx_cube; typedef SpMat sp_umat; typedef SpCol sp_uvec; typedef SpCol sp_ucolvec; typedef SpRow sp_urowvec; typedef SpMat sp_imat; typedef SpCol sp_ivec; typedef SpCol sp_icolvec; typedef SpRow sp_irowvec; typedef SpMat sp_fmat; typedef SpCol sp_fvec; typedef SpCol sp_fcolvec; typedef SpRow sp_frowvec; typedef SpMat sp_mat; typedef SpCol sp_vec; typedef SpCol sp_colvec; typedef SpRow sp_rowvec; typedef SpMat sp_cx_fmat; typedef SpCol sp_cx_fvec; typedef SpCol sp_cx_fcolvec; typedef SpRow sp_cx_frowvec; typedef SpMat sp_cx_mat; typedef SpCol sp_cx_vec; typedef SpCol sp_cx_colvec; typedef SpRow sp_cx_rowvec; //! @} armadillo-6.500.5/include/armadillo_bits/SpRow_bones.hpp0000666000000000000000000000455212620272703021725 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin // Written by Matthew Amidon //! \addtogroup SpRow //! @{ //! Class for sparse row vectors (sparse matrices with only one row) template class SpRow : public SpMat { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = true; static const bool is_col = false; inline SpRow(); inline explicit SpRow(const uword N); inline SpRow(const uword in_rows, const uword in_cols); inline SpRow(const char* text); inline const SpRow& operator=(const char* text); inline SpRow(const std::string& text); inline const SpRow& operator=(const std::string& text); inline const SpRow& operator=(const eT val); template inline SpRow(const Base& X); template inline const SpRow& operator=(const Base& X); template inline SpRow(const SpBase& X); template inline const SpRow& operator=(const SpBase& X); template inline explicit SpRow(const SpBase& A, const SpBase& B); inline void shed_col (const uword col_num); inline void shed_cols(const uword in_col1, const uword in_col2); // inline void insert_cols(const uword col_num, const uword N, const bool set_to_zero = true); typedef typename SpMat::iterator row_iterator; typedef typename SpMat::const_iterator const_row_iterator; inline row_iterator begin_row(const uword row_num = 0); inline const_row_iterator begin_row(const uword row_num = 0) const; inline row_iterator end_row(const uword row_num = 0); inline const_row_iterator end_row(const uword row_num = 0) const; #ifdef ARMA_EXTRA_SPROW_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPROW_PROTO) #endif }; //! @} armadillo-6.500.5/include/armadillo_bits/op_misc_meat.hpp0000666000000000000000000002062512620272703022123 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_misc //! @{ template inline void op_real::apply( Mat& out, const mtOp& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); out.set_size(n_rows, n_cols); T* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::real( A[i] ); } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { *out_mem = std::real( P.at(row,col) ); out_mem++; } } } template inline void op_real::apply( Cube& out, const mtOpCube& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const ProxyCube P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_slices = P.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); T* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::real( A[i] ); } } else { for(uword slice=0; slice < n_slices; ++slice) for(uword col=0; col < n_cols; ++col ) for(uword row=0; row < n_rows; ++row ) { *out_mem = std::real( P.at(row,col,slice) ); out_mem++; } } } template inline void op_imag::apply( Mat& out, const mtOp& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); out.set_size(n_rows, n_cols); T* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::imag( A[i] ); } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { *out_mem = std::imag( P.at(row,col) ); out_mem++; } } } template inline void op_imag::apply( Cube& out, const mtOpCube& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const ProxyCube P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_slices = P.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); T* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::imag( A[i] ); } } else { for(uword slice=0; slice < n_slices; ++slice) for(uword col=0; col < n_cols; ++col ) for(uword row=0; row < n_rows; ++row ) { *out_mem = std::imag( P.at(row,col,slice) ); out_mem++; } } } template inline void op_abs::apply( Mat& out, const mtOp& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); out.set_size(n_rows, n_cols); T* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::abs( A[i] ); } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { *out_mem = std::abs( P.at(row,col) ); out_mem++; } } } template inline void op_abs::apply( Cube& out, const mtOpCube& X ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const ProxyCube P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_slices = P.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); T* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; const uword n_elem = P.get_n_elem(); ea_type A = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::abs( A[i] ); } } else { for(uword slice=0; slice < n_slices; ++slice) for(uword col=0; col < n_cols; ++col ) for(uword row=0; row < n_rows; ++row ) { *out_mem = std::abs( P.at(row,col,slice) ); out_mem++; } } } template inline void op_orth::apply( Mat& out, const Op& expr ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; T tol = access::tmp_real(expr.aux); arma_debug_check((tol < T(0)), "orth(): tolerance must be >= 0"); const unwrap tmp(expr.m); const Mat& X = tmp.M; Mat U; Col< T> s; Mat V; const bool status = auxlib::svd_dc(U, s, V, X); V.reset(); if(status == false) { out.reset(); arma_bad("orth(): svd failed"); return; } if(s.is_empty()) { out.reset(); return; } const uword s_n_elem = s.n_elem; const T* s_mem = s.memptr(); // set tolerance to default if it hasn't been specified if(tol == T(0)) { tol = (std::max)(X.n_rows, X.n_cols) * s_mem[0] * std::numeric_limits::epsilon(); } uword count = 0; for(uword i=0; i < s_n_elem; ++i) { count += (s_mem[i] > tol) ? uword(1) : uword(0); } if(count > 0) { out = U.head_cols(count); // out *= eT(-1); } else { out.set_size(X.n_rows, 0); } } template inline void op_null::apply( Mat& out, const Op& expr ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; T tol = access::tmp_real(expr.aux); arma_debug_check((tol < T(0)), "null(): tolerance must be >= 0"); const unwrap tmp(expr.m); const Mat& X = tmp.M; Mat U; Col< T> s; Mat V; const bool status = auxlib::svd_dc(U, s, V, X); U.reset(); if(status == false) { out.reset(); arma_bad("null(): svd failed"); return; } if(s.is_empty()) { out.reset(); return; } const uword s_n_elem = s.n_elem; const T* s_mem = s.memptr(); // set tolerance to default if it hasn't been specified if(tol == T(0)) { tol = (std::max)(X.n_rows, X.n_cols) * s_mem[0] * std::numeric_limits::epsilon(); } uword count = 0; for(uword i=0; i < s_n_elem; ++i) { count += (s_mem[i] > tol) ? uword(1) : uword(0); } if(count < X.n_cols) { out = V.tail_cols(X.n_cols - count); const uword out_n_elem = out.n_elem; eT* out_mem = out.memptr(); for(uword i=0; i::epsilon()) { out_mem[i] = eT(0); } } } else { out.set_size(X.n_cols, 0); } } //! @} armadillo-6.500.5/include/armadillo_bits/operator_cube_schur.hpp0000666000000000000000000000540712620272703023522 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup operator_cube_schur //! @{ // operator %, which we define it to do a schur product (element-wise multiplication) //! element-wise multiplication of BaseCube objects with same element type template arma_inline const eGlueCube operator% ( const BaseCube& X, const BaseCube& Y ) { arma_extra_debug_sigprint(); return eGlueCube(X.get_ref(), Y.get_ref()); } //! element-wise multiplication of BaseCube objects with different element types template inline const mtGlueCube::result, T1, T2, glue_mixed_schur> operator% ( const BaseCube< typename force_different_type::T1_result, T1>& X, const BaseCube< typename force_different_type::T2_result, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template arma_inline Cube operator% ( const subview_cube_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_cube_each1_aux::operator_schur(X, Y.get_ref()); } template arma_inline Cube operator% ( const Base& X, const subview_cube_each1& Y ) { arma_extra_debug_sigprint(); return subview_cube_each1_aux::operator_schur(Y, X.get_ref()); // NOTE: swapped order } template arma_inline Cube operator% ( const subview_cube_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_cube_each2_aux::operator_schur(X, Y.get_ref()); } template arma_inline Cube operator% ( const Base& X, const subview_cube_each2& Y ) { arma_extra_debug_sigprint(); return subview_cube_each2_aux::operator_schur(Y, X.get_ref()); // NOTE: swapped order } //! @} armadillo-6.500.5/include/armadillo_bits/Row_bones.hpp0000666000000000000000000002173112620272703021420 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Row //! @{ //! Class for row vectors (matrices with only one row) template class Row : public Mat { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = false; static const bool is_row = true; inline Row(); inline Row(const Row& X); inline explicit Row(const uword N); inline explicit Row(const uword in_rows, const uword in_cols); inline explicit Row(const SizeMat& s); template inline Row(const uword n_elem, const fill::fill_class& f); template inline Row(const uword in_rows, const uword in_cols, const fill::fill_class& f); template inline Row(const SizeMat& s, const fill::fill_class& f); inline Row(const char* text); inline const Row& operator=(const char* text); inline Row(const std::string& text); inline const Row& operator=(const std::string& text); inline Row(const std::vector& x); inline const Row& operator=(const std::vector& x); #if defined(ARMA_USE_CXX11) inline Row(const std::initializer_list& list); inline const Row& operator=(const std::initializer_list& list); inline Row(Row&& m); inline const Row& operator=(Row&& m); #endif inline explicit Row(const SpRow& X); inline const Row& operator=(const eT val); inline const Row& operator=(const Row& X); template inline Row(const Base& X); template inline const Row& operator=(const Base& X); inline Row( eT* aux_mem, const uword aux_length, const bool copy_aux_mem = true, const bool strict = false); inline Row(const eT* aux_mem, const uword aux_length); template inline explicit Row(const Base& A, const Base& B); template inline Row(const BaseCube& X); template inline const Row& operator=(const BaseCube& X); inline Row(const subview_cube& X); inline const Row& operator=(const subview_cube& X); inline mat_injector operator<<(const eT val); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; arma_inline subview_row col(const uword col_num); arma_inline const subview_row col(const uword col_num) const; using Mat::cols; using Mat::operator(); arma_inline subview_row cols(const uword in_col1, const uword in_col2); arma_inline const subview_row cols(const uword in_col1, const uword in_col2) const; arma_inline subview_row subvec(const uword in_col1, const uword in_col2); arma_inline const subview_row subvec(const uword in_col1, const uword in_col2) const; arma_inline subview_row cols(const span& col_span); arma_inline const subview_row cols(const span& col_span) const; arma_inline subview_row subvec(const span& col_span); arma_inline const subview_row subvec(const span& col_span) const; arma_inline subview_row operator()(const span& col_span); arma_inline const subview_row operator()(const span& col_span) const; arma_inline subview_row head(const uword N); arma_inline const subview_row head(const uword N) const; arma_inline subview_row tail(const uword N); arma_inline const subview_row tail(const uword N) const; arma_inline subview_row head_cols(const uword N); arma_inline const subview_row head_cols(const uword N) const; arma_inline subview_row tail_cols(const uword N); arma_inline const subview_row tail_cols(const uword N) const; inline void shed_col (const uword col_num); inline void shed_cols(const uword in_col1, const uword in_col2); inline void insert_cols(const uword col_num, const uword N, const bool set_to_zero = true); template inline void insert_cols(const uword col_num, const Base& X); arma_inline arma_warn_unused eT& at(const uword i); arma_inline arma_warn_unused const eT& at(const uword i) const; arma_inline arma_warn_unused eT& at(const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at(const uword in_row, const uword in_col) const; typedef eT* row_iterator; typedef const eT* const_row_iterator; inline row_iterator begin_row(const uword row_num); inline const_row_iterator begin_row(const uword row_num) const; inline row_iterator end_row (const uword row_num); inline const_row_iterator end_row (const uword row_num) const; template class fixed; protected: inline Row(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem); public: #ifdef ARMA_EXTRA_ROW_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_ROW_PROTO) #endif }; template template class Row::fixed : public Row { private: static const bool use_extra = (fixed_n_elem > arma_config::mat_prealloc); arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; public: typedef fixed Row_fixed_type; typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = false; static const bool is_row = true; static const uword n_rows = 1; static const uword n_cols = fixed_n_elem; static const uword n_elem = fixed_n_elem; arma_inline fixed(); arma_inline fixed(const fixed& X); inline fixed(const subview_cube& X); template inline fixed(const fill::fill_class& f); template inline fixed(const Base& A); template inline fixed(const Base& A, const Base& B); inline fixed(const eT* aux_mem); inline fixed(const char* text); inline fixed(const std::string& text); template inline const Row& operator=(const Base& A); inline const Row& operator=(const eT val); inline const Row& operator=(const char* text); inline const Row& operator=(const std::string& text); inline const Row& operator=(const subview_cube& X); using Row::operator(); #if defined(ARMA_USE_CXX11) inline fixed(const std::initializer_list& list); inline const Row& operator=(const std::initializer_list& list); #endif arma_inline const Row& operator=(const fixed& X); #if defined(ARMA_GOOD_COMPILER) template inline const Row& operator=(const eOp& X); template inline const Row& operator=(const eGlue& X); #endif arma_inline const Op< Row_fixed_type, op_htrans > t() const; arma_inline const Op< Row_fixed_type, op_htrans > ht() const; arma_inline const Op< Row_fixed_type, op_strans > st() const; arma_inline arma_warn_unused const eT& at_alt (const uword i) const; arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at (const uword i); arma_inline arma_warn_unused const eT& at (const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; arma_hot inline const Row& fill(const eT val); arma_hot inline const Row& zeros(); arma_hot inline const Row& ones(); }; //! @} armadillo-6.500.5/include/armadillo_bits/glue_toeplitz_meat.hpp0000666000000000000000000000302112620272703023347 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_toeplitz //! @{ template inline void glue_toeplitz::apply(Mat& out, const Glue& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp1(in.A, out); const unwrap_check tmp2(in.B, out); const Mat& A = tmp1.M; const Mat& B = tmp2.M; arma_debug_check ( ( ((A.is_vec() == false) && (A.is_empty() == false)) || ((B.is_vec() == false) && (B.is_empty() == false)) ), "toeplitz(): given object is not a vector" ); const uword A_N = A.n_elem; const uword B_N = B.n_elem; const eT* A_mem = A.memptr(); const eT* B_mem = B.memptr(); out.set_size(A_N, B_N); if( out.is_empty() ) { return; } for(uword col=0; col < B_N; ++col) { eT* col_mem = out.colptr(col); uword i = 0; for(uword row=col; row < A_N; ++row, ++i) { col_mem[row] = A_mem[i]; } } for(uword row=0; row < A_N; ++row) { uword i = 1; for(uword col=(row+1); col < B_N; ++col, ++i) { out.at(row,col) = B_mem[i]; } } } //! @} armadillo-6.500.5/include/armadillo_bits/auxlib_meat.hpp0000666000000000000000000033766012656144025021774 0ustar rootroot// Copyright (C) 2008-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by James Sanders // Written by Stanislav Funiak // Written by Eric Jon Sundstrom // Written by Michael McNeil Forbes // Written by Keith O'Hara //! \addtogroup auxlib //! @{ //! matrix inverse template inline bool auxlib::inv(Mat& out, const Base& X) { arma_extra_debug_sigprint(); out = X.get_ref(); arma_debug_check( (out.is_square() == false), "inv(): given matrix must be square sized" ); const uword N = out.n_rows; if(N <= 4) { Mat tmp(N,N); const bool status = auxlib::inv_noalias_tinymat(tmp, out, N); if(status == true) { arrayops::copy( out.memptr(), tmp.memptr(), tmp.n_elem ); return true; } } return auxlib::inv_inplace_lapack(out); } template inline bool auxlib::inv(Mat& out, const Mat& X) { arma_extra_debug_sigprint(); arma_debug_check( (X.is_square() == false), "inv(): given matrix must be square sized" ); const uword N = X.n_rows; if(N <= 4) { if(&out != &X) { out.set_size(N,N); const bool status = auxlib::inv_noalias_tinymat(out, X, N); if(status == true) { return true; } } else { Mat tmp(N,N); const bool status = auxlib::inv_noalias_tinymat(tmp, X, N); if(status == true) { arrayops::copy( out.memptr(), tmp.memptr(), tmp.n_elem ); return true; } } } out = X; return auxlib::inv_inplace_lapack(out); } template inline bool auxlib::inv_noalias_tinymat(Mat& out, const Mat& X, const uword N) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const T det_min = std::numeric_limits::epsilon(); bool calc_ok = false; const eT* Xm = X.memptr(); eT* outm = out.memptr(); // NOTE: the output matrix is assumed to have the correct size switch(N) { case 1: { outm[0] = eT(1) / Xm[0]; calc_ok = true; }; break; case 2: { const eT a = Xm[pos<0,0>::n2]; const eT b = Xm[pos<0,1>::n2]; const eT c = Xm[pos<1,0>::n2]; const eT d = Xm[pos<1,1>::n2]; const eT det_val = (a*d - b*c); if(std::abs(det_val) >= det_min) { outm[pos<0,0>::n2] = d / det_val; outm[pos<0,1>::n2] = -b / det_val; outm[pos<1,0>::n2] = -c / det_val; outm[pos<1,1>::n2] = a / det_val; calc_ok = true; } }; break; case 3: { const eT det_val = auxlib::det_tinymat(X,3); if(std::abs(det_val) >= det_min) { outm[pos<0,0>::n3] = (Xm[pos<2,2>::n3]*Xm[pos<1,1>::n3] - Xm[pos<2,1>::n3]*Xm[pos<1,2>::n3]) / det_val; outm[pos<1,0>::n3] = -(Xm[pos<2,2>::n3]*Xm[pos<1,0>::n3] - Xm[pos<2,0>::n3]*Xm[pos<1,2>::n3]) / det_val; outm[pos<2,0>::n3] = (Xm[pos<2,1>::n3]*Xm[pos<1,0>::n3] - Xm[pos<2,0>::n3]*Xm[pos<1,1>::n3]) / det_val; outm[pos<0,1>::n3] = -(Xm[pos<2,2>::n3]*Xm[pos<0,1>::n3] - Xm[pos<2,1>::n3]*Xm[pos<0,2>::n3]) / det_val; outm[pos<1,1>::n3] = (Xm[pos<2,2>::n3]*Xm[pos<0,0>::n3] - Xm[pos<2,0>::n3]*Xm[pos<0,2>::n3]) / det_val; outm[pos<2,1>::n3] = -(Xm[pos<2,1>::n3]*Xm[pos<0,0>::n3] - Xm[pos<2,0>::n3]*Xm[pos<0,1>::n3]) / det_val; outm[pos<0,2>::n3] = (Xm[pos<1,2>::n3]*Xm[pos<0,1>::n3] - Xm[pos<1,1>::n3]*Xm[pos<0,2>::n3]) / det_val; outm[pos<1,2>::n3] = -(Xm[pos<1,2>::n3]*Xm[pos<0,0>::n3] - Xm[pos<1,0>::n3]*Xm[pos<0,2>::n3]) / det_val; outm[pos<2,2>::n3] = (Xm[pos<1,1>::n3]*Xm[pos<0,0>::n3] - Xm[pos<1,0>::n3]*Xm[pos<0,1>::n3]) / det_val; const eT check_val = Xm[pos<0,0>::n3]*outm[pos<0,0>::n3] + Xm[pos<0,1>::n3]*outm[pos<1,0>::n3] + Xm[pos<0,2>::n3]*outm[pos<2,0>::n3]; const T max_diff = (is_float::value) ? T(1e-4) : T(1e-10); // empirically determined; may need tuning if(std::abs(T(1) - check_val) < max_diff) { calc_ok = true; } } }; break; case 4: { const eT det_val = auxlib::det_tinymat(X,4); if(std::abs(det_val) >= det_min) { outm[pos<0,0>::n4] = ( Xm[pos<1,2>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<1,3>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,1>::n4] + Xm[pos<1,3>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,2>::n4] - Xm[pos<1,1>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,2>::n4] - Xm[pos<1,2>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,3>::n4] + Xm[pos<1,1>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<1,0>::n4] = ( Xm[pos<1,3>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,2>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,3>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,2>::n4] + Xm[pos<1,0>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,2>::n4] + Xm[pos<1,2>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,3>::n4] - Xm[pos<1,0>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<2,0>::n4] = ( Xm[pos<1,1>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,3>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,0>::n4] + Xm[pos<1,3>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,1>::n4] - Xm[pos<1,0>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<1,1>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,3>::n4] + Xm[pos<1,0>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<3,0>::n4] = ( Xm[pos<1,2>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,1>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<1,2>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,1>::n4] + Xm[pos<1,0>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,1>::n4] + Xm[pos<1,1>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,2>::n4] - Xm[pos<1,0>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,2>::n4] ) / det_val; outm[pos<0,1>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,2>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,3>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,1>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,2>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,3>::n4] - Xm[pos<0,1>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<1,1>::n4] = ( Xm[pos<0,2>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,0>::n4] + Xm[pos<0,3>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,0>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,2>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,3>::n4] + Xm[pos<0,0>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<2,1>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,1>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,0>::n4]*Xm[pos<2,3>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,1>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,3>::n4] - Xm[pos<0,0>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<3,1>::n4] = ( Xm[pos<0,1>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,2>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,0>::n4] + Xm[pos<0,2>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,0>::n4]*Xm[pos<2,2>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,1>::n4]*Xm[pos<2,0>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,0>::n4]*Xm[pos<2,1>::n4]*Xm[pos<3,2>::n4] ) / det_val; outm[pos<0,2>::n4] = ( Xm[pos<0,2>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,3>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,3>::n4] + Xm[pos<0,1>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<1,2>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,2>::n4] + Xm[pos<0,2>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,3>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<2,2>::n4] = ( Xm[pos<0,1>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,0>::n4] + Xm[pos<0,3>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,3>::n4]*Xm[pos<3,1>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,3>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,3>::n4] ) / det_val; outm[pos<3,2>::n4] = ( Xm[pos<0,2>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,0>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,2>::n4]*Xm[pos<3,1>::n4] + Xm[pos<0,1>::n4]*Xm[pos<1,0>::n4]*Xm[pos<3,2>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,1>::n4]*Xm[pos<3,2>::n4] ) / det_val; outm[pos<0,3>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,1>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,1>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,2>::n4] + Xm[pos<0,1>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,2>::n4] + Xm[pos<0,2>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,3>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,3>::n4] ) / det_val; outm[pos<1,3>::n4] = ( Xm[pos<0,2>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,0>::n4] + Xm[pos<0,3>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,2>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,2>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,3>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,3>::n4] ) / det_val; outm[pos<2,3>::n4] = ( Xm[pos<0,3>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,0>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,0>::n4] - Xm[pos<0,3>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,1>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,3>::n4]*Xm[pos<2,1>::n4] + Xm[pos<0,1>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,3>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,3>::n4] ) / det_val; outm[pos<3,3>::n4] = ( Xm[pos<0,1>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,0>::n4] - Xm[pos<0,2>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,0>::n4] + Xm[pos<0,2>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,1>::n4] - Xm[pos<0,0>::n4]*Xm[pos<1,2>::n4]*Xm[pos<2,1>::n4] - Xm[pos<0,1>::n4]*Xm[pos<1,0>::n4]*Xm[pos<2,2>::n4] + Xm[pos<0,0>::n4]*Xm[pos<1,1>::n4]*Xm[pos<2,2>::n4] ) / det_val; const eT check_val = Xm[pos<0,0>::n4]*outm[pos<0,0>::n4] + Xm[pos<0,1>::n4]*outm[pos<1,0>::n4] + Xm[pos<0,2>::n4]*outm[pos<2,0>::n4] + Xm[pos<0,3>::n4]*outm[pos<3,0>::n4]; const T max_diff = (is_float::value) ? T(1e-4) : T(1e-10); // empirically determined; may need tuning if(std::abs(T(1) - check_val) < max_diff) { calc_ok = true; } } }; break; default: ; } return calc_ok; } template inline bool auxlib::inv_inplace_lapack(Mat& out) { arma_extra_debug_sigprint(); if(out.is_empty()) { return true; } #if defined(ARMA_USE_ATLAS) { arma_debug_assert_atlas_size(out); podarray ipiv(out.n_rows); int info = 0; arma_extra_debug_print("atlas::clapack_getrf()"); info = atlas::clapack_getrf(atlas::CblasColMajor, out.n_rows, out.n_cols, out.memptr(), out.n_rows, ipiv.memptr()); if(info != 0) { return false; } arma_extra_debug_print("atlas::clapack_getri()"); info = atlas::clapack_getri(atlas::CblasColMajor, out.n_rows, out.memptr(), out.n_rows, ipiv.memptr()); return (info == 0); } #elif defined(ARMA_USE_LAPACK) { arma_debug_assert_blas_size(out); blas_int n_rows = out.n_rows; blas_int lwork = (std::max)(blas_int(podarray_prealloc_n_elem::val), n_rows); blas_int info = 0; podarray ipiv(out.n_rows); if(n_rows > 16) { eT work_query[2]; blas_int lwork_query = -1; arma_extra_debug_print("lapack::getri()"); lapack::getri(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), &work_query[0], &lwork_query, &info); if(info != 0) { return false; } blas_int lwork_proposed = static_cast( access::tmp_real(work_query[0]) ); lwork = (std::max)(lwork_proposed, lwork); } podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::getrf()"); lapack::getrf(&n_rows, &n_rows, out.memptr(), &n_rows, ipiv.memptr(), &info); if(info != 0) { return false; } arma_extra_debug_print("lapack::getri()"); lapack::getri(&n_rows, out.memptr(), &n_rows, ipiv.memptr(), work.memptr(), &lwork, &info); return (info == 0); } #else { arma_stop("inv(): use of ATLAS or LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::inv_tr(Mat& out, const Base& X, const uword layout) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { out = X.get_ref(); arma_debug_check( (out.is_square() == false), "inv(): given matrix must be square sized" ); if(out.is_empty()) { return true; } arma_debug_assert_blas_size(out); char uplo = (layout == 0) ? 'U' : 'L'; char diag = 'N'; blas_int n = blas_int(out.n_rows); blas_int info = 0; arma_extra_debug_print("lapack::trtri()"); lapack::trtri(&uplo, &diag, &n, out.memptr(), &n, &info); if(layout == 0) { out = trimatu(out); // upper triangular } else { out = trimatl(out); // lower triangular } return (info == 0); } #else { arma_ignore(out); arma_ignore(X); arma_ignore(layout); arma_stop("inv(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::inv_sym(Mat& out, const Base& X, const uword layout) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { out = X.get_ref(); arma_debug_check( (out.is_square() == false), "inv(): given matrix must be square sized" ); if(out.is_empty()) { return true; } arma_debug_assert_blas_size(out); char uplo = (layout == 0) ? 'U' : 'L'; blas_int n = blas_int(out.n_rows); blas_int lwork = (std::max)(blas_int(podarray_prealloc_n_elem::val), 2*n); blas_int info = 0; podarray ipiv; ipiv.set_size(out.n_rows); podarray work; work.set_size( uword(lwork) ); arma_extra_debug_print("lapack::sytrf()"); lapack::sytrf(&uplo, &n, out.memptr(), &n, ipiv.memptr(), work.memptr(), &lwork, &info); if(info != 0) { return false; } arma_extra_debug_print("lapack::sytri()"); lapack::sytri(&uplo, &n, out.memptr(), &n, ipiv.memptr(), work.memptr(), &info); if(layout == 0) { out = symmatu(out); } else { out = symmatl(out); } return (info == 0); } #else { arma_ignore(out); arma_ignore(X); arma_ignore(layout); arma_stop("inv(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::inv_sympd(Mat& out, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { out = X.get_ref(); arma_debug_check( (out.is_square() == false), "inv_sympd(): given matrix must be square sized" ); if(out.is_empty()) { return true; } arma_debug_assert_blas_size(out); char uplo = 'L'; blas_int n = blas_int(out.n_rows); blas_int info = 0; arma_extra_debug_print("lapack::potrf()"); lapack::potrf(&uplo, &n, out.memptr(), &n, &info); if(info != 0) { return false; } arma_extra_debug_print("lapack::potri()"); lapack::potri(&uplo, &n, out.memptr(), &n, &info); out = symmatl(out); return (info == 0); } #else { arma_ignore(out); arma_ignore(X); arma_stop("inv_sympd(): use of LAPACK must be enabled"); return false; } #endif } template inline eT auxlib::det(const Base& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const bool make_copy = (is_Mat::value) ? true : false; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; arma_debug_check( (A.is_square() == false), "det(): given matrix must be square sized" ); const uword N = A.n_rows; if(N <= 4) { const eT det_val = auxlib::det_tinymat(A, N); const T det_min = std::numeric_limits::epsilon(); if(std::abs(det_val) >= det_min) { return det_val; } } return auxlib::det_lapack(A, make_copy); } template inline eT auxlib::det_tinymat(const Mat& X, const uword N) { arma_extra_debug_sigprint(); switch(N) { case 0: return eT(1); break; case 1: return X[0]; break; case 2: { const eT* Xm = X.memptr(); return ( Xm[pos<0,0>::n2]*Xm[pos<1,1>::n2] - Xm[pos<0,1>::n2]*Xm[pos<1,0>::n2] ); } break; case 3: { // const double tmp1 = X.at(0,0) * X.at(1,1) * X.at(2,2); // const double tmp2 = X.at(0,1) * X.at(1,2) * X.at(2,0); // const double tmp3 = X.at(0,2) * X.at(1,0) * X.at(2,1); // const double tmp4 = X.at(2,0) * X.at(1,1) * X.at(0,2); // const double tmp5 = X.at(2,1) * X.at(1,2) * X.at(0,0); // const double tmp6 = X.at(2,2) * X.at(1,0) * X.at(0,1); // return (tmp1+tmp2+tmp3) - (tmp4+tmp5+tmp6); const eT* Xm = X.memptr(); const eT val1 = Xm[pos<0,0>::n3]*(Xm[pos<2,2>::n3]*Xm[pos<1,1>::n3] - Xm[pos<2,1>::n3]*Xm[pos<1,2>::n3]); const eT val2 = Xm[pos<1,0>::n3]*(Xm[pos<2,2>::n3]*Xm[pos<0,1>::n3] - Xm[pos<2,1>::n3]*Xm[pos<0,2>::n3]); const eT val3 = Xm[pos<2,0>::n3]*(Xm[pos<1,2>::n3]*Xm[pos<0,1>::n3] - Xm[pos<1,1>::n3]*Xm[pos<0,2>::n3]); return ( val1 - val2 + val3 ); } break; case 4: { const eT* Xm = X.memptr(); const eT val = \ Xm[pos<0,3>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,0>::n4] \ - Xm[pos<0,2>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,0>::n4] \ - Xm[pos<0,3>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,0>::n4] \ + Xm[pos<0,1>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,0>::n4] \ + Xm[pos<0,2>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,0>::n4] \ - Xm[pos<0,1>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,0>::n4] \ - Xm[pos<0,3>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,1>::n4] \ + Xm[pos<0,2>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,1>::n4] \ + Xm[pos<0,3>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,1>::n4] \ - Xm[pos<0,0>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,1>::n4] \ - Xm[pos<0,2>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,1>::n4] \ + Xm[pos<0,0>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,1>::n4] \ + Xm[pos<0,3>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,2>::n4] \ - Xm[pos<0,1>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,2>::n4] \ - Xm[pos<0,3>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,2>::n4] \ + Xm[pos<0,0>::n4] * Xm[pos<1,3>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,2>::n4] \ + Xm[pos<0,1>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,2>::n4] \ - Xm[pos<0,0>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,3>::n4] * Xm[pos<3,2>::n4] \ - Xm[pos<0,2>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,3>::n4] \ + Xm[pos<0,1>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,0>::n4] * Xm[pos<3,3>::n4] \ + Xm[pos<0,2>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,3>::n4] \ - Xm[pos<0,0>::n4] * Xm[pos<1,2>::n4] * Xm[pos<2,1>::n4] * Xm[pos<3,3>::n4] \ - Xm[pos<0,1>::n4] * Xm[pos<1,0>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,3>::n4] \ + Xm[pos<0,0>::n4] * Xm[pos<1,1>::n4] * Xm[pos<2,2>::n4] * Xm[pos<3,3>::n4] \ ; return val; } break; default: return eT(0); ; } } //! determinant of a matrix template inline eT auxlib::det_lapack(const Mat& X, const bool make_copy) { arma_extra_debug_sigprint(); Mat X_copy; if(make_copy) { X_copy = X; } Mat& tmp = (make_copy) ? X_copy : const_cast< Mat& >(X); if(tmp.is_empty()) { return eT(1); } #if defined(ARMA_USE_ATLAS) { arma_debug_assert_atlas_size(tmp); podarray ipiv(tmp.n_rows); arma_extra_debug_print("atlas::clapack_getrf()"); //const int info = atlas::clapack_getrf(atlas::CblasColMajor, tmp.n_rows, tmp.n_cols, tmp.memptr(), tmp.n_rows, ipiv.memptr()); // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero eT val = tmp.at(0,0); for(uword i=1; i < tmp.n_rows; ++i) { val *= tmp.at(i,i); } int sign = +1; for(uword i=0; i < tmp.n_rows; ++i) { if( int(i) != ipiv.mem[i] ) // NOTE: no adjustment required, as the clapack version of getrf() assumes counting from 0 { sign *= -1; } } return ( (sign < 0) ? -val : val ); } #elif defined(ARMA_USE_LAPACK) { arma_debug_assert_blas_size(tmp); podarray ipiv(tmp.n_rows); blas_int info = 0; blas_int n_rows = blas_int(tmp.n_rows); blas_int n_cols = blas_int(tmp.n_cols); arma_extra_debug_print("lapack::getrf()"); lapack::getrf(&n_rows, &n_cols, tmp.memptr(), &n_rows, ipiv.memptr(), &info); // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero eT val = tmp.at(0,0); for(uword i=1; i < tmp.n_rows; ++i) { val *= tmp.at(i,i); } blas_int sign = +1; for(uword i=0; i < tmp.n_rows; ++i) { if( blas_int(i) != (ipiv.mem[i] - 1) ) // NOTE: adjustment of -1 is required as Fortran counts from 1 { sign *= -1; } } return ( (sign < 0) ? -val : val ); } #else { arma_stop("det(): use of ATLAS or LAPACK must be enabled"); return eT(0); } #endif } //! log determinant of a matrix template inline bool auxlib::log_det(eT& out_val, typename get_pod_type::result& out_sign, const Base& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; #if defined(ARMA_USE_ATLAS) { Mat tmp(X.get_ref()); arma_debug_check( (tmp.is_square() == false), "log_det(): given matrix must be square sized" ); if(tmp.is_empty()) { out_val = eT(0); out_sign = T(1); return true; } arma_debug_assert_atlas_size(tmp); podarray ipiv(tmp.n_rows); arma_extra_debug_print("atlas::clapack_getrf()"); const int info = atlas::clapack_getrf(atlas::CblasColMajor, tmp.n_rows, tmp.n_cols, tmp.memptr(), tmp.n_rows, ipiv.memptr()); // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero sword sign = (is_complex::value == false) ? ( (access::tmp_real( tmp.at(0,0) ) < T(0)) ? -1 : +1 ) : +1; eT val = (is_complex::value == false) ? std::log( (access::tmp_real( tmp.at(0,0) ) < T(0)) ? tmp.at(0,0)*T(-1) : tmp.at(0,0) ) : std::log( tmp.at(0,0) ); for(uword i=1; i < tmp.n_rows; ++i) { const eT x = tmp.at(i,i); sign *= (is_complex::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1; val += (is_complex::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x); } for(uword i=0; i < tmp.n_rows; ++i) { if( int(i) != ipiv.mem[i] ) // NOTE: no adjustment required, as the clapack version of getrf() assumes counting from 0 { sign *= -1; } } out_val = val; out_sign = T(sign); return (info == 0); } #elif defined(ARMA_USE_LAPACK) { Mat tmp(X.get_ref()); arma_debug_check( (tmp.is_square() == false), "log_det(): given matrix must be square sized" ); if(tmp.is_empty()) { out_val = eT(0); out_sign = T(1); return true; } arma_debug_assert_blas_size(tmp); podarray ipiv(tmp.n_rows); blas_int info = 0; blas_int n_rows = blas_int(tmp.n_rows); blas_int n_cols = blas_int(tmp.n_cols); arma_extra_debug_print("lapack::getrf()"); lapack::getrf(&n_rows, &n_cols, tmp.memptr(), &n_rows, ipiv.memptr(), &info); // on output tmp appears to be L+U_alt, where U_alt is U with the main diagonal set to zero sword sign = (is_complex::value == false) ? ( (access::tmp_real( tmp.at(0,0) ) < T(0)) ? -1 : +1 ) : +1; eT val = (is_complex::value == false) ? std::log( (access::tmp_real( tmp.at(0,0) ) < T(0)) ? tmp.at(0,0)*T(-1) : tmp.at(0,0) ) : std::log( tmp.at(0,0) ); for(uword i=1; i < tmp.n_rows; ++i) { const eT x = tmp.at(i,i); sign *= (is_complex::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1; val += (is_complex::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x); } for(uword i=0; i < tmp.n_rows; ++i) { if( blas_int(i) != (ipiv.mem[i] - 1) ) // NOTE: adjustment of -1 is required as Fortran counts from 1 { sign *= -1; } } out_val = val; out_sign = T(sign); return (info == 0); } #else { arma_ignore(X); out_val = eT(0); out_sign = T(0); arma_stop("log_det(): use of ATLAS or LAPACK must be enabled"); return false; } #endif } //! LU decomposition of a matrix template inline bool auxlib::lu(Mat& L, Mat& U, podarray& ipiv, const Base& X) { arma_extra_debug_sigprint(); U = X.get_ref(); const uword U_n_rows = U.n_rows; const uword U_n_cols = U.n_cols; if(U.is_empty()) { L.set_size(U_n_rows, 0); U.set_size(0, U_n_cols); ipiv.reset(); return true; } #if defined(ARMA_USE_ATLAS) || defined(ARMA_USE_LAPACK) { bool status = false; #if defined(ARMA_USE_ATLAS) { arma_debug_assert_atlas_size(U); ipiv.set_size( (std::min)(U_n_rows, U_n_cols) ); arma_extra_debug_print("atlas::clapack_getrf()"); int info = atlas::clapack_getrf(atlas::CblasColMajor, U_n_rows, U_n_cols, U.memptr(), U_n_rows, ipiv.memptr()); status = (info == 0); } #elif defined(ARMA_USE_LAPACK) { arma_debug_assert_blas_size(U); ipiv.set_size( (std::min)(U_n_rows, U_n_cols) ); blas_int info = 0; blas_int n_rows = blas_int(U_n_rows); blas_int n_cols = blas_int(U_n_cols); arma_extra_debug_print("lapack::getrf()"); lapack::getrf(&n_rows, &n_cols, U.memptr(), &n_rows, ipiv.memptr(), &info); // take into account that Fortran counts from 1 arrayops::inplace_minus(ipiv.memptr(), blas_int(1), ipiv.n_elem); status = (info == 0); } #endif L.copy_size(U); for(uword col=0; col < U_n_cols; ++col) { for(uword row=0; (row < col) && (row < U_n_rows); ++row) { L.at(row,col) = eT(0); } if( L.in_range(col,col) == true ) { L.at(col,col) = eT(1); } for(uword row = (col+1); row < U_n_rows; ++row) { L.at(row,col) = U.at(row,col); U.at(row,col) = eT(0); } } return status; } #else { arma_stop("lu(): use of ATLAS or LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::lu(Mat& L, Mat& U, Mat& P, const Base& X) { arma_extra_debug_sigprint(); podarray ipiv1; const bool status = auxlib::lu(L, U, ipiv1, X); if(status == false) { return false; } if(U.is_empty()) { // L and U have been already set to the correct empty matrices P.eye(L.n_rows, L.n_rows); return true; } const uword n = ipiv1.n_elem; const uword P_rows = U.n_rows; podarray ipiv2(P_rows); const blas_int* ipiv1_mem = ipiv1.memptr(); blas_int* ipiv2_mem = ipiv2.memptr(); for(uword i=0; i(ipiv1_mem[i]); if( ipiv2_mem[i] != ipiv2_mem[k] ) { std::swap( ipiv2_mem[i], ipiv2_mem[k] ); } } P.zeros(P_rows, P_rows); for(uword row=0; row(ipiv2_mem[row])) = eT(1); } if(L.n_cols > U.n_rows) { L.shed_cols(U.n_rows, L.n_cols-1); } if(U.n_rows > L.n_cols) { U.shed_rows(L.n_cols, U.n_rows-1); } return true; } template inline bool auxlib::lu(Mat& L, Mat& U, const Base& X) { arma_extra_debug_sigprint(); podarray ipiv1; const bool status = auxlib::lu(L, U, ipiv1, X); if(status == false) { return false; } if(U.is_empty()) { // L and U have been already set to the correct empty matrices return true; } const uword n = ipiv1.n_elem; const uword P_rows = U.n_rows; podarray ipiv2(P_rows); const blas_int* ipiv1_mem = ipiv1.memptr(); blas_int* ipiv2_mem = ipiv2.memptr(); for(uword i=0; i(ipiv1_mem[i]); if( ipiv2_mem[i] != ipiv2_mem[k] ) { std::swap( ipiv2_mem[i], ipiv2_mem[k] ); L.swap_rows( static_cast(ipiv2_mem[i]), static_cast(ipiv2_mem[k]) ); } } if(L.n_cols > U.n_rows) { L.shed_cols(U.n_rows, L.n_cols-1); } if(U.n_rows > L.n_cols) { U.shed_rows(L.n_cols, U.n_rows-1); } return true; } //! eigen decomposition of general square matrix (real) template inline bool auxlib::eig_gen ( Mat< std::complex >& vals, Mat< std::complex >& vecs, const bool vecs_on, const Base& expr ) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename T1::pod_type T; Mat X = expr.get_ref(); arma_debug_check( (X.is_square() == false), "eig_gen(): given matrix must be square sized" ); arma_debug_assert_blas_size(X); if(X.is_empty()) { vals.reset(); vecs.reset(); return true; } if(X.is_finite() == false) { return false; } vals.set_size(X.n_rows, 1); Mat tmp(1,1); if(vecs_on) { vecs.set_size(X.n_rows, X.n_rows); tmp.set_size(X.n_rows, X.n_rows); } podarray junk(1); char jobvl = 'N'; char jobvr = (vecs_on) ? 'V' : 'N'; blas_int N = blas_int(X.n_rows); T* vl = junk.memptr(); T* vr = (vecs_on) ? tmp.memptr() : junk.memptr(); blas_int ldvl = blas_int(1); blas_int ldvr = (vecs_on) ? blas_int(tmp.n_rows) : blas_int(1); blas_int lwork = (vecs_on) ? (3 * ((std::max)(blas_int(1), 4*N)) ) : (3 * ((std::max)(blas_int(1), 3*N)) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray vals_real(X.n_rows); podarray vals_imag(X.n_rows); arma_extra_debug_print("lapack::geev() -- START"); lapack::geev(&jobvl, &jobvr, &N, X.memptr(), &N, vals_real.memptr(), vals_imag.memptr(), vl, &ldvl, vr, &ldvr, work.memptr(), &lwork, &info); arma_extra_debug_print("lapack::geev() -- END"); if(info != 0) { return false; } arma_extra_debug_print("reformatting eigenvalues and eigenvectors"); std::complex* vals_mem = vals.memptr(); for(uword i=0; i < X.n_rows; ++i) { vals_mem[i] = std::complex(vals_real[i], vals_imag[i]); } if(vecs_on) { for(uword j=0; j < X.n_rows; ++j) { if( (j < (X.n_rows-1)) && (vals_mem[j] == std::conj(vals_mem[j+1])) ) { for(uword i=0; i < X.n_rows; ++i) { vecs.at(i,j) = std::complex( tmp.at(i,j), tmp.at(i,j+1) ); vecs.at(i,j+1) = std::complex( tmp.at(i,j), -tmp.at(i,j+1) ); } ++j; } else { for(uword i=0; i(tmp.at(i,j), T(0)); } } } } return true; } #else { arma_ignore(vals); arma_ignore(vecs); arma_ignore(vecs_on); arma_ignore(expr); arma_stop("eig_gen(): use of LAPACK must be enabled"); return false; } #endif } //! eigen decomposition of general square matrix (complex) template inline bool auxlib::eig_gen ( Mat< std::complex >& vals, Mat< std::complex >& vecs, const bool vecs_on, const Base< std::complex, T1 >& expr ) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename T1::pod_type T; typedef typename std::complex eT; Mat X = expr.get_ref(); arma_debug_check( (X.is_square() == false), "eig_gen(): given matrix must be square sized" ); arma_debug_assert_blas_size(X); if(X.is_empty()) { vals.reset(); vecs.reset(); return true; } if(X.is_finite() == false) { return false; } vals.set_size(X.n_rows, 1); if(vecs_on) { vecs.set_size(X.n_rows, X.n_rows); } podarray junk(1); char jobvl = 'N'; char jobvr = (vecs_on) ? 'V' : 'N'; blas_int N = blas_int(X.n_rows); eT* vl = junk.memptr(); eT* vr = (vecs_on) ? vecs.memptr() : junk.memptr(); blas_int ldvl = blas_int(1); blas_int ldvr = (vecs_on) ? blas_int(vecs.n_rows) : blas_int(1); blas_int lwork = 3 * ((std::max)(blas_int(1), 2*N)); blas_int info = 0; podarray work( static_cast(lwork) ); podarray< T> rwork( static_cast(2*N) ); arma_extra_debug_print("lapack::cx_geev() -- START"); lapack::cx_geev(&jobvl, &jobvr, &N, X.memptr(), &N, vals.memptr(), vl, &ldvl, vr, &ldvr, work.memptr(), &lwork, rwork.memptr(), &info); arma_extra_debug_print("lapack::cx_geev() -- END"); return (info == 0); } #else { arma_ignore(vals); arma_ignore(vecs); arma_ignore(vecs_on); arma_ignore(expr); arma_stop("eig_gen(): use of LAPACK must be enabled"); return false; } #endif } //! eigendecomposition of general square real matrix pair (real) template inline bool auxlib::eig_pair ( Mat< std::complex >& vals, Mat< std::complex >& vecs, const bool vecs_on, const Base& A_expr, const Base& B_expr ) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename T1::pod_type T; typedef std::complex eT; Mat A(A_expr.get_ref()); Mat B(B_expr.get_ref()); arma_debug_check( ((A.is_square() == false) || (B.is_square() == false)), "eig_pair(): given matrices must be square sized" ); arma_debug_check( (A.n_rows != B.n_rows), "eig_pair(): given matrices must have the same size" ); arma_debug_assert_blas_size(A); if(A.is_empty()) { vals.reset(); vecs.reset(); return true; } if(A.is_finite() == false) { return false; } if(B.is_finite() == false) { return false; } vals.set_size(A.n_rows, 1); Mat tmp(1,1); if(vecs_on) { vecs.set_size(A.n_rows, A.n_rows); tmp.set_size(A.n_rows, A.n_rows); } podarray junk(1); char jobvl = 'N'; char jobvr = (vecs_on) ? 'V' : 'N'; blas_int N = blas_int(A.n_rows); T* vl = junk.memptr(); T* vr = (vecs_on) ? tmp.memptr() : junk.memptr(); blas_int ldvl = blas_int(1); blas_int ldvr = (vecs_on) ? blas_int(tmp.n_rows) : blas_int(1); blas_int lwork = 3 * ((std::max)(blas_int(1), 8*N)); blas_int info = 0; podarray alphar(A.n_rows); podarray alphai(A.n_rows); podarray beta(A.n_rows); podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::ggev()"); lapack::ggev(&jobvl, &jobvr, &N, A.memptr(), &N, B.memptr(), &N, alphar.memptr(), alphai.memptr(), beta.memptr(), vl, &ldvl, vr, &ldvr, work.memptr(), &lwork, &info); if(info != 0) { return false; } arma_extra_debug_print("reformatting eigenvalues and eigenvectors"); eT* vals_mem = vals.memptr(); const T* alphar_mem = alphar.memptr(); const T* alphai_mem = alphai.memptr(); const T* beta_mem = beta.memptr(); bool beta_has_zero = false; for(uword j=0; j(re, im); if( (alphai_val > T(0)) && (j < (A.n_rows-1)) ) { ++j; vals_mem[j] = std::complex(re,-im); // force exact conjugate } } if(beta_has_zero) { arma_debug_warn("eig_pair(): given matrices appear ill-conditioned"); } if(vecs_on) { for(uword j=0; j( tmp.at(i,j), tmp.at(i,j+1) ); vecs.at(i,j+1) = std::complex( tmp.at(i,j), -tmp.at(i,j+1) ); } ++j; } else { for(uword i=0; i(tmp.at(i,j), T(0)); } } } } return true; } #else { arma_ignore(vals); arma_ignore(vecs); arma_ignore(vecs_on); arma_ignore(A_expr); arma_ignore(B_expr); arma_stop("eig_pair(): use of LAPACK must be enabled"); return false; } #endif } //! eigendecomposition of general square real matrix pair (complex) template inline bool auxlib::eig_pair ( Mat< std::complex >& vals, Mat< std::complex >& vecs, const bool vecs_on, const Base< std::complex, T1 >& A_expr, const Base< std::complex, T2 >& B_expr ) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_CRIPPLED_LAPACK)) { arma_ignore(vals); arma_ignore(vecs); arma_ignore(vecs_on); arma_ignore(A_expr); arma_ignore(B_expr); arma_stop("eig_pair() for complex matrices not available due to crippled LAPACK"); return false; } #elif defined(ARMA_USE_LAPACK) { typedef typename T1::pod_type T; typedef typename std::complex eT; Mat A(A_expr.get_ref()); Mat B(B_expr.get_ref()); arma_debug_check( ((A.is_square() == false) || (B.is_square() == false)), "eig_pair(): given matrices must be square sized" ); arma_debug_check( (A.n_rows != B.n_rows), "eig_pair(): given matrices must have the same size" ); arma_debug_assert_blas_size(A); if(A.is_empty()) { vals.reset(); vecs.reset(); return true; } if(A.is_finite() == false) { return false; } if(B.is_finite() == false) { return false; } vals.set_size(A.n_rows, 1); if(vecs_on) { vecs.set_size(A.n_rows, A.n_rows); } podarray junk(1); char jobvl = 'N'; char jobvr = (vecs_on) ? 'V' : 'N'; blas_int N = blas_int(A.n_rows); eT* vl = junk.memptr(); eT* vr = (vecs_on) ? vecs.memptr() : junk.memptr(); blas_int ldvl = blas_int(1); blas_int ldvr = (vecs_on) ? blas_int(vecs.n_rows) : blas_int(1); blas_int lwork = 3 * ((std::max)(blas_int(1),2*N)); blas_int info = 0; podarray alpha(A.n_rows); podarray beta(A.n_rows); podarray work( static_cast(lwork) ); podarray rwork( static_cast(8*N) ); arma_extra_debug_print("lapack::cx_ggev()"); lapack::cx_ggev(&jobvl, &jobvr, &N, A.memptr(), &N, B.memptr(), &N, alpha.memptr(), beta.memptr(), vl, &ldvl, vr, &ldvr, work.memptr(), &lwork, rwork.memptr(), &info); if(info != 0) { return false; } eT* vals_mem = vals.memptr(); const eT* alpha_mem = alpha.memptr(); const eT* beta_mem = beta.memptr(); const std::complex zero(T(0), T(0)); bool beta_has_zero = false; for(uword i=0; i inline bool auxlib::eig_sym(Col& eigval, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix must be square sized" ); if(A.is_empty()) { eigval.reset(); return true; } arma_debug_assert_blas_size(A); eigval.set_size(A.n_rows); char jobz = 'N'; char uplo = 'U'; blas_int N = blas_int(A.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 3*N-1) ); blas_int info = 0; podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::syev()"); lapack::syev(&jobz, &uplo, &N, A.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK must be enabled"); return false; } #endif } //! eigenvalues of a hermitian complex matrix template inline bool auxlib::eig_sym(Col& eigval, const Base,T1>& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename std::complex eT; Mat A(X.get_ref()); arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix must be square sized" ); if(A.is_empty()) { eigval.reset(); return true; } arma_debug_assert_blas_size(A); eigval.set_size(A.n_rows); char jobz = 'N'; char uplo = 'U'; blas_int N = blas_int(A.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*N-1) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray rwork( static_cast( (std::max)(blas_int(1), 3*N-2) ) ); arma_extra_debug_print("lapack::heev()"); lapack::heev(&jobz, &uplo, &N, A.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, rwork.memptr(), &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK must be enabled"); return false; } #endif } //! eigenvalues and eigenvectors of a symmetric real matrix template inline bool auxlib::eig_sym(Col& eigval, Mat& eigvec, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { eigvec = X.get_ref(); arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matrix must be square sized" ); if(eigvec.is_empty()) { eigval.reset(); eigvec.reset(); return true; } arma_debug_assert_blas_size(eigvec); eigval.set_size(eigvec.n_rows); char jobz = 'V'; char uplo = 'U'; blas_int N = blas_int(eigvec.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 3*N-1) ); blas_int info = 0; podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::syev()"); lapack::syev(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK must be enabled"); return false; } #endif } //! eigenvalues and eigenvectors of a hermitian complex matrix template inline bool auxlib::eig_sym(Col& eigval, Mat< std::complex >& eigvec, const Base,T1>& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename std::complex eT; eigvec = X.get_ref(); arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matrix must be square sized" ); if(eigvec.is_empty()) { eigval.reset(); eigvec.reset(); return true; } arma_debug_assert_blas_size(eigvec); eigval.set_size(eigvec.n_rows); char jobz = 'V'; char uplo = 'U'; blas_int N = blas_int(eigvec.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*N-1) ); blas_int info = 0; podarray work( static_cast(lwork) ); podarray rwork( static_cast((std::max)(blas_int(1), 3*N-2)) ); arma_extra_debug_print("lapack::heev()"); lapack::heev(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, rwork.memptr(), &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK must be enabled"); return false; } #endif } //! eigenvalues and eigenvectors of a symmetric real matrix (divide and conquer algorithm) template inline bool auxlib::eig_sym_dc(Col& eigval, Mat& eigvec, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { eigvec = X.get_ref(); arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matrix must be square sized" ); if(eigvec.is_empty()) { eigval.reset(); eigvec.reset(); return true; } arma_debug_assert_blas_size(eigvec); eigval.set_size(eigvec.n_rows); char jobz = 'V'; char uplo = 'U'; blas_int N = blas_int(eigvec.n_rows); blas_int lwork = 2 * (1 + 6*N + 2*(N*N)); blas_int liwork = 3 * (3 + 5*N); blas_int info = 0; podarray work( static_cast( lwork) ); podarray iwork( static_cast(liwork) ); arma_extra_debug_print("lapack::syevd()"); lapack::syevd(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, iwork.memptr(), &liwork, &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK must be enabled"); return false; } #endif } //! eigenvalues and eigenvectors of a hermitian complex matrix (divide and conquer algorithm) template inline bool auxlib::eig_sym_dc(Col& eigval, Mat< std::complex >& eigvec, const Base,T1>& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename std::complex eT; eigvec = X.get_ref(); arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matrix must be square sized" ); if(eigvec.is_empty()) { eigval.reset(); eigvec.reset(); return true; } arma_debug_assert_blas_size(eigvec); eigval.set_size(eigvec.n_rows); char jobz = 'V'; char uplo = 'U'; blas_int N = blas_int(eigvec.n_rows); blas_int lwork = 2 * (2*N + N*N); blas_int lrwork = 2 * (1 + 5*N + 2*(N*N)); blas_int liwork = 3 * (3 + 5*N); blas_int info = 0; podarray work( static_cast(lwork) ); podarray rwork( static_cast(lrwork) ); podarray iwork( static_cast(liwork) ); arma_extra_debug_print("lapack::heevd()"); lapack::heevd(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), work.memptr(), &lwork, rwork.memptr(), &lrwork, iwork.memptr(), &liwork, &info); return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_stop("eig_sym(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::chol(Mat& out, const Base& X, const uword layout) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { out = X.get_ref(); arma_debug_check( (out.is_square() == false), "chol(): given matrix must be square sized" ); if(out.is_empty()) { return true; } arma_debug_assert_blas_size(out); const uword out_n_rows = out.n_rows; char uplo = (layout == 0) ? 'U' : 'L'; blas_int n = out_n_rows; blas_int info = 0; arma_extra_debug_print("lapack::potrf()"); lapack::potrf(&uplo, &n, out.memptr(), &n, &info); if(layout == 0) { for(uword col=0; col < out_n_rows; ++col) { eT* colptr = out.colptr(col); for(uword row=(col+1); row < out_n_rows; ++row) { colptr[row] = eT(0); } } } else { for(uword col=1; col < out_n_rows; ++col) { eT* colptr = out.colptr(col); for(uword row=0; row < col; ++row) { colptr[row] = eT(0); } } } return (info == 0); } #else { arma_ignore(out); arma_ignore(X); arma_ignore(layout); arma_stop("chol(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::qr(Mat& Q, Mat& R, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { R = X.get_ref(); const uword R_n_rows = R.n_rows; const uword R_n_cols = R.n_cols; if(R.is_empty()) { Q.eye(R_n_rows, R_n_rows); return true; } arma_debug_assert_blas_size(R); blas_int m = static_cast(R_n_rows); blas_int n = static_cast(R_n_cols); blas_int lwork = 0; blas_int lwork_min = (std::max)(blas_int(1), (std::max)(m,n)); // take into account requirements of geqrf() _and_ orgqr()/ungqr() blas_int k = (std::min)(m,n); blas_int info = 0; podarray tau( static_cast(k) ); eT work_query[2]; blas_int lwork_query = -1; arma_extra_debug_print("lapack::geqrf()"); lapack::geqrf(&m, &n, R.memptr(), &m, tau.memptr(), &work_query[0], &lwork_query, &info); if(info != 0) { return false; } blas_int lwork_proposed = static_cast( access::tmp_real(work_query[0]) ); lwork = (std::max)(lwork_proposed, lwork_min); podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::geqrf()"); lapack::geqrf(&m, &n, R.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); if(info != 0) { return false; } Q.set_size(R_n_rows, R_n_rows); arrayops::copy( Q.memptr(), R.memptr(), (std::min)(Q.n_elem, R.n_elem) ); // // construct R for(uword col=0; col < R_n_cols; ++col) { for(uword row=(col+1); row < R_n_rows; ++row) { R.at(row,col) = eT(0); } } if( (is_float::value) || (is_double::value) ) { arma_extra_debug_print("lapack::orgqr()"); lapack::orgqr(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); } else if( (is_supported_complex_float::value) || (is_supported_complex_double::value) ) { arma_extra_debug_print("lapack::ungqr()"); lapack::ungqr(&m, &m, &k, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); } return (info == 0); } #else { arma_ignore(Q); arma_ignore(R); arma_ignore(X); arma_stop("qr(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::qr_econ(Mat& Q, Mat& R, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { if(is_Mat::value) { const unwrap tmp(X.get_ref()); const Mat& M = tmp.M; if(M.n_rows < M.n_cols) { return auxlib::qr(Q, R, X); } } Q = X.get_ref(); const uword Q_n_rows = Q.n_rows; const uword Q_n_cols = Q.n_cols; if( Q_n_rows <= Q_n_cols ) { return auxlib::qr(Q, R, Q); } if(Q.is_empty()) { Q.set_size(Q_n_rows, 0 ); R.set_size(0, Q_n_cols); return true; } arma_debug_assert_blas_size(Q); blas_int m = static_cast(Q_n_rows); blas_int n = static_cast(Q_n_cols); blas_int lwork = 0; blas_int lwork_min = (std::max)(blas_int(1), (std::max)(m,n)); // take into account requirements of geqrf() _and_ orgqr()/ungqr() blas_int k = (std::min)(m,n); blas_int info = 0; podarray tau( static_cast(k) ); eT work_query[2]; blas_int lwork_query = -1; arma_extra_debug_print("lapack::geqrf()"); lapack::geqrf(&m, &n, Q.memptr(), &m, tau.memptr(), &work_query[0], &lwork_query, &info); if(info != 0) { return false; } blas_int lwork_proposed = static_cast( access::tmp_real(work_query[0]) ); lwork = (std::max)(lwork_proposed, lwork_min); podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::geqrf()"); lapack::geqrf(&m, &n, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); if(info != 0) { return false; } R.set_size(Q_n_cols, Q_n_cols); // // construct R for(uword col=0; col < Q_n_cols; ++col) { for(uword row=0; row <= col; ++row) { R.at(row,col) = Q.at(row,col); } for(uword row=(col+1); row < Q_n_cols; ++row) { R.at(row,col) = eT(0); } } if( (is_float::value) || (is_double::value) ) { arma_extra_debug_print("lapack::orgqr()"); lapack::orgqr(&m, &n, &k, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); } else if( (is_supported_complex_float::value) || (is_supported_complex_double::value) ) { arma_extra_debug_print("lapack::ungqr()"); lapack::ungqr(&m, &n, &k, Q.memptr(), &m, tau.memptr(), work.memptr(), &lwork, &info); } return (info == 0); } #else { arma_ignore(Q); arma_ignore(R); arma_ignore(X); arma_stop("qr_econ(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd(Col& S, const Base& X, uword& X_n_rows, uword& X_n_cols) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); X_n_rows = A.n_rows; X_n_cols = A.n_cols; if(A.is_empty()) { S.reset(); return true; } arma_debug_assert_blas_size(A); Mat U(1, 1); Mat V(1, A.n_cols); char jobu = 'N'; char jobvt = 'N'; blas_int m = A.n_rows; blas_int n = A.n_cols; blas_int min_mn = (std::min)(m,n); blas_int lda = A.n_rows; blas_int ldu = U.n_rows; blas_int ldvt = V.n_rows; blas_int lwork = 0; blas_int lwork_min = (std::max)( blas_int(1), (std::max)( (3*min_mn + (std::max)(m,n)), 5*min_mn ) ); blas_int info = 0; S.set_size( static_cast(min_mn) ); eT work_query[2]; blas_int lwork_query = -1; arma_extra_debug_print("lapack::gesvd()"); lapack::gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, &work_query[0], &lwork_query, &info); if(info != 0) { return false; } blas_int lwork_proposed = static_cast( work_query[0] ); lwork = (std::max)(lwork_proposed, lwork_min); podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::gesvd()"); lapack::gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, &info); return (info == 0); } #else { arma_ignore(S); arma_ignore(X); arma_ignore(X_n_rows); arma_ignore(X_n_cols); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd(Col& S, const Base, T1>& X, uword& X_n_rows, uword& X_n_cols) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); X_n_rows = A.n_rows; X_n_cols = A.n_cols; if(A.is_empty()) { S.reset(); return true; } arma_debug_assert_blas_size(A); Mat U(1, 1); Mat V(1, A.n_cols); char jobu = 'N'; char jobvt = 'N'; blas_int m = A.n_rows; blas_int n = A.n_cols; blas_int min_mn = (std::min)(m,n); blas_int lda = A.n_rows; blas_int ldu = U.n_rows; blas_int ldvt = V.n_rows; blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*min_mn+(std::max)(m,n) ) ); blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray< T> rwork( static_cast(5*min_mn) ); blas_int lwork_tmp = -1; // let gesvd_() calculate the optimum size of the workspace arma_extra_debug_print("lapack::cx_gesvd()"); lapack::cx_gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork_tmp, rwork.memptr(), &info); if(info != 0) { return false; } blas_int proposed_lwork = static_cast(real(work[0])); if(proposed_lwork > lwork) { lwork = proposed_lwork; work.set_size( static_cast(lwork) ); } arma_extra_debug_print("lapack::cx_gesvd()"); lapack::cx_gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), &info); return (info == 0); } #else { arma_ignore(S); arma_ignore(X); arma_ignore(X_n_rows); arma_ignore(X_n_cols); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd(Col& S, const Base& X) { arma_extra_debug_sigprint(); uword junk; return auxlib::svd(S, X, junk, junk); } template inline bool auxlib::svd(Col& S, const Base, T1>& X) { arma_extra_debug_sigprint(); uword junk; return auxlib::svd(S, X, junk, junk); } template inline bool auxlib::svd(Mat& U, Col& S, Mat& V, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); S.reset(); V.eye(A.n_cols, A.n_cols); return true; } arma_debug_assert_blas_size(A); U.set_size(A.n_rows, A.n_rows); V.set_size(A.n_cols, A.n_cols); char jobu = 'A'; char jobvt = 'A'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork_min = (std::max)( blas_int(1), (std::max)( (3*min_mn + (std::max)(m,n)), 5*min_mn ) ); blas_int lwork = 0; blas_int info = 0; S.set_size( static_cast(min_mn) ); // let gesvd_() calculate the optimum size of the workspace eT work_query[2]; blas_int lwork_query = -1; arma_extra_debug_print("lapack::gesvd()"); lapack::gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, &work_query[0], &lwork_query, &info); if(info != 0) { return false; } blas_int lwork_proposed = static_cast( work_query[0] ); lwork = (std::max)(lwork_proposed, lwork_min); podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::gesvd()"); lapack::gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, &info); op_strans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); S.reset(); V.eye(A.n_cols, A.n_cols); return true; } arma_debug_assert_blas_size(A); U.set_size(A.n_rows, A.n_rows); V.set_size(A.n_cols, A.n_cols); char jobu = 'A'; char jobvt = 'A'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork = 3 * ( (std::max)(blas_int(1), 2*min_mn + (std::max)(m,n) ) ); blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray rwork( static_cast(5*min_mn) ); blas_int lwork_tmp = -1; // let gesvd_() calculate the optimum size of the workspace arma_extra_debug_print("lapack::cx_gesvd()"); lapack::cx_gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork_tmp, rwork.memptr(), &info); if(info != 0) { return false; } blas_int proposed_lwork = static_cast(real(work[0])); if(proposed_lwork > lwork) { lwork = proposed_lwork; work.set_size( static_cast(lwork) ); } arma_extra_debug_print("lapack::cx_gesvd()"); lapack::cx_gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), &info); op_htrans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd_econ(Mat& U, Col& S, Mat& V, const Base& X, const char mode) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); if(A.is_empty()) { U.eye(); S.reset(); V.eye(); return true; } arma_debug_assert_blas_size(A); blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); S.set_size( static_cast(min_mn) ); blas_int ldu = 0; blas_int ldvt = 0; char jobu = char(0); char jobvt = char(0); if(mode == 'l') { jobu = 'S'; jobvt = 'N'; ldu = m; ldvt = 1; U.set_size( static_cast(ldu), static_cast(min_mn) ); V.reset(); } if(mode == 'r') { jobu = 'N'; jobvt = 'S'; ldu = 1; ldvt = (std::min)(m,n); U.reset(); V.set_size( static_cast(ldvt), static_cast(n) ); } if(mode == 'b') { jobu = 'S'; jobvt = 'S'; ldu = m; ldvt = (std::min)(m,n); U.set_size( static_cast(ldu), static_cast(min_mn) ); V.set_size( static_cast(ldvt), static_cast(n ) ); } blas_int lwork = 3 * ( (std::max)(blas_int(1), (std::max)( (3*min_mn + (std::max)(m,n)), 5*min_mn ) ) ); blas_int info = 0; podarray work( static_cast(lwork) ); blas_int lwork_tmp = -1; // let gesvd_() calculate the optimum size of the workspace arma_extra_debug_print("lapack::gesvd()"); lapack::gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork_tmp, &info); if(info != 0) { return false; } blas_int proposed_lwork = static_cast(work[0]); if(proposed_lwork > lwork) { lwork = proposed_lwork; work.set_size( static_cast(lwork) ); } arma_extra_debug_print("lapack::gesvd()"); lapack::gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, &info); op_strans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_ignore(mode); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd_econ(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X, const char mode) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); if(A.is_empty()) { U.eye(); S.reset(); V.eye(); return true; } arma_debug_assert_blas_size(A); blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); S.set_size( static_cast(min_mn) ); blas_int ldu = 0; blas_int ldvt = 0; char jobu = char(0); char jobvt = char(0); if(mode == 'l') { jobu = 'S'; jobvt = 'N'; ldu = m; ldvt = 1; U.set_size( static_cast(ldu), static_cast(min_mn) ); V.reset(); } if(mode == 'r') { jobu = 'N'; jobvt = 'S'; ldu = 1; ldvt = (std::min)(m,n); U.reset(); V.set_size( static_cast(ldvt), static_cast(n) ); } if(mode == 'b') { jobu = 'S'; jobvt = 'S'; ldu = m; ldvt = (std::min)(m,n); U.set_size( static_cast(ldu), static_cast(min_mn) ); V.set_size( static_cast(ldvt), static_cast(n) ); } blas_int lwork = 3 * ( (std::max)(blas_int(1), (std::max)( (3*min_mn + (std::max)(m,n)), 5*min_mn ) ) ); blas_int info = 0; podarray work( static_cast(lwork ) ); podarray rwork( static_cast(5*min_mn) ); blas_int lwork_tmp = -1; // let gesvd_() calculate the optimum size of the workspace arma_extra_debug_print("lapack::cx_gesvd()"); lapack::cx_gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork_tmp, rwork.memptr(), &info); if(info != 0) { return false; } blas_int proposed_lwork = static_cast(real(work[0])); if(proposed_lwork > lwork) { lwork = proposed_lwork; work.set_size( static_cast(lwork) ); } arma_extra_debug_print("lapack::cx_gesvd()"); lapack::cx_gesvd(&jobu, &jobvt, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), &info); op_htrans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_ignore(mode); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd_dc(Col& S, const Base& X, uword& X_n_rows, uword& X_n_cols) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); X_n_rows = A.n_rows; X_n_cols = A.n_cols; if(A.is_empty()) { S.reset(); return true; } arma_debug_assert_blas_size(A); Mat U(1, 1); Mat V(1, 1); char jobz = 'N'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork = 3 * ( 3*min_mn + std::max( std::max(m,n), 7*min_mn ) ); blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray iwork( static_cast(8*min_mn) ); arma_extra_debug_print("lapack::gesdd()"); lapack::gesdd(&jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, iwork.memptr(), &info); return (info == 0); } #else { arma_ignore(S); arma_ignore(X); arma_ignore(X_n_rows); arma_ignore(X_n_cols); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd_dc(Col& S, const Base, T1>& X, uword& X_n_rows, uword& X_n_cols) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_CRIPPLED_LAPACK)) { arma_extra_debug_print("auxlib::svd_dc(): redirecting to auxlib::svd() due to crippled LAPACK"); return auxlib::svd(S, X, X_n_rows, X_n_cols); } #elif defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); X_n_rows = A.n_rows; X_n_cols = A.n_cols; if(A.is_empty()) { S.reset(); return true; } arma_debug_assert_blas_size(A); Mat U(1, 1); Mat V(1, 1); char jobz = 'N'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork = 3 * (2*min_mn + std::max(m,n)); blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray rwork( static_cast(7*min_mn) ); // LAPACK 3.4.2 docs state 5*min(m,n), while zgesdd() seems to write past the end podarray iwork( static_cast(8*min_mn) ); arma_extra_debug_print("lapack::cx_gesdd()"); lapack::cx_gesdd(&jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info); return (info == 0); } #else { arma_ignore(S); arma_ignore(X); arma_ignore(X_n_rows); arma_ignore(X_n_cols); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd_dc(Col& S, const Base& X) { arma_extra_debug_sigprint(); uword junk; return auxlib::svd_dc(S, X, junk, junk); } template inline bool auxlib::svd_dc(Col& S, const Base, T1>& X) { arma_extra_debug_sigprint(); uword junk; return auxlib::svd_dc(S, X, junk, junk); } template inline bool auxlib::svd_dc(Mat& U, Col& S, Mat& V, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); S.reset(); V.eye(A.n_cols, A.n_cols); return true; } arma_debug_assert_blas_size(A); U.set_size(A.n_rows, A.n_rows); V.set_size(A.n_cols, A.n_cols); char jobz = 'A'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int max_mn = (std::max)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork1 = 3*min_mn*min_mn + (std::max)( max_mn, 4*min_mn*min_mn + 4*min_mn ); blas_int lwork2 = 3*min_mn + (std::max)( max_mn, 4*min_mn*min_mn + 3*min_mn + max_mn ); blas_int lwork = 2 * ((std::max)(lwork1, lwork2)); // due to differences between lapack 3.1 and 3.4 blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray iwork( static_cast(8*min_mn) ); arma_extra_debug_print("lapack::gesdd()"); lapack::gesdd(&jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, iwork.memptr(), &info); op_strans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_CRIPPLED_LAPACK)) { arma_extra_debug_print("auxlib::svd_dc(): redirecting to auxlib::svd() due to crippled LAPACK"); return auxlib::svd(U, S, V, X); } #elif defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); if(A.is_empty()) { U.eye(A.n_rows, A.n_rows); S.reset(); V.eye(A.n_cols, A.n_cols); return true; } arma_debug_assert_blas_size(A); U.set_size(A.n_rows, A.n_rows); V.set_size(A.n_cols, A.n_cols); char jobz = 'A'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int max_mn = (std::max)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = blas_int(U.n_rows); blas_int ldvt = blas_int(V.n_rows); blas_int lwork = 2 * (min_mn*min_mn + 2*min_mn + max_mn); blas_int lrwork1 = 5*min_mn*min_mn + 7*min_mn; blas_int lrwork2 = min_mn * ((std::max)(5*min_mn+7, 2*max_mn + 2*min_mn+1)); blas_int lrwork = (std::max)(lrwork1, lrwork2); // due to differences between lapack 3.1 and 3.4 blas_int info = 0; S.set_size( static_cast(min_mn) ); podarray work( static_cast(lwork ) ); podarray rwork( static_cast(lrwork ) ); podarray iwork( static_cast(8*min_mn) ); arma_extra_debug_print("lapack::cx_gesdd()"); lapack::cx_gesdd(&jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info); op_htrans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd_dc_econ(Mat& U, Col& S, Mat& V, const Base& X) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { Mat A(X.get_ref()); arma_debug_assert_blas_size(A); char jobz = 'S'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int max_mn = (std::max)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = m; blas_int ldvt = min_mn; blas_int lwork1 = 3*min_mn*min_mn + (std::max)( max_mn, 4*min_mn*min_mn + 4*min_mn ); blas_int lwork2 = 3*min_mn + (std::max)( max_mn, 4*min_mn*min_mn + 3*min_mn + max_mn ); blas_int lwork = 2 * ((std::max)(lwork1, lwork2)); // due to differences between lapack 3.1 and 3.4 blas_int info = 0; if(A.is_empty()) { U.eye(); S.reset(); V.eye( static_cast(n), static_cast(min_mn) ); return true; } S.set_size( static_cast(min_mn) ); U.set_size( static_cast(m), static_cast(min_mn) ); V.set_size( static_cast(min_mn), static_cast(n) ); podarray work( static_cast(lwork ) ); podarray iwork( static_cast(8*min_mn) ); arma_extra_debug_print("lapack::gesdd()"); lapack::gesdd(&jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, iwork.memptr(), &info); op_strans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::svd_dc_econ(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_CRIPPLED_LAPACK)) { arma_extra_debug_print("auxlib::svd_dc_econ(): redirecting to auxlib::svd_econ() due to crippled LAPACK"); return auxlib::svd_econ(U, S, V, X, 'b'); } #elif defined(ARMA_USE_LAPACK) { typedef std::complex eT; Mat A(X.get_ref()); arma_debug_assert_blas_size(A); char jobz = 'S'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int min_mn = (std::min)(m,n); blas_int max_mn = (std::max)(m,n); blas_int lda = blas_int(A.n_rows); blas_int ldu = m; blas_int ldvt = min_mn; blas_int lwork = 2 * (min_mn*min_mn + 2*min_mn + max_mn); blas_int lrwork1 = 5*min_mn*min_mn + 7*min_mn; blas_int lrwork2 = min_mn * ((std::max)(5*min_mn+7, 2*max_mn + 2*min_mn+1)); blas_int lrwork = (std::max)(lrwork1, lrwork2); // due to differences between lapack 3.1 and 3.4 blas_int info = 0; if(A.is_empty()) { U.eye(); S.reset(); V.eye( static_cast(n), static_cast(min_mn) ); return true; } S.set_size( static_cast(min_mn) ); U.set_size( static_cast(m), static_cast(min_mn) ); V.set_size( static_cast(min_mn), static_cast(n) ); podarray work( static_cast(lwork ) ); podarray rwork( static_cast(lrwork ) ); podarray iwork( static_cast(8*min_mn) ); arma_extra_debug_print("lapack::cx_gesdd()"); lapack::cx_gesdd(&jobz, &m, &n, A.memptr(), &lda, S.memptr(), U.memptr(), &ldu, V.memptr(), &ldvt, work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info); op_htrans::apply_mat_inplace(V); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(V); arma_ignore(X); arma_stop("svd(): use of LAPACK must be enabled"); return false; } #endif } //! solve a system of linear equations via LU decomposition template inline bool auxlib::solve_square_fast(Mat& out, Mat& A, const Base& B_expr) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword A_n_rows = A.n_rows; if(A_n_rows <= 4) { Mat A_inv(A_n_rows, A_n_rows); const bool status = auxlib::inv_noalias_tinymat(A_inv, A, A_n_rows); if(status == true) { const unwrap U(B_expr.get_ref()); const Mat& B = U.M; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in the given matrices must be the same" ); if(A.is_empty() || B.is_empty()) { out.zeros(A.n_cols, B_n_cols); return true; } if(&out != &B) { out.set_size(A_n_rows, B_n_cols); gemm_emul::apply(out, A_inv, B); } else { Mat tmp(A_n_rows, B_n_cols); gemm_emul::apply(tmp, A_inv, B); out.steal_mem(tmp); } return true; } } out = B_expr.get_ref(); const uword B_n_rows = out.n_rows; const uword B_n_cols = out.n_cols; arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in the given matrices must be the same" ); if(A.is_empty() || out.is_empty()) { out.zeros(A.n_cols, B_n_cols); return true; } #if defined(ARMA_USE_ATLAS) { arma_debug_assert_atlas_size(A); podarray ipiv(A_n_rows + 2); // +2 for paranoia: old versions of Atlas might be trashing memory arma_extra_debug_print("atlas::clapack_gesv()"); int info = atlas::clapack_gesv(atlas::CblasColMajor, A_n_rows, B_n_cols, A.memptr(), A_n_rows, ipiv.memptr(), out.memptr(), A_n_rows); return (info == 0); } #elif defined(ARMA_USE_LAPACK) { arma_debug_assert_blas_size(A); blas_int n = blas_int(A_n_rows); // assuming A is square blas_int lda = blas_int(A_n_rows); blas_int ldb = blas_int(A_n_rows); blas_int nrhs = blas_int(B_n_cols); blas_int info = blas_int(0); podarray ipiv(A_n_rows + 2); // +2 for paranoia: some versions of Lapack might be trashing memory arma_extra_debug_print("lapack::gesv()"); lapack::gesv(&n, &nrhs, A.memptr(), &lda, ipiv.memptr(), out.memptr(), &ldb, &info); return (info == 0); } #else { arma_stop("solve(): use of ATLAS or LAPACK must be enabled"); return false; } #endif } //! solve a system of linear equations via LU decomposition with refinement (real matrices) template inline bool auxlib::solve_square_refine(Mat& out, typename T1::pod_type& out_rcond, Mat& A, const Base& B_expr, const bool equilibrate) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename T1::pod_type eT; Mat B = B_expr.get_ref(); // B is overwritten by lapack::gesvx() arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in the given matrices must be the same" ); if(A.is_empty() || B.is_empty()) { out.zeros(A.n_rows, B.n_cols); return true; } arma_debug_assert_blas_size(A,B); out.set_size(A.n_rows, B.n_cols); char fact = (equilibrate) ? 'E' : 'N'; char trans = 'N'; char equed = char(0); blas_int n = blas_int(A.n_rows); blas_int nrhs = blas_int(B.n_cols); blas_int lda = blas_int(A.n_rows); blas_int ldaf = blas_int(A.n_rows); blas_int ldb = blas_int(A.n_rows); blas_int ldx = blas_int(A.n_rows); blas_int info = blas_int(0); eT rcond = eT(0); Mat AF(A.n_rows, A.n_rows); podarray IPIV( A.n_rows); podarray R( A.n_rows); podarray C( A.n_rows); podarray FERR( B.n_cols); podarray BERR( B.n_cols); podarray WORK(4*A.n_rows); podarray IWORK( A.n_rows); arma_extra_debug_print("lapack::gesvx()"); lapack::gesvx ( &fact, &trans, &n, &nrhs, A.memptr(), &lda, AF.memptr(), &ldaf, IPIV.memptr(), &equed, R.memptr(), C.memptr(), B.memptr(), &ldb, out.memptr(), &ldx, &rcond, FERR.memptr(), BERR.memptr(), WORK.memptr(), IWORK.memptr(), &info ); // if(info == (n+1)) { arma_debug_warn("solve(): matrix appears singular to working precision; rcond = ", rcond); } // // const bool singular = ( (info > 0) && (info <= n) ); // // return (singular == false); out_rcond = rcond; return (info == 0); } #else { arma_ignore(out); arma_ignore(out_rcond); arma_ignore(A); arma_ignore(B_expr); arma_stop("solve(): use of LAPACK must be enabled"); return false; } #endif } //! solve a system of linear equations via LU decomposition with refinement (complex matrices) template inline bool auxlib::solve_square_refine(Mat< std::complex >& out, typename T1::pod_type& out_rcond, Mat< std::complex >& A, const Base,T1>& B_expr, const bool equilibrate) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_CRIPPLED_LAPACK)) { arma_ignore(out_rcond); arma_ignore(equilibrate); arma_debug_warn("solve(): refinement and/or equilibration not done due to crippled LAPACK"); return auxlib::solve_square_fast(out, A, B_expr); } #elif defined(ARMA_USE_LAPACK) { typedef typename T1::pod_type T; typedef typename std::complex eT; Mat B = B_expr.get_ref(); // B is overwritten by lapack::cx_gesvx() arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in the given matrices must be the same" ); if(A.is_empty() || B.is_empty()) { out.zeros(A.n_rows, B.n_cols); return true; } arma_debug_assert_blas_size(A,B); out.set_size(A.n_rows, B.n_cols); char fact = (equilibrate) ? 'E' : 'N'; char trans = 'N'; char equed = char(0); blas_int n = blas_int(A.n_rows); blas_int nrhs = blas_int(B.n_cols); blas_int lda = blas_int(A.n_rows); blas_int ldaf = blas_int(A.n_rows); blas_int ldb = blas_int(A.n_rows); blas_int ldx = blas_int(A.n_rows); blas_int info = blas_int(0); T rcond = T(0); Mat AF(A.n_rows, A.n_rows); podarray IPIV( A.n_rows); podarray< T> R( A.n_rows); podarray< T> C( A.n_rows); podarray< T> FERR( B.n_cols); podarray< T> BERR( B.n_cols); podarray WORK(2*A.n_rows); podarray< T> RWORK(2*A.n_rows); arma_extra_debug_print("lapack::cx_gesvx()"); lapack::cx_gesvx ( &fact, &trans, &n, &nrhs, A.memptr(), &lda, AF.memptr(), &ldaf, IPIV.memptr(), &equed, R.memptr(), C.memptr(), B.memptr(), &ldb, out.memptr(), &ldx, &rcond, FERR.memptr(), BERR.memptr(), WORK.memptr(), RWORK.memptr(), &info ); // if(info == (n+1)) { arma_debug_warn("solve(): matrix appears singular to working precision; rcond = ", rcond); } // // const bool singular = ( (info > 0) && (info <= n) ); // // return (singular == false); out_rcond = rcond; return (info == 0); } #else { arma_ignore(out); arma_ignore(out_rcond); arma_ignore(A); arma_ignore(B_expr); arma_stop("solve(): use of LAPACK must be enabled"); return false; } #endif } //! solve a non-square full-rank system via QR or LQ decomposition template inline bool auxlib::solve_approx_fast(Mat& out, Mat& A, const Base& B_expr) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename T1::elem_type eT; const unwrap U(B_expr.get_ref()); const Mat& B = U.M; arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in the given matrices must be the same" ); if(A.is_empty() || B.is_empty()) { out.zeros(A.n_cols, B.n_cols); return true; } arma_debug_assert_blas_size(A,B); Mat tmp( (std::max)(A.n_rows, A.n_cols), B.n_cols ); if(size(tmp) == size(B)) { tmp = B; } else { tmp.zeros(); tmp(0,0, size(B)) = B; } char trans = 'N'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int lda = blas_int(A.n_rows); blas_int ldb = blas_int(tmp.n_rows); blas_int nrhs = blas_int(B.n_cols); blas_int mn = (std::min)(m,n); blas_int lwork = 3 * ( (std::max)(blas_int(1), mn + (std::max)(mn, nrhs)) ); blas_int info = 0; podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::gels()"); lapack::gels( &trans, &m, &n, &nrhs, A.memptr(), &lda, tmp.memptr(), &ldb, work.memptr(), &lwork, &info ); if(info != 0) { return false; } if(tmp.n_rows == A.n_cols) { out.steal_mem(tmp); } else { out = tmp.head_rows(A.n_cols); } return true; } #else { arma_ignore(out); arma_ignore(A); arma_ignore(B_expr); arma_stop("solve(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::solve_approx_svd(Mat& out, Mat& A, const Base& B_expr) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { typedef typename T1::pod_type eT; const unwrap U(B_expr.get_ref()); const Mat& B = U.M; arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in the given matrices must be the same" ); if(A.is_empty() || B.is_empty()) { out.zeros(A.n_cols, B.n_cols); return true; } arma_debug_assert_blas_size(A,B); Mat tmp( (std::max)(A.n_rows, A.n_cols), B.n_cols ); if(size(tmp) == size(B)) { tmp = B; } else { tmp.zeros(); tmp(0,0, size(B)) = B; } blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int nrhs = blas_int(B.n_cols); blas_int lda = blas_int(A.n_rows); blas_int ldb = blas_int(tmp.n_rows); eT rcond = eT(-1); // -1 means "use machine precision" blas_int rank = blas_int(0); blas_int info = blas_int(0); const uword min_mn = (std::min)(A.n_rows, A.n_cols); podarray S(min_mn); blas_int ispec = blas_int(9); const char* const_name = (is_float::value) ? "SGELSD" : "DGELSD"; const char* const_opts = ""; char* name = const_cast(const_name); char* opts = const_cast(const_opts); blas_int n1 = m; blas_int n2 = n; blas_int n3 = nrhs; blas_int n4 = lda; blas_int smlsiz = (std::max)( blas_int(25), lapack::laenv(&ispec, name, opts, &n1, &n2, &n3, &n4) ); // in case lapack::laenv() returns -1 blas_int smlsiz_p1 = blas_int(1) + smlsiz; blas_int nlvl = (std::max)( blas_int(0), blas_int(1) + blas_int( std::log(double(min_mn) / double(smlsiz_p1))/double(0.69314718055994530942) ) ); blas_int liwork = (std::max)( blas_int(1), (blas_int(3)*blas_int(min_mn)*nlvl + blas_int(11)*blas_int(min_mn)) ); podarray iwork( static_cast(liwork) ); eT work_query[2]; blas_int lwork_query = blas_int(-1); arma_extra_debug_print("lapack::gelsd()"); lapack::gelsd(&m, &n, &nrhs, A.memptr(), &lda, tmp.memptr(), &ldb, S.memptr(), &rcond, &rank, &work_query[0], &lwork_query, iwork.memptr(), &info); if(info != 0) { return false; } blas_int lwork = static_cast( access::tmp_real(work_query[0]) ); podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::gelsd()"); lapack::gelsd(&m, &n, &nrhs, A.memptr(), &lda, tmp.memptr(), &ldb, S.memptr(), &rcond, &rank, work.memptr(), &lwork, iwork.memptr(), &info); if(info != 0) { return false; } if(tmp.n_rows == A.n_cols) { out.steal_mem(tmp); } else { out = tmp.head_rows(A.n_cols); } return true; } #else { arma_ignore(out); arma_ignore(A); arma_ignore(B_expr); arma_stop("solve(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::solve_approx_svd(Mat< std::complex >& out, Mat< std::complex >& A, const Base,T1>& B_expr) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_CRIPPLED_LAPACK)) { arma_ignore(out); arma_ignore(A); arma_ignore(B_expr); arma_debug_warn("solve() for rank-deficient matrices not available due to crippled LAPACK"); return false; } #elif defined(ARMA_USE_LAPACK) { typedef typename T1::pod_type T; typedef typename std::complex eT; const unwrap U(B_expr.get_ref()); const Mat& B = U.M; arma_debug_check( (A.n_rows != B.n_rows), "solve(): number of rows in the given matrices must be the same" ); if(A.is_empty() || B.is_empty()) { out.zeros(A.n_cols, B.n_cols); return true; } arma_debug_assert_blas_size(A,B); Mat tmp( (std::max)(A.n_rows, A.n_cols), B.n_cols ); if(size(tmp) == size(B)) { tmp = B; } else { tmp.zeros(); tmp(0,0, size(B)) = B; } blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_cols); blas_int nrhs = blas_int(B.n_cols); blas_int lda = blas_int(A.n_rows); blas_int ldb = blas_int(tmp.n_rows); T rcond = T(-1); // -1 means "use machine precision" blas_int rank = blas_int(0); blas_int info = blas_int(0); const uword min_mn = (std::min)(A.n_rows, A.n_cols); podarray S(min_mn); blas_int ispec = blas_int(9); const char* const_name = (is_float::value) ? "CGELSD" : "ZGELSD"; const char* const_opts = ""; char* name = const_cast(const_name); char* opts = const_cast(const_opts); blas_int n1 = m; blas_int n2 = n; blas_int n3 = nrhs; blas_int n4 = lda; blas_int smlsiz = (std::max)( blas_int(25), lapack::laenv(&ispec, name, opts, &n1, &n2, &n3, &n4) ); // in case lapack::laenv() returns -1 blas_int smlsiz_p1 = blas_int(1) + smlsiz; blas_int nlvl = (std::max)( blas_int(0), blas_int(1) + blas_int( std::log(double(min_mn) / double(smlsiz_p1))/double(0.69314718055994530942) ) ); blas_int lrwork = (m >= n) ? blas_int(10)*n + blas_int(2)*n*smlsiz + blas_int(8)*n*nlvl + blas_int(3)*smlsiz*nrhs + (std::max)( (smlsiz_p1)*(smlsiz_p1), n*(blas_int(1)+nrhs) + blas_int(2)*nrhs ) : blas_int(10)*m + blas_int(2)*m*smlsiz + blas_int(8)*m*nlvl + blas_int(3)*smlsiz*nrhs + (std::max)( (smlsiz_p1)*(smlsiz_p1), n*(blas_int(1)+nrhs) + blas_int(2)*nrhs ); blas_int liwork = (std::max)( blas_int(1), (blas_int(3)*blas_int(min_mn)*nlvl + blas_int(11)*blas_int(min_mn)) ); podarray rwork( static_cast(lrwork) ); podarray iwork( static_cast(liwork) ); eT work_query[2]; blas_int lwork_query = blas_int(-1); arma_extra_debug_print("lapack::cx_gelsd()"); lapack::cx_gelsd(&m, &n, &nrhs, A.memptr(), &lda, tmp.memptr(), &ldb, S.memptr(), &rcond, &rank, &work_query[0], &lwork_query, rwork.memptr(), iwork.memptr(), &info); if(info != 0) { return false; } blas_int lwork = static_cast( access::tmp_real( work_query[0]) ); podarray work( static_cast(lwork) ); arma_extra_debug_print("lapack::cx_gelsd()"); lapack::cx_gelsd(&m, &n, &nrhs, A.memptr(), &lda, tmp.memptr(), &ldb, S.memptr(), &rcond, &rank, work.memptr(), &lwork, rwork.memptr(), iwork.memptr(), &info); if(info != 0) { return false; } if(tmp.n_rows == A.n_cols) { out.steal_mem(tmp); } else { out = tmp.head_rows(A.n_cols); } return true; } #else { arma_ignore(out); arma_ignore(A); arma_ignore(B_expr); arma_stop("solve(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::solve_tri(Mat& out, const Mat& A, const Base& B_expr, const uword layout) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { out = B_expr.get_ref(); const uword B_n_rows = out.n_rows; const uword B_n_cols = out.n_cols; arma_debug_check( (A.n_rows != B_n_rows), "solve(): number of rows in the given matrices must be the same" ); if(A.is_empty() || out.is_empty()) { out.zeros(A.n_cols, B_n_cols); return true; } arma_debug_assert_blas_size(A,out); char uplo = (layout == 0) ? 'U' : 'L'; char trans = 'N'; char diag = 'N'; blas_int n = blas_int(A.n_rows); blas_int nrhs = blas_int(B_n_cols); blas_int info = 0; arma_extra_debug_print("lapack::trtrs()"); lapack::trtrs(&uplo, &trans, &diag, &n, &nrhs, A.memptr(), &n, out.memptr(), &n, &info); return (info == 0); } #else { arma_ignore(out); arma_ignore(A); arma_ignore(B_expr); arma_ignore(layout); arma_stop("solve(): use of LAPACK must be enabled"); return false; } #endif } // // Schur decomposition template inline bool auxlib::schur(Mat& U, Mat& S, const Base& X, const bool calc_U) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { S = X.get_ref(); arma_debug_check( (S.is_square() == false), "schur(): given matrix must be square sized" ); if(S.is_empty()) { U.reset(); S.reset(); return true; } arma_debug_assert_blas_size(S); const uword S_n_rows = S.n_rows; if(calc_U) { U.set_size(S_n_rows, S_n_rows); } else { U.set_size(1,1); } char jobvs = calc_U ? 'V' : 'N'; char sort = 'N'; void* select = 0; blas_int n = blas_int(S_n_rows); blas_int sdim = 0; blas_int ldvs = calc_U ? n : blas_int(1); blas_int lwork = 3 * ((std::max)(blas_int(1), 3*n)); blas_int info = 0; podarray wr(S_n_rows); podarray wi(S_n_rows); podarray work( static_cast(lwork) ); podarray bwork(S_n_rows); arma_extra_debug_print("lapack::gees()"); lapack::gees(&jobvs, &sort, select, &n, S.memptr(), &n, &sdim, wr.memptr(), wi.memptr(), U.memptr(), &ldvs, work.memptr(), &lwork, bwork.memptr(), &info); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(X); arma_stop("schur(): use of LAPACK must be enabled"); return false; } #endif } template inline bool auxlib::schur(Mat >& U, Mat >& S, const Base,T1>& X, const bool calc_U) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_CRIPPLED_LAPACK)) { arma_ignore(U); arma_ignore(S); arma_ignore(X); arma_ignore(calc_U); arma_stop("schur() for complex matrices not available due to crippled LAPACK"); return false; } #elif defined(ARMA_USE_LAPACK) { typedef std::complex eT; S = X.get_ref(); arma_debug_check( (S.is_square() == false), "schur(): given matrix must be square sized" ); if(S.is_empty()) { U.reset(); S.reset(); return true; } arma_debug_assert_blas_size(S); const uword S_n_rows = S.n_rows; if(calc_U) { U.set_size(S_n_rows, S_n_rows); } else { U.set_size(1,1); } char jobvs = calc_U ? 'V' : 'N'; char sort = 'N'; void* select = 0; blas_int n = blas_int(S_n_rows); blas_int sdim = 0; blas_int ldvs = calc_U ? n : blas_int(1); blas_int lwork = 3 * ((std::max)(blas_int(1), 2*n)); blas_int info = 0; podarray w(S_n_rows); podarray work( static_cast(lwork) ); podarray< T> rwork(S_n_rows); podarray bwork(S_n_rows); arma_extra_debug_print("lapack::cx_gees()"); lapack::cx_gees(&jobvs, &sort, select, &n, S.memptr(), &n, &sdim, w.memptr(), U.memptr(), &ldvs, work.memptr(), &lwork, rwork.memptr(), bwork.memptr(), &info); return (info == 0); } #else { arma_ignore(U); arma_ignore(S); arma_ignore(X); arma_ignore(calc_U); arma_stop("schur(): use of LAPACK must be enabled"); return false; } #endif } // // syl (solution of the Sylvester equation AX + XB = C) template inline bool auxlib::syl(Mat& X, const Mat& A, const Mat& B, const Mat& C) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { arma_debug_check( (A.is_square() == false) || (B.is_square() == false), "syl(): given matrices must be square sized" ); arma_debug_check( (C.n_rows != A.n_rows) || (C.n_cols != B.n_cols), "syl(): matrices are not conformant" ); if(A.is_empty() || B.is_empty() || C.is_empty()) { X.reset(); return true; } Mat Z1, Z2, T1, T2; const bool status_sd1 = auxlib::schur(Z1, T1, A); const bool status_sd2 = auxlib::schur(Z2, T2, B); if( (status_sd1 == false) || (status_sd2 == false) ) { return false; } char trana = 'N'; char tranb = 'N'; blas_int isgn = +1; blas_int m = blas_int(T1.n_rows); blas_int n = blas_int(T2.n_cols); eT scale = eT(0); blas_int info = 0; Mat Y = trans(Z1) * C * Z2; arma_extra_debug_print("lapack::trsyl()"); lapack::trsyl(&trana, &tranb, &isgn, &m, &n, T1.memptr(), &m, T2.memptr(), &n, Y.memptr(), &m, &scale, &info); //Y /= scale; Y /= (-scale); X = Z1 * Y * trans(Z2); return (info >= 0); } #else { arma_ignore(X); arma_ignore(A); arma_ignore(B); arma_ignore(C); arma_stop("syl(): use of LAPACK must be enabled"); return false; } #endif } // // QZ decomposition of general square real matrix pair template inline bool auxlib::qz(Mat& A, Mat& B, Mat& vsl, Mat& vsr, const Base& X_expr, const Base& Y_expr) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_LAPACK) { A = X_expr.get_ref(); B = Y_expr.get_ref(); arma_debug_check( ((A.is_square() == false) || (B.is_square() == false)), "qz(): given matrices must be square sized" ); arma_debug_check( (A.n_rows != B.n_rows), "qz(): given matrices must have the same size" ); if(A.is_empty()) { A.reset(); B.reset(); vsl.reset(); vsr.reset(); return true; } arma_debug_assert_blas_size(A); vsl.set_size(A.n_rows, A.n_rows); vsr.set_size(A.n_rows, A.n_rows); char jobvsl = 'V'; char jobvsr = 'V'; char eigsort = 'N'; void* selctg = 0; blas_int N = blas_int(A.n_rows); blas_int sdim = 0; blas_int lwork = 3 * ((std::max)(blas_int(1),8*N+16)); blas_int info = 0; podarray alphar(A.n_rows); podarray alphai(A.n_rows); podarray beta(A.n_rows); podarray work( static_cast(lwork) ); podarray bwork( static_cast(N) ); arma_extra_debug_print("lapack::gges()"); lapack::gges ( &jobvsl, &jobvsr, &eigsort, selctg, &N, A.memptr(), &N, B.memptr(), &N, &sdim, alphar.memptr(), alphai.memptr(), beta.memptr(), vsl.memptr(), &N, vsr.memptr(), &N, work.memptr(), &lwork, bwork.memptr(), &info ); op_strans::apply_mat_inplace(vsl); return (info == 0); } #else { arma_ignore(A); arma_ignore(B); arma_ignore(vsl); arma_ignore(vsr); arma_ignore(X_expr); arma_ignore(Y_expr); arma_stop("qz(): use of LAPACK must be enabled"); return false; } #endif } // // QZ decomposition of general square complex matrix pair template inline bool auxlib::qz(Mat< std::complex >& A, Mat< std::complex >& B, Mat< std::complex >& vsl, Mat< std::complex >& vsr, const Base< std::complex, T1 >& X_expr, const Base< std::complex, T2 >& Y_expr) { arma_extra_debug_sigprint(); #if (defined(ARMA_USE_LAPACK) && defined(ARMA_CRIPPLED_LAPACK)) { arma_ignore(A); arma_ignore(B); arma_ignore(vsl); arma_ignore(vsr); arma_ignore(X_expr); arma_ignore(Y_expr); arma_stop("qz() for complex matrices not available due to crippled LAPACK"); return false; } #elif defined(ARMA_USE_LAPACK) { typedef typename std::complex eT; A = X_expr.get_ref(); B = Y_expr.get_ref(); arma_debug_check( ((A.is_square() == false) || (B.is_square() == false)), "qz(): given matrices must be square sized" ); arma_debug_check( (A.n_rows != B.n_rows), "qz(): given matrices must have the same size" ); if(A.is_empty()) { A.reset(); B.reset(); vsl.reset(); vsr.reset(); return true; } arma_debug_assert_blas_size(A); vsl.set_size(A.n_rows, A.n_rows); vsr.set_size(A.n_rows, A.n_rows); char jobvsl = 'V'; char jobvsr = 'V'; char eigsort = 'N'; void* selctg = 0; blas_int N = blas_int(A.n_rows); blas_int sdim = 0; blas_int lwork = 3 * ((std::max)(blas_int(1),2*N)); blas_int info = 0; podarray alpha(A.n_rows); podarray beta(A.n_rows); podarray work( static_cast(lwork) ); podarray< T> rwork( static_cast(8*N) ); podarray< T> bwork( static_cast(N) ); arma_extra_debug_print("lapack::cx_gges()"); lapack::cx_gges ( &jobvsl, &jobvsr, &eigsort, selctg, &N, A.memptr(), &N, B.memptr(), &N, &sdim, alpha.memptr(), beta.memptr(), vsl.memptr(), &N, vsr.memptr(), &N, work.memptr(), &lwork, rwork.memptr(), bwork.memptr(), &info ); op_htrans::apply_mat_inplace(vsl); return (info == 0); } #else { arma_ignore(A); arma_ignore(B); arma_ignore(vsl); arma_ignore(vsr); arma_ignore(X_expr); arma_ignore(Y_expr); arma_stop("qz(): use of LAPACK must be enabled"); return false; } #endif } template inline typename T1::pod_type auxlib::rcond(const Base& A_expr) { typedef typename T1::pod_type T; #if defined(ARMA_USE_LAPACK) { typedef typename T1::elem_type eT; Mat A = A_expr.get_ref(); arma_debug_check( (A.is_square() == false), "rcond(): matrix must be square sized" ); if(A.is_empty()) { return Datum::inf; } arma_debug_assert_blas_size(A); char norm_id = '1'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_rows); // assuming square matrix blas_int lda = blas_int(A.n_rows); T norm_val = T(0); T rcond = T(0); blas_int info = blas_int(0); podarray work(4*A.n_rows); podarray iwork(A.n_rows); podarray ipiv( (std::min)(A.n_rows, A.n_cols) ); norm_val = lapack::lange(&norm_id, &m, &n, A.memptr(), &lda, work.memptr()); lapack::getrf(&m, &n, A.memptr(), &lda, ipiv.memptr(), &info); if(info != blas_int(0)) { return T(0); } lapack::gecon(&norm_id, &n, A.memptr(), &lda, &norm_val, &rcond, work.memptr(), iwork.memptr(), &info); if(info != blas_int(0)) { return T(0); } return rcond; } #else { arma_ignore(A_expr); arma_stop("rcond(): use of LAPACK must be enabled"); } #endif return T(0); } template inline typename T1::pod_type auxlib::rcond(const Base,T1>& A_expr) { typedef typename T1::pod_type T; #if defined(ARMA_USE_LAPACK) { typedef typename T1::elem_type eT; Mat A = A_expr.get_ref(); arma_debug_check( (A.is_square() == false), "rcond(): matrix must be square sized" ); if(A.is_empty()) { return Datum::inf; } arma_debug_assert_blas_size(A); char norm_id = '1'; blas_int m = blas_int(A.n_rows); blas_int n = blas_int(A.n_rows); // assuming square matrix blas_int lda = blas_int(A.n_rows); T norm_val = T(0); T rcond = T(0); blas_int info = blas_int(0); podarray< T> junk(1); podarray work(2*A.n_rows); podarray< T> rwork(2*A.n_rows); podarray iwork(A.n_rows); podarray ipiv( (std::min)(A.n_rows, A.n_cols) ); norm_val = lapack::lange(&norm_id, &m, &n, A.memptr(), &lda, junk.memptr()); lapack::getrf(&m, &n, A.memptr(), &lda, ipiv.memptr(), &info); if(info != blas_int(0)) { return T(0); } lapack::cx_gecon(&norm_id, &n, A.memptr(), &lda, &norm_val, &rcond, work.memptr(), rwork.memptr(), &info); if(info != blas_int(0)) { return T(0); } return rcond; } #else { arma_ignore(A_expr); arma_stop("rcond(): use of LAPACK must be enabled"); } #endif return T(0); } //! @} armadillo-6.500.5/include/armadillo_bits/SpMat_meat.hpp0000666000000000000000000035037512650111756021531 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin // Written by Matthew Amidon //! \addtogroup SpMat //! @{ /** * Initialize a sparse matrix with size 0x0 (empty). */ template inline SpMat::SpMat() : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(memory::acquire_chunked(1)) , row_indices(memory::acquire_chunked(1)) , col_ptrs(memory::acquire(2)) { arma_extra_debug_sigprint_this(this); access::rw(values[0]) = 0; access::rw(row_indices[0]) = 0; access::rw(col_ptrs[0]) = 0; // No elements. access::rw(col_ptrs[1]) = std::numeric_limits::max(); } /** * Clean up the memory of a sparse matrix and destruct it. */ template inline SpMat::~SpMat() { arma_extra_debug_sigprint_this(this); if(values ) { memory::release(access::rw(values)); } if(row_indices) { memory::release(access::rw(row_indices)); } if(col_ptrs ) { memory::release(access::rw(col_ptrs)); } } /** * Constructor with size given. */ template inline SpMat::SpMat(const uword in_rows, const uword in_cols) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(in_rows, in_cols); } template inline SpMat::SpMat(const SizeMat& s) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(s.n_rows, s.n_cols); } /** * Assemble from text. */ template inline SpMat::SpMat(const char* text) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(std::string(text)); } template inline const SpMat& SpMat::operator=(const char* text) { arma_extra_debug_sigprint(); init(std::string(text)); return *this; } template inline SpMat::SpMat(const std::string& text) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint(); init(text); } template inline const SpMat& SpMat::operator=(const std::string& text) { arma_extra_debug_sigprint(); init(text); return *this; } template inline SpMat::SpMat(const SpMat& x) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(x); } #if defined(ARMA_USE_CXX11) template inline SpMat::SpMat(SpMat&& in_mat) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint(arma_str::format("this = %x in_mat = %x") % this % &in_mat); (*this).steal_mem(in_mat); } template inline const SpMat& SpMat::operator=(SpMat&& in_mat) { arma_extra_debug_sigprint(arma_str::format("this = %x in_mat = %x") % this % &in_mat); (*this).steal_mem(in_mat); return *this; } #endif //! Insert a large number of values at once. //! locations.row[0] should be row indices, locations.row[1] should be column indices, //! and values should be the corresponding values. //! If sort_locations is false, then it is assumed that the locations and values //! are already sorted in column-major ordering. template template inline SpMat::SpMat(const Base& locations_expr, const Base& vals_expr, const bool sort_locations) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); const unwrap locs_tmp( locations_expr.get_ref() ); const unwrap vals_tmp( vals_expr.get_ref() ); const Mat& locs = locs_tmp.M; const Mat& vals = vals_tmp.M; arma_debug_check( (vals.is_vec() == false), "SpMat::SpMat(): given 'values' object is not a vector" ); arma_debug_check( (locs.n_rows != 2), "SpMat::SpMat(): locations matrix must have two rows" ); arma_debug_check( (locs.n_cols != vals.n_elem), "SpMat::SpMat(): number of locations is different than number of values" ); // If there are no elements in the list, max() will fail. if(locs.n_cols == 0) { init(0, 0); return; } // Automatically determine size before pruning zeros. uvec bounds = arma::max(locs, 1); init(bounds[0] + 1, bounds[1] + 1); // Ensure that there are no zeros const uword N_old = vals.n_elem; uword N_new = 0; for(uword i = 0; i < N_old; ++i) { if(vals[i] != eT(0)) { ++N_new; } } if(N_new != N_old) { Col filtered_vals(N_new); Mat filtered_locs(2, N_new); uword index = 0; for(uword i = 0; i < N_old; ++i) { if(vals[i] != eT(0)) { filtered_vals[index] = vals[i]; filtered_locs.at(0, index) = locs.at(0, i); filtered_locs.at(1, index) = locs.at(1, i); ++index; } } init_batch_std(filtered_locs, filtered_vals, sort_locations); } else { init_batch_std(locs, vals, sort_locations); } } //! Insert a large number of values at once. //! locations.row[0] should be row indices, locations.row[1] should be column indices, //! and values should be the corresponding values. //! If sort_locations is false, then it is assumed that the locations and values //! are already sorted in column-major ordering. //! In this constructor the size is explicitly given. template template inline SpMat::SpMat(const Base& locations_expr, const Base& vals_expr, const uword in_n_rows, const uword in_n_cols, const bool sort_locations, const bool check_for_zeros) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); const unwrap locs_tmp( locations_expr.get_ref() ); const unwrap vals_tmp( vals_expr.get_ref() ); const Mat& locs = locs_tmp.M; const Mat& vals = vals_tmp.M; arma_debug_check( (vals.is_vec() == false), "SpMat::SpMat(): given 'values' object is not a vector" ); arma_debug_check( (locs.n_rows != 2), "SpMat::SpMat(): locations matrix must have two rows" ); arma_debug_check( (locs.n_cols != vals.n_elem), "SpMat::SpMat(): number of locations is different than number of values" ); init(in_n_rows, in_n_cols); // Ensure that there are no zeros, unless the user asked not to. if(check_for_zeros) { const uword N_old = vals.n_elem; uword N_new = 0; for(uword i = 0; i < N_old; ++i) { if(vals[i] != eT(0)) { ++N_new; } } if(N_new != N_old) { Col filtered_vals(N_new); Mat filtered_locs(2, N_new); uword index = 0; for(uword i = 0; i < N_old; ++i) { if(vals[i] != eT(0)) { filtered_vals[index] = vals[i]; filtered_locs.at(0, index) = locs.at(0, i); filtered_locs.at(1, index) = locs.at(1, i); ++index; } } init_batch_std(filtered_locs, filtered_vals, sort_locations); } else { init_batch_std(locs, vals, sort_locations); } } else { init_batch_std(locs, vals, sort_locations); } } template template inline SpMat::SpMat(const bool add_values, const Base& locations_expr, const Base& vals_expr, const uword in_n_rows, const uword in_n_cols, const bool sort_locations, const bool check_for_zeros) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); const unwrap locs_tmp( locations_expr.get_ref() ); const unwrap vals_tmp( vals_expr.get_ref() ); const Mat& locs = locs_tmp.M; const Mat& vals = vals_tmp.M; arma_debug_check( (vals.is_vec() == false), "SpMat::SpMat(): given 'values' object is not a vector" ); arma_debug_check( (locs.n_rows != 2), "SpMat::SpMat(): locations matrix must have two rows" ); arma_debug_check( (locs.n_cols != vals.n_elem), "SpMat::SpMat(): number of locations is different than number of values" ); init(in_n_rows, in_n_cols); // Ensure that there are no zeros, unless the user asked not to. if(check_for_zeros) { const uword N_old = vals.n_elem; uword N_new = 0; for(uword i = 0; i < N_old; ++i) { if(vals[i] != eT(0)) { ++N_new; } } if(N_new != N_old) { Col filtered_vals(N_new); Mat filtered_locs(2, N_new); uword index = 0; for(uword i = 0; i < N_old; ++i) { if(vals[i] != eT(0)) { filtered_vals[index] = vals[i]; filtered_locs.at(0, index) = locs.at(0, i); filtered_locs.at(1, index) = locs.at(1, i); ++index; } } add_values ? init_batch_add(filtered_locs, filtered_vals, sort_locations) : init_batch_std(filtered_locs, filtered_vals, sort_locations); } else { add_values ? init_batch_add(locs, vals, sort_locations) : init_batch_std(locs, vals, sort_locations); } } else { add_values ? init_batch_add(locs, vals, sort_locations) : init_batch_std(locs, vals, sort_locations); } } //! Insert a large number of values at once. //! Per CSC format, rowind_expr should be row indices, //! colptr_expr should column ptr indices locations, //! and values should be the corresponding values. //! In this constructor the size is explicitly given. //! Values are assumed to be sorted, and the size //! information is trusted template template inline SpMat::SpMat ( const Base& rowind_expr, const Base& colptr_expr, const Base& values_expr, const uword in_n_rows, const uword in_n_cols ) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); init(in_n_rows, in_n_cols); const unwrap rowind_tmp( rowind_expr.get_ref() ); const unwrap colptr_tmp( colptr_expr.get_ref() ); const unwrap vals_tmp( values_expr.get_ref() ); const Mat& rowind = rowind_tmp.M; const Mat& colptr = colptr_tmp.M; const Mat& vals = vals_tmp.M; arma_debug_check( (rowind.is_vec() == false), "SpMat::SpMat(): given 'rowind' object is not a vector" ); arma_debug_check( (colptr.is_vec() == false), "SpMat::SpMat(): given 'colptr' object is not a vector" ); arma_debug_check( (vals.is_vec() == false), "SpMat::SpMat(): given 'values' object is not a vector" ); arma_debug_check( (rowind.n_elem != vals.n_elem), "SpMat::SpMat(): number of row indices is not equal to number of values" ); arma_debug_check( (colptr.n_elem != (n_cols+1) ), "SpMat::SpMat(): number of column pointers is not equal to n_cols+1" ); // Resize to correct number of elements (this also sets n_nonzero) mem_resize(vals.n_elem); // copy supplied values into sparse matrix -- not checked for consistency arrayops::copy(access::rwp(row_indices), rowind.memptr(), rowind.n_elem ); arrayops::copy(access::rwp(col_ptrs), colptr.memptr(), colptr.n_elem ); arrayops::copy(access::rwp(values), vals.memptr(), vals.n_elem ); // important: set the sentinel as well access::rw(col_ptrs[n_cols + 1]) = std::numeric_limits::max(); } template inline const SpMat& SpMat::operator=(const eT val) { arma_extra_debug_sigprint(); if(val != eT(0)) { // Resize to 1x1 then set that to the right value. init(1, 1); // Sets col_ptrs to 0. mem_resize(1); // One element. // Manually set element. access::rw(values[0]) = val; access::rw(row_indices[0]) = 0; access::rw(col_ptrs[1]) = 1; } else { init(0, 0); } return *this; } template inline const SpMat& SpMat::operator*=(const eT val) { arma_extra_debug_sigprint(); if(val != eT(0)) { arrayops::inplace_mul( access::rwp(values), val, n_nonzero ); remove_zeros(); } else { // Everything will be zero. init(n_rows, n_cols); } return *this; } template inline const SpMat& SpMat::operator/=(const eT val) { arma_extra_debug_sigprint(); arma_debug_check( (val == eT(0)), "element-wise division: division by zero" ); arrayops::inplace_div( access::rwp(values), val, n_nonzero ); remove_zeros(); return *this; } template inline const SpMat& SpMat::operator=(const SpMat& x) { arma_extra_debug_sigprint(); init(x); return *this; } template inline const SpMat& SpMat::operator+=(const SpMat& x) { arma_extra_debug_sigprint(); SpMat out = (*this) + x; steal_mem(out); return *this; } template inline const SpMat& SpMat::operator-=(const SpMat& x) { arma_extra_debug_sigprint(); SpMat out = (*this) - x; steal_mem(out); return *this; } template inline const SpMat& SpMat::operator*=(const SpMat& y) { arma_extra_debug_sigprint(); SpMat z = (*this) * y; steal_mem(z); return *this; } // This is in-place element-wise matrix multiplication. template inline const SpMat& SpMat::operator%=(const SpMat& y) { arma_extra_debug_sigprint(); SpMat z = (*this) % y; steal_mem(z); return *this; } // Construct a complex matrix out of two non-complex matrices template template inline SpMat::SpMat ( const SpBase::pod_type, T1>& A, const SpBase::pod_type, T2>& B ) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element is set when mem_resize is called , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint(); typedef typename T1::elem_type T; // Make sure eT is complex and T is not (compile-time check). arma_type_check(( is_complex::value == false )); arma_type_check(( is_complex< T>::value == true )); // Compile-time abort if types are not compatible. arma_type_check(( is_same_type< std::complex, eT >::no )); const unwrap_spmat tmp1(A.get_ref()); const unwrap_spmat tmp2(B.get_ref()); const SpMat& X = tmp1.M; const SpMat& Y = tmp2.M; arma_debug_assert_same_size(X.n_rows, X.n_cols, Y.n_rows, Y.n_cols, "SpMat()"); const uword l_n_rows = X.n_rows; const uword l_n_cols = X.n_cols; // Set size of matrix correctly. init(l_n_rows, l_n_cols); mem_resize(n_unique(X, Y, op_n_unique_count())); // Now on a second iteration, fill it. typename SpMat::const_iterator x_it = X.begin(); typename SpMat::const_iterator x_end = X.end(); typename SpMat::const_iterator y_it = Y.begin(); typename SpMat::const_iterator y_end = Y.end(); uword cur_pos = 0; while ((x_it != x_end) || (y_it != y_end)) { if(x_it == y_it) // if we are at the same place { access::rw(values[cur_pos]) = std::complex((T) *x_it, (T) *y_it); access::rw(row_indices[cur_pos]) = x_it.row(); ++access::rw(col_ptrs[x_it.col() + 1]); ++x_it; ++y_it; } else { if((x_it.col() < y_it.col()) || ((x_it.col() == y_it.col()) && (x_it.row() < y_it.row()))) // if y is closer to the end { access::rw(values[cur_pos]) = std::complex((T) *x_it, T(0)); access::rw(row_indices[cur_pos]) = x_it.row(); ++access::rw(col_ptrs[x_it.col() + 1]); ++x_it; } else // x is closer to the end { access::rw(values[cur_pos]) = std::complex(T(0), (T) *y_it); access::rw(row_indices[cur_pos]) = y_it.row(); ++access::rw(col_ptrs[y_it.col() + 1]); ++y_it; } } ++cur_pos; } // Now fix the column pointers; they are supposed to be a sum. for (uword c = 1; c <= n_cols; ++c) { access::rw(col_ptrs[c]) += col_ptrs[c - 1]; } } template inline const SpMat& SpMat::operator/=(const SpMat& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise division"); // If you use this method, you are probably stupid or misguided, but for compatibility with Mat, we have implemented it anyway. // We have to loop over every element, which is not good. In fact, it makes me physically sad to write this. for(uword c = 0; c < n_cols; ++c) { for(uword r = 0; r < n_rows; ++r) { at(r, c) /= x.at(r, c); } } return *this; } template template inline SpMat::SpMat(const Base& x) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element is set when mem_resize is called in operator=() , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); (*this).operator=(x); } template template inline const SpMat& SpMat::operator=(const Base& expr) { arma_extra_debug_sigprint(); const quasi_unwrap tmp(expr.get_ref()); const Mat& x = tmp.M; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; const uword x_n_elem = x.n_elem; init(x_n_rows, x_n_cols); // Count number of nonzero elements in base object. uword n = 0; const eT* x_mem = x.memptr(); for(uword i = 0; i < x_n_elem; ++i) { n += (x_mem[i] != eT(0)) ? uword(1) : uword(0); } mem_resize(n); // Now the memory is resized correctly; add nonzero elements. n = 0; for(uword j = 0; j < x_n_cols; ++j) for(uword i = 0; i < x_n_rows; ++i) { const eT val = (*x_mem); x_mem++; if(val != eT(0)) { access::rw(values[n]) = val; access::rw(row_indices[n]) = i; access::rw(col_ptrs[j + 1])++; ++n; } } // Sum column counts to be column pointers. for(uword c = 1; c <= n_cols; ++c) { access::rw(col_ptrs[c]) += col_ptrs[c - 1]; } return *this; } template template inline const SpMat& SpMat::operator+=(const Base& x) { arma_extra_debug_sigprint(); return (*this).operator=( (*this) + x.get_ref() ); } template template inline const SpMat& SpMat::operator-=(const Base& x) { arma_extra_debug_sigprint(); return (*this).operator=( (*this) - x.get_ref() ); } template template inline const SpMat& SpMat::operator*=(const Base& y) { arma_extra_debug_sigprint(); const Proxy p(y.get_ref()); arma_debug_assert_mul_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "matrix multiplication"); // We assume the matrix structure is such that we will end up with a sparse // matrix. Assuming that every entry in the dense matrix is nonzero (which is // a fairly valid assumption), each row with any nonzero elements in it (in this // matrix) implies an entire nonzero column. Therefore, we iterate over all // the row_indices and count the number of rows with any elements in them // (using the quasi-linked-list idea from SYMBMM -- see operator_times.hpp). podarray index(n_rows); index.fill(n_rows); // Fill with invalid links. uword last_index = n_rows + 1; for(uword i = 0; i < n_nonzero; ++i) { if(index[row_indices[i]] == n_rows) { index[row_indices[i]] = last_index; last_index = row_indices[i]; } } // Now count the number of rows which have nonzero elements. uword nonzero_rows = 0; while(last_index != n_rows + 1) { ++nonzero_rows; last_index = index[last_index]; } SpMat z(n_rows, p.get_n_cols()); z.mem_resize(nonzero_rows * p.get_n_cols()); // upper bound on size // Now we have to fill all the elements using a modification of the NUMBMM algorithm. uword cur_pos = 0; podarray partial_sums(n_rows); partial_sums.zeros(); for(uword lcol = 0; lcol < n_cols; ++lcol) { const_iterator it = begin(); while(it != end()) { const eT value = (*it); partial_sums[it.row()] += (value * p.at(it.col(), lcol)); ++it; } // Now add all partial sums to the matrix. for(uword i = 0; i < n_rows; ++i) { if(partial_sums[i] != eT(0)) { access::rw(z.values[cur_pos]) = partial_sums[i]; access::rw(z.row_indices[cur_pos]) = i; ++access::rw(z.col_ptrs[lcol + 1]); //printf("colptr %d now %d\n", lcol + 1, z.col_ptrs[lcol + 1]); ++cur_pos; partial_sums[i] = 0; // Would it be faster to do this in batch later? } } } // Now fix the column pointers. for(uword c = 1; c <= z.n_cols; ++c) { access::rw(z.col_ptrs[c]) += z.col_ptrs[c - 1]; } // Resize to final correct size. z.mem_resize(z.col_ptrs[z.n_cols]); // Now take the memory of the temporary matrix. steal_mem(z); return *this; } /** * Don't use this function. It's not mathematically well-defined and wastes * cycles to trash all your data. This is dumb. */ template template inline const SpMat& SpMat::operator/=(const Base& x) { arma_extra_debug_sigprint(); SpMat tmp = (*this) / x.get_ref(); steal_mem(tmp); return *this; } template template inline const SpMat& SpMat::operator%=(const Base& x) { arma_extra_debug_sigprint(); const Proxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise multiplication"); // Count the number of elements we will need. SpMat tmp(n_rows, n_cols); const_iterator it = begin(); uword new_n_nonzero = 0; while(it != end()) { // prefer_at_accessor == false can't save us any work here if(((*it) * p.at(it.row(), it.col())) != eT(0)) { ++new_n_nonzero; } ++it; } // Resize. tmp.mem_resize(new_n_nonzero); const_iterator c_it = begin(); uword cur_pos = 0; while(c_it != end()) { // prefer_at_accessor == false can't save us any work here const eT val = (*c_it) * p.at(c_it.row(), c_it.col()); if(val != eT(0)) { access::rw(tmp.values[cur_pos]) = val; access::rw(tmp.row_indices[cur_pos]) = c_it.row(); ++access::rw(tmp.col_ptrs[c_it.col() + 1]); ++cur_pos; } ++c_it; } // Fix column pointers. for(uword c = 1; c <= n_cols; ++c) { access::rw(tmp.col_ptrs[c]) += tmp.col_ptrs[c - 1]; } steal_mem(tmp); return *this; } /** * Functions on subviews. */ template inline SpMat::SpMat(const SpSubview& X) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element added when mem_resize is called , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); (*this).operator=(X); } template inline const SpMat& SpMat::operator=(const SpSubview& X) { arma_extra_debug_sigprint(); const uword in_n_cols = X.n_cols; const uword in_n_rows = X.n_rows; const bool alias = (this == &(X.m)); if(alias == false) { init(in_n_rows, in_n_cols); const uword x_n_nonzero = X.n_nonzero; mem_resize(x_n_nonzero); typename SpSubview::const_iterator it = X.begin(); typename SpSubview::const_iterator it_end = X.end(); while(it != it_end) { access::rw(row_indices[it.pos()]) = it.row(); access::rw(values[it.pos()]) = (*it); ++access::rw(col_ptrs[it.col() + 1]); ++it; } // Now sum column pointers. for(uword c = 1; c <= n_cols; ++c) { access::rw(col_ptrs[c]) += col_ptrs[c - 1]; } } else { // Create it in a temporary. SpMat tmp(X); steal_mem(tmp); } return *this; } template inline const SpMat& SpMat::operator+=(const SpSubview& X) { arma_extra_debug_sigprint(); SpMat tmp = (*this) + X; steal_mem(tmp); return *this; } template inline const SpMat& SpMat::operator-=(const SpSubview& X) { arma_extra_debug_sigprint(); SpMat tmp = (*this) - X; steal_mem(tmp); return *this; } template inline const SpMat& SpMat::operator*=(const SpSubview& y) { arma_extra_debug_sigprint(); SpMat z = (*this) * y; steal_mem(z); return *this; } template inline const SpMat& SpMat::operator%=(const SpSubview& x) { arma_extra_debug_sigprint(); SpMat tmp = (*this) % x; steal_mem(tmp); return *this; } template inline const SpMat& SpMat::operator/=(const SpSubview& x) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, x.n_rows, x.n_cols, "element-wise division"); // There is no pretty way to do this. for(uword elem = 0; elem < n_elem; elem++) { at(elem) /= x(elem); } return *this; } template template inline SpMat::SpMat(const SpOp& X) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // set in application of sparse operation , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); spop_type::apply(*this, X); } template template inline const SpMat& SpMat::operator=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); spop_type::apply(*this, X); return *this; } template template inline const SpMat& SpMat::operator+=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator+=(m); } template template inline const SpMat& SpMat::operator-=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator-=(m); } template template inline const SpMat& SpMat::operator*=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator*=(m); } template template inline const SpMat& SpMat::operator%=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator%=(m); } template template inline const SpMat& SpMat::operator/=(const SpOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator/=(m); } template template inline SpMat::SpMat(const SpGlue& X) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element set in application of sparse glue , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); spglue_type::apply(*this, X); } template template inline SpMat::SpMat(const mtSpOp& X) : n_rows(0) , n_cols(0) , n_elem(0) , n_nonzero(0) , vec_state(0) , values(NULL) // extra element set in application of sparse glue , row_indices(NULL) , col_ptrs(NULL) { arma_extra_debug_sigprint_this(this); spop_type::apply(*this, X); } template template inline const SpMat& SpMat::operator=(const mtSpOp& X) { arma_extra_debug_sigprint(); spop_type::apply(*this, X); return *this; } template template inline const SpMat& SpMat::operator+=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator+=(m); } template template inline const SpMat& SpMat::operator-=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator-=(m); } template template inline const SpMat& SpMat::operator*=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator*=(m); } template template inline const SpMat& SpMat::operator%=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator%=(m); } template template inline const SpMat& SpMat::operator/=(const mtSpOp& X) { arma_extra_debug_sigprint(); const SpMat m(X); return (*this).operator/=(m); } template template inline const SpMat& SpMat::operator=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); spglue_type::apply(*this, X); return *this; } template template inline const SpMat& SpMat::operator+=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator+=(m); } template template inline const SpMat& SpMat::operator-=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator-=(m); } template template inline const SpMat& SpMat::operator*=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator*=(m); } template template inline const SpMat& SpMat::operator%=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator%=(m); } template template inline const SpMat& SpMat::operator/=(const SpGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const SpMat m(X); return (*this).operator/=(m); } template arma_inline SpSubview SpMat::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check(row_num >= n_rows, "SpMat::row(): out of bounds"); return SpSubview(*this, row_num, 0, 1, n_cols); } template arma_inline const SpSubview SpMat::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check(row_num >= n_rows, "SpMat::row(): out of bounds"); return SpSubview(*this, row_num, 0, 1, n_cols); } template inline SpSubview SpMat::operator()(const uword row_num, const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "SpMat::operator(): indices out of bounds or incorrectly used" ); return SpSubview(*this, row_num, in_col1, 1, submat_n_cols); } template inline const SpSubview SpMat::operator()(const uword row_num, const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "SpMat::operator(): indices out of bounds or incorrectly used" ); return SpSubview(*this, row_num, in_col1, 1, submat_n_cols); } template arma_inline SpSubview SpMat::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check(col_num >= n_cols, "SpMat::col(): out of bounds"); return SpSubview(*this, 0, col_num, n_rows, 1); } template arma_inline const SpSubview SpMat::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check(col_num >= n_cols, "SpMat::col(): out of bounds"); return SpSubview(*this, 0, col_num, n_rows, 1); } template inline SpSubview SpMat::operator()(const span& row_span, const uword col_num) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "SpMat::operator(): indices out of bounds or incorrectly used" ); return SpSubview(*this, in_row1, col_num, submat_n_rows, 1); } template inline const SpSubview SpMat::operator()(const span& row_span, const uword col_num) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "SpMat::operator(): indices out of bounds or incorrectly used" ); return SpSubview(*this, in_row1, col_num, submat_n_rows, 1); } template arma_inline SpSubview SpMat::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpMat::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; return SpSubview(*this, in_row1, 0, subview_n_rows, n_cols); } template arma_inline const SpSubview SpMat::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpMat::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; return SpSubview(*this, in_row1, 0, subview_n_rows, n_cols); } template arma_inline SpSubview SpMat::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpMat::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; return SpSubview(*this, 0, in_col1, n_rows, subview_n_cols); } template arma_inline const SpSubview SpMat::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpMat::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; return SpSubview(*this, 0, in_col1, n_rows, subview_n_cols); } template arma_inline SpSubview SpMat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "SpMat::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; return SpSubview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); } template arma_inline const SpSubview SpMat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "SpMat::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; return SpSubview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); } template arma_inline SpSubview SpMat::submat(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "SpMat::submat(): indices or size out of bounds" ); return SpSubview(*this, in_row1, in_col1, s_n_rows, s_n_cols); } template arma_inline const SpSubview SpMat::submat(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "SpMat::submat(): indices or size out of bounds" ); return SpSubview(*this, in_row1, in_col1, s_n_rows, s_n_cols); } template inline SpSubview SpMat::submat(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "SpMat::submat(): indices out of bounds or incorrectly used" ); return SpSubview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); } template inline const SpSubview SpMat::submat(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "SpMat::submat(): indices out of bounds or incorrectly used" ); return SpSubview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); } template inline SpSubview SpMat::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return submat(row_span, col_span); } template inline const SpSubview SpMat::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return submat(row_span, col_span); } template arma_inline SpSubview SpMat::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).submat(in_row1, in_col1, s); } template arma_inline const SpSubview SpMat::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); return (*this).submat(in_row1, in_col1, s); } template inline SpSubview SpMat::head_rows(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > n_rows), "SpMat::head_rows(): size out of bounds"); return SpSubview(*this, 0, 0, N, n_cols); } template inline const SpSubview SpMat::head_rows(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > n_rows), "SpMat::head_rows(): size out of bounds"); return SpSubview(*this, 0, 0, N, n_cols); } template inline SpSubview SpMat::tail_rows(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > n_rows), "SpMat::tail_rows(): size out of bounds"); const uword start_row = n_rows - N; return SpSubview(*this, start_row, 0, N, n_cols); } template inline const SpSubview SpMat::tail_rows(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > n_rows), "SpMat::tail_rows(): size out of bounds"); const uword start_row = n_rows - N; return SpSubview(*this, start_row, 0, N, n_cols); } template inline SpSubview SpMat::head_cols(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > n_cols), "SpMat::head_cols(): size out of bounds"); return SpSubview(*this, 0, 0, n_rows, N); } template inline const SpSubview SpMat::head_cols(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > n_cols), "SpMat::head_cols(): size out of bounds"); return SpSubview(*this, 0, 0, n_rows, N); } template inline SpSubview SpMat::tail_cols(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > n_cols), "SpMat::tail_cols(): size out of bounds"); const uword start_col = n_cols - N; return SpSubview(*this, 0, start_col, n_rows, N); } template inline const SpSubview SpMat::tail_cols(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > n_cols), "SpMat::tail_cols(): size out of bounds"); const uword start_col = n_cols - N; return SpSubview(*this, 0, start_col, n_rows, N); } //! creation of spdiagview (diagonal) template inline spdiagview SpMat::diag(const sword in_id) { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? uword(-in_id) : 0; const uword col_offset = (in_id > 0) ? uword( in_id) : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "SpMat::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); return spdiagview(*this, row_offset, col_offset, len); } //! creation of spdiagview (diagonal) template inline const spdiagview SpMat::diag(const sword in_id) const { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? -in_id : 0; const uword col_offset = (in_id > 0) ? in_id : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "SpMat::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); return spdiagview(*this, row_offset, col_offset, len); } template inline void SpMat::swap_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 >= n_rows) || (in_row2 >= n_rows), "SpMat::swap_rows(): out of bounds" ); // Sanity check. if (in_row1 == in_row2) { return; } // The easier way to do this, instead of collecting all the elements in one row and then swapping with the other, will be // to iterate over each column of the matrix (since we store in column-major format) and then swap the two elements in the two rows at that time. // We will try to avoid using the at() call since it is expensive, instead preferring to use an iterator to track our position. uword col1 = (in_row1 < in_row2) ? in_row1 : in_row2; uword col2 = (in_row1 < in_row2) ? in_row2 : in_row1; for (uword lcol = 0; lcol < n_cols; lcol++) { // If there is nothing in this column we can ignore it. if (col_ptrs[lcol] == col_ptrs[lcol + 1]) { continue; } // These will represent the positions of the items themselves. uword loc1 = n_nonzero + 1; uword loc2 = n_nonzero + 1; for (uword search_pos = col_ptrs[lcol]; search_pos < col_ptrs[lcol + 1]; search_pos++) { if (row_indices[search_pos] == col1) { loc1 = search_pos; } if (row_indices[search_pos] == col2) { loc2 = search_pos; break; // No need to look any further. } } // There are four cases: we found both elements; we found one element (loc1); we found one element (loc2); we found zero elements. // If we found zero elements no work needs to be done and we can continue to the next column. if ((loc1 != (n_nonzero + 1)) && (loc2 != (n_nonzero + 1))) { // This is an easy case: just swap the values. No index modifying necessary. eT tmp = values[loc1]; access::rw(values[loc1]) = values[loc2]; access::rw(values[loc2]) = tmp; } else if (loc1 != (n_nonzero + 1)) // We only found loc1 and not loc2. { // We need to find the correct place to move our value to. It will be forward (not backwards) because in_row2 > in_row1. // Each iteration of the loop swaps the current value (loc1) with (loc1 + 1); in this manner we move our value down to where it should be. while (((loc1 + 1) < col_ptrs[lcol + 1]) && (row_indices[loc1 + 1] < in_row2)) { // Swap both the values and the indices. The column should not change. eT tmp = values[loc1]; access::rw(values[loc1]) = values[loc1 + 1]; access::rw(values[loc1 + 1]) = tmp; uword tmp_index = row_indices[loc1]; access::rw(row_indices[loc1]) = row_indices[loc1 + 1]; access::rw(row_indices[loc1 + 1]) = tmp_index; loc1++; // And increment the counter. } // Now set the row index correctly. access::rw(row_indices[loc1]) = in_row2; } else if (loc2 != (n_nonzero + 1)) { // We need to find the correct place to move our value to. It will be backwards (not forwards) because in_row1 < in_row2. // Each iteration of the loop swaps the current value (loc2) with (loc2 - 1); in this manner we move our value up to where it should be. while (((loc2 - 1) >= col_ptrs[lcol]) && (row_indices[loc2 - 1] > in_row1)) { // Swap both the values and the indices. The column should not change. eT tmp = values[loc2]; access::rw(values[loc2]) = values[loc2 - 1]; access::rw(values[loc2 - 1]) = tmp; uword tmp_index = row_indices[loc2]; access::rw(row_indices[loc2]) = row_indices[loc2 - 1]; access::rw(row_indices[loc2 - 1]) = tmp_index; loc2--; // And decrement the counter. } // Now set the row index correctly. access::rw(row_indices[loc2]) = in_row1; } /* else: no need to swap anything; both values are zero */ } } template inline void SpMat::swap_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); // slow but works for(uword lrow = 0; lrow < n_rows; ++lrow) { eT tmp = at(lrow, in_col1); at(lrow, in_col1) = at(lrow, in_col2); at(lrow, in_col2) = tmp; } } template inline void SpMat::shed_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check (row_num >= n_rows, "SpMat::shed_row(): out of bounds"); shed_rows (row_num, row_num); } template inline void SpMat::shed_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check (col_num >= n_cols, "SpMat::shed_col(): out of bounds"); shed_cols(col_num, col_num); } template inline void SpMat::shed_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpMat::shed_rows(): indices out of bounds or incorectly used" ); SpMat newmat(n_rows - (in_row2 - in_row1 + 1), n_cols); // First, count the number of elements we will be removing. uword removing = 0; for (uword i = 0; i < n_nonzero; ++i) { const uword lrow = row_indices[i]; if (lrow >= in_row1 && lrow <= in_row2) { ++removing; } } // Obtain counts of the number of points in each column and store them as the // (invalid) column pointers of the new matrix. for (uword i = 1; i < n_cols + 1; ++i) { access::rw(newmat.col_ptrs[i]) = col_ptrs[i] - col_ptrs[i - 1]; } // Now initialize memory for the new matrix. newmat.mem_resize(n_nonzero - removing); // Now, copy over the elements. // i is the index in the old matrix; j is the index in the new matrix. const_iterator it = begin(); const_iterator it_end = end(); uword j = 0; // The index in the new matrix. while (it != it_end) { const uword lrow = it.row(); const uword lcol = it.col(); if (lrow >= in_row1 && lrow <= in_row2) { // This element is being removed. Subtract it from the column counts. --access::rw(newmat.col_ptrs[lcol + 1]); } else { // This element is being kept. We may need to map the row index, // if it is past the section of rows we are removing. if (lrow > in_row2) { access::rw(newmat.row_indices[j]) = lrow - (in_row2 - in_row1 + 1); } else { access::rw(newmat.row_indices[j]) = lrow; } access::rw(newmat.values[j]) = (*it); ++j; // Increment index in new matrix. } ++it; } // Finally, sum the column counts so they are correct column pointers. for (uword i = 1; i < n_cols + 1; ++i) { access::rw(newmat.col_ptrs[i]) += newmat.col_ptrs[i - 1]; } // Now steal the memory of the new matrix. steal_mem(newmat); } template inline void SpMat::shed_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpMat::shed_cols(): indices out of bounds or incorrectly used" ); // First we find the locations in values and row_indices for the column entries. uword col_beg = col_ptrs[in_col1]; uword col_end = col_ptrs[in_col2 + 1]; // Then we find the number of entries in the column. uword diff = col_end - col_beg; if (diff > 0) { eT* new_values = memory::acquire_chunked (n_nonzero - diff); uword* new_row_indices = memory::acquire_chunked(n_nonzero - diff); // Copy first part. if (col_beg != 0) { arrayops::copy(new_values, values, col_beg); arrayops::copy(new_row_indices, row_indices, col_beg); } // Copy second part. if (col_end != n_nonzero) { arrayops::copy(new_values + col_beg, values + col_end, n_nonzero - col_end); arrayops::copy(new_row_indices + col_beg, row_indices + col_end, n_nonzero - col_end); } memory::release(values); memory::release(row_indices); access::rw(values) = new_values; access::rw(row_indices) = new_row_indices; // Update counts and such. access::rw(n_nonzero) -= diff; } // Update column pointers. const uword new_n_cols = n_cols - ((in_col2 - in_col1) + 1); uword* new_col_ptrs = memory::acquire(new_n_cols + 2); new_col_ptrs[new_n_cols + 1] = std::numeric_limits::max(); // Copy first set of columns (no manipulation required). if (in_col1 != 0) { arrayops::copy(new_col_ptrs, col_ptrs, in_col1); } // Copy second set of columns (manipulation required). uword cur_col = in_col1; for (uword i = in_col2 + 1; i <= n_cols; ++i, ++cur_col) { new_col_ptrs[cur_col] = col_ptrs[i] - diff; } memory::release(col_ptrs); access::rw(col_ptrs) = new_col_ptrs; // We update the element and column counts, and we're done. access::rw(n_cols) = new_n_cols; access::rw(n_elem) = n_cols * n_rows; } /** * Element access; acces the i'th element (works identically to the Mat accessors). * If there is nothing at element i, 0 is returned. */ template arma_inline arma_warn_unused SpValProxy > SpMat::operator[](const uword i) { return get_value(i); } template arma_inline arma_warn_unused eT SpMat::operator[](const uword i) const { return get_value(i); } template arma_inline arma_warn_unused SpValProxy > SpMat::at(const uword i) { return get_value(i); } template arma_inline arma_warn_unused eT SpMat::at(const uword i) const { return get_value(i); } template arma_inline arma_warn_unused SpValProxy > SpMat::operator()(const uword i) { arma_debug_check( (i >= n_elem), "SpMat::operator(): out of bounds"); return get_value(i); } template arma_inline arma_warn_unused eT SpMat::operator()(const uword i) const { arma_debug_check( (i >= n_elem), "SpMat::operator(): out of bounds"); return get_value(i); } /** * Element access; access the element at row in_rows and column in_col. * If there is nothing at that position, 0 is returned. */ template arma_inline arma_warn_unused SpValProxy > SpMat::at(const uword in_row, const uword in_col) { return get_value(in_row, in_col); } template arma_inline arma_warn_unused eT SpMat::at(const uword in_row, const uword in_col) const { return get_value(in_row, in_col); } template arma_inline arma_warn_unused SpValProxy > SpMat::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "SpMat::operator(): out of bounds"); return get_value(in_row, in_col); } template arma_inline arma_warn_unused eT SpMat::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "SpMat::operator(): out of bounds"); return get_value(in_row, in_col); } /** * Check if matrix is empty (no size, no values). */ template arma_inline arma_warn_unused bool SpMat::is_empty() const { return(n_elem == 0); } //! returns true if the object can be interpreted as a column or row vector template arma_inline arma_warn_unused bool SpMat::is_vec() const { return ( (n_rows == 1) || (n_cols == 1) ); } //! returns true if the object can be interpreted as a row vector template arma_inline arma_warn_unused bool SpMat::is_rowvec() const { return (n_rows == 1); } //! returns true if the object can be interpreted as a column vector template arma_inline arma_warn_unused bool SpMat::is_colvec() const { return (n_cols == 1); } //! returns true if the object has the same number of non-zero rows and columnns template arma_inline arma_warn_unused bool SpMat::is_square() const { return (n_rows == n_cols); } //! returns true if all of the elements are finite template inline arma_warn_unused bool SpMat::is_finite() const { arma_extra_debug_sigprint(); return arrayops::is_finite(values, n_nonzero); } template inline arma_warn_unused bool SpMat::has_inf() const { arma_extra_debug_sigprint(); return arrayops::has_inf(values, n_nonzero); } template inline arma_warn_unused bool SpMat::has_nan() const { arma_extra_debug_sigprint(); return arrayops::has_nan(values, n_nonzero); } //! returns true if the given index is currently in range template arma_inline arma_warn_unused bool SpMat::in_range(const uword i) const { return (i < n_elem); } //! returns true if the given start and end indices are currently in range template arma_inline arma_warn_unused bool SpMat::in_range(const span& x) const { arma_extra_debug_sigprint(); if(x.whole == true) { return true; } else { const uword a = x.a; const uword b = x.b; return ( (a <= b) && (b < n_elem) ); } } //! returns true if the given location is currently in range template arma_inline arma_warn_unused bool SpMat::in_range(const uword in_row, const uword in_col) const { return ( (in_row < n_rows) && (in_col < n_cols) ); } template arma_inline arma_warn_unused bool SpMat::in_range(const span& row_span, const uword in_col) const { arma_extra_debug_sigprint(); if(row_span.whole == true) { return (in_col < n_cols); } else { const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) ); } } template arma_inline arma_warn_unused bool SpMat::in_range(const uword in_row, const span& col_span) const { arma_extra_debug_sigprint(); if(col_span.whole == true) { return (in_row < n_rows); } else { const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); } } template arma_inline arma_warn_unused bool SpMat::in_range(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); return ( (rows_ok == true) && (cols_ok == true) ); } template arma_inline arma_warn_unused bool SpMat::in_range(const uword in_row, const uword in_col, const SizeMat& s) const { const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) ) { return false; } else { return true; } } template inline void SpMat::impl_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true); } template inline void SpMat::impl_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this, true); } template inline void SpMat::impl_raw_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false); } template inline void SpMat::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this, false); } /** * Matrix printing, prepends supplied text. * Prints 0 wherever no element exists. */ template inline void SpMat::impl_print_dense(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print_dense(ARMA_DEFAULT_OSTREAM, *this, true); } template inline void SpMat::impl_print_dense(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print_dense(user_stream, *this, true); } template inline void SpMat::impl_raw_print_dense(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print_dense(ARMA_DEFAULT_OSTREAM, *this, false); } template inline void SpMat::impl_raw_print_dense(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print_dense(user_stream, *this, false); } //! Set the size to the size of another matrix. template template inline void SpMat::copy_size(const SpMat& m) { arma_extra_debug_sigprint(); set_size(m.n_rows, m.n_cols); } template template inline void SpMat::copy_size(const Mat& m) { arma_extra_debug_sigprint(); set_size(m.n_rows, m.n_cols); } template inline void SpMat::set_size(const uword in_elem) { arma_extra_debug_sigprint(); // If this is a row vector, we resize to a row vector. if(vec_state == 2) { set_size(1, in_elem); } else { set_size(in_elem, 1); } } template inline void SpMat::set_size(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); if( (n_rows == in_rows) && (n_cols == in_cols) ) { return; } else { init(in_rows, in_cols); } } template inline void SpMat::set_size(const SizeMat& s) { arma_extra_debug_sigprint(); (*this).set_size(s.n_rows, s.n_cols); } template inline void SpMat::resize(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); if( (n_rows == in_rows) && (n_cols == in_cols) ) { return; } if( (n_elem == 0) || (n_nonzero == 0) ) { set_size(in_rows, in_cols); return; } SpMat tmp(in_rows, in_cols); if(tmp.n_elem > 0) { const uword last_row = (std::min)(in_rows, n_rows) - 1; const uword last_col = (std::min)(in_cols, n_cols) - 1; tmp.submat(0, 0, last_row, last_col) = (*this).submat(0, 0, last_row, last_col); } steal_mem(tmp); } template inline void SpMat::resize(const SizeMat& s) { arma_extra_debug_sigprint(); (*this).resize(s.n_rows, s.n_cols); } template inline void SpMat::reshape(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); arma_check( ((in_rows*in_cols) != n_elem), "SpMat::reshape(): changing the number of elements in a sparse matrix is currently not supported" ); if( (n_rows == in_rows) && (n_cols == in_cols) ) { return; } // We have to modify all of the relevant row indices and the relevant column pointers. // Iterate over all the points to do this. We won't be deleting any points, but we will be modifying // columns and rows. We'll have to store a new set of column vectors. uword* new_col_ptrs = memory::acquire(in_cols + 2); new_col_ptrs[in_cols + 1] = std::numeric_limits::max(); uword* new_row_indices = memory::acquire_chunked(n_nonzero + 1); access::rw(new_row_indices[n_nonzero]) = 0; arrayops::inplace_set(new_col_ptrs, uword(0), in_cols + 1); for(const_iterator it = begin(); it != end(); it++) { uword vector_position = (it.col() * n_rows) + it.row(); new_row_indices[it.pos()] = vector_position % in_rows; ++new_col_ptrs[vector_position / in_rows + 1]; } // Now sum the column counts to get the new column pointers. for(uword i = 1; i <= in_cols; i++) { access::rw(new_col_ptrs[i]) += new_col_ptrs[i - 1]; } // Copy the new row indices. memory::release(row_indices); access::rw(row_indices) = new_row_indices; memory::release(col_ptrs); access::rw(col_ptrs) = new_col_ptrs; // Now set the size. access::rw(n_rows) = in_rows; access::rw(n_cols) = in_cols; } template inline void SpMat::reshape(const SizeMat& s) { arma_extra_debug_sigprint(); (*this).reshape(s.n_rows, s.n_cols); } // this form is deprecated: don't use it template inline void SpMat::reshape(const uword in_rows, const uword in_cols, const uword dim) { arma_extra_debug_sigprint(); arma_debug_check( (dim > 1), "SpMat::reshape(): paramter 'dim' must be 0 or 1" ); if(dim == 0) { (*this).reshape(in_rows, in_cols); } else if(dim == 1) { arma_check( ((in_rows*in_cols) != n_elem), "SpMat::reshape(): changing the number of elements in a sparse matrix is currently not supported" ); // Row-wise reshaping. This is more tedious and we will use a separate sparse matrix to do it. SpMat tmp(in_rows, in_cols); for(const_row_iterator it = begin_row(); it.pos() < n_nonzero; it++) { uword vector_position = (it.row() * n_cols) + it.col(); tmp((vector_position / in_cols), (vector_position % in_cols)) = (*it); } steal_mem(tmp); } } template inline const SpMat& SpMat::zeros() { arma_extra_debug_sigprint(); if(n_nonzero != 0) { init(n_rows, n_cols); } return *this; } template inline const SpMat& SpMat::zeros(const uword in_elem) { arma_extra_debug_sigprint(); if(vec_state == 2) { zeros(1, in_elem); // Row vector } else { zeros(in_elem, 1); } return *this; } template inline const SpMat& SpMat::zeros(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); const bool already_done = ( (n_nonzero == 0) && (n_rows == in_rows) && (n_cols == in_cols) ); if(already_done == false) { init(in_rows, in_cols); } return *this; } template inline const SpMat& SpMat::zeros(const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).zeros(s.n_rows, s.n_cols); } template inline const SpMat& SpMat::eye() { arma_extra_debug_sigprint(); return (*this).eye(n_rows, n_cols); } template inline const SpMat& SpMat::eye(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); const uword N = (std::min)(in_rows, in_cols); zeros(in_rows, in_cols); mem_resize(N); arrayops::inplace_set(access::rwp(values), eT(1), N); for(uword i = 0; i < N; ++i) { access::rw(row_indices[i]) = i; } for(uword i = 0; i <= N; ++i) { access::rw(col_ptrs[i]) = i; } access::rw(n_nonzero) = N; return *this; } template inline const SpMat& SpMat::eye(const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).eye(s.n_rows, s.n_cols); } template inline const SpMat& SpMat::speye() { arma_extra_debug_sigprint(); return (*this).eye(n_rows, n_cols); } template inline const SpMat& SpMat::speye(const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); return (*this).eye(in_n_rows, in_n_cols); } template inline const SpMat& SpMat::speye(const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).eye(s.n_rows, s.n_cols); } template inline const SpMat& SpMat::sprandu(const uword in_rows, const uword in_cols, const double density) { arma_extra_debug_sigprint(); arma_debug_check( ( (density < double(0)) || (density > double(1)) ), "sprandu(): density must be in the [0,1] interval" ); zeros(in_rows, in_cols); mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) ); if(n_nonzero == 0) { return *this; } arma_rng::randu::fill( access::rwp(values), n_nonzero ); uvec indices = linspace( 0u, in_rows*in_cols-1, n_nonzero ); // perturb the indices for(uword i=1; i < n_nonzero-1; ++i) { const uword index_left = indices[i-1]; const uword index_right = indices[i+1]; const uword center = (index_left + index_right) / 2; const uword delta1 = center - index_left - 1; const uword delta2 = index_right - center - 1; const uword min_delta = (std::min)(delta1, delta2); uword index_new = uword( double(center) + double(min_delta) * (2.0*randu()-1.0) ); // paranoia, but better be safe than sorry if( (index_left < index_new) && (index_new < index_right) ) { indices[i] = index_new; } } uword cur_index = 0; uword count = 0; for(uword lcol = 0; lcol < in_cols; ++lcol) for(uword lrow = 0; lrow < in_rows; ++lrow) { if(count == indices[cur_index]) { access::rw(row_indices[cur_index]) = lrow; access::rw(col_ptrs[lcol + 1])++; ++cur_index; } ++count; } if(cur_index != n_nonzero) { // Fix size to correct size. mem_resize(cur_index); } // Sum column pointers. for(uword lcol = 1; lcol <= in_cols; ++lcol) { access::rw(col_ptrs[lcol]) += col_ptrs[lcol - 1]; } return *this; } template inline const SpMat& SpMat::sprandu(const SizeMat& s, const double density) { arma_extra_debug_sigprint(); return (*this).sprandu(s.n_rows, s.n_cols, density); } template inline const SpMat& SpMat::sprandn(const uword in_rows, const uword in_cols, const double density) { arma_extra_debug_sigprint(); arma_debug_check( ( (density < double(0)) || (density > double(1)) ), "sprandn(): density must be in the [0,1] interval" ); zeros(in_rows, in_cols); mem_resize( uword(density * double(in_rows) * double(in_cols) + 0.5) ); if(n_nonzero == 0) { return *this; } arma_rng::randn::fill( access::rwp(values), n_nonzero ); uvec indices = linspace( 0u, in_rows*in_cols-1, n_nonzero ); // perturb the indices for(uword i=1; i < n_nonzero-1; ++i) { const uword index_left = indices[i-1]; const uword index_right = indices[i+1]; const uword center = (index_left + index_right) / 2; const uword delta1 = center - index_left - 1; const uword delta2 = index_right - center - 1; const uword min_delta = (std::min)(delta1, delta2); uword index_new = uword( double(center) + double(min_delta) * (2.0*randu()-1.0) ); // paranoia, but better be safe than sorry if( (index_left < index_new) && (index_new < index_right) ) { indices[i] = index_new; } } uword cur_index = 0; uword count = 0; for(uword lcol = 0; lcol < in_cols; ++lcol) for(uword lrow = 0; lrow < in_rows; ++lrow) { if(count == indices[cur_index]) { access::rw(row_indices[cur_index]) = lrow; access::rw(col_ptrs[lcol + 1])++; ++cur_index; } ++count; } if(cur_index != n_nonzero) { // Fix size to correct size. mem_resize(cur_index); } // Sum column pointers. for(uword lcol = 1; lcol <= in_cols; ++lcol) { access::rw(col_ptrs[lcol]) += col_ptrs[lcol - 1]; } return *this; } template inline const SpMat& SpMat::sprandn(const SizeMat& s, const double density) { arma_extra_debug_sigprint(); return (*this).sprandn(s.n_rows, s.n_cols, density); } template inline void SpMat::reset() { arma_extra_debug_sigprint(); switch(vec_state) { default: init(0, 0); break; case 1: init(0, 1); break; case 2: init(1, 0); break; } } template template inline void SpMat::set_real(const SpBase::pod_type,T1>& X) { arma_extra_debug_sigprint(); SpMat_aux::set_real(*this, X); } template template inline void SpMat::set_imag(const SpBase::pod_type,T1>& X) { arma_extra_debug_sigprint(); SpMat_aux::set_imag(*this, X); } //! save the matrix to a file template inline bool SpMat::save(const std::string name, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { // case raw_ascii: // save_okay = diskio::save_raw_ascii(*this, name); // break; // case csv_ascii: // save_okay = diskio::save_csv_ascii(*this, name); // break; case arma_binary: save_okay = diskio::save_arma_binary(*this, name); break; case coord_ascii: save_okay = diskio::save_coord_ascii(*this, name); break; default: if(print_status) { arma_debug_warn("SpMat::save(): unsupported file type"); } save_okay = false; } if(print_status && (save_okay == false)) { arma_debug_warn("SpMat::save(): couldn't write to ", name); } return save_okay; } //! save the matrix to a stream template inline bool SpMat::save(std::ostream& os, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { // case raw_ascii: // save_okay = diskio::save_raw_ascii(*this, os); // break; // case csv_ascii: // save_okay = diskio::save_csv_ascii(*this, os); // break; case arma_binary: save_okay = diskio::save_arma_binary(*this, os); break; case coord_ascii: save_okay = diskio::save_coord_ascii(*this, os); break; default: if(print_status) { arma_debug_warn("SpMat::save(): unsupported file type"); } save_okay = false; } if(print_status && (save_okay == false)) { arma_debug_warn("SpMat::save(): couldn't write to the given stream"); } return save_okay; } //! load a matrix from a file template inline bool SpMat::load(const std::string name, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { // case auto_detect: // load_okay = diskio::load_auto_detect(*this, name, err_msg); // break; // case raw_ascii: // load_okay = diskio::load_raw_ascii(*this, name, err_msg); // break; // case csv_ascii: // load_okay = diskio::load_csv_ascii(*this, name, err_msg); // break; case arma_binary: load_okay = diskio::load_arma_binary(*this, name, err_msg); break; case coord_ascii: load_okay = diskio::load_coord_ascii(*this, name, err_msg); break; default: if(print_status) { arma_debug_warn("SpMat::load(): unsupported file type"); } load_okay = false; } if(print_status && (load_okay == false)) { if(err_msg.length() > 0) { arma_debug_warn("SpMat::load(): ", err_msg, name); } else { arma_debug_warn("SpMat::load(): couldn't read ", name); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! load a matrix from a stream template inline bool SpMat::load(std::istream& is, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { // case auto_detect: // load_okay = diskio::load_auto_detect(*this, is, err_msg); // break; // case raw_ascii: // load_okay = diskio::load_raw_ascii(*this, is, err_msg); // break; // case csv_ascii: // load_okay = diskio::load_csv_ascii(*this, is, err_msg); // break; case arma_binary: load_okay = diskio::load_arma_binary(*this, is, err_msg); break; case coord_ascii: load_okay = diskio::load_coord_ascii(*this, is, err_msg); break; default: if(print_status) { arma_debug_warn("SpMat::load(): unsupported file type"); } load_okay = false; } if(print_status && (load_okay == false)) { if(err_msg.length() > 0) { arma_debug_warn("SpMat::load(): ", err_msg, "the given stream"); } else { arma_debug_warn("SpMat::load(): couldn't load from the given stream"); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! save the matrix to a file, without printing any error messages template inline bool SpMat::quiet_save(const std::string name, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(name, type, false); } //! save the matrix to a stream, without printing any error messages template inline bool SpMat::quiet_save(std::ostream& os, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(os, type, false); } //! load a matrix from a file, without printing any error messages template inline bool SpMat::quiet_load(const std::string name, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(name, type, false); } //! load a matrix from a stream, without printing any error messages template inline bool SpMat::quiet_load(std::istream& is, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(is, type, false); } /** * Initialize the matrix to the specified size. Data is not preserved, so the matrix is assumed to be entirely sparse (empty). */ template inline void SpMat::init(uword in_rows, uword in_cols) { arma_extra_debug_sigprint(); // Verify that we are allowed to do this. if(vec_state > 0) { if((in_rows == 0) && (in_cols == 0)) { if(vec_state == 1) { in_cols = 1; } else if(vec_state == 2) { in_rows = 1; } } else { arma_debug_check ( ( ((vec_state == 1) && (in_cols != 1)) || ((vec_state == 2) && (in_rows != 1)) ), "SpMat::init(): object is a row or column vector; requested size is not compatible" ); } } #if (defined(ARMA_USE_CXX11) || defined(ARMA_64BIT_WORD)) const char* error_message = "SpMat::init(): requested size is too large"; #else const char* error_message = "SpMat::init(): requested size is too large; suggest to compile in C++11 mode or enable ARMA_64BIT_WORD"; #endif // Ensure that n_elem can hold the result of (n_rows * n_cols) arma_debug_check ( ( ( (in_rows > ARMA_MAX_UHWORD) || (in_cols > ARMA_MAX_UHWORD) ) ? ( (double(in_rows) * double(in_cols)) > double(ARMA_MAX_UWORD) ) : false ), error_message ); // Clean out the existing memory. if (values) { memory::release(values); memory::release(row_indices); } access::rw(values) = memory::acquire_chunked (1); access::rw(row_indices) = memory::acquire_chunked(1); access::rw(values[0]) = 0; access::rw(row_indices[0]) = 0; memory::release(col_ptrs); // Set the new size accordingly. access::rw(n_rows) = in_rows; access::rw(n_cols) = in_cols; access::rw(n_elem) = (in_rows * in_cols); access::rw(n_nonzero) = 0; // Try to allocate the column pointers, filling them with 0, // except for the last element which contains the maximum possible element // (so iterators terminate correctly). access::rw(col_ptrs) = memory::acquire(in_cols + 2); arrayops::inplace_set(access::rwp(col_ptrs), uword(0), in_cols + 1); access::rw(col_ptrs[in_cols + 1]) = std::numeric_limits::max(); } /** * Initialize the matrix from a string. */ template inline void SpMat::init(const std::string& text) { arma_extra_debug_sigprint(); // Figure out the size first. uword t_n_rows = 0; uword t_n_cols = 0; bool t_n_cols_found = false; std::string token; std::string::size_type line_start = 0; std::string::size_type line_end = 0; while (line_start < text.length()) { line_end = text.find(';', line_start); if (line_end == std::string::npos) line_end = text.length() - 1; std::string::size_type line_len = line_end - line_start + 1; std::stringstream line_stream(text.substr(line_start, line_len)); // Step through each column. uword line_n_cols = 0; while (line_stream >> token) { ++line_n_cols; } if (line_n_cols > 0) { if (t_n_cols_found == false) { t_n_cols = line_n_cols; t_n_cols_found = true; } else // Check it each time through, just to make sure. arma_check((line_n_cols != t_n_cols), "SpMat::init(): inconsistent number of columns in given string"); ++t_n_rows; } line_start = line_end + 1; } zeros(t_n_rows, t_n_cols); // Second time through will pick up all the values. line_start = 0; line_end = 0; uword lrow = 0; while (line_start < text.length()) { line_end = text.find(';', line_start); if (line_end == std::string::npos) line_end = text.length() - 1; std::string::size_type line_len = line_end - line_start + 1; std::stringstream line_stream(text.substr(line_start, line_len)); uword lcol = 0; eT val; while (line_stream >> val) { // Only add nonzero elements. if (val != eT(0)) { get_value(lrow, lcol) = val; } ++lcol; } ++lrow; line_start = line_end + 1; } } /** * Copy from another matrix. */ template inline void SpMat::init(const SpMat& x) { arma_extra_debug_sigprint(); // Ensure we are not initializing to ourselves. if (this != &x) { init(x.n_rows, x.n_cols); // values and row_indices may not be null. if (values != NULL) { memory::release(values); memory::release(row_indices); } access::rw(values) = memory::acquire_chunked (x.n_nonzero + 1); access::rw(row_indices) = memory::acquire_chunked(x.n_nonzero + 1); // Now copy over the elements. arrayops::copy(access::rwp(values), x.values, x.n_nonzero + 1); arrayops::copy(access::rwp(row_indices), x.row_indices, x.n_nonzero + 1); arrayops::copy(access::rwp(col_ptrs), x.col_ptrs, x.n_cols + 1); access::rw(n_nonzero) = x.n_nonzero; } } template inline void SpMat::init_batch_std(const Mat& locs, const Mat& vals, const bool sort_locations) { arma_extra_debug_sigprint(); // Resize to correct number of elements. mem_resize(vals.n_elem); // Reset column pointers to zero. arrayops::inplace_set(access::rwp(col_ptrs), uword(0), n_cols + 1); bool actually_sorted = true; if(sort_locations == true) { // sort_index() uses std::sort() which may use quicksort... so we better // make sure it's not already sorted before taking an O(N^2) sort penalty. for (uword i = 1; i < locs.n_cols; ++i) { const uword* locs_i = locs.colptr(i ); const uword* locs_im1 = locs.colptr(i-1); if( (locs_i[1] < locs_im1[1]) || (locs_i[1] == locs_im1[1] && locs_i[0] <= locs_im1[0]) ) { actually_sorted = false; break; } } if(actually_sorted == false) { // This may not be the fastest possible implementation but it maximizes code reuse. Col abslocs(locs.n_cols); for (uword i = 0; i < locs.n_cols; ++i) { const uword* locs_i = locs.colptr(i); abslocs[i] = locs_i[1] * n_rows + locs_i[0]; } uvec sorted_indices = sort_index(abslocs); // Ascending sort. // Now we add the elements in this sorted order. for (uword i = 0; i < sorted_indices.n_elem; ++i) { const uword* locs_i = locs.colptr( sorted_indices[i] ); arma_debug_check( ( (locs_i[0] >= n_rows) || (locs_i[1] >= n_cols) ), "SpMat::SpMat(): invalid row or column index" ); if(i > 0) { const uword* locs_im1 = locs.colptr( sorted_indices[i-1] ); arma_debug_check( ( (locs_i[1] == locs_im1[1]) && (locs_i[0] == locs_im1[0]) ), "SpMat::SpMat(): detected identical locations" ); } access::rw(values[i]) = vals[ sorted_indices[i] ]; access::rw(row_indices[i]) = locs_i[0]; access::rw(col_ptrs[ locs_i[1] + 1 ])++; } } } if( (sort_locations == false) || (actually_sorted == true) ) { // Now set the values and row indices correctly. // Increment the column pointers in each column (so they are column "counts"). for(uword i = 0; i < vals.n_elem; ++i) { const uword* locs_i = locs.colptr(i); arma_debug_check( ( (locs_i[0] >= n_rows) || (locs_i[1] >= n_cols) ), "SpMat::SpMat(): invalid row or column index" ); if(i > 0) { const uword* locs_im1 = locs.colptr(i-1); arma_debug_check ( ( (locs_i[1] < locs_im1[1]) || (locs_i[1] == locs_im1[1] && locs_i[0] < locs_im1[0]) ), "SpMat::SpMat(): out of order points; either pass sort_locations = true, or sort points in column-major ordering" ); arma_debug_check( ( (locs_i[1] == locs_im1[1]) && (locs_i[0] == locs_im1[0]) ), "SpMat::SpMat(): detected identical locations" ); } access::rw(values[i]) = vals[i]; access::rw(row_indices[i]) = locs_i[0]; access::rw(col_ptrs[ locs_i[1] + 1 ])++; } } // Now fix the column pointers. for (uword i = 0; i < n_cols; ++i) { access::rw(col_ptrs[i + 1]) += col_ptrs[i]; } } template inline void SpMat::init_batch_add(const Mat& locs, const Mat& vals, const bool sort_locations) { arma_extra_debug_sigprint(); if(locs.n_cols < 2) { init_batch_std(locs, vals, false); return; } // Reset column pointers to zero. arrayops::inplace_set(access::rwp(col_ptrs), uword(0), n_cols + 1); bool actually_sorted = true; if(sort_locations == true) { // sort_index() uses std::sort() which may use quicksort... so we better // make sure it's not already sorted before taking an O(N^2) sort penalty. for (uword i = 1; i < locs.n_cols; ++i) { const uword* locs_i = locs.colptr(i ); const uword* locs_im1 = locs.colptr(i-1); if( (locs_i[1] < locs_im1[1]) || (locs_i[1] == locs_im1[1] && locs_i[0] <= locs_im1[0]) ) { actually_sorted = false; break; } } if(actually_sorted == false) { // This may not be the fastest possible implementation but it maximizes code reuse. Col abslocs(locs.n_cols); for (uword i = 0; i < locs.n_cols; ++i) { const uword* locs_i = locs.colptr(i); abslocs[i] = locs_i[1] * n_rows + locs_i[0]; } uvec sorted_indices = sort_index(abslocs); // Ascending sort. // work out the number of unique elments uword n_unique = 1; // first element is unique for(uword i=1; i < sorted_indices.n_elem; ++i) { const uword* locs_i = locs.colptr( sorted_indices[i ] ); const uword* locs_im1 = locs.colptr( sorted_indices[i-1] ); if( (locs_i[1] != locs_im1[1]) || (locs_i[0] != locs_im1[0]) ) { ++n_unique; } } // resize to correct number of elements mem_resize(n_unique); // Now we add the elements in this sorted order. uword count = 0; // first element { const uword i = 0; const uword* locs_i = locs.colptr( sorted_indices[i] ); arma_debug_check( ( (locs_i[0] >= n_rows) || (locs_i[1] >= n_cols) ), "SpMat::SpMat(): invalid row or column index" ); access::rw(values[count]) = vals[ sorted_indices[i] ]; access::rw(row_indices[count]) = locs_i[0]; access::rw(col_ptrs[ locs_i[1] + 1 ])++; } for(uword i=1; i < sorted_indices.n_elem; ++i) { const uword* locs_i = locs.colptr( sorted_indices[i ] ); const uword* locs_im1 = locs.colptr( sorted_indices[i-1] ); arma_debug_check( ( (locs_i[0] >= n_rows) || (locs_i[1] >= n_cols) ), "SpMat::SpMat(): invalid row or column index" ); if( (locs_i[1] == locs_im1[1]) && (locs_i[0] == locs_im1[0]) ) { access::rw(values[count]) += vals[ sorted_indices[i] ]; } else { count++; access::rw(values[count]) = vals[ sorted_indices[i] ]; access::rw(row_indices[count]) = locs_i[0]; access::rw(col_ptrs[ locs_i[1] + 1 ])++; } } } } if( (sort_locations == false) || (actually_sorted == true) ) { // work out the number of unique elments uword n_unique = 1; // first element is unique for(uword i=1; i < locs.n_cols; ++i) { const uword* locs_i = locs.colptr(i ); const uword* locs_im1 = locs.colptr(i-1); if( (locs_i[1] != locs_im1[1]) || (locs_i[0] != locs_im1[0]) ) { ++n_unique; } } // resize to correct number of elements mem_resize(n_unique); // Now set the values and row indices correctly. // Increment the column pointers in each column (so they are column "counts"). uword count = 0; // first element { const uword i = 0; const uword* locs_i = locs.colptr(i); arma_debug_check( ( (locs_i[0] >= n_rows) || (locs_i[1] >= n_cols) ), "SpMat::SpMat(): invalid row or column index" ); access::rw(values[count]) = vals[i]; access::rw(row_indices[count]) = locs_i[0]; access::rw(col_ptrs[ locs_i[1] + 1 ])++; } for(uword i=1; i < locs.n_cols; ++i) { const uword* locs_i = locs.colptr(i ); const uword* locs_im1 = locs.colptr(i-1); arma_debug_check( ( (locs_i[0] >= n_rows) || (locs_i[1] >= n_cols) ), "SpMat::SpMat(): invalid row or column index" ); arma_debug_check ( ( (locs_i[1] < locs_im1[1]) || (locs_i[1] == locs_im1[1] && locs_i[0] < locs_im1[0]) ), "SpMat::SpMat(): out of order points; either pass sort_locations = true, or sort points in column-major ordering" ); if( (locs_i[1] == locs_im1[1]) && (locs_i[0] == locs_im1[0]) ) { access::rw(values[count]) += vals[i]; } else { count++; access::rw(values[count]) = vals[i]; access::rw(row_indices[count]) = locs_i[0]; access::rw(col_ptrs[ locs_i[1] + 1 ])++; } } } // Now fix the column pointers. for (uword i = 0; i < n_cols; ++i) { access::rw(col_ptrs[i + 1]) += col_ptrs[i]; } } template inline void SpMat::mem_resize(const uword new_n_nonzero) { arma_extra_debug_sigprint(); if(n_nonzero != new_n_nonzero) { if(new_n_nonzero == 0) { memory::release(values); memory::release(row_indices); access::rw(values) = memory::acquire_chunked (1); access::rw(row_indices) = memory::acquire_chunked(1); access::rw( values[0]) = 0; access::rw(row_indices[0]) = 0; } else { // Figure out the actual amount of memory currently allocated // NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero); if(n_alloc < new_n_nonzero) { eT* new_values = memory::acquire_chunked (new_n_nonzero + 1); uword* new_row_indices = memory::acquire_chunked(new_n_nonzero + 1); if(n_nonzero > 0) { // Copy old elements. uword copy_len = std::min(n_nonzero, new_n_nonzero); arrayops::copy(new_values, values, copy_len); arrayops::copy(new_row_indices, row_indices, copy_len); } memory::release(values); memory::release(row_indices); access::rw(values) = new_values; access::rw(row_indices) = new_row_indices; } // Set the "fake end" of the matrix by setting the last value and row // index to 0. This helps the iterators work correctly. access::rw( values[new_n_nonzero]) = 0; access::rw(row_indices[new_n_nonzero]) = 0; } access::rw(n_nonzero) = new_n_nonzero; } } template inline void SpMat::remove_zeros() { arma_extra_debug_sigprint(); const uword old_n_nonzero = n_nonzero; uword new_n_nonzero = 0; const eT* old_values = values; for(uword i=0; i < old_n_nonzero; ++i) { new_n_nonzero += (old_values[i] != eT(0)) ? uword(1) : uword(0); } if(new_n_nonzero != old_n_nonzero) { if(new_n_nonzero == 0) { init(n_rows, n_cols); return; } SpMat tmp(n_rows, n_cols); tmp.mem_resize(new_n_nonzero); uword new_index = 0; const_iterator it = begin(); const_iterator it_end = end(); for(; it != it_end; ++it) { const eT val = eT(*it); if(val != eT(0)) { access::rw(tmp.values[new_index]) = val; access::rw(tmp.row_indices[new_index]) = it.row(); access::rw(tmp.col_ptrs[it.col() + 1])++; ++new_index; } } for(uword i=0; i < n_cols; ++i) { access::rw(tmp.col_ptrs[i + 1]) += tmp.col_ptrs[i]; } steal_mem(tmp); } } // Steal memory from another matrix. template inline void SpMat::steal_mem(SpMat& x) { arma_extra_debug_sigprint(); if(this != &x) { if(values ) { memory::release(access::rw(values)); } if(row_indices) { memory::release(access::rw(row_indices)); } if(col_ptrs ) { memory::release(access::rw(col_ptrs)); } access::rw(n_rows) = x.n_rows; access::rw(n_cols) = x.n_cols; access::rw(n_elem) = x.n_elem; access::rw(n_nonzero) = x.n_nonzero; access::rw(values) = x.values; access::rw(row_indices) = x.row_indices; access::rw(col_ptrs) = x.col_ptrs; // Set other matrix to empty. access::rw(x.n_rows) = 0; access::rw(x.n_cols) = 0; access::rw(x.n_elem) = 0; access::rw(x.n_nonzero) = 0; access::rw(x.values) = NULL; access::rw(x.row_indices) = NULL; access::rw(x.col_ptrs) = NULL; } } template template arma_hot inline void SpMat::init_xform(const SpBase& A, const Functor& func) { arma_extra_debug_sigprint(); // if possible, avoid doing a copy and instead apply func to the generated elements if(SpProxy::Q_created_by_proxy) { (*this) = A.get_ref(); const uword nnz = n_nonzero; eT* t_values = access::rwp(values); for(uword i=0; i < nnz; ++i) { t_values[i] = func(t_values[i]); } remove_zeros(); } else { init_xform_mt(A.get_ref(), func); } } template template arma_hot inline void SpMat::init_xform_mt(const SpBase& A, const Functor& func) { arma_extra_debug_sigprint(); const SpProxy P(A.get_ref()); if( (P.is_alias(*this) == true) || (is_SpMat::stored_type>::value == true) ) { // NOTE: unwrap_spmat will convert a submatrix to a matrix, which in effect takes care of aliasing with submatrices; // NOTE: however, when more delayed ops are implemented, more elaborate handling of aliasing will be necessary const unwrap_spmat::stored_type> tmp(P.Q); const SpMat& x = tmp.M; if(void_ptr(this) != void_ptr(&x)) { init(x.n_rows, x.n_cols); // values and row_indices may not be null. if(values != NULL) { memory::release(values); memory::release(row_indices); } access::rw(values) = memory::acquire_chunked (x.n_nonzero + 1); access::rw(row_indices) = memory::acquire_chunked(x.n_nonzero + 1); arrayops::copy(access::rwp(row_indices), x.row_indices, x.n_nonzero + 1); arrayops::copy(access::rwp(col_ptrs), x.col_ptrs, x.n_cols + 1); access::rw(n_nonzero) = x.n_nonzero; } // initialise the elements array with a transformed version of the elements from x const uword nnz = n_nonzero; const eT2* x_values = x.values; eT* t_values = access::rwp(values); for(uword i=0; i < nnz; ++i) { t_values[i] = func(x_values[i]); // NOTE: func() must produce a value of type eT (ie. act as a convertor between eT2 and eT) } } else { init(P.get_n_rows(), P.get_n_cols()); mem_resize(P.get_n_nonzero()); typename SpProxy::const_iterator_type it = P.begin(); typename SpProxy::const_iterator_type it_end = P.end(); while(it != it_end) { access::rw(row_indices[it.pos()]) = it.row(); access::rw(values[it.pos()]) = func(*it); // NOTE: func() must produce a value of type eT (ie. act as a convertor between eT2 and eT) ++access::rw(col_ptrs[it.col() + 1]); ++it; } // Now sum column pointers. for(uword c = 1; c <= n_cols; ++c) { access::rw(col_ptrs[c]) += col_ptrs[c - 1]; } } remove_zeros(); } template inline typename SpMat::iterator SpMat::begin() { return iterator(*this); } template inline typename SpMat::const_iterator SpMat::begin() const { return const_iterator(*this); } template inline typename SpMat::iterator SpMat::end() { return iterator(*this, 0, n_cols, n_nonzero); } template inline typename SpMat::const_iterator SpMat::end() const { return const_iterator(*this, 0, n_cols, n_nonzero); } template inline typename SpMat::iterator SpMat::begin_col(const uword col_num) { return iterator(*this, 0, col_num); } template inline typename SpMat::const_iterator SpMat::begin_col(const uword col_num) const { return const_iterator(*this, 0, col_num); } template inline typename SpMat::iterator SpMat::end_col(const uword col_num) { return iterator(*this, 0, col_num + 1); } template inline typename SpMat::const_iterator SpMat::end_col(const uword col_num) const { return const_iterator(*this, 0, col_num + 1); } template inline typename SpMat::row_iterator SpMat::begin_row(const uword row_num) { return row_iterator(*this, row_num, 0); } template inline typename SpMat::const_row_iterator SpMat::begin_row(const uword row_num) const { return const_row_iterator(*this, row_num, 0); } template inline typename SpMat::row_iterator SpMat::end_row() { return row_iterator(*this, n_nonzero); } template inline typename SpMat::const_row_iterator SpMat::end_row() const { return const_row_iterator(*this, n_nonzero); } template inline typename SpMat::row_iterator SpMat::end_row(const uword row_num) { return row_iterator(*this, row_num + 1, 0); } template inline typename SpMat::const_row_iterator SpMat::end_row(const uword row_num) const { return const_row_iterator(*this, row_num + 1, 0); } template inline typename SpMat::row_col_iterator SpMat::begin_row_col() { return begin(); } template inline typename SpMat::const_row_col_iterator SpMat::begin_row_col() const { return begin(); } template inline typename SpMat::row_col_iterator SpMat::end_row_col() { return end(); } template inline typename SpMat::const_row_col_iterator SpMat::end_row_col() const { return end(); } template inline void SpMat::clear() { (*this).reset(); } template inline bool SpMat::empty() const { return (n_elem == 0); } template inline uword SpMat::size() const { return n_elem; } template inline arma_hot arma_warn_unused SpValProxy > SpMat::get_value(const uword i) { // First convert to the actual location. uword lcol = i / n_rows; // Integer division. uword lrow = i % n_rows; return get_value(lrow, lcol); } template inline arma_hot arma_warn_unused eT SpMat::get_value(const uword i) const { // First convert to the actual location. uword lcol = i / n_rows; // Integer division. uword lrow = i % n_rows; return get_value(lrow, lcol); } template inline arma_hot arma_warn_unused SpValProxy > SpMat::get_value(const uword in_row, const uword in_col) { const uword colptr = col_ptrs[in_col]; const uword next_colptr = col_ptrs[in_col + 1]; // Step through the row indices to see if our element exists. for (uword i = colptr; i < next_colptr; ++i) { const uword row_index = row_indices[i]; // First check that we have not stepped past it. if (in_row < row_index) // If we have, then it doesn't exist: return 0. { return SpValProxy >(in_row, in_col, *this); // Proxy for a zero value. } // Now check if we are at the correct place. if (in_row == row_index) // If we are, return a reference to the value. { return SpValProxy >(in_row, in_col, *this, &access::rw(values[i])); } } // We did not find it, so it does not exist: return 0. return SpValProxy >(in_row, in_col, *this); } template inline arma_hot arma_warn_unused eT SpMat::get_value(const uword in_row, const uword in_col) const { const uword colptr = col_ptrs[in_col]; const uword next_colptr = col_ptrs[in_col + 1]; // Step through the row indices to see if our element exists. for (uword i = colptr; i < next_colptr; ++i) { const uword row_index = row_indices[i]; // First check that we have not stepped past it. if (in_row < row_index) // If we have, then it doesn't exist: return 0. { return eT(0); } // Now check if we are at the correct place. if (in_row == row_index) // If we are, return the value. { return values[i]; } } // We did not find it, so it does not exist: return 0. return eT(0); } /** * Given the index representing which of the nonzero values this is, return its * actual location, either in row/col or just the index. */ template arma_hot arma_inline arma_warn_unused uword SpMat::get_position(const uword i) const { uword lrow, lcol; get_position(i, lrow, lcol); // Assemble the row/col into the element's location in the matrix. return (lrow + n_rows * lcol); } template arma_hot arma_inline void SpMat::get_position(const uword i, uword& row_of_i, uword& col_of_i) const { arma_debug_check((i >= n_nonzero), "SpMat::get_position(): index out of bounds"); col_of_i = 0; while (col_ptrs[col_of_i + 1] <= i) { col_of_i++; } row_of_i = row_indices[i]; return; } /** * Add an element at the given position, and return a reference to it. The * element will be set to 0 (unless otherwise specified). If the element * already exists, its value will be overwritten. * * @param in_row Row of new element. * @param in_col Column of new element. * @param in_val Value to set new element to (default 0.0). */ template inline arma_hot arma_warn_unused eT& SpMat::add_element(const uword in_row, const uword in_col, const eT val) { arma_extra_debug_sigprint(); // We will assume the new element does not exist and begin the search for // where to insert it. If we find that it already exists, we will then // overwrite it. uword colptr = col_ptrs[in_col ]; uword next_colptr = col_ptrs[in_col + 1]; uword pos = colptr; // The position in the matrix of this value. if (colptr != next_colptr) { // There are other elements in this column, so we must find where this // element will fit as compared to those. while (pos < next_colptr && in_row > row_indices[pos]) { pos++; } // We aren't inserting into the last position, so it is still possible // that the element may exist. if (pos != next_colptr && row_indices[pos] == in_row) { // It already exists. Then, just overwrite it. access::rw(values[pos]) = val; return access::rw(values[pos]); } } // // Element doesn't exist, so we have to insert it // // We have to update the rest of the column pointers. for (uword i = in_col + 1; i < n_cols + 1; i++) { access::rw(col_ptrs[i])++; // We are only inserting one new element. } // Figure out the actual amount of memory currently allocated // NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays const uword n_alloc = memory::enlarge_to_mult_of_chunksize(n_nonzero + 1); // If possible, avoid time-consuming memory allocation if(n_alloc > (n_nonzero + 1)) { arrayops::copy_backwards(access::rwp(values) + pos + 1, values + pos, (n_nonzero - pos) + 1); arrayops::copy_backwards(access::rwp(row_indices) + pos + 1, row_indices + pos, (n_nonzero - pos) + 1); // Insert the new element. access::rw(values[pos]) = val; access::rw(row_indices[pos]) = in_row; access::rw(n_nonzero)++; } else { const uword old_n_nonzero = n_nonzero; access::rw(n_nonzero)++; // Add to count of nonzero elements. // Allocate larger memory. eT* new_values = memory::acquire_chunked (n_nonzero + 1); uword* new_row_indices = memory::acquire_chunked(n_nonzero + 1); // Copy things over, before the new element. if (pos > 0) { arrayops::copy(new_values, values, pos); arrayops::copy(new_row_indices, row_indices, pos); } // Insert the new element. new_values[pos] = val; new_row_indices[pos] = in_row; // Copy the rest of things over (including the extra element at the end). arrayops::copy(new_values + pos + 1, values + pos, (old_n_nonzero - pos) + 1); arrayops::copy(new_row_indices + pos + 1, row_indices + pos, (old_n_nonzero - pos) + 1); // Assign new pointers. memory::release(values); memory::release(row_indices); access::rw(values) = new_values; access::rw(row_indices) = new_row_indices; } return access::rw(values[pos]); } /** * Delete an element at the given position. * * @param in_row Row of element to be deleted. * @param in_col Column of element to be deleted. */ template inline arma_hot void SpMat::delete_element(const uword in_row, const uword in_col) { arma_extra_debug_sigprint(); // We assume the element exists (although... it may not) and look for its // exact position. If it doesn't exist... well, we don't need to do anything. uword colptr = col_ptrs[in_col]; uword next_colptr = col_ptrs[in_col + 1]; if (colptr != next_colptr) { // There's at least one element in this column. // Let's see if we are one of them. for (uword pos = colptr; pos < next_colptr; pos++) { if (in_row == row_indices[pos]) { const uword old_n_nonzero = n_nonzero; --access::rw(n_nonzero); // Remove one from the count of nonzero elements. // Found it. Now remove it. // Figure out the actual amount of memory currently allocated and the actual amount that will be required // NOTE: this relies on memory::acquire_chunked() being used for the 'values' and 'row_indices' arrays const uword n_alloc = memory::enlarge_to_mult_of_chunksize(old_n_nonzero + 1); const uword n_alloc_mod = memory::enlarge_to_mult_of_chunksize(n_nonzero + 1); // If possible, avoid time-consuming memory allocation if(n_alloc_mod == n_alloc) { if (pos < n_nonzero) // remember, we decremented n_nonzero { arrayops::copy_forwards(access::rwp(values) + pos, values + pos + 1, (n_nonzero - pos) + 1); arrayops::copy_forwards(access::rwp(row_indices) + pos, row_indices + pos + 1, (n_nonzero - pos) + 1); } } else { // Make new arrays. eT* new_values = memory::acquire_chunked (n_nonzero + 1); uword* new_row_indices = memory::acquire_chunked(n_nonzero + 1); if (pos > 0) { arrayops::copy(new_values, values, pos); arrayops::copy(new_row_indices, row_indices, pos); } arrayops::copy(new_values + pos, values + pos + 1, (n_nonzero - pos) + 1); arrayops::copy(new_row_indices + pos, row_indices + pos + 1, (n_nonzero - pos) + 1); memory::release(values); memory::release(row_indices); access::rw(values) = new_values; access::rw(row_indices) = new_row_indices; } // And lastly, update all the column pointers (decrement by one). for (uword i = in_col + 1; i < n_cols + 1; i++) { --access::rw(col_ptrs[i]); // We only removed one element. } return; // There is nothing left to do. } } } return; // The element does not exist, so there's nothing for us to do. } template inline void SpMat_aux::set_real(SpMat& out, const SpBase& X) { arma_extra_debug_sigprint(); const unwrap_spmat tmp(X.get_ref()); const SpMat& A = tmp.M; arma_debug_assert_same_size( out, A, "SpMat::set_real()" ); out = A; } template inline void SpMat_aux::set_imag(SpMat&, const SpBase&) { arma_extra_debug_sigprint(); } template inline void SpMat_aux::set_real(SpMat< std::complex >& out, const SpBase& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const unwrap_spmat U(X.get_ref()); const SpMat& Y = U.M; arma_debug_assert_same_size(out, Y, "SpMat::set_real()"); SpMat tmp(Y,arma::imag(out)); // arma:: prefix required due to bugs in GCC 4.4 - 4.6 out.steal_mem(tmp); } template inline void SpMat_aux::set_imag(SpMat< std::complex >& out, const SpBase& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const unwrap_spmat U(X.get_ref()); const SpMat& Y = U.M; arma_debug_assert_same_size(out, Y, "SpMat::set_imag()"); SpMat tmp(arma::real(out),Y); // arma:: prefix required due to bugs in GCC 4.4 - 4.6 out.steal_mem(tmp); } #ifdef ARMA_EXTRA_SPMAT_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPMAT_MEAT) #endif //! @} armadillo-6.500.5/include/armadillo_bits/op_cor_meat.hpp0000666000000000000000000000430312620272703021746 0ustar rootroot// Copyright (C) 2009-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_cor //! @{ template inline void op_cor::direct_cor(Mat& out, const Mat& A, const uword norm_type) { arma_extra_debug_sigprint(); if(A.is_empty()) { out.reset(); return; } if(A.is_vec()) { out.set_size(1,1); out[0] = eT(1); } else { const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); const Row acc = sum(A); const Row sd = stddev(A); out = (trans(A) * A); out -= (trans(acc) * acc)/eT(N); out /= norm_val; out /= trans(sd) * sd; } } template inline void op_cor::direct_cor(Mat< std::complex >& out, const Mat< std::complex >& A, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(A.is_empty()) { out.reset(); return; } if(A.is_vec()) { out.set_size(1,1); out[0] = eT(1); } else { const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); const Row acc = sum(A); const Row sd = stddev(A); out = trans(A) * A; // out = strans(conj(A)) * A; out -= (trans(acc) * acc)/eT(N); // out -= (strans(conj(acc)) * acc)/eT(N); out /= norm_val; //out = out / (trans(sd) * sd); out /= conv_to< Mat >::from(trans(sd) * sd); } } template inline void op_cor::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& A = tmp.M; const uword norm_type = in.aux_uword_a; op_cor::direct_cor(out, A, norm_type); } //! @} armadillo-6.500.5/include/armadillo_bits/glue_max_bones.hpp0000666000000000000000000000161612620272703022452 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_max //! @{ class glue_max { public: template inline static void apply(Mat< eT >& out, const Proxy& PA, const Proxy& PB); template inline static void apply(Mat< std::complex >& out, const Proxy& PA, const Proxy& PB); template inline static void apply(Mat& out, const Glue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_vectorise.hpp0000666000000000000000000000237112620272703022150 0ustar rootroot// Copyright (C) 2013-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_vectorise //! @{ template inline typename enable_if2 < is_arma_type::value, const Op >::result vectorise(const T1& X) { arma_extra_debug_sigprint(); return Op(X); } template inline typename enable_if2 < is_arma_type::value, const Op >::result vectorise(const T1& X, const uword dim) { arma_extra_debug_sigprint(); arma_debug_check( (dim > 1), "vectorise(): parameter 'dim' must be 0 or 1" ); return Op(X, dim, 0); } template inline Col vectorise(const BaseCube& X) { arma_extra_debug_sigprint(); Col out; op_vectorise_cube_col::apply(out, X); return out; } //! @} armadillo-6.500.5/include/armadillo_bits/SpProxy.hpp0000666000000000000000000004023712620272703021111 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup SpProxy //! @{ template class SpProxy< SpMat > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef SpMat stored_type; typedef typename SpMat::const_iterator const_iterator_type; typedef typename SpMat::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const SpMat& Q; inline explicit SpProxy(const SpMat& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } }; template class SpProxy< SpCol > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef SpCol stored_type; typedef typename SpCol::const_iterator const_iterator_type; typedef typename SpCol::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const SpCol& Q; inline explicit SpProxy(const SpCol& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword) const { return Q.begin(); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } }; template class SpProxy< SpRow > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef SpRow stored_type; typedef typename SpRow::const_iterator const_iterator_type; typedef typename SpRow::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = false; static const bool is_row = true; static const bool is_col = false; arma_aligned const SpRow& Q; inline explicit SpProxy(const SpRow& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } }; template class SpProxy< SpSubview > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef SpSubview stored_type; typedef typename SpSubview::const_iterator const_iterator_type; typedef typename SpSubview::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = true; static const bool Q_created_by_proxy = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const SpSubview& Q; inline explicit SpProxy(const SpSubview& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.m.values; } arma_inline const uword* get_row_indices() const { return Q.m.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.m.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat& X) const { return (void_ptr(&Q.m) == void_ptr(&X)); } }; template class SpProxy< SpOp > { public: typedef typename T1::elem_type elem_type; typedef typename T1::elem_type eT; typedef typename get_pod_type::result pod_type; typedef SpMat stored_type; typedef typename SpMat::const_iterator const_iterator_type; typedef typename SpMat::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = true; static const bool is_row = SpOp::is_row; static const bool is_col = SpOp::is_col; arma_aligned const SpMat Q; inline explicit SpProxy(const SpOp& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat&) const { return false; } }; template class SpProxy< SpGlue > { public: typedef typename T1::elem_type elem_type; typedef typename T1::elem_type eT; typedef typename get_pod_type::result pod_type; typedef SpMat stored_type; typedef typename SpMat::const_iterator const_iterator_type; typedef typename SpMat::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = true; static const bool is_row = SpGlue::is_row; static const bool is_col = SpGlue::is_col; arma_aligned const SpMat Q; inline explicit SpProxy(const SpGlue& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat&) const { return false; } }; template class SpProxy< mtSpOp > { public: typedef out_eT elem_type; typedef typename T1::elem_type eT; typedef typename get_pod_type::result pod_type; typedef SpMat stored_type; typedef typename SpMat::const_iterator const_iterator_type; typedef typename SpMat::const_row_iterator const_row_iterator_type; static const bool must_use_iterator = false; static const bool Q_created_by_proxy = true; static const bool is_row = mtSpOp::is_row; static const bool is_col = mtSpOp::is_col; arma_aligned const SpMat Q; inline explicit SpProxy(const mtSpOp& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline uword get_n_nonzero() const { return Q.n_nonzero; } arma_inline elem_type operator[](const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline const eT* get_values() const { return Q.values; } arma_inline const uword* get_row_indices() const { return Q.row_indices; } arma_inline const uword* get_col_ptrs() const { return Q.col_ptrs; } arma_inline const_iterator_type begin() const { return Q.begin(); } arma_inline const_iterator_type begin_col(const uword col_num) const { return Q.begin_col(col_num); } arma_inline const_row_iterator_type begin_row(const uword row_num = 0) const { return Q.begin_row(row_num); } arma_inline const_iterator_type end() const { return Q.end(); } arma_inline const_row_iterator_type end_row() const { return Q.end_row(); } arma_inline const_row_iterator_type end_row(const uword row_num) const { return Q.end_row(row_num); } template arma_inline bool is_alias(const SpMat&) const { return false; } }; //! @} armadillo-6.500.5/include/armadillo_bits/mtOpCube_meat.hpp0000666000000000000000000000374012620272703022207 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup mtOpCube //! @{ template inline mtOpCube::mtOpCube(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline mtOpCube::mtOpCube(const T1& in_m, const typename T1::elem_type in_aux) : m(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline mtOpCube::mtOpCube(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template inline mtOpCube::mtOpCube(const T1& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : m(in_m) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template inline mtOpCube::mtOpCube(const char junk, const T1& in_m, const out_eT in_aux) : m(in_m) , aux_out_eT(in_aux) { arma_extra_debug_sigprint(); arma_ignore(junk); } template inline mtOpCube::~mtOpCube() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/wall_clock_meat.hpp0000666000000000000000000000402212623320713022573 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup wall_clock //! @{ inline wall_clock::wall_clock() : valid(false) { arma_extra_debug_sigprint(); } inline wall_clock::~wall_clock() { arma_extra_debug_sigprint(); } inline void wall_clock::tic() { arma_extra_debug_sigprint(); #if defined(ARMA_USE_CXX11) && !defined(ARMA_DONT_USE_CXX11_CHRONO) { chrono_time1 = std::chrono::steady_clock::now(); valid = true; } #elif defined(ARMA_HAVE_GETTIMEOFDAY) { gettimeofday(&posix_time1, 0); valid = true; } #else { time1 = std::clock(); valid = true; } #endif } inline double wall_clock::toc() { arma_extra_debug_sigprint(); if(valid) { #if defined(ARMA_USE_CXX11) && !defined(ARMA_DONT_USE_CXX11_CHRONO) { const std::chrono::steady_clock::time_point chrono_time2 = std::chrono::steady_clock::now(); typedef std::chrono::duration duration_type; const duration_type chrono_span = std::chrono::duration_cast< duration_type >(chrono_time2 - chrono_time1); return chrono_span.count(); } #elif defined(ARMA_HAVE_GETTIMEOFDAY) { gettimeofday(&posix_time2, 0); const double tmp_time1 = posix_time1.tv_sec + posix_time1.tv_usec * 1.0e-6; const double tmp_time2 = posix_time2.tv_sec + posix_time2.tv_usec * 1.0e-6; return tmp_time2 - tmp_time1; } #else { std::clock_t time2 = std::clock(); std::clock_t diff = time2 - time1; return double(diff) / double(CLOCKS_PER_SEC); } #endif } else { return 0.0; } } //! @} armadillo-6.500.5/include/armadillo_bits/subview_cube_bones.hpp0000666000000000000000000001203412633721645023337 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_cube //! @{ //! Class for storing data required to construct or apply operations to a subcube //! (i.e. where the subcube starts and ends as well as a reference/pointer to the original cube), template class subview_cube : public BaseCube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; arma_aligned const Cube& m; const uword aux_row1; const uword aux_col1; const uword aux_slice1; const uword n_rows; const uword n_cols; const uword n_elem_slice; const uword n_slices; const uword n_elem; protected: arma_inline subview_cube(const Cube& in_m, const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices); public: inline ~subview_cube(); inline void operator= (const eT val); inline void operator+= (const eT val); inline void operator-= (const eT val); inline void operator*= (const eT val); inline void operator/= (const eT val); // deliberately returning void template inline void operator= (const BaseCube& x); template inline void operator+= (const BaseCube& x); template inline void operator-= (const BaseCube& x); template inline void operator%= (const BaseCube& x); template inline void operator/= (const BaseCube& x); inline void operator= (const subview_cube& x); inline void operator+= (const subview_cube& x); inline void operator-= (const subview_cube& x); inline void operator%= (const subview_cube& x); inline void operator/= (const subview_cube& x); template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); inline static void extract(Cube& out, const subview_cube& in); inline static void plus_inplace(Cube& out, const subview_cube& in); inline static void minus_inplace(Cube& out, const subview_cube& in); inline static void schur_inplace(Cube& out, const subview_cube& in); inline static void div_inplace(Cube& out, const subview_cube& in); inline static void extract(Mat& out, const subview_cube& in); inline static void plus_inplace(Mat& out, const subview_cube& in); inline static void minus_inplace(Mat& out, const subview_cube& in); inline static void schur_inplace(Mat& out, const subview_cube& in); inline static void div_inplace(Mat& out, const subview_cube& in); template inline void for_each(functor F); template inline void for_each(functor F) const; template inline void transform(functor F); template inline void imbue(functor F); #if defined(ARMA_USE_CXX11) inline void each_slice(const std::function< void( Mat&) >& F); inline void each_slice(const std::function< void(const Mat&) >& F) const; #endif inline void fill(const eT val); inline void zeros(); inline void ones(); inline void randu(); inline void randn(); inline arma_warn_unused bool is_finite() const; inline arma_warn_unused bool has_inf() const; inline arma_warn_unused bool has_nan() const; inline arma_warn_unused eT min() const; inline arma_warn_unused eT max() const; inline eT at_alt (const uword i) const; inline eT& operator[](const uword i); inline eT operator[](const uword i) const; inline eT& operator()(const uword i); inline eT operator()(const uword i) const; arma_inline eT& operator()(const uword in_row, const uword in_col, const uword in_slice); arma_inline eT operator()(const uword in_row, const uword in_col, const uword in_slice) const; arma_inline eT& at(const uword in_row, const uword in_col, const uword in_slice); arma_inline eT at(const uword in_row, const uword in_col, const uword in_slice) const; arma_inline eT* slice_colptr(const uword in_slice, const uword in_col); arma_inline const eT* slice_colptr(const uword in_slice, const uword in_col) const; inline bool check_overlap(const subview_cube& x) const; inline bool check_overlap(const Mat& x) const; private: friend class Mat; friend class Cube; subview_cube(); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_sum_meat.hpp0000666000000000000000000000631012620272703021767 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_sum //! @{ template arma_hot inline void op_sum::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "sum(): parameter 'dim' must be 0 or 1" ); const Proxy P(in.m); if(P.is_alias(out) == false) { op_sum::apply_noalias(out, P, dim); } else { Mat tmp; op_sum::apply_noalias(tmp, P, dim); out.steal_mem(tmp); } } template arma_hot inline void op_sum::apply_noalias(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); if(is_Mat::stored_type>::value) { op_sum::apply_noalias_unwrap(out, P, dim); } else { op_sum::apply_noalias_proxy(out, P, dim); } } template arma_hot inline void op_sum::apply_noalias_unwrap(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename Proxy::stored_type P_stored_type; const unwrap tmp(P.Q); const typename unwrap::stored_type& X = tmp.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { out.set_size(1, X_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col < X_n_cols; ++col) { out_mem[col] = arrayops::accumulate( X.colptr(col), X_n_rows ); } } else { out.zeros(X_n_rows, 1); eT* out_mem = out.memptr(); for(uword col=0; col < X_n_cols; ++col) { arrayops::inplace_plus( out_mem, X.colptr(col), X_n_rows ); } } } template arma_hot inline void op_sum::apply_noalias_proxy(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword P_n_rows = P.get_n_rows(); const uword P_n_cols = P.get_n_cols(); if(dim == 0) { out.set_size(1, P_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col < P_n_cols; ++col) { eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j < P_n_rows; i+=2, j+=2) { val1 += P.at(i,col); val2 += P.at(j,col); } if(i < P_n_rows) { val1 += P.at(i,col); } out_mem[col] = (val1 + val2); } } else { out.zeros(P_n_rows, 1); eT* out_mem = out.memptr(); for(uword col=0; col < P_n_cols; ++col) for(uword row=0; row < P_n_rows; ++row) { out_mem[row] += P.at(row,col); } } } //! @} armadillo-6.500.5/include/armadillo_bits/fn_chol.hpp0000666000000000000000000000312512620272703021070 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_chol //! @{ template inline typename enable_if2< is_supported_blas_type::value, const Op >::result chol ( const Base& X, const char* layout = "upper" ) { arma_extra_debug_sigprint(); const char sig = (layout != NULL) ? layout[0] : char(0); arma_debug_check( ((sig != 'u') && (sig != 'l')), "chol(): layout must be \"upper\" or \"lower\"" ); return Op(X.get_ref(), ((sig == 'u') ? 0 : 1), 0 ); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result chol ( Mat& out, const Base& X, const char* layout = "upper" ) { arma_extra_debug_sigprint(); const char sig = (layout != NULL) ? layout[0] : char(0); arma_debug_check( ((sig != 'u') && (sig != 'l')), "chol(): layout must be \"upper\" or \"lower\"" ); const bool status = auxlib::chol(out, X.get_ref(), ((sig == 'u') ? 0 : 1)); if(status == false) { out.reset(); arma_debug_warn("chol(): decomposition failed"); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/podarray_bones.hpp0000666000000000000000000000377012620272703022475 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup podarray //! @{ struct podarray_prealloc_n_elem { static const uword val = 16; }; //! A lightweight array for POD types. For internal use only! template class podarray { public: arma_aligned const uword n_elem; //!< number of elements held arma_aligned eT* mem; //!< pointer to memory used by the object protected: //! internal memory, to avoid calling the 'new' operator for small amounts of memory. arma_align_mem eT mem_local[ podarray_prealloc_n_elem::val ]; public: inline ~podarray(); inline podarray(); inline podarray (const podarray& x); inline const podarray& operator=(const podarray& x); arma_inline explicit podarray(const uword new_N); arma_inline explicit podarray(const eT* X, const uword new_N); template inline explicit podarray(const Proxy& P); arma_inline eT& operator[] (const uword i); arma_inline eT operator[] (const uword i) const; arma_inline eT& operator() (const uword i); arma_inline eT operator() (const uword i) const; inline void set_min_size(const uword min_n_elem); inline void set_size(const uword new_n_elem); inline void reset(); inline void fill(const eT val); inline void zeros(); inline void zeros(const uword new_n_elem); arma_inline eT* memptr(); arma_inline const eT* memptr() const; arma_hot inline void copy_row(const Mat& A, const uword row); protected: inline void init_cold(const uword new_n_elem); inline void init_warm(const uword new_n_elem); }; //! @} armadillo-6.500.5/include/armadillo_bits/distr_param.hpp0000666000000000000000000000164612620272703021773 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup distr_param //! @{ class distr_param { public: uword state; union { int a_int; double a_double; }; union { int b_int; double b_double; }; inline distr_param() : state(0) { } inline explicit distr_param(const int a, const int b) : state(1) , a_int(a) , b_int(b) { } inline explicit distr_param(const double a, const double b) : state(2) , a_double(a) , b_double(b) { } }; //! @} armadillo-6.500.5/include/armadillo_bits/glue_cor_meat.hpp0000666000000000000000000001044212620272703022265 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup glue_cor //! @{ template inline void glue_cor::direct_cor(Mat& out, const Mat& A, const Mat& B, const uword norm_type) { arma_extra_debug_sigprint(); if(A.is_empty() || B.is_empty() ) { out.reset(); return; } if(A.is_vec() && B.is_vec()) { arma_debug_check( (A.n_elem != B.n_elem), "cor(): the number of elements in the two vectors must match" ); const eT* A_ptr = A.memptr(); const eT* B_ptr = B.memptr(); eT A_acc = eT(0); eT B_acc = eT(0); eT out_acc = eT(0); const uword N = A.n_elem; for(uword i=0; i 1) ? eT(N-1) : eT(1) ) : eT(N); out.set_size(1,1); out[0] = out_acc/norm_val; const Mat stddev_A = (A.n_rows == 1) ? Mat(stddev(trans(A))) : Mat(stddev(A)); const Mat stddev_B = (B.n_rows == 1) ? Mat(stddev(trans(B))) : Mat(stddev(B)); out /= stddev_A * stddev_B; } else { arma_debug_assert_mul_size(A, B, true, false, "cor()"); const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out = trans(A) * B; out -= (trans(sum(A)) * sum(B))/eT(N); out /= norm_val; out /= trans(stddev(A)) * stddev(B); } } template inline void glue_cor::direct_cor(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(A.is_empty() || B.is_empty() ) { out.reset(); return; } if(A.is_vec() && B.is_vec()) { arma_debug_check( (A.n_elem != B.n_elem), "cor(): the number of elements in the two vectors must match" ); const eT* A_ptr = A.memptr(); const eT* B_ptr = B.memptr(); eT A_acc = eT(0); eT B_acc = eT(0); eT out_acc = eT(0); const uword N = A.n_elem; for(uword i=0; i 1) ? eT(N-1) : eT(1) ) : eT(N); out.set_size(1,1); out[0] = out_acc/norm_val; const Mat stddev_A = (A.n_rows == 1) ? Mat(stddev(trans(A))) : Mat(stddev(A)); const Mat stddev_B = (B.n_rows == 1) ? Mat(stddev(trans(B))) : Mat(stddev(B)); out /= conv_to< Mat >::from( stddev_A * stddev_B ); } else { arma_debug_assert_mul_size(A, B, true, false, "cor()"); const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out = trans(A) * B; // out = strans(conj(A)) * B; out -= (trans(sum(A)) * sum(B))/eT(N); // out -= (strans(conj(sum(A))) * sum(B))/eT(N); out /= norm_val; out /= conv_to< Mat >::from( trans(stddev(A)) * stddev(B) ); } } template inline void glue_cor::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check A_tmp(X.A, out); const unwrap_check B_tmp(X.B, out); const Mat& A = A_tmp.M; const Mat& B = B_tmp.M; const uword norm_type = X.aux_uword; if(&A != &B) { glue_cor::direct_cor(out, A, B, norm_type); } else { op_cor::direct_cor(out, A, norm_type); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_cx_scalar_meat.hpp0000666000000000000000000002753312620272703023134 0ustar rootroot// Copyright (C) 2008-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_cx_scalar //! @{ template inline void op_cx_scalar_times::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_times>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_plus::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_plus>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_minus_pre::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_minus_pre>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_minus_post::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_minus_post>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_div_pre::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_div_pre>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_div_post::apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_div_post>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); const eT k = X.aux_out_eT; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = A.get_n_elem(); for(uword i=0; i inline void op_cx_scalar_times::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_times>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_plus::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_plus>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_minus_pre::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_minus_pre>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_minus_post::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_minus_post>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_div_pre::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_div_pre>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline void op_cx_scalar_div_post::apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_div_post>& X ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube A(X.m); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); const eT k = X.aux_out_eT; const uword n_elem = out.n_elem; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { for(uword i=0; i inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/eop_aux.hpp0000666000000000000000000003526212650723436021136 0ustar rootroot// Copyright (C) 2010-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eop_aux //! @{ //! use of the SFINAE approach to work around compiler limitations //! http://en.wikipedia.org/wiki/SFINAE class eop_aux { public: template arma_inline static typename arma_integral_only::result acos (const eT x) { return eT( std::acos(double(x)) ); } template arma_inline static typename arma_integral_only::result asin (const eT x) { return eT( std::asin(double(x)) ); } template arma_inline static typename arma_integral_only::result atan (const eT x) { return eT( std::atan(double(x)) ); } template arma_inline static typename arma_real_only::result acos (const eT x) { return std::acos(x); } template arma_inline static typename arma_real_only::result asin (const eT x) { return std::asin(x); } template arma_inline static typename arma_real_only::result atan (const eT x) { return std::atan(x); } template arma_inline static typename arma_cx_only::result acos (const eT x) { return arma_acos(x); } template arma_inline static typename arma_cx_only::result asin (const eT x) { return arma_asin(x); } template arma_inline static typename arma_cx_only::result atan (const eT x) { return arma_atan(x); } template arma_inline static typename arma_integral_only::result acosh (const eT x) { return eT( arma_acosh(double(x)) ); } template arma_inline static typename arma_integral_only::result asinh (const eT x) { return eT( arma_asinh(double(x)) ); } template arma_inline static typename arma_integral_only::result atanh (const eT x) { return eT( arma_atanh(double(x)) ); } template arma_inline static typename arma_real_or_cx_only::result acosh (const eT x) { return arma_acosh(x); } template arma_inline static typename arma_real_or_cx_only::result asinh (const eT x) { return arma_asinh(x); } template arma_inline static typename arma_real_or_cx_only::result atanh (const eT x) { return arma_atanh(x); } template arma_inline static typename arma_not_cx::result conj(const eT x) { return x; } template arma_inline static std::complex conj(const std::complex& x) { return std::conj(x); } template arma_inline static typename arma_integral_only::result sqrt (const eT x) { return eT( std::sqrt (double(x)) ); } template arma_inline static typename arma_integral_only::result log10 (const eT x) { return eT( std::log10(double(x)) ); } template arma_inline static typename arma_integral_only::result log (const eT x) { return eT( std::log (double(x)) ); } template arma_inline static typename arma_integral_only::result exp (const eT x) { return eT( std::exp (double(x)) ); } template arma_inline static typename arma_integral_only::result cos (const eT x) { return eT( std::cos (double(x)) ); } template arma_inline static typename arma_integral_only::result sin (const eT x) { return eT( std::sin (double(x)) ); } template arma_inline static typename arma_integral_only::result tan (const eT x) { return eT( std::tan (double(x)) ); } template arma_inline static typename arma_integral_only::result cosh (const eT x) { return eT( std::cosh (double(x)) ); } template arma_inline static typename arma_integral_only::result sinh (const eT x) { return eT( std::sinh (double(x)) ); } template arma_inline static typename arma_integral_only::result tanh (const eT x) { return eT( std::tanh (double(x)) ); } template arma_inline static typename arma_real_or_cx_only::result sqrt (const eT x) { return std::sqrt (x); } template arma_inline static typename arma_real_or_cx_only::result log10 (const eT x) { return std::log10(x); } template arma_inline static typename arma_real_or_cx_only::result log (const eT x) { return std::log (x); } template arma_inline static typename arma_real_or_cx_only::result exp (const eT x) { return std::exp (x); } template arma_inline static typename arma_real_or_cx_only::result cos (const eT x) { return std::cos (x); } template arma_inline static typename arma_real_or_cx_only::result sin (const eT x) { return std::sin (x); } template arma_inline static typename arma_real_or_cx_only::result tan (const eT x) { return std::tan (x); } template arma_inline static typename arma_real_or_cx_only::result cosh (const eT x) { return std::cosh (x); } template arma_inline static typename arma_real_or_cx_only::result sinh (const eT x) { return std::sinh (x); } template arma_inline static typename arma_real_or_cx_only::result tanh (const eT x) { return std::tanh (x); } template arma_inline static typename arma_unsigned_integral_only::result neg (const eT x) { return x; } template arma_inline static typename arma_signed_only::result neg (const eT x) { return -x; } template arma_inline static typename arma_integral_only::result floor (const eT x) { return x; } template arma_inline static typename arma_real_only::result floor (const eT x) { return std::floor(x); } template arma_inline static typename arma_cx_only::result floor (const eT& x) { return eT( std::floor(x.real()), std::floor(x.imag()) ); } template arma_inline static typename arma_integral_only::result ceil (const eT x) { return x; } template arma_inline static typename arma_real_only::result ceil (const eT x) { return std::ceil(x); } template arma_inline static typename arma_cx_only::result ceil (const eT& x) { return eT( std::ceil(x.real()), std::ceil(x.imag()) ); } #if defined(ARMA_USE_CXX11) template arma_inline static typename arma_integral_only::result round (const eT x) { return x; } template arma_inline static typename arma_real_only::result round (const eT x) { return std::round(x); } template arma_inline static typename arma_cx_only::result round (const eT& x) { return eT( std::round(x.real()), std::round(x.imag()) ); } #else template arma_inline static typename arma_integral_only::result round (const eT x) { return x; } template arma_inline static typename arma_real_only::result round (const eT x) { return (x >= eT(0)) ? std::floor(x+0.5) : std::ceil(x-0.5); } template arma_inline static typename arma_cx_only::result round (const eT& x) { return eT( eop_aux::round(x.real()), eop_aux::round(x.imag()) ); } #endif #if defined(ARMA_USE_CXX11) template arma_inline static typename arma_integral_only::result trunc (const eT x) { return x; } template arma_inline static typename arma_real_only::result trunc (const eT x) { return std::trunc(x); } template arma_inline static typename arma_cx_only::result trunc (const eT& x) { return eT( std::trunc(x.real()), std::trunc(x.imag()) ); } #else template arma_inline static typename arma_integral_only::result trunc (const eT x) { return x; } template arma_inline static typename arma_real_only::result trunc (const eT x) { return (x >= eT(0)) ? std::floor(x) : std::ceil(x); } template arma_inline static typename arma_cx_only::result trunc (const eT& x) { return eT( eop_aux::trunc(x.real()), eop_aux::trunc(x.imag()) ); } #endif #if defined(ARMA_USE_CXX11) template arma_inline static typename arma_integral_only::result log2 (const eT x) { return eT( std::log(double(x))/ double(0.69314718055994530942) ); } template arma_inline static typename arma_real_only::result log2 (const eT x) { return std::log2(x); } template arma_inline static typename arma_cx_only::result log2 (const eT& x) { typedef typename get_pod_type::result T; return std::log(x) / T(0.69314718055994530942); } #else template arma_inline static typename arma_integral_only::result log2 (const eT x) { return eT( std::log(double(x))/ double(0.69314718055994530942) ); } template arma_inline static typename arma_real_or_cx_only::result log2 (const eT x) { typedef typename get_pod_type::result T; return std::log(x) / T(0.69314718055994530942); } #endif #if defined(ARMA_USE_CXX11) template arma_inline static typename arma_integral_only::result exp2 (const eT x) { return eT( std::pow(double(2), double(x)) ); } template arma_inline static typename arma_real_only::result exp2 (const eT x) { return std::exp2(x); } template arma_inline static typename arma_cx_only::result exp2 (const eT& x) { typedef typename get_pod_type::result T; return std::pow( T(2), x); } #else template arma_inline static typename arma_integral_only::result exp2 (const eT x) { return eT( std::pow(double(2), double(x)) ); } template arma_inline static typename arma_real_or_cx_only::result exp2 (const eT x) { typedef typename get_pod_type::result T; return std::pow( T(2), x); } #endif template arma_inline static typename arma_integral_only::result exp10 (const eT x) { return eT( std::pow(double(10), double(x)) ); } template arma_inline static typename arma_real_or_cx_only::result exp10 (const eT x) { typedef typename get_pod_type::result T; return std::pow( T(10), x); } template arma_inline static typename arma_unsigned_integral_only::result arma_abs (const eT x) { return x; } template arma_inline static typename arma_signed_integral_only::result arma_abs (const eT x) { return std::abs(x); } template arma_inline static typename arma_real_only::result arma_abs (const eT x) { return std::abs(x); } template arma_inline static typename arma_real_only< T>::result arma_abs (const std::complex& x) { return std::abs(x); } template arma_inline static typename arma_unsigned_integral_only::result sign (const eT x) { return (x > eT(0)) ? eT(+1) : eT(0); } template arma_inline static typename arma_signed_integral_only::result sign (const eT x) { return (x > eT(0)) ? eT(+1) : ( (x < eT(0)) ? eT(-1) : eT(0) ); } template arma_inline static typename arma_real_only::result sign (const eT x) { return (x > eT(0)) ? eT(+1) : ( (x < eT(0)) ? eT(-1) : eT(0) ); } template arma_inline static typename arma_cx_only::result sign (const eT& x) { typedef typename eT::value_type T; return (x.real() != T(0) && x.imag() != T(0)) ? (x / std::abs(x)) : x; } template arma_inline static typename arma_integral_only::result pow (const T1 base, const T2 exponent) { return T1( std::pow( double(base), double(exponent) ) ); } template arma_inline static typename arma_real_or_cx_only::result pow (const T1 base, const T2 exponent) { return std::pow(base, exponent); } template arma_inline static typename arma_integral_only::result direct_eps(const eT) { return eT(0); } template inline static typename arma_real_only::result direct_eps(const eT x) { //arma_extra_debug_sigprint(); // acording to IEEE Standard for Floating-Point Arithmetic (IEEE 754) // the mantissa length for double is 53 bits = std::numeric_limits::digits // the mantissa length for float is 24 bits = std::numeric_limits::digits //return std::pow( std::numeric_limits::radix, (std::floor(std::log10(std::abs(x))/std::log10(std::numeric_limits::radix))-(std::numeric_limits::digits-1)) ); const eT radix_eT = eT(std::numeric_limits::radix); const eT digits_m1_eT = eT(std::numeric_limits::digits - 1); // return std::pow( radix_eT, eT(std::floor(std::log10(std::abs(x))/std::log10(radix_eT)) - digits_m1_eT) ); return eop_aux::pow( radix_eT, eT(std::floor(std::log10(std::abs(x))/std::log10(radix_eT)) - digits_m1_eT) ); } template inline static typename arma_real_only::result direct_eps(const std::complex x) { //arma_extra_debug_sigprint(); //return std::pow( std::numeric_limits::radix, (std::floor(std::log10(std::abs(x))/std::log10(std::numeric_limits::radix))-(std::numeric_limits::digits-1)) ); const T radix_T = T(std::numeric_limits::radix); const T digits_m1_T = T(std::numeric_limits::digits - 1); return std::pow( radix_T, T(std::floor(std::log10(std::abs(x))/std::log10(radix_T)) - digits_m1_T) ); } }; //! @} armadillo-6.500.5/include/armadillo_bits/op_norm_bones.hpp0000666000000000000000000000562712620272703022330 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_norm //! @{ class op_norm { public: // norms for dense vectors and matrices template arma_hot inline static typename T1::pod_type vec_norm_1(const Proxy& P, const typename arma_not_cx::result* junk = 0); template arma_hot inline static typename T1::pod_type vec_norm_1(const Proxy& P, const typename arma_cx_only::result* junk = 0); template arma_hot inline static eT vec_norm_1_direct_std(const Mat& X); template arma_hot inline static eT vec_norm_1_direct_mem(const uword N, const eT* A); template arma_hot inline static typename T1::pod_type vec_norm_2(const Proxy& P, const typename arma_not_cx::result* junk = 0); template arma_hot inline static typename T1::pod_type vec_norm_2(const Proxy& P, const typename arma_cx_only::result* junk = 0); template arma_hot inline static eT vec_norm_2_direct_std(const Mat& X); template arma_hot inline static eT vec_norm_2_direct_mem(const uword N, const eT* A); template arma_hot inline static eT vec_norm_2_direct_robust(const Mat& X); template arma_hot inline static typename T1::pod_type vec_norm_k(const Proxy& P, const int k); template arma_hot inline static typename T1::pod_type vec_norm_max(const Proxy& P); template arma_hot inline static typename T1::pod_type vec_norm_min(const Proxy& P); template inline static typename T1::pod_type mat_norm_1(const Proxy& P); template inline static typename T1::pod_type mat_norm_2(const Proxy& P); template inline static typename T1::pod_type mat_norm_inf(const Proxy& P); // norms for sparse matrices template inline static typename T1::pod_type mat_norm_1(const SpProxy& P); template inline static typename T1::pod_type mat_norm_2(const SpProxy& P, const typename arma_real_only::result* junk = 0); template inline static typename T1::pod_type mat_norm_2(const SpProxy& P, const typename arma_cx_only::result* junk = 0); template inline static typename T1::pod_type mat_norm_inf(const SpProxy& P); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_toeplitz.hpp0000666000000000000000000000212712620272703022016 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_toeplitz //! @{ template inline Op toeplitz(const Base& X) { arma_extra_debug_sigprint(); return Op( X.get_ref() ); } template inline Op circ_toeplitz(const Base& X) { arma_extra_debug_sigprint(); return Op( X.get_ref() ); } template inline Glue toeplitz(const Base& X, const Base& Y) { arma_extra_debug_sigprint(); return Glue( X.get_ref(), Y.get_ref() ); } //! @} armadillo-6.500.5/include/armadillo_bits/spop_max_meat.hpp0000666000000000000000000003571712620272703022330 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_max //! @{ template inline void spop_max::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "max(): parameter 'dim' must be 0 or 1" ); const SpProxy p(in.m); const uword p_n_rows = p.get_n_rows(); const uword p_n_cols = p.get_n_cols(); if( (p_n_rows == 0) || (p_n_cols == 0) || (p.get_n_nonzero() == 0) ) { if(dim == 0) { out.zeros((p_n_rows > 0) ? 1 : 0, p_n_cols); } if(dim == 1) { out.zeros(p_n_rows, (p_n_cols > 0) ? 1 : 0); } return; } spop_max::apply_proxy(out, p, dim); } template inline void spop_max::apply_proxy ( SpMat& out, const SpProxy& p, const uword dim, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); const uword p_n_cols = p.get_n_cols(); const uword p_n_rows = p.get_n_rows(); if(dim == 0) // find the maximum in each column { Row value(p_n_cols, fill::zeros); urowvec count(p_n_cols, fill::zeros); while(it != it_end) { const uword col = it.col(); value[col] = (count[col] == 0) ? (*it) : (std::max)(value[col], (*it)); count[col]++; ++it; } for(uword col=0; col value(p_n_rows, fill::zeros); ucolvec count(p_n_rows, fill::zeros); while(it != it_end) { const uword row = it.row(); value[row] = (count[row] == 0) ? (*it) : (std::max)(value[row], (*it)); count[row]++; ++it; } for(uword row=0; row inline typename T1::elem_type spop_max::vector_max ( const T1& x, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const SpProxy p(x); if(p.get_n_elem() == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } if(p.get_n_nonzero() == 0) { return eT(0); } if(SpProxy::must_use_iterator == false) { // direct access of values if(p.get_n_nonzero() == p.get_n_elem()) { return op_max::direct_max(p.get_values(), p.get_n_nonzero()); } else { return std::max(eT(0), op_max::direct_max(p.get_values(), p.get_n_nonzero())); } } else { // use iterator typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); eT result = (*it); ++it; while(it != it_end) { if((*it) > result) { result = (*it); } ++it; } if(p.get_n_nonzero() == p.get_n_elem()) { return result; } else { return std::max(eT(0), result); } } } template inline typename arma_not_cx::result spop_max::max(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); const uword n_nonzero = P.get_n_nonzero(); if(n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } eT max_val = priv::most_neg(); if(SpProxy::must_use_iterator) { // We have to iterate over the elements. typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { if ((*it) > max_val) { max_val = *it; } ++it; } } else { // We can do direct access of the values, row_indices, and col_ptrs. // We don't need the location of the max value, so we can just call out to // other functions... max_val = op_max::direct_max(P.get_values(), n_nonzero); } if(n_elem == n_nonzero) { return max_val; } else { return std::max(eT(0), max_val); } } template inline typename arma_not_cx::result spop_max::max_with_index(const SpProxy& P, uword& index_of_max_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_elem = P.get_n_elem(); const uword n_nonzero = P.get_n_nonzero(); const uword n_rows = P.get_n_rows(); if(n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } eT max_val = priv::most_neg(); if(SpProxy::must_use_iterator) { // We have to iterate over the elements. typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { if ((*it) > max_val) { max_val = *it; index_of_max_val = it.row() + it.col() * n_rows; } ++it; } } else { // We can do direct access. max_val = op_max::direct_max(P.get_values(), n_nonzero, index_of_max_val); // Convert to actual position in matrix. const uword row = P.get_row_indices()[index_of_max_val]; uword col = 0; while (P.get_col_ptrs()[++col] <= index_of_max_val) { } index_of_max_val = (col - 1) * n_rows + row; } if(n_elem != n_nonzero) { max_val = std::max(eT(0), max_val); // If the max_val is a nonzero element, we need its actual position in the matrix. if(max_val == eT(0)) { // Find first zero element. uword last_row = 0; uword last_col = 0; typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { // Have we moved more than one position from the last place? if ((it.col() == last_col) && (it.row() - last_row > 1)) { index_of_max_val = it.col() * n_rows + last_row + 1; break; } else if ((it.col() >= last_col + 1) && (last_row < n_rows - 1)) { index_of_max_val = last_col * n_rows + last_row + 1; break; } else if ((it.col() == last_col + 1) && (it.row() > 0)) { index_of_max_val = it.col() * n_rows; break; } else if (it.col() > last_col + 1) { index_of_max_val = (last_col + 1) * n_rows; break; } last_row = it.row(); last_col = it.col(); ++it; } } } return max_val; } template inline void spop_max::apply_proxy ( SpMat& out, const SpProxy& p, const uword dim, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); const uword p_n_cols = p.get_n_cols(); const uword p_n_rows = p.get_n_rows(); if(dim == 0) // find the maximum in each column { Row rawval(p_n_cols, fill::zeros); Row< T> absval(p_n_cols, fill::zeros); while(it != it_end) { const uword col = it.col(); const eT& v = (*it); const T a = std::abs(v); if(a > absval[col]) { absval[col] = a; rawval[col] = v; } ++it; } out = rawval; } else if(dim == 1) // find the maximum in each row { Col rawval(p_n_rows, fill::zeros); Col< T> absval(p_n_rows, fill::zeros); while(it != it_end) { const uword row = it.row(); const eT& v = (*it); const T a = std::abs(v); if(a > absval[row]) { absval[row] = a; rawval[row] = v; } ++it; } out = rawval; } } template inline typename T1::elem_type spop_max::vector_max ( const T1& x, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const SpProxy p(x); if(p.get_n_elem() == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } if(p.get_n_nonzero() == 0) { return eT(0); } if(SpProxy::must_use_iterator == false) { // direct access of values if(p.get_n_nonzero() == p.get_n_elem()) { return op_max::direct_max(p.get_values(), p.get_n_nonzero()); } else { const eT val1 = eT(0); const eT val2 = op_max::direct_max(p.get_values(), p.get_n_nonzero()); return ( std::abs(val1) >= std::abs(val2) ) ? val1 : val2; } } else { // use iterator typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); eT best_val_orig = *it; T best_val_abs = std::abs(best_val_orig); ++it; while(it != it_end) { eT val_orig = *it; T val_abs = std::abs(val_orig); if(val_abs > best_val_abs) { best_val_abs = val_abs; best_val_orig = val_orig; } ++it; } if(p.get_n_nonzero() == p.get_n_elem()) { return best_val_orig; } else { const eT val1 = eT(0); return ( std::abs(val1) >= best_val_abs ) ? val1 : best_val_orig; } } } template inline typename arma_cx_only::result spop_max::max(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const SpProxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); const uword n_nonzero = P.get_n_nonzero(); if(n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } T max_val = priv::most_neg(); eT ret_val; if(SpProxy::must_use_iterator) { // We have to iterate over the elements. typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { const T tmp_val = std::abs(*it); if (tmp_val > max_val) { max_val = tmp_val; ret_val = *it; } ++it; } } else { // We can do direct access of the values, row_indices, and col_ptrs. // We don't need the location of the max value, so we can just call out to // other functions... ret_val = op_max::direct_max(P.get_values(), n_nonzero); max_val = std::abs(ret_val); } if(n_elem == n_nonzero) { return max_val; } else { if (T(0) > max_val) return eT(0); else return ret_val; } } template inline typename arma_cx_only::result spop_max::max_with_index(const SpProxy& P, uword& index_of_max_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const uword n_elem = P.get_n_elem(); const uword n_nonzero = P.get_n_nonzero(); const uword n_rows = P.get_n_rows(); if(n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } T max_val = priv::most_neg(); if(SpProxy::must_use_iterator) { // We have to iterate over the elements. typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { const T tmp_val = std::abs(*it); if (tmp_val > max_val) { max_val = tmp_val; index_of_max_val = it.row() + it.col() * n_rows; } ++it; } } else { // We can do direct access. max_val = std::abs(op_max::direct_max(P.get_values(), n_nonzero, index_of_max_val)); // Convert to actual position in matrix. const uword row = P.get_row_indices()[index_of_max_val]; uword col = 0; while (P.get_col_ptrs()[++col] <= index_of_max_val) { } index_of_max_val = (col - 1) * n_rows + row; } if(n_elem != n_nonzero) { max_val = std::max(T(0), max_val); // If the max_val is a nonzero element, we need its actual position in the matrix. if(max_val == T(0)) { // Find first zero element. uword last_row = 0; uword last_col = 0; typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { // Have we moved more than one position from the last place? if ((it.col() == last_col) && (it.row() - last_row > 1)) { index_of_max_val = it.col() * n_rows + last_row + 1; break; } else if ((it.col() >= last_col + 1) && (last_row < n_rows - 1)) { index_of_max_val = last_col * n_rows + last_row + 1; break; } else if ((it.col() == last_col + 1) && (it.row() > 0)) { index_of_max_val = it.col() * n_rows; break; } else if (it.col() > last_col + 1) { index_of_max_val = (last_col + 1) * n_rows; break; } last_row = it.row(); last_col = it.col(); ++it; } } } return P[index_of_max_val]; } //! @} armadillo-6.500.5/include/armadillo_bits/op_reshape_meat.hpp0000666000000000000000000002075612620272703022624 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_reshape //! @{ template inline void op_reshape::apply_unwrap(Mat& out, const Mat& A, const uword in_n_rows, const uword in_n_cols, const uword in_dim) { arma_extra_debug_sigprint(); const bool is_alias = (&out == &A); const uword in_n_elem = in_n_rows * in_n_cols; if(A.n_elem == in_n_elem) { if(in_dim == 0) { if(is_alias == false) { out.set_size(in_n_rows, in_n_cols); arrayops::copy( out.memptr(), A.memptr(), out.n_elem ); } else // &out == &A, i.e. inplace resize { out.set_size(in_n_rows, in_n_cols); // set_size() doesn't destroy data as long as the number of elements in the matrix remains the same } } else { unwrap_check< Mat > B_tmp(A, is_alias); const Mat& B = B_tmp.M; out.set_size(in_n_rows, in_n_cols); eT* out_mem = out.memptr(); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; for(uword row=0; row > B_tmp(A, is_alias); const Mat& B = B_tmp.M; const uword n_elem_to_copy = (std::min)(B.n_elem, in_n_elem); out.set_size(in_n_rows, in_n_cols); eT* out_mem = out.memptr(); if(in_dim == 0) { arrayops::copy( out_mem, B.memptr(), n_elem_to_copy ); } else { uword row = 0; uword col = 0; const uword B_n_cols = B.n_cols; for(uword i=0; i= B_n_cols) { col = 0; ++row; } } } for(uword i=n_elem_to_copy; i inline void op_reshape::apply_proxy(Mat& out, const Proxy& P, const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; out.set_size(in_n_rows, in_n_cols); eT* out_mem = out.memptr(); const uword in_n_elem = in_n_rows * in_n_cols; if(P.get_n_elem() == in_n_elem) { if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i= n_elem_to_copy) { goto nested_loop_end; } out_mem[i] = P.at(row,col); ++i; } nested_loop_end: ; } for(uword i=n_elem_to_copy; i inline void op_reshape::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(in.m); const uword in_n_rows = in.aux_uword_a; const uword in_n_cols = in.aux_uword_b; if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { // not checking for aliasing here, as this might be an inplace reshape const unwrap::stored_type> tmp(P.Q); op_reshape::apply_unwrap(out, tmp.M, in_n_rows, in_n_cols, uword(0)); } else { if(P.is_alias(out)) { Mat tmp; op_reshape::apply_proxy(tmp, P, in_n_rows, in_n_cols); out.steal_mem(tmp); } else { op_reshape::apply_proxy(out, P, in_n_rows, in_n_cols); } } } template inline void op_reshape_ext::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.m); const uword in_n_rows = in.aux_uword_a; const uword in_n_cols = in.aux_uword_b; const uword in_dim = in.aux_uword_c; op_reshape::apply_unwrap(out, tmp.M, in_n_rows, in_n_cols, in_dim); } template inline void op_reshape_ext::apply(Cube& out, const OpCube& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube A_tmp(in.m); const Cube& A = A_tmp.M; const uword in_n_rows = in.aux_uword_a; const uword in_n_cols = in.aux_uword_b; const uword in_n_slices = in.aux_uword_c; const uword in_dim = in.aux_uword_d; const uword in_n_elem = in_n_rows * in_n_cols * in_n_slices; if(A.n_elem == in_n_elem) { if(in_dim == 0) { if(&out != &A) { out.set_size(in_n_rows, in_n_cols, in_n_slices); arrayops::copy( out.memptr(), A.memptr(), out.n_elem ); } else // &out == &A, i.e. inplace resize { out.set_size(in_n_rows, in_n_cols, in_n_slices); // set_size() doesn't destroy data as long as the number of elements in the cube remains the same } } else { unwrap_cube_check< Cube > B_tmp(A, out); const Cube& B = B_tmp.M; out.set_size(in_n_rows, in_n_cols, in_n_slices); eT* out_mem = out.memptr(); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; const uword B_n_slices = B.n_slices; for(uword slice = 0; slice < B_n_slices; ++slice) for(uword row = 0; row < B_n_rows; ++row ) for(uword col = 0; col < B_n_cols; ++col ) { *out_mem = B.at(row,col,slice); out_mem++; } } } else { const unwrap_cube_check< Cube > B_tmp(A, out); const Cube& B = B_tmp.M; const uword n_elem_to_copy = (std::min)(B.n_elem, in_n_elem); out.set_size(in_n_rows, in_n_cols, in_n_slices); eT* out_mem = out.memptr(); if(in_dim == 0) { arrayops::copy( out_mem, B.memptr(), n_elem_to_copy ); } else { uword row = 0; uword col = 0; uword slice = 0; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; for(uword i=0; i= B_n_cols) { col = 0; ++row; if(row >= B_n_rows) { row = 0; ++slice; } } } } for(uword i=n_elem_to_copy; i inline bool op_any::any_vec_helper(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i inline bool op_any::any_vec_helper ( const mtOp& X, const typename arma_op_rel_only::result junk1, const typename arma_not_cx::result junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy P(X.m); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); const uword n_elem = P.get_n_elem(); for(uword i=0; i < n_elem; ++i) { const eT tmp = Pea[i]; if(is_same_type::yes) { if(val < tmp) { return true; } } else if(is_same_type::yes) { if(tmp < val) { return true; } } else if(is_same_type::yes) { if(val > tmp) { return true; } } else if(is_same_type::yes) { if(tmp > val) { return true; } } else if(is_same_type::yes) { if(val <= tmp) { return true; } } else if(is_same_type::yes) { if(tmp <= val) { return true; } } else if(is_same_type::yes) { if(val >= tmp) { return true; } } else if(is_same_type::yes) { if(tmp >= val) { return true; } } else if(is_same_type::yes) { if(tmp == val) { return true; } } else if(is_same_type::yes) { if(tmp != val) { return true; } } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT tmp = P.at(row,col); if(is_same_type::yes) { if(val < tmp) { return true; } } else if(is_same_type::yes) { if(tmp < val) { return true; } } else if(is_same_type::yes) { if(val > tmp) { return true; } } else if(is_same_type::yes) { if(tmp > val) { return true; } } else if(is_same_type::yes) { if(val <= tmp) { return true; } } else if(is_same_type::yes) { if(tmp <= val) { return true; } } else if(is_same_type::yes) { if(val >= tmp) { return true; } } else if(is_same_type::yes) { if(tmp >= val) { return true; } } else if(is_same_type::yes) { if(tmp == val) { return true; } } else if(is_same_type::yes) { if(tmp != val) { return true; } } } } return false; } template inline bool op_any::any_vec_helper ( const mtGlue& X, const typename arma_glue_rel_only::result junk1, const typename arma_not_cx::result junk2, const typename arma_not_cx::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); const bool prefer_at_accessor = Proxy::prefer_at_accessor || Proxy::prefer_at_accessor; if(prefer_at_accessor == false) { ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); const uword n_elem = A.get_n_elem(); for(uword i=0; i::yes) { if(tmp1 < tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 > tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 <= tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 >= tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 == tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 != tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 && tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 || tmp2) { return true; } } } } else { const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT1 tmp1 = A.at(row,col); const eT2 tmp2 = B.at(row,col); if(is_same_type::yes) { if(tmp1 < tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 > tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 <= tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 >= tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 == tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 != tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 && tmp2) { return true; } } else if(is_same_type::yes) { if(tmp1 || tmp2) { return true; } } } } return false; } template inline bool op_any::any_vec(T1& X) { arma_extra_debug_sigprint(); return op_any::any_vec_helper(X); } template inline void op_any::apply_helper(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); typedef typename Proxy::elem_type eT; if(dim == 0) // traverse rows (ie. process each column) { out.zeros(1, n_cols); uword* out_mem = out.memptr(); if(is_Mat::stored_type>::value) { const unwrap::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { out_mem[col] = uword(1); break; } } } } else { for(uword col=0; col < n_cols; ++col) { for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { out_mem[col] = uword(1); break; } } } } } else { out.zeros(n_rows, 1); uword* out_mem = out.memptr(); if(is_Mat::stored_type>::value) { const unwrap::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); for(uword row=0; row < n_rows; ++row) { if(colmem[row] != eT(0)) { out_mem[row] = uword(1); } } } } else { for(uword col=0; col < n_cols; ++col) { for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { out_mem[row] = uword(1); } } } } } } template inline void op_any::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); const uword dim = X.aux_uword_a; const Proxy P(X.m); if(P.is_alias(out) == false) { op_any::apply_helper(out, P, dim); } else { Mat out2; op_any::apply_helper(out2, P, dim); out.steal_mem(out2); } } //! @} armadillo-6.500.5/include/armadillo_bits/glue_cross_bones.hpp0000666000000000000000000000114612620272703023014 0ustar rootroot// Copyright (C) 2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_cross //! @{ class glue_cross { public: template inline static void apply(Mat& out, const Glue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_diagmat_bones.hpp0000666000000000000000000000162612620272703022756 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_diagmat //! @{ class op_diagmat { public: template inline static void apply(Mat& out, const Op& X); }; class op_diagmat2 { public: template inline static void apply(Mat& out, const Proxy& P, const uword row_offset, const uword col_offset); template inline static void apply(Mat& out, const Op& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/compiler_setup.hpp0000666000000000000000000003201512653555454022527 0ustar rootroot// Copyright (C) 2008-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au #undef arma_hot #undef arma_cold #undef arma_pure #undef arma_const #undef arma_aligned #undef arma_align_mem #undef arma_warn_unused #undef arma_deprecated #undef arma_malloc #undef arma_inline #undef arma_noinline #undef arma_ignore #define arma_hot #define arma_cold #define arma_pure #define arma_const #define arma_aligned #define arma_align_mem #define arma_warn_unused #define arma_deprecated #define arma_malloc #define arma_inline inline #define arma_noinline #define arma_ignore(variable) ((void)(variable)) #undef arma_fortran_noprefix #undef arma_fortran_prefix #undef arma_fortran2_noprefix #undef arma_fortran2_prefix #if defined(ARMA_BLAS_UNDERSCORE) #define arma_fortran2_noprefix(function) function##_ #define arma_fortran2_prefix(function) wrapper_##function##_ #else #define arma_fortran2_noprefix(function) function #define arma_fortran2_prefix(function) wrapper_##function #endif #if defined(ARMA_USE_WRAPPER) #define arma_fortran(function) arma_fortran2_prefix(function) #define arma_wrapper(function) wrapper_##function #else #define arma_fortran(function) arma_fortran2_noprefix(function) #define arma_wrapper(function) function #endif #define arma_fortran_prefix(function) arma_fortran2_prefix(function) #define arma_fortran_noprefix(function) arma_fortran2_noprefix(function) #undef ARMA_INCFILE_WRAP #define ARMA_INCFILE_WRAP(x) #if defined(__CYGWIN__) #if defined(ARMA_USE_CXX11) #pragma message ("WARNING: Cygwin may have incomplete support for C++11 features;") #pragma message ("WARNING: if something breaks, you get to keep all the pieces.") #pragma message ("WARNING: to forcefully prevent Armadillo from using C++11 features,") #pragma message ("WARNING: #define ARMA_DONT_USE_CXX11 before #include ") #endif #endif #if defined(ARMA_USE_CXX11) #undef ARMA_USE_U64S64 #define ARMA_USE_U64S64 #if !defined(ARMA_32BIT_WORD) #undef ARMA_64BIT_WORD #define ARMA_64BIT_WORD #endif #if defined(ARMA_64BIT_WORD) && defined(SIZE_MAX) #if (SIZE_MAX < 0xFFFFFFFFFFFFFFFFull) #pragma message ("WARNING: disabled use of 64 bit integers, as std::size_t is smaller than 64 bits") #undef ARMA_64BIT_WORD #endif #endif #endif #if defined(ARMA_64BIT_WORD) #undef ARMA_USE_U64S64 #define ARMA_USE_U64S64 #endif // most compilers can't vectorise slightly elaborate loops; // for example clang: http://llvm.org/bugs/show_bug.cgi?id=16358 #undef ARMA_SIMPLE_LOOPS #define ARMA_SIMPLE_LOOPS #undef ARMA_GOOD_COMPILER #undef ARMA_HAVE_TR1 #undef ARMA_HAVE_GETTIMEOFDAY #undef ARMA_HAVE_SNPRINTF #undef ARMA_HAVE_ISFINITE #undef ARMA_HAVE_LOG1P #undef ARMA_HAVE_ISINF #undef ARMA_HAVE_ISNAN #if (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) #define ARMA_HAVE_GETTIMEOFDAY #endif // posix_memalign() is part of IEEE standard 1003.1 // http://pubs.opengroup.org/onlinepubs/009696899/functions/posix_memalign.html // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html // http://sourceforge.net/p/predef/wiki/Standards/ #if ( defined(_POSIX_ADVISORY_INFO) && (_POSIX_ADVISORY_INFO >= 200112L) ) #undef ARMA_HAVE_POSIX_MEMALIGN #define ARMA_HAVE_POSIX_MEMALIGN #endif #if defined(__APPLE__) #undef ARMA_BLAS_SDOT_BUG #define ARMA_BLAS_SDOT_BUG #undef ARMA_HAVE_POSIX_MEMALIGN #endif #if defined(__MINGW32__) #undef ARMA_HAVE_POSIX_MEMALIGN #endif #undef ARMA_FNSIG #if defined (__GNUG__) #define ARMA_FNSIG __PRETTY_FUNCTION__ #elif defined (_MSC_VER) #define ARMA_FNSIG __FUNCSIG__ #elif defined(__INTEL_COMPILER) #define ARMA_FNSIG __FUNCTION__ #elif defined(ARMA_USE_CXX11) #define ARMA_FNSIG __func__ #else #define ARMA_FNSIG "(unknown)" #endif #if (defined(__GNUG__) || defined(__GNUC__)) && (defined(__clang__) || defined(__INTEL_COMPILER) || defined(__NVCC__) || defined(__CUDACC__) || defined(__PGI) || defined(__PATHSCALE__)) #undef ARMA_FAKE_GCC #define ARMA_FAKE_GCC #endif #if defined(__GNUG__) && !defined(ARMA_FAKE_GCC) #undef ARMA_GCC_VERSION #define ARMA_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #if (ARMA_GCC_VERSION < 40200) #error "*** Need a newer compiler ***" #endif #if ( (ARMA_GCC_VERSION >= 40700) && (ARMA_GCC_VERSION <= 40701) ) #error "gcc versions 4.7.0 and 4.7.1 are unsupported; use 4.7.2 or later" // due to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53549 #endif #define ARMA_GOOD_COMPILER #undef arma_pure #undef arma_const #undef arma_aligned #undef arma_align_mem #undef arma_warn_unused #undef arma_deprecated #undef arma_malloc #undef arma_inline #undef arma_noinline #define arma_pure __attribute__((__pure__)) #define arma_const __attribute__((__const__)) #define arma_aligned __attribute__((__aligned__)) #define arma_align_mem __attribute__((__aligned__(16))) #define arma_warn_unused __attribute__((__warn_unused_result__)) #define arma_deprecated __attribute__((__deprecated__)) #define arma_malloc __attribute__((__malloc__)) #define arma_inline inline __attribute__((__always_inline__)) #define arma_noinline __attribute__((__noinline__)) #undef ARMA_HAVE_ALIGNED_ATTRIBUTE #define ARMA_HAVE_ALIGNED_ATTRIBUTE #if defined(ARMA_USE_CXX11) #if (ARMA_GCC_VERSION < 40800) #pragma message ("WARNING: compiler is in C++11 mode, but it has incomplete support for C++11 features;") #pragma message ("WARNING: if something breaks, you get to keep all the pieces.") #pragma message ("WARNING: to forcefully prevent Armadillo from using C++11 features,") #pragma message ("WARNING: #define ARMA_DONT_USE_CXX11 before #include ") #define ARMA_DONT_USE_CXX11_CHRONO #endif #endif #if !defined(ARMA_USE_CXX11) #if defined(_GLIBCXX_USE_C99_MATH_TR1) && defined(_GLIBCXX_USE_C99_COMPLEX_TR1) #define ARMA_HAVE_TR1 #endif #endif #if (ARMA_GCC_VERSION >= 40300) #undef arma_hot #undef arma_cold #define arma_hot __attribute__((__hot__)) #define arma_cold __attribute__((__cold__)) #endif #if (ARMA_GCC_VERSION >= 40700) #define ARMA_HAVE_GCC_ASSUME_ALIGNED #endif // gcc's vectoriser can handle elaborate loops #undef ARMA_SIMPLE_LOOPS #if defined(__OPTIMIZE_SIZE__) #define ARMA_SIMPLE_LOOPS #endif #if (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) #define ARMA_HAVE_SNPRINTF #define ARMA_HAVE_ISFINITE #define ARMA_HAVE_LOG1P #define ARMA_HAVE_ISINF #define ARMA_HAVE_ISNAN #endif #undef ARMA_GCC_VERSION #endif #if defined(__clang__) && (defined(__INTEL_COMPILER) || defined(__NVCC__) || defined(__CUDACC__) || defined(__PGI) || defined(__PATHSCALE__)) #undef ARMA_FAKE_CLANG #define ARMA_FAKE_CLANG #endif #if defined(__clang__) && !defined(ARMA_FAKE_CLANG) #define ARMA_GOOD_COMPILER #if !defined(__has_attribute) #define __has_attribute(x) 0 #endif #if __has_attribute(__pure__) #undef arma_pure #define arma_pure __attribute__((__pure__)) #endif #if __has_attribute(__const__) #undef arma_const #define arma_const __attribute__((__const__)) #endif #if __has_attribute(__aligned__) #undef arma_aligned #undef arma_align_mem #define arma_aligned __attribute__((__aligned__)) #define arma_align_mem __attribute__((__aligned__(16))) #undef ARMA_HAVE_ALIGNED_ATTRIBUTE #define ARMA_HAVE_ALIGNED_ATTRIBUTE #endif #if __has_attribute(__warn_unused_result__) #undef arma_warn_unused #define arma_warn_unused __attribute__((__warn_unused_result__)) #endif #if __has_attribute(__deprecated__) #undef arma_deprecated #define arma_deprecated __attribute__((__deprecated__)) #endif #if __has_attribute(__malloc__) #undef arma_malloc #define arma_malloc __attribute__((__malloc__)) #endif #if __has_attribute(__always_inline__) #undef arma_inline #define arma_inline inline __attribute__((__always_inline__)) #endif #if __has_attribute(__noinline__) #undef arma_noinline #define arma_noinline __attribute__((__noinline__)) #endif #if __has_attribute(__hot__) #undef arma_hot #define arma_hot __attribute__((__hot__)) #endif #if __has_attribute(__cold__) #undef arma_cold #define arma_cold __attribute__((__cold__)) #endif #if defined(__has_builtin) && __has_builtin(__builtin_assume_aligned) #undef ARMA_HAVE_GCC_ASSUME_ALIGNED #define ARMA_HAVE_GCC_ASSUME_ALIGNED #endif #if defined(__apple_build_version__) #undef ARMA_USE_EXTERN_CXX11_RNG // TODO: check the status of support for "extern thread_local" in clang shipped with Mac OS X #endif #if (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) #define ARMA_HAVE_SNPRINTF #define ARMA_HAVE_ISFINITE #define ARMA_HAVE_LOG1P #define ARMA_HAVE_ISINF #define ARMA_HAVE_ISNAN #endif #endif #if defined(__INTEL_COMPILER) #if (__INTEL_COMPILER_BUILD_DATE < 20090623) #error "*** Need a newer compiler ***" #endif #undef ARMA_HAVE_GCC_ASSUME_ALIGNED #undef ARMA_HAVE_ICC_ASSUME_ALIGNED #define ARMA_HAVE_ICC_ASSUME_ALIGNED #endif #if defined(_MSC_VER) #if (_MSC_VER < 1600) #error "*** Need a newer compiler ***" #endif #if (_MSC_VER < 1700) #pragma message ("WARNING: this compiler is outdated and has incomplete support for the C++ standard;") #pragma message ("WARNING: if something breaks, you get to keep all the pieces") #define ARMA_BAD_COMPILER #endif #if defined(ARMA_USE_CXX11) #if (_MSC_VER < 1900) #pragma message ("WARNING: compiler is in C++11 mode, but it has incomplete support for C++11 features;") #pragma message ("WARNING: if something breaks, you get to keep all the pieces.") #pragma message ("WARNING: to forcefully prevent Armadillo from using C++11 features,") #pragma message ("WARNING: #define ARMA_DONT_USE_CXX11 before #include ") #endif #endif // #undef arma_inline // #define arma_inline inline __forceinline #pragma warning(push) #pragma warning(disable: 4127) // conditional expression is constant #pragma warning(disable: 4244) // possible loss of data when converting types #pragma warning(disable: 4510) // default constructor could not be generated #pragma warning(disable: 4511) // copy constructor can't be generated #pragma warning(disable: 4512) // assignment operator can't be generated #pragma warning(disable: 4513) // destructor can't be generated #pragma warning(disable: 4514) // unreferenced inline function has been removed #pragma warning(disable: 4522) // multiple assignment operators specified #pragma warning(disable: 4623) // default constructor can't be generated #pragma warning(disable: 4624) // destructor can't be generated #pragma warning(disable: 4625) // copy constructor can't be generated #pragma warning(disable: 4626) // assignment operator can't be generated #pragma warning(disable: 4702) // unreachable code #pragma warning(disable: 4710) // function not inlined #pragma warning(disable: 4711) // call was inlined #pragma warning(disable: 4714) // __forceinline can't be inlined // #if (_MANAGED == 1) || (_M_CEE == 1) // // // don't do any alignment when compiling in "managed code" mode // // #undef arma_aligned // #define arma_aligned // // #undef arma_align_mem // #define arma_align_mem // // #elif (_MSC_VER >= 1700) // // #undef arma_align_mem // #define arma_align_mem __declspec(align(16)) // // #define ARMA_HAVE_ALIGNED_ATTRIBUTE // // // disable warnings: "structure was padded due to __declspec(align(16))" // #pragma warning(disable: 4324) // // #endif #endif #if defined(__SUNPRO_CC) // http://www.oracle.com/technetwork/server-storage/solarisstudio/training/index-jsp-141991.html // http://www.oracle.com/technetwork/server-storage/solarisstudio/documentation/cplusplus-faq-355066.html #if (__SUNPRO_CC < 0x5100) #error "*** Need a newer compiler ***" #endif #endif #if defined(log2) #undef log2 #pragma message ("WARNING: detected 'log2' macro and undefined it") #endif // // whoever defined macros with the names "min" and "max" should be permanently removed from the gene pool #if defined(min) || defined(max) #undef min #undef max #pragma message ("WARNING: detected 'min' and/or 'max' macros and undefined them;") #pragma message ("WARNING: you may wish to define NOMINMAX before including any windows header") #endif armadillo-6.500.5/include/armadillo_bits/fn_inplace_strans.hpp0000666000000000000000000000433512620272703023154 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Alexandre Drouin //! \addtogroup fn_inplace_strans //! @{ template inline void inplace_strans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); const char sig = (method != NULL) ? method[0] : char(0); arma_debug_check( ((sig != 's') && (sig != 'l')), "inplace_strans(): unknown method specified" ); const bool low_memory = (sig == 'l'); if( (low_memory == false) || (X.n_rows == X.n_cols) ) { op_strans::apply_mat_inplace(X); } else { // in-place algorithm inspired by: // Fred G. Gustavson, Tadeusz Swirszcz. // In-Place Transposition of Rectangular Matrices. // Applied Parallel Computing. State of the Art in Scientific Computing. // Lecture Notes in Computer Science. Volume 4699, pp. 560-569, 2007. // X.set_size() will check whether we can change the dimensions of X; // X.set_size() will also reuse existing memory, as the number of elements hasn't changed X.set_size(X.n_cols, X.n_rows); const uword m = X.n_cols; const uword n = X.n_rows; std::vector visited(X.n_elem); // TODO: replace std::vector with a better implementation for(uword col = 0; col < m; ++col) for(uword row = 0; row < n; ++row) { const uword pos = col*n + row; if(visited[pos] == false) { uword curr_pos = pos; eT val = X.at(row, col); while(visited[curr_pos] == false) { visited[curr_pos] = true; const uword j = curr_pos / m; const uword i = curr_pos - m * j; const eT tmp = X.at(j, i); X.at(j, i) = val; val = tmp; curr_pos = i*n + j; } } } } } //! @} armadillo-6.500.5/include/armadillo_bits/injector_meat.hpp0000666000000000000000000002464112620272703022311 0ustar rootroot// Copyright (C) 2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup injector //! @{ template inline mat_injector_row::mat_injector_row() : n_cols(0) { arma_extra_debug_sigprint(); A.set_size( podarray_prealloc_n_elem::val ); } template inline void mat_injector_row::insert(const eT val) const { arma_extra_debug_sigprint(); if(n_cols < A.n_elem) { A[n_cols] = val; ++n_cols; } else { B.set_size(2 * A.n_elem); arrayops::copy(B.memptr(), A.memptr(), n_cols); B[n_cols] = val; ++n_cols; std::swap( access::rw(A.mem), access::rw(B.mem) ); std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); } } // // // template inline mat_injector::mat_injector(T1& in_X, const typename mat_injector::elem_type val) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; AA = new podarray< mat_injector_row* >; BB = new podarray< mat_injector_row* >; podarray< mat_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*(A[0])).insert(val); } template inline mat_injector::mat_injector(T1& in_X, const injector_end_of_row<>& x) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); arma_ignore(x); typedef typename mat_injector::elem_type eT; AA = new podarray< mat_injector_row* >; BB = new podarray< mat_injector_row* >; podarray< mat_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*this).end_of_row(); } template inline mat_injector::~mat_injector() { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; podarray< mat_injector_row* >& A = *AA; if(n_rows > 0) { uword max_n_cols = (*(A[0])).n_cols; for(uword row=1; row::value == true) { X.set_size(max_n_rows, max_n_cols); for(uword row=0; row::value == true) { arma_debug_check( (max_n_rows > 1), "matrix initialisation: incompatible dimensions" ); const uword n_cols = (*(A[0])).n_cols; X.set_size(1, n_cols); arrayops::copy( X.memptr(), (*(A[0])).A.memptr(), n_cols ); } else if(is_Col::value == true) { const bool is_vec = ( (max_n_rows == 1) || (max_n_cols == 1) ); arma_debug_check( (is_vec == false), "matrix initialisation: incompatible dimensions" ); const uword n_elem = (std::max)(max_n_rows, max_n_cols); X.set_size(n_elem, 1); uword i = 0; for(uword row=0; row inline void mat_injector::insert(const typename mat_injector::elem_type val) const { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; podarray< mat_injector_row* >& A = *AA; (*(A[n_rows-1])).insert(val); } template inline void mat_injector::end_of_row() const { arma_extra_debug_sigprint(); typedef typename mat_injector::elem_type eT; podarray< mat_injector_row* >& A = *AA; podarray< mat_injector_row* >& B = *BB; B.set_size( n_rows+1 ); arrayops::copy(B.memptr(), A.memptr(), n_rows); for(uword row=n_rows; row<(n_rows+1); ++row) { B[row] = new mat_injector_row; } std::swap(AA, BB); n_rows += 1; } template arma_inline const mat_injector& operator<<(const mat_injector& ref, const typename mat_injector::elem_type val) { arma_extra_debug_sigprint(); ref.insert(val); return ref; } template arma_inline const mat_injector& operator<<(const mat_injector& ref, const injector_end_of_row<>& x) { arma_extra_debug_sigprint(); arma_ignore(x); ref.end_of_row(); return ref; } //// using a mixture of operator << and , doesn't work yet //// e.g. A << 1, 2, 3 << endr //// in the above "3 << endr" requires special handling. //// similarly, special handling is necessary for "endr << 3" //// // template // arma_inline // const mat_injector& // operator,(const mat_injector& ref, const typename mat_injector::elem_type val) // { // arma_extra_debug_sigprint(); // // ref.insert(val); // // return ref; // } // template // arma_inline // const mat_injector& // operator,(const mat_injector& ref, const injector_end_of_row<>& x) // { // arma_extra_debug_sigprint(); // arma_ignore(x); // // ref.end_of_row(); // // return ref; // } // // // template inline field_injector_row::field_injector_row() : n_cols(0) { arma_extra_debug_sigprint(); AA = new field; BB = new field; field& A = *AA; A.set_size( field_prealloc_n_elem::val ); } template inline field_injector_row::~field_injector_row() { arma_extra_debug_sigprint(); delete AA; delete BB; } template inline void field_injector_row::insert(const oT& val) const { arma_extra_debug_sigprint(); field& A = *AA; field& B = *BB; if(n_cols < A.n_elem) { A[n_cols] = val; ++n_cols; } else { B.set_size(2 * A.n_elem); for(uword i=0; i inline field_injector::field_injector(T1& in_X, const typename field_injector::object_type& val) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; AA = new podarray< field_injector_row* >; BB = new podarray< field_injector_row* >; podarray< field_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*(A[0])).insert(val); } template inline field_injector::field_injector(T1& in_X, const injector_end_of_row<>& x) : X(in_X) , n_rows(1) { arma_extra_debug_sigprint(); arma_ignore(x); typedef typename field_injector::object_type oT; AA = new podarray< field_injector_row* >; BB = new podarray< field_injector_row* >; podarray< field_injector_row* >& A = *AA; A.set_size(n_rows); for(uword row=0; row; } (*this).end_of_row(); } template inline field_injector::~field_injector() { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; podarray< field_injector_row* >& A = *AA; if(n_rows > 0) { uword max_n_cols = (*(A[0])).n_cols; for(uword row=1; row& tmp = *((*(A[row])).AA); X.at(row,col) = tmp[col]; } for(uword col=n_cols; col inline void field_injector::insert(const typename field_injector::object_type& val) const { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; podarray< field_injector_row* >& A = *AA; (*(A[n_rows-1])).insert(val); } template inline void field_injector::end_of_row() const { arma_extra_debug_sigprint(); typedef typename field_injector::object_type oT; podarray< field_injector_row* >& A = *AA; podarray< field_injector_row* >& B = *BB; B.set_size( n_rows+1 ); for(uword row=0; row; } std::swap(AA, BB); n_rows += 1; } template arma_inline const field_injector& operator<<(const field_injector& ref, const typename field_injector::object_type& val) { arma_extra_debug_sigprint(); ref.insert(val); return ref; } template arma_inline const field_injector& operator<<(const field_injector& ref, const injector_end_of_row<>& x) { arma_extra_debug_sigprint(); arma_ignore(x); ref.end_of_row(); return ref; } //! @} armadillo-6.500.5/include/armadillo_bits/op_median_bones.hpp0000666000000000000000000000307712620272703022607 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_median //! @{ template struct arma_cx_median_packet { T val; uword index; }; template arma_inline bool operator< (const arma_cx_median_packet& A, const arma_cx_median_packet& B) { return A.val < B.val; } //! Class for finding median values of a matrix class op_median { public: template inline static void apply(Mat& out, const Op& in); template inline static void apply(Mat< std::complex >& out, const Op& in); // // template inline static typename T1::elem_type median_vec(const T1& X, const typename arma_not_cx::result* junk = 0); template inline static typename T1::elem_type median_vec(const T1& X, const typename arma_cx_only::result* junk = 0); // // template inline static eT direct_median(std::vector& X); template inline static void direct_cx_median_index(uword& out_index1, uword& out_index2, std::vector< arma_cx_median_packet >& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/GlueCube_bones.hpp0000666000000000000000000000177512620272703022352 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup GlueCube //! @{ //! analog of the Glue class, intended for Cube objects template class GlueCube : public BaseCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; arma_inline GlueCube(const BaseCube& in_A, const BaseCube& in_B); arma_inline ~GlueCube(); const T1& A; //!< first operand const T2& B; //!< second operand }; //! @} armadillo-6.500.5/include/armadillo_bits/unwrap_spmat.hpp0000666000000000000000000000444112620272703022202 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup unwrap_spmat //! @{ template struct unwrap_spmat { typedef typename T1::elem_type eT; typedef SpMat stored_type; inline unwrap_spmat(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat M; }; template struct unwrap_spmat< SpMat > { typedef SpMat stored_type; inline unwrap_spmat(const SpMat& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat& M; }; template struct unwrap_spmat< SpRow > { typedef SpRow stored_type; inline unwrap_spmat(const SpRow& A) : M(A) { arma_extra_debug_sigprint(); } const SpRow& M; }; template struct unwrap_spmat< SpCol > { typedef SpCol stored_type; inline unwrap_spmat(const SpCol& A) : M(A) { arma_extra_debug_sigprint(); } const SpCol& M; }; template struct unwrap_spmat< SpOp > { typedef typename T1::elem_type eT; typedef SpMat stored_type; inline unwrap_spmat(const SpOp& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat M; }; template struct unwrap_spmat< SpGlue > { typedef typename T1::elem_type eT; typedef SpMat stored_type; inline unwrap_spmat(const SpGlue& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat M; }; template struct unwrap_spmat< mtSpOp > { typedef SpMat stored_type; inline unwrap_spmat(const mtSpOp& A) : M(A) { arma_extra_debug_sigprint(); } const SpMat M; }; //! @} armadillo-6.500.5/include/armadillo_bits/typedef_mat_fixed.hpp0000666000000000000000000001607512620272703023150 0ustar rootroot// Copyright (C) 2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup typedef_mat_fixed //! @{ typedef umat::fixed<2,2> umat22; typedef umat::fixed<3,3> umat33; typedef umat::fixed<4,4> umat44; typedef umat::fixed<5,5> umat55; typedef umat::fixed<6,6> umat66; typedef umat::fixed<7,7> umat77; typedef umat::fixed<8,8> umat88; typedef umat::fixed<9,9> umat99; typedef imat::fixed<2,2> imat22; typedef imat::fixed<3,3> imat33; typedef imat::fixed<4,4> imat44; typedef imat::fixed<5,5> imat55; typedef imat::fixed<6,6> imat66; typedef imat::fixed<7,7> imat77; typedef imat::fixed<8,8> imat88; typedef imat::fixed<9,9> imat99; typedef fmat::fixed<2,2> fmat22; typedef fmat::fixed<3,3> fmat33; typedef fmat::fixed<4,4> fmat44; typedef fmat::fixed<5,5> fmat55; typedef fmat::fixed<6,6> fmat66; typedef fmat::fixed<7,7> fmat77; typedef fmat::fixed<8,8> fmat88; typedef fmat::fixed<9,9> fmat99; typedef mat::fixed<2,2> mat22; typedef mat::fixed<3,3> mat33; typedef mat::fixed<4,4> mat44; typedef mat::fixed<5,5> mat55; typedef mat::fixed<6,6> mat66; typedef mat::fixed<7,7> mat77; typedef mat::fixed<8,8> mat88; typedef mat::fixed<9,9> mat99; typedef cx_fmat::fixed<2,2> cx_fmat22; typedef cx_fmat::fixed<3,3> cx_fmat33; typedef cx_fmat::fixed<4,4> cx_fmat44; typedef cx_fmat::fixed<5,5> cx_fmat55; typedef cx_fmat::fixed<6,6> cx_fmat66; typedef cx_fmat::fixed<7,7> cx_fmat77; typedef cx_fmat::fixed<8,8> cx_fmat88; typedef cx_fmat::fixed<9,9> cx_fmat99; typedef cx_mat::fixed<2,2> cx_mat22; typedef cx_mat::fixed<3,3> cx_mat33; typedef cx_mat::fixed<4,4> cx_mat44; typedef cx_mat::fixed<5,5> cx_mat55; typedef cx_mat::fixed<6,6> cx_mat66; typedef cx_mat::fixed<7,7> cx_mat77; typedef cx_mat::fixed<8,8> cx_mat88; typedef cx_mat::fixed<9,9> cx_mat99; // typedef uvec::fixed<2> uvec2; typedef uvec::fixed<3> uvec3; typedef uvec::fixed<4> uvec4; typedef uvec::fixed<5> uvec5; typedef uvec::fixed<6> uvec6; typedef uvec::fixed<7> uvec7; typedef uvec::fixed<8> uvec8; typedef uvec::fixed<9> uvec9; typedef ivec::fixed<2> ivec2; typedef ivec::fixed<3> ivec3; typedef ivec::fixed<4> ivec4; typedef ivec::fixed<5> ivec5; typedef ivec::fixed<6> ivec6; typedef ivec::fixed<7> ivec7; typedef ivec::fixed<8> ivec8; typedef ivec::fixed<9> ivec9; typedef fvec::fixed<2> fvec2; typedef fvec::fixed<3> fvec3; typedef fvec::fixed<4> fvec4; typedef fvec::fixed<5> fvec5; typedef fvec::fixed<6> fvec6; typedef fvec::fixed<7> fvec7; typedef fvec::fixed<8> fvec8; typedef fvec::fixed<9> fvec9; typedef vec::fixed<2> vec2; typedef vec::fixed<3> vec3; typedef vec::fixed<4> vec4; typedef vec::fixed<5> vec5; typedef vec::fixed<6> vec6; typedef vec::fixed<7> vec7; typedef vec::fixed<8> vec8; typedef vec::fixed<9> vec9; typedef cx_fvec::fixed<2> cx_fvec2; typedef cx_fvec::fixed<3> cx_fvec3; typedef cx_fvec::fixed<4> cx_fvec4; typedef cx_fvec::fixed<5> cx_fvec5; typedef cx_fvec::fixed<6> cx_fvec6; typedef cx_fvec::fixed<7> cx_fvec7; typedef cx_fvec::fixed<8> cx_fvec8; typedef cx_fvec::fixed<9> cx_fvec9; typedef cx_vec::fixed<2> cx_vec2; typedef cx_vec::fixed<3> cx_vec3; typedef cx_vec::fixed<4> cx_vec4; typedef cx_vec::fixed<5> cx_vec5; typedef cx_vec::fixed<6> cx_vec6; typedef cx_vec::fixed<7> cx_vec7; typedef cx_vec::fixed<8> cx_vec8; typedef cx_vec::fixed<9> cx_vec9; // typedef ucolvec::fixed<2> ucolvec2; typedef ucolvec::fixed<3> ucolvec3; typedef ucolvec::fixed<4> ucolvec4; typedef ucolvec::fixed<5> ucolvec5; typedef ucolvec::fixed<6> ucolvec6; typedef ucolvec::fixed<7> ucolvec7; typedef ucolvec::fixed<8> ucolvec8; typedef ucolvec::fixed<9> ucolvec9; typedef icolvec::fixed<2> icolvec2; typedef icolvec::fixed<3> icolvec3; typedef icolvec::fixed<4> icolvec4; typedef icolvec::fixed<5> icolvec5; typedef icolvec::fixed<6> icolvec6; typedef icolvec::fixed<7> icolvec7; typedef icolvec::fixed<8> icolvec8; typedef icolvec::fixed<9> icolvec9; typedef fcolvec::fixed<2> fcolvec2; typedef fcolvec::fixed<3> fcolvec3; typedef fcolvec::fixed<4> fcolvec4; typedef fcolvec::fixed<5> fcolvec5; typedef fcolvec::fixed<6> fcolvec6; typedef fcolvec::fixed<7> fcolvec7; typedef fcolvec::fixed<8> fcolvec8; typedef fcolvec::fixed<9> fcolvec9; typedef colvec::fixed<2> colvec2; typedef colvec::fixed<3> colvec3; typedef colvec::fixed<4> colvec4; typedef colvec::fixed<5> colvec5; typedef colvec::fixed<6> colvec6; typedef colvec::fixed<7> colvec7; typedef colvec::fixed<8> colvec8; typedef colvec::fixed<9> colvec9; typedef cx_fcolvec::fixed<2> cx_fcolvec2; typedef cx_fcolvec::fixed<3> cx_fcolvec3; typedef cx_fcolvec::fixed<4> cx_fcolvec4; typedef cx_fcolvec::fixed<5> cx_fcolvec5; typedef cx_fcolvec::fixed<6> cx_fcolvec6; typedef cx_fcolvec::fixed<7> cx_fcolvec7; typedef cx_fcolvec::fixed<8> cx_fcolvec8; typedef cx_fcolvec::fixed<9> cx_fcolvec9; typedef cx_colvec::fixed<2> cx_colvec2; typedef cx_colvec::fixed<3> cx_colvec3; typedef cx_colvec::fixed<4> cx_colvec4; typedef cx_colvec::fixed<5> cx_colvec5; typedef cx_colvec::fixed<6> cx_colvec6; typedef cx_colvec::fixed<7> cx_colvec7; typedef cx_colvec::fixed<8> cx_colvec8; typedef cx_colvec::fixed<9> cx_colvec9; // typedef urowvec::fixed<2> urowvec2; typedef urowvec::fixed<3> urowvec3; typedef urowvec::fixed<4> urowvec4; typedef urowvec::fixed<5> urowvec5; typedef urowvec::fixed<6> urowvec6; typedef urowvec::fixed<7> urowvec7; typedef urowvec::fixed<8> urowvec8; typedef urowvec::fixed<9> urowvec9; typedef irowvec::fixed<2> irowvec2; typedef irowvec::fixed<3> irowvec3; typedef irowvec::fixed<4> irowvec4; typedef irowvec::fixed<5> irowvec5; typedef irowvec::fixed<6> irowvec6; typedef irowvec::fixed<7> irowvec7; typedef irowvec::fixed<8> irowvec8; typedef irowvec::fixed<9> irowvec9; typedef frowvec::fixed<2> frowvec2; typedef frowvec::fixed<3> frowvec3; typedef frowvec::fixed<4> frowvec4; typedef frowvec::fixed<5> frowvec5; typedef frowvec::fixed<6> frowvec6; typedef frowvec::fixed<7> frowvec7; typedef frowvec::fixed<8> frowvec8; typedef frowvec::fixed<9> frowvec9; typedef rowvec::fixed<2> rowvec2; typedef rowvec::fixed<3> rowvec3; typedef rowvec::fixed<4> rowvec4; typedef rowvec::fixed<5> rowvec5; typedef rowvec::fixed<6> rowvec6; typedef rowvec::fixed<7> rowvec7; typedef rowvec::fixed<8> rowvec8; typedef rowvec::fixed<9> rowvec9; typedef cx_frowvec::fixed<2> cx_frowvec2; typedef cx_frowvec::fixed<3> cx_frowvec3; typedef cx_frowvec::fixed<4> cx_frowvec4; typedef cx_frowvec::fixed<5> cx_frowvec5; typedef cx_frowvec::fixed<6> cx_frowvec6; typedef cx_frowvec::fixed<7> cx_frowvec7; typedef cx_frowvec::fixed<8> cx_frowvec8; typedef cx_frowvec::fixed<9> cx_frowvec9; typedef cx_rowvec::fixed<2> cx_rowvec2; typedef cx_rowvec::fixed<3> cx_rowvec3; typedef cx_rowvec::fixed<4> cx_rowvec4; typedef cx_rowvec::fixed<5> cx_rowvec5; typedef cx_rowvec::fixed<6> cx_rowvec6; typedef cx_rowvec::fixed<7> cx_rowvec7; typedef cx_rowvec::fixed<8> cx_rowvec8; typedef cx_rowvec::fixed<9> cx_rowvec9; //! @} armadillo-6.500.5/include/armadillo_bits/op_clamp_bones.hpp0000666000000000000000000000145212620272703022441 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_clamp //! @{ class op_clamp { public: template inline static void apply(Mat& out, const mtOp& in); template inline static void apply_noalias(Mat& out, const Proxy& P, const typename T1::elem_type min_val, const typename T1::elem_type max_val); }; //! @} armadillo-6.500.5/include/armadillo_bits/SpRow_meat.hpp0000666000000000000000000002112012620272703021533 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin // Written by Matthew Amidon //! \addtogroup SpRow //! @{ template inline SpRow::SpRow() : SpMat(1, 0) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; } template inline SpRow::SpRow(const uword in_n_elem) : SpMat(1, in_n_elem) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; } template inline SpRow::SpRow(const uword in_n_rows, const uword in_n_cols) : SpMat(in_n_rows, in_n_cols) { arma_extra_debug_sigprint(); arma_debug_check((in_n_rows != 1), "SpRow::SpRow(): must have only one row"); access::rw(SpMat::vec_state) = 2; } template inline SpRow::SpRow(const char* text) : SpMat(text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; arma_debug_check((SpMat::n_rows != 1), "SpRow::SpRow(): must have only one row"); } template inline const SpRow& SpRow::operator=(const char* text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; SpMat::operator=(text); return *this; } template inline SpRow::SpRow(const std::string& text) : SpMat(text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; arma_debug_check((SpMat::n_rows != 1), "SpRow::SpRow(): must have only one row"); } template inline const SpRow& SpRow::operator=(const std::string& text) { arma_extra_debug_sigprint(); SpMat::operator=(text); return *this; } template inline const SpRow& SpRow::operator=(const eT val) { arma_extra_debug_sigprint(); SpMat::operator=(val); return *this; } template template inline SpRow::SpRow(const Base& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; SpMat::operator=(X.get_ref()); } template template inline const SpRow& SpRow::operator=(const Base& X) { arma_extra_debug_sigprint(); SpMat::operator=(X.get_ref()); return *this; } template template inline SpRow::SpRow(const SpBase& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; SpMat::operator=(X.get_ref()); } template template inline const SpRow& SpRow::operator=(const SpBase& X) { arma_extra_debug_sigprint(); SpMat::operator=(X.get_ref()); return *this; } template template inline SpRow::SpRow ( const SpBase::pod_type, T1>& A, const SpBase::pod_type, T2>& B ) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 2; SpMat::init(A,B); } //! remove specified columns template inline void SpRow::shed_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= SpMat::n_cols, "SpRow::shed_col(): out of bounds"); shed_cols(col_num, col_num); } //! remove specified columns template inline void SpRow::shed_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= SpMat::n_cols), "SpRow::shed_cols(): indices out of bounds or incorrectly used" ); const uword diff = (in_col2 - in_col1 + 1); // This is doubleplus easy because we have all the column pointers stored. const uword start = SpMat::col_ptrs[in_col1]; const uword end = SpMat::col_ptrs[in_col2 + 1]; if (start != end) { const uword elem_diff = end - start; eT* new_values = memory::acquire_chunked (SpMat::n_nonzero - elem_diff); uword* new_row_indices = memory::acquire_chunked(SpMat::n_nonzero - elem_diff); // Copy first set of elements, if necessary. if (start > 0) { arrayops::copy(new_values, SpMat::values, start); arrayops::copy(new_row_indices, SpMat::row_indices, start); } // Copy last set of elements, if necessary. if (end != SpMat::n_nonzero) { arrayops::copy(new_values + start, SpMat::values + end, (SpMat::n_nonzero - end)); arrayops::copy(new_row_indices + start, SpMat::row_indices + end, (SpMat::n_nonzero - end)); } memory::release(SpMat::values); memory::release(SpMat::row_indices); access::rw(SpMat::values) = new_values; access::rw(SpMat::row_indices) = new_row_indices; access::rw(SpMat::n_nonzero) -= elem_diff; } // Update column pointers. uword* new_col_ptrs = memory::acquire(SpMat::n_cols - diff + 1); // Copy first part of column pointers. if (in_col1 > 0) { arrayops::copy(new_col_ptrs, SpMat::col_ptrs, in_col1); } // Copy last part of column pointers (and adjust their values as necessary). if (in_col2 < SpMat::n_cols - 1) { arrayops::copy(new_col_ptrs + in_col1, SpMat::col_ptrs + in_col2 + 1, SpMat::n_cols - in_col2); // Modify their values. arrayops::inplace_minus(new_col_ptrs + in_col1, (end - start), SpMat::n_cols - in_col2); } memory::release(SpMat::col_ptrs); access::rw(SpMat::col_ptrs) = new_col_ptrs; access::rw(SpMat::n_cols) -= diff; access::rw(SpMat::n_elem) -= diff; } // //! insert N cols at the specified col position, // //! optionally setting the elements of the inserted cols to zero // template // inline // void // SpRow::insert_cols(const uword col_num, const uword N, const bool set_to_zero) // { // arma_extra_debug_sigprint(); // // // insertion at col_num == n_cols is in effect an append operation // arma_debug_check( (col_num > SpMat::n_cols), "SpRow::insert_cols(): out of bounds"); // // arma_debug_check( (set_to_zero == false), "SpRow::insert_cols(): cannot set elements to nonzero values"); // // uword newVal = (col_num == 0) ? 0 : SpMat::col_ptrs[col_num]; // SpMat::col_ptrs.insert(col_num, N, newVal); // uword* new_col_ptrs = memory::acquire(SpMat::n_cols + N); // // arrayops::copy(new_col_ptrs, SpMat::col_ptrs, col_num); // // uword fill_value = (col_num == 0) ? 0 : SpMat::col_ptrs[col_num - 1]; // arrayops::inplace_set(new_col_ptrs + col_num, fill_value, N); // // arrayops::copy(new_col_ptrs + col_num + N, SpMat::col_ptrs + col_num, SpMat::n_cols - col_num); // // access::rw(SpMat::n_cols) += N; // access::rw(SpMat::n_elem) += N; // } template inline typename SpRow::row_iterator SpRow::begin_row(const uword row_num) { arma_extra_debug_sigprint(); // Since this is a row, row_num can only be 0. But the option is provided for // compatibility. arma_debug_check((row_num >= 1), "SpRow::begin_row(): index out of bounds"); return SpMat::begin(); } template inline typename SpRow::const_row_iterator SpRow::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); // Since this is a row, row_num can only be 0. But the option is provided for // compatibility. arma_debug_check((row_num >= 1), "SpRow::begin_row(): index out of bounds"); return SpMat::begin(); } template inline typename SpRow::row_iterator SpRow::end_row(const uword row_num) { arma_extra_debug_sigprint(); // Since this is a row, row_num can only be 0. But the option is provided for // compatibility. arma_debug_check((row_num >= 1), "SpRow::end_row(): index out of bounds"); return SpMat::end(); } template inline typename SpRow::const_row_iterator SpRow::end_row(const uword row_num) const { arma_extra_debug_sigprint(); // Since this is a row, row_num can only be 0. But the option is provided for // compatibility. arma_debug_check((row_num >= 1), "SpRow::end_row(): index out of bounds"); return SpMat::end(); } #ifdef ARMA_EXTRA_SPROW_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPROW_MEAT) #endif //! @} armadillo-6.500.5/include/armadillo_bits/op_norm_meat.hpp0000666000000000000000000004646012620272703022150 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_norm //! @{ template arma_hot inline typename T1::pod_type op_norm::vec_norm_1(const Proxy& P, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool have_direct_mem = (is_Mat::stored_type>::value) || (is_subview_col::stored_type>::value); if(have_direct_mem) { const quasi_unwrap::stored_type> tmp(P.Q); return op_norm::vec_norm_1_direct_std(tmp.M); } typedef typename T1::pod_type T; T acc = T(0); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); T acc1 = T(0); T acc2 = T(0); uword i,j; for(i=0, j=1; j arma_hot inline typename T1::pod_type op_norm::vec_norm_1(const Proxy& P, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; T acc = T(0); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); for(uword i=0; i& X = A[i]; const T a = X.real(); const T b = X.imag(); acc += std::sqrt( (a*a) + (b*b) ); } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { for(uword col=0; col& X = P.at(0,col); const T a = X.real(); const T b = X.imag(); acc += std::sqrt( (a*a) + (b*b) ); } } else { for(uword col=0; col& X = P.at(row,col); const T a = X.real(); const T b = X.imag(); acc += std::sqrt( (a*a) + (b*b) ); } } } if( (acc != T(0)) && arma_isfinite(acc) ) { return acc; } else { arma_extra_debug_print("op_norm::vec_norm_1(): detected possible underflow or overflow"); const quasi_unwrap::stored_type> R(P.Q); const uword N = R.M.n_elem; const eT* R_mem = R.M.memptr(); T max_val = priv::most_neg(); for(uword i=0; i& X = R_mem[i]; const T a = std::abs(X.real()); const T b = std::abs(X.imag()); if(a > max_val) { max_val = a; } if(b > max_val) { max_val = b; } } if(max_val == T(0)) { return T(0); } T alt_acc = T(0); for(uword i=0; i& X = R_mem[i]; const T a = X.real() / max_val; const T b = X.imag() / max_val; alt_acc += std::sqrt( (a*a) + (b*b) ); } return ( alt_acc * max_val ); } } template arma_hot inline eT op_norm::vec_norm_1_direct_std(const Mat& X) { arma_extra_debug_sigprint(); const uword N = X.n_elem; const eT* A = X.memptr(); if(N < uword(32)) { return op_norm::vec_norm_1_direct_mem(N,A); } else { #if defined(ARMA_USE_ATLAS) { return atlas::cblas_asum(N,A); } #elif defined(ARMA_USE_BLAS) { return blas::asum(N,A); } #else { return op_norm::vec_norm_1_direct_mem(N,A); } #endif } } template arma_hot inline eT op_norm::vec_norm_1_direct_mem(const uword N, const eT* A) { arma_extra_debug_sigprint(); #if defined(ARMA_SIMPLE_LOOPS) || (defined(__FINITE_MATH_ONLY__) && (__FINITE_MATH_ONLY__ > 0)) { eT acc1 = eT(0); if(memory::is_aligned(A)) { memory::mark_as_aligned(A); for(uword i=0; i arma_hot inline typename T1::pod_type op_norm::vec_norm_2(const Proxy& P, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool have_direct_mem = (is_Mat::stored_type>::value) || (is_subview_col::stored_type>::value); if(have_direct_mem) { const quasi_unwrap::stored_type> tmp(P.Q); return op_norm::vec_norm_2_direct_std(tmp.M); } typedef typename T1::pod_type T; T acc = T(0); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); T acc1 = T(0); T acc2 = T(0); uword i,j; for(i=0, j=1; j::stored_type> tmp(P.Q); return op_norm::vec_norm_2_direct_robust(tmp.M); } } template arma_hot inline typename T1::pod_type op_norm::vec_norm_2(const Proxy& P, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; T acc = T(0); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); for(uword i=0; i& X = A[i]; const T a = X.real(); const T b = X.imag(); acc += (a*a) + (b*b); } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { for(uword col=0; col& X = P.at(0,col); const T a = X.real(); const T b = X.imag(); acc += (a*a) + (b*b); } } else { for(uword col=0; col& X = P.at(row,col); const T a = X.real(); const T b = X.imag(); acc += (a*a) + (b*b); } } } const T sqrt_acc = std::sqrt(acc); if( (sqrt_acc != T(0)) && arma_isfinite(sqrt_acc) ) { return sqrt_acc; } else { arma_extra_debug_print("op_norm::vec_norm_2(): detected possible underflow or overflow"); const quasi_unwrap::stored_type> R(P.Q); const uword N = R.M.n_elem; const eT* R_mem = R.M.memptr(); T max_val = priv::most_neg(); for(uword i=0; i max_val) { max_val = val_i; } } if(max_val == T(0)) { return T(0); } T alt_acc = T(0); for(uword i=0; i arma_hot inline eT op_norm::vec_norm_2_direct_std(const Mat& X) { arma_extra_debug_sigprint(); const uword N = X.n_elem; const eT* A = X.memptr(); eT result; if(N < uword(32)) { result = op_norm::vec_norm_2_direct_mem(N,A); } else { #if defined(ARMA_USE_ATLAS) { result = atlas::cblas_nrm2(N,A); } #elif defined(ARMA_USE_BLAS) { result = blas::nrm2(N,A); } #else { result = op_norm::vec_norm_2_direct_mem(N,A); } #endif } if( (result != eT(0)) && arma_isfinite(result) ) { return result; } else { arma_extra_debug_print("op_norm::vec_norm_2_direct_std(): detected possible underflow or overflow"); return op_norm::vec_norm_2_direct_robust(X); } } template arma_hot inline eT op_norm::vec_norm_2_direct_mem(const uword N, const eT* A) { arma_extra_debug_sigprint(); eT acc; #if defined(ARMA_SIMPLE_LOOPS) || (defined(__FINITE_MATH_ONLY__) && (__FINITE_MATH_ONLY__ > 0)) { eT acc1 = eT(0); if(memory::is_aligned(A)) { memory::mark_as_aligned(A); for(uword i=0; i arma_hot inline eT op_norm::vec_norm_2_direct_robust(const Mat& X) { arma_extra_debug_sigprint(); const uword N = X.n_elem; const eT* A = X.memptr(); eT max_val = priv::most_neg(); uword j; for(j=1; j max_val) { max_val = val_i; } if(val_j > max_val) { max_val = val_j; } } if((j-1) < N) { const eT val_i = std::abs(*A); if(val_i > max_val) { max_val = val_i; } } if(max_val == eT(0)) { return eT(0); } const eT* B = X.memptr(); eT acc1 = eT(0); eT acc2 = eT(0); for(j=1; j arma_hot inline typename T1::pod_type op_norm::vec_norm_k(const Proxy& P, const int k) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; T acc = T(0); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); const uword N = P.get_n_elem(); uword i,j; for(i=0, j=1; j arma_hot inline typename T1::pod_type op_norm::vec_norm_max(const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const uword N = P.get_n_elem(); T max_val = (N != 1) ? priv::most_neg() : std::abs(P[0]); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j arma_hot inline typename T1::pod_type op_norm::vec_norm_min(const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const uword N = P.get_n_elem(); T min_val = (N != 1) ? priv::most_pos() : std::abs(P[0]); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j tmp_i) { min_val = tmp_i; } if(min_val > tmp_j) { min_val = tmp_j; } } if(i < N) { const T tmp_i = std::abs(A[i]); if(min_val > tmp_i) { min_val = tmp_i; } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows != 1) { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const T tmp = std::abs(P.at(row,col)); if(min_val > tmp) { min_val = tmp; } } } else { for(uword col=0; col < n_cols; ++col) { const T tmp = std::abs(P.at(0,col)); if(min_val > tmp) { min_val = tmp; } } } } return min_val; } template inline typename T1::pod_type op_norm::mat_norm_1(const Proxy& P) { arma_extra_debug_sigprint(); // TODO: this can be sped up with a dedicated implementation return as_scalar( max( sum(abs(P.Q), 0), 1) ); } template inline typename T1::pod_type op_norm::mat_norm_2(const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; Col S; svd(S, P.Q); return (S.n_elem > 0) ? max(S) : T(0); } template inline typename T1::pod_type op_norm::mat_norm_inf(const Proxy& P) { arma_extra_debug_sigprint(); // TODO: this can be sped up with a dedicated implementation return as_scalar( max( sum(abs(P.Q), 1), 0) ); } // // norms for sparse matrices template inline typename T1::pod_type op_norm::mat_norm_1(const SpProxy& P) { arma_extra_debug_sigprint(); // TODO: this can be sped up with a dedicated implementation return as_scalar( max( sum(abs(P.Q), 0), 1) ); } template inline typename T1::pod_type op_norm::mat_norm_2(const SpProxy& P, const typename arma_real_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); // norm = sqrt( largest eigenvalue of (A^H)*A ), where ^H is the conjugate transpose // http://math.stackexchange.com/questions/4368/computing-the-largest-eigenvalue-of-a-very-large-sparse-matrix typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const unwrap_spmat::stored_type> tmp(P.Q); const SpMat& A = tmp.M; const SpMat B = trans(A); const SpMat C = (A.n_rows <= A.n_cols) ? (A*B) : (B*A); const Col eigval = eigs_sym(C, 1); return (eigval.n_elem > 0) ? std::sqrt(eigval[0]) : T(0); } template inline typename T1::pod_type op_norm::mat_norm_2(const SpProxy& P, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); //typedef typename T1::elem_type eT; typedef typename T1::pod_type T; arma_ignore(P); arma_stop("norm(): unimplemented norm type for complex sparse matrices"); return T(0); // const unwrap_spmat::stored_type> tmp(P.Q); // // const SpMat& A = tmp.M; // const SpMat B = trans(A); // // const SpMat C = (A.n_rows <= A.n_cols) ? (A*B) : (B*A); // // const Col eigval = eigs_gen(C, 1); } template inline typename T1::pod_type op_norm::mat_norm_inf(const SpProxy& P) { arma_extra_debug_sigprint(); // TODO: this can be sped up with a dedicated implementation return as_scalar( max( sum(abs(P.Q), 1), 0) ); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_shuffle.hpp0000666000000000000000000000173512620272703021604 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup fn_shuffle //! @{ template arma_inline typename enable_if2 < (is_arma_type::value), const Op >::result shuffle ( const T1& X ) { arma_extra_debug_sigprint(); return Op(X); } template arma_inline typename enable_if2 < (is_arma_type::value), const Op >::result shuffle ( const T1& X, const uword dim ) { arma_extra_debug_sigprint(); return Op(X, dim, 0); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_flip.hpp0000666000000000000000000000154012620272703021074 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_flip //! @{ template arma_inline typename enable_if2< is_arma_type::value, const Op >::result flipud(const T1& X) { arma_extra_debug_sigprint(); return Op(X); } template arma_inline typename enable_if2< is_arma_type::value, const Op >::result fliplr(const T1& X) { arma_extra_debug_sigprint(); return Op(X); } //! @} armadillo-6.500.5/include/armadillo_bits/mul_gemv.hpp0000666000000000000000000003057712650111756021311 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup gemv //! @{ //! for tiny square matrices, size <= 4x4 template class gemv_emul_tinysq { public: template struct pos { static const uword n2 = (do_trans_A == false) ? (row + col*2) : (col + row*2); static const uword n3 = (do_trans_A == false) ? (row + col*3) : (col + row*3); static const uword n4 = (do_trans_A == false) ? (row + col*4) : (col + row*4); }; template arma_hot arma_inline static void assign(eT* y, const eT acc, const eT alpha, const eT beta) { if(use_beta == false) { y[i] = (use_alpha == false) ? acc : alpha*acc; } else { const eT tmp = y[i]; y[i] = beta*tmp + ( (use_alpha == false) ? acc : alpha*acc ); } } template arma_hot inline static void apply( eT* y, const TA& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); const eT* Am = A.memptr(); switch(A.n_rows) { case 1: { const eT acc = Am[0] * x[0]; assign(y, acc, alpha, beta); } break; case 2: { const eT x0 = x[0]; const eT x1 = x[1]; const eT acc0 = Am[pos<0,0>::n2]*x0 + Am[pos<0,1>::n2]*x1; const eT acc1 = Am[pos<1,0>::n2]*x0 + Am[pos<1,1>::n2]*x1; assign(y, acc0, alpha, beta); assign(y, acc1, alpha, beta); } break; case 3: { const eT x0 = x[0]; const eT x1 = x[1]; const eT x2 = x[2]; const eT acc0 = Am[pos<0,0>::n3]*x0 + Am[pos<0,1>::n3]*x1 + Am[pos<0,2>::n3]*x2; const eT acc1 = Am[pos<1,0>::n3]*x0 + Am[pos<1,1>::n3]*x1 + Am[pos<1,2>::n3]*x2; const eT acc2 = Am[pos<2,0>::n3]*x0 + Am[pos<2,1>::n3]*x1 + Am[pos<2,2>::n3]*x2; assign(y, acc0, alpha, beta); assign(y, acc1, alpha, beta); assign(y, acc2, alpha, beta); } break; case 4: { const eT x0 = x[0]; const eT x1 = x[1]; const eT x2 = x[2]; const eT x3 = x[3]; const eT acc0 = Am[pos<0,0>::n4]*x0 + Am[pos<0,1>::n4]*x1 + Am[pos<0,2>::n4]*x2 + Am[pos<0,3>::n4]*x3; const eT acc1 = Am[pos<1,0>::n4]*x0 + Am[pos<1,1>::n4]*x1 + Am[pos<1,2>::n4]*x2 + Am[pos<1,3>::n4]*x3; const eT acc2 = Am[pos<2,0>::n4]*x0 + Am[pos<2,1>::n4]*x1 + Am[pos<2,2>::n4]*x2 + Am[pos<2,3>::n4]*x3; const eT acc3 = Am[pos<3,0>::n4]*x0 + Am[pos<3,1>::n4]*x1 + Am[pos<3,2>::n4]*x2 + Am[pos<3,3>::n4]*x3; assign(y, acc0, alpha, beta); assign(y, acc1, alpha, beta); assign(y, acc2, alpha, beta); assign(y, acc3, alpha, beta); } break; default: ; } } }; class gemv_emul_helper { public: template arma_hot inline static typename arma_not_cx::result dot_row_col( const TA& A, const eT* x, const uword row, const uword N ) { eT acc1 = eT(0); eT acc2 = eT(0); uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT xi = x[i]; const eT xj = x[j]; acc1 += A.at(row,i) * xi; acc2 += A.at(row,j) * xj; } if(i < N) { acc1 += A.at(row,i) * x[i]; } return (acc1 + acc2); } template arma_hot inline static typename arma_cx_only::result dot_row_col( const TA& A, const eT* x, const uword row, const uword N ) { typedef typename get_pod_type::result T; T val_real = T(0); T val_imag = T(0); for(uword i=0; i& Ai = A.at(row,i); const std::complex& xi = x[i]; const T a = Ai.real(); const T b = Ai.imag(); const T c = xi.real(); const T d = xi.imag(); val_real += (a*c) - (b*d); val_imag += (a*d) + (b*c); } return std::complex(val_real, val_imag); } }; //! \brief //! Partial emulation of ATLAS/BLAS gemv(). //! 'y' is assumed to have been set to the correct size (i.e. taking into account the transpose) template class gemv_emul { public: template arma_hot inline static void apply( eT* y, const TA& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; if(do_trans_A == false) { if(A_n_rows == 1) { const eT acc = op_dot::direct_dot_arma(A_n_cols, A.memptr(), x); if( (use_alpha == false) && (use_beta == false) ) { y[0] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { y[0] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { y[0] = acc + beta*y[0]; } else if( (use_alpha == true ) && (use_beta == true ) ) { y[0] = alpha*acc + beta*y[0]; } } else for(uword row=0; row < A_n_rows; ++row) { const eT acc = gemv_emul_helper::dot_row_col(A, x, row, A_n_cols); if( (use_alpha == false) && (use_beta == false) ) { y[row] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { y[row] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { y[row] = acc + beta*y[row]; } else if( (use_alpha == true ) && (use_beta == true ) ) { y[row] = alpha*acc + beta*y[row]; } } } else if(do_trans_A == true) { if(is_cx::no) { for(uword col=0; col < A_n_cols; ++col) { // col is interpreted as row when storing the results in 'y' // const eT* A_coldata = A.colptr(col); // // eT acc = eT(0); // for(uword row=0; row < A_n_rows; ++row) // { // acc += A_coldata[row] * x[row]; // } const eT acc = op_dot::direct_dot_arma(A_n_rows, A.colptr(col), x); if( (use_alpha == false) && (use_beta == false) ) { y[col] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { y[col] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { y[col] = acc + beta*y[col]; } else if( (use_alpha == true ) && (use_beta == true ) ) { y[col] = alpha*acc + beta*y[col]; } } } else { Mat AA; op_htrans::apply_mat_noalias(AA, A); gemv_emul::apply(y, AA, x, alpha, beta); } } } }; //! \brief //! Wrapper for ATLAS/BLAS gemv function, using template arguments to control the arguments passed to gemv. //! 'y' is assumed to have been set to the correct size (i.e. taking into account the transpose) template class gemv { public: template inline static void apply_blas_type( eT* y, const TA& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); if( (A.n_rows <= 4) && (A.n_rows == A.n_cols) && (is_cx::no) ) { gemv_emul_tinysq::apply(y, A, x, alpha, beta); } else { #if defined(ARMA_USE_ATLAS) { arma_debug_assert_atlas_size(A); if(is_cx::no) { // use gemm() instead of gemv() to work around a speed issue in Atlas 3.8.4 arma_extra_debug_print("atlas::cblas_gemm()"); atlas::cblas_gemm ( atlas::CblasColMajor, (do_trans_A) ? ( is_cx::yes ? CblasConjTrans : atlas::CblasTrans ) : atlas::CblasNoTrans, atlas::CblasNoTrans, (do_trans_A) ? A.n_cols : A.n_rows, 1, (do_trans_A) ? A.n_rows : A.n_cols, (use_alpha) ? alpha : eT(1), A.mem, A.n_rows, x, (do_trans_A) ? A.n_rows : A.n_cols, (use_beta) ? beta : eT(0), y, (do_trans_A) ? A.n_cols : A.n_rows ); } else { arma_extra_debug_print("atlas::cblas_gemv()"); atlas::cblas_gemv ( atlas::CblasColMajor, (do_trans_A) ? ( is_cx::yes ? CblasConjTrans : atlas::CblasTrans ) : atlas::CblasNoTrans, A.n_rows, A.n_cols, (use_alpha) ? alpha : eT(1), A.mem, A.n_rows, x, 1, (use_beta) ? beta : eT(0), y, 1 ); } } #elif defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::gemv()"); arma_debug_assert_blas_size(A); const char trans_A = (do_trans_A) ? ( is_cx::yes ? 'C' : 'T' ) : 'N'; const blas_int m = blas_int(A.n_rows); const blas_int n = blas_int(A.n_cols); const eT local_alpha = (use_alpha) ? alpha : eT(1); //const blas_int lda = A.n_rows; const blas_int inc = blas_int(1); const eT local_beta = (use_beta) ? beta : eT(0); arma_extra_debug_print( arma_str::format("blas::gemv(): trans_A = %c") % trans_A ); blas::gemv ( &trans_A, &m, &n, &local_alpha, A.mem, &m, // lda x, &inc, &local_beta, y, &inc ); } #else { gemv_emul::apply(y,A,x,alpha,beta); } #endif } } template arma_inline static void apply( eT* y, const TA& A, const eT* x, const eT alpha = eT(1), const eT beta = eT(0) ) { gemv_emul::apply(y,A,x,alpha,beta); } template arma_inline static void apply ( float* y, const TA& A, const float* x, const float alpha = float(1), const float beta = float(0) ) { gemv::apply_blas_type(y,A,x,alpha,beta); } template arma_inline static void apply ( double* y, const TA& A, const double* x, const double alpha = double(1), const double beta = double(0) ) { gemv::apply_blas_type(y,A,x,alpha,beta); } template arma_inline static void apply ( std::complex* y, const TA& A, const std::complex* x, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { gemv::apply_blas_type(y,A,x,alpha,beta); } template arma_inline static void apply ( std::complex* y, const TA& A, const std::complex* x, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { gemv::apply_blas_type(y,A,x,alpha,beta); } }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_cov.hpp0000666000000000000000000000222112620272703020726 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup fn_cov //! @{ template inline const Op cov(const Base& X, const uword norm_type = 0) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "cov(): parameter 'norm_type' must be 0 or 1" ); return Op(X.get_ref(), norm_type, 0); } template inline const Glue cov(const Base& A, const Base& B, const uword norm_type = 0) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "cov(): parameter 'norm_type' must be 0 or 1" ); return Glue(A.get_ref(), B.get_ref(), norm_type); } //! @} armadillo-6.500.5/include/armadillo_bits/arma_rng_cxx11.hpp0000666000000000000000000000520312633722167022301 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arma_rng_cxx11 //! @{ #if defined(ARMA_USE_CXX11) class arma_rng_cxx11 { public: typedef std::mt19937_64::result_type seed_type; inline void set_seed(const seed_type val); arma_inline int randi_val(); arma_inline double randu_val(); arma_inline double randn_val(); template arma_inline void randn_dual_val(eT& out1, eT& out2); template inline void randi_fill(eT* mem, const uword N, const int a, const int b); inline static int randi_max_val(); template inline void randg_fill(eT* mem, const uword N, const double a, const double b); private: arma_aligned std::mt19937_64 engine; // typedef for std::mersenne_twister_engine with preset parameters arma_aligned std::uniform_int_distribution i_distr; // by default uses a=0, b=std::numeric_limits::max() arma_aligned std::uniform_real_distribution u_distr; // by default uses [0,1) interval arma_aligned std::normal_distribution n_distr; // by default uses mean=0.0 and stddev=1.0 }; inline void arma_rng_cxx11::set_seed(const arma_rng_cxx11::seed_type val) { engine.seed(val); } arma_inline int arma_rng_cxx11::randi_val() { return i_distr(engine); } arma_inline double arma_rng_cxx11::randu_val() { return u_distr(engine); } arma_inline double arma_rng_cxx11::randn_val() { return n_distr(engine); } template arma_inline void arma_rng_cxx11::randn_dual_val(eT& out1, eT& out2) { out1 = eT( n_distr(engine) ); out2 = eT( n_distr(engine) ); } template inline void arma_rng_cxx11::randi_fill(eT* mem, const uword N, const int a, const int b) { std::uniform_int_distribution local_i_distr(a, b); for(uword i=0; i::max(); } template inline void arma_rng_cxx11::randg_fill(eT* mem, const uword N, const double a, const double b) { std::gamma_distribution g_distr(a,b); for(uword i=0; i principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors //! tsquared_out -> Hotelling's T^2 statistic template inline bool princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, Col& tsquared_out, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = op_princomp::direct_princomp(coeff_out, score_out, latent_out, tsquared_out, X); if(status == false) { coeff_out.reset(); score_out.reset(); latent_out.reset(); tsquared_out.reset(); arma_debug_warn("princomp(): decomposition failed"); } return status; } //! \brief //! principal component analysis -- 3 arguments version //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors template inline bool princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = op_princomp::direct_princomp(coeff_out, score_out, latent_out, X); if(status == false) { coeff_out.reset(); score_out.reset(); latent_out.reset(); arma_debug_warn("princomp(): decomposition failed"); } return status; } //! \brief //! principal component analysis -- 2 arguments version //! coeff_out -> principal component coefficients //! score_out -> projected samples template inline bool princomp ( Mat& coeff_out, Mat& score_out, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = op_princomp::direct_princomp(coeff_out, score_out, X); if(status == false) { coeff_out.reset(); score_out.reset(); arma_debug_warn("princomp(): decomposition failed"); } return status; } //! \brief //! principal component analysis -- 1 argument version //! coeff_out -> principal component coefficients template inline bool princomp ( Mat& coeff_out, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = op_princomp::direct_princomp(coeff_out, X); if(status == false) { coeff_out.reset(); arma_debug_warn("princomp(): decomposition failed"); } return status; } template inline const Op princomp ( const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X.get_ref()); } //! @} armadillo-6.500.5/include/armadillo_bits/gmm_diag_meat.hpp0000666000000000000000000014740012646454123022245 0ustar rootroot// Copyright (C) 2014-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup gmm_diag //! @{ namespace gmm_priv { template inline gmm_diag::~gmm_diag() { arma_extra_debug_sigprint_this(this); arma_type_check(( (is_same_type::value == false) && (is_same_type::value == false) )); } template inline gmm_diag::gmm_diag() { arma_extra_debug_sigprint_this(this); } template inline gmm_diag::gmm_diag(const gmm_diag& x) { arma_extra_debug_sigprint_this(this); init(x); } template inline const gmm_diag& gmm_diag::operator=(const gmm_diag& x) { arma_extra_debug_sigprint(); init(x); return *this; } template inline gmm_diag::gmm_diag(const uword in_n_dims, const uword in_n_gaus) { arma_extra_debug_sigprint_this(this); init(in_n_dims, in_n_gaus); } template inline void gmm_diag::reset() { arma_extra_debug_sigprint(); mah_aux.reset(); init(0, 0); } template inline void gmm_diag::reset(const uword in_n_dims, const uword in_n_gaus) { arma_extra_debug_sigprint(); mah_aux.reset(); init(in_n_dims, in_n_gaus); } template template inline void gmm_diag::set_params(const Base& in_means_expr, const Base& in_dcovs_expr, const Base& in_hefts_expr) { arma_extra_debug_sigprint(); const unwrap tmp1(in_means_expr.get_ref()); const unwrap tmp2(in_dcovs_expr.get_ref()); const unwrap tmp3(in_hefts_expr.get_ref()); const Mat& in_means = tmp1.M; const Mat& in_dcovs = tmp2.M; const Mat& in_hefts = tmp3.M; arma_debug_check ( (size(in_means) != size(in_dcovs)) || (in_hefts.n_cols != in_means.n_cols) || (in_hefts.n_rows != 1), "gmm_diag::set_params(): given parameters have inconsistent and/or wrong sizes" ); arma_debug_check( (in_means.is_finite() == false), "gmm_diag::set_params(): given means have non-finite values" ); arma_debug_check( (in_dcovs.is_finite() == false), "gmm_diag::set_params(): given dcovs have non-finite values" ); arma_debug_check( (in_hefts.is_finite() == false), "gmm_diag::set_params(): given hefts have non-finite values" ); arma_debug_check( (any(vectorise(in_dcovs) <= eT(0))), "gmm_diag::set_params(): given dcovs have negative or zero values" ); arma_debug_check( (any(vectorise(in_hefts) < eT(0))), "gmm_diag::set_params(): given hefts have negative values" ); const eT s = accu(in_hefts); arma_debug_check( ((s < (eT(1) - Datum::eps)) || (s > (eT(1) + Datum::eps))), "gmm_diag::set_params(): sum of given hefts is not 1" ); access::rw(means) = in_means; access::rw(dcovs) = in_dcovs; access::rw(hefts) = in_hefts; init_constants(); } template template inline void gmm_diag::set_means(const Base& in_means_expr) { arma_extra_debug_sigprint(); const unwrap tmp(in_means_expr.get_ref()); const Mat& in_means = tmp.M; arma_debug_check( (size(in_means) != size(means)), "gmm_diag::set_means(): given means have incompatible size" ); arma_debug_check( (in_means.is_finite() == false), "gmm_diag::set_means(): given means have non-finite values" ); access::rw(means) = in_means; } template template inline void gmm_diag::set_dcovs(const Base& in_dcovs_expr) { arma_extra_debug_sigprint(); const unwrap tmp(in_dcovs_expr.get_ref()); const Mat& in_dcovs = tmp.M; arma_debug_check( (size(in_dcovs) != size(dcovs)), "gmm_diag::set_dcovs(): given dcovs have incompatible size" ); arma_debug_check( (in_dcovs.is_finite() == false), "gmm_diag::set_dcovs(): given dcovs have non-finite values" ); arma_debug_check( (any(vectorise(in_dcovs) <= eT(0))), "gmm_diag::set_dcovs(): given dcovs have negative or zero values" ); access::rw(dcovs) = in_dcovs; init_constants(); } template template inline void gmm_diag::set_hefts(const Base& in_hefts_expr) { arma_extra_debug_sigprint(); const unwrap tmp(in_hefts_expr.get_ref()); const Mat& in_hefts = tmp.M; arma_debug_check( (size(in_hefts) != size(hefts)), "gmm_diag::set_hefts(): given hefts have incompatible size" ); arma_debug_check( (in_hefts.is_finite() == false), "gmm_diag::set_hefts(): given hefts have non-finite values" ); arma_debug_check( (any(vectorise(in_hefts) < eT(0))), "gmm_diag::set_hefts(): given hefts have negative values" ); const eT s = accu(in_hefts); arma_debug_check( ((s < (eT(1) - Datum::eps)) || (s > (eT(1) + Datum::eps))), "gmm_diag::set_hefts(): sum of given hefts is not 1" ); // make sure all hefts are positive and non-zero const eT* in_hefts_mem = in_hefts.memptr(); eT* hefts_mem = access::rw(hefts).memptr(); for(uword i=0; i < hefts.n_elem; ++i) { hefts_mem[i] = (std::max)( in_hefts_mem[i], std::numeric_limits::min() ); } access::rw(hefts) /= accu(hefts); log_hefts = log(hefts); } template inline uword gmm_diag::n_dims() const { return means.n_rows; } template inline uword gmm_diag::n_gaus() const { return means.n_cols; } template inline bool gmm_diag::load(const std::string name) { arma_extra_debug_sigprint(); Cube Q; bool status = Q.load(name, arma_binary); if( (status == false) || (Q.n_slices != 2) ) { reset(); return false; } if( (Q.n_rows < 2) || (Q.n_cols < 1) ) { reset(); return true; } access::rw(hefts) = Q.slice(0).row(0); access::rw(means) = Q.slice(0).submat(1, 0, Q.n_rows-1, Q.n_cols-1); access::rw(dcovs) = Q.slice(1).submat(1, 0, Q.n_rows-1, Q.n_cols-1); init_constants(); return true; } template inline bool gmm_diag::save(const std::string name) const { arma_extra_debug_sigprint(); Cube Q(means.n_rows + 1, means.n_cols, 2); if(Q.n_elem > 0) { Q.slice(0).row(0) = hefts; Q.slice(1).row(0).zeros(); // reserved for future use Q.slice(0).submat(1, 0, size(means)) = means; Q.slice(1).submat(1, 0, size(dcovs)) = dcovs; } const bool status = Q.save(name, arma_binary); return status; } template inline Col gmm_diag::generate() const { arma_extra_debug_sigprint(); const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; Col out( (N_gaus > 0) ? N_dims : uword(0) ); if(N_gaus > 0) { const double val = randu(); double csum = double(0); uword gaus_id = 0; for(uword j=0; j < N_gaus; ++j) { csum += hefts[j]; if(val <= csum) { gaus_id = j; break; } } out = randn< Col >(N_dims); out %= sqrt(dcovs.col(gaus_id)); out += means.col(gaus_id); } return out; } template inline Mat gmm_diag::generate(const uword N_vec) const { arma_extra_debug_sigprint(); const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; Mat out( ( (N_gaus > 0) ? N_dims : uword(0) ), N_vec ); if(N_gaus > 0) { const eT* hefts_mem = hefts.memptr(); for(uword i=0; i < N_vec; ++i) { const double val = randu(); double csum = double(0); uword gaus_id = 0; for(uword j=0; j < N_gaus; ++j) { csum += hefts_mem[j]; if(val <= csum) { gaus_id = j; break; } } subview_col out_col = out.col(i); out_col = randn< Col >(N_dims); out_col %= sqrt(dcovs.col(gaus_id)); out_col += means.col(gaus_id); } } return out; } template template inline eT gmm_diag::log_p(const T1& expr, const gmm_empty_arg& junk1, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == true))>::result* junk2) const { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); const quasi_unwrap tmp(expr); arma_debug_check( (tmp.M.n_rows != means.n_rows), "gmm_diag::log_p(): incompatible dimensions" ); return internal_scalar_log_p( tmp.M.memptr() ); } template template inline eT gmm_diag::log_p(const T1& expr, const uword gaus_id, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == true))>::result* junk2) const { arma_extra_debug_sigprint(); arma_ignore(junk2); const quasi_unwrap tmp(expr); arma_debug_check( (tmp.M.n_rows != means.n_rows), "gmm_diag::log_p(): incompatible dimensions" ); arma_debug_check( (gaus_id >= means.n_cols), "gmm_diag::log_p(): specified gaussian is out of range" ); return internal_scalar_log_p( tmp.M.memptr(), gaus_id ); } template template inline Row gmm_diag::log_p(const T1& expr, const gmm_empty_arg& junk1, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == false))>::result* junk2) const { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_subview::value) { const subview& X = reinterpret_cast< const subview& >(expr); return internal_vec_log_p(X); } else { const unwrap tmp(expr); const Mat& X = tmp.M; return internal_vec_log_p(X); } } template template inline Row gmm_diag::log_p(const T1& expr, const uword gaus_id, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == false))>::result* junk2) const { arma_extra_debug_sigprint(); arma_ignore(junk2); if(is_subview::value) { const subview& X = reinterpret_cast< const subview& >(expr); return internal_vec_log_p(X, gaus_id); } else { const unwrap tmp(expr); const Mat& X = tmp.M; return internal_vec_log_p(X, gaus_id); } } template template inline eT gmm_diag::avg_log_p(const Base& expr) const { arma_extra_debug_sigprint(); if(is_subview::value) { const subview& X = reinterpret_cast< const subview& >( expr.get_ref() ); return internal_avg_log_p(X); } else { const unwrap tmp(expr.get_ref()); const Mat& X = tmp.M; return internal_avg_log_p(X); } } template template inline eT gmm_diag::avg_log_p(const Base& expr, const uword gaus_id) const { arma_extra_debug_sigprint(); if(is_subview::value) { const subview& X = reinterpret_cast< const subview& >( expr.get_ref() ); return internal_avg_log_p(X, gaus_id); } else { const unwrap tmp(expr.get_ref()); const Mat& X = tmp.M; return internal_avg_log_p(X, gaus_id); } } template template inline uword gmm_diag::assign(const T1& expr, const gmm_dist_mode& dist, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == true))>::result* junk) const { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_subview_col::value) { const subview_col& X = reinterpret_cast< const subview_col& >(expr); return internal_scalar_assign(X, dist); } else { const unwrap tmp(expr); const Mat& X = tmp.M; return internal_scalar_assign(X, dist); } } template template inline urowvec gmm_diag::assign(const T1& expr, const gmm_dist_mode& dist, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == false))>::result* junk) const { arma_extra_debug_sigprint(); arma_ignore(junk); urowvec out; if(is_subview::value) { const subview& X = reinterpret_cast< const subview& >(expr); internal_vec_assign(out, X, dist); } else { const unwrap tmp(expr); const Mat& X = tmp.M; internal_vec_assign(out, X, dist); } return out; } template template inline urowvec gmm_diag::raw_hist(const Base& expr, const gmm_dist_mode& dist_mode) const { arma_extra_debug_sigprint(); const unwrap tmp(expr.get_ref()); const Mat& X = tmp.M; arma_debug_check( (X.n_rows != means.n_rows), "gmm_diag::raw_hist(): incompatible dimensions" ); arma_debug_check( ((dist_mode != eucl_dist) && (dist_mode != prob_dist)), "gmm_diag::raw_hist(): unsupported distance mode" ); urowvec hist; internal_raw_hist(hist, X, dist_mode); return hist; } template template inline Row gmm_diag::norm_hist(const Base& expr, const gmm_dist_mode& dist_mode) const { arma_extra_debug_sigprint(); const unwrap tmp(expr.get_ref()); const Mat& X = tmp.M; arma_debug_check( (X.n_rows != means.n_rows), "gmm_diag::norm_hist(): incompatible dimensions" ); arma_debug_check( ((dist_mode != eucl_dist) && (dist_mode != prob_dist)), "gmm_diag::norm_hist(): unsupported distance mode" ); urowvec hist; internal_raw_hist(hist, X, dist_mode); const uword hist_n_elem = hist.n_elem; const uword* hist_mem = hist.memptr(); eT acc = eT(0); for(uword i=0; i out(hist_n_elem); eT* out_mem = out.memptr(); for(uword i=0; i template inline bool gmm_diag::learn ( const Base& data, const uword N_gaus, const gmm_dist_mode& dist_mode, const gmm_seed_mode& seed_mode, const uword km_iter, const uword em_iter, const eT var_floor, const bool print_mode ) { arma_extra_debug_sigprint(); const bool dist_mode_ok = (dist_mode == eucl_dist) || (dist_mode == maha_dist); const bool seed_mode_ok = \ (seed_mode == keep_existing) || (seed_mode == static_subset) || (seed_mode == static_spread) || (seed_mode == random_subset) || (seed_mode == random_spread); arma_debug_check( (dist_mode_ok == false), "gmm_diag::learn(): dist_mode must be eucl_dist or maha_dist" ); arma_debug_check( (seed_mode_ok == false), "gmm_diag::learn(): unknown seed_mode" ); arma_debug_check( (var_floor < eT(0) ), "gmm_diag::learn(): variance floor is negative" ); const unwrap tmp_X(data.get_ref()); const Mat& X = tmp_X.M; if(X.is_empty() ) { arma_debug_warn("gmm_diag::learn(): given matrix is empty" ); return false; } if(X.is_finite() == false) { arma_debug_warn("gmm_diag::learn(): given matrix has non-finite values"); return false; } if(N_gaus == 0) { reset(); return true; } if(dist_mode == maha_dist) { mah_aux = var(X,1,1); const uword mah_aux_n_elem = mah_aux.n_elem; eT* mah_aux_mem = mah_aux.memptr(); for(uword i=0; i < mah_aux_n_elem; ++i) { const eT val = mah_aux_mem[i]; mah_aux_mem[i] = ((val != eT(0)) && arma_isfinite(val)) ? eT(1) / val : eT(1); } } // copy current model, in case of failure by k-means and/or EM const gmm_diag orig = (*this); // initial means if(seed_mode == keep_existing) { if(means.is_empty() ) { arma_debug_warn("gmm_diag::learn(): no existing means" ); return false; } if(X.n_rows != means.n_rows) { arma_debug_warn("gmm_diag::learn(): dimensionality mismatch"); return false; } // TODO: also check for number of vectors? } else { if(X.n_cols < N_gaus) { arma_debug_warn("gmm_diag::learn(): number of vectors is less than number of gaussians"); return false; } reset(X.n_rows, N_gaus); if(print_mode) { get_stream_err2() << "gmm_diag::learn(): generating initial means\n"; } if(dist_mode == eucl_dist) { generate_initial_means<1>(X, seed_mode); } else if(dist_mode == maha_dist) { generate_initial_means<2>(X, seed_mode); } } // k-means if(km_iter > 0) { const arma_ostream_state stream_state(get_stream_err2()); bool status = false; if(dist_mode == eucl_dist) { status = km_iterate<1>(X, km_iter, print_mode, "gmm_diag::learn(): k-means"); } else if(dist_mode == maha_dist) { status = km_iterate<2>(X, km_iter, print_mode, "gmm_diag::learn(): k-means"); } stream_state.restore(get_stream_err2()); if(status == false) { arma_debug_warn("gmm_diag::learn(): k-means algorithm failed; not enough data, or too many gaussians requested"); init(orig); return false; } } // initial dcovs const eT vfloor = (eT(var_floor) > eT(0)) ? eT(var_floor) : std::numeric_limits::min(); if(seed_mode != keep_existing) { if(print_mode) { get_stream_err2() << "gmm_diag::learn(): generating initial covariances\n"; } if(dist_mode == eucl_dist) { generate_initial_dcovs_and_hefts<1>(X, vfloor); } else if(dist_mode == maha_dist) { generate_initial_dcovs_and_hefts<2>(X, vfloor); } } // EM algorithm if(em_iter > 0) { const arma_ostream_state stream_state(get_stream_err2()); const bool status = em_iterate(X, em_iter, vfloor, print_mode); stream_state.restore(get_stream_err2()); if(status == false) { arma_debug_warn("gmm_diag::learn(): EM algorithm failed"); init(orig); return false; } } mah_aux.reset(); init_constants(); return true; } template template inline bool gmm_diag::kmeans_wrapper ( Mat& user_means, const Base& data, const uword N_gaus, const gmm_seed_mode& seed_mode, const uword km_iter, const bool print_mode ) { arma_extra_debug_sigprint(); const bool seed_mode_ok = \ (seed_mode == keep_existing) || (seed_mode == static_subset) || (seed_mode == static_spread) || (seed_mode == random_subset) || (seed_mode == random_spread); arma_debug_check( (seed_mode_ok == false), "kmeans(): unknown seed_mode" ); const unwrap tmp_X(data.get_ref()); const Mat& X = tmp_X.M; if(X.is_empty() ) { arma_debug_warn("kmeans(): given matrix is empty" ); return false; } if(X.is_finite() == false) { arma_debug_warn("kmeans(): given matrix has non-finite values"); return false; } if(N_gaus == 0) { reset(); return true; } // initial means if(seed_mode == keep_existing) { access::rw(means) = user_means; if(means.is_empty() ) { arma_debug_warn("kmeans(): no existing means" ); return false; } if(X.n_rows != means.n_rows) { arma_debug_warn("kmeans(): dimensionality mismatch"); return false; } // TODO: also check for number of vectors? } else { if(X.n_cols < N_gaus) { arma_debug_warn("kmeans(): number of vectors is less than number of means"); return false; } access::rw(means).zeros(X.n_rows, N_gaus); if(print_mode) { get_stream_err2() << "kmeans(): generating initial means\n"; } generate_initial_means<1>(X, seed_mode); } // k-means if(km_iter > 0) { const arma_ostream_state stream_state(get_stream_err2()); bool status = false; status = km_iterate<1>(X, km_iter, print_mode, "kmeans()"); stream_state.restore(get_stream_err2()); if(status == false) { arma_debug_warn("kmeans(): clustering failed; not enough data, or too many means requested"); return false; } } return true; } // // // template inline void gmm_diag::init(const gmm_diag& x) { arma_extra_debug_sigprint(); gmm_diag& t = *this; if(&t != &x) { access::rw(t.means) = x.means; access::rw(t.dcovs) = x.dcovs; access::rw(t.hefts) = x.hefts; init_constants(); } } template inline void gmm_diag::init(const uword in_n_dims, const uword in_n_gaus) { arma_extra_debug_sigprint(); access::rw(means).zeros(in_n_dims, in_n_gaus); access::rw(dcovs).ones(in_n_dims, in_n_gaus); access::rw(hefts).set_size(in_n_gaus); access::rw(hefts).fill(eT(1) / eT(in_n_gaus)); init_constants(); } template inline void gmm_diag::init_constants() { arma_extra_debug_sigprint(); const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; const eT tmp = (eT(N_dims)/eT(2)) * std::log(eT(2) * Datum::pi); log_det_etc.set_size(N_gaus); for(uword i=0; i::min() ); } log_hefts = log(hefts); } template inline umat gmm_diag::internal_gen_boundaries(const uword N) const { arma_extra_debug_sigprint(); #if defined(_OPENMP) // const uword n_cores = 0; const uword n_cores = uword(omp_get_num_procs()); const uword n_threads = (n_cores > 0) ? ( (n_cores <= N) ? n_cores : 1 ) : 1; #else // static const uword n_cores = 0; static const uword n_threads = 1; #endif // get_stream_err2() << "gmm_diag::internal_gen_boundaries(): n_cores: " << n_cores << '\n'; // get_stream_err2() << "gmm_diag::internal_gen_boundaries(): n_threads: " << n_threads << '\n'; umat boundaries(2, n_threads); if(N > 0) { const uword chunk_size = N / n_threads; uword count = 0; for(uword t=0; t arma_hot inline eT gmm_diag::internal_scalar_log_p(const eT* x) const { arma_extra_debug_sigprint(); const eT* log_hefts_mem = log_hefts.mem; const uword N_gaus = means.n_cols; if(N_gaus > 0) { eT log_sum = internal_scalar_log_p(x, 0) + log_hefts_mem[0]; for(uword g=1; g < N_gaus; ++g) { const eT tmp = internal_scalar_log_p(x, g) + log_hefts_mem[g]; log_sum = log_add_exp(log_sum, tmp); } return log_sum; } else { return -Datum::inf; } } template arma_hot inline eT gmm_diag::internal_scalar_log_p(const eT* x, const uword g) const { arma_extra_debug_sigprint(); const eT* mean = means.colptr(g); const eT* dcov = dcovs.colptr(g); const uword N_dims = means.n_rows; eT val_i = eT(0); eT val_j = eT(0); uword i,j; for(i=0, j=1; j template inline Row gmm_diag::internal_vec_log_p(const T1& X) const { arma_extra_debug_sigprint(); arma_debug_check( (X.n_rows != means.n_rows), "gmm_diag::log_p(): incompatible dimensions" ); const uword N = X.n_cols; Row out(N); if(N > 0) { #if defined(_OPENMP) { const arma_omp_state save_omp_state; const umat boundaries = internal_gen_boundaries(N); const uword n_threads = boundaries.n_cols; #pragma omp parallel for for(uword t=0; t < n_threads; ++t) { const uword start_index = boundaries.at(0,t); const uword end_index = boundaries.at(1,t); eT* out_mem = out.memptr(); for(uword i=start_index; i <= end_index; ++i) { out_mem[i] = internal_scalar_log_p( X.colptr(i) ); } } } #else { eT* out_mem = out.memptr(); for(uword i=0; i < N; ++i) { out_mem[i] = internal_scalar_log_p( X.colptr(i) ); } } #endif } return out; } template template inline Row gmm_diag::internal_vec_log_p(const T1& X, const uword gaus_id) const { arma_extra_debug_sigprint(); arma_debug_check( (X.n_rows != means.n_rows), "gmm_diag::log_p(): incompatible dimensions" ); arma_debug_check( (gaus_id >= means.n_cols), "gmm_diag::log_p(): gaus_id is out of range" ); const uword N = X.n_cols; Row out(N); if(N > 0) { #if defined(_OPENMP) { const arma_omp_state save_omp_state; const umat boundaries = internal_gen_boundaries(N); const uword n_threads = boundaries.n_cols; #pragma omp parallel for for(uword t=0; t < n_threads; ++t) { const uword start_index = boundaries.at(0,t); const uword end_index = boundaries.at(1,t); eT* out_mem = out.memptr(); for(uword i=start_index; i <= end_index; ++i) { out_mem[i] = internal_scalar_log_p( X.colptr(i), gaus_id ); } } } #else { eT* out_mem = out.memptr(); for(uword i=0; i < N; ++i) { out_mem[i] = internal_scalar_log_p( X.colptr(i), gaus_id ); } } #endif } return out; } template template inline eT gmm_diag::internal_avg_log_p(const T1& X) const { arma_extra_debug_sigprint(); arma_debug_check( (X.n_rows != means.n_rows), "gmm_diag::avg_log_p(): incompatible dimensions" ); const uword N = X.n_cols; if(N == 0) { return (-Datum::inf); } #if defined(_OPENMP) { const arma_omp_state save_omp_state; const umat boundaries = internal_gen_boundaries(N); const uword n_threads = boundaries.n_cols; field< running_mean_scalar > t_running_means(n_threads); #pragma omp parallel for for(uword t=0; t < n_threads; ++t) { const uword start_index = boundaries.at(0,t); const uword end_index = boundaries.at(1,t); running_mean_scalar& current_running_mean = t_running_means[t]; for(uword i=start_index; i <= end_index; ++i) { current_running_mean( internal_scalar_log_p( X.colptr(i) ) ); } } eT avg = eT(0); for(uword t=0; t < n_threads; ++t) { running_mean_scalar& current_running_mean = t_running_means[t]; const eT w = eT(current_running_mean.count()) / eT(N); avg += w * current_running_mean.mean(); } return avg; } #else { running_mean_scalar running_mean; for(uword i=0; i template inline eT gmm_diag::internal_avg_log_p(const T1& X, const uword gaus_id) const { arma_extra_debug_sigprint(); arma_debug_check( (X.n_rows != means.n_rows), "gmm_diag::avg_log_p(): incompatible dimensions" ); arma_debug_check( (gaus_id >= means.n_cols), "gmm_diag::avg_log_p(): specified gaussian is out of range" ); const uword N = X.n_cols; if(N == 0) { return (-Datum::inf); } #if defined(_OPENMP) { const arma_omp_state save_omp_state; const umat boundaries = internal_gen_boundaries(N); const uword n_threads = boundaries.n_cols; field< running_mean_scalar > t_running_means(n_threads); #pragma omp parallel for for(uword t=0; t < n_threads; ++t) { const uword start_index = boundaries.at(0,t); const uword end_index = boundaries.at(1,t); running_mean_scalar& current_running_mean = t_running_means[t]; for(uword i=start_index; i <= end_index; ++i) { current_running_mean( internal_scalar_log_p( X.colptr(i), gaus_id) ); } } eT avg = eT(0); for(uword t=0; t < n_threads; ++t) { running_mean_scalar& current_running_mean = t_running_means[t]; const eT w = eT(current_running_mean.count()) / eT(N); avg += w * current_running_mean.mean(); } return avg; } #else { running_mean_scalar running_mean; for(uword i=0; i template inline uword gmm_diag::internal_scalar_assign(const T1& X, const gmm_dist_mode& dist_mode) const { arma_extra_debug_sigprint(); const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; arma_debug_check( (X.n_rows != N_dims), "gmm_diag::assign(): incompatible dimensions" ); arma_debug_check( (N_gaus == 0), "gmm_diag::assign(): model has no means" ); const eT* X_mem = X.colptr(0); if(dist_mode == eucl_dist) { eT best_dist = Datum::inf; uword best_g = 0; for(uword g=0; g < N_gaus; ++g) { const eT tmp_dist = distance::eval(N_dims, X_mem, means.colptr(g), X_mem); if(tmp_dist <= best_dist) { best_dist = tmp_dist; best_g = g; } } return best_g; } else if(dist_mode == prob_dist) { const eT* log_hefts_mem = log_hefts.memptr(); eT best_p = -Datum::inf; uword best_g = 0; for(uword g=0; g < N_gaus; ++g) { const eT tmp_p = internal_scalar_log_p(X_mem, g) + log_hefts_mem[g]; if(tmp_p >= best_p) { best_p = tmp_p; best_g = g; } } return best_g; } else { arma_debug_check(true, "gmm_diag::assign(): unsupported distance mode"); } return uword(0); } template template inline void gmm_diag::internal_vec_assign(urowvec& out, const T1& X, const gmm_dist_mode& dist_mode) const { arma_extra_debug_sigprint(); const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; arma_debug_check( (X.n_rows != N_dims), "gmm_diag::assign(): incompatible dimensions" ); const uword X_n_cols = (N_gaus > 0) ? X.n_cols : 0; out.set_size(1,X_n_cols); uword* out_mem = out.memptr(); if(dist_mode == eucl_dist) { for(uword i=0; i::inf; uword best_g = 0; for(uword g=0; g::eval(N_dims, X_colptr, means.colptr(g), X_colptr); if(tmp_dist <= best_dist) { best_dist = tmp_dist; best_g = g; } } out_mem[i] = best_g; } } else if(dist_mode == prob_dist) { const eT* log_hefts_mem = log_hefts.memptr(); for(uword i=0; i::inf; uword best_g = 0; for(uword g=0; g= best_p) { best_p = tmp_p; best_g = g; } } out_mem[i] = best_g; } } else { arma_debug_check(true, "gmm_diag::assign(): unsupported distance mode"); } } template inline void gmm_diag::internal_raw_hist(urowvec& hist, const Mat& X, const gmm_dist_mode& dist_mode) const { arma_extra_debug_sigprint(); const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; const uword X_n_cols = X.n_cols; hist.zeros(N_gaus); if(N_gaus == 0) { return; } uword* hist_mem = hist.memptr(); if(dist_mode == eucl_dist) { for(uword i=0; i::inf; uword best_g = 0; for(uword g=0; g < N_gaus; ++g) { const eT tmp_dist = distance::eval(N_dims, X_colptr, means.colptr(g), X_colptr); if(tmp_dist <= best_dist) { best_dist = tmp_dist; best_g = g; } } hist_mem[best_g]++; } } else if(dist_mode == prob_dist) { const eT* log_hefts_mem = log_hefts.memptr(); for(uword i=0; i::inf; uword best_g = 0; for(uword g=0; g < N_gaus; ++g) { const eT tmp_p = internal_scalar_log_p(X_colptr, g) + log_hefts_mem[g]; if(tmp_p >= best_p) { best_p = tmp_p; best_g = g; } } hist_mem[best_g]++; } } } template template inline void gmm_diag::generate_initial_means(const Mat& X, const gmm_seed_mode& seed_mode) { const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; if( (seed_mode == static_subset) || (seed_mode == random_subset) ) { uvec initial_indices; if(seed_mode == static_subset) { initial_indices = linspace(0, X.n_cols-1, N_gaus); } else if(seed_mode == random_subset) { initial_indices = uvec(sort_index(randu(X.n_cols))).rows(0,N_gaus-1); } // not using randi() here as on some primitive systems it produces vectors with non-unique values // initial_indices.print("initial_indices:"); access::rw(means) = X.cols(initial_indices); } else if( (seed_mode == static_spread) || (seed_mode == random_spread) ) { uword start_index = 0; if(seed_mode == static_spread) { start_index = X.n_cols / 2; } else if(seed_mode == random_spread) { start_index = as_scalar(randi(1, distr_param(0,X.n_cols-1))); } access::rw(means).col(0) = X.unsafe_col(start_index); const eT* mah_aux_mem = mah_aux.memptr(); running_stat rs; for(uword g=1; g < N_gaus; ++g) { eT max_dist = eT(0); uword best_i = uword(0); for(uword i=0; i < X.n_cols; ++i) { rs.reset(); const eT* X_colptr = X.colptr(i); bool ignore_i = false; // find the average distance between sample i and the means so far for(uword h = 0; h < g; ++h) { const eT dist = distance::eval(N_dims, X_colptr, means.colptr(h), mah_aux_mem); // ignore sample already selected as a mean if(dist == eT(0)) { ignore_i = true; break; } else { rs(dist); } } if( (rs.mean() >= max_dist) && (ignore_i == false)) { max_dist = eT(rs.mean()); best_i = i; } } // set the mean to the sample that is the furthest away from the means so far access::rw(means).col(g) = X.unsafe_col(best_i); } } // get_stream_err2() << "generate_initial_means():" << '\n'; // means.print(); } template template inline void gmm_diag::generate_initial_dcovs_and_hefts(const Mat& X, const eT var_floor) { const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; field< running_stat_vec< Col > > rs(N_gaus); const eT* mah_aux_mem = mah_aux.memptr(); for(uword i=0; i::inf; uword best_g = 0; for(uword g=0; g::eval(N_dims, X_colptr, means.colptr(g), mah_aux_mem); if(dist <= min_dist) { min_dist = dist; best_g = g; } } rs(best_g)(X.unsafe_col(i)); } for(uword g=0; g= eT(2) ) { access::rw(dcovs).col(g) = rs(g).var(1); } else { access::rw(dcovs).col(g).ones(); } access::rw(hefts)(g) = (std::max)( (rs(g).count() / eT(X.n_cols)), std::numeric_limits::min() ); } em_fix_params(var_floor); } //! multi-threaded implementation of k-means, inspired by MapReduce template template inline bool gmm_diag::km_iterate(const Mat& X, const uword max_iter, const bool verbose, const char* signature) { arma_extra_debug_sigprint(); if(verbose) { get_stream_err2().unsetf(ios::showbase); get_stream_err2().unsetf(ios::uppercase); get_stream_err2().unsetf(ios::showpos); get_stream_err2().unsetf(ios::scientific); get_stream_err2().setf(ios::right); get_stream_err2().setf(ios::fixed); } const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; Mat old_means = means; Mat new_means = means; running_mean_scalar rs_delta; field< running_mean_vec > running_means(N_gaus); const eT* mah_aux_mem = mah_aux.memptr(); #if defined(_OPENMP) const arma_omp_state save_omp_state; const umat boundaries = internal_gen_boundaries(X.n_cols); const uword n_threads = boundaries.n_cols; field< field< running_mean_vec > > t_running_means(n_threads); for(uword t=0; t < n_threads; ++t) { t_running_means[t].set_size(N_gaus); } Col tmp_mean(N_dims); if(verbose) { get_stream_err2() << signature << ": n_threads: " << n_threads << '\n'; } #endif for(uword iter=1; iter <= max_iter; ++iter) { #if defined(_OPENMP) { for(uword t=0; t < n_threads; ++t) { for(uword g=0; g < N_gaus; ++g) { t_running_means[t][g].reset(); } } // km_update_stats() is the "map" operation, which produces partial means #pragma omp parallel for for(uword t=0; t < n_threads; ++t) { field< running_mean_vec >& current_running_means = t_running_means[t]; km_update_stats(X, boundaries.at(0,t), boundaries.at(1,t), old_means, current_running_means); } // the "reduce" operation, which combines the partial means produced by the separate threads; // takes into account the counts for each mean for(uword g=0; g < N_gaus; ++g) { uword total_count = 0; for(uword t=0; t < n_threads; ++t) { total_count += t_running_means[t][g].count(); } tmp_mean.zeros(); bool dead = true; uword last_index = 0; if(total_count > 0) { for(uword t=0; t < n_threads; ++t) { const eT w = eT(t_running_means[t][g].count()) / eT(total_count); if(w > eT(0)) { tmp_mean += w * t_running_means[t][g].mean(); dead = false; last_index = t_running_means[t][g].last_index(); } } } running_means[g].reset(); if(dead == false) { running_means[g](tmp_mean, last_index); } } } #else { for(uword g=0; g < N_gaus; ++g) { running_means[g].reset(); } km_update_stats(X, 0, X.n_cols-1, old_means, running_means); } #endif uword n_dead_means = 0; for(uword g=0; g < N_gaus; ++g) { if(running_means[g].count() > 0) { new_means.col(g) = running_means[g].mean(); } else { n_dead_means++; } } // heuristics to resurrect dead means if(n_dead_means > 0) { if(verbose) { get_stream_err2() << signature << ": recovering from dead means\n"; } if(n_dead_means == 1) { uword dead_g = 0; uword populous_g = 0; uword populous_count = running_means(0).count(); for(uword g=1; g < N_gaus; ++g) { const uword count = running_means(g).count(); if(count == 0) { dead_g = g; } if(populous_count < count) { populous_count = count; populous_g = g; } } if( (populous_count <= 2) || (dead_g == populous_g) ) { return false; } new_means.col(dead_g) = X.unsafe_col( running_means(populous_g).last_index() ); } else { uword n_resurrected_means = 0; uword dead_g = 0; for(uword live_g = 0; live_g < N_gaus; ++live_g) { if(running_means(live_g).count() >= 2) { for(; dead_g < N_gaus; ++dead_g) { if(running_means(dead_g).count() == 0) { break; } } if(dead_g == N_gaus) { break; } new_means.col(dead_g) = X.unsafe_col( running_means(live_g).last_index() ); dead_g++; n_resurrected_means++; } } if(n_resurrected_means != n_dead_means) { if(verbose) { get_stream_err2() << signature << ": WARNING: did not resurrect all dead means\n"; } } } } rs_delta.reset(); for(uword g=0; g < N_gaus; ++g) { rs_delta( distance::eval(N_dims, old_means.colptr(g), new_means.colptr(g), mah_aux_mem) ); } if(verbose) { get_stream_err2() << signature << ": iteration: "; get_stream_err2().unsetf(ios::scientific); get_stream_err2().setf(ios::fixed); get_stream_err2().width(std::streamsize(4)); get_stream_err2() << iter; get_stream_err2() << " delta: "; get_stream_err2().unsetf(ios::fixed); //get_stream_err2().setf(ios::scientific); get_stream_err2() << rs_delta.mean() << '\n'; } arma::swap(old_means, new_means); if(rs_delta.mean() <= Datum::eps) { break; } } access::rw(means) = old_means; return true; } template template inline void gmm_diag::km_update_stats(const Mat& X, const uword start_index, const uword end_index, const Mat& old_means, field< running_mean_vec >& running_means) const { arma_extra_debug_sigprint(); // get_stream_err2() << "km_update_stats(): start_index: " << start_index << '\n'; // get_stream_err2() << "km_update_stats(): end_index: " << end_index << '\n'; const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; const eT* mah_aux_mem = mah_aux.memptr(); for(uword i=start_index; i <= end_index; ++i) { const eT* X_colptr = X.colptr(i); double best_dist = Datum::inf; uword best_g = 0; for(uword g=0; g < N_gaus; ++g) { const double dist = distance::eval(N_dims, X_colptr, old_means.colptr(g), mah_aux_mem); // get_stream_err2() << "g: " << g << " dist: " << dist << '\n'; // old_means.col(g).print("old_means.col(g):"); // vec tmp(old_means.colptr(g), old_means.n_rows); // tmp.print("tmp:"); if(dist <= best_dist) { best_dist = dist; best_g = g; } } // get_stream_err2() << "best_g: " << best_g << '\n'; running_means[best_g]( X.unsafe_col(i), i ); } } //! multi-threaded implementation of Expectation-Maximisation, inspired by MapReduce template inline bool gmm_diag::em_iterate(const Mat& X, const uword max_iter, const eT var_floor, const bool verbose) { arma_extra_debug_sigprint(); const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; if(verbose) { get_stream_err2().unsetf(ios::showbase); get_stream_err2().unsetf(ios::uppercase); get_stream_err2().unsetf(ios::showpos); get_stream_err2().unsetf(ios::scientific); get_stream_err2().setf(ios::right); get_stream_err2().setf(ios::fixed); } #if defined(_OPENMP) const arma_omp_state save_omp_state; #endif const umat boundaries = internal_gen_boundaries(X.n_cols); const uword n_threads = boundaries.n_cols; field< Mat > t_acc_means(n_threads); field< Mat > t_acc_dcovs(n_threads); field< Col > t_acc_norm_lhoods(n_threads); field< Col > t_gaus_log_lhoods(n_threads); Col t_progress_log_lhood(n_threads); for(uword t=0; t::inf; for(uword iter=1; iter <= max_iter; ++iter) { init_constants(); em_update_params(X, boundaries, t_acc_means, t_acc_dcovs, t_acc_norm_lhoods, t_gaus_log_lhoods, t_progress_log_lhood); em_fix_params(var_floor); const eT new_avg_log_p = mean(t_progress_log_lhood); if(verbose) { get_stream_err2() << "gmm_diag::learn(): EM: iteration: "; get_stream_err2().unsetf(ios::scientific); get_stream_err2().setf(ios::fixed); get_stream_err2().width(std::streamsize(4)); get_stream_err2() << iter; get_stream_err2() << " avg_log_p: "; get_stream_err2().unsetf(ios::fixed); //get_stream_err2().setf(ios::scientific); get_stream_err2() << new_avg_log_p << '\n'; } if(is_finite(new_avg_log_p) == false) { return false; } if(std::abs(old_avg_log_p - new_avg_log_p) <= Datum::eps) { break; } old_avg_log_p = new_avg_log_p; } if(any(vectorise(dcovs) <= eT(0))) { return false; } if(means.is_finite() == false ) { return false; } if(dcovs.is_finite() == false ) { return false; } if(hefts.is_finite() == false ) { return false; } return true; } template inline void gmm_diag::em_update_params ( const Mat& X, const umat& boundaries, field< Mat >& t_acc_means, field< Mat >& t_acc_dcovs, field< Col >& t_acc_norm_lhoods, field< Col >& t_gaus_log_lhoods, Col& t_progress_log_lhood ) { arma_extra_debug_sigprint(); const uword n_threads = boundaries.n_cols; // em_generate_acc() is the "map" operation, which produces partial accumulators for means, diagonal covariances and hefts #if defined(_OPENMP) { #pragma omp parallel for for(uword t=0; t& acc_means = t_acc_means[t]; Mat& acc_dcovs = t_acc_dcovs[t]; Col& acc_norm_lhoods = t_acc_norm_lhoods[t]; Col& gaus_log_lhoods = t_gaus_log_lhoods[t]; eT& progress_log_lhood = t_progress_log_lhood[t]; em_generate_acc(X, boundaries.at(0,t), boundaries.at(1,t), acc_means, acc_dcovs, acc_norm_lhoods, gaus_log_lhoods, progress_log_lhood); } } #else { em_generate_acc(X, boundaries.at(0,0), boundaries.at(1,0), t_acc_means[0], t_acc_dcovs[0], t_acc_norm_lhoods[0], t_gaus_log_lhoods[0], t_progress_log_lhood[0]); } #endif const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; Mat& final_acc_means = t_acc_means[0]; Mat& final_acc_dcovs = t_acc_dcovs[0]; Col& final_acc_norm_lhoods = t_acc_norm_lhoods[0]; // the "reduce" operation, which combines the partial accumulators produced by the separate threads for(uword t=1; t::min() ); hefts_mem[g] = acc_norm_lhood / eT(X.n_cols); for(uword d=0; d < N_dims; ++d) { const eT tmp = acc_mean_mem[d] / acc_norm_lhood; mean_mem[d] = tmp; dcov_mem[d] = acc_dcov_mem[d] / acc_norm_lhood - tmp*tmp; } } } template inline void gmm_diag::em_generate_acc ( const Mat& X, const uword start_index, const uword end_index, Mat& acc_means, Mat& acc_dcovs, Col& acc_norm_lhoods, Col& gaus_log_lhoods, eT& progress_log_lhood ) const { arma_extra_debug_sigprint(); progress_log_lhood = eT(0); acc_means.zeros(); acc_dcovs.zeros(); acc_norm_lhoods.zeros(); gaus_log_lhoods.zeros(); const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; const eT* log_hefts_mem = log_hefts.memptr(); eT* gaus_log_lhoods_mem = gaus_log_lhoods.memptr(); for(uword i=start_index; i <= end_index; i++) { const eT* x = X.colptr(i); for(uword g=0; g < N_gaus; ++g) { gaus_log_lhoods_mem[g] = internal_scalar_log_p(x, g) + log_hefts_mem[g]; } eT log_lhood_sum = gaus_log_lhoods_mem[0]; for(uword g=1; g < N_gaus; ++g) { log_lhood_sum = log_add_exp(log_lhood_sum, gaus_log_lhoods_mem[g]); } progress_log_lhood += log_lhood_sum; for(uword g=0; g < N_gaus; ++g) { const eT norm_lhood = std::exp(gaus_log_lhoods_mem[g] - log_lhood_sum); acc_norm_lhoods[g] += norm_lhood; eT* acc_mean_mem = acc_means.colptr(g); eT* acc_dcov_mem = acc_dcovs.colptr(g); for(uword d=0; d < N_dims; ++d) { const eT x_d = x[d]; const eT y_d = x_d * norm_lhood; acc_mean_mem[d] += y_d; acc_dcov_mem[d] += y_d * x_d; // equivalent to x_d * x_d * norm_lhood } } } progress_log_lhood /= eT((end_index - start_index) + 1); } template inline void gmm_diag::em_fix_params(const eT var_floor) { arma_extra_debug_sigprint(); const uword N_dims = means.n_rows; const uword N_gaus = means.n_cols; for(uword g=0; g < N_gaus; ++g) { eT* dcov_mem = access::rw(dcovs).colptr(g); for(uword d=0; d < N_dims; ++d) { if(dcov_mem[d] < var_floor) { dcov_mem[d] = var_floor; } } } const eT heft_sum = accu(hefts); if(heft_sum != eT(1)) { access::rw(hefts) / heft_sum; } } } //! @} armadillo-6.500.5/include/armadillo_bits/fn_cor.hpp0000666000000000000000000000222312620272703020724 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup fn_cor //! @{ template inline const Op cor(const Base& X, const uword norm_type = 0) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "cor(): parameter 'norm_type' must be 0 or 1" ); return Op(X.get_ref(), norm_type, 0); } template inline const Glue cor(const Base& A, const Base& B, const uword norm_type = 0) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "cor(): parameter 'norm_type' must be 0 or 1" ); return Glue(A.get_ref(), B.get_ref(), norm_type); } //! @} armadillo-6.500.5/include/armadillo_bits/mtOp_bones.hpp0000666000000000000000000000604212620272703021566 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup mtOp //! @{ struct mtOp_dual_aux_indicator {}; template class mtOp : public Base > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef typename T1::elem_type in_eT; static const bool is_row = \ ( // operations which result in a row vector if the input is a row vector T1::is_row && ( is_op_mixed_elem::value || is_same_type::value || is_same_type::value || is_same_type::value || is_same_type::value || is_same_type::value ) ); static const bool is_col = \ ( // operations which always result in a column vector (is_same_type::value) || (is_same_type::value) || (is_same_type::value) || (is_same_type::value) || (is_same_type::value) ) || ( // operations which result in a column vector if the input is a column vector T1::is_col && ( is_op_mixed_elem::value || is_same_type::value || is_same_type::value || is_same_type::value || is_same_type::value || is_same_type::value ) ); inline explicit mtOp(const T1& in_m); inline mtOp(const T1& in_m, const in_eT in_aux); inline mtOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline mtOp(const T1& in_m, const in_eT in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b); inline mtOp(const char junk, const T1& in_m, const out_eT in_aux); inline mtOp(const mtOp_dual_aux_indicator&, const T1& in_m, const in_eT in_aux_a, const out_eT in_aux_b); inline ~mtOp(); arma_aligned const T1& m; //!< storage of reference to the operand (eg. a matrix) arma_aligned in_eT aux; //!< storage of auxiliary data, using the element type as used by T1 arma_aligned out_eT aux_out_eT; //!< storage of auxiliary data, using the element type as specified by the out_eT template parameter arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format }; //! @} armadillo-6.500.5/include/armadillo_bits/Op_bones.hpp0000666000000000000000000001025412620272703021225 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Op //! @{ //! Class for storing data required for delayed unary operations, //! such as the operand (e.g. the matrix to which the operation is to be applied) and the unary operator (e.g. inverse). //! The operand is stored as a reference (which can be optimised away), //! while the operator is "stored" through the template definition (op_type). //! The operands can be 'Mat', 'Row', 'Col', 'Op', and 'Glue'. //! Note that as 'Glue' can be one of the operands, more than one matrix can be stored. //! //! For example, we could have: //! Op< Glue< Mat, Mat, glue_times >, op_htrans > template class Op : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline explicit Op(const T1& in_m); inline Op(const T1& in_m, const elem_type in_aux); inline Op(const T1& in_m, const elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b); inline Op(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline Op(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c, const char junk); inline ~Op(); arma_aligned const T1& m; //!< storage of reference to the operand (eg. a matrix) arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_c; //!< storage of auxiliary data, uword format static const bool is_row = \ ( // operations which result in a row vector if the input is a row vector T1::is_row && ( is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes ) ) || ( // operations which result in a row vector if the input is a column vector T1::is_col && ( is_same_type::yes || is_same_type::yes || is_same_type::yes ) ) ; static const bool is_col = \ ( // operations which always result in a column vector is_same_type::yes || is_same_type::yes || is_same_type::yes ) || ( // operations which result in a column vector if the input is a column vector T1::is_col && ( is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes || is_same_type::yes ) ) || ( // operations which result in a column vector if the input is a row vector T1::is_row && ( is_same_type::yes || is_same_type::yes || is_same_type::yes ) ) ; }; //! @} armadillo-6.500.5/include/armadillo_bits/running_stat_bones.hpp0000666000000000000000000000507712620272703023371 0ustar rootroot// Copyright (C) 2009-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup running_stat //! @{ template class arma_counter { public: inline ~arma_counter(); inline arma_counter(); inline const arma_counter& operator++(); inline void operator++(int); inline void reset(); inline eT value() const; inline eT value_plus_1() const; inline eT value_minus_1() const; private: arma_aligned eT d_count; arma_aligned uword i_count; }; //! Class for keeping statistics of a continuously sampled process / signal. //! Useful if the storage of individual samples is not necessary or desired. //! Also useful if the number of samples is not known beforehand or exceeds //! available memory. template class running_stat { public: typedef typename get_pod_type::result T; inline ~running_stat(); inline running_stat(); inline void operator() (const T sample); inline void operator() (const std::complex& sample); inline void reset(); inline eT mean() const; inline T var (const uword norm_type = 0) const; inline T stddev(const uword norm_type = 0) const; inline eT min() const; inline eT max() const; inline T count() const; // // private: arma_aligned arma_counter counter; arma_aligned eT r_mean; arma_aligned T r_var; arma_aligned eT min_val; arma_aligned eT max_val; arma_aligned T min_val_norm; arma_aligned T max_val_norm; friend class running_stat_aux; }; class running_stat_aux { public: template inline static void update_stats(running_stat& x, const eT sample, const typename arma_not_cx::result* junk = 0); template inline static void update_stats(running_stat& x, const std::complex& sample, const typename arma_not_cx::result* junk = 0); template inline static void update_stats(running_stat& x, const typename eT::value_type sample, const typename arma_cx_only::result* junk = 0); template inline static void update_stats(running_stat& x, const eT& sample, const typename arma_cx_only::result* junk = 0); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_nonzeros.hpp0000666000000000000000000000157412620272703022026 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_nonzeros //! @{ template inline const Op nonzeros(const Base& X) { arma_extra_debug_sigprint(); return Op(X.get_ref()); } template inline Col nonzeros(const SpBase& X) { arma_extra_debug_sigprint(); Col out; op_nonzeros::apply_noalias(out, X.get_ref()); return out; } //! @} armadillo-6.500.5/include/armadillo_bits/op_flip_meat.hpp0000666000000000000000000000441312620272703022117 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_flip //! @{ template inline void op_flipud::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat& X = tmp.M; const uword X_n_rows = T1::is_row ? uword(1) : X.n_rows; const uword X_n_cols = T1::is_col ? uword(1) : X.n_cols; if(&out != &X) { out.copy_size(X); for(uword col=0; col inline void op_fliplr::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat& X = tmp.M; const uword X_n_cols = X.n_cols; if(&out != &X) { out.copy_size(X); if(T1::is_row || X.is_rowvec()) { for(uword i=0; i inline subview_field::~subview_field() { arma_extra_debug_sigprint(); } template arma_inline subview_field::subview_field ( const field& in_f, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols ) : f(in_f) , aux_row1(in_row1) , aux_col1(in_col1) , aux_slice1(0) , n_rows(in_n_rows) , n_cols(in_n_cols) , n_slices(1) , n_elem(in_n_rows*in_n_cols) { arma_extra_debug_sigprint(); } template arma_inline subview_field::subview_field ( const field& in_f, const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices ) : f(in_f) , aux_row1(in_row1) , aux_col1(in_col1) , aux_slice1(in_slice1) , n_rows(in_n_rows) , n_cols(in_n_cols) , n_slices(in_n_slices) , n_elem(in_n_rows*in_n_cols*in_n_slices) { arma_extra_debug_sigprint(); } template inline void subview_field::operator= (const field& x) { arma_extra_debug_sigprint(); subview_field& t = *this; arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols) || (t.n_slices != x.n_slices), "incompatible field dimensions"); if(t.n_slices == 1) { for(uword col=0; col < t.n_cols; ++col) for(uword row=0; row < t.n_rows; ++row) { t.at(row,col) = x.at(row,col); } } else { for(uword slice=0; slice < t.n_slices; ++slice) for(uword col=0; col < t.n_cols; ++col ) for(uword row=0; row < t.n_rows; ++row ) { t.at(row,col,slice) = x.at(row,col,slice); } } } //! x.subfield(...) = y.subfield(...) template inline void subview_field::operator= (const subview_field& x) { arma_extra_debug_sigprint(); if(check_overlap(x)) { const field tmp(x); (*this).operator=(tmp); return; } subview_field& t = *this; arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols) || (t.n_slices != x.n_slices), "incompatible field dimensions"); if(t.n_slices == 1) { for(uword col=0; col < t.n_cols; ++col) for(uword row=0; row < t.n_rows; ++row) { t.at(row,col) = x.at(row,col); } } else { for(uword slice=0; slice < t.n_slices; ++slice) for(uword col=0; col < t.n_cols; ++col ) for(uword row=0; row < t.n_rows; ++row ) { t.at(row,col,slice) = x.at(row,col,slice); } } } template arma_inline oT& subview_field::operator[](const uword i) { uword index; if(n_slices == 1) { const uword in_col = i / n_rows; const uword in_row = i % n_rows; index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; } else { const uword n_elem_slice = n_rows*n_cols; const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; index = (in_slice + aux_slice1)*(f.n_rows*f.n_cols) + (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; } return *((const_cast< field& >(f)).mem[index]); } template arma_inline const oT& subview_field::operator[](const uword i) const { uword index; if(n_slices == 1) { const uword in_col = i / n_rows; const uword in_row = i % n_rows; index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; } else { const uword n_elem_slice = n_rows*n_cols; const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; index = (in_slice + aux_slice1)*(f.n_rows*f.n_cols) + (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; } return *(f.mem[index]); } template arma_inline oT& subview_field::operator()(const uword i) { arma_debug_check( (i >= n_elem), "subview_field::operator(): index out of bounds"); return operator[](i); } template arma_inline const oT& subview_field::operator()(const uword i) const { arma_debug_check( (i >= n_elem), "subview_field::operator(): index out of bounds"); return operator[](i); } template arma_inline oT& subview_field::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview_field::operator(): index out of bounds"); const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *((const_cast< field& >(f)).mem[index]); } template arma_inline const oT& subview_field::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview_field::operator(): index out of bounds"); const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *(f.mem[index]); } template arma_inline oT& subview_field::operator()(const uword in_row, const uword in_col, const uword in_slice) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices)), "subview_field::operator(): index out of bounds"); const uword index = (in_slice + aux_slice1)*(f.n_rows*f.n_cols) + (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *((const_cast< field& >(f)).mem[index]); } template arma_inline const oT& subview_field::operator()(const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices)), "subview_field::operator(): index out of bounds"); const uword index = (in_slice + aux_slice1)*(f.n_rows*f.n_cols) + (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *(f.mem[index]); } template arma_inline oT& subview_field::at(const uword in_row, const uword in_col) { const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *((const_cast< field& >(f)).mem[index]); } template arma_inline const oT& subview_field::at(const uword in_row, const uword in_col) const { const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *(f.mem[index]); } template arma_inline oT& subview_field::at(const uword in_row, const uword in_col, const uword in_slice) { const uword index = (in_slice + aux_slice1)*(f.n_rows*f.n_cols) + (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *((const_cast< field& >(f)).mem[index]); } template arma_inline const oT& subview_field::at(const uword in_row, const uword in_col, const uword in_slice) const { const uword index = (in_slice + aux_slice1)*(f.n_rows*f.n_cols) + (in_col + aux_col1)*f.n_rows + aux_row1 + in_row; return *(f.mem[index]); } template inline bool subview_field::check_overlap(const subview_field& x) const { const subview_field& t = *this; if(&t.f != &x.f) { return false; } else { if( (t.n_elem == 0) || (x.n_elem == 0) ) { return false; } else { const uword t_row_start = t.aux_row1; const uword t_row_end_p1 = t_row_start + t.n_rows; const uword t_col_start = t.aux_col1; const uword t_col_end_p1 = t_col_start + t.n_cols; const uword t_slice_start = t.aux_slice1; const uword t_slice_end_p1 = t_slice_start + t.n_slices; const uword x_row_start = x.aux_row1; const uword x_row_end_p1 = x_row_start + x.n_rows; const uword x_col_start = x.aux_col1; const uword x_col_end_p1 = x_col_start + x.n_cols; const uword x_slice_start = x.aux_slice1; const uword x_slice_end_p1 = x_slice_start + x.n_slices; const bool outside_rows = ( (x_row_start >= t_row_end_p1 ) || (t_row_start >= x_row_end_p1 ) ); const bool outside_cols = ( (x_col_start >= t_col_end_p1 ) || (t_col_start >= x_col_end_p1 ) ); const bool outside_slices = ( (x_slice_start >= t_slice_end_p1) || (t_slice_start >= x_slice_end_p1) ); return ( (outside_rows == false) && (outside_cols == false) && (outside_slices == false) ); } } } template inline void subview_field::print(const std::string extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this); } template inline void subview_field::print(std::ostream& user_stream, const std::string extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this); } template template inline void subview_field::for_each(functor F) { arma_extra_debug_sigprint(); subview_field& t = *this; if(t.n_slices == 1) { for(uword col=0; col < t.n_cols; ++col) for(uword row=0; row < t.n_rows; ++row) { F( t.at(row,col) ); } } else { for(uword slice=0; slice < t.n_slices; ++slice) for(uword col=0; col < t.n_cols; ++col ) for(uword row=0; row < t.n_rows; ++row ) { F( t.at(row,col,slice) ); } } } template template inline void subview_field::for_each(functor F) const { arma_extra_debug_sigprint(); const subview_field& t = *this; if(t.n_slices == 1) { for(uword col=0; col < t.n_cols; ++col) for(uword row=0; row < t.n_rows; ++row) { F( t.at(row,col) ); } } else { for(uword slice=0; slice < t.n_slices; ++slice) for(uword col=0; col < t.n_cols; ++col ) for(uword row=0; row < t.n_rows; ++row ) { F( t.at(row,col,slice) ); } } } template inline void subview_field::fill(const oT& x) { arma_extra_debug_sigprint(); subview_field& t = *this; if(t.n_slices == 1) { for(uword col=0; col < t.n_cols; ++col) for(uword row=0; row < t.n_rows; ++row) { t.at(row,col) = x; } } else { for(uword slice=0; slice < t.n_slices; ++slice) for(uword col=0; col < t.n_cols; ++col ) for(uword row=0; row < t.n_rows; ++row ) { t.at(row,col,slice) = x; } } } //! X = Y.subfield(...) template inline void subview_field::extract(field& actual_out, const subview_field& in) { arma_extra_debug_sigprint(); // const bool alias = (&actual_out == &in.f); field* tmp = (alias) ? new field : 0; field& out = (alias) ? (*tmp) : actual_out; // const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; const uword n_slices = in.n_slices; out.set_size(n_rows, n_cols, n_slices); arma_extra_debug_print(arma_str::format("out.n_rows = %d out.n_cols = %d out.n_slices = %d in.m.n_rows = %d in.m.n_cols = %d in.m.n_slices = %d") % out.n_rows % out.n_cols % out.n_slices % in.f.n_rows % in.f.n_cols % in.f.n_slices); if(n_slices == 1) { for(uword col = 0; col < n_cols; ++col) for(uword row = 0; row < n_rows; ++row) { out.at(row,col) = in.at(row,col); } } else { for(uword slice = 0; slice < n_slices; ++slice) for(uword col = 0; col < n_cols; ++col ) for(uword row = 0; row < n_rows; ++row ) { out.at(row,col,slice) = in.at(row,col,slice); } } if(alias) { actual_out = out; delete tmp; } } //! @} armadillo-6.500.5/include/armadillo_bits/fn_strans.hpp0000666000000000000000000000355112620272703021460 0ustar rootroot// Copyright (C) 2011-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_strans //! @{ template arma_inline const Op strans ( const T1& X, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename arma_cx_only::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X); } // NOTE: for non-complex objects, deliberately returning op_htrans instead of op_strans, // NOTE: due to currently more optimisations available when using op_htrans, especially by glue_times template arma_inline const Op strans ( const T1& X, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename arma_not_cx::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X); } //! two consecutive transpose operations cancel each other template arma_inline const T1& strans(const Op& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("strans(): removing op_strans"); return X.m; } // // handling of sparse matrices template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result strans(const T1& x) { arma_extra_debug_sigprint(); return SpOp(x); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_symmat.hpp0000666000000000000000000000326112620272703021456 0ustar rootroot// Copyright (C) 2011-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_symmat //! @{ template arma_inline typename enable_if2< is_cx::no, const Op >::result symmatu(const Base& X, const bool do_conj = false) { arma_extra_debug_sigprint(); arma_ignore(do_conj); return Op(X.get_ref(), 0, 0); } template arma_inline typename enable_if2< is_cx::no, const Op >::result symmatl(const Base& X, const bool do_conj = false) { arma_extra_debug_sigprint(); arma_ignore(do_conj); return Op(X.get_ref(), 1, 0); } template arma_inline typename enable_if2< is_cx::yes, const Op >::result symmatu(const Base& X, const bool do_conj = true) { arma_extra_debug_sigprint(); return Op(X.get_ref(), 0, (do_conj ? 1 : 0)); } template arma_inline typename enable_if2< is_cx::yes, const Op >::result symmatl(const Base& X, const bool do_conj = true) { arma_extra_debug_sigprint(); return Op(X.get_ref(), 1, (do_conj ? 1 : 0)); } //! @} armadillo-6.500.5/include/armadillo_bits/sp_auxlib_meat.hpp0000666000000000000000000010753212627476623022501 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup sp_auxlib //! @{ inline sp_auxlib::form_type sp_auxlib::interpret_form_str(const char* form_str) { arma_extra_debug_sigprint(); // the order of the 3 if statements below is important if( form_str == NULL ) { return form_none; } if( form_str[0] == char(0) ) { return form_none; } if( form_str[1] == char(0) ) { return form_none; } const char c1 = form_str[0]; const char c2 = form_str[1]; if(c1 == 'l') { if(c2 == 'm') { return form_lm; } if(c2 == 'r') { return form_lr; } if(c2 == 'i') { return form_li; } if(c2 == 'a') { return form_la; } } else if(c1 == 's') { if(c2 == 'm') { return form_sm; } if(c2 == 'r') { return form_sr; } if(c2 == 'i') { return form_si; } if(c2 == 'a') { return form_sa; } } return form_none; } //! immediate eigendecomposition of symmetric real sparse object template inline bool sp_auxlib::eigs_sym(Col& eigval, Mat& eigvec, const SpBase& X, const uword n_eigvals, const char* form_str, const eT default_tol) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_ARPACK) { const form_type form_val = sp_auxlib::interpret_form_str(form_str); arma_debug_check( (form_val != form_lm) && (form_val != form_sm) && (form_val != form_la) && (form_val != form_sa), "eigs_sym(): unknown form specified" ); char which_sm[3] = "SM"; char which_lm[3] = "LM"; char which_sa[3] = "SA"; char which_la[3] = "LA"; char* which; switch (form_val) { case form_sm: which = which_sm; break; case form_lm: which = which_lm; break; case form_sa: which = which_sa; break; case form_la: which = which_la; break; default: which = which_lm; break; } // Make a sparse proxy object. SpProxy p(X.get_ref()); // Make sure it's square. arma_debug_check( (p.get_n_rows() != p.get_n_cols()), "eigs_sym(): given matrix must be square sized" ); // Make sure we aren't asking for every eigenvalue. // The _saupd() functions allow asking for one more eigenvalue than the _naupd() functions. arma_debug_check( (n_eigvals >= p.get_n_rows()), "eigs_sym(): n_eigvals must be less than the number of rows in the matrix" ); // If the matrix is empty, the case is trivial. if(p.get_n_cols() == 0) // We already know n_cols == n_rows. { eigval.reset(); eigvec.reset(); return true; } // Set up variables that get used for neupd(). blas_int n, ncv, ldv, lworkl, info; eT tol = default_tol; podarray resid, v, workd, workl; podarray iparam, ipntr; podarray rwork; // Not used in this case. run_aupd(n_eigvals, which, p, true /* sym, not gen */, n, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); if(info != 0) { return false; } // The process has converged, and now we need to recover the actual eigenvectors using seupd() blas_int rvec = 1; // .TRUE blas_int nev = n_eigvals; char howmny = 'A'; char bmat = 'I'; // We are considering the standard eigenvalue problem. podarray select(ncv); // Logical array of dimension NCV. blas_int ldz = n; // seupd() will output directly into the eigval and eigvec objects. eigval.set_size(n_eigvals); eigvec.set_size(n, n_eigvals); arpack::seupd(&rvec, &howmny, select.memptr(), eigval.memptr(), eigvec.memptr(), &ldz, (eT*) NULL, &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, &info); // Check for errors. if(info != 0) { arma_debug_warn("eigs_sym(): ARPACK error ", info, " in seupd()"); return false; } return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_ignore(n_eigvals); arma_ignore(form_str); arma_ignore(default_tol); arma_stop("eigs_sym(): use of ARPACK must be enabled"); return false; } #endif } //! immediate eigendecomposition of non-symmetric real sparse object template inline bool sp_auxlib::eigs_gen(Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase& X, const uword n_eigvals, const char* form_str, const T default_tol) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_ARPACK) { const form_type form_val = sp_auxlib::interpret_form_str(form_str); arma_debug_check( (form_val == form_none), "eigs_gen(): unknown form specified" ); char which_lm[3] = "LM"; char which_sm[3] = "SM"; char which_lr[3] = "LR"; char which_sr[3] = "SR"; char which_li[3] = "LI"; char which_si[3] = "SI"; char* which; switch(form_val) { case form_lm: which = which_lm; break; case form_sm: which = which_sm; break; case form_lr: which = which_lr; break; case form_sr: which = which_sr; break; case form_li: which = which_li; break; case form_si: which = which_si; break; default: which = which_lm; } // Make a sparse proxy object. SpProxy p(X.get_ref()); // Make sure it's square. arma_debug_check( (p.get_n_rows() != p.get_n_cols()), "eigs_gen(): given matrix must be square sized" ); // Make sure we aren't asking for every eigenvalue. arma_debug_check( (n_eigvals + 1 >= p.get_n_rows()), "eigs_gen(): n_eigvals + 1 must be less than the number of rows in the matrix" ); // If the matrix is empty, the case is trivial. if(p.get_n_cols() == 0) // We already know n_cols == n_rows. { eigval.reset(); eigvec.reset(); return true; } // Set up variables that get used for neupd(). blas_int n, ncv, ldv, lworkl, info; T tol = default_tol; podarray resid, v, workd, workl; podarray iparam, ipntr; podarray rwork; // Not used in the real case. run_aupd(n_eigvals, which, p, false /* gen, not sym */, n, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); if(info != 0) { return false; } // The process has converged, and now we need to recover the actual eigenvectors using neupd(). blas_int rvec = 1; // .TRUE blas_int nev = n_eigvals; char howmny = 'A'; char bmat = 'I'; // We are considering the standard eigenvalue problem. podarray select(ncv); // Logical array of dimension NCV. podarray dr(nev + 1); // Real array of dimension NEV + 1. podarray di(nev + 1); // Real array of dimension NEV + 1. podarray z(n * (nev + 1)); // Real N by NEV array if HOWMNY = 'A'. blas_int ldz = n; podarray workev(3 * ncv); arpack::neupd(&rvec, &howmny, select.memptr(), dr.memptr(), di.memptr(), z.memptr(), &ldz, (T*) NULL, (T*) NULL, workev.memptr(), &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, rwork.memptr(), &info); // Check for errors. if(info != 0) { arma_debug_warn("eigs_gen(): ARPACK error ", info, " in neupd()"); return false; } // Put it into the outputs. eigval.set_size(n_eigvals); eigvec.set_size(n, n_eigvals); for (uword i = 0; i < n_eigvals; ++i) { eigval[i] = std::complex(dr[i], di[i]); } // Now recover the eigenvectors. for (uword i = 0; i < n_eigvals; ++i) { // ARPACK ?neupd lays things out kinda odd in memory; // so does LAPACK ?geev -- see auxlib::eig_gen() if((i < n_eigvals - 1) && (eigval[i] == std::conj(eigval[i + 1]))) { for (uword j = 0; j < uword(n); ++j) { eigvec.at(j, i) = std::complex(z[n * i + j], z[n * (i + 1) + j]); eigvec.at(j, i + 1) = std::complex(z[n * i + j], -z[n * (i + 1) + j]); } ++i; // Skip the next one. } else if((i == n_eigvals - 1) && (std::complex(eigval[i]).imag() != 0.0)) { // We don't have the matched conjugate eigenvalue. for (uword j = 0; j < uword(n); ++j) { eigvec.at(j, i) = std::complex(z[n * i + j], z[n * (i + 1) + j]); } } else { // The eigenvector is entirely real. for (uword j = 0; j < uword(n); ++j) { eigvec.at(j, i) = std::complex(z[n * i + j], T(0)); } } } return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_ignore(n_eigvals); arma_ignore(form_str); arma_ignore(default_tol); arma_stop("eigs_gen(): use of ARPACK must be enabled"); return false; } #endif } //! immediate eigendecomposition of non-symmetric complex sparse object template inline bool sp_auxlib::eigs_gen(Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase< std::complex, T1>& X, const uword n_eigvals, const char* form_str, const T default_tol) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_ARPACK) { const form_type form_val = sp_auxlib::interpret_form_str(form_str); arma_debug_check( (form_val == form_none), "eigs_gen(): unknown form specified" ); char which_lm[3] = "LM"; char which_sm[3] = "SM"; char which_lr[3] = "LR"; char which_sr[3] = "SR"; char which_li[3] = "LI"; char which_si[3] = "SI"; char* which; switch(form_val) { case form_lm: which = which_lm; break; case form_sm: which = which_sm; break; case form_lr: which = which_lr; break; case form_sr: which = which_sr; break; case form_li: which = which_li; break; case form_si: which = which_si; break; default: which = which_lm; } // Make a sparse proxy object. SpProxy p(X.get_ref()); // Make sure it's square. arma_debug_check( (p.get_n_rows() != p.get_n_cols()), "eigs_gen(): given matrix must be square sized" ); // Make sure we aren't asking for every eigenvalue. arma_debug_check( (n_eigvals + 1 >= p.get_n_rows()), "eigs_gen(): n_eigvals + 1 must be less than the number of rows in the matrix" ); // If the matrix is empty, the case is trivial. if(p.get_n_cols() == 0) // We already know n_cols == n_rows. { eigval.reset(); eigvec.reset(); return true; } // Set up variables that get used for neupd(). blas_int n, ncv, ldv, lworkl, info; T tol = default_tol; podarray< std::complex > resid, v, workd, workl; podarray iparam, ipntr; podarray rwork; run_aupd(n_eigvals, which, p, false /* gen, not sym */, n, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, rwork, info); if(info != 0) { return false; } // The process has converged, and now we need to recover the actual eigenvectors using neupd(). blas_int rvec = 1; // .TRUE blas_int nev = n_eigvals; char howmny = 'A'; char bmat = 'I'; // We are considering the standard eigenvalue problem. podarray select(ncv); // Logical array of dimension NCV. podarray > d(nev + 1); // Real array of dimension NEV + 1. podarray > z(n * nev); // Real N by NEV array if HOWMNY = 'A'. blas_int ldz = n; podarray > workev(2 * ncv); // Prepare the outputs; neupd() will write directly to them. eigval.set_size(n_eigvals); eigvec.set_size(n, n_eigvals); std::complex sigma; arpack::neupd(&rvec, &howmny, select.memptr(), eigval.memptr(), (std::complex*) NULL, eigvec.memptr(), &ldz, (std::complex*) &sigma, (std::complex*) NULL, workev.memptr(), &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, rwork.memptr(), &info); // Check for errors. if(info != 0) { arma_debug_warn("eigs_gen(): ARPACK error ", info, " in neupd()"); return false; } return (info == 0); } #else { arma_ignore(eigval); arma_ignore(eigvec); arma_ignore(X); arma_ignore(n_eigvals); arma_ignore(form_str); arma_ignore(default_tol); arma_stop("eigs_gen(): use of ARPACK must be enabled"); return false; } #endif } template inline bool sp_auxlib::spsolve_simple(Mat& X, const SpBase& A_expr, const Base& B_expr, const superlu_opts& user_opts) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_SUPERLU) { typedef typename T1::elem_type eT; superlu::superlu_options_t options; sp_auxlib::set_superlu_opts(options, user_opts); const unwrap_spmat tmp1(A_expr.get_ref()); const SpMat& A = tmp1.M; X = B_expr.get_ref(); // superlu::gssv() uses X as input (the B matrix) and as output (the solution) if(A.n_rows > A.n_cols) { arma_stop("spsolve(): solving over-determined systems currently not supported"); X.reset(); return false; } else if(A.n_rows < A.n_cols) { arma_stop("spsolve(): solving under-determined systems currently not supported"); X.reset(); return false; } arma_debug_check( (A.n_rows != X.n_rows), "spsolve(): number of rows in the given objects must be the same" ); if(A.is_empty() || X.is_empty()) { X.zeros(A.n_cols, X.n_cols); return true; } if(arma_config::debug) { bool overflow; overflow = (A.n_nonzero > INT_MAX); overflow = (A.n_rows > INT_MAX) || overflow; overflow = (A.n_cols > INT_MAX) || overflow; overflow = (X.n_rows > INT_MAX) || overflow; overflow = (X.n_cols > INT_MAX) || overflow; if(overflow) { arma_bad("spsolve(): integer overflow: matrix dimensions are too large for integer type used by SuperLU"); } } superlu::SuperMatrix x; arrayops::inplace_set(reinterpret_cast(&x), char(0), sizeof(superlu::SuperMatrix)); superlu::SuperMatrix a; arrayops::inplace_set(reinterpret_cast(&a), char(0), sizeof(superlu::SuperMatrix)); const bool status_x = wrap_to_supermatrix(x, X); const bool status_a = copy_to_supermatrix(a, A); if( (status_x == false) || (status_a == false) ) { destroy_supermatrix(a); destroy_supermatrix(x); X.reset(); return false; } superlu::SuperMatrix l; arrayops::inplace_set(reinterpret_cast(&l), char(0), sizeof(superlu::SuperMatrix)); superlu::SuperMatrix u; arrayops::inplace_set(reinterpret_cast(&u), char(0), sizeof(superlu::SuperMatrix)); // paranoia: use SuperLU's memory allocation, in case it reallocs int* perm_c = (int*) superlu::malloc( (A.n_cols+1) * sizeof(int)); // extra paranoia: increase array length by 1 int* perm_r = (int*) superlu::malloc( (A.n_rows+1) * sizeof(int)); arma_check_bad_alloc( (perm_c == 0), "spsolve(): out of memory" ); arma_check_bad_alloc( (perm_r == 0), "spsolve(): out of memory" ); arrayops::inplace_set(perm_c, 0, A.n_cols+1); arrayops::inplace_set(perm_r, 0, A.n_rows+1); superlu::SuperLUStat_t stat; superlu::init_stat(&stat); int info = 0; // Return code. superlu::gssv(&options, &a, perm_c, perm_r, &l, &u, &x, &stat, &info); // Process the return code. if( (info > 0) && (info <= int(A.n_cols)) ) { // std::stringstream tmp; // tmp << "spsolve(): could not solve system; LU factorisation completed, but detected zero in U(" << (info-1) << ',' << (info-1) << ')'; // arma_debug_warn(tmp.str()); } else if(info > int(A.n_cols)) { arma_debug_warn("spsolve(): memory allocation failure: could not allocate ", (info - int(A.n_cols)), " bytes"); } else if(info < 0) { arma_debug_warn("spsolve(): unknown SuperLU error code from gssv(): ", info); } superlu::free_stat(&stat); superlu::free(perm_c); superlu::free(perm_r); destroy_supermatrix(u); destroy_supermatrix(l); destroy_supermatrix(a); destroy_supermatrix(x); // No need to extract the data from x, since it's using the same memory as X return (info == 0); } #else { arma_ignore(X); arma_ignore(A_expr); arma_ignore(B_expr); arma_ignore(user_opts); arma_stop("spsolve(): use of SuperLU must be enabled"); return false; } #endif } template inline bool sp_auxlib::spsolve_refine(Mat& X, typename T1::pod_type& out_rcond, const SpBase& A_expr, const Base& B_expr, const superlu_opts& user_opts) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_SUPERLU) { typedef typename T1::pod_type T; typedef typename T1::elem_type eT; superlu::superlu_options_t options; sp_auxlib::set_superlu_opts(options, user_opts); const unwrap_spmat tmp1(A_expr.get_ref()); const SpMat& A = tmp1.M; const unwrap tmp2(B_expr.get_ref()); const Mat& B_unwrap = tmp2.M; const bool B_is_modified = ( (user_opts.equilibrate) || (&B_unwrap == &X) ); Mat B_copy; if(B_is_modified) { B_copy = B_unwrap; } const Mat& B = (B_is_modified) ? B_copy : B_unwrap; if(A.n_rows > A.n_cols) { arma_stop("spsolve(): solving over-determined systems currently not supported"); X.reset(); return false; } else if(A.n_rows < A.n_cols) { arma_stop("spsolve(): solving under-determined systems currently not supported"); X.reset(); return false; } arma_debug_check( (A.n_rows != B.n_rows), "spsolve(): number of rows in the given objects must be the same" ); X.zeros(A.n_cols, B.n_cols); // set the elements to zero, as we don't trust the SuperLU spaghetti code if(A.is_empty() || B.is_empty()) { return true; } if(arma_config::debug) { bool overflow; overflow = (A.n_nonzero > INT_MAX); overflow = (A.n_rows > INT_MAX) || overflow; overflow = (A.n_cols > INT_MAX) || overflow; overflow = (B.n_rows > INT_MAX) || overflow; overflow = (B.n_cols > INT_MAX) || overflow; overflow = (X.n_rows > INT_MAX) || overflow; overflow = (X.n_cols > INT_MAX) || overflow; if(overflow) { arma_bad("spsolve(): integer overflow: matrix dimensions are too large for integer type used by SuperLU"); } } superlu::SuperMatrix x; arrayops::inplace_set(reinterpret_cast(&x), char(0), sizeof(superlu::SuperMatrix)); superlu::SuperMatrix a; arrayops::inplace_set(reinterpret_cast(&a), char(0), sizeof(superlu::SuperMatrix)); superlu::SuperMatrix b; arrayops::inplace_set(reinterpret_cast(&b), char(0), sizeof(superlu::SuperMatrix)); const bool status_x = wrap_to_supermatrix(x, X); const bool status_a = copy_to_supermatrix(a, A); // NOTE: superlu::gssvx() modifies 'a' if equilibration is enabled const bool status_b = wrap_to_supermatrix(b, B); // NOTE: superlu::gssvx() modifies 'b' if equilibration is enabled if( (status_x == false) || (status_a == false) || (status_b == false) ) { destroy_supermatrix(x); destroy_supermatrix(a); destroy_supermatrix(b); X.reset(); return false; } superlu::SuperMatrix l; arrayops::inplace_set(reinterpret_cast(&l), char(0), sizeof(superlu::SuperMatrix)); superlu::SuperMatrix u; arrayops::inplace_set(reinterpret_cast(&u), char(0), sizeof(superlu::SuperMatrix)); // paranoia: use SuperLU's memory allocation, in case it reallocs int* perm_c = (int*) superlu::malloc( (A.n_cols+1) * sizeof(int) ); // extra paranoia: increase array length by 1 int* perm_r = (int*) superlu::malloc( (A.n_rows+1) * sizeof(int) ); int* etree = (int*) superlu::malloc( (A.n_cols+1) * sizeof(int) ); T* R = (T*) superlu::malloc( (A.n_rows+1) * sizeof(T) ); T* C = (T*) superlu::malloc( (A.n_cols+1) * sizeof(T) ); T* ferr = (T*) superlu::malloc( (B.n_cols+1) * sizeof(T) ); T* berr = (T*) superlu::malloc( (B.n_cols+1) * sizeof(T) ); arma_check_bad_alloc( (perm_c == 0), "spsolve(): out of memory" ); arma_check_bad_alloc( (perm_r == 0), "spsolve(): out of memory" ); arma_check_bad_alloc( (etree == 0), "spsolve(): out of memory" ); arma_check_bad_alloc( (R == 0), "spsolve(): out of memory" ); arma_check_bad_alloc( (C == 0), "spsolve(): out of memory" ); arma_check_bad_alloc( (ferr == 0), "spsolve(): out of memory" ); arma_check_bad_alloc( (berr == 0), "spsolve(): out of memory" ); arrayops::inplace_set(perm_c, int(0), A.n_cols+1); arrayops::inplace_set(perm_r, int(0), A.n_rows+1); arrayops::inplace_set(etree, int(0), A.n_cols+1); arrayops::inplace_set(R, T(0), A.n_rows+1); arrayops::inplace_set(C, T(0), A.n_cols+1); arrayops::inplace_set(ferr, T(0), B.n_cols+1); arrayops::inplace_set(berr, T(0), B.n_cols+1); superlu::mem_usage_t mu; arrayops::inplace_set(reinterpret_cast(&mu), char(0), sizeof(superlu::mem_usage_t)); superlu::SuperLUStat_t stat; superlu::init_stat(&stat); char equed[8]; // extra characters for paranoia T rpg = T(0); T rcond = T(0); int info = int(0); // Return code. char work[8]; int lwork = int(0); // 0 means superlu will allocate memory superlu::gssvx(&options, &a, perm_c, perm_r, etree, equed, R, C, &l, &u, &work[0], lwork, &b, &x, &rpg, &rcond, ferr, berr, &mu, &stat, &info); // Process the return code. if( (info > 0) && (info <= int(A.n_cols)) ) { // std::stringstream tmp; // tmp << "spsolve(): could not solve system; LU factorisation completed, but detected zero in U(" << (info-1) << ',' << (info-1) << ')'; // arma_debug_warn(tmp.str()); } else if(info == int(A.n_cols+1)) { // arma_debug_warn("spsolve(): system solved, but rcond is less than machine precision"); } else if(info > int(A.n_cols+1)) { arma_debug_warn("spsolve(): memory allocation failure: could not allocate ", (info - int(A.n_cols)), " bytes"); } else if(info < 0) { arma_debug_warn("spsolve(): unknown SuperLU error code from gssvx(): ", info); } superlu::free_stat(&stat); superlu::free(berr); superlu::free(ferr); superlu::free(C); superlu::free(R); superlu::free(etree); superlu::free(perm_r); superlu::free(perm_c); destroy_supermatrix(u); destroy_supermatrix(l); destroy_supermatrix(b); destroy_supermatrix(a); destroy_supermatrix(x); // No need to extract the data from x, since it's using the same memory as X out_rcond = rcond; return (info == 0); } #else { arma_ignore(X); arma_ignore(out_rcond); arma_ignore(A_expr); arma_ignore(B_expr); arma_ignore(user_opts); arma_stop("spsolve(): use of SuperLU must be enabled"); return false; } #endif } #if defined(ARMA_USE_SUPERLU) inline void sp_auxlib::set_superlu_opts(superlu::superlu_options_t& options, const superlu_opts& user_opts) { arma_extra_debug_sigprint(); // default options as the starting point superlu::set_default_opts(&options); // our settings options.Trans = superlu::NOTRANS; options.ConditionNumber = superlu::YES; // process user_opts if(user_opts.equilibrate == true) { options.Equil = superlu::YES; } if(user_opts.equilibrate == false) { options.Equil = superlu::NO; } if(user_opts.symmetric == true) { options.SymmetricMode = superlu::YES; } if(user_opts.symmetric == false) { options.SymmetricMode = superlu::NO; } options.DiagPivotThresh = user_opts.pivot_thresh; if(user_opts.permutation == superlu_opts::NATURAL) { options.ColPerm = superlu::NATURAL; } if(user_opts.permutation == superlu_opts::MMD_ATA) { options.ColPerm = superlu::MMD_ATA; } if(user_opts.permutation == superlu_opts::MMD_AT_PLUS_A) { options.ColPerm = superlu::MMD_AT_PLUS_A; } if(user_opts.permutation == superlu_opts::COLAMD) { options.ColPerm = superlu::COLAMD; } if(user_opts.refine == superlu_opts::REF_NONE) { options.IterRefine = superlu::NOREFINE; } if(user_opts.refine == superlu_opts::REF_SINGLE) { options.IterRefine = superlu::SLU_SINGLE; } if(user_opts.refine == superlu_opts::REF_DOUBLE) { options.IterRefine = superlu::SLU_DOUBLE; } if(user_opts.refine == superlu_opts::REF_EXTRA) { options.IterRefine = superlu::SLU_EXTRA; } } template inline bool sp_auxlib::copy_to_supermatrix(superlu::SuperMatrix& out, const SpMat& A) { arma_extra_debug_sigprint(); // We store in column-major CSC. out.Stype = superlu::SLU_NC; if(is_float::value) { out.Dtype = superlu::SLU_S; } else if(is_double::value) { out.Dtype = superlu::SLU_D; } else if(is_supported_complex_float::value) { out.Dtype = superlu::SLU_C; } else if(is_supported_complex_double::value) { out.Dtype = superlu::SLU_Z; } out.Mtype = superlu::SLU_GE; // Just a general matrix. We don't know more now. // We have to actually create the object which stores the data. // This gets cleaned by destroy_supermatrix(). // We have to use SuperLU's stupid memory allocation routines since they are // not guaranteed to be new and delete. See the comments in def_superlu.hpp superlu::NCformat* nc = (superlu::NCformat*)superlu::malloc(sizeof(superlu::NCformat)); if(nc == NULL) { return false; } nc->nnz = A.n_nonzero; nc->nzval = (void*) superlu::malloc(sizeof(eT) * A.n_nonzero ); nc->colptr = (superlu::int_t*)superlu::malloc(sizeof(superlu::int_t) * (A.n_cols + 1)); nc->rowind = (superlu::int_t*)superlu::malloc(sizeof(superlu::int_t) * A.n_nonzero ); if( (nc->nzval == NULL) || (nc->colptr == NULL) || (nc->rowind == NULL) ) { return false; } // Fill the matrix. arrayops::copy((eT*) nc->nzval, A.values, A.n_nonzero); // // These have to be copied by hand, because the types may differ. // for (uword i = 0; i <= A.n_cols; ++i) { nc->colptr[i] = (int_t) A.col_ptrs[i]; } // for (uword i = 0; i < A.n_nonzero; ++i) { nc->rowind[i] = (int_t) A.row_indices[i]; } arrayops::convert(nc->colptr, A.col_ptrs, A.n_cols+1 ); arrayops::convert(nc->rowind, A.row_indices, A.n_nonzero); out.nrow = A.n_rows; out.ncol = A.n_cols; out.Store = (void*) nc; return true; } template inline bool sp_auxlib::wrap_to_supermatrix(superlu::SuperMatrix& out, const Mat& A) { arma_extra_debug_sigprint(); // NOTE: this function re-uses memory from matrix A // This is being stored as a dense matrix. out.Stype = superlu::SLU_DN; if(is_float::value) { out.Dtype = superlu::SLU_S; } else if(is_double::value) { out.Dtype = superlu::SLU_D; } else if(is_supported_complex_float::value) { out.Dtype = superlu::SLU_C; } else if(is_supported_complex_double::value) { out.Dtype = superlu::SLU_Z; } out.Mtype = superlu::SLU_GE; // We have to create the object that stores the data. superlu::DNformat* dn = (superlu::DNformat*)superlu::malloc(sizeof(superlu::DNformat)); if(dn == NULL) { return false; } dn->lda = A.n_rows; dn->nzval = (void*) A.memptr(); // re-use memory instead of copying out.nrow = A.n_rows; out.ncol = A.n_cols; out.Store = (void*) dn; return true; } inline void sp_auxlib::destroy_supermatrix(superlu::SuperMatrix& out) { arma_extra_debug_sigprint(); // Clean up. if(out.Stype == superlu::SLU_NC) { superlu::destroy_compcol_mat(&out); } else if(out.Stype == superlu::SLU_DN) { // superlu::destroy_dense_mat(&out); // since dn->nzval is set to re-use memory from a Mat object (which manages its own memory), // we cannot simply call superlu::destroy_dense_mat(). // Only the out.Store structure can be freed. superlu::DNformat* dn = (superlu::DNformat*) out.Store; if(dn != NULL) { superlu::free(dn); } } else if(out.Stype == superlu::SLU_SC) { superlu::destroy_supernode_mat(&out); } else { // Uh, crap. std::stringstream tmp; tmp << "sp_auxlib::destroy_supermatrix(): unhandled Stype" << std::endl; tmp << "Stype val: " << out.Stype << std::endl; tmp << "Stype name: "; if(out.Stype == superlu::SLU_NC) { tmp << "SLU_NC"; } if(out.Stype == superlu::SLU_NCP) { tmp << "SLU_NCP"; } if(out.Stype == superlu::SLU_NR) { tmp << "SLU_NR"; } if(out.Stype == superlu::SLU_SC) { tmp << "SLU_SC"; } if(out.Stype == superlu::SLU_SCP) { tmp << "SLU_SCP"; } if(out.Stype == superlu::SLU_SR) { tmp << "SLU_SR"; } if(out.Stype == superlu::SLU_DN) { tmp << "SLU_DN"; } if(out.Stype == superlu::SLU_NR_loc) { tmp << "SLU_NR_loc"; } arma_debug_warn(tmp.str()); arma_bad("sp_auxlib::destroy_supermatrix(): internal error"); } } #endif template inline void sp_auxlib::run_aupd ( const uword n_eigvals, char* which, const SpProxy& p, const bool sym, blas_int& n, eT& tol, podarray& resid, blas_int& ncv, podarray& v, blas_int& ldv, podarray& iparam, podarray& ipntr, podarray& workd, podarray& workl, blas_int& lworkl, podarray& rwork, blas_int& info ) { #if defined(ARMA_USE_ARPACK) { // ARPACK provides a "reverse communication interface" which is an // entertainingly archaic FORTRAN software engineering technique that // basically means that we call saupd()/naupd() and it tells us with some // return code what we need to do next (usually a matrix-vector product) and // then call it again. So this results in some type of iterative process // where we call saupd()/naupd() many times. blas_int ido = 0; // This must be 0 for the first call. char bmat = 'I'; // We are considering the standard eigenvalue problem. n = p.get_n_rows(); // The size of the matrix. blas_int nev = n_eigvals; resid.set_size(n); // Two contraints on NCV: (NCV > NEV + 2) and (NCV <= N) // // We're calling either arpack::saupd() or arpack::naupd(), // which have slighly different minimum constraint and recommended value for NCV: // http://www.caam.rice.edu/software/ARPACK/UG/node136.html // http://www.caam.rice.edu/software/ARPACK/UG/node138.html ncv = nev + 2 + 1; if (ncv < (2 * nev + 1)) { ncv = 2 * nev + 1; } if (ncv > n ) { ncv = n; } v.set_size(n * ncv); // Array N by NCV (output). rwork.set_size(ncv); // Work array of size NCV for complex calls. ldv = n; // "Leading dimension of V exactly as declared in the calling program." // IPARAM: integer array of length 11. iparam.zeros(11); iparam(0) = 1; // Exact shifts (not provided by us). iparam(2) = 1000; // Maximum iterations; all the examples use 300, but they were written in the ancient times. iparam(6) = 1; // Mode 1: A * x = lambda * x. // IPNTR: integer array of length 14 (output). ipntr.set_size(14); // Real work array used in the basic Arnoldi iteration for reverse communication. workd.set_size(3 * n); // lworkl must be at least 3 * NCV^2 + 6 * NCV. lworkl = 3 * (ncv * ncv) + 6 * ncv; // Real work array of length lworkl. workl.set_size(lworkl); info = 0; // Set to 0 initially to use random initial vector. // All the parameters have been set or created. Time to loop a lot. while (ido != 99) { // Call saupd() or naupd() with the current parameters. if(sym) arpack::saupd(&ido, &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, &info); else arpack::naupd(&ido, &bmat, &n, which, &nev, &tol, resid.memptr(), &ncv, v.memptr(), &ldv, iparam.memptr(), ipntr.memptr(), workd.memptr(), workl.memptr(), &lworkl, rwork.memptr(), &info); // What do we do now? switch (ido) { case -1: case 1: { // We need to calculate the matrix-vector multiplication y = OP * x // where x is of length n and starts at workd(ipntr(0)), and y is of // length n and starts at workd(ipntr(1)). // operator*(sp_mat, vec) doesn't properly put the result into the // right place so we'll just reimplement it here for now... // Set the output to point at the right memory. We have to subtract // one from FORTRAN pointers... Col out(workd.memptr() + ipntr(1) - 1, n, false /* don't copy */); // Set the input to point at the right memory. Col in(workd.memptr() + ipntr(0) - 1, n, false /* don't copy */); out.zeros(); typename SpProxy::const_iterator_type x_it = p.begin(); typename SpProxy::const_iterator_type x_it_end = p.end(); while(x_it != x_it_end) { out[x_it.row()] += (*x_it) * in[x_it.col()]; ++x_it; } // No need to modify memory further since it was all done in-place. break; } case 99: // Nothing to do here, things have converged. break; default: { return; // Parent frame can look at the value of info. } } } // The process has ended; check the return code. if( (info != 0) && (info != 1) ) { // Print warnings if there was a failure. if(sym) { arma_debug_warn("eigs_sym(): ARPACK error ", info, " in saupd()"); } else { arma_debug_warn("eigs_gen(): ARPACK error ", info, " in naupd()"); } return; // Parent frame can look at the value of info. } } #else arma_ignore(n_eigvals); arma_ignore(which); arma_ignore(p); arma_ignore(sym); arma_ignore(n); arma_ignore(tol); arma_ignore(resid); arma_ignore(ncv); arma_ignore(v); arma_ignore(ldv); arma_ignore(iparam); arma_ignore(ipntr); arma_ignore(workd); arma_ignore(workl); arma_ignore(lworkl); arma_ignore(rwork); arma_ignore(info); #endif } armadillo-6.500.5/include/armadillo_bits/op_dotext_bones.hpp0000666000000000000000000000217212620272703022654 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_dotext //! @{ class op_dotext { public: template inline static eT direct_rowvec_mat_colvec (const eT* A_mem, const Mat& B, const eT* C_mem); template inline static eT direct_rowvec_transmat_colvec (const eT* A_mem, const Mat& B, const eT* C_mem); template inline static eT direct_rowvec_diagmat_colvec (const eT* A_mem, const Mat& B, const eT* C_mem); template inline static eT direct_rowvec_invdiagmat_colvec(const eT* A_mem, const Mat& B, const eT* C_mem); template inline static eT direct_rowvec_invdiagvec_colvec(const eT* A_mem, const Mat& B, const eT* C_mem); }; //! @} armadillo-6.500.5/include/armadillo_bits/subview_meat.hpp0000666000000000000000000022573712650111756022174 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin // Written by James Sanders //! \addtogroup subview //! @{ template inline subview::~subview() { arma_extra_debug_sigprint(); } template inline subview::subview(const Mat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols) : m(in_m) , aux_row1(in_row1) , aux_col1(in_col1) , n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows*in_n_cols) { arma_extra_debug_sigprint(); } template inline void subview::operator= (const eT val) { arma_extra_debug_sigprint(); if(n_elem != 1) { arma_debug_assert_same_size(n_rows, n_cols, 1, 1, "copy into submatrix"); } Mat& X = const_cast< Mat& >(m); X.at(aux_row1, aux_col1) = val; } template template inline void subview::inplace_op(const eT val) { arma_extra_debug_sigprint(); subview& s = *this; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(s.m); const uword A_n_rows = A.n_rows; eT* Aptr = &(A.at(s.aux_row1,s.aux_col1)); uword jj; for(jj=1; jj < s_n_cols; jj+=2) { if(is_same_type::yes) { (*Aptr) += val; Aptr += A_n_rows; (*Aptr) += val; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) -= val; Aptr += A_n_rows; (*Aptr) -= val; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) *= val; Aptr += A_n_rows; (*Aptr) *= val; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) /= val; Aptr += A_n_rows; (*Aptr) /= val; Aptr += A_n_rows; } } if((jj-1) < s_n_cols) { if(is_same_type::yes) { (*Aptr) += val; } if(is_same_type::yes) { (*Aptr) -= val; } if(is_same_type::yes) { (*Aptr) *= val; } if(is_same_type::yes) { (*Aptr) /= val; } } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { if(is_same_type::yes) { arrayops::inplace_plus ( colptr(ucol), val, s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_minus( colptr(ucol), val, s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_mul ( colptr(ucol), val, s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_div ( colptr(ucol), val, s_n_rows ); } } } } template template inline void subview::inplace_op(const Base& in, const char* identifier) { arma_extra_debug_sigprint(); const Proxy P(in.get_ref()); subview& s = *this; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_assert_same_size(s, P, identifier); const bool is_alias = P.is_alias(s.m); if(is_alias) { arma_extra_debug_print("aliasing detected"); } if( (is_Mat::stored_type>::value) || (is_alias) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& B = tmp.M; if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(m); const uword A_n_rows = A.n_rows; eT* Aptr = &(A.at(aux_row1,aux_col1)); const eT* Bptr = B.memptr(); uword jj; for(jj=1; jj < s_n_cols; jj+=2) { const eT tmp1 = (*Bptr); Bptr++; const eT tmp2 = (*Bptr); Bptr++; if(is_same_type::yes) { (*Aptr) = tmp1; Aptr += A_n_rows; (*Aptr) = tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) += tmp1; Aptr += A_n_rows; (*Aptr) += tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) -= tmp1; Aptr += A_n_rows; (*Aptr) -= tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) *= tmp1; Aptr += A_n_rows; (*Aptr) *= tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) /= tmp1; Aptr += A_n_rows; (*Aptr) /= tmp2; Aptr += A_n_rows; } } if((jj-1) < s_n_cols) { if(is_same_type::yes) { (*Aptr) = (*Bptr); } if(is_same_type::yes) { (*Aptr) += (*Bptr); } if(is_same_type::yes) { (*Aptr) -= (*Bptr); } if(is_same_type::yes) { (*Aptr) *= (*Bptr); } if(is_same_type::yes) { (*Aptr) /= (*Bptr); } } } else // not a row vector { for(uword ucol=0; ucol < s_n_cols; ++ucol) { if(is_same_type::yes) { arrayops::copy ( s.colptr(ucol), B.colptr(ucol), s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_plus ( s.colptr(ucol), B.colptr(ucol), s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_minus( s.colptr(ucol), B.colptr(ucol), s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_mul ( s.colptr(ucol), B.colptr(ucol), s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_div ( s.colptr(ucol), B.colptr(ucol), s_n_rows ); } } } } else // use the Proxy { if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(m); const uword A_n_rows = A.n_rows; eT* Aptr = &(A.at(aux_row1,aux_col1)); uword jj; for(jj=1; jj < s_n_cols; jj+=2) { const uword ii = (jj-1); const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,jj) : P[jj]; if(is_same_type::yes) { (*Aptr) = tmp1; Aptr += A_n_rows; (*Aptr) = tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) += tmp1; Aptr += A_n_rows; (*Aptr) += tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) -= tmp1; Aptr += A_n_rows; (*Aptr) -= tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) *= tmp1; Aptr += A_n_rows; (*Aptr) *= tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) /= tmp1; Aptr += A_n_rows; (*Aptr) /= tmp2; Aptr += A_n_rows; } } const uword ii = (jj-1); if(ii < s_n_cols) { if(is_same_type::yes) { (*Aptr) = (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } if(is_same_type::yes) { (*Aptr) += (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } if(is_same_type::yes) { (*Aptr) -= (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } if(is_same_type::yes) { (*Aptr) *= (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } if(is_same_type::yes) { (*Aptr) /= (Proxy::prefer_at_accessor) ? P.at(0,ii) : P[ii]; } } } else // not a row vector { if(Proxy::prefer_at_accessor) { for(uword ucol=0; ucol < s_n_cols; ++ucol) { eT* s_col_data = s.colptr(ucol); uword jj; for(jj=1; jj < s_n_rows; jj+=2) { const uword ii = (jj-1); const eT tmp1 = P.at(ii,ucol); const eT tmp2 = P.at(jj,ucol); if(is_same_type::yes) { (*s_col_data) = tmp1; s_col_data++; (*s_col_data) = tmp2; s_col_data++; } if(is_same_type::yes) { (*s_col_data) += tmp1; s_col_data++; (*s_col_data) += tmp2; s_col_data++; } if(is_same_type::yes) { (*s_col_data) -= tmp1; s_col_data++; (*s_col_data) -= tmp2; s_col_data++; } if(is_same_type::yes) { (*s_col_data) *= tmp1; s_col_data++; (*s_col_data) *= tmp2; s_col_data++; } if(is_same_type::yes) { (*s_col_data) /= tmp1; s_col_data++; (*s_col_data) /= tmp2; s_col_data++; } } const uword ii = (jj-1); if(ii < s_n_rows) { if(is_same_type::yes) { (*s_col_data) = P.at(ii,ucol); } if(is_same_type::yes) { (*s_col_data) += P.at(ii,ucol); } if(is_same_type::yes) { (*s_col_data) -= P.at(ii,ucol); } if(is_same_type::yes) { (*s_col_data) *= P.at(ii,ucol); } if(is_same_type::yes) { (*s_col_data) /= P.at(ii,ucol); } } } } else { typename Proxy::ea_type Pea = P.get_ea(); uword count = 0; for(uword ucol=0; ucol < s_n_cols; ++ucol) { eT* s_col_data = s.colptr(ucol); uword jj; for(jj=1; jj < s_n_rows; jj+=2) { const eT tmp1 = Pea[count]; count++; const eT tmp2 = Pea[count]; count++; if(is_same_type::yes) { (*s_col_data) = tmp1; s_col_data++; (*s_col_data) = tmp2; s_col_data++; } if(is_same_type::yes) { (*s_col_data) += tmp1; s_col_data++; (*s_col_data) += tmp2; s_col_data++; } if(is_same_type::yes) { (*s_col_data) -= tmp1; s_col_data++; (*s_col_data) -= tmp2; s_col_data++; } if(is_same_type::yes) { (*s_col_data) *= tmp1; s_col_data++; (*s_col_data) *= tmp2; s_col_data++; } if(is_same_type::yes) { (*s_col_data) /= tmp1; s_col_data++; (*s_col_data) /= tmp2; s_col_data++; } } if((jj-1) < s_n_rows) { if(is_same_type::yes) { (*s_col_data) = Pea[count]; count++; } if(is_same_type::yes) { (*s_col_data) += Pea[count]; count++; } if(is_same_type::yes) { (*s_col_data) -= Pea[count]; count++; } if(is_same_type::yes) { (*s_col_data) *= Pea[count]; count++; } if(is_same_type::yes) { (*s_col_data) /= Pea[count]; count++; } } } } } } } template template inline void subview::inplace_op(const subview& x, const char* identifier) { arma_extra_debug_sigprint(); if(check_overlap(x)) { const Mat tmp(x); if(is_same_type::yes) { (*this).operator= (tmp); } if(is_same_type::yes) { (*this).operator+=(tmp); } if(is_same_type::yes) { (*this).operator-=(tmp); } if(is_same_type::yes) { (*this).operator%=(tmp); } if(is_same_type::yes) { (*this).operator/=(tmp); } return; } subview& s = *this; arma_debug_assert_same_size(s, x, identifier); const uword s_n_cols = s.n_cols; const uword s_n_rows = s.n_rows; if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(s.m); const Mat& B = x.m; const uword A_n_rows = A.n_rows; const uword B_n_rows = B.n_rows; eT* Aptr = &(A.at(s.aux_row1,s.aux_col1)); const eT* Bptr = &(B.at(x.aux_row1,x.aux_col1)); uword jj; for(jj=1; jj < s_n_cols; jj+=2) { const eT tmp1 = (*Bptr); Bptr += B_n_rows; const eT tmp2 = (*Bptr); Bptr += B_n_rows; if(is_same_type::yes) { (*Aptr) = tmp1; Aptr += A_n_rows; (*Aptr) = tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) += tmp1; Aptr += A_n_rows; (*Aptr) += tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) -= tmp1; Aptr += A_n_rows; (*Aptr) -= tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) *= tmp1; Aptr += A_n_rows; (*Aptr) *= tmp2; Aptr += A_n_rows; } if(is_same_type::yes) { (*Aptr) /= tmp1; Aptr += A_n_rows; (*Aptr) /= tmp2; Aptr += A_n_rows; } } if((jj-1) < s_n_cols) { if(is_same_type::yes) { (*Aptr) = (*Bptr); } if(is_same_type::yes) { (*Aptr) += (*Bptr); } if(is_same_type::yes) { (*Aptr) -= (*Bptr); } if(is_same_type::yes) { (*Aptr) *= (*Bptr); } if(is_same_type::yes) { (*Aptr) /= (*Bptr); } } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { if(is_same_type::yes) { arrayops::copy ( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_plus ( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_minus( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_mul ( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } if(is_same_type::yes) { arrayops::inplace_div ( s.colptr(ucol), x.colptr(ucol), s_n_rows ); } } } } template inline void subview::operator+= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview::operator-= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview::operator*= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview::operator/= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview::operator= (const subview& x) { arma_extra_debug_sigprint(); inplace_op(x, "copy into submatrix"); } template inline void subview::operator+= (const subview& x) { arma_extra_debug_sigprint(); inplace_op(x, "addition"); } template inline void subview::operator-= (const subview& x) { arma_extra_debug_sigprint(); inplace_op(x, "subtraction"); } template inline void subview::operator%= (const subview& x) { arma_extra_debug_sigprint(); inplace_op(x, "element-wise multiplication"); } template inline void subview::operator/= (const subview& x) { arma_extra_debug_sigprint(); inplace_op(x, "element-wise division"); } template template inline void subview::operator= (const Base& in) { arma_extra_debug_sigprint(); inplace_op(in, "copy into submatrix"); } template template inline void subview::operator+= (const Base& in) { arma_extra_debug_sigprint(); inplace_op(in, "addition"); } template template inline void subview::operator-= (const Base& in) { arma_extra_debug_sigprint(); inplace_op(in, "subtraction"); } template template inline void subview::operator%= (const Base& in) { arma_extra_debug_sigprint(); inplace_op(in, "element-wise multiplication"); } template template inline void subview::operator/= (const Base& in) { arma_extra_debug_sigprint(); inplace_op(in, "element-wise division"); } template template inline void subview::operator=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "copy into submatrix"); // Clear the subview. zeros(); // Iterate through the sparse subview and set the nonzero values appropriately. typename SpProxy::const_iterator_type cit = p.begin(); typename SpProxy::const_iterator_type cit_end = p.end(); while(cit != cit_end) { at(cit.row(), cit.col()) = *cit; ++cit; } } template template inline void subview::operator+=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "addition"); // Iterate through the sparse subview and add its values. typename SpProxy::const_iterator_type cit = p.begin(); typename SpProxy::const_iterator_type cit_end = p.end(); while(cit != cit_end) { at(cit.row(), cit.col()) += *cit; ++cit; } } template template inline void subview::operator-=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "subtraction"); // Iterate through the sparse subview and subtract its values. typename SpProxy::const_iterator_type cit = p.begin(); typename SpProxy::const_iterator_type cit_end = p.end(); while(cit != cit_end) { at(cit.row(), cit.col()) -= *cit; ++cit; } } template template inline void subview::operator%=(const SpBase& x) { arma_extra_debug_sigprint(); const uword s_n_rows = (*this).n_rows; const uword s_n_cols = (*this).n_cols; const SpProxy p(x.get_ref()); arma_debug_assert_same_size(s_n_rows, s_n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise multiplication"); if(n_elem == 0) { return; } if(p.get_n_nonzero() == 0) { (*this).zeros(); return; } // Iterate over nonzero values. // Any zero values in the sparse expression will result in a zero in our subview. typename SpProxy::const_iterator_type cit = p.begin(); typename SpProxy::const_iterator_type cit_end = p.end(); uword r = 0; uword c = 0; while(cit != cit_end) { const uword cit_row = cit.row(); const uword cit_col = cit.col(); while( ((r == cit_row) && (c == cit_col)) == false ) { at(r,c) = eT(0); r++; if(r >= s_n_rows) { r = 0; c++; } } at(r, c) *= (*cit); ++cit; r++; if(r >= s_n_rows) { r = 0; c++; } } } template template inline void subview::operator/=(const SpBase& x) { arma_extra_debug_sigprint(); const SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise division"); // This is probably going to fill your subview with a bunch of NaNs, // so I'm not going to bother to implement it fast. // You can have slow NaNs. They're fine too. for (uword c = 0; c < n_cols; ++c) for (uword r = 0; r < n_rows; ++r) { at(r, c) /= p.at(r, c); } } template template inline typename enable_if2< is_same_type::value, void>::result subview::operator= (const Gen& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(n_rows, n_cols, in.n_rows, in.n_cols, "copy into submatrix"); in.apply(*this); } //! apply a functor to each element template template inline void subview::for_each(functor F) { arma_extra_debug_sigprint(); Mat& X = const_cast< Mat& >(m); if(n_rows == 1) { const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + n_cols; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) { F( X.at(urow, ucol) ); } } else { const uword start_col = aux_col1; const uword start_row = aux_row1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) for(uword urow = start_row; urow < end_row_plus1; ++urow) { F( X.at(urow, ucol) ); } } } template template inline void subview::for_each(functor F) const { arma_extra_debug_sigprint(); const Mat& X = m; if(n_rows == 1) { const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + n_cols; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) { F( X.at(urow, ucol) ); } } else { const uword start_col = aux_col1; const uword start_row = aux_row1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) for(uword urow = start_row; urow < end_row_plus1; ++urow) { F( X.at(urow, ucol) ); } } } //! transform each element in the subview using a functor template template inline void subview::transform(functor F) { arma_extra_debug_sigprint(); Mat& X = const_cast< Mat& >(m); if(n_rows == 1) { const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + n_cols; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) { X.at(urow, ucol) = eT( F( X.at(urow, ucol) ) ); } } else { const uword start_col = aux_col1; const uword start_row = aux_row1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) for(uword urow = start_row; urow < end_row_plus1; ++urow) { X.at(urow, ucol) = eT( F( X.at(urow, ucol) ) ); } } } //! imbue (fill) the subview with values provided by a functor template template inline void subview::imbue(functor F) { arma_extra_debug_sigprint(); Mat& X = const_cast< Mat& >(m); if(n_rows == 1) { const uword urow = aux_row1; const uword start_col = aux_col1; const uword end_col_plus1 = start_col + n_cols; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) { X.at(urow, ucol) = eT( F() ); } } else { const uword start_col = aux_col1; const uword start_row = aux_row1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; for(uword ucol = start_col; ucol < end_col_plus1; ++ucol) for(uword urow = start_row; urow < end_row_plus1; ++urow) { X.at(urow, ucol) = eT( F() ); } } } template inline void subview::fill(const eT val) { arma_extra_debug_sigprint(); subview& s = *this; const uword s_n_cols = s.n_cols; const uword s_n_rows = s.n_rows; if(s_n_rows == 1) { Mat& A = const_cast< Mat& >(s.m); const uword A_n_rows = A.n_rows; eT* Aptr = &(A.at(s.aux_row1,s.aux_col1)); uword jj; for(jj=1; jj < s_n_cols; jj+=2) { (*Aptr) = val; Aptr += A_n_rows; (*Aptr) = val; Aptr += A_n_rows; } if((jj-1) < s_n_cols) { (*Aptr) = val; } } else { for(uword ucol=0; ucol < s_n_cols; ++ucol) { arrayops::inplace_set( s.colptr(ucol), val, s_n_rows ); } } } template inline void subview::zeros() { arma_extra_debug_sigprint(); (*this).fill(eT(0)); } template inline void subview::ones() { arma_extra_debug_sigprint(); (*this).fill(eT(1)); } template inline void subview::eye() { arma_extra_debug_sigprint(); (*this).zeros(); const uword N = (std::min)(n_rows, n_cols); for(uword ii=0; ii < N; ++ii) { at(ii,ii) = eT(1); } } template inline void subview::randu() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; if(local_n_rows == 1) { for(uword ii=0; ii < local_n_cols; ++ii) { at(0,ii) = eT(arma_rng::randu()); } } else { for(uword ii=0; ii < local_n_cols; ++ii) { arma_rng::randu::fill( colptr(ii), local_n_rows ); } } } template inline void subview::randn() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; if(local_n_rows == 1) { for(uword ii=0; ii < local_n_cols; ++ii) { at(0,ii) = eT(arma_rng::randn()); } } else { for(uword ii=0; ii < local_n_cols; ++ii) { arma_rng::randn::fill( colptr(ii), local_n_rows ); } } } template inline eT subview::at_alt(const uword ii) const { return operator[](ii); } template inline eT& subview::operator[](const uword ii) { const uword in_col = ii / n_rows; const uword in_row = ii % n_rows; const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Mat& >(m)).mem[index] ); } template inline eT subview::operator[](const uword ii) const { const uword in_col = ii / n_rows; const uword in_row = ii % n_rows; const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template inline eT& subview::operator()(const uword ii) { arma_debug_check( (ii >= n_elem), "subview::operator(): index out of bounds"); const uword in_col = ii / n_rows; const uword in_row = ii % n_rows; const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Mat& >(m)).mem[index] ); } template inline eT subview::operator()(const uword ii) const { arma_debug_check( (ii >= n_elem), "subview::operator(): index out of bounds"); const uword in_col = ii / n_rows; const uword in_row = ii % n_rows; const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template inline eT& subview::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds"); const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Mat& >(m)).mem[index] ); } template inline eT subview::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds"); const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template inline eT& subview::at(const uword in_row, const uword in_col) { const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Mat& >(m)).mem[index] ); } template inline eT subview::at(const uword in_row, const uword in_col) const { const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template arma_inline eT* subview::colptr(const uword in_col) { return & access::rw((const_cast< Mat& >(m)).mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]); } template arma_inline const eT* subview::colptr(const uword in_col) const { return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]; } template inline bool subview::check_overlap(const subview& x) const { const subview& s = *this; if(&s.m != &x.m) { return false; } else { if( (s.n_elem == 0) || (x.n_elem == 0) ) { return false; } else { const uword s_row_start = s.aux_row1; const uword s_row_end_p1 = s_row_start + s.n_rows; const uword s_col_start = s.aux_col1; const uword s_col_end_p1 = s_col_start + s.n_cols; const uword x_row_start = x.aux_row1; const uword x_row_end_p1 = x_row_start + x.n_rows; const uword x_col_start = x.aux_col1; const uword x_col_end_p1 = x_col_start + x.n_cols; const bool outside_rows = ( (x_row_start >= s_row_end_p1) || (s_row_start >= x_row_end_p1) ); const bool outside_cols = ( (x_col_start >= s_col_end_p1) || (s_col_start >= x_col_end_p1) ); return ( (outside_rows == false) && (outside_cols == false) ); } } } template inline arma_warn_unused bool subview::is_vec() const { return ( (n_rows == 1) || (n_cols == 1) ); } template inline arma_warn_unused bool subview::is_finite() const { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; for(uword ii=0; ii inline arma_warn_unused bool subview::has_inf() const { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; for(uword ii=0; ii inline arma_warn_unused bool subview::has_nan() const { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; for(uword ii=0; ii inline void subview::extract(Mat& out, const subview& in) { arma_extra_debug_sigprint(); // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const uword n_rows = in.n_rows; // number of rows in the subview const uword n_cols = in.n_cols; // number of columns in the subview arma_extra_debug_print(arma_str::format("out.n_rows = %d out.n_cols = %d in.m.n_rows = %d in.m.n_cols = %d") % out.n_rows % out.n_cols % in.m.n_rows % in.m.n_cols ); if(in.is_vec() == true) { if(n_cols == 1) // a column vector { arma_extra_debug_print("subview::extract(): copying col (going across rows)"); // in.colptr(0) the first column of the subview, taking into account any row offset arrayops::copy( out.memptr(), in.colptr(0), n_rows ); } else // a row vector (possibly empty) { arma_extra_debug_print("subview::extract(): copying row (going across columns)"); eT* out_mem = out.memptr(); const uword X_n_rows = in.m.n_rows; const eT* Xptr = &(in.m.at(in.aux_row1,in.aux_col1)); uword j; for(j=1; j < n_cols; j+=2) { const eT tmp1 = (*Xptr); Xptr += X_n_rows; const eT tmp2 = (*Xptr); Xptr += X_n_rows; (*out_mem) = tmp1; out_mem++; (*out_mem) = tmp2; out_mem++; } if((j-1) < n_cols) { (*out_mem) = (*Xptr); } } } else // general submatrix { arma_extra_debug_print("subview::extract(): general submatrix"); for(uword col=0; col < n_cols; ++col) { arrayops::copy( out.colptr(col), in.colptr(col), n_rows ); } } } //! X += Y.submat(...) template inline void subview::plus_inplace(Mat& out, const subview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "addition"); const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows == 1) { eT* out_mem = out.memptr(); const Mat& X = in.m; const uword row = in.aux_row1; const uword start_col = in.aux_col1; uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp1 = X.at(row, start_col+i); const eT tmp2 = X.at(row, start_col+j); out_mem[i] += tmp1; out_mem[j] += tmp2; } if(i < n_cols) { out_mem[i] += X.at(row, start_col+i); } } else { for(uword col=0; col < n_cols; ++col) { arrayops::inplace_plus(out.colptr(col), in.colptr(col), n_rows); } } } //! X -= Y.submat(...) template inline void subview::minus_inplace(Mat& out, const subview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "subtraction"); const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows == 1) { eT* out_mem = out.memptr(); const Mat& X = in.m; const uword row = in.aux_row1; const uword start_col = in.aux_col1; uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp1 = X.at(row, start_col+i); const eT tmp2 = X.at(row, start_col+j); out_mem[i] -= tmp1; out_mem[j] -= tmp2; } if(i < n_cols) { out_mem[i] -= X.at(row, start_col+i); } } else { for(uword col=0; col < n_cols; ++col) { arrayops::inplace_minus(out.colptr(col), in.colptr(col), n_rows); } } } //! X %= Y.submat(...) template inline void subview::schur_inplace(Mat& out, const subview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "element-wise multiplication"); const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows == 1) { eT* out_mem = out.memptr(); const Mat& X = in.m; const uword row = in.aux_row1; const uword start_col = in.aux_col1; uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp1 = X.at(row, start_col+i); const eT tmp2 = X.at(row, start_col+j); out_mem[i] *= tmp1; out_mem[j] *= tmp2; } if(i < n_cols) { out_mem[i] *= X.at(row, start_col+i); } } else { for(uword col=0; col < n_cols; ++col) { arrayops::inplace_mul(out.colptr(col), in.colptr(col), n_rows); } } } //! X /= Y.submat(...) template inline void subview::div_inplace(Mat& out, const subview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "element-wise division"); const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows == 1) { eT* out_mem = out.memptr(); const Mat& X = in.m; const uword row = in.aux_row1; const uword start_col = in.aux_col1; uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp1 = X.at(row, start_col+i); const eT tmp2 = X.at(row, start_col+j); out_mem[i] /= tmp1; out_mem[j] /= tmp2; } if(i < n_cols) { out_mem[i] /= X.at(row, start_col+i); } } else { for(uword col=0; col < n_cols; ++col) { arrayops::inplace_div(out.colptr(col), in.colptr(col), n_rows); } } } //! creation of subview (row vector) template inline subview_row subview::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" ); const uword base_row = aux_row1 + row_num; return subview_row(m, base_row, aux_col1, n_cols); } //! creation of subview (row vector) template inline const subview_row subview::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" ); const uword base_row = aux_row1 + row_num; return subview_row(m, base_row, aux_col1, n_cols); } template inline subview_row subview::operator()(const uword row_num, const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword base_col1 = aux_col1 + in_col1; const uword base_row = aux_row1 + row_num; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "subview::operator(): indices out of bounds or incorrectly used" ); return subview_row(m, base_row, base_col1, submat_n_cols); } template inline const subview_row subview::operator()(const uword row_num, const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword base_col1 = aux_col1 + in_col1; const uword base_row = aux_row1 + row_num; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "subview::operator(): indices out of bounds or incorrectly used" ); return subview_row(m, base_row, base_col1, submat_n_cols); } //! creation of subview (column vector) template inline subview_col subview::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds"); const uword base_col = aux_col1 + col_num; return subview_col(m, base_col, aux_row1, n_rows); } //! creation of subview (column vector) template inline const subview_col subview::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds"); const uword base_col = aux_col1 + col_num; return subview_col(m, base_col, aux_row1, n_rows); } template inline subview_col subview::operator()(const span& row_span, const uword col_num) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword base_row1 = aux_row1 + in_row1; const uword base_col = aux_col1 + col_num; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "subview::operator(): indices out of bounds or incorrectly used" ); return subview_col(m, base_col, base_row1, submat_n_rows); } template inline const subview_col subview::operator()(const span& row_span, const uword col_num) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword base_row1 = aux_row1 + in_row1; const uword base_col = aux_col1 + col_num; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "subview::operator(): indices out of bounds or incorrectly used" ); return subview_col(m, base_col, base_row1, submat_n_rows); } //! create a Col object which uses memory from an existing matrix object. //! this approach is currently not alias safe //! and does not take into account that the parent matrix object could be deleted. //! if deleted memory is accessed by the created Col object, //! it will cause memory corruption and/or a crash template inline Col subview::unsafe_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds"); return Col(colptr(col_num), n_rows, false, true); } //! create a Col object which uses memory from an existing matrix object. //! this approach is currently not alias safe //! and does not take into account that the parent matrix object could be deleted. //! if deleted memory is accessed by the created Col object, //! it will cause memory corruption and/or a crash template inline const Col subview::unsafe_col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds"); return Col(const_cast(colptr(col_num)), n_rows, false, true); } //! creation of subview (submatrix comprised of specified row vectors) template inline subview subview::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "subview::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = aux_row1 + in_row1; return subview(m, base_row1, aux_col1, subview_n_rows, n_cols ); } //! creation of subview (submatrix comprised of specified row vectors) template inline const subview subview::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "subview::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = aux_row1 + in_row1; return subview(m, base_row1, aux_col1, subview_n_rows, n_cols ); } //! creation of subview (submatrix comprised of specified column vectors) template inline subview subview::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "subview::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = aux_col1 + in_col1; return subview(m, aux_row1, base_col1, n_rows, subview_n_cols); } //! creation of subview (submatrix comprised of specified column vectors) template inline const subview subview::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "subview::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = aux_col1 + in_col1; return subview(m, aux_row1, base_col1, n_rows, subview_n_cols); } //! creation of subview (submatrix) template inline subview subview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "subview::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_row1 = aux_row1 + in_row1; const uword base_col1 = aux_col1 + in_col1; return subview(m, base_row1, base_col1, subview_n_rows, subview_n_cols); } //! creation of subview (generic submatrix) template inline const subview subview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "subview::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_row1 = aux_row1 + in_row1; const uword base_col1 = aux_col1 + in_col1; return subview(m, base_row1, base_col1, subview_n_rows, subview_n_cols); } //! creation of subview (submatrix) template inline subview subview::submat(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "subview::submat(): indices out of bounds or incorrectly used" ); const uword base_row1 = aux_row1 + in_row1; const uword base_col1 = aux_col1 + in_col1; return subview(m, base_row1, base_col1, submat_n_rows, submat_n_cols); } //! creation of subview (generic submatrix) template inline const subview subview::submat(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "subview::submat(): indices out of bounds or incorrectly used" ); const uword base_row1 = aux_row1 + in_row1; const uword base_col1 = aux_col1 + in_col1; return subview(m, base_row1, base_col1, submat_n_rows, submat_n_cols); } template inline subview subview::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return (*this).submat(row_span, col_span); } template inline const subview subview::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return (*this).submat(row_span, col_span); } template inline subview_each1< subview, 0 > subview::each_col() { arma_extra_debug_sigprint(); return subview_each1< subview, 0 >(*this); } template inline subview_each1< subview, 1 > subview::each_row() { arma_extra_debug_sigprint(); return subview_each1< subview, 1 >(*this); } template template inline subview_each2< subview, 0, T1 > subview::each_col(const Base& indices) { arma_extra_debug_sigprint(); return subview_each2< subview, 0, T1 >(*this, indices); } template template inline subview_each2< subview, 1, T1 > subview::each_row(const Base& indices) { arma_extra_debug_sigprint(); return subview_each2< subview, 1, T1 >(*this, indices); } #if defined(ARMA_USE_CXX11) //! apply a lambda function to each column, where each column is interpreted as a column vector template inline void subview::each_col(const std::function< void(Col&) >& F) { arma_extra_debug_sigprint(); for(uword ii=0; ii < n_cols; ++ii) { Col tmp(colptr(ii), n_rows, false, true); F(tmp); } } template inline void subview::each_col(const std::function< void(const Col&) >& F) const { arma_extra_debug_sigprint(); for(uword ii=0; ii < n_cols; ++ii) { const Col tmp(colptr(ii), n_rows, false, true); F(tmp); } } //! apply a lambda function to each row, where each row is interpreted as a row vector template inline void subview::each_row(const std::function< void(Row&) >& F) { arma_extra_debug_sigprint(); podarray array1(n_cols); podarray array2(n_cols); Row tmp1( array1.memptr(), n_cols, false, true ); Row tmp2( array2.memptr(), n_cols, false, true ); eT* tmp1_mem = tmp1.memptr(); eT* tmp2_mem = tmp2.memptr(); uword ii, jj; for(ii=0, jj=1; jj < n_rows; ii+=2, jj+=2) { for(uword col_id = 0; col_id < n_cols; ++col_id) { const eT* col_mem = colptr(col_id); tmp1_mem[col_id] = col_mem[ii]; tmp2_mem[col_id] = col_mem[jj]; } F(tmp1); F(tmp2); for(uword col_id = 0; col_id < n_cols; ++col_id) { eT* col_mem = colptr(col_id); col_mem[ii] = tmp1_mem[col_id]; col_mem[jj] = tmp2_mem[col_id]; } } if(ii < n_rows) { tmp1 = (*this).row(ii); F(tmp1); (*this).row(ii) = tmp1; } } template inline void subview::each_row(const std::function< void(const Row&) >& F) const { arma_extra_debug_sigprint(); podarray array1(n_cols); podarray array2(n_cols); Row tmp1( array1.memptr(), n_cols, false, true ); Row tmp2( array2.memptr(), n_cols, false, true ); eT* tmp1_mem = tmp1.memptr(); eT* tmp2_mem = tmp2.memptr(); uword ii, jj; for(ii=0, jj=1; jj < n_rows; ii+=2, jj+=2) { for(uword col_id = 0; col_id < n_cols; ++col_id) { const eT* col_mem = colptr(col_id); tmp1_mem[col_id] = col_mem[ii]; tmp2_mem[col_id] = col_mem[jj]; } F(tmp1); F(tmp2); } if(ii < n_rows) { tmp1 = (*this).row(ii); F(tmp1); } } #endif //! creation of diagview (diagonal) template inline diagview subview::diag(const sword in_id) { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? uword(-in_id) : 0; const uword col_offset = (in_id > 0) ? uword( in_id) : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "subview::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); const uword base_row_offset = aux_row1 + row_offset; const uword base_col_offset = aux_col1 + col_offset; return diagview(m, base_row_offset, base_col_offset, len); } //! creation of diagview (diagonal) template inline const diagview subview::diag(const sword in_id) const { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? -in_id : 0; const uword col_offset = (in_id > 0) ? in_id : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "subview::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); const uword base_row_offset = aux_row1 + row_offset; const uword base_col_offset = aux_col1 + col_offset; return diagview(m, base_row_offset, base_col_offset, len); } template inline void subview::swap_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 >= n_rows) || (in_row2 >= n_rows), "subview::swap_rows(): out of bounds" ); eT* mem = (const_cast< Mat& >(m)).memptr(); if(n_elem > 0) { const uword m_n_rows = m.n_rows; for(uword ucol=0; ucol < n_cols; ++ucol) { const uword offset = (aux_col1 + ucol) * m_n_rows; const uword pos1 = aux_row1 + in_row1 + offset; const uword pos2 = aux_row1 + in_row2 + offset; std::swap( access::rw(mem[pos1]), access::rw(mem[pos2]) ); } } } template inline void subview::swap_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 >= n_cols) || (in_col2 >= n_cols), "subview::swap_cols(): out of bounds" ); if(n_elem > 0) { eT* ptr1 = colptr(in_col1); eT* ptr2 = colptr(in_col2); for(uword urow=0; urow < n_rows; ++urow) { std::swap( ptr1[urow], ptr2[urow] ); } } } // template // inline // subview::iter::iter(const subview& S) // : mem (S.m.mem) // , n_rows (S.m.n_rows) // , row_start (S.aux_row1) // , row_end_p1(row_start + S.n_rows) // , row (row_start) // , col (S.aux_col1) // , i (row + col*n_rows) // { // arma_extra_debug_sigprint(); // } // // // // template // arma_inline // eT // subview::iter::operator*() const // { // return mem[i]; // } // // // // template // inline // void // subview::iter::operator++() // { // ++row; // // if(row < row_end_p1) // { // ++i; // } // else // { // row = row_start; // ++col; // // i = row + col*n_rows; // } // } // // // // template // inline // void // subview::iter::operator++(int) // { // operator++(); // } // // // template inline subview_col::subview_col(const Mat& in_m, const uword in_col) : subview(in_m, 0, in_col, in_m.n_rows, 1) , colmem(subview::colptr(0)) { arma_extra_debug_sigprint(); } template inline subview_col::subview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows) : subview(in_m, in_row1, in_col, in_n_rows, 1) , colmem(subview::colptr(0)) { arma_extra_debug_sigprint(); } template inline void subview_col::operator=(const subview& X) { arma_extra_debug_sigprint(); subview::operator=(X); } template inline void subview_col::operator=(const subview_col& X) { arma_extra_debug_sigprint(); subview::operator=(X); // interprets 'subview_col' as 'subview' } template inline void subview_col::operator=(const eT val) { arma_extra_debug_sigprint(); if(subview::n_elem != 1) { arma_debug_assert_same_size(subview::n_rows, subview::n_cols, 1, 1, "copy into submatrix"); } access::rw( colmem[0] ) = val; } template template inline void subview_col::operator=(const Base& X) { arma_extra_debug_sigprint(); subview::operator=(X); } template template inline typename enable_if2< is_same_type::value, void>::result subview_col::operator= (const Gen& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(subview::n_rows, uword(1), in.n_rows, (in.is_col ? uword(1) : in.n_cols), "copy into submatrix"); in.apply(*this); } template arma_inline const Op,op_htrans> subview_col::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> subview_col::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> subview_col::st() const { return Op,op_strans>(*this); } template inline void subview_col::fill(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_set( access::rwp(colmem), val, subview::n_rows ); } template inline void subview_col::zeros() { arma_extra_debug_sigprint(); arrayops::fill_zeros( access::rwp(colmem), subview::n_rows ); } template inline void subview_col::ones() { arma_extra_debug_sigprint(); arrayops::inplace_set( access::rwp(colmem), eT(1), subview::n_rows ); } template arma_inline eT subview_col::at_alt(const uword ii) const { const eT* colmem_aligned = colmem; memory::mark_as_aligned(colmem_aligned); return colmem_aligned[ii]; } template arma_inline eT& subview_col::operator[](const uword ii) { return access::rw( colmem[ii] ); } template arma_inline eT subview_col::operator[](const uword ii) const { return colmem[ii]; } template inline eT& subview_col::operator()(const uword ii) { arma_debug_check( (ii >= subview::n_elem), "subview::operator(): index out of bounds"); return access::rw( colmem[ii] ); } template inline eT subview_col::operator()(const uword ii) const { arma_debug_check( (ii >= subview::n_elem), "subview::operator(): index out of bounds"); return colmem[ii]; } template inline eT& subview_col::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= subview::n_rows) || (in_col > 0)), "subview::operator(): index out of bounds"); return access::rw( colmem[in_row] ); } template inline eT subview_col::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= subview::n_rows) || (in_col > 0)), "subview::operator(): index out of bounds"); return colmem[in_row]; } template inline eT& subview_col::at(const uword in_row, const uword) { return access::rw( colmem[in_row] ); } template inline eT subview_col::at(const uword in_row, const uword) const { return colmem[in_row]; } template arma_inline eT* subview_col::colptr(const uword) { return const_cast(colmem); } template arma_inline const eT* subview_col::colptr(const uword) const { return colmem; } template inline subview_col subview_col::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = this->aux_row1 + in_row1; return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); } template inline const subview_col subview_col::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = this->aux_row1 + in_row1; return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); } template inline subview_col subview_col::subvec(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = this->aux_row1 + in_row1; return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); } template inline const subview_col subview_col::subvec(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword base_row1 = this->aux_row1 + in_row1; return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); } template inline subview_col subview_col::head(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > subview::n_rows), "subview_col::head(): size out of bounds"); return subview_col(this->m, this->aux_col1, this->aux_row1, N); } template inline const subview_col subview_col::head(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > subview::n_rows), "subview_col::head(): size out of bounds"); return subview_col(this->m, this->aux_col1, this->aux_row1, N); } template inline subview_col subview_col::tail(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > subview::n_rows), "subview_col::tail(): size out of bounds"); const uword start_row = subview::aux_row1 + subview::n_rows - N; return subview_col(this->m, this->aux_col1, start_row, N); } template inline const subview_col subview_col::tail(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > subview::n_rows), "subview_col::tail(): size out of bounds"); const uword start_row = subview::aux_row1 + subview::n_rows - N; return subview_col(this->m, this->aux_col1, start_row, N); } // // // template inline subview_row::subview_row(const Mat& in_m, const uword in_row) : subview(in_m, in_row, 0, 1, in_m.n_cols) { arma_extra_debug_sigprint(); } template inline subview_row::subview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols) : subview(in_m, in_row, in_col1, 1, in_n_cols) { arma_extra_debug_sigprint(); } template inline void subview_row::operator=(const subview& X) { arma_extra_debug_sigprint(); subview::operator=(X); } template inline void subview_row::operator=(const subview_row& X) { arma_extra_debug_sigprint(); subview::operator=(X); // interprets 'subview_row' as 'subview' } template inline void subview_row::operator=(const eT val) { arma_extra_debug_sigprint(); subview::operator=(val); // interprets 'subview_row' as 'subview' } template template inline void subview_row::operator=(const Base& X) { arma_extra_debug_sigprint(); subview::operator=(X); } template template inline typename enable_if2< is_same_type::value, void>::result subview_row::operator= (const Gen& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(uword(1), subview::n_cols, (in.is_row ? uword(1) : in.n_rows), in.n_cols, "copy into submatrix"); in.apply(*this); } template arma_inline const Op,op_htrans> subview_row::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> subview_row::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> subview_row::st() const { return Op,op_strans>(*this); } template inline eT subview_row::at_alt(const uword ii) const { const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline eT& subview_row::operator[](const uword ii) { const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return access::rw( (const_cast< Mat& >(subview::m)).mem[index] ); } template inline eT subview_row::operator[](const uword ii) const { const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline eT& subview_row::operator()(const uword ii) { arma_debug_check( (ii >= subview::n_elem), "subview::operator(): index out of bounds"); const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return access::rw( (const_cast< Mat& >(subview::m)).mem[index] ); } template inline eT subview_row::operator()(const uword ii) const { arma_debug_check( (ii >= subview::n_elem), "subview::operator(): index out of bounds"); const uword index = (ii + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline eT& subview_row::operator()(const uword in_row, const uword in_col) { arma_debug_check( ((in_row > 0) || (in_col >= subview::n_cols)), "subview::operator(): index out of bounds"); const uword index = (in_col + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return access::rw( (const_cast< Mat& >(subview::m)).mem[index] ); } template inline eT subview_row::operator()(const uword in_row, const uword in_col) const { arma_debug_check( ((in_row > 0) || (in_col >= subview::n_cols)), "subview::operator(): index out of bounds"); const uword index = (in_col + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline eT& subview_row::at(const uword, const uword in_col) { const uword index = (in_col + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return access::rw( (const_cast< Mat& >(subview::m)).mem[index] ); } template inline eT subview_row::at(const uword, const uword in_col) const { const uword index = (in_col + (subview::aux_col1))*(subview::m).n_rows + (subview::aux_row1); return subview::m.mem[index]; } template inline subview_row subview_row::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = this->aux_col1 + in_col1; return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); } template inline const subview_row subview_row::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = this->aux_col1 + in_col1; return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); } template inline subview_row subview_row::subvec(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = this->aux_col1 + in_col1; return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); } template inline const subview_row subview_row::subvec(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; const uword base_col1 = this->aux_col1 + in_col1; return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); } template inline subview_row subview_row::head(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > subview::n_cols), "subview_row::head(): size out of bounds"); return subview_row(this->m, this->aux_row1, this->aux_col1, N); } template inline const subview_row subview_row::head(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > subview::n_cols), "subview_row::head(): size out of bounds"); return subview_row(this->m, this->aux_row1, this->aux_col1, N); } template inline subview_row subview_row::tail(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > subview::n_cols), "subview_row::tail(): size out of bounds"); const uword start_col = subview::aux_col1 + subview::n_cols - N; return subview_row(this->m, this->aux_row1, start_col, N); } template inline const subview_row subview_row::tail(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > subview::n_cols), "subview_row::tail(): size out of bounds"); const uword start_col = subview::aux_col1 + subview::n_cols - N; return subview_row(this->m, this->aux_row1, start_col, N); } // // // template inline subview_row_strans::subview_row_strans(const subview_row& in_sv_row) : sv_row(in_sv_row ) , n_rows(in_sv_row.n_cols) , n_elem(in_sv_row.n_elem) { arma_extra_debug_sigprint(); } template inline void subview_row_strans::extract(Mat& out) const { arma_extra_debug_sigprint(); // NOTE: this function assumes that matrix 'out' has already been set to the correct size const Mat& X = sv_row.m; eT* out_mem = out.memptr(); const uword row = sv_row.aux_row1; const uword start_col = sv_row.aux_col1; const uword sv_row_n_cols = sv_row.n_cols; uword ii,jj; for(ii=0, jj=1; jj < sv_row_n_cols; ii+=2, jj+=2) { const eT tmp1 = X.at(row, start_col+ii); const eT tmp2 = X.at(row, start_col+jj); out_mem[ii] = tmp1; out_mem[jj] = tmp2; } if(ii < sv_row_n_cols) { out_mem[ii] = X.at(row, start_col+ii); } } template inline eT subview_row_strans::at_alt(const uword ii) const { return sv_row[ii]; } template inline eT subview_row_strans::operator[](const uword ii) const { return sv_row[ii]; } template inline eT subview_row_strans::operator()(const uword ii) const { return sv_row(ii); } template inline eT subview_row_strans::operator()(const uword in_row, const uword in_col) const { return sv_row(in_col, in_row); // deliberately swapped } template inline eT subview_row_strans::at(const uword in_row, const uword) const { return sv_row.at(0, in_row); // deliberately swapped } // // // template inline subview_row_htrans::subview_row_htrans(const subview_row& in_sv_row) : sv_row(in_sv_row ) , n_rows(in_sv_row.n_cols) , n_elem(in_sv_row.n_elem) { arma_extra_debug_sigprint(); } template inline void subview_row_htrans::extract(Mat& out) const { arma_extra_debug_sigprint(); // NOTE: this function assumes that matrix 'out' has already been set to the correct size const Mat& X = sv_row.m; eT* out_mem = out.memptr(); const uword row = sv_row.aux_row1; const uword start_col = sv_row.aux_col1; const uword sv_row_n_cols = sv_row.n_cols; for(uword ii=0; ii < sv_row_n_cols; ++ii) { out_mem[ii] = access::alt_conj( X.at(row, start_col+ii) ); } } template inline eT subview_row_htrans::at_alt(const uword ii) const { return access::alt_conj( sv_row[ii] ); } template inline eT subview_row_htrans::operator[](const uword ii) const { return access::alt_conj( sv_row[ii] ); } template inline eT subview_row_htrans::operator()(const uword ii) const { return access::alt_conj( sv_row(ii) ); } template inline eT subview_row_htrans::operator()(const uword in_row, const uword in_col) const { return access::alt_conj( sv_row(in_col, in_row) ); // deliberately swapped } template inline eT subview_row_htrans::at(const uword in_row, const uword) const { return access::alt_conj( sv_row.at(0, in_row) ); // deliberately swapped } //! @} armadillo-6.500.5/include/armadillo_bits/fn_find_unique.hpp0000666000000000000000000000224512620272703022453 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_find_unique //! @{ template inline typename enable_if2 < is_arma_type::value, const mtOp >::result find_unique ( const T1& X, const bool ascending_indices = true ) { arma_extra_debug_sigprint(); return mtOp(X, ((ascending_indices) ? uword(1) : uword(0)), uword(0)); } template inline uvec find_unique ( const BaseCube& X, const bool ascending_indices = true ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.get_ref()); const Mat R( const_cast< eT* >(tmp.M.memptr()), tmp.M.n_elem, 1, false ); return find_unique(R,ascending_indices); } //! @} armadillo-6.500.5/include/armadillo_bits/glue_cov_bones.hpp0000666000000000000000000000174112620272703022453 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup glue_cov //! @{ class glue_cov { public: template inline static void direct_cov(Mat& out, const Mat& A, const Mat& B, const uword norm_type); template inline static void direct_cov(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type); template inline static void apply(Mat& out, const Glue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/subview_cube_each_bones.hpp0000666000000000000000000001001012634445270024305 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_cube_each //! @{ template class subview_cube_each_common { public: const Cube& P; inline void check_size(const Mat& A) const; protected: arma_inline subview_cube_each_common(const Cube& in_p); arma_cold inline const std::string incompat_size_string(const Mat& A) const; private: subview_cube_each_common(); }; template class subview_cube_each1 : public subview_cube_each_common { protected: arma_inline subview_cube_each1(const Cube& in_p); public: inline ~subview_cube_each1(); // deliberately returning void template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); private: friend class Cube; }; template class subview_cube_each2 : public subview_cube_each_common { protected: inline subview_cube_each2(const Cube& in_p, const Base& in_indices); public: const Base& base_indices; inline void check_indices(const Mat& indices) const; inline ~subview_cube_each2(); // deliberately returning void template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); private: friend class Cube; }; class subview_cube_each1_aux { public: template static inline Cube operator_plus(const subview_cube_each1& X, const Base& Y); template static inline Cube operator_minus(const subview_cube_each1& X, const Base& Y); template static inline Cube operator_minus(const Base& X, const subview_cube_each1& Y); template static inline Cube operator_schur(const subview_cube_each1& X, const Base& Y); template static inline Cube operator_div(const subview_cube_each1& X,const Base& Y); template static inline Cube operator_div(const Base& X, const subview_cube_each1& Y); }; class subview_cube_each2_aux { public: template static inline Cube operator_plus(const subview_cube_each2& X, const Base& Y); template static inline Cube operator_minus(const subview_cube_each2& X, const Base& Y); template static inline Cube operator_minus(const Base& X, const subview_cube_each2& Y); template static inline Cube operator_schur(const subview_cube_each2& X, const Base& Y); template static inline Cube operator_div(const subview_cube_each2& X, const Base& Y); template static inline Cube operator_div(const Base& X, const subview_cube_each2& Y); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_min_meat.hpp0000666000000000000000000004000612650172354021752 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_min //! @{ template inline void op_min::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "min(): parameter 'dim' must be 0 or 1"); const unwrap U(in.m); const Mat& X = U.M; if(&out != &X) { op_min::apply_noalias(out, X, dim); } else { Mat tmp; op_min::apply_noalias(tmp, X, dim); out.steal_mem(tmp); } } template inline void op_min::apply_noalias(Mat& out, const Mat& X, const uword dim, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_min::apply(): dim = 0"); out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col 0) ? 1 : 0); if(X_n_cols == 0) { return; } eT* out_mem = out.memptr(); arrayops::copy(out_mem, X.colptr(0), X_n_rows); for(uword col=1; col inline void op_min::apply_noalias(Mat& out, const Mat& X, const uword dim, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_min::apply(): dim = 0"); out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col 0) ? 1 : 0); if(X_n_cols == 0) { return; } eT* out_mem = out.memptr(); for(uword row=0; row inline eT op_min::direct_min(const eT* const X, const uword n_elem) { arma_extra_debug_sigprint(); eT min_val = priv::most_pos(); uword i,j; for(i=0, j=1; j inline eT op_min::direct_min(const eT* const X, const uword n_elem, uword& index_of_min_val) { arma_extra_debug_sigprint(); eT min_val = priv::most_pos(); uword best_index = 0; uword i,j; for(i=0, j=1; j inline eT op_min::direct_min(const Mat& X, const uword row) { arma_extra_debug_sigprint(); const uword X_n_cols = X.n_cols; eT min_val = priv::most_pos(); uword i,j; for(i=0, j=1; j < X_n_cols; i+=2, j+=2) { const eT tmp_i = X.at(row,i); const eT tmp_j = X.at(row,j); if(tmp_i < min_val) { min_val = tmp_i; } if(tmp_j < min_val) { min_val = tmp_j; } } if(i < X_n_cols) { const eT tmp_i = X.at(row,i); if(tmp_i < min_val) { min_val = tmp_i; } } return min_val; } template inline eT op_min::min(const subview& X) { arma_extra_debug_sigprint(); if(X.n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; eT min_val = priv::most_pos(); if(X_n_rows == 1) { const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X_n_cols; uword i,j; for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) { const eT tmp_i = A.at(start_row, i); const eT tmp_j = A.at(start_row, j); if(tmp_i < min_val) { min_val = tmp_i; } if(tmp_j < min_val) { min_val = tmp_j; } } if(i < end_col_p1) { const eT tmp_i = A.at(start_row, i); if(tmp_i < min_val) { min_val = tmp_i; } } } else { for(uword col=0; col < X_n_cols; ++col) { min_val = (std::min)(min_val, op_min::direct_min(X.colptr(col), X_n_rows)); } } return min_val; } template inline typename arma_not_cx::result op_min::min(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } eT min_val = priv::most_pos(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j inline typename arma_not_cx::result op_min::min_with_index(const Proxy& P, uword& index_of_min_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } eT best_val = priv::most_pos(); uword best_index = 0; if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); for(uword i=0; i inline std::complex op_min::direct_min(const std::complex* const X, const uword n_elem) { arma_extra_debug_sigprint(); uword index = 0; T min_val = priv::most_pos(); for(uword i=0; i inline std::complex op_min::direct_min(const std::complex* const X, const uword n_elem, uword& index_of_min_val) { arma_extra_debug_sigprint(); uword index = 0; T min_val = priv::most_pos(); for(uword i=0; i inline std::complex op_min::direct_min(const Mat< std::complex >& X, const uword row) { arma_extra_debug_sigprint(); const uword X_n_cols = X.n_cols; uword index = 0; T min_val = priv::most_pos(); for(uword col=0; col inline std::complex op_min::min(const subview< std::complex >& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(X.n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } const Mat& A = X.m; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_row_p1 = start_row + X_n_rows; const uword end_col_p1 = start_col + X_n_cols; T min_val = priv::most_pos(); uword best_row = 0; uword best_col = 0; if(X_n_rows == 1) { best_col = 0; for(uword col=start_col; col < end_col_p1; ++col) { const T tmp_val = std::abs( A.at(start_row, col) ); if(tmp_val < min_val) { min_val = tmp_val; best_col = col; } } best_row = start_row; } else { for(uword col=start_col; col < end_col_p1; ++col) for(uword row=start_row; row < end_row_p1; ++row) { const T tmp_val = std::abs( A.at(row, col) ); if(tmp_val < min_val) { min_val = tmp_val; best_row = row; best_col = col; } } } return A.at(best_row, best_col); } template inline typename arma_cx_only::result op_min::min(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } T min_val = priv::most_pos(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword index = 0; for(uword i=0; i inline typename arma_cx_only::result op_min::min_with_index(const Proxy& P, uword& index_of_min_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } T best_val = priv::most_pos(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword best_index = 0; for(uword i=0; i inline xtrans_mat::xtrans_mat(const Mat& in_X) : X (in_X ) , n_rows(in_X.n_cols) // deliberately swapped , n_cols(in_X.n_rows) , n_elem(in_X.n_elem) { arma_extra_debug_sigprint(); } template inline void xtrans_mat::extract(Mat& out) const { arma_extra_debug_sigprint(); do_conj ? op_htrans::apply_mat(out, X) : op_strans::apply_mat(out, X); } template inline eT xtrans_mat::operator[](const uword ii) const { if(Y.n_elem > 0) { return Y[ii]; } else { do_conj ? op_htrans::apply_mat(Y, X) : op_strans::apply_mat(Y, X); return Y[ii]; } } template inline eT xtrans_mat::at_alt(const uword ii) const { return (*this).operator[](ii); } template arma_inline eT xtrans_mat::at(const uword in_row, const uword in_col) const { if(do_conj) { return access::alt_conj( X.at(in_col, in_row) ); // deliberately swapped } else { return X.at(in_col, in_row); // deliberately swapped } } //! @} armadillo-6.500.5/include/armadillo_bits/op_htrans_bones.hpp0000666000000000000000000000563312620272703022651 0ustar rootroot// Copyright (C) 2008-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_htrans //! @{ //! 'hermitian transpose' operation class op_htrans { public: template arma_hot arma_inline static void apply_mat_noalias(Mat& out, const Mat& A, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply_mat_noalias(Mat& out, const Mat& A, const typename arma_cx_only::result* junk = 0); // template arma_hot arma_inline static void apply_mat_inplace(Mat& out, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply_mat_inplace(Mat& out, const typename arma_cx_only::result* junk = 0); // template arma_hot arma_inline static void apply_mat(Mat& out, const Mat& A, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply_mat(Mat& out, const Mat& A, const typename arma_cx_only::result* junk = 0); // template arma_hot inline static void apply_proxy(Mat& out, const T1& X); // template arma_hot inline static void apply(Mat& out, const Op& in, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk = 0); // template arma_hot inline static void apply(Mat& out, const Op< Op, op_htrans>& in); }; class op_htrans2 { public: template arma_hot inline static void apply_noalias(Mat& out, const Mat& A, const eT val); template arma_hot inline static void apply(Mat& out, const Mat& A, const eT val); // template arma_hot inline static void apply_proxy(Mat& out, const T1& X, const typename T1::elem_type val); // template arma_hot inline static void apply(Mat& out, const Op& in, const typename arma_not_cx::result* junk = 0); template arma_hot inline static void apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk = 0); }; //! @} armadillo-6.500.5/include/armadillo_bits/spop_misc_bones.hpp0000666000000000000000000000441112620272703022641 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spop_misc //! @{ class spop_scalar_times { public: template inline static void apply(SpMat& out, const SpOp& in); }; class spop_square { public: template inline static void apply(SpMat& out, const SpOp& in); }; class spop_sqrt { public: template inline static void apply(SpMat& out, const SpOp& in); }; class spop_abs { public: template inline static void apply(SpMat& out, const SpOp& in); }; class spop_cx_abs { public: template inline static void apply(SpMat& out, const mtSpOp& in); }; class spop_real { public: template inline static void apply(SpMat& out, const mtSpOp& in); }; class spop_imag { public: template inline static void apply(SpMat& out, const mtSpOp& in); }; class spop_conj { public: template inline static void apply(SpMat& out, const SpOp& in); }; class spop_repmat { public: template inline static void apply(SpMat& out, const SpOp& in); }; class spop_reshape { public: template inline static void apply(SpMat& out, const SpOp& in); }; class spop_resize { public: template inline static void apply(SpMat& out, const SpOp& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/gmm_misc_bones.hpp0000666000000000000000000000364512620272703022450 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup gmm_diag //! @{ namespace gmm_priv { // running_mean_scalar template class running_mean_scalar { public: inline running_mean_scalar(); inline running_mean_scalar(const running_mean_scalar& in_rms); inline const running_mean_scalar& operator=(const running_mean_scalar& in_rms); arma_hot inline void operator() (const eT X); inline void reset(); inline uword count() const; inline eT mean() const; private: arma_aligned uword counter; arma_aligned eT r_mean; }; // running_mean_vec template class running_mean_vec { public: inline running_mean_vec(); inline running_mean_vec(const running_mean_vec& in_rmv); inline const running_mean_vec& operator=(const running_mean_vec& in_rmv); arma_hot inline void operator() (const Col& X, const uword index); inline void reset(); inline uword last_index() const; inline uword count() const; inline const Col& mean() const; private: arma_aligned uword last_i; arma_aligned uword counter; arma_aligned Col r_mean; }; // distance template struct distance {}; template struct distance { arma_inline arma_hot static eT eval(const uword N, const eT* A, const eT* B, const eT*); }; template struct distance { arma_inline arma_hot static eT eval(const uword N, const eT* A, const eT* B, const eT* C); }; } //! @} armadillo-6.500.5/include/armadillo_bits/op_pinv_meat.hpp0000666000000000000000000000520712620272703022143 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas // Written by Stanislav Funiak //! \addtogroup op_pinv //! @{ template inline void op_pinv::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const bool use_divide_and_conquer = (in.aux_uword_a == 1); T tol = access::tmp_real(in.aux); arma_debug_check((tol < T(0)), "pinv(): tolerance must be >= 0"); const Proxy P(in.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if( (n_rows*n_cols) == 0 ) { out.set_size(n_cols,n_rows); return; } // economical SVD decomposition Mat U; Col< T> s; Mat V; bool status = false; if(use_divide_and_conquer) { status = (n_cols > n_rows) ? auxlib::svd_dc_econ(U, s, V, trans(P.Q)) : auxlib::svd_dc_econ(U, s, V, P.Q); } else { status = (n_cols > n_rows) ? auxlib::svd_econ(U, s, V, trans(P.Q), 'b') : auxlib::svd_econ(U, s, V, P.Q, 'b'); } if(status == false) { out.reset(); arma_bad("pinv(): svd failed"); return; } const uword s_n_elem = s.n_elem; const T* s_mem = s.memptr(); // set tolerance to default if it hasn't been specified if( (tol == T(0)) && (s_n_elem > 0) ) { tol = (std::max)(n_rows, n_cols) * s_mem[0] * std::numeric_limits::epsilon(); } uword count = 0; for(uword i = 0; i < s_n_elem; ++i) { count += (s_mem[i] >= tol) ? uword(1) : uword(0); } if(count > 0) { Col s2(count); T* s2_mem = s2.memptr(); uword count2 = 0; for(uword i=0; i < s_n_elem; ++i) { const T val = s_mem[i]; if(val >= tol) { s2_mem[count2] = T(1) / val; ++count2; } } if(n_rows >= n_cols) { out = ( (V.n_cols > count) ? V.cols(0,count-1) : V ) * diagmat(s2) * trans( (U.n_cols > count) ? U.cols(0,count-1) : U ); } else { out = ( (U.n_cols > count) ? U.cols(0,count-1) : U ) * diagmat(s2) * trans( (V.n_cols > count) ? V.cols(0,count-1) : V ); } } else { out.zeros(n_cols, n_rows); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_inv_bones.hpp0000666000000000000000000000237312624342232022143 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_inv //! @{ //! 'invert matrix' operation (general matrices) class op_inv { public: template inline static void apply(Mat& out, const Mat& A); template inline static void apply(Mat& out, const Op& in); template inline static bool apply_diagmat(Mat& out, const T1& X); }; //! 'invert matrix' operation (triangular matrices) class op_inv_tr { public: template inline static void apply(Mat& out, const Op& in); }; //! 'invert matrix' operation (symmetric positive definite matrices) class op_inv_sympd { public: template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_inv.hpp0000666000000000000000000001312212656144025020741 0ustar rootroot// Copyright (C) 2008-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_inv //! @{ template arma_inline typename enable_if2< is_supported_blas_type::value, const Op >::result inv ( const Base& X ) { arma_extra_debug_sigprint(); return Op(X.get_ref()); } template arma_inline typename enable_if2< is_supported_blas_type::value, const Op >::result inv ( const Base& X, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return Op(X.get_ref()); } template arma_inline typename enable_if2< is_supported_blas_type::value, const Op >::result inv ( const Base& X, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return Op(X.get_ref()); } template arma_inline typename enable_if2< is_supported_blas_type::value, const Op >::result inv ( const Op& X ) { arma_extra_debug_sigprint(); return Op(X.m, X.aux_uword_a, 0); } template arma_inline typename enable_if2< is_supported_blas_type::value, const Op >::result inv ( const Op& X, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return Op(X.m, X.aux_uword_a, 0); } template arma_inline typename enable_if2< is_supported_blas_type::value, const Op >::result inv ( const Op& X, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return Op(X.m, X.aux_uword_a, 0); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result inv ( Mat& out, const Base& X ) { arma_extra_debug_sigprint(); try { out = inv(X); } catch(std::runtime_error&) { return false; } return true; } template inline typename enable_if2< is_supported_blas_type::value, bool >::result inv ( Mat& out, const Base& X, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return inv(out,X); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result inv ( Mat& out, const Base& X, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return inv(out,X); } template arma_inline typename enable_if2< is_supported_blas_type::value, const Op >::result inv_sympd ( const Base& X ) { arma_extra_debug_sigprint(); return Op(X.get_ref()); } template arma_inline typename enable_if2< is_supported_blas_type::value, const Op >::result inv_sympd ( const Base& X, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return Op(X.get_ref()); } template arma_inline typename enable_if2< is_supported_blas_type::value, const Op >::result inv_sympd ( const Base& X, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return Op(X.get_ref()); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result inv_sympd ( Mat& out, const Base& X ) { arma_extra_debug_sigprint(); try { out = inv_sympd(X); } catch(std::runtime_error&) { return false; } return true; } template inline typename enable_if2< is_supported_blas_type::value, bool >::result inv_sympd ( Mat& out, const Base& X, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return inv_sympd(out,X); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result inv_sympd ( Mat& out, const Base& X, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return inv_sympd(out,X); } //! @} armadillo-6.500.5/include/armadillo_bits/op_flip_bones.hpp0000666000000000000000000000136012620272703022275 0ustar rootroot// Copyright (C) 2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_flip //! @{ class op_flipud { public: template inline static void apply(Mat& out, const Op& in); }; class op_fliplr { public: template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/glue_toeplitz_bones.hpp0000666000000000000000000000117012620272703023532 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_toeplitz //! @{ class glue_toeplitz { public: template inline static void apply(Mat& out, const Glue& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_hist_meat.hpp0000666000000000000000000000454112620272703022136 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_hist //! @{ template inline void op_hist::apply_noalias(Mat& out, const Mat& A, const uword n_bins, const bool A_is_row) { arma_extra_debug_sigprint(); arma_debug_check( ((A.is_vec() == false) && (A.is_empty() == false)), "hist(): only vectors are supported when automatically determining bin centers" ); if(n_bins == 0) { out.reset(); return; } uword A_n_elem = A.n_elem; const eT* A_mem = A.memptr(); eT min_val = priv::most_pos(); eT max_val = priv::most_neg(); uword i,j; for(i=0, j=1; j < A_n_elem; i+=2, j+=2) { const eT val_i = A_mem[i]; const eT val_j = A_mem[j]; if(min_val > val_i) { min_val = val_i; } if(min_val > val_j) { min_val = val_j; } if(max_val < val_i) { max_val = val_i; } if(max_val < val_j) { max_val = val_j; } } if(i < A_n_elem) { const eT val_i = A_mem[i]; if(min_val > val_i) { min_val = val_i; } if(max_val < val_i) { max_val = val_i; } } if(arma_isfinite(min_val) == false) { min_val = priv::most_neg(); } if(arma_isfinite(max_val) == false) { max_val = priv::most_pos(); } Col c(n_bins); eT* c_mem = c.memptr(); for(uword ii=0; ii < n_bins; ++ii) { c_mem[ii] = (0.5 + ii) / double(n_bins); // TODO: may need to be modified for integer matrices } c = ((max_val - min_val) * c) + min_val; const uword dim = (A_is_row) ? 1 : 0; glue_hist::apply_noalias(out, A, c, dim); } template inline void op_hist::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); const uword n_bins = X.aux_uword_a; const quasi_unwrap U(X.m); if(U.is_alias(out)) { Mat tmp; op_hist::apply_noalias(tmp, U.M, n_bins, (T1::is_row)); out.steal_mem(tmp); } else { op_hist::apply_noalias(out, U.M, n_bins, (T1::is_row)); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_unique_meat.hpp0000666000000000000000000000564312620272703022501 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Arnold Wiliem //! \addtogroup op_unique //! @{ template inline bool op_unique::apply_helper(Mat& out, const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { out.set_size(n_rows, n_cols); return true; } if(n_elem == 1) { const eT tmp = Proxy::prefer_at_accessor ? P.at(0,0) : P[0]; out.set_size(n_rows, n_cols); out[0] = tmp; return true; } Mat X(n_elem,1); eT* X_mem = X.memptr(); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i comparator; std::sort( X.begin(), X.end(), comparator ); uword N_unique = 1; for(uword i=1; i < n_elem; ++i) { const eT a = X_mem[i-1]; const eT b = X_mem[i ]; const eT diff = a - b; if(diff != eT(0)) { ++N_unique; } } uword out_n_rows; uword out_n_cols; if( (n_rows == 1) || (n_cols == 1) ) { if(n_rows == 1) { out_n_rows = 1; out_n_cols = N_unique; } else { out_n_rows = N_unique; out_n_cols = 1; } } else { out_n_rows = N_unique; out_n_cols = 1; } out.set_size(out_n_rows, out_n_cols); eT* out_mem = out.memptr(); if(n_elem > 0) { (*out_mem) = X_mem[0]; out_mem++; } for(uword i=1; i < n_elem; ++i) { const eT a = X_mem[i-1]; const eT b = X_mem[i ]; const eT diff = a - b; if(diff != eT(0)) { (*out_mem) = b; out_mem++; } } return true; } template inline void op_unique::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); const bool all_non_nan = op_unique::apply_helper(out, P); arma_debug_check( (all_non_nan == false), "unique(): detected NaN" ); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_reshape.hpp0000666000000000000000000000524112620272703021573 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_reshape //! @{ template inline typename enable_if2< is_arma_type::value, const Op >::result reshape(const T1& X, const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); return Op(X, in_n_rows, in_n_cols); } template inline typename enable_if2< is_arma_type::value, const Op >::result reshape(const T1& X, const SizeMat& s) { arma_extra_debug_sigprint(); return Op(X, s.n_rows, s.n_cols); } //! NOTE: this form is deprecated: don't use it template arma_deprecated inline const Op reshape(const Base& X, const uword in_n_rows, const uword in_n_cols, const uword dim) { arma_extra_debug_sigprint(); arma_debug_check( (dim > 1), "reshape(): parameter 'dim' must be 0 or 1" ); return Op(X.get_ref(), in_n_rows, in_n_cols, dim, 'j'); } template inline const OpCube reshape(const BaseCube& X, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices, const uword dim = 0) { arma_extra_debug_sigprint(); arma_debug_check( (dim > 1), "reshape(): parameter 'dim' must be 0 or 1" ); return OpCube(X.get_ref(), in_n_rows, in_n_cols, in_n_slices, dim, 'j'); } template inline const OpCube reshape(const BaseCube& X, const SizeCube& s, const uword dim = 0) { arma_extra_debug_sigprint(); arma_debug_check( (dim > 1), "reshape(): parameter 'dim' must be 0 or 1" ); return OpCube(X.get_ref(), s.n_rows, s.n_cols, s.n_slices, dim, 'j'); } template inline const SpOp reshape(const SpBase& X, const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); return SpOp(X.get_ref(), in_n_rows, in_n_cols); } template inline const SpOp reshape(const SpBase& X, const SizeMat& s) { arma_extra_debug_sigprint(); return SpOp(X.get_ref(), s.n_rows, s.n_cols); } //! @} armadillo-6.500.5/include/armadillo_bits/glue_solve_meat.hpp0000666000000000000000000001334312627532323022641 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_solve //! @{ // // glue_solve_gen template inline void glue_solve_gen::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); const bool status = glue_solve_gen::apply( out, X.A, X.B, X.aux_uword ); if(status == false) { arma_bad("solve(): solution not found"); } } template inline bool glue_solve_gen::apply(Mat& out, const Base& A_expr, const Base& B_expr, const uword flags) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const bool fast = bool(flags & solve_opts::flag_fast ); const bool equilibrate = bool(flags & solve_opts::flag_equilibrate); const bool no_approx = bool(flags & solve_opts::flag_no_approx ); arma_extra_debug_print("glue_solve_gen::apply(): enabled flags:"); if(fast ) { arma_extra_debug_print("fast"); } if(equilibrate) { arma_extra_debug_print("equilibrate"); } if(no_approx ) { arma_extra_debug_print("no_approx"); } T rcond = T(0); bool status = false; Mat A = A_expr.get_ref(); if(A.n_rows == A.n_cols) { arma_extra_debug_print("glue_solve_gen::apply(): detected square system"); if(fast) { arma_extra_debug_print("glue_solve_gen::apply(): (fast)"); if(equilibrate) { arma_debug_warn("solve(): option 'equilibrate' ignored, as option 'fast' is enabled"); } status = auxlib::solve_square_fast(out, A, B_expr.get_ref()); // A is overwritten } else { arma_extra_debug_print("glue_solve_gen::apply(): (refine)"); status = auxlib::solve_square_refine(out, rcond, A, B_expr, equilibrate); // A is overwritten } if( (status == false) && (no_approx == false) ) { arma_extra_debug_print("glue_solve_gen::apply(): solving rank deficient system"); if(rcond > T(0)) { arma_debug_warn("solve(): system appears singular (rcond: ", rcond, "); attempting approximate solution"); } else { arma_debug_warn("solve(): system appears singular; attempting approximate solution"); } Mat AA = A_expr.get_ref(); status = auxlib::solve_approx_svd(out, AA, B_expr.get_ref()); // AA is overwritten } } else { arma_extra_debug_print("glue_solve_gen::apply(): detected non-square system"); if(equilibrate) { arma_debug_warn( "solve(): option 'equilibrate' ignored for non-square matrix" ); } if(fast) { status = auxlib::solve_approx_fast(out, A, B_expr.get_ref()); // A is overwritten if(status == false) { Mat AA = A_expr.get_ref(); status = auxlib::solve_approx_svd(out, AA, B_expr.get_ref()); // AA is overwritten } } else { status = auxlib::solve_approx_svd(out, A, B_expr.get_ref()); // A is overwritten } } if(status == false) { out.reset(); } return status; } // // glue_solve_tri template inline void glue_solve_tri::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); const bool status = glue_solve_tri::apply( out, X.A, X.B, X.aux_uword ); if(status == false) { arma_bad("solve(): solution not found"); } } template inline bool glue_solve_tri::apply(Mat& out, const Base& A_expr, const Base& B_expr, const uword flags) { arma_extra_debug_sigprint(); const bool fast = bool(flags & solve_opts::flag_fast ); const bool equilibrate = bool(flags & solve_opts::flag_equilibrate); const bool no_approx = bool(flags & solve_opts::flag_no_approx ); const bool triu = bool(flags & solve_opts::flag_triu ); const bool tril = bool(flags & solve_opts::flag_tril ); arma_extra_debug_print("glue_solve_tri::apply(): enabled flags:"); if(fast ) { arma_extra_debug_print("fast"); } if(equilibrate) { arma_extra_debug_print("equilibrate"); } if(no_approx ) { arma_extra_debug_print("no_approx"); } if(triu ) { arma_extra_debug_print("triu"); } if(tril ) { arma_extra_debug_print("tril"); } bool status = false; if(equilibrate) { arma_debug_warn("solve(): option 'equilibrate' ignored for triangular matrices"); } const unwrap_check U(A_expr.get_ref(), out); const Mat& A = U.M; arma_debug_check( (A.is_square() == false), "solve(): matrix marked as triangular must be square sized" ); const uword layout = (triu) ? uword(0) : uword(1); status = auxlib::solve_tri(out, A, B_expr.get_ref(), layout); // A is not modified if( (status == false) && (no_approx == false) ) { arma_extra_debug_print("glue_solve_tri::apply(): solving rank deficient system"); arma_debug_warn("solve(): system appears singular; attempting approximate solution"); Mat triA = (triu) ? trimatu( A_expr.get_ref() ) : trimatl( A_expr.get_ref() ); status = auxlib::solve_approx_svd(out, triA, B_expr.get_ref()); // triA is overwritten } if(status == false) { out.reset(); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/eOp_bones.hpp0000666000000000000000000000403712620272703021374 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eOp //! @{ template class eOp : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Proxy proxy_type; static const bool prefer_at_accessor = Proxy::prefer_at_accessor; static const bool has_subview = Proxy::has_subview; static const bool fake_mat = Proxy::fake_mat; static const bool is_row = Proxy::is_row; static const bool is_col = Proxy::is_col; arma_aligned const Proxy P; arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format inline ~eOp(); inline explicit eOp(const T1& in_m); inline eOp(const T1& in_m, const elem_type in_aux); inline eOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline eOp(const T1& in_m, const elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b); arma_inline uword get_n_rows() const; arma_inline uword get_n_cols() const; arma_inline uword get_n_elem() const; arma_inline elem_type operator[] (const uword ii) const; arma_inline elem_type at (const uword row, const uword col) const; arma_inline elem_type at_alt (const uword ii) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_speye.hpp0000666000000000000000000000330312620272703021266 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup fn_speye //! @{ //! Generate a sparse matrix with the values along the main diagonal set to one template inline obj_type speye(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only::result* junk = NULL) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_SpCol::value == true) { arma_debug_check( (n_cols != 1), "speye(): incompatible size" ); } else if(is_SpRow::value == true) { arma_debug_check( (n_rows != 1), "speye(): incompatible size" ); } obj_type out; out.eye(n_rows, n_cols); return out; } template inline obj_type speye(const SizeMat& s, const typename arma_SpMat_SpCol_SpRow_only::result* junk = NULL) { arma_extra_debug_sigprint(); arma_ignore(junk); return speye(s.n_rows, s.n_cols); } // Convenience shortcut method (no template parameter necessary) inline sp_mat speye(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); sp_mat out; out.eye(n_rows, n_cols); return out; } inline sp_mat speye(const SizeMat& s) { arma_extra_debug_sigprint(); sp_mat out; out.eye(s.n_rows, s.n_cols); return out; } //! @} armadillo-6.500.5/include/armadillo_bits/mtSpOp_bones.hpp0000666000000000000000000000237612620272703022077 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup mtSpOp //! @{ // Class for delayed multi-type sparse operations. These are operations where // the resulting type is different than the stored type. template class mtSpOp : public SpBase > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef typename T1::elem_type in_eT; static const bool is_row = false; static const bool is_col = false; inline explicit mtSpOp(const T1& in_m); inline mtSpOp(const T1& in_m, const uword aux_uword_a, const uword aux_uword_b); inline ~mtSpOp(); arma_aligned const T1& m; arma_aligned uword aux_uword_a; arma_aligned uword aux_uword_b; }; //! @} armadillo-6.500.5/include/armadillo_bits/SpCol_bones.hpp0000666000000000000000000000455412620272703021675 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin // Written by Matthew Amidon //! \addtogroup SpCol //! @{ //! Class for sparse column vectors (matrices with only one column) template class SpCol : public SpMat { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; inline SpCol(); inline explicit SpCol(const uword n_elem); inline SpCol(const uword in_rows, const uword in_cols); inline SpCol(const char* text); inline const SpCol& operator=(const char* text); inline SpCol(const std::string& text); inline const SpCol& operator=(const std::string& text); inline const SpCol& operator=(const eT val); template inline SpCol(const Base& X); template inline const SpCol& operator=(const Base& X); template inline SpCol(const SpBase& X); template inline const SpCol& operator=(const SpBase& X); template inline explicit SpCol(const SpBase& A, const SpBase& B); inline void shed_row (const uword row_num); inline void shed_rows(const uword in_row1, const uword in_row2); // inline void insert_rows(const uword row_num, const uword N, const bool set_to_zero = true); typedef typename SpMat::iterator row_iterator; typedef typename SpMat::const_iterator const_row_iterator; inline row_iterator begin_row(const uword row_num = 0); inline const_row_iterator begin_row(const uword row_num = 0) const; inline row_iterator end_row (const uword row_num = 0); inline const_row_iterator end_row (const uword row_num = 0) const; #ifdef ARMA_EXTRA_SPCOL_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPCOL_PROTO) #endif }; armadillo-6.500.5/include/armadillo_bits/glue_min_meat.hpp0000666000000000000000000000613212620272703022266 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_min //! @{ template inline void glue_min::apply(Mat& out, const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); const uword n_rows = PA.get_n_rows(); const uword n_cols = PA.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, PB.get_n_rows(), PB.get_n_cols(), "min(): given matrices must have the same size"); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const uword N = PA.get_n_elem(); for(uword i=0; i inline void glue_min::apply(Mat< std::complex >& out, const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const uword n_rows = PA.get_n_rows(); const uword n_cols = PA.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, PB.get_n_rows(), PB.get_n_cols(), "min(): given matrices must have the same size"); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const uword N = PA.get_n_elem(); for(uword i=0; i inline void glue_min::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy PA(X.A); const Proxy PB(X.B); if(PA.is_alias(out) || PB.is_alias(out)) { Mat tmp; glue_min::apply(tmp, PA, PB); out.steal_mem(tmp); } else { glue_min::apply(out, PA, PB); } } //! @} armadillo-6.500.5/include/armadillo_bits/wrapper_atlas.hpp0000666000000000000000000002421012620272703022322 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au #ifdef ARMA_USE_ATLAS //! \namespace atlas namespace for ATLAS functions (imported from the global namespace) namespace atlas { template inline static const eT& tmp_real(const eT& X) { return X; } template inline static const T tmp_real(const std::complex& X) { return X.real(); } template arma_inline eT cblas_asum(const int N, const eT* X) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; return eT( arma_wrapper(cblas_sasum)(N, (const T*)X, 1) ); } else if(is_double::value) { typedef double T; return eT( arma_wrapper(cblas_dasum)(N, (const T*)X, 1) ); } else { return eT(0); } } template arma_inline eT cblas_nrm2(const int N, const eT* X) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; return eT( arma_wrapper(cblas_snrm2)(N, (const T*)X, 1) ); } else if(is_double::value) { typedef double T; return eT( arma_wrapper(cblas_dnrm2)(N, (const T*)X, 1) ); } else { return eT(0); } } template arma_inline eT cblas_dot(const int N, const eT* X, const eT* Y) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; return eT( arma_wrapper(cblas_sdot)(N, (const T*)X, 1, (const T*)Y, 1) ); } else if(is_double::value) { typedef double T; return eT( arma_wrapper(cblas_ddot)(N, (const T*)X, 1, (const T*)Y, 1) ); } else { return eT(0); } } template arma_inline eT cblas_cx_dot(const int N, const eT* X, const eT* Y) { arma_type_check((is_supported_blas_type::value == false)); if(is_supported_complex_float::value) { typedef typename std::complex T; T out; arma_wrapper(cblas_cdotu_sub)(N, (const T*)X, 1, (const T*)Y, 1, &out); return eT(out); } else if(is_supported_complex_double::value) { typedef typename std::complex T; T out; arma_wrapper(cblas_zdotu_sub)(N, (const T*)X, 1, (const T*)Y, 1, &out); return eT(out); } else { return eT(0); } } template inline void cblas_gemv ( const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const eT alpha, const eT *A, const int lda, const eT *X, const int incX, const eT beta, eT *Y, const int incY ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; arma_wrapper(cblas_sgemv)(Order, TransA, M, N, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)X, incX, (const T)tmp_real(beta), (T*)Y, incY); } else if(is_double::value) { typedef double T; arma_wrapper(cblas_dgemv)(Order, TransA, M, N, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)X, incX, (const T)tmp_real(beta), (T*)Y, incY); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_wrapper(cblas_cgemv)(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_wrapper(cblas_zgemv)(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY); } } template inline void cblas_gemm ( const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const eT alpha, const eT *A, const int lda, const eT *B, const int ldb, const eT beta, eT *C, const int ldc ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; arma_wrapper(cblas_sgemm)(Order, TransA, TransB, M, N, K, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)B, ldb, (const T)tmp_real(beta), (T*)C, ldc); } else if(is_double::value) { typedef double T; arma_wrapper(cblas_dgemm)(Order, TransA, TransB, M, N, K, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)B, ldb, (const T)tmp_real(beta), (T*)C, ldc); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_wrapper(cblas_cgemm)(Order, TransA, TransB, M, N, K, (const T*)&alpha, (const T*)A, lda, (const T*)B, ldb, (const T*)&beta, (T*)C, ldc); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_wrapper(cblas_zgemm)(Order, TransA, TransB, M, N, K, (const T*)&alpha, (const T*)A, lda, (const T*)B, ldb, (const T*)&beta, (T*)C, ldc); } } template inline void cblas_syrk ( const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const eT alpha, const eT* A, const int lda, const eT beta, eT* C, const int ldc ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; arma_wrapper(cblas_ssyrk)(Order, Uplo, Trans, N, K, (const T)alpha, (const T*)A, lda, (const T)beta, (T*)C, ldc); } else if(is_double::value) { typedef double T; arma_wrapper(cblas_dsyrk)(Order, Uplo, Trans, N, K, (const T)alpha, (const T*)A, lda, (const T)beta, (T*)C, ldc); } } template inline void cblas_herk ( const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const T alpha, const std::complex* A, const int lda, const T beta, std::complex* C, const int ldc ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float TT; typedef std::complex cx_TT; arma_wrapper(cblas_cherk)(Order, Uplo, Trans, N, K, (const TT)alpha, (const cx_TT*)A, lda, (const TT)beta, (cx_TT*)C, ldc); } else if(is_double::value) { typedef double TT; typedef std::complex cx_TT; arma_wrapper(cblas_zherk)(Order, Uplo, Trans, N, K, (const TT)alpha, (const cx_TT*)A, lda, (const TT)beta, (cx_TT*)C, ldc); } } template inline int clapack_getrf ( const enum CBLAS_ORDER Order, const int M, const int N, eT *A, const int lda, int *ipiv ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; return arma_wrapper(clapack_sgetrf)(Order, M, N, (T*)A, lda, ipiv); } else if(is_double::value) { typedef double T; return arma_wrapper(clapack_dgetrf)(Order, M, N, (T*)A, lda, ipiv); } else if(is_supported_complex_float::value) { typedef std::complex T; return arma_wrapper(clapack_cgetrf)(Order, M, N, (T*)A, lda, ipiv); } else if(is_supported_complex_double::value) { typedef std::complex T; return arma_wrapper(clapack_zgetrf)(Order, M, N, (T*)A, lda, ipiv); } else { return -1; } } template inline int clapack_getri ( const enum CBLAS_ORDER Order, const int N, eT *A, const int lda, const int *ipiv ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; return arma_wrapper(clapack_sgetri)(Order, N, (T*)A, lda, ipiv); } else if(is_double::value) { typedef double T; return arma_wrapper(clapack_dgetri)(Order, N, (T*)A, lda, ipiv); } else if(is_supported_complex_float::value) { typedef std::complex T; return arma_wrapper(clapack_cgetri)(Order, N, (T*)A, lda, ipiv); } else if(is_supported_complex_double::value) { typedef std::complex T; return arma_wrapper(clapack_zgetri)(Order, N, (T*)A, lda, ipiv); } else { return -1; } } template inline int clapack_gesv ( const enum CBLAS_ORDER Order, const int N, const int NRHS, eT* A, const int lda, int* ipiv, eT* B, const int ldb ) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; return arma_wrapper(clapack_sgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb); } else if(is_double::value) { typedef double T; return arma_wrapper(clapack_dgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb); } else if(is_supported_complex_float::value) { typedef std::complex T; return arma_wrapper(clapack_cgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb); } else if(is_supported_complex_double::value) { typedef std::complex T; return arma_wrapper(clapack_zgesv)(Order, N, NRHS, (T*)A, lda, ipiv, (T*)B, ldb); } else { return -1; } } } #endif armadillo-6.500.5/include/armadillo_bits/fft_engine.hpp0000666000000000000000000002477412625473530021607 0ustar rootroot// This Source Code Form is a compilation of: // (1) source code written by Conrad Sanderson, and // (2) a modified form of source code referred to as "kissfft.hh". // // This compilation is Copyright (C) 2013 National ICT Australia (NICTA) // and is subject to the terms of the Mozilla Public License, v. 2.0. // // The source code that is distinct and separate from "kissfft.hh" // is Copyright (C) 2013 National ICT Australia (NICTA) // and is subject to the terms of the Mozilla Public License, v. 2.0. // // If a copy of the MPL was not distributed with this file, // You can obtain one at http://mozilla.org/MPL/2.0/. // // The original "kissfft.hh" source code is licensed under a 3-clause BSD license, // as follows: // // Copyright (c) 2003-2010 Mark Borgerding // // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * Neither the author nor the names of any contributors may be used to endorse or promote // products derived from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //! \addtogroup fft_engine //! @{ template struct store {}; template struct store { static const uword N = fixed_N; arma_aligned cx_type coeffs_array[fixed_N]; inline store() {} inline store(uword) {} arma_inline cx_type* coeffs_ptr() { return &coeffs_array[0]; } arma_inline const cx_type* coeffs_ptr() const { return &coeffs_array[0]; } }; template struct store { const uword N; podarray coeffs_array; inline store() : N(0) {} inline store(uword in_N) : N(in_N) { coeffs_array.set_size(N); } arma_inline cx_type* coeffs_ptr() { return coeffs_array.memptr(); } arma_inline const cx_type* coeffs_ptr() const { return coeffs_array.memptr(); } }; template class fft_engine : public store 0)> { public: typedef typename get_pod_type::result T; using store 0)>::N; using store 0)>::coeffs_ptr; podarray residue; podarray radix; podarray tmp_array; template inline uword calc_radix() { uword i = 0; for(uword n = N, r=4; n >= 2; ++i) { while( (n % r) > 0 ) { switch(r) { case 2: r = 3; break; case 4: r = 2; break; default: r += 2; break; } if(r*r > n) { r = n; } } n /= r; if(fill) { residue[i] = n; radix[i] = r; } } return i; } inline fft_engine(const uword in_N) : store< cx_type, fixed_N, (fixed_N > 0) >(in_N) { arma_extra_debug_sigprint(); const uword len = calc_radix(); residue.set_size(len); radix.set_size(len); calc_radix(); // calculate the constant coefficients cx_type* coeffs = coeffs_ptr(); const T k = T( (inverse) ? +2 : -2 ) * std::acos( T(-1) ) / T(N); for(uword i=0; i < N; ++i) { coeffs[i] = std::exp( cx_type(T(0), i*k) ); } } arma_hot inline void butterfly_2(cx_type* Y, const uword stride, const uword m) { arma_extra_debug_sigprint(); const cx_type* coeffs = coeffs_ptr(); for(uword i=0; i < m; ++i) { const cx_type t = Y[i+m] * coeffs[i*stride]; Y[i+m] = Y[i] - t; Y[i ] += t; } } arma_hot inline void butterfly_3(cx_type* Y, const uword stride, const uword m) { arma_extra_debug_sigprint(); arma_aligned cx_type tmp[5]; cx_type* coeffs1 = coeffs_ptr(); cx_type* coeffs2 = coeffs1; const T coeff_sm_imag = coeffs1[stride*m].imag(); const uword n = m*2; // TODO: rearrange the indices within tmp[] into a more sane order for(uword i = m; i > 0; --i) { tmp[1] = Y[m] * (*coeffs1); tmp[2] = Y[n] * (*coeffs2); tmp[0] = tmp[1] - tmp[2]; tmp[0] *= coeff_sm_imag; tmp[3] = tmp[1] + tmp[2]; Y[m] = cx_type( (Y[0].real() - (T(0.5)*tmp[3].real())), (Y[0].imag() - (T(0.5)*tmp[3].imag())) ); Y[0] += tmp[3]; Y[n] = cx_type( (Y[m].real() + tmp[0].imag()), (Y[m].imag() - tmp[0].real()) ); Y[m] += cx_type( -tmp[0].imag(), tmp[0].real() ); Y++; coeffs1 += stride; coeffs2 += stride*2; } } arma_hot inline void butterfly_4(cx_type* Y, const uword stride, const uword m) { arma_extra_debug_sigprint(); arma_aligned cx_type tmp[7]; const cx_type* coeffs = coeffs_ptr(); const uword m2 = m*2; const uword m3 = m*3; // TODO: rearrange the indices within tmp[] into a more sane order for(uword i=0; i < m; ++i) { tmp[0] = Y[i + m ] * coeffs[i*stride ]; tmp[2] = Y[i + m3] * coeffs[i*stride*3]; tmp[3] = tmp[0] + tmp[2]; //tmp[4] = tmp[0] - tmp[2]; //tmp[4] = (inverse) ? cx_type( -(tmp[4].imag()), tmp[4].real() ) : cx_type( tmp[4].imag(), -tmp[4].real() ); tmp[4] = (inverse) ? cx_type( (tmp[2].imag() - tmp[0].imag()), (tmp[0].real() - tmp[2].real()) ) : cx_type( (tmp[0].imag() - tmp[2].imag()), (tmp[2].real() - tmp[0].real()) ); tmp[1] = Y[i + m2] * coeffs[i*stride*2]; tmp[5] = Y[i] - tmp[1]; Y[i ] += tmp[1]; Y[i + m2] = Y[i] - tmp[3]; Y[i ] += tmp[3]; Y[i + m ] = tmp[5] + tmp[4]; Y[i + m3] = tmp[5] - tmp[4]; } } inline arma_hot void butterfly_5(cx_type* Y, const uword stride, const uword m) { arma_extra_debug_sigprint(); arma_aligned cx_type tmp[13]; const cx_type* coeffs = coeffs_ptr(); const T a_real = coeffs[stride*1*m].real(); const T a_imag = coeffs[stride*1*m].imag(); const T b_real = coeffs[stride*2*m].real(); const T b_imag = coeffs[stride*2*m].imag(); cx_type* Y0 = Y; cx_type* Y1 = Y + 1*m; cx_type* Y2 = Y + 2*m; cx_type* Y3 = Y + 3*m; cx_type* Y4 = Y + 4*m; for(uword i=0; i < m; ++i) { tmp[0] = (*Y0); tmp[1] = (*Y1) * coeffs[stride*1*i]; tmp[2] = (*Y2) * coeffs[stride*2*i]; tmp[3] = (*Y3) * coeffs[stride*3*i]; tmp[4] = (*Y4) * coeffs[stride*4*i]; tmp[7] = tmp[1] + tmp[4]; tmp[8] = tmp[2] + tmp[3]; tmp[9] = tmp[2] - tmp[3]; tmp[10] = tmp[1] - tmp[4]; (*Y0) += tmp[7]; (*Y0) += tmp[8]; tmp[5] = tmp[0] + cx_type( ( (tmp[7].real() * a_real) + (tmp[8].real() * b_real) ), ( (tmp[7].imag() * a_real) + (tmp[8].imag() * b_real) ) ); tmp[6] = cx_type( ( (tmp[10].imag() * a_imag) + (tmp[9].imag() * b_imag) ), ( -(tmp[10].real() * a_imag) - (tmp[9].real() * b_imag) ) ); (*Y1) = tmp[5] - tmp[6]; (*Y4) = tmp[5] + tmp[6]; tmp[11] = tmp[0] + cx_type( ( (tmp[7].real() * b_real) + (tmp[8].real() * a_real) ), ( (tmp[7].imag() * b_real) + (tmp[8].imag() * a_real) ) ); tmp[12] = cx_type( ( -(tmp[10].imag() * b_imag) + (tmp[9].imag() * a_imag) ), ( (tmp[10].real() * b_imag) - (tmp[9].real() * a_imag) ) ); (*Y2) = tmp[11] + tmp[12]; (*Y3) = tmp[11] - tmp[12]; Y0++; Y1++; Y2++; Y3++; Y4++; } } arma_hot inline void butterfly_N(cx_type* Y, const uword stride, const uword m, const uword r) { arma_extra_debug_sigprint(); const cx_type* coeffs = coeffs_ptr(); tmp_array.set_min_size(r); cx_type* tmp = tmp_array.memptr(); for(uword u=0; u < m; ++u) { uword k = u; for(uword v=0; v < r; ++v) { tmp[v] = Y[k]; k += m; } k = u; for(uword v=0; v < r; ++v) { Y[k] = tmp[0]; uword j = 0; for(uword w=1; w < r; ++w) { j += stride * k; if(j >= N) { j -= N; } Y[k] += tmp[w] * coeffs[j]; } k += m; } } } inline void run(cx_type* Y, const cx_type* X, const uword stage = 0, const uword stride = 1) { arma_extra_debug_sigprint(); const uword m = residue[stage]; const uword r = radix[stage]; const cx_type *Y_end = Y + r*m; if(m == 1) { for(cx_type* Yi = Y; Yi != Y_end; Yi++, X += stride) { (*Yi) = (*X); } } else { const uword next_stage = stage + 1; const uword next_stride = stride * r; for(cx_type* Yi = Y; Yi != Y_end; Yi += m, X += stride) { run(Yi, X, next_stage, next_stride); } } switch(r) { case 2: butterfly_2(Y, stride, m ); break; case 3: butterfly_3(Y, stride, m ); break; case 4: butterfly_4(Y, stride, m ); break; case 5: butterfly_5(Y, stride, m ); break; default: butterfly_N(Y, stride, m, r); break; } } }; //! @} armadillo-6.500.5/include/armadillo_bits/op_fft_bones.hpp0000666000000000000000000000302212620272703022117 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_fft //! @{ class op_fft_real { public: template inline static void apply( Mat< std::complex >& out, const mtOp,T1,op_fft_real>& in ); }; class op_fft_cx { public: template inline static void apply( Mat& out, const Op& in ); template inline static void apply_noalias(Mat& out, const Proxy& P, const uword a, const uword b); template arma_hot inline static void copy_vec (typename Proxy::elem_type* dest, const Proxy& P, const uword N); template arma_hot inline static void copy_vec_proxy (typename Proxy::elem_type* dest, const Proxy& P, const uword N); template arma_hot inline static void copy_vec_unwrap(typename Proxy::elem_type* dest, const Proxy& P, const uword N); }; class op_ifft_cx { public: template inline static void apply( Mat& out, const Op& in ); }; //! @} armadillo-6.500.5/include/armadillo_bits/Col_bones.hpp0000666000000000000000000002201312620272703021360 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Col //! @{ //! Class for column vectors (matrices with only one column) template class Col : public Mat { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = true; static const bool is_row = false; inline Col(); inline Col(const Col& X); inline explicit Col(const uword n_elem); inline explicit Col(const uword in_rows, const uword in_cols); inline explicit Col(const SizeMat& s); template inline Col(const uword n_elem, const fill::fill_class& f); template inline Col(const uword in_rows, const uword in_cols, const fill::fill_class& f); template inline Col(const SizeMat& s, const fill::fill_class& f); inline Col(const char* text); inline const Col& operator=(const char* text); inline Col(const std::string& text); inline const Col& operator=(const std::string& text); inline Col(const std::vector& x); inline const Col& operator=(const std::vector& x); #if defined(ARMA_USE_CXX11) inline Col(const std::initializer_list& list); inline const Col& operator=(const std::initializer_list& list); inline Col(Col&& m); inline const Col& operator=(Col&& m); #endif inline explicit Col(const SpCol& X); inline const Col& operator=(const eT val); inline const Col& operator=(const Col& m); template inline Col(const Base& X); template inline const Col& operator=(const Base& X); inline Col( eT* aux_mem, const uword aux_length, const bool copy_aux_mem = true, const bool strict = false); inline Col(const eT* aux_mem, const uword aux_length); template inline explicit Col(const Base& A, const Base& B); template inline Col(const BaseCube& X); template inline const Col& operator=(const BaseCube& X); inline Col(const subview_cube& X); inline const Col& operator=(const subview_cube& X); inline mat_injector operator<<(const eT val); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; arma_inline subview_col row(const uword row_num); arma_inline const subview_col row(const uword row_num) const; using Mat::rows; using Mat::operator(); arma_inline subview_col rows(const uword in_row1, const uword in_row2); arma_inline const subview_col rows(const uword in_row1, const uword in_row2) const; arma_inline subview_col subvec(const uword in_row1, const uword in_row2); arma_inline const subview_col subvec(const uword in_row1, const uword in_row2) const; arma_inline subview_col rows(const span& row_span); arma_inline const subview_col rows(const span& row_span) const; arma_inline subview_col subvec(const span& row_span); arma_inline const subview_col subvec(const span& row_span) const; arma_inline subview_col operator()(const span& row_span); arma_inline const subview_col operator()(const span& row_span) const; arma_inline subview_col head(const uword N); arma_inline const subview_col head(const uword N) const; arma_inline subview_col tail(const uword N); arma_inline const subview_col tail(const uword N) const; arma_inline subview_col head_rows(const uword N); arma_inline const subview_col head_rows(const uword N) const; arma_inline subview_col tail_rows(const uword N); arma_inline const subview_col tail_rows(const uword N) const; inline void shed_row (const uword row_num); inline void shed_rows(const uword in_row1, const uword in_row2); inline void insert_rows(const uword row_num, const uword N, const bool set_to_zero = true); template inline void insert_rows(const uword row_num, const Base& X); arma_inline arma_warn_unused eT& at(const uword i); arma_inline arma_warn_unused const eT& at(const uword i) const; arma_inline arma_warn_unused eT& at(const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at(const uword in_row, const uword in_col) const; typedef eT* row_iterator; typedef const eT* const_row_iterator; inline row_iterator begin_row(const uword row_num); inline const_row_iterator begin_row(const uword row_num) const; inline row_iterator end_row (const uword row_num); inline const_row_iterator end_row (const uword row_num) const; template class fixed; protected: inline Col(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem); public: #ifdef ARMA_EXTRA_COL_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_COL_PROTO) #endif }; template template class Col::fixed : public Col { private: static const bool use_extra = (fixed_n_elem > arma_config::mat_prealloc); arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; arma_inline void change_to_row(); public: typedef fixed Col_fixed_type; typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = true; static const bool is_row = false; static const uword n_rows = fixed_n_elem; static const uword n_cols = 1; static const uword n_elem = fixed_n_elem; arma_inline fixed(); arma_inline fixed(const fixed& X); inline fixed(const subview_cube& X); template inline fixed(const fill::fill_class& f); template inline fixed(const Base& A); template inline fixed(const Base& A, const Base& B); inline fixed(const eT* aux_mem); inline fixed(const char* text); inline fixed(const std::string& text); template inline const Col& operator=(const Base& A); inline const Col& operator=(const eT val); inline const Col& operator=(const char* text); inline const Col& operator=(const std::string& text); inline const Col& operator=(const subview_cube& X); using Col::operator(); #if defined(ARMA_USE_CXX11) inline fixed(const std::initializer_list& list); inline const Col& operator=(const std::initializer_list& list); #endif arma_inline const Col& operator=(const fixed& X); #if defined(ARMA_GOOD_COMPILER) template inline const Col& operator=(const eOp& X); template inline const Col& operator=(const eGlue& X); #endif arma_inline const Op< Col_fixed_type, op_htrans > t() const; arma_inline const Op< Col_fixed_type, op_htrans > ht() const; arma_inline const Op< Col_fixed_type, op_strans > st() const; arma_inline arma_warn_unused const eT& at_alt (const uword i) const; arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at (const uword i); arma_inline arma_warn_unused const eT& at (const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; arma_hot inline const Col& fill(const eT val); arma_hot inline const Col& zeros(); arma_hot inline const Col& ones(); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_eigs_sym.hpp0000666000000000000000000000555112620272703021767 0ustar rootroot// Copyright (C) 2013-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup fn_eigs_sym //! @{ //! eigenvalues of symmetric real sparse matrix X template inline Col eigs_sym ( const SpBase& X, const uword n_eigvals, const char* form = "lm", const typename T1::elem_type tol = 0.0, const typename arma_real_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat eigvec; Col eigval; const bool status = sp_auxlib::eigs_sym(eigval, eigvec, X, n_eigvals, form, tol); if(status == false) { eigval.reset(); arma_bad("eigs_sym(): decomposition failed"); } return eigval; } //! eigenvalues of symmetric real sparse matrix X template inline bool eigs_sym ( Col& eigval, const SpBase& X, const uword n_eigvals, const char* form = "lm", const typename T1::elem_type tol = 0.0, const typename arma_real_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat eigvec; const bool status = sp_auxlib::eigs_sym(eigval, eigvec, X, n_eigvals, form, tol); if(status == false) { eigval.reset(); arma_debug_warn("eigs_sym(): decomposition failed"); } return status; } //! eigenvalues and eigenvectors of symmetric real sparse matrix X template inline bool eigs_sym ( Col& eigval, Mat& eigvec, const SpBase& X, const uword n_eigvals, const char* form = "lm", const typename T1::elem_type tol = 0.0, const typename arma_real_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( void_ptr(&eigval) == void_ptr(&eigvec), "eigs_sym(): paramater 'eigval' is an alias of parameter 'eigvec'" ); const bool status = sp_auxlib::eigs_sym(eigval, eigvec, X, n_eigvals, form, tol); if(status == false) { eigval.reset(); arma_debug_warn("eigs_sym(): decomposition failed"); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/wrapper_arpack.hpp0000666000000000000000000001365712620272703022474 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Ryan Curtin #ifdef ARMA_USE_ARPACK //! \namespace arpack namespace for ARPACK functions namespace arpack { // If real, then eT == eeT; otherwise, eT == std::complex. // For real calls, rwork is ignored; it's only necessary in the complex case. template inline void naupd(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, eeT* tol, eT* resid, blas_int* ncv, eT* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, eT* workd, eT* workl, blas_int* lworkl, eeT* rwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_snaupd)(ido, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dnaupd)(ido, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_supported_complex_float::value) { typedef std::complex T; typedef float xT; arma_fortran(arma_cnaupd)(ido, bmat, n, which, nev, (xT*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, (xT*) rwork, info); } else if(is_supported_complex_double::value) { typedef std::complex T; typedef double xT; arma_fortran(arma_znaupd)(ido, bmat, n, which, nev, (xT*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, (xT*) rwork, info); } } //! The use of two template types is necessary here because the compiler will //! instantiate this method for complex types (where eT != eeT) but that in //! practice that is never actually used. template inline void saupd(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, eeT* tol, eT* resid, blas_int* ncv, eT* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, eT* workd, eT* workl, blas_int* lworkl, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_ssaupd)(ido, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dsaupd)(ido, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } } template inline void seupd(blas_int* rvec, char* howmny, blas_int* select, eT* d, eT* z, blas_int* ldz, eT* sigma, char* bmat, blas_int* n, char* which, blas_int* nev, eT* tol, eT* resid, blas_int* ncv, eT* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, eT* workd, eT* workl, blas_int* lworkl, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sseupd)(rvec, howmny, select, (T*) d, (T*) z, ldz, (T*) sigma, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dseupd)(rvec, howmny, select, (T*) d, (T*) z, ldz, (T*) sigma, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } } // for complex versions, pass d for dr, and null for di; pass sigma for // sigmar, and null for sigmai; rwork isn't used for non-complex versions template inline void neupd(blas_int* rvec, char* howmny, blas_int* select, eT* dr, eT* di, eT* z, blas_int* ldz, eT* sigmar, eT* sigmai, eT* workev, char* bmat, blas_int* n, char* which, blas_int* nev, eeT* tol, eT* resid, blas_int* ncv, eT* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, eT* workd, eT* workl, blas_int* lworkl, eeT* rwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sneupd)(rvec, howmny, select, (T*) dr, (T*) di, (T*) z, ldz, (T*) sigmar, (T*) sigmai, (T*) workev, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dneupd)(rvec, howmny, select, (T*) dr, (T*) di, (T*) z, ldz, (T*) sigmar, (T*) sigmai, (T*) workev, bmat, n, which, nev, (T*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, info); } else if(is_supported_complex_float::value) { typedef float xT; // eT is taken typedef std::complex T; arma_fortran(arma_cneupd)(rvec, howmny, select, (T*) dr, (T*) z, ldz, (T*) sigmar, (T*) workev, bmat, n, which, nev, (xT*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, (xT*) rwork, info); } else if(is_supported_complex_double::value) { typedef double xT; // eT is taken typedef std::complex T; arma_fortran(arma_zneupd)(rvec, howmny, select, (T*) dr, (T*) z, ldz, (T*) sigmar, (T*) workev, bmat, n, which, nev, (xT*) tol, (T*) resid, ncv, (T*) v, ldv, iparam, ipntr, (T*) workd, (T*) workl, lworkl, (xT*) rwork, info); } } } // namespace arpack #endif armadillo-6.500.5/include/armadillo_bits/glue_join_bones.hpp0000666000000000000000000000242712620272703022625 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_join //! @{ class glue_join_cols { public: template inline static void apply(Mat& out, const Glue& X); template inline static void apply_noalias(Mat& out, const Proxy& A, const Proxy& B); }; class glue_join_rows { public: template inline static void apply(Mat& out, const Glue& X); template inline static void apply_noalias(Mat& out, const Proxy& A, const Proxy& B); }; class glue_join_slices { public: template inline static void apply(Cube& out, const GlueCube& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_clamp_meat.hpp0000666000000000000000000000450012620272703022256 0ustar rootroot// Copyright (C) 2014-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_clamp //! @{ template inline void op_clamp::apply(Mat& out, const mtOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(in.m); if(P.is_alias(out) && (is_Mat::value == false)) { Mat tmp; op_clamp::apply_noalias(tmp, P, in.aux, in.aux_out_eT); out.steal_mem(tmp); } else { op_clamp::apply_noalias(out, P, in.aux, in.aux_out_eT); } } template inline void op_clamp::apply_noalias(Mat& out, const Proxy& P, const typename T1::elem_type min_val, const typename T1::elem_type max_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword N = P.get_n_elem(); typename Proxy::ea_type A = P.get_ea(); uword j; for(j=1; j max_val) ? max_val : val_i); val_j = (val_j < min_val) ? min_val : ((val_j > max_val) ? max_val : val_j); (*out_mem) = val_i; out_mem++; (*out_mem) = val_j; out_mem++; } const uword i = j-1; if(i < N) { eT val_i = A[i]; val_i = (val_i < min_val) ? min_val : ((val_i > max_val) ? max_val : val_i); (*out_mem) = val_i; } } else { for(uword col=0; col max_val) ? max_val : val); (*out_mem) = val; out_mem++; } } } //! @} armadillo-6.500.5/include/armadillo_bits/typedef_elem_check.hpp0000666000000000000000000000336512620272703023265 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup typedef_elem //! @{ namespace junk { struct arma_elem_size_test { // arma_static_check( (sizeof(size_t) < sizeof(uword)), ERROR___TYPE_SIZE_T_IS_SMALLER_THAN_UWORD ); arma_static_check( (sizeof(u8) != 1), ERROR___TYPE_U8_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(s8) != 1), ERROR___TYPE_S8_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(u16) != 2), ERROR___TYPE_U16_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(s16) != 2), ERROR___TYPE_S16_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(u32) != 4), ERROR___TYPE_U32_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(s32) != 4), ERROR___TYPE_S32_HAS_UNSUPPORTED_SIZE ); #if defined(ARMA_USE_U64S64) arma_static_check( (sizeof(u64) != 8), ERROR___TYPE_U64_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(s64) != 8), ERROR___TYPE_S64_HAS_UNSUPPORTED_SIZE ); #endif arma_static_check( (sizeof(float) != 4), ERROR___TYPE_FLOAT_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(double) != 8), ERROR___TYPE_DOUBLE_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(std::complex) != 8), ERROR___TYPE_COMPLEX_FLOAT_HAS_UNSUPPORTED_SIZE ); arma_static_check( (sizeof(std::complex) != 16), ERROR___TYPE_COMPLEX_DOUBLE_HAS_UNSUPPORTED_SIZE ); }; } //! @} armadillo-6.500.5/include/armadillo_bits/eglue_core_bones.hpp0000666000000000000000000000515312620272703022762 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eglue_core //! @{ template struct eglue_core { // matrices template arma_hot inline static void apply(outT& out, const eGlue& x); template arma_hot inline static void apply_inplace_plus (Mat& out, const eGlue& x); template arma_hot inline static void apply_inplace_minus(Mat& out, const eGlue& x); template arma_hot inline static void apply_inplace_schur(Mat& out, const eGlue& x); template arma_hot inline static void apply_inplace_div (Mat& out, const eGlue& x); // cubes template arma_hot inline static void apply(Cube& out, const eGlueCube& x); template arma_hot inline static void apply_inplace_plus (Cube& out, const eGlueCube& x); template arma_hot inline static void apply_inplace_minus(Cube& out, const eGlueCube& x); template arma_hot inline static void apply_inplace_schur(Cube& out, const eGlueCube& x); template arma_hot inline static void apply_inplace_div (Cube& out, const eGlueCube& x); }; class eglue_plus : public eglue_core { public: inline static const char* text() { return "addition"; } }; class eglue_minus : public eglue_core { public: inline static const char* text() { return "subtraction"; } }; class eglue_div : public eglue_core { public: inline static const char* text() { return "element-wise division"; } }; class eglue_schur : public eglue_core { public: inline static const char* text() { return "element-wise multiplication"; } }; //! @} armadillo-6.500.5/include/armadillo_bits/op_stddev_meat.hpp0000666000000000000000000000436712620272703022466 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_stddev //! @{ //! \brief //! For each row or for each column, find the standard deviation. //! The result is stored in a dense matrix that has either one column or one row. //! The dimension for which the standard deviations are found is set via the stddev() function. template inline void op_stddev::apply(Mat& out, const mtOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type in_eT; typedef typename T1::pod_type out_eT; const unwrap_check_mixed tmp(in.m, out); const Mat& X = tmp.M; const uword norm_type = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check( (norm_type > 1), "stddev(): parameter 'norm_type' must be 0 or 1" ); arma_debug_check( (dim > 1), "stddev(): parameter 'dim' must be 0 or 1" ); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_stddev::apply(): dim = 0"); out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows > 0) { out_eT* out_mem = out.memptr(); for(uword col=0; col 0) ? 1 : 0); if(X_n_cols > 0) { podarray dat(X_n_cols); in_eT* dat_mem = dat.memptr(); out_eT* out_mem = out.memptr(); for(uword row=0; row arma_inline typename enable_if2 < is_arma_type::value, const Op >::result cumprod(const T1& X) { arma_extra_debug_sigprint(); return Op(X); } template arma_inline typename enable_if2 < is_arma_type::value, const Op >::result cumprod(const T1& X, const uword dim) { arma_extra_debug_sigprint(); return Op(X, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & cumprod(const T& x) { return x; } //! @} armadillo-6.500.5/include/armadillo_bits/glue_histc_meat.hpp0000666000000000000000000000770712620272703022626 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_histc //! @{ template inline void glue_histc::apply_noalias(Mat& C, const Mat& A, const Mat& B, const uword dim) { arma_extra_debug_sigprint(); arma_debug_check( ((B.is_vec() == false) && (B.is_empty() == false)), "histc(): parameter 'edges' is not a vector" ); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_elem = B.n_elem; if( B_n_elem == uword(0) ) { C.reset(); return; } const eT* B_mem = B.memptr(); const uword B_n_elem_m1 = B_n_elem - 1; if(dim == uword(0)) { C.zeros(B_n_elem, A_n_cols); for(uword col=0; col < A_n_cols; ++col) { const eT* A_coldata = A.colptr(col); uword* C_coldata = C.colptr(col); for(uword row=0; row < A_n_rows; ++row) { const eT x = A_coldata[row]; for(uword i=0; i < B_n_elem_m1; ++i) { if( (B_mem[i] <= x) && (x < B_mem[i+1]) ) { C_coldata[i]++; break; } else if( B_mem[B_n_elem_m1] == x ) { C_coldata[B_n_elem_m1]++; break; } // for compatibility with Matlab } } } } else if(dim == uword(1)) { C.zeros(A_n_rows, B_n_elem); if(A.n_rows == 1) { const uword A_n_elem = A.n_elem; const eT* A_mem = A.memptr(); uword* C_mem = C.memptr(); for(uword j=0; j < A_n_elem; ++j) { const eT x = A_mem[j]; for(uword i=0; i < B_n_elem_m1; ++i) { if( (B_mem[i] <= x) && (x < B_mem[i+1]) ) { C_mem[i]++; break; } else if( B_mem[B_n_elem_m1] == x ) { C_mem[B_n_elem_m1]++; break; } // for compatibility with Matlab } } } else { for(uword row=0; row < A_n_rows; ++row) for(uword col=0; col < A_n_cols; ++col) { const eT x = A.at(row,col); for(uword i=0; i < B_n_elem_m1; ++i) { if( (B_mem[i] <= x) && (x < B_mem[i+1]) ) { C.at(row,i)++; break; } else if( B_mem[B_n_elem_m1] == x ) { C.at(row,B_n_elem_m1)++; break; } // for compatibility with Matlab } } } } } template inline void glue_histc::apply(Mat& C, const mtGlue& expr) { arma_extra_debug_sigprint(); const uword dim = expr.aux_uword; arma_debug_check( (dim > 1), "histc(): parameter 'dim' must be 0 or 1" ); const quasi_unwrap UA(expr.A); const quasi_unwrap UB(expr.B); if(UA.is_alias(C) || UB.is_alias(C)) { Mat tmp; glue_histc::apply_noalias(tmp, UA.M, UB.M, dim); C.steal_mem(tmp); } else { glue_histc::apply_noalias(C, UA.M, UB.M, dim); } } template inline void glue_histc_default::apply(Mat& C, const mtGlue& expr) { arma_extra_debug_sigprint(); const quasi_unwrap UA(expr.A); const quasi_unwrap UB(expr.B); //const uword dim = ( (T1::is_row) || ((UA.M.vec_state == 0) && (UA.M.n_elem <= 1) && (C.vec_state == 2)) ) ? 1 : 0; const uword dim = (T1::is_row) ? 1 : 0; if(UA.is_alias(C) || UB.is_alias(C)) { Mat tmp; glue_histc::apply_noalias(tmp, UA.M, UB.M, dim); C.steal_mem(tmp); } else { glue_histc::apply_noalias(C, UA.M, UB.M, dim); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_dot_meat.hpp0000666000000000000000000003122312650172354021756 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_dot //! @{ //! for two arrays, generic version for non-complex values template arma_hot arma_inline typename arma_not_cx::result op_dot::direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); #if defined(__FINITE_MATH_ONLY__) && (__FINITE_MATH_ONLY__ > 0) { eT val = eT(0); for(uword i=0; i arma_hot inline typename arma_cx_only::result op_dot::direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; T val_real = T(0); T val_imag = T(0); for(uword i=0; i& X = A[i]; const std::complex& Y = B[i]; const T a = X.real(); const T b = X.imag(); const T c = Y.real(); const T d = Y.imag(); val_real += (a*c) - (b*d); val_imag += (a*d) + (b*c); } return std::complex(val_real, val_imag); } //! for two arrays, float and double version template arma_hot inline typename arma_real_only::result op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); if( n_elem <= 32u ) { return op_dot::direct_dot_arma(n_elem, A, B); } else { #if defined(ARMA_USE_ATLAS) { arma_extra_debug_print("atlas::cblas_dot()"); return atlas::cblas_dot(n_elem, A, B); } #elif defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::dot()"); return blas::dot(n_elem, A, B); } #else { return op_dot::direct_dot_arma(n_elem, A, B); } #endif } } //! for two arrays, complex version template inline arma_hot typename arma_cx_only::result op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B) { if( n_elem <= 16u ) { return op_dot::direct_dot_arma(n_elem, A, B); } else { #if defined(ARMA_USE_ATLAS) { arma_extra_debug_print("atlas::cblas_cx_dot()"); return atlas::cblas_cx_dot(n_elem, A, B); } #elif defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::dot()"); return blas::dot(n_elem, A, B); } #else { return op_dot::direct_dot_arma(n_elem, A, B); } #endif } } //! for two arrays, integral version template arma_hot inline typename arma_integral_only::result op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B) { return op_dot::direct_dot_arma(n_elem, A, B); } //! for three arrays template arma_hot inline eT op_dot::direct_dot(const uword n_elem, const eT* const A, const eT* const B, const eT* C) { arma_extra_debug_sigprint(); eT val = eT(0); for(uword i=0; i arma_hot inline typename T1::elem_type op_dot::apply(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor) || (Proxy::prefer_at_accessor); const bool have_direct_mem = ((is_Mat::value || is_subview_col::value) && (is_Mat::value || is_subview_col::value)); if(prefer_at_accessor || have_direct_mem) { const quasi_unwrap A(X); const quasi_unwrap B(Y); arma_debug_check( (A.M.n_elem != B.M.n_elem), "dot(): objects must have the same number of elements" ); return op_dot::direct_dot(A.M.n_elem, A.M.memptr(), B.M.memptr()); } else { if(is_subview_row::value && is_subview_row::value) { typedef typename T1::elem_type eT; const subview_row& A = reinterpret_cast< const subview_row& >(X); const subview_row& B = reinterpret_cast< const subview_row& >(Y); if( (A.m.n_rows == 1) && (B.m.n_rows == 1) ) { arma_debug_check( (A.n_elem != B.n_elem), "dot(): objects must have the same number of elements" ); const eT* A_mem = A.m.memptr(); const eT* B_mem = B.m.memptr(); return op_dot::direct_dot(A.n_elem, &A_mem[A.aux_col1], &B_mem[B.aux_col1]); } } const Proxy PA(X); const Proxy PB(Y); arma_debug_check( (PA.get_n_elem() != PB.get_n_elem()), "dot(): objects must have the same number of elements" ); if(is_Mat::stored_type>::value && is_Mat::stored_type>::value) { const quasi_unwrap::stored_type> A(PA.Q); const quasi_unwrap::stored_type> B(PB.Q); return op_dot::direct_dot(A.M.n_elem, A.M.memptr(), B.M.memptr()); } return op_dot::apply_proxy(PA,PB); } } template arma_hot inline typename arma_not_cx::result op_dot::apply_proxy(const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const uword N = PA.get_n_elem(); ea_type1 A = PA.get_ea(); ea_type2 B = PB.get_ea(); eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j arma_hot inline typename arma_cx_only::result op_dot::apply_proxy(const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const uword N = PA.get_n_elem(); ea_type1 A = PA.get_ea(); ea_type2 B = PB.get_ea(); T val_real = T(0); T val_imag = T(0); for(uword i=0; i xx = A[i]; const std::complex yy = B[i]; const T a = xx.real(); const T b = xx.imag(); const T c = yy.real(); const T d = yy.imag(); val_real += (a*c) - (b*d); val_imag += (a*d) + (b*c); } return std::complex(val_real, val_imag); } // // op_norm_dot template arma_hot inline typename T1::elem_type op_norm_dot::apply(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const quasi_unwrap tmp1(X); const quasi_unwrap tmp2(Y); const Col A( const_cast(tmp1.M.memptr()), tmp1.M.n_elem, false ); const Col B( const_cast(tmp2.M.memptr()), tmp2.M.n_elem, false ); arma_debug_check( (A.n_elem != B.n_elem), "norm_dot(): objects must have the same number of elements" ); const T denom = norm(A,2) * norm(B,2); return (denom != T(0)) ? ( op_dot::apply(A,B) / denom ) : eT(0); } // // op_cdot template arma_hot inline eT op_cdot::direct_cdot_arma(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; T val_real = T(0); T val_imag = T(0); for(uword i=0; i& X = A[i]; const std::complex& Y = B[i]; const T a = X.real(); const T b = X.imag(); const T c = Y.real(); const T d = Y.imag(); val_real += (a*c) + (b*d); val_imag += (a*d) - (b*c); } return std::complex(val_real, val_imag); } template arma_hot inline eT op_cdot::direct_cdot(const uword n_elem, const eT* const A, const eT* const B) { arma_extra_debug_sigprint(); if( n_elem <= 32u ) { return op_cdot::direct_cdot_arma(n_elem, A, B); } else { #if defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::gemv()"); // using gemv() workaround due to compatibility issues with cdotc() and zdotc() const char trans = 'C'; const blas_int m = blas_int(n_elem); const blas_int n = 1; //const blas_int lda = (n_elem > 0) ? blas_int(n_elem) : blas_int(1); const blas_int inc = 1; const eT alpha = eT(1); const eT beta = eT(0); eT result[2]; // paranoia: using two elements instead of one //blas::gemv(&trans, &m, &n, &alpha, A, &lda, B, &inc, &beta, &result[0], &inc); blas::gemv(&trans, &m, &n, &alpha, A, &m, B, &inc, &beta, &result[0], &inc); return result[0]; } #elif defined(ARMA_USE_ATLAS) { // TODO: use dedicated atlas functions cblas_cdotc_sub() and cblas_zdotc_sub() and retune threshold return op_cdot::direct_cdot_arma(n_elem, A, B); } #else { return op_cdot::direct_cdot_arma(n_elem, A, B); } #endif } } template arma_hot inline typename T1::elem_type op_cdot::apply(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); if( (is_Mat::value == true) && (is_Mat::value == true) ) { return op_cdot::apply_unwrap(X,Y); } else { return op_cdot::apply_proxy(X,Y); } } template arma_hot inline typename T1::elem_type op_cdot::apply_unwrap(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp1(X); const unwrap tmp2(Y); const Mat& A = tmp1.M; const Mat& B = tmp2.M; arma_debug_check( (A.n_elem != B.n_elem), "cdot(): objects must have the same number of elements" ); return op_cdot::direct_cdot( A.n_elem, A.mem, B.mem ); } template arma_hot inline typename T1::elem_type op_cdot::apply_proxy(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const bool prefer_at_accessor = (Proxy::prefer_at_accessor) || (Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const Proxy PA(X); const Proxy PB(Y); const uword N = PA.get_n_elem(); arma_debug_check( (N != PB.get_n_elem()), "cdot(): objects must have the same number of elements" ); ea_type1 A = PA.get_ea(); ea_type2 B = PB.get_ea(); T val_real = T(0); T val_imag = T(0); for(uword i=0; i AA = A[i]; const std::complex BB = B[i]; const T a = AA.real(); const T b = AA.imag(); const T c = BB.real(); const T d = BB.imag(); val_real += (a*c) + (b*d); val_imag += (a*d) - (b*c); } return std::complex(val_real, val_imag); } else { return op_cdot::apply_unwrap( X, Y ); } } template arma_hot inline typename promote_type::result op_dot_mixed::apply(const T1& A, const T2& B) { arma_extra_debug_sigprint(); typedef typename T1::elem_type in_eT1; typedef typename T2::elem_type in_eT2; typedef typename promote_type::result out_eT; const Proxy PA(A); const Proxy PB(B); const uword N = PA.get_n_elem(); arma_debug_check( (N != PB.get_n_elem()), "dot(): objects must have the same number of elements" ); out_eT acc = out_eT(0); for(uword i=0; i < N; ++i) { acc += upgrade_val::apply(PA[i]) * upgrade_val::apply(PB[i]); } return acc; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_hist.hpp0000666000000000000000000000315612620272703021116 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_hist //! @{ template arma_inline typename enable_if2 < (is_arma_type::value) && (is_not_complex::value), const mtOp >::result hist(const T1& A, const uword n_bins = 10) { arma_extra_debug_sigprint(); return mtOp(A, n_bins, 0); } template arma_inline typename enable_if2 < (is_arma_type::value) && (is_arma_type::value) && (is_not_complex::value) && (is_same_type::value), const mtGlue >::result hist(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue(X, Y); } template arma_inline typename enable_if2 < (is_arma_type::value) && (is_arma_type::value) && (is_not_complex::value) && (is_same_type::value), const mtGlue >::result hist(const T1& X, const T2& Y, const uword dim) { arma_extra_debug_sigprint(); return mtGlue(X, Y, dim); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_trunc_exp.hpp0000666000000000000000000000265312620272703022157 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_trunc_exp //! @{ template inline static typename arma_real_only::result trunc_exp(const eT x) { if(std::numeric_limits::is_iec559 && (x >= Math::log_max() )) { return std::numeric_limits::max(); } else { return std::exp(x); } } template inline static typename arma_integral_only::result trunc_exp(const eT x) { return eT( trunc_exp( double(x) ) ); } template inline static std::complex trunc_exp(const std::complex& x) { return std::polar( trunc_exp( x.real() ), x.imag() ); } template arma_inline const eOp trunc_exp(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube trunc_exp(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_conv.hpp0000666000000000000000000000335712647105221021116 0ustar rootroot// Copyright (C) 2010-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_conv //! @{ //! Convolution, which is also equivalent to polynomial multiplication and FIR digital filtering. template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && is_same_type::value), const Glue >::result conv(const T1& A, const T2& B, const char* shape = "full") { arma_extra_debug_sigprint(); const char sig = (shape != NULL) ? shape[0] : char(0); arma_debug_check( ((sig != 'f') && (sig != 's')), "conv(): unsupported value of 'shape' parameter" ); const uword mode = (sig == 's') ? uword(1) : uword(0); return Glue(A, B, mode); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && is_same_type::value), const Glue >::result conv2(const T1& A, const T2& B, const char* shape = "full") { arma_extra_debug_sigprint(); const char sig = (shape != NULL) ? shape[0] : char(0); arma_debug_check( ((sig != 'f') && (sig != 's')), "conv2(): unsupported value of 'shape' parameter" ); const uword mode = (sig == 's') ? uword(1) : uword(0); return Glue(A, B, mode); } //! @} armadillo-6.500.5/include/armadillo_bits/spop_mean_meat.hpp0000666000000000000000000001701212620272703022447 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_mean //! @{ template inline void spop_mean::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "mean(): parameter 'dim' must be 0 or 1" ); const SpProxy p(in.m); if(p.is_alias(out) == false) { spop_mean::apply_noalias_fast(out, p, dim); } else { SpMat tmp; spop_mean::apply_noalias_fast(tmp, p, dim); out.steal_mem(tmp); } } template inline void spop_mean::apply_noalias_fast ( SpMat& out, const SpProxy& p, const uword dim ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const uword p_n_rows = p.get_n_rows(); const uword p_n_cols = p.get_n_cols(); if( (p_n_rows == 0) || (p_n_cols == 0) || (p.get_n_nonzero() == 0) ) { if(dim == 0) { out.zeros((p_n_rows > 0) ? 1 : 0, p_n_cols); } if(dim == 1) { out.zeros(p_n_rows, (p_n_cols > 0) ? 1 : 0); } return; } if(dim == 0) // find the mean in each column { Row acc(p_n_cols, fill::zeros); if(SpProxy::must_use_iterator) { typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { acc[it.col()] += (*it); ++it; } acc /= T(p_n_rows); } else { for(uword col = 0; col < p_n_cols; ++col) { acc[col] = arrayops::accumulate ( &p.get_values()[p.get_col_ptrs()[col]], p.get_col_ptrs()[col + 1] - p.get_col_ptrs()[col] ) / T(p_n_rows); } } out = acc; } else if(dim == 1) // find the mean in each row { Col acc(p_n_rows, fill::zeros); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { acc[it.row()] += (*it); ++it; } acc /= T(p_n_cols); out = acc; } if(out.is_finite() == false) { spop_mean::apply_noalias_slow(out, p, dim); } } template inline void spop_mean::apply_noalias_slow ( SpMat& out, const SpProxy& p, const uword dim ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword p_n_rows = p.get_n_rows(); const uword p_n_cols = p.get_n_cols(); if(dim == 0) // find the mean in each column { arma_extra_debug_print("spop_mean::apply_noalias(): dim = 0"); out.set_size((p_n_rows > 0) ? 1 : 0, p_n_cols); if( (p_n_rows == 0) || (p.get_n_nonzero() == 0) ) { return; } for(uword col = 0; col < p_n_cols; ++col) { // Do we have to use an iterator or can we use memory directly? if(SpProxy::must_use_iterator) { typename SpProxy::const_iterator_type it = p.begin_col(col); typename SpProxy::const_iterator_type end = p.begin_col(col + 1); const uword n_zero = p_n_rows - (end.pos() - it.pos()); out.at(0,col) = spop_mean::iterator_mean(it, end, n_zero, eT(0)); } else { out.at(0,col) = spop_mean::direct_mean ( &p.get_values()[p.get_col_ptrs()[col]], p.get_col_ptrs()[col + 1] - p.get_col_ptrs()[col], p_n_rows ); } } } else if(dim == 1) // find the mean in each row { arma_extra_debug_print("spop_mean::apply_noalias(): dim = 1"); out.set_size(p_n_rows, (p_n_cols > 0) ? 1 : 0); if( (p_n_cols == 0) || (p.get_n_nonzero() == 0) ) { return; } for(uword row = 0; row < p_n_rows; ++row) { // We must use an iterator regardless of how it is stored. typename SpProxy::const_row_iterator_type it = p.begin_row(row); typename SpProxy::const_row_iterator_type end = p.end_row(row); const uword n_zero = p_n_cols - (end.pos() - it.pos()); out.at(row,0) = spop_mean::iterator_mean(it, end, n_zero, eT(0)); } } } template inline eT spop_mean::direct_mean ( const eT* const X, const uword length, const uword N ) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const eT result = ((length > 0) && (N > 0)) ? eT(arrayops::accumulate(X, length) / T(N)) : eT(0); return arma_isfinite(result) ? result : spop_mean::direct_mean_robust(X, length, N); } template inline eT spop_mean::direct_mean_robust ( const eT* const X, const uword length, const uword N ) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; uword i, j; eT r_mean = eT(0); const uword diff = (N - length); // number of zeros for(i = 0, j = 1; j < length; i += 2, j += 2) { const eT Xi = X[i]; const eT Xj = X[j]; r_mean += (Xi - r_mean) / T(diff + j); r_mean += (Xj - r_mean) / T(diff + j + 1); } if(i < length) { const eT Xi = X[i]; r_mean += (Xi - r_mean) / T(diff + i + 1); } return r_mean; } template inline typename T1::elem_type spop_mean::mean_all(const SpBase& X) { arma_extra_debug_sigprint(); SpProxy p(X.get_ref()); if(SpProxy::must_use_iterator) { typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type end = p.end(); return spop_mean::iterator_mean(it, end, p.get_n_elem() - p.get_n_nonzero(), typename T1::elem_type(0)); } else // must_use_iterator == false; that is, we can directly access the values array { return spop_mean::direct_mean(p.get_values(), p.get_n_nonzero(), p.get_n_elem()); } } template inline eT spop_mean::iterator_mean(T1& it, const T1& end, const uword n_zero, const eT junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename get_pod_type::result T; eT acc = eT(0); T1 backup_it(it); // in case we have to use robust iterator_mean const uword it_begin_pos = it.pos(); while (it != end) { acc += (*it); ++it; } const uword count = n_zero + (it.pos() - it_begin_pos); const eT result = (count > 0) ? eT(acc / T(count)) : eT(0); return arma_isfinite(result) ? result : spop_mean::iterator_mean_robust(backup_it, end, n_zero, eT(0)); } template inline eT spop_mean::iterator_mean_robust(T1& it, const T1& end, const uword n_zero, const eT junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename get_pod_type::result T; eT r_mean = eT(0); const uword it_begin_pos = it.pos(); while (it != end) { r_mean += ((*it - r_mean) / T(n_zero + (it.pos() - it_begin_pos) + 1)); ++it; } return r_mean; } //! @} armadillo-6.500.5/include/armadillo_bits/eGlue_bones.hpp0000666000000000000000000000344712620272703021716 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eGlue //! @{ template class eGlue : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Proxy proxy1_type; typedef Proxy proxy2_type; static const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); static const bool has_subview = (Proxy::has_subview || Proxy::has_subview ); static const bool fake_mat = (Proxy::fake_mat || Proxy::fake_mat ); static const bool is_col = (Proxy::is_col || Proxy::is_col); static const bool is_row = (Proxy::is_row || Proxy::is_row); arma_aligned const Proxy P1; arma_aligned const Proxy P2; arma_inline ~eGlue(); arma_inline eGlue(const T1& in_A, const T2& in_B); arma_inline uword get_n_rows() const; arma_inline uword get_n_cols() const; arma_inline uword get_n_elem() const; arma_inline elem_type operator[] (const uword ii) const; arma_inline elem_type at (const uword row, const uword col) const; arma_inline elem_type at_alt (const uword ii) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/op_diagvec_bones.hpp0000666000000000000000000000172512620272703022752 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_diagvec //! @{ class op_diagvec { public: template inline static void apply(Mat& out, const Op& X); template arma_hot inline static void apply_unwrap(Mat& out, const T1& X, const uword row_offset, const uword col_offset, const uword len); template arma_hot inline static void apply_proxy(Mat& out, const Proxy& P, const uword row_offset, const uword col_offset, const uword len); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_diagvec.hpp0000666000000000000000000000140012620272703021537 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_diagvec //! @{ //! extract a diagonal from a matrix template arma_inline const Op diagvec(const Base& X, const sword diag_id = 0) { arma_extra_debug_sigprint(); return Op(X.get_ref(), ((diag_id < 0) ? -diag_id : diag_id), ((diag_id < 0) ? 1 : 0) ); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_randn.hpp0000666000000000000000000000735012620272703021251 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_randn //! @{ inline double randn() { return double(arma_rng::randn()); } template inline typename arma_scalar_only::result randn() { return eT(arma_rng::randn()); } //! Generate a vector with all elements set to random values with a gaussian distribution (zero mean, unit variance) arma_inline const Gen randn(const uword n_elem) { arma_extra_debug_sigprint(); return Gen(n_elem, 1); } template arma_inline const Gen randn(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value == true) { return Gen(1, n_elem); } else { return Gen(n_elem, 1); } } //! Generate a dense matrix with all elements set to random values with a gaussian distribution (zero mean, unit variance) arma_inline const Gen randn(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } arma_inline const Gen randn(const SizeMat& s) { arma_extra_debug_sigprint(); return Gen(s.n_rows, s.n_cols); } template arma_inline const Gen randn(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "randn(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "randn(): incompatible size" ); } return Gen(n_rows, n_cols); } template arma_inline const Gen randn(const SizeMat& s, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return randn(s.n_rows, s.n_cols); } arma_inline const GenCube randn(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return GenCube(n_rows, n_cols, n_slices); } arma_inline const GenCube randn(const SizeCube& s) { arma_extra_debug_sigprint(); return GenCube(s.n_rows, s.n_cols, s.n_slices); } template arma_inline const GenCube randn(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(n_rows, n_cols, n_slices); } template arma_inline const GenCube randn(const SizeCube& s, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(s.n_rows, s.n_cols, s.n_slices); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_zeros.hpp0000666000000000000000000001006412620272703021305 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_zeros //! @{ arma_inline const Gen zeros(const uword n_elem) { arma_extra_debug_sigprint(); return Gen(n_elem, 1); } template arma_inline const Gen zeros(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value) { return Gen(1, n_elem); } else { return Gen(n_elem, 1); } } arma_inline const Gen zeros(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } arma_inline const Gen zeros(const SizeMat& s) { arma_extra_debug_sigprint(); return Gen(s.n_rows, s.n_cols); } template arma_inline const Gen zeros(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value) { arma_debug_check( (n_cols != 1), "zeros(): incompatible size" ); } else if(is_Row::value) { arma_debug_check( (n_rows != 1), "zeros(): incompatible size" ); } return Gen(n_rows, n_cols); } template arma_inline const Gen zeros(const SizeMat& s, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return zeros(s.n_rows, s.n_cols); } arma_inline const GenCube zeros(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return GenCube(n_rows, n_cols, n_slices); } arma_inline const GenCube zeros(const SizeCube& s) { arma_extra_debug_sigprint(); return GenCube(s.n_rows, s.n_cols, s.n_slices); } template arma_inline const GenCube zeros(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(n_rows, n_cols, n_slices); } template arma_inline const GenCube zeros(const SizeCube& s, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(s.n_rows, s.n_cols, s.n_slices); } template inline sp_obj_type zeros(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_SpCol::value == true) { arma_debug_check( (n_cols != 1), "zeros(): incompatible size" ); } else if(is_SpRow::value == true) { arma_debug_check( (n_rows != 1), "zeros(): incompatible size" ); } return sp_obj_type(n_rows, n_cols); } template inline sp_obj_type zeros(const SizeMat& s, const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return zeros(s.n_rows, s.n_cols); } //! @} armadillo-6.500.5/include/armadillo_bits/OpCube_meat.hpp0000666000000000000000000000467012620272703021651 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup OpCube //! @{ template OpCube::OpCube(const BaseCube& in_m) : m(in_m.get_ref()) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const typename T1::elem_type in_aux) : m(in_m.get_ref()) , aux(in_aux) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : m(in_m.get_ref()) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m.get_ref()) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : m(in_m.get_ref()) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template OpCube::OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c, const uword in_aux_uword_d, const char) : m(in_m.get_ref()) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) , aux_uword_d(in_aux_uword_d) { arma_extra_debug_sigprint(); } template OpCube::~OpCube() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_expmat.hpp0000666000000000000000000000130212620272703021434 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_expmat //! @{ template inline typename enable_if2 < is_real::value, const Op >::result expmat(const Base& A) { arma_extra_debug_sigprint(); return Op( A.get_ref() ); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_trace.hpp0000666000000000000000000001125512620272703021244 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup fn_trace //! @{ template arma_hot arma_warn_unused inline typename enable_if2::value, typename T1::elem_type>::result trace(const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy A(X); const uword N = (std::min)(A.get_n_rows(), A.get_n_cols()); eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j arma_hot arma_warn_unused inline typename T1::elem_type trace(const Op& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const diagmat_proxy A(X.m); const uword N = (std::min)(A.n_rows, A.n_cols); eT val = eT(0); for(uword i=0; i arma_hot inline typename T1::elem_type trace_mul_unwrap(const Proxy& PA, const T2& XB) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmpB(XB); const Mat& B = tmpB.M; const uword A_n_rows = PA.get_n_rows(); const uword A_n_cols = PA.get_n_cols(); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; arma_debug_assert_mul_size(A_n_rows, A_n_cols, B_n_rows, B_n_cols, "matrix multiplication"); const uword N = (std::min)(A_n_rows, B_n_cols); eT val = eT(0); for(uword k=0; k < N; ++k) { const eT* B_colptr = B.colptr(k); eT acc1 = eT(0); eT acc2 = eT(0); uword j; for(j=1; j < A_n_cols; j+=2) { const uword i = (j-1); const eT tmp_i = B_colptr[i]; const eT tmp_j = B_colptr[j]; acc1 += PA.at(k, i) * tmp_i; acc2 += PA.at(k, j) * tmp_j; } const uword i = (j-1); if(i < A_n_cols) { acc1 += PA.at(k, i) * B_colptr[i]; } val += (acc1 + acc2); } return val; } //! speedup for trace(A*B), where the result of A*B is a square sized matrix template arma_hot inline typename T1::elem_type trace_mul_proxy(const Proxy& PA, const T2& XB) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy PB(XB); if(is_Mat::stored_type>::value) { return trace_mul_unwrap(PA, PB.Q); } const uword A_n_rows = PA.get_n_rows(); const uword A_n_cols = PA.get_n_cols(); const uword B_n_rows = PB.get_n_rows(); const uword B_n_cols = PB.get_n_cols(); arma_debug_assert_mul_size(A_n_rows, A_n_cols, B_n_rows, B_n_cols, "matrix multiplication"); const uword N = (std::min)(A_n_rows, B_n_cols); eT val = eT(0); for(uword k=0; k < N; ++k) { eT acc1 = eT(0); eT acc2 = eT(0); uword j; for(j=1; j < A_n_cols; j+=2) { const uword i = (j-1); const eT tmp_i = PB.at(i, k); const eT tmp_j = PB.at(j, k); acc1 += PA.at(k, i) * tmp_i; acc2 += PA.at(k, j) * tmp_j; } const uword i = (j-1); if(i < A_n_cols) { acc1 += PA.at(k, i) * PB.at(i, k); } val += (acc1 + acc2); } return val; } //! speedup for trace(A*B), where the result of A*B is a square sized matrix template arma_hot arma_warn_unused inline typename T1::elem_type trace(const Glue& X) { arma_extra_debug_sigprint(); const Proxy PA(X.A); return (is_Mat::value) ? trace_mul_unwrap(PA, X.B) : trace_mul_proxy(PA, X.B); } //! trace of sparse object template arma_hot arma_warn_unused inline typename enable_if2::value, typename T1::elem_type>::result trace(const T1& x) { arma_extra_debug_sigprint(); const SpProxy p(x); typedef typename T1::elem_type eT; eT result = eT(0); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { if(it.row() == it.col()) { result += (*it); } ++it; } return result; } //! @} armadillo-6.500.5/include/armadillo_bits/spop_var_bones.hpp0000666000000000000000000000420512620272703022477 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_var //! @{ //! Class for finding variance values of a sparse matrix class spop_var { public: template inline static void apply(SpMat& out, const mtSpOp& in); template inline static void apply_noalias(SpMat& out, const SpProxy& p, const uword norm_type, const uword dim); // Calculate variance of a sparse vector, where we can directly use the memory. template inline static typename T1::pod_type var_vec(const T1& X, const uword norm_type = 0); // Calculate the variance directly. Because this is for sparse matrices, we // specify both the number of elements in the array (the length of the array) // as well as the actual number of elements when zeros are included. template inline static eT direct_var(const eT* const X, const uword length, const uword N, const uword norm_type = 0); // For complex numbers. template inline static T direct_var(const std::complex* const X, const uword length, const uword N, const uword norm_type = 0); // Calculate the variance using iterators, for non-complex numbers. template inline static eT iterator_var(T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_not_cx::result* junk2 = 0); // Calculate the variance using iterators, for complex numbers. template inline static typename get_pod_type::result iterator_var(T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_cx_only::result* junk2 = 0); }; //! @} armadillo-6.500.5/include/armadillo_bits/eglue_core_meat.hpp0000666000000000000000000007670012620272703022610 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eglue_core //! @{ #undef arma_applier_1u #undef arma_applier_1a #undef arma_applier_2 #undef arma_applier_3 #undef operatorA #undef operatorB #if defined(ARMA_SIMPLE_LOOPS) #define arma_applier_1u(operatorA, operatorB) \ {\ for(uword i=0; i template arma_hot inline void eglue_core::apply(outT& out, const eGlue& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() eT* out_mem = out.memptr(); if(prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(=, +); } else if(is_same_type::yes) { arma_applier_1a(=, -); } else if(is_same_type::yes) { arma_applier_1a(=, /); } else if(is_same_type::yes) { arma_applier_1a(=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(=, +); } else if(is_same_type::yes) { arma_applier_1u(=, -); } else if(is_same_type::yes) { arma_applier_1u(=, /); } else if(is_same_type::yes) { arma_applier_1u(=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(=, +); } else if(is_same_type::yes) { arma_applier_1u(=, -); } else if(is_same_type::yes) { arma_applier_1u(=, /); } else if(is_same_type::yes) { arma_applier_1u(=, *); } } } else { const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(=, +); } else if(is_same_type::yes) { arma_applier_2(=, -); } else if(is_same_type::yes) { arma_applier_2(=, /); } else if(is_same_type::yes) { arma_applier_2(=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_plus(Mat& out, const eGlue& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(+=, +); } else if(is_same_type::yes) { arma_applier_1a(+=, -); } else if(is_same_type::yes) { arma_applier_1a(+=, /); } else if(is_same_type::yes) { arma_applier_1a(+=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(+=, +); } else if(is_same_type::yes) { arma_applier_1u(+=, -); } else if(is_same_type::yes) { arma_applier_1u(+=, /); } else if(is_same_type::yes) { arma_applier_1u(+=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(+=, +); } else if(is_same_type::yes) { arma_applier_1u(+=, -); } else if(is_same_type::yes) { arma_applier_1u(+=, /); } else if(is_same_type::yes) { arma_applier_1u(+=, *); } } } else { const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(+=, +); } else if(is_same_type::yes) { arma_applier_2(+=, -); } else if(is_same_type::yes) { arma_applier_2(+=, /); } else if(is_same_type::yes) { arma_applier_2(+=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_minus(Mat& out, const eGlue& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(-=, +); } else if(is_same_type::yes) { arma_applier_1a(-=, -); } else if(is_same_type::yes) { arma_applier_1a(-=, /); } else if(is_same_type::yes) { arma_applier_1a(-=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(-=, +); } else if(is_same_type::yes) { arma_applier_1u(-=, -); } else if(is_same_type::yes) { arma_applier_1u(-=, /); } else if(is_same_type::yes) { arma_applier_1u(-=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(-=, +); } else if(is_same_type::yes) { arma_applier_1u(-=, -); } else if(is_same_type::yes) { arma_applier_1u(-=, /); } else if(is_same_type::yes) { arma_applier_1u(-=, *); } } } else { const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(-=, +); } else if(is_same_type::yes) { arma_applier_2(-=, -); } else if(is_same_type::yes) { arma_applier_2(-=, /); } else if(is_same_type::yes) { arma_applier_2(-=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_schur(Mat& out, const eGlue& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise multiplication"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(*=, +); } else if(is_same_type::yes) { arma_applier_1a(*=, -); } else if(is_same_type::yes) { arma_applier_1a(*=, /); } else if(is_same_type::yes) { arma_applier_1a(*=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(*=, +); } else if(is_same_type::yes) { arma_applier_1u(*=, -); } else if(is_same_type::yes) { arma_applier_1u(*=, /); } else if(is_same_type::yes) { arma_applier_1u(*=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(*=, +); } else if(is_same_type::yes) { arma_applier_1u(*=, -); } else if(is_same_type::yes) { arma_applier_1u(*=, /); } else if(is_same_type::yes) { arma_applier_1u(*=, *); } } } else { const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(*=, +); } else if(is_same_type::yes) { arma_applier_2(*=, -); } else if(is_same_type::yes) { arma_applier_2(*=, /); } else if(is_same_type::yes) { arma_applier_2(*=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_div(Mat& out, const eGlue& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise division"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename Proxy::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename Proxy::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(/=, +); } else if(is_same_type::yes) { arma_applier_1a(/=, -); } else if(is_same_type::yes) { arma_applier_1a(/=, /); } else if(is_same_type::yes) { arma_applier_1a(/=, *); } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(/=, +); } else if(is_same_type::yes) { arma_applier_1u(/=, -); } else if(is_same_type::yes) { arma_applier_1u(/=, /); } else if(is_same_type::yes) { arma_applier_1u(/=, *); } } } else { typename Proxy::ea_type P1 = x.P1.get_ea(); typename Proxy::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(/=, +); } else if(is_same_type::yes) { arma_applier_1u(/=, -); } else if(is_same_type::yes) { arma_applier_1u(/=, /); } else if(is_same_type::yes) { arma_applier_1u(/=, *); } } } else { const Proxy& P1 = x.P1; const Proxy& P2 = x.P2; if(is_same_type::yes) { arma_applier_2(/=, +); } else if(is_same_type::yes) { arma_applier_2(/=, -); } else if(is_same_type::yes) { arma_applier_2(/=, /); } else if(is_same_type::yes) { arma_applier_2(/=, *); } } } // // cubes template template arma_hot inline void eglue_core::apply(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Cube contructor or operator=() eT* out_mem = out.memptr(); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(=, +); } else if(is_same_type::yes) { arma_applier_1a(=, -); } else if(is_same_type::yes) { arma_applier_1a(=, /); } else if(is_same_type::yes) { arma_applier_1a(=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(=, +); } else if(is_same_type::yes) { arma_applier_1u(=, -); } else if(is_same_type::yes) { arma_applier_1u(=, /); } else if(is_same_type::yes) { arma_applier_1u(=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(=, +); } else if(is_same_type::yes) { arma_applier_1u(=, -); } else if(is_same_type::yes) { arma_applier_1u(=, /); } else if(is_same_type::yes) { arma_applier_1u(=, *); } } } else { const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(=, +); } else if(is_same_type::yes) { arma_applier_3(=, -); } else if(is_same_type::yes) { arma_applier_3(=, /); } else if(is_same_type::yes) { arma_applier_3(=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_plus(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(+=, +); } else if(is_same_type::yes) { arma_applier_1a(+=, -); } else if(is_same_type::yes) { arma_applier_1a(+=, /); } else if(is_same_type::yes) { arma_applier_1a(+=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(+=, +); } else if(is_same_type::yes) { arma_applier_1u(+=, -); } else if(is_same_type::yes) { arma_applier_1u(+=, /); } else if(is_same_type::yes) { arma_applier_1u(+=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(+=, +); } else if(is_same_type::yes) { arma_applier_1u(+=, -); } else if(is_same_type::yes) { arma_applier_1u(+=, /); } else if(is_same_type::yes) { arma_applier_1u(+=, *); } } } else { const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(+=, +); } else if(is_same_type::yes) { arma_applier_3(+=, -); } else if(is_same_type::yes) { arma_applier_3(+=, /); } else if(is_same_type::yes) { arma_applier_3(+=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_minus(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(-=, +); } else if(is_same_type::yes) { arma_applier_1a(-=, -); } else if(is_same_type::yes) { arma_applier_1a(-=, /); } else if(is_same_type::yes) { arma_applier_1a(-=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(-=, +); } else if(is_same_type::yes) { arma_applier_1u(-=, -); } else if(is_same_type::yes) { arma_applier_1u(-=, /); } else if(is_same_type::yes) { arma_applier_1u(-=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(-=, +); } else if(is_same_type::yes) { arma_applier_1u(-=, -); } else if(is_same_type::yes) { arma_applier_1u(-=, /); } else if(is_same_type::yes) { arma_applier_1u(-=, *); } } } else { const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(-=, +); } else if(is_same_type::yes) { arma_applier_3(-=, -); } else if(is_same_type::yes) { arma_applier_3(-=, /); } else if(is_same_type::yes) { arma_applier_3(-=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_schur(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(*=, +); } else if(is_same_type::yes) { arma_applier_1a(*=, -); } else if(is_same_type::yes) { arma_applier_1a(*=, /); } else if(is_same_type::yes) { arma_applier_1a(*=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(*=, +); } else if(is_same_type::yes) { arma_applier_1u(*=, -); } else if(is_same_type::yes) { arma_applier_1u(*=, /); } else if(is_same_type::yes) { arma_applier_1u(*=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(*=, +); } else if(is_same_type::yes) { arma_applier_1u(*=, -); } else if(is_same_type::yes) { arma_applier_1u(*=, /); } else if(is_same_type::yes) { arma_applier_1u(*=, *); } } } else { const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(*=, +); } else if(is_same_type::yes) { arma_applier_3(*=, -); } else if(is_same_type::yes) { arma_applier_3(*=, /); } else if(is_same_type::yes) { arma_applier_3(*=, *); } } } template template arma_hot inline void eglue_core::apply_inplace_div(Cube& out, const eGlueCube& x) { arma_extra_debug_sigprint(); const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); typedef typename T1::elem_type eT; eT* out_mem = out.memptr(); const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P1.is_aligned() && x.P2.is_aligned()) { typename ProxyCube::aligned_ea_type P1 = x.P1.get_aligned_ea(); typename ProxyCube::aligned_ea_type P2 = x.P2.get_aligned_ea(); if(is_same_type::yes) { arma_applier_1a(/=, +); } else if(is_same_type::yes) { arma_applier_1a(/=, -); } else if(is_same_type::yes) { arma_applier_1a(/=, /); } else if(is_same_type::yes) { arma_applier_1a(/=, *); } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(/=, +); } else if(is_same_type::yes) { arma_applier_1u(/=, -); } else if(is_same_type::yes) { arma_applier_1u(/=, /); } else if(is_same_type::yes) { arma_applier_1u(/=, *); } } } else { typename ProxyCube::ea_type P1 = x.P1.get_ea(); typename ProxyCube::ea_type P2 = x.P2.get_ea(); if(is_same_type::yes) { arma_applier_1u(/=, +); } else if(is_same_type::yes) { arma_applier_1u(/=, -); } else if(is_same_type::yes) { arma_applier_1u(/=, /); } else if(is_same_type::yes) { arma_applier_1u(/=, *); } } } else { const ProxyCube& P1 = x.P1; const ProxyCube& P2 = x.P2; if(is_same_type::yes) { arma_applier_3(/=, +); } else if(is_same_type::yes) { arma_applier_3(/=, -); } else if(is_same_type::yes) { arma_applier_3(/=, /); } else if(is_same_type::yes) { arma_applier_3(/=, *); } } } #undef arma_applier_1u #undef arma_applier_1a #undef arma_applier_2 #undef arma_applier_3 //! @} armadillo-6.500.5/include/armadillo_bits/fn_spsolve.hpp0000666000000000000000000001051712627351654021653 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup fn_spsolve //! @{ //! Solve a system of linear equations, i.e., A*X = B, where X is unknown, //! A is sparse, and B is dense. X will be dense too. template inline bool spsolve_helper ( Mat& out, const SpBase& A, const Base& B, const char* solver, const spsolve_opts_base& settings, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef typename T1::elem_type eT; const char sig = (solver != NULL) ? solver[0] : char(0); arma_debug_check( ((sig != 'l') && (sig != 's')), "spsolve(): unknown solver" ); T rcond = T(0); bool status = false; if(sig == 's') // SuperLU solver { const superlu_opts& opts = (settings.id == 1) ? static_cast(settings) : superlu_opts(); arma_debug_check( ( (opts.pivot_thresh < double(0)) || (opts.pivot_thresh > double(1)) ), "spsolve(): pivot_thresh out of bounds" ); if( (opts.equilibrate == false) && (opts.refine == superlu_opts::REF_NONE) ) { status = sp_auxlib::spsolve_simple(out, A.get_ref(), B.get_ref(), opts); } else { status = sp_auxlib::spsolve_refine(out, rcond, A.get_ref(), B.get_ref(), opts); } } else if(sig == 'l') // brutal LAPACK solver { if(settings.id != 0) { arma_debug_warn("spsolve(): ignoring settings not applicable to LAPACK based solver"); } Mat AA; bool conversion_ok = false; try { Mat tmp(A.get_ref()); // conversion from sparse to dense can throw std::bad_alloc AA.steal_mem(tmp); conversion_ok = true; } catch(std::bad_alloc&) { arma_debug_warn("spsolve(): not enough memory to use LAPACK based solver"); } if(conversion_ok) { arma_debug_check( (AA.n_rows != AA.n_cols), "spsolve(): matrix A must be square sized" ); status = auxlib::solve_square_refine(out, rcond, AA, B.get_ref(), false); } } if(status == false) { if(rcond > T(0)) { arma_debug_warn("spsolve(): system appears singular (rcond: ", rcond, ")"); } else { arma_debug_warn("spsolve(): system appears singular"); } out.reset(); } return status; } template inline bool spsolve ( Mat& out, const SpBase& A, const Base& B, const char* solver = "superlu", const spsolve_opts_base& settings = spsolve_opts_none(), const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = spsolve_helper(out, A.get_ref(), B.get_ref(), solver, settings); return status; } template inline Mat spsolve ( const SpBase& A, const Base& B, const char* solver = "superlu", const spsolve_opts_base& settings = spsolve_opts_none(), const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; Mat out; const bool status = spsolve_helper(out, A.get_ref(), B.get_ref(), solver, settings); if(status == false) { arma_bad("spsolve(): solution not found"); } return out; } //! @} armadillo-6.500.5/include/armadillo_bits/subview_field_bones.hpp0000666000000000000000000000547712633721645023521 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_field //! @{ //! Class for storing data required to construct or apply operations to a subfield //! (i.e. where the subfield starts and ends as well as a reference/pointer to the original field), template class subview_field { public: typedef oT object_type; const field& f; const uword aux_row1; const uword aux_col1; const uword aux_slice1; const uword n_rows; const uword n_cols; const uword n_slices; const uword n_elem; protected: arma_inline subview_field(const field& in_f, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); arma_inline subview_field(const field& in_f, const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices); public: inline ~subview_field(); inline void operator= (const field& x); inline void operator= (const subview_field& x); arma_inline oT& operator[](const uword i); arma_inline const oT& operator[](const uword i) const; arma_inline oT& operator()(const uword i); arma_inline const oT& operator()(const uword i) const; arma_inline oT& at(const uword row, const uword col); arma_inline const oT& at(const uword row, const uword col) const; arma_inline oT& at(const uword row, const uword col, const uword slice); arma_inline const oT& at(const uword row, const uword col, const uword slice) const; arma_inline oT& operator()(const uword row, const uword col); arma_inline const oT& operator()(const uword row, const uword col) const; arma_inline oT& operator()(const uword row, const uword col, const uword slice); arma_inline const oT& operator()(const uword row, const uword col, const uword slice) const; inline bool check_overlap(const subview_field& x) const; inline void print(const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const; template inline void for_each(functor F); template inline void for_each(functor F) const; inline void fill(const oT& x); inline static void extract(field& out, const subview_field& in); private: friend class field; subview_field(); //subview_field(const subview_field&); }; //! @} armadillo-6.500.5/include/armadillo_bits/spop_max_bones.hpp0000666000000000000000000000370712620272703022502 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_max //! @{ class spop_max { public: template inline static void apply(SpMat& out, const SpOp& in); // template inline static void apply_proxy(SpMat& out, const SpProxy& p, const uword dim, const typename arma_not_cx::result* junk = 0); template inline static typename T1::elem_type vector_max(const T1& X, const typename arma_not_cx::result* junk = 0); template inline static typename arma_not_cx::result max(const SpBase& X); template inline static typename arma_not_cx::result max_with_index(const SpProxy& P, uword& index_of_max_val); // template inline static void apply_proxy(SpMat& out, const SpProxy& p, const uword dim, const typename arma_cx_only::result* junk = 0); template inline static typename T1::elem_type vector_max(const T1& X, const typename arma_cx_only::result* junk = 0); template inline static typename arma_cx_only::result max(const SpBase& X); template inline static typename arma_cx_only::result max_with_index(const SpProxy& P, uword& index_of_max_val); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_diff_meat.hpp0000666000000000000000000001075512620272703022103 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_diff //! @{ template inline void op_diff::apply_noalias(Mat& out, const Mat& X, const uword k, const uword dim) { arma_extra_debug_sigprint(); uword n_rows = X.n_rows; uword n_cols = X.n_cols; if(dim == 0) { if(n_rows <= k) { out.set_size(0,n_cols); return; } --n_rows; out.set_size(n_rows,n_cols); for(uword col=0; col < n_cols; ++col) { eT* out_colmem = out.colptr(col); const eT* X_colmem = X.colptr(col); for(uword row=0; row < n_rows; ++row) { const eT val0 = X_colmem[row ]; const eT val1 = X_colmem[row+1]; out_colmem[row] = val1 - val0; } } if(k >= 2) { for(uword iter=2; iter <= k; ++iter) { --n_rows; for(uword col=0; col < n_cols; ++col) { eT* colmem = out.colptr(col); for(uword row=0; row < n_rows; ++row) { const eT val0 = colmem[row ]; const eT val1 = colmem[row+1]; colmem[row] = val1 - val0; } } } out = out( span(0,n_rows-1), span::all ); } } else if(dim == 1) { if(n_cols <= k) { out.set_size(n_rows,0); return; } --n_cols; out.set_size(n_rows,n_cols); if(n_rows == 1) { const eT* X_mem = X.memptr(); eT* out_mem = out.memptr(); for(uword col=0; col < n_cols; ++col) { const eT val0 = X_mem[col ]; const eT val1 = X_mem[col+1]; out_mem[col] = val1 - val0; } } else { for(uword col=0; col < n_cols; ++col) { eT* out_col_mem = out.colptr(col); const eT* X_col0_mem = X.colptr(col ); const eT* X_col1_mem = X.colptr(col+1); for(uword row=0; row < n_rows; ++row) { out_col_mem[row] = X_col1_mem[row] - X_col0_mem[row]; } } } if(k >= 2) { for(uword iter=2; iter <= k; ++iter) { --n_cols; if(n_rows == 1) { eT* out_mem = out.memptr(); for(uword col=0; col < n_cols; ++col) { const eT val0 = out_mem[col ]; const eT val1 = out_mem[col+1]; out_mem[col] = val1 - val0; } } else { for(uword col=0; col < n_cols; ++col) { eT* col0_mem = out.colptr(col ); const eT* col1_mem = out.colptr(col+1); for(uword row=0; row < n_rows; ++row) { col0_mem[row] = col1_mem[row] - col0_mem[row]; } } } } out = out( span::all, span(0,n_cols-1) ); } } } template inline void op_diff::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword k = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check( (dim > 1), "diff(): parameter 'dim' must be 0 or 1" ); if(k == 0) { out = in.m; return; } const quasi_unwrap U(in.m); if(U.is_alias(out)) { Mat tmp; op_diff::apply_noalias(tmp, U.M, k, dim); out.steal_mem(tmp); } else { op_diff::apply_noalias(out, U.M, k, dim); } } template inline void op_diff_default::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword k = in.aux_uword_a; if(k == 0) { out = in.m; return; } const quasi_unwrap U(in.m); const uword dim = (T1::is_row) ? 1 : 0; if(U.is_alias(out)) { Mat tmp; op_diff::apply_noalias(tmp, U.M, k, dim); out.steal_mem(tmp); } else { op_diff::apply_noalias(out, U.M, k, dim); } } //! @} armadillo-6.500.5/include/armadillo_bits/fn_stddev.hpp0000666000000000000000000000350512620272703021436 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_stddev //! @{ template inline const mtOp stddev ( const T1& X, const uword norm_type = 0, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtOp(X, norm_type, dim); } template inline const mtOp stddev ( const T1& X, const uword norm_type, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOp(X, norm_type, dim); } template inline arma_warn_unused typename T1::pod_type stddev ( const T1& X, const uword norm_type = 0, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return std::sqrt( op_var::var_vec(X, norm_type) ); } template arma_inline arma_warn_unused const typename arma_scalar_only::result stddev(const T&) { return T(0); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_trans.hpp0000666000000000000000000000532612620272703021277 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_trans //! @{ template arma_inline const Op trans ( const T1& X, const typename enable_if< is_arma_type::value == true >::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X); } template arma_inline const Op htrans ( const T1& X, const typename enable_if< is_arma_type::value == true >::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X); } //! two consecutive transpose operations cancel each other template arma_inline const T1& trans(const Op& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("trans(): removing op_htrans"); return X.m; } template arma_inline const T1& htrans(const Op& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("htrans(): removing op_htrans"); return X.m; } // // handling of sparse matrices template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result trans ( const T1& x, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(x); } template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result trans ( const T1& x, const typename arma_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(x); } template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result htrans ( const T1& x, const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(x); } template inline typename enable_if2 < is_arma_sparse_type::value, const SpOp >::result htrans ( const T1& x, const typename arma_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(x); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_dot.hpp0000666000000000000000000001511212620272703020730 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup fn_dot //! @{ template arma_inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::yes, typename T1::elem_type >::result dot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_dot::apply(A,B); } template inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::no, typename promote_type::result >::result dot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_dot_mixed::apply(A,B); } template inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, typename T1::elem_type >::result norm_dot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_norm_dot::apply(A,B); } // // cdot template arma_inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value && is_not_complex::value, typename T1::elem_type >::result cdot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_dot::apply(A,B); } template arma_inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value && is_complex::value, typename T1::elem_type >::result cdot ( const T1& A, const T2& B ) { arma_extra_debug_sigprint(); return op_cdot::apply(A,B); } // convert dot(htrans(x), y) to cdot(x,y) template arma_inline arma_warn_unused typename enable_if2 < is_arma_type::value && is_same_type::value && is_complex::value, typename T1::elem_type >::result dot ( const Op& A, const T2& B ) { arma_extra_debug_sigprint(); return cdot(A.m, B); } // // for sparse matrices // namespace priv { template arma_hot inline typename T1::elem_type dot_helper(const SpProxy& pa, const SpProxy& pb) { typedef typename T1::elem_type eT; // Iterate over both objects and see when they are the same eT result = eT(0); typename SpProxy::const_iterator_type a_it = pa.begin(); typename SpProxy::const_iterator_type a_end = pa.end(); typename SpProxy::const_iterator_type b_it = pb.begin(); typename SpProxy::const_iterator_type b_end = pb.end(); while((a_it != a_end) && (b_it != b_end)) { if(a_it == b_it) { result += (*a_it) * (*b_it); ++a_it; ++b_it; } else if((a_it.col() < b_it.col()) || ((a_it.col() == b_it.col()) && (a_it.row() < b_it.row()))) { // a_it is "behind" ++a_it; } else { // b_it is "behind" ++b_it; } } return result; } } //! dot product of two sparse objects template arma_warn_unused arma_hot inline typename enable_if2 <(is_arma_sparse_type::value) && (is_arma_sparse_type::value) && (is_same_type::value), typename T1::elem_type >::result dot ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const SpProxy pa(x); const SpProxy pb(y); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "dot()"); typedef typename T1::elem_type eT; typedef typename SpProxy::stored_type pa_Q_type; typedef typename SpProxy::stored_type pb_Q_type; if( ( (SpProxy::must_use_iterator == false) && (SpProxy::must_use_iterator == false) ) && ( (is_SpMat::value == true ) && (is_SpMat::value == true ) ) ) { const unwrap_spmat tmp_a(pa.Q); const unwrap_spmat tmp_b(pb.Q); const SpMat& A = tmp_a.M; const SpMat& B = tmp_b.M; if( &A == &B ) { // We can do it directly! return op_dot::direct_dot_arma(A.n_nonzero, A.values, A.values); } else { return priv::dot_helper(pa,pb); } } else { return priv::dot_helper(pa,pb); } } //! dot product of one dense and one sparse object template arma_warn_unused arma_hot inline typename enable_if2 <(is_arma_type::value) && (is_arma_sparse_type::value) && (is_same_type::value), typename T1::elem_type >::result dot ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const Proxy pa(x); const SpProxy pb(y); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "dot()"); typedef typename T1::elem_type eT; eT result = eT(0); typename SpProxy::const_iterator_type it = pb.begin(); typename SpProxy::const_iterator_type it_end = pb.end(); // prefer_at_accessor won't save us operations while(it != it_end) { result += (*it) * pa.at(it.row(), it.col()); ++it; } return result; } //! dot product of one sparse and one dense object template arma_warn_unused arma_hot inline typename enable_if2 <(is_arma_sparse_type::value) && (is_arma_type::value) && (is_same_type::value), typename T1::elem_type >::result dot ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); // this is commutative return dot(y, x); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_max.hpp0000666000000000000000000001016112620272703020726 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_max //! @{ //! \brief //! Delayed 'maximum values' operation. //! The dimension, along which the maxima are found, is set via 'dim'. //! For dim = 0, the maximum value of each column is found (i.e. searches by traversing across rows). //! For dim = 1, the maximum value of each row is found (i.e. searches by traversing across columns). //! The default is dim = 0. template arma_inline const Op max ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op max ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type max ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_max::max(X); } //! \brief //! Immediate 'find maximum value' operation, //! invoked, for example, by: max(max(A)) template inline arma_warn_unused typename T1::elem_type max(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("max(): two consecutive max() calls detected"); return op_max::max(in.m); } template arma_inline const Op< Op, op_max> max(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op< Op, op_max>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & max(const T& x) { return x; } //! element-wise maximum template arma_inline typename enable_if2 < ( is_arma_type::value && is_arma_type::value && is_same_type::value ), const Glue >::result max ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return Glue(X, Y); } template inline arma_warn_unused typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == true), typename T1::elem_type >::result max(const T1& x) { arma_extra_debug_sigprint(); return spop_max::vector_max(x); } template inline typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == false), const SpOp >::result max(const T1& X, const uword dim = 0) { arma_extra_debug_sigprint(); return SpOp(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type max(const SpOp& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("max(): two consecutive max() calls detected"); return spop_max::vector_max(X.m); } template inline const SpOp< SpOp, spop_max> max(const SpOp& in, const uword dim) { arma_extra_debug_sigprint(); return SpOp< SpOp, spop_max>(in, dim, 0); } inline uword max(const SizeMat& s) { return (std::max)(s.n_rows, s.n_cols); } inline uword max(const SizeCube& s) { return (std::max)( (std::max)(s.n_rows, s.n_cols), s.n_slices ); } //! @} armadillo-6.500.5/include/armadillo_bits/diagmat_proxy.hpp0000666000000000000000000003611512620272703022334 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup diagmat_proxy //! @{ template class diagmat_proxy_default { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_default(const T1& X) : P ( X ) , P_is_vec( (resolves_to_vector::value) || (P.get_n_rows() == 1) || (P.get_n_cols() == 1) ) , P_is_col( T1::is_col || (P.get_n_cols() == 1) ) , n_rows ( P_is_vec ? P.get_n_elem() : P.get_n_rows() ) , n_cols ( P_is_vec ? P.get_n_elem() : P.get_n_cols() ) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[](const uword i) const { if(Proxy::prefer_at_accessor == false) { return P_is_vec ? P[i] : P.at(i,i); } else { if(P_is_vec) { return (P_is_col) ? P.at(i,0) : P.at(0,i); } else { return P.at(i,i); } } } arma_inline elem_type at(const uword row, const uword col) const { if(row == col) { if(Proxy::prefer_at_accessor == false) { return (P_is_vec) ? P[row] : P.at(row,row); } else { if(P_is_vec) { return (P_is_col) ? P.at(row,0) : P.at(0,row); } else { return P.at(row,row); } } } else { return elem_type(0); } } arma_inline bool is_alias(const Mat&) const { return false; } const Proxy P; const bool P_is_vec; const bool P_is_col; const uword n_rows; const uword n_cols; }; template class diagmat_proxy_fixed { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_fixed(const T1& X) : P(X) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[](const uword i) const { return (P_is_vec) ? P[i] : P.at(i,i); } arma_inline elem_type at(const uword row, const uword col) const { if(row == col) { return (P_is_vec) ? P[row] : P.at(row,row); } else { return elem_type(0); } } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&P)); } const T1& P; static const bool P_is_vec = (T1::n_rows == 1) || (T1::n_cols == 1); static const uword n_rows = P_is_vec ? T1::n_elem : T1::n_rows; static const uword n_cols = P_is_vec ? T1::n_elem : T1::n_cols; }; template struct diagmat_proxy_redirect {}; template struct diagmat_proxy_redirect { typedef diagmat_proxy_default result; }; template struct diagmat_proxy_redirect { typedef diagmat_proxy_fixed result; }; template class diagmat_proxy : public diagmat_proxy_redirect::value >::result { public: inline diagmat_proxy(const T1& X) : diagmat_proxy_redirect< T1, is_Mat_fixed::value >::result(X) { } }; template class diagmat_proxy< Mat > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const Mat& X) : P ( X ) , P_is_vec( (X.n_rows == 1) || (X.n_cols == 1) ) , n_rows ( P_is_vec ? X.n_elem : X.n_rows ) , n_cols ( P_is_vec ? X.n_elem : X.n_cols ) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P_is_vec ? P[i] : P.at(i,i); } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&P)); } const Mat& P; const bool P_is_vec; const uword n_rows; const uword n_cols; }; template class diagmat_proxy< Row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const Row& X) : P(X) , n_rows(X.n_elem) , n_cols(X.n_elem) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&P)); } static const bool P_is_vec = true; const Row& P; const uword n_rows; const uword n_cols; }; template class diagmat_proxy< Col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const Col& X) : P(X) , n_rows(X.n_elem) , n_cols(X.n_elem) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&P)); } static const bool P_is_vec = true; const Col& P; const uword n_rows; const uword n_cols; }; template class diagmat_proxy< subview_row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const subview_row& X) : P(X) , n_rows(X.n_elem) , n_cols(X.n_elem) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&(P.m))); } static const bool P_is_vec = true; const subview_row& P; const uword n_rows; const uword n_cols; }; template class diagmat_proxy< subview_col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy(const subview_col& X) : P(X) , n_rows(X.n_elem) , n_cols(X.n_elem) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&(P.m))); } static const bool P_is_vec = true; const subview_col& P; const uword n_rows; const uword n_cols; }; // // // template class diagmat_proxy_check_default { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check_default(const T1& X, const Mat&) : P(X) , P_is_vec( (resolves_to_vector::value) || (P.n_rows == 1) || (P.n_cols == 1) ) , n_rows( P_is_vec ? P.n_elem : P.n_rows ) , n_cols( P_is_vec ? P.n_elem : P.n_cols ) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P_is_vec ? P[i] : P.at(i,i); } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); } const Mat P; const bool P_is_vec; const uword n_rows; const uword n_cols; }; template class diagmat_proxy_check_fixed { public: typedef typename T1::elem_type eT; typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check_fixed(const T1& X, const Mat& out) : P( const_cast(X.memptr()), T1::n_rows, T1::n_cols, (&X == &out), false ) { arma_extra_debug_sigprint(); } arma_inline eT operator[] (const uword i) const { return P_is_vec ? P[i] : P.at(i,i); } arma_inline eT at (const uword row, const uword col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); } const Mat P; // TODO: why not just store X directly as T1& ? test with fixed size vectors and matrices static const bool P_is_vec = (T1::n_rows == 1) || (T1::n_cols == 1); static const uword n_rows = P_is_vec ? T1::n_elem : T1::n_rows; static const uword n_cols = P_is_vec ? T1::n_elem : T1::n_cols; }; template struct diagmat_proxy_check_redirect {}; template struct diagmat_proxy_check_redirect { typedef diagmat_proxy_check_default result; }; template struct diagmat_proxy_check_redirect { typedef diagmat_proxy_check_fixed result; }; template class diagmat_proxy_check : public diagmat_proxy_check_redirect::value >::result { public: inline diagmat_proxy_check(const T1& X, const Mat& out) : diagmat_proxy_check_redirect< T1, is_Mat_fixed::value >::result(X, out) { } }; template class diagmat_proxy_check< Mat > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const Mat& X, const Mat& out) : P_local ( (&X == &out) ? new Mat(X) : 0 ) , P ( (&X == &out) ? (*P_local) : X ) , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) ) , n_rows ( P_is_vec ? P.n_elem : P.n_rows ) , n_cols ( P_is_vec ? P.n_elem : P.n_cols ) { arma_extra_debug_sigprint(); } inline ~diagmat_proxy_check() { if(P_local) { delete P_local; } } arma_inline elem_type operator[] (const uword i) const { return P_is_vec ? P[i] : P.at(i,i); } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); } const Mat* P_local; const Mat& P; const bool P_is_vec; const uword n_rows; const uword n_cols; }; template class diagmat_proxy_check< Row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const Row& X, const Mat& out) : P_local ( (&X == reinterpret_cast*>(&out)) ? new Row(X) : 0 ) , P ( (&X == reinterpret_cast*>(&out)) ? (*P_local) : X ) , n_rows (X.n_elem) , n_cols (X.n_elem) { arma_extra_debug_sigprint(); } inline ~diagmat_proxy_check() { if(P_local) { delete P_local; } } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Row* P_local; const Row& P; const uword n_rows; const uword n_cols; }; template class diagmat_proxy_check< Col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const Col& X, const Mat& out) : P_local ( (&X == reinterpret_cast*>(&out)) ? new Col(X) : 0 ) , P ( (&X == reinterpret_cast*>(&out)) ? (*P_local) : X ) , n_rows (X.n_elem) , n_cols (X.n_elem) { arma_extra_debug_sigprint(); } inline ~diagmat_proxy_check() { if(P_local) { delete P_local; } } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Col* P_local; const Col& P; const uword n_rows; const uword n_cols; }; template class diagmat_proxy_check< subview_row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const subview_row& X, const Mat&) : P ( X ) , n_rows ( X.n_elem ) , n_cols ( X.n_elem ) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Row P; const uword n_rows; const uword n_cols; }; template class diagmat_proxy_check< subview_col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline diagmat_proxy_check(const subview_col& X, const Mat& out) : P ( const_cast(X.colptr(0)), X.n_rows, (&(X.m) == &out), false ) , n_rows( X.n_elem ) , n_cols( X.n_elem ) { arma_extra_debug_sigprint(); } arma_inline elem_type operator[] (const uword i) const { return P[i]; } arma_inline elem_type at (const uword row, const uword col) const { return (row == col) ? P[row] : elem_type(0); } static const bool P_is_vec = true; const Col P; const uword n_rows; const uword n_cols; }; //! @} armadillo-6.500.5/include/armadillo_bits/traits.hpp0000666000000000000000000007714212623015476021005 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup traits //! @{ template struct get_pod_type { typedef T1 result; }; template struct get_pod_type< std::complex > { typedef T2 result; }; template struct is_Mat_fixed_only { typedef char yes[1]; typedef char no[2]; template static yes& check(typename X::Mat_fixed_type*); template static no& check(...); static const bool value = ( sizeof(check(0)) == sizeof(yes) ); }; template struct is_Row_fixed_only { typedef char yes[1]; typedef char no[2]; template static yes& check(typename X::Row_fixed_type*); template static no& check(...); static const bool value = ( sizeof(check(0)) == sizeof(yes) ); }; template struct is_Col_fixed_only { typedef char yes[1]; typedef char no[2]; template static yes& check(typename X::Col_fixed_type*); template static no& check(...); static const bool value = ( sizeof(check(0)) == sizeof(yes) ); }; template struct is_Mat_fixed { static const bool value = ( is_Mat_fixed_only::value || is_Row_fixed_only::value || is_Col_fixed_only::value ); }; template struct is_Mat_only { static const bool value = is_Mat_fixed_only::value; }; template struct is_Mat_only< Mat > { static const bool value = true; }; template struct is_Mat_only< const Mat > { static const bool value = true; }; template struct is_Mat { static const bool value = ( is_Mat_fixed_only::value || is_Row_fixed_only::value || is_Col_fixed_only::value ); }; template struct is_Mat< Mat > { static const bool value = true; }; template struct is_Mat< const Mat > { static const bool value = true; }; template struct is_Mat< Row > { static const bool value = true; }; template struct is_Mat< const Row > { static const bool value = true; }; template struct is_Mat< Col > { static const bool value = true; }; template struct is_Mat< const Col > { static const bool value = true; }; template struct is_Row { static const bool value = is_Row_fixed_only::value; }; template struct is_Row< Row > { static const bool value = true; }; template struct is_Row< const Row > { static const bool value = true; }; template struct is_Col { static const bool value = is_Col_fixed_only::value; }; template struct is_Col< Col > { static const bool value = true; }; template struct is_Col< const Col > { static const bool value = true; }; template struct is_diagview { static const bool value = false; }; template struct is_diagview< diagview > { static const bool value = true; }; template struct is_diagview< const diagview > { static const bool value = true; }; template struct is_subview { static const bool value = false; }; template struct is_subview< subview > { static const bool value = true; }; template struct is_subview< const subview > { static const bool value = true; }; template struct is_subview_row { static const bool value = false; }; template struct is_subview_row< subview_row > { static const bool value = true; }; template struct is_subview_row< const subview_row > { static const bool value = true; }; template struct is_subview_col { static const bool value = false; }; template struct is_subview_col< subview_col > { static const bool value = true; }; template struct is_subview_col< const subview_col > { static const bool value = true; }; template struct is_subview_elem1 { static const bool value = false; }; template struct is_subview_elem1< subview_elem1 > { static const bool value = true; }; template struct is_subview_elem1< const subview_elem1 > { static const bool value = true; }; template struct is_subview_elem2 { static const bool value = false; }; template struct is_subview_elem2< subview_elem2 > { static const bool value = true; }; template struct is_subview_elem2< const subview_elem2 > { static const bool value = true; }; // // // template struct is_Cube { static const bool value = false; }; template struct is_Cube< Cube > { static const bool value = true; }; template struct is_subview_cube { static const bool value = false; }; template struct is_subview_cube< subview_cube > { static const bool value = true; }; // // // template struct is_Gen { static const bool value = false; }; template struct is_Gen< Gen > { static const bool value = true; }; template struct is_Gen< const Gen > { static const bool value = true; }; template struct is_Op { static const bool value = false; }; template struct is_Op< Op > { static const bool value = true; }; template struct is_Op< const Op > { static const bool value = true; }; template struct is_eOp { static const bool value = false; }; template struct is_eOp< eOp > { static const bool value = true; }; template struct is_eOp< const eOp > { static const bool value = true; }; template struct is_mtOp { static const bool value = false; }; template struct is_mtOp< mtOp > { static const bool value = true; }; template struct is_mtOp< const mtOp > { static const bool value = true; }; template struct is_Glue { static const bool value = false; }; template struct is_Glue< Glue > { static const bool value = true; }; template struct is_Glue< const Glue > { static const bool value = true; }; template struct is_eGlue { static const bool value = false; }; template struct is_eGlue< eGlue > { static const bool value = true; }; template struct is_eGlue< const eGlue > { static const bool value = true; }; template struct is_mtGlue { static const bool value = false; }; template struct is_mtGlue< mtGlue > { static const bool value = true; }; template struct is_mtGlue< const mtGlue > { static const bool value = true; }; // // template struct is_glue_times { static const bool value = false; }; template struct is_glue_times< Glue > { static const bool value = true; }; template struct is_glue_times< const Glue > { static const bool value = true; }; template struct is_glue_times_diag { static const bool value = false; }; template struct is_glue_times_diag< Glue > { static const bool value = true; }; template struct is_glue_times_diag< const Glue > { static const bool value = true; }; template struct is_op_diagmat { static const bool value = false; }; template struct is_op_diagmat< Op > { static const bool value = true; }; template struct is_op_diagmat< const Op > { static const bool value = true; }; template struct is_op_strans { static const bool value = false; }; template struct is_op_strans< Op > { static const bool value = true; }; template struct is_op_strans< const Op > { static const bool value = true; }; template struct is_op_htrans { static const bool value = false; }; template struct is_op_htrans< Op > { static const bool value = true; }; template struct is_op_htrans< const Op > { static const bool value = true; }; template struct is_op_htrans2 { static const bool value = false; }; template struct is_op_htrans2< Op > { static const bool value = true; }; template struct is_op_htrans2< const Op > { static const bool value = true; }; // // template struct is_Mat_trans { static const bool value = false; }; template struct is_Mat_trans< Op > { static const bool value = is_Mat::value; }; template struct is_Mat_trans< Op > { static const bool value = is_Mat::value; }; // // template struct is_GenCube { static const bool value = false; }; template struct is_GenCube< GenCube > { static const bool value = true; }; template struct is_OpCube { static const bool value = false; }; template struct is_OpCube< OpCube > { static const bool value = true; }; template struct is_eOpCube { static const bool value = false; }; template struct is_eOpCube< eOpCube > { static const bool value = true; }; template struct is_mtOpCube { static const bool value = false; }; template struct is_mtOpCube< mtOpCube > { static const bool value = true; }; template struct is_GlueCube { static const bool value = false; }; template struct is_GlueCube< GlueCube > { static const bool value = true; }; template struct is_eGlueCube { static const bool value = false; }; template struct is_eGlueCube< eGlueCube > { static const bool value = true; }; template struct is_mtGlueCube { static const bool value = false; }; template struct is_mtGlueCube< mtGlueCube > { static const bool value = true; }; // // // template struct is_op_rel { static const bool value = false; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; template struct is_op_rel< mtOp > { static const bool value = true; }; // // // template struct is_basevec { static const bool value = ( is_Row_fixed_only::value || is_Col_fixed_only::value ); }; template struct is_basevec< Row > { static const bool value = true; }; template struct is_basevec< const Row > { static const bool value = true; }; template struct is_basevec< Col > { static const bool value = true; }; template struct is_basevec< const Col > { static const bool value = true; }; template struct is_basevec< subview_row > { static const bool value = true; }; template struct is_basevec< const subview_row > { static const bool value = true; }; template struct is_basevec< subview_col > { static const bool value = true; }; template struct is_basevec< const subview_col > { static const bool value = true; }; template struct is_basevec< diagview > { static const bool value = true; }; template struct is_basevec< const diagview > { static const bool value = true; }; template struct is_basevec< subview_elem1 > { static const bool value = true; }; template struct is_basevec< const subview_elem1 > { static const bool value = true; }; // // // template struct is_arma_type { static const bool value = is_Mat::value || is_Gen::value || is_Op::value || is_Glue::value || is_eOp::value || is_eGlue::value || is_mtOp::value || is_mtGlue::value || is_diagview::value || is_subview::value || is_subview_row::value || is_subview_col::value || is_subview_elem1::value || is_subview_elem2::value ; }; template struct is_arma_cube_type { static const bool value = is_Cube::value || is_GenCube::value || is_OpCube::value || is_eOpCube::value || is_mtOpCube::value || is_GlueCube::value || is_eGlueCube::value || is_mtGlueCube::value || is_subview_cube::value ; }; // // // template struct is_SpMat { static const bool value = false; }; template struct is_SpMat< SpMat > { static const bool value = true; }; template struct is_SpMat< SpCol > { static const bool value = true; }; template struct is_SpMat< SpRow > { static const bool value = true; }; template struct is_SpRow { static const bool value = false; }; template struct is_SpRow< SpRow > { static const bool value = true; }; template struct is_SpCol { static const bool value = false; }; template struct is_SpCol< SpCol > { static const bool value = true; }; template struct is_SpSubview { static const bool value = false; }; template struct is_SpSubview< SpSubview > { static const bool value = true; }; template struct is_SpOp { static const bool value = false; }; template struct is_SpOp< SpOp > { static const bool value = true; }; template struct is_SpGlue { static const bool value = false; }; template struct is_SpGlue< SpGlue > { static const bool value = true; }; template struct is_mtSpOp { static const bool value = false; }; template struct is_mtSpOp< mtSpOp > { static const bool value = true; }; template struct is_arma_sparse_type { static const bool value = is_SpMat::value || is_SpSubview::value || is_SpOp::value || is_SpGlue::value || is_mtSpOp::value ; }; // // // template struct is_same_type { static const bool value = false; static const bool yes = false; static const bool no = true; }; template struct is_same_type { static const bool value = true; static const bool yes = true; static const bool no = false; }; // // // template struct is_u8 { static const bool value = false; }; template<> struct is_u8 { static const bool value = true; }; template struct is_s8 { static const bool value = false; }; template<> struct is_s8 { static const bool value = true; }; template struct is_u16 { static const bool value = false; }; template<> struct is_u16 { static const bool value = true; }; template struct is_s16 { static const bool value = false; }; template<> struct is_s16 { static const bool value = true; }; template struct is_u32 { static const bool value = false; }; template<> struct is_u32 { static const bool value = true; }; template struct is_s32 { static const bool value = false; }; template<> struct is_s32 { static const bool value = true; }; #if defined(ARMA_USE_U64S64) template struct is_u64 { static const bool value = false; }; template<> struct is_u64 { static const bool value = true; }; template struct is_s64 { static const bool value = false; }; template<> struct is_s64 { static const bool value = true; }; #endif template struct is_ulng_t { static const bool value = false; }; template<> struct is_ulng_t { static const bool value = true; }; template struct is_slng_t { static const bool value = false; }; template<> struct is_slng_t { static const bool value = true; }; template struct is_ulng_t_32 { static const bool value = false; }; template<> struct is_ulng_t_32 { static const bool value = (sizeof(ulng_t) == 4); }; template struct is_slng_t_32 { static const bool value = false; }; template<> struct is_slng_t_32 { static const bool value = (sizeof(slng_t) == 4); }; template struct is_ulng_t_64 { static const bool value = false; }; template<> struct is_ulng_t_64 { static const bool value = (sizeof(ulng_t) == 8); }; template struct is_slng_t_64 { static const bool value = false; }; template<> struct is_slng_t_64 { static const bool value = (sizeof(slng_t) == 8); }; template struct is_uword { static const bool value = false; }; template<> struct is_uword { static const bool value = true; }; template struct is_sword { static const bool value = false; }; template<> struct is_sword { static const bool value = true; }; template struct is_float { static const bool value = false; }; template<> struct is_float { static const bool value = true; }; template struct is_double { static const bool value = false; }; template<> struct is_double { static const bool value = true; }; template struct is_real { static const bool value = false; }; template<> struct is_real { static const bool value = true; }; template<> struct is_real { static const bool value = true; }; template struct is_not_complex { static const bool value = true; }; template struct is_not_complex< std::complex > { static const bool value = false; }; template struct is_complex { static const bool value = false; }; // template<> template struct is_complex< std::complex > { static const bool value = true; }; template struct is_complex_float { static const bool value = false; }; template<> struct is_complex_float< std::complex > { static const bool value = true; }; template struct is_complex_double { static const bool value = false; }; template<> struct is_complex_double< std::complex > { static const bool value = true; }; template struct is_complex_strict { static const bool value = false; }; template<> struct is_complex_strict< std::complex > { static const bool value = true; }; template<> struct is_complex_strict< std::complex > { static const bool value = true; }; template struct is_cx { static const bool value = false; static const bool yes = false; static const bool no = true; }; // template<> template struct is_cx< std::complex > { static const bool value = true; static const bool yes = true; static const bool no = false; }; //! check for a weird implementation of the std::complex class template struct is_supported_complex { static const bool value = false; }; //template<> template struct is_supported_complex< std::complex > { static const bool value = ( sizeof(std::complex) == 2*sizeof(eT) ); }; template struct is_supported_complex_float { static const bool value = false; }; template<> struct is_supported_complex_float< std::complex > { static const bool value = ( sizeof(std::complex) == 2*sizeof(float) ); }; template struct is_supported_complex_double { static const bool value = false; }; template<> struct is_supported_complex_double< std::complex > { static const bool value = ( sizeof(std::complex) == 2*sizeof(double) ); }; template struct is_supported_elem_type { static const bool value = \ is_u8::value || is_s8::value || is_u16::value || is_s16::value || is_u32::value || is_s32::value || #if defined(ARMA_USE_U64S64) is_u64::value || is_s64::value || #endif #if defined(ARMA_ALLOW_LONG) is_ulng_t::value || is_slng_t::value || #endif is_float::value || is_double::value || is_supported_complex_float::value || is_supported_complex_double::value; }; template struct is_supported_blas_type { static const bool value = \ is_float::value || is_double::value || is_supported_complex_float::value || is_supported_complex_double::value; }; template struct is_signed { static const bool value = true; }; template<> struct is_signed { static const bool value = false; }; template<> struct is_signed { static const bool value = false; }; template<> struct is_signed { static const bool value = false; }; #if defined(ARMA_USE_U64S64) template<> struct is_signed { static const bool value = false; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_signed { static const bool value = false; }; #endif template struct is_non_integral { static const bool value = false; }; template<> struct is_non_integral< float > { static const bool value = true; }; template<> struct is_non_integral< double > { static const bool value = true; }; template<> struct is_non_integral< std::complex > { static const bool value = true; }; template<> struct is_non_integral< std::complex > { static const bool value = true; }; // class arma_junk_class; template struct force_different_type { typedef T1 T1_result; typedef T2 T2_result; }; template struct force_different_type { typedef T1 T1_result; typedef arma_junk_class T2_result; }; // template struct resolves_to_vector_default { static const bool value = false; }; template struct resolves_to_vector_test { static const bool value = T1::is_col || T1::is_row; }; template struct resolves_to_vector_redirect {}; template struct resolves_to_vector_redirect { typedef resolves_to_vector_default result; }; template struct resolves_to_vector_redirect { typedef resolves_to_vector_test result; }; template struct resolves_to_vector : public resolves_to_vector_redirect::value>::result {}; template struct resolves_to_sparse_vector : public resolves_to_vector_redirect::value>::result {}; // template struct resolves_to_rowvector_default { static const bool value = false; }; template struct resolves_to_rowvector_test { static const bool value = T1::is_row; }; template struct resolves_to_rowvector_redirect {}; template struct resolves_to_rowvector_redirect { typedef resolves_to_rowvector_default result; }; template struct resolves_to_rowvector_redirect { typedef resolves_to_rowvector_test result; }; template struct resolves_to_rowvector : public resolves_to_rowvector_redirect::value>::result {}; // template struct resolves_to_colvector_default { static const bool value = false; }; template struct resolves_to_colvector_test { static const bool value = T1::is_col; }; template struct resolves_to_colvector_redirect {}; template struct resolves_to_colvector_redirect { typedef resolves_to_colvector_default result; }; template struct resolves_to_colvector_redirect { typedef resolves_to_colvector_test result; }; template struct resolves_to_colvector : public resolves_to_colvector_redirect::value>::result {}; template struct is_glue_mixed_times { static const bool value = false; }; template<> struct is_glue_mixed_times { static const bool value = true; }; template struct is_glue_mixed_elem { static const bool value = false; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template<> struct is_glue_mixed_elem { static const bool value = true; }; template struct is_op_mixed_elem { static const bool value = false; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template<> struct is_op_mixed_elem { static const bool value = true; }; template struct is_spop_elem { static const bool value = false; }; template<> struct is_spop_elem { static const bool value = true; }; template struct is_spglue_elem { static const bool value = false; }; template<> struct is_spglue_elem { static const bool value = true; }; template<> struct is_spglue_elem { static const bool value = true; }; template<> struct is_spglue_elem { static const bool value = true; }; template<> struct is_spglue_elem { static const bool value = true; }; template struct is_spglue_times { static const bool value = false; }; template<> struct is_spglue_times { static const bool value = true; }; template struct is_spglue_times2 { static const bool value = false; }; template<> struct is_spglue_times { static const bool value = true; }; template struct is_outer_product { static const bool value = false; }; template struct is_outer_product< Glue > { static const bool value = (resolves_to_colvector::value && resolves_to_rowvector::value); }; template struct has_op_inv { static const bool value = false; }; template struct has_op_inv< Op > { static const bool value = true; }; template struct has_op_inv< Glue, T2, glue_times> > { static const bool value = true; }; template struct has_op_inv< Glue, glue_times> > { static const bool value = true; }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_min.hpp0000666000000000000000000001015712620272703020731 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_min //! @{ //! \brief //! Delayed 'minimum values' operation. //! The dimension, along which the minima are found, is set via 'dim'. //! For dim = 0, the minimum value of each column is found (i.e. searches by traversing across rows). //! For dim = 1, the minimum value of each row is found (i.e. searches by traversing across columns). //! The default is dim = 0. template arma_inline const Op min ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op min ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type min ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_min::min(X); } //! \brief //! Immediate 'find minimum value' operation, //! invoked, for example, by: min(min(A)) template inline arma_warn_unused typename T1::elem_type min(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("min(): two consecutive min() calls detected"); return op_min::min(in.m); } template arma_inline const Op< Op, op_min> min(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op< Op, op_min>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & min(const T& x) { return x; } //! element-wise minimum template arma_inline typename enable_if2 < ( is_arma_type::value && is_arma_type::value && is_same_type::value ), const Glue >::result min ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return Glue(X, Y); } template inline arma_warn_unused typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == true), typename T1::elem_type >::result min(const T1& x) { arma_extra_debug_sigprint(); return spop_min::vector_min(x); } template inline typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == false), const SpOp >::result min(const T1& X, const uword dim = 0) { arma_extra_debug_sigprint(); return SpOp(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type min(const SpOp& X) { arma_extra_debug_sigprint(); arma_extra_debug_print("min(): two consecutive min() calls detected"); return spop_min::vector_min(X.m); } template inline const SpOp< SpOp, spop_min> min(const SpOp& in, const uword dim) { arma_extra_debug_sigprint(); return SpOp< SpOp, spop_min>(in, dim, 0); } inline uword min(const SizeMat& s) { return (std::min)(s.n_rows, s.n_cols); } inline uword min(const SizeCube& s) { return (std::min)( (std::min)(s.n_rows, s.n_cols), s.n_slices ); } //! @} armadillo-6.500.5/include/armadillo_bits/config.hpp0000666000000000000000000001616712620272703020737 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin #if !defined(ARMA_USE_LAPACK) #define ARMA_USE_LAPACK //// Comment out the above line if you don't have LAPACK or a high-speed replacement for LAPACK, //// such as Intel MKL, AMD ACML, or the Accelerate framework. //// LAPACK is required for matrix decompositions (eg. SVD) and matrix inverse. #endif #if !defined(ARMA_USE_BLAS) #define ARMA_USE_BLAS //// Comment out the above line if you don't have BLAS or a high-speed replacement for BLAS, //// such as OpenBLAS, GotoBLAS, Intel MKL, AMD ACML, or the Accelerate framework. //// BLAS is used for matrix multiplication. //// Without BLAS, matrix multiplication will still work, but might be slower. #endif #if !defined(ARMA_USE_ARPACK) // #define ARMA_USE_ARPACK //// Uncomment the above line if you have ARPACK or a high-speed replacement for ARPACK. //// ARPACK is required for eigendecompositions of sparse matrices, eg. eigs_sym(), svds() #endif #if !defined(ARMA_USE_SUPERLU) // #define ARMA_USE_SUPERLU //// Uncomment the above line if you have SuperLU. //// SuperLU is used for solving sparse linear systems via spsolve() //// Caveat: only SuperLU version 4.3 can be used! #endif #if !defined(ARMA_SUPERLU_INCLUDE_DIR) // #define ARMA_SUPERLU_INCLUDE_DIR /usr/include/ //// If you're using SuperLU and want to explicitly include the SuperLU headers, //// uncomment the above define and specify the appropriate include directory. //// Make sure the directory has a trailing / #endif // #define ARMA_USE_WRAPPER //// Comment out the above line if you're getting linking errors when compiling your programs, //// or if you prefer to directly link with LAPACK, BLAS + etc instead of the Armadillo runtime library. //// You will then need to link your programs directly with -llapack -lblas instead of -larmadillo // #define ARMA_BLAS_CAPITALS //// Uncomment the above line if your BLAS and LAPACK libraries have capitalised function names (eg. ACML on 64-bit Windows) #define ARMA_BLAS_UNDERSCORE //// Uncomment the above line if your BLAS and LAPACK libraries have function names with a trailing underscore. //// Conversely, comment it out if the function names don't have a trailing underscore. // #define ARMA_BLAS_LONG //// Uncomment the above line if your BLAS and LAPACK libraries use "long" instead of "int" // #define ARMA_BLAS_LONG_LONG //// Uncomment the above line if your BLAS and LAPACK libraries use "long long" instead of "int" // #define ARMA_USE_TBB_ALLOC //// Uncomment the above line if you want to use Intel TBB scalable_malloc() and scalable_free() instead of standard malloc() and free() // #define ARMA_USE_MKL_ALLOC //// Uncomment the above line if you want to use Intel MKL mkl_malloc() and mkl_free() instead of standard malloc() and free() // #define ARMA_USE_ATLAS // #define ARMA_ATLAS_INCLUDE_DIR /usr/include/ //// If you're using ATLAS and the compiler can't find cblas.h and/or clapack.h //// uncomment the above define and specify the appropriate include directory. //// Make sure the directory has a trailing / #if !defined(ARMA_USE_CXX11) // #define ARMA_USE_CXX11 //// Uncomment the above line to forcefully enable use of C++11 features (eg. initialiser lists). //// Note that ARMA_USE_CXX11 is automatically enabled when a C++11 compiler is detected. #endif #if !defined(ARMA_64BIT_WORD) // #define ARMA_64BIT_WORD //// Uncomment the above line if you require matrices/vectors capable of holding more than 4 billion elements. //// Your machine and compiler must have support for 64 bit integers (eg. via "long" or "long long"). //// Note that ARMA_64BIT_WORD is automatically enabled when a C++11 compiler is detected. #endif #if !defined(ARMA_USE_HDF5) // #define ARMA_USE_HDF5 //// Uncomment the above line to allow the ability to save and load matrices stored in HDF5 format; //// the hdf5.h header file must be available on your system, //// and you will need to link with the hdf5 library (eg. -lhdf5) #endif // #define ARMA_USE_HDF5_ALT #if defined(ARMA_USE_HDF5_ALT) && defined(ARMA_USE_WRAPPER) #undef ARMA_USE_HDF5 #define ARMA_USE_HDF5 // #define ARMA_HDF5_INCLUDE_DIR /usr/include/ #endif #if !defined(ARMA_MAT_PREALLOC) #define ARMA_MAT_PREALLOC 16 #endif //// This is the number of preallocated elements used by matrices and vectors; //// it must be an integer that is at least 1. //// If you mainly use lots of very small vectors (eg. <= 4 elements), //// change the number to the size of your vectors. #if !defined(ARMA_SPMAT_CHUNKSIZE) #define ARMA_SPMAT_CHUNKSIZE 256 #endif //// This is the minimum increase in the amount of memory (in terms of elements) allocated by a sparse matrix; //// it must be an integer that is at least 1. //// The minimum recommended size is 16. // #define ARMA_NO_DEBUG //// Uncomment the above line if you want to disable all run-time checks. //// This will result in faster code, but you first need to make sure that your code runs correctly! //// We strongly recommend to have the run-time checks enabled during development, //// as this greatly aids in finding mistakes in your code, and hence speeds up development. //// We recommend that run-time checks be disabled _only_ for the shipped version of your program. // #define ARMA_EXTRA_DEBUG //// Uncomment the above line if you want to see the function traces of how Armadillo evaluates expressions. //// This is mainly useful for debugging of the library. #if !defined(ARMA_DEFAULT_OSTREAM) #define ARMA_DEFAULT_OSTREAM std::cout #endif #if !defined(ARMA_PRINT_ERRORS) #define ARMA_PRINT_ERRORS //// Comment out the above line if you don't want errors and warnings printed (eg. failed decompositions) #endif #if !defined(ARMA_PRINT_HDF5_ERRORS) // #define ARMA_PRINT_HDF5_ERRORS #endif #if defined(ARMA_DONT_USE_LAPACK) #undef ARMA_USE_LAPACK #endif #if defined(ARMA_DONT_USE_BLAS) #undef ARMA_USE_BLAS #endif #if defined(ARMA_DONT_USE_ARPACK) #undef ARMA_USE_ARPACK #endif #if defined(ARMA_DONT_USE_SUPERLU) #undef ARMA_USE_SUPERLU #undef ARMA_SUPERLU_INCLUDE_DIR #endif #if defined(ARMA_DONT_USE_ATLAS) #undef ARMA_USE_ATLAS #undef ARMA_ATLAS_INCLUDE_DIR #endif #if defined(ARMA_DONT_USE_WRAPPER) #undef ARMA_USE_WRAPPER #undef ARMA_USE_HDF5_ALT #endif #if defined(ARMA_DONT_USE_CXX11) #undef ARMA_USE_CXX11 #undef ARMA_USE_EXTERN_CXX11_RNG #endif #if defined(ARMA_USE_WRAPPER) #if defined(ARMA_USE_CXX11) #if !defined(ARMA_USE_EXTERN_CXX11_RNG) // #define ARMA_USE_EXTERN_CXX11_RNG #endif #endif #endif #if defined(ARMA_DONT_USE_EXTERN_CXX11_RNG) #undef ARMA_USE_EXTERN_CXX11_RNG #endif #if defined(ARMA_32BIT_WORD) #undef ARMA_64BIT_WORD #endif #if defined(ARMA_DONT_USE_HDF5) #undef ARMA_USE_HDF5 #endif #if defined(ARMA_DONT_PRINT_ERRORS) #undef ARMA_PRINT_ERRORS #endif #if defined(ARMA_DONT_PRINT_HDF5_ERRORS) #undef ARMA_PRINT_HDF5_ERRORS #endif armadillo-6.500.5/include/armadillo_bits/fn_interp1.hpp0000666000000000000000000002042012620272703021522 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_interp1 //! @{ template inline void interp1_helper_nearest(const Mat& XG, const Mat& YG, const Mat& XI, Mat& YI, const eT extrap_val) { arma_extra_debug_sigprint(); const eT XG_min = XG.min(); const eT XG_max = XG.max(); YI.copy_size(XI); const eT* XG_mem = XG.memptr(); const eT* YG_mem = YG.memptr(); const eT* XI_mem = XI.memptr(); eT* YI_mem = YI.memptr(); const uword NG = XG.n_elem; const uword NI = XI.n_elem; uword best_j = 0; for(uword i=0; i::inf; const eT XI_val = XI_mem[i]; if((XI_val < XG_min) || (XI_val > XG_max)) { YI_mem[i] = extrap_val; } else { // XG and XI are guaranteed to be sorted in ascending manner, // so start searching XG from last known optimum position for(uword j=best_j; j= eT(0)) ? tmp : -tmp; if(err >= best_err) { // error is going up, so we have found the optimum position break; } else { best_err = err; best_j = j; // remember the optimum position } } YI_mem[i] = YG_mem[best_j]; } } } template inline void interp1_helper_linear(const Mat& XG, const Mat& YG, const Mat& XI, Mat& YI, const eT extrap_val) { arma_extra_debug_sigprint(); const eT XG_min = XG.min(); const eT XG_max = XG.max(); YI.copy_size(XI); const eT* XG_mem = XG.memptr(); const eT* YG_mem = YG.memptr(); const eT* XI_mem = XI.memptr(); eT* YI_mem = YI.memptr(); const uword NG = XG.n_elem; const uword NI = XI.n_elem; uword a_best_j = 0; uword b_best_j = 0; for(uword i=0; i XG_max)) { YI_mem[i] = extrap_val; } else { // XG and XI are guaranteed to be sorted in ascending manner, // so start searching XG from last known optimum position eT a_best_err = Datum::inf; eT b_best_err = Datum::inf; for(uword j=a_best_j; j= eT(0)) ? tmp : -tmp; if(err >= a_best_err) { break; } else { a_best_err = err; a_best_j = j; } } if( (XG_mem[a_best_j] - XI_val) <= eT(0) ) { // a_best_j is to the left of the interpolated position b_best_j = ( (a_best_j+1) < NG) ? (a_best_j+1) : a_best_j; } else { // a_best_j is to the right of the interpolated position b_best_j = (a_best_j >= 1) ? (a_best_j-1) : a_best_j; } b_best_err = std::abs( XG_mem[b_best_j] - XI_val ); if(a_best_j > b_best_j) { std::swap(a_best_j, b_best_j ); std::swap(a_best_err, b_best_err); } const eT weight = (a_best_err > eT(0)) ? (a_best_err / (a_best_err + b_best_err)) : eT(0); YI_mem[i] = (eT(1) - weight)*YG_mem[a_best_j] + (weight)*YG_mem[b_best_j]; } } } template inline void interp1_helper(const Mat& X, const Mat& Y, const Mat& XI, Mat& YI, const uword sig, const eT extrap_val) { arma_extra_debug_sigprint(); arma_debug_check( ((X.is_vec() == false) || (Y.is_vec() == false) || (XI.is_vec() == false)), "interp1(): currently only vectors are supported" ); arma_debug_check( (X.n_elem != Y.n_elem), "interp1(): X and Y must have the same number of elements" ); arma_debug_check( (X.n_elem < 2), "interp1(): X must have at least two unique elements" ); // sig = 10: nearest neighbour // sig = 11: nearest neighbour, assume monotonic increase in X and XI // // sig = 20: linear // sig = 21: linear, assume monotonic increase in X and XI if(sig == 11) { interp1_helper_nearest(X, Y, XI, YI, extrap_val); return; } if(sig == 21) { interp1_helper_linear (X, Y, XI, YI, extrap_val); return; } uvec X_indices; try { X_indices = find_unique(X,false); } catch(...) { } // NOTE: find_unique(X,false) provides indices of elements sorted in ascending order // NOTE: find_unique(X,false) will reset X_indices if X has NaN const uword N_subset = X_indices.n_elem; arma_debug_check( (N_subset < 2), "interp1(): X must have at least two unique elements" ); Mat X_sanitised(N_subset,1); Mat Y_sanitised(N_subset,1); eT* X_sanitised_mem = X_sanitised.memptr(); eT* Y_sanitised_mem = Y_sanitised.memptr(); const eT* X_mem = X.memptr(); const eT* Y_mem = Y.memptr(); const uword* X_indices_mem = X_indices.memptr(); for(uword i=0; i XI_tmp; uvec XI_indices; const bool XI_is_sorted = XI.is_sorted(); if(XI_is_sorted == false) { XI_indices = sort_index(XI); const uword N = XI.n_elem; XI_tmp.copy_size(XI); const uword* XI_indices_mem = XI_indices.memptr(); const eT* XI_mem = XI.memptr(); eT* XI_tmp_mem = XI_tmp.memptr(); for(uword i=0; i& XI_sorted = (XI_is_sorted) ? XI : XI_tmp; if(sig == 10) { interp1_helper_nearest(X_sanitised, Y_sanitised, XI_sorted, YI, extrap_val); } else if(sig == 20) { interp1_helper_linear (X_sanitised, Y_sanitised, XI_sorted, YI, extrap_val); } if( (XI_is_sorted == false) && (YI.n_elem > 0) ) { Mat YI_unsorted; YI_unsorted.copy_size(YI); const eT* YI_mem = YI.memptr(); eT* YI_unsorted_mem = YI_unsorted.memptr(); const uword N = XI_sorted.n_elem; const uword* XI_indices_mem = XI_indices.memptr(); for(uword i=0; i inline typename enable_if2 < is_real::value, void >::result interp1 ( const Base& X, const Base& Y, const Base& XI, Mat& YI, const char* method = "linear", const typename T1::elem_type extrap_val = Datum::nan ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; uword sig = 0; if(method != NULL ) if(method[0] != char(0)) if(method[1] != char(0)) { const char c1 = method[0]; const char c2 = method[1]; if(c1 == 'n') { sig = 10; } // nearest neighbour else if(c1 == 'l') { sig = 20; } // linear else { if( (c1 == '*') && (c2 == 'n') ) { sig = 11; } // nearest neighour, assume monotonic increase in X and XI if( (c1 == '*') && (c2 == 'l') ) { sig = 21; } // linear, assume monotonic increase in X and XI } } arma_debug_check( (sig == 0), "interp1(): unsupported interpolation type" ); const quasi_unwrap X_tmp( X.get_ref()); const quasi_unwrap Y_tmp( Y.get_ref()); const quasi_unwrap XI_tmp(XI.get_ref()); if( X_tmp.is_alias(YI) || Y_tmp.is_alias(YI) || XI_tmp.is_alias(YI) ) { Mat tmp; interp1_helper(X_tmp.M, Y_tmp.M, XI_tmp.M, tmp, sig, extrap_val); YI.steal_mem(tmp); } else { interp1_helper(X_tmp.M, Y_tmp.M, XI_tmp.M, YI, sig, extrap_val); } } //! @} armadillo-6.500.5/include/armadillo_bits/def_hdf5.hpp0000666000000000000000000001327612620272703021134 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Ryan Curtin #if defined(ARMA_USE_HDF5) #if !defined(ARMA_USE_HDF5_ALT) // macros needed if the wrapper run-time library is not being used #define arma_H5Tcopy H5Tcopy #define arma_H5Tcreate H5Tcreate #define arma_H5Tinsert H5Tinsert #define arma_H5Tequal H5Tequal #define arma_H5Tclose H5Tclose #define arma_H5Dopen H5Dopen #define arma_H5Dget_type H5Dget_type #define arma_H5Dclose H5Dclose #define arma_H5Dwrite H5Dwrite #define arma_H5Dget_space H5Dget_space #define arma_H5Dread H5Dread #define arma_H5Dcreate H5Dcreate #define arma_H5Sget_simple_extent_ndims H5Sget_simple_extent_ndims #define arma_H5Sget_simple_extent_dims H5Sget_simple_extent_dims #define arma_H5Sclose H5Sclose #define arma_H5Screate_simple H5Screate_simple #define arma_H5Ovisit H5Ovisit #define arma_H5Eset_auto H5Eset_auto #define arma_H5Eget_auto H5Eget_auto #define arma_H5Fopen H5Fopen #define arma_H5Fcreate H5Fcreate #define arma_H5Fclose H5Fclose #define arma_H5Fis_hdf5 H5Fis_hdf5 #define arma_H5T_NATIVE_UCHAR H5T_NATIVE_UCHAR #define arma_H5T_NATIVE_CHAR H5T_NATIVE_CHAR #define arma_H5T_NATIVE_SHORT H5T_NATIVE_SHORT #define arma_H5T_NATIVE_USHORT H5T_NATIVE_USHORT #define arma_H5T_NATIVE_INT H5T_NATIVE_INT #define arma_H5T_NATIVE_UINT H5T_NATIVE_UINT #define arma_H5T_NATIVE_LONG H5T_NATIVE_LONG #define arma_H5T_NATIVE_ULONG H5T_NATIVE_ULONG #define arma_H5T_NATIVE_LLONG H5T_NATIVE_LLONG #define arma_H5T_NATIVE_ULLONG H5T_NATIVE_ULLONG #define arma_H5T_NATIVE_FLOAT H5T_NATIVE_FLOAT #define arma_H5T_NATIVE_DOUBLE H5T_NATIVE_DOUBLE #else // prototypes for the wrapper functions defined in the wrapper run-time library (src/wrapper.cpp) extern "C" { // Wrapper functions for H5* functions. hid_t arma_H5Tcopy(hid_t dtype_id); hid_t arma_H5Tcreate(H5T_class_t cl, size_t size); herr_t arma_H5Tinsert(hid_t dtype_id, const char* name, size_t offset, hid_t field_id); htri_t arma_H5Tequal(hid_t dtype_id1, hid_t dtype_id2); herr_t arma_H5Tclose(hid_t dtype_id); hid_t arma_H5Dopen(hid_t loc_id, const char* name, hid_t dapl_id); hid_t arma_H5Dget_type(hid_t dataset_id); herr_t arma_H5Dclose(hid_t dataset_id); hid_t arma_H5Dcreate(hid_t loc_id, const char* name, hid_t dtype_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id); herr_t arma_H5Dwrite(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, const void* buf); hid_t arma_H5Dget_space(hid_t dataset_id); herr_t arma_H5Dread(hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, void* buf); int arma_H5Sget_simple_extent_ndims(hid_t space_id); int arma_H5Sget_simple_extent_dims(hid_t space_id, hsize_t* dims, hsize_t* maxdims); herr_t arma_H5Sclose(hid_t space_id); hid_t arma_H5Screate_simple(int rank, const hsize_t* current_dims, const hsize_t* maximum_dims); herr_t arma_H5Ovisit(hid_t object_id, H5_index_t index_type, H5_iter_order_t order, H5O_iterate_t op, void* op_data); herr_t arma_H5Eset_auto(hid_t estack_id, H5E_auto_t func, void* client_data); herr_t arma_H5Eget_auto(hid_t estack_id, H5E_auto_t* func, void** client_data); hid_t arma_H5Fopen(const char* name, unsigned flags, hid_t fapl_id); hid_t arma_H5Fcreate(const char* name, unsigned flags, hid_t fcpl_id, hid_t fapl_id); herr_t arma_H5Fclose(hid_t file_id); htri_t arma_H5Fis_hdf5(const char* name); // Wrapper variables that represent the hid_t values for the H5T_NATIVE_* // types. Note that H5T_NATIVE_UCHAR itself is a macro that resolves to about // forty other macros, and we definitely don't want to hijack those, // so this is the best way to go about wrapping these... extern hid_t arma_H5T_NATIVE_UCHAR; extern hid_t arma_H5T_NATIVE_CHAR; extern hid_t arma_H5T_NATIVE_SHORT; extern hid_t arma_H5T_NATIVE_USHORT; extern hid_t arma_H5T_NATIVE_INT; extern hid_t arma_H5T_NATIVE_UINT; extern hid_t arma_H5T_NATIVE_LONG; extern hid_t arma_H5T_NATIVE_ULONG; extern hid_t arma_H5T_NATIVE_LLONG; extern hid_t arma_H5T_NATIVE_ULLONG; extern hid_t arma_H5T_NATIVE_FLOAT; extern hid_t arma_H5T_NATIVE_DOUBLE; } // Lastly, we have to hijack H5open() and H5check_version(), which are called // by some expanded macros of the other H5* functions. This means we can't // create arma_H5open(), because we can't modify those macros. Instead, we'll // create arma::H5open() and arma::H5check_version(), and then issue a using // directive so that arma::H5open() and arma::H5check_version() are always // called. // // There is potential danger in the use of a using directive like this, but in // this case, I can't think of a better way to solve the problem, and I doubt // this will cause problems in any situations that aren't truly bizarre. And // if it does cause problems, the user can #define ARMA_DONT_USE_WRAPPER or // #undef ARMA_USE_WRAPPER in their Armadillo configuration. herr_t H5open(); herr_t H5check_version(unsigned majnum, unsigned minnum, unsigned relnum); using arma::H5open; using arma::H5check_version; #endif #endif armadillo-6.500.5/include/armadillo_bits/SizeMat_bones.hpp0000666000000000000000000000214612620272703022224 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup SizeMat //! @{ class SizeMat { public: const uword n_rows; const uword n_cols; inline explicit SizeMat(const uword in_n_rows, const uword in_n_cols); inline uword operator[](const uword dim) const; inline uword operator()(const uword dim) const; inline bool operator==(const SizeMat& s) const; inline bool operator!=(const SizeMat& s) const; inline SizeMat operator+(const SizeMat& s) const; inline SizeMat operator-(const SizeMat& s) const; inline SizeMat operator+(const uword val) const; inline SizeMat operator-(const uword val) const; inline SizeMat operator*(const uword val) const; inline SizeMat operator/(const uword val) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/op_median_meat.hpp0000666000000000000000000002521012620272703022420 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_median //! @{ //! \brief //! For each row or for each column, find the median value. //! The result is stored in a dense matrix that has either one column or one row. //! The dimension, for which the medians are found, is set via the median() function. template inline void op_median::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "median(): parameter 'dim' must be 0 or 1" ); const Proxy P(in.m); typedef typename Proxy::stored_type P_stored_type; const bool is_alias = P.is_alias(out); if( (is_Mat::value == true) || is_alias ) { const unwrap_check tmp(P.Q, is_alias); const typename unwrap_check::stored_type& X = tmp.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) // in each column { arma_extra_debug_print("op_median::apply(): dim = 0"); out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows > 0) { std::vector tmp_vec(X_n_rows); for(uword col=0; col < X_n_cols; ++col) { arrayops::copy( &(tmp_vec[0]), X.colptr(col), X_n_rows ); out[col] = op_median::direct_median(tmp_vec); } } } else // in each row { arma_extra_debug_print("op_median::apply(): dim = 1"); out.set_size(X_n_rows, (X_n_cols > 0) ? 1 : 0); if(X_n_cols > 0) { std::vector tmp_vec(X_n_cols); for(uword row=0; row < X_n_rows; ++row) { for(uword col=0; col < X_n_cols; ++col) { tmp_vec[col] = X.at(row,col); } out[row] = op_median::direct_median(tmp_vec); } } } } else { const uword P_n_rows = P.get_n_rows(); const uword P_n_cols = P.get_n_cols(); if(dim == 0) // in each column { arma_extra_debug_print("op_median::apply(): dim = 0"); out.set_size((P_n_rows > 0) ? 1 : 0, P_n_cols); if(P_n_rows > 0) { std::vector tmp_vec(P_n_rows); for(uword col=0; col < P_n_cols; ++col) { for(uword row=0; row < P_n_rows; ++row) { tmp_vec[row] = P.at(row,col); } out[col] = op_median::direct_median(tmp_vec); } } } else // in each row { arma_extra_debug_print("op_median::apply(): dim = 1"); out.set_size(P_n_rows, (P_n_cols > 0) ? 1 : 0); if(P_n_cols > 0) { std::vector tmp_vec(P_n_cols); for(uword row=0; row < P_n_rows; ++row) { for(uword col=0; col < P_n_cols; ++col) { tmp_vec[col] = P.at(row,col); } out[row] = op_median::direct_median(tmp_vec); } } } } } //! Implementation for complex numbers template inline void op_median::apply(Mat< std::complex >& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename std::complex eT; arma_type_check(( is_same_type::no )); const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "median(): parameter 'dim' must be 0 or 1" ); if(dim == 0) // in each column { arma_extra_debug_print("op_median::apply(): dim = 0"); out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows > 0) { std::vector< arma_cx_median_packet > tmp_vec(X_n_rows); for(uword col=0; col 0) ? 1 : 0); if(X_n_cols > 0) { std::vector< arma_cx_median_packet > tmp_vec(X_n_cols); for(uword row=0; row inline typename T1::elem_type op_median::median_vec ( const T1& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename Proxy::stored_type P_stored_type; const Proxy P(X); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "median(): object has no elements"); return Datum::nan; } std::vector tmp_vec(n_elem); if(is_Mat::value == true) { const unwrap tmp(P.Q); const typename unwrap::stored_type& Y = tmp.M; arrayops::copy( &(tmp_vec[0]), Y.memptr(), n_elem ); } else { if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); for(uword i=0; i inline typename T1::elem_type op_median::median_vec ( const T1& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const Proxy P(X); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "median(): object has no elements"); return Datum::nan; } std::vector< arma_cx_median_packet > tmp_vec(n_elem); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); for(uword i=0; i inline eT op_median::direct_median(std::vector& X) { arma_extra_debug_sigprint(); const uword n_elem = uword(X.size()); const uword half = n_elem/2; typename std::vector::iterator first = X.begin(); typename std::vector::iterator nth = first + half; typename std::vector::iterator pastlast = X.end(); std::nth_element(first, nth, pastlast); if((n_elem % 2) == 0) // even number of elements { typename std::vector::iterator start = X.begin(); typename std::vector::iterator pastend = start + half; const eT val1 = (*nth); const eT val2 = (*(std::max_element(start, pastend))); return op_mean::robust_mean(val1, val2); } else // odd number of elements { return (*nth); } } template inline void op_median::direct_cx_median_index ( uword& out_index1, uword& out_index2, std::vector< arma_cx_median_packet >& X ) { arma_extra_debug_sigprint(); typedef arma_cx_median_packet eT; const uword n_elem = uword(X.size()); const uword half = n_elem/2; typename std::vector::iterator first = X.begin(); typename std::vector::iterator nth = first + half; typename std::vector::iterator pastlast = X.end(); std::nth_element(first, nth, pastlast); out_index1 = (*nth).index; if((n_elem % 2) == 0) // even number of elements { typename std::vector::iterator start = X.begin(); typename std::vector::iterator pastend = start + half; out_index2 = (*(std::max_element(start, pastend))).index; } else // odd number of elements { out_index2 = out_index1; } } //! @} armadillo-6.500.5/include/armadillo_bits/GlueCube_meat.hpp0000666000000000000000000000155012620272703022161 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup GlueCube //! @{ template inline GlueCube::GlueCube(const BaseCube& in_A, const BaseCube& in_B) : A(in_A.get_ref()) , B(in_B.get_ref()) { arma_extra_debug_sigprint(); } template inline GlueCube::~GlueCube() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/op_inv_meat.hpp0000666000000000000000000000606412656144025021771 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_inv //! @{ //! immediate inverse of a matrix, storing the result in a dense matrix template inline void op_inv::apply(Mat& out, const Mat& A) { arma_extra_debug_sigprint(); // no need to check for aliasing, due to: // - auxlib::inv() copies A to out before inversion // - for 2x2 and 3x3 matrices the code is alias safe bool status = auxlib::inv(out, A); if(status == false) { out.reset(); arma_bad("inv(): matrix appears to be singular"); } } //! immediate inverse of T1, storing the result in a dense matrix template inline void op_inv::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); const strip_diagmat strip(X.m); bool status; if(strip.do_diagmat == true) { status = op_inv::apply_diagmat(out, strip.M); } else { status = auxlib::inv(out, X.m); } if(status == false) { out.reset(); arma_bad("inv(): matrix appears to be singular"); } } template inline bool op_inv::apply_diagmat(Mat& out, const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const diagmat_proxy A(X); arma_debug_check( (A.n_rows != A.n_cols), "inv(): given matrix must be square sized" ); const uword N = (std::min)(A.n_rows, A.n_cols); bool status = true; if(A.is_alias(out) == false) { out.zeros(N,N); for(uword i=0; i tmp(N, N, fill::zeros); for(uword i=0; i inline void op_inv_tr::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); const bool status = auxlib::inv_tr(out, X.m, X.aux_uword_a); if(status == false) { out.reset(); arma_bad("inv(): matrix appears to be singular"); } } //! inverse of T1 (symmetric positive definite matrices) template inline void op_inv_sympd::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); const bool status = auxlib::inv_sympd(out, X.m); if(status == false) { out.reset(); arma_bad("inv_sympd(): matrix appears to be singular"); } } //! @} armadillo-6.500.5/include/armadillo_bits/spop_var_meat.hpp0000666000000000000000000002205412620272703022321 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_var //! @{ template inline void spop_var::apply(SpMat& out, const mtSpOp& in) { arma_extra_debug_sigprint(); //typedef typename T1::elem_type in_eT; typedef typename T1::pod_type out_eT; const uword norm_type = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check( (norm_type > 1), "var(): parameter 'norm_type' must be 0 or 1" ); arma_debug_check( (dim > 1), "var(): parameter 'dim' must be 0 or 1" ); const SpProxy p(in.m); if(p.is_alias(out) == false) { spop_var::apply_noalias(out, p, norm_type, dim); } else { SpMat tmp; spop_var::apply_noalias(tmp, p, norm_type, dim); out.steal_mem(tmp); } } template inline void spop_var::apply_noalias ( SpMat& out, const SpProxy& p, const uword norm_type, const uword dim ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type in_eT; //typedef typename T1::pod_type out_eT; const uword p_n_rows = p.get_n_rows(); const uword p_n_cols = p.get_n_cols(); // TODO: this is slow; rewrite based on the approach used by sparse mean() if(dim == 0) // find variance in each column { arma_extra_debug_print("spop_var::apply_noalias(): dim = 0"); out.set_size((p_n_rows > 0) ? 1 : 0, p_n_cols); if( (p_n_rows == 0) || (p.get_n_nonzero() == 0) ) { return; } for(uword col = 0; col < p_n_cols; ++col) { if(SpProxy::must_use_iterator) { // We must use an iterator; we can't access memory directly. typename SpProxy::const_iterator_type it = p.begin_col(col); typename SpProxy::const_iterator_type end = p.begin_col(col + 1); const uword n_zero = p_n_rows - (end.pos() - it.pos()); // in_eT is used just to get the specialization right (complex / noncomplex) out.at(0, col) = spop_var::iterator_var(it, end, n_zero, norm_type, in_eT(0)); } else { // We can use direct memory access to calculate the variance. out.at(0, col) = spop_var::direct_var ( &p.get_values()[p.get_col_ptrs()[col]], p.get_col_ptrs()[col + 1] - p.get_col_ptrs()[col], p_n_rows, norm_type ); } } } else if(dim == 1) // find variance in each row { arma_extra_debug_print("spop_var::apply_noalias(): dim = 1"); out.set_size(p_n_rows, (p_n_cols > 0) ? 1 : 0); if( (p_n_cols == 0) || (p.get_n_nonzero() == 0) ) { return; } for(uword row = 0; row < p_n_rows; ++row) { // We have to use an iterator here regardless of whether or not we can // directly access memory. typename SpProxy::const_row_iterator_type it = p.begin_row(row); typename SpProxy::const_row_iterator_type end = p.end_row(row); const uword n_zero = p_n_cols - (end.pos() - it.pos()); out.at(row, 0) = spop_var::iterator_var(it, end, n_zero, norm_type, in_eT(0)); } } } template inline typename T1::pod_type spop_var::var_vec ( const T1& X, const uword norm_type ) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "var(): parameter 'norm_type' must be 0 or 1" ); // conditionally unwrap it into a temporary and then directly operate. const unwrap_spmat tmp(X); return direct_var(tmp.M.values, tmp.M.n_nonzero, tmp.M.n_elem, norm_type); } template inline eT spop_var::direct_var ( const eT* const X, const uword length, const uword N, const uword norm_type ) { arma_extra_debug_sigprint(); if(length >= 2 && N >= 2) { const eT acc1 = spop_mean::direct_mean(X, length, N); eT acc2 = eT(0); eT acc3 = eT(0); uword i, j; for(i = 0, j = 1; j < length; i += 2, j += 2) { const eT Xi = X[i]; const eT Xj = X[j]; const eT tmpi = acc1 - Xi; const eT tmpj = acc1 - Xj; acc2 += tmpi * tmpi + tmpj * tmpj; acc3 += tmpi + tmpj; } if(i < length) { const eT Xi = X[i]; const eT tmpi = acc1 - Xi; acc2 += tmpi * tmpi; acc3 += tmpi; } // Now add in all zero elements. acc2 += (N - length) * (acc1 * acc1); acc3 += (N - length) * acc1; const eT norm_val = (norm_type == 0) ? eT(N - 1) : eT(N); const eT var_val = (acc2 - (acc3 * acc3) / eT(N)) / norm_val; return var_val; } else if(length == 1 && N > 1) // if N == 1, then variance is zero. { const eT mean = X[0] / eT(N); const eT val = mean - X[0]; const eT acc2 = (val * val) + (N - length) * (mean * mean); const eT acc3 = val + (N - length) * mean; const eT norm_val = (norm_type == 0) ? eT(N - 1) : eT(N); const eT var_val = (acc2 - (acc3 * acc3) / eT(N)) / norm_val; return var_val; } else { return eT(0); } } template inline T spop_var::direct_var ( const std::complex* const X, const uword length, const uword N, const uword norm_type ) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(length >= 2 && N >= 2) { const eT acc1 = spop_mean::direct_mean(X, length, N); T acc2 = T(0); eT acc3 = eT(0); for (uword i = 0; i < length; ++i) { const eT tmp = acc1 - X[i]; acc2 += std::norm(tmp); acc3 += tmp; } // Add zero elements to sums acc2 += std::norm(acc1) * T(N - length); acc3 += acc1 * T(N - length); const T norm_val = (norm_type == 0) ? T(N - 1) : T(N); const T var_val = (acc2 - std::norm(acc3) / T(N)) / norm_val; return var_val; } else if(length == 1 && N > 1) // if N == 1, then variance is zero. { const eT mean = X[0] / T(N); const eT val = mean - X[0]; const T acc2 = std::norm(val) + (N - length) * std::norm(mean); const eT acc3 = val + T(N - length) * mean; const T norm_val = (norm_type == 0) ? T(N - 1) : T(N); const T var_val = (acc2 - std::norm(acc3) / T(N)) / norm_val; return var_val; } else { return T(0); // All elements are zero } } template inline eT spop_var::iterator_var ( T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_not_cx::result* junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); T1 new_it(it); // for mean // T1 backup_it(it); // in case we have to call robust iterator_var eT mean = spop_mean::iterator_mean(new_it, end, n_zero, eT(0)); eT acc2 = eT(0); eT acc3 = eT(0); const uword it_begin_pos = it.pos(); while (it != end) { const eT tmp = mean - (*it); acc2 += (tmp * tmp); acc3 += (tmp); ++it; } const uword n_nonzero = (it.pos() - it_begin_pos); if (n_nonzero == 0) { return eT(0); } if (n_nonzero + n_zero == 1) { return eT(0); // only one element } // Add in entries for zeros. acc2 += eT(n_zero) * (mean * mean); acc3 += eT(n_zero) * mean; const eT norm_val = (norm_type == 0) ? eT(n_zero + n_nonzero - 1) : eT(n_zero + n_nonzero); const eT var_val = (acc2 - (acc3 * acc3) / eT(n_nonzero + n_zero)) / norm_val; return var_val; } template inline typename get_pod_type::result spop_var::iterator_var ( T1& it, const T1& end, const uword n_zero, const uword norm_type, const eT junk1, const typename arma_cx_only::result* junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename get_pod_type::result T; T1 new_it(it); // for mean // T1 backup_it(it); // in case we have to call robust iterator_var eT mean = spop_mean::iterator_mean(new_it, end, n_zero, eT(0)); T acc2 = T(0); eT acc3 = eT(0); const uword it_begin_pos = it.pos(); while (it != end) { eT tmp = mean - (*it); acc2 += std::norm(tmp); acc3 += (tmp); ++it; } const uword n_nonzero = (it.pos() - it_begin_pos); if (n_nonzero == 0) { return T(0); } if (n_nonzero + n_zero == 1) { return T(0); // only one element } // Add in entries for zero elements. acc2 += T(n_zero) * std::norm(mean); acc3 += T(n_zero) * mean; const T norm_val = (norm_type == 0) ? T(n_zero + n_nonzero - 1) : T(n_zero + n_nonzero); const T var_val = (acc2 - std::norm(acc3) / T(n_nonzero + n_zero)) / norm_val; return var_val; } //! @} armadillo-6.500.5/include/armadillo_bits/op_normalise_meat.hpp0000666000000000000000000000505312620272703023157 0ustar rootroot// Copyright (C) 2014-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_normalise //! @{ template inline void op_normalise_vec::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; const uword p = in.aux_uword_a; arma_debug_check( (p == 0), "normalise(): parameter 'p' must be greater than zero" ); const quasi_unwrap tmp(in.m); const T norm_val_a = norm(tmp.M, p); const T norm_val_b = (norm_val_a != T(0)) ? norm_val_a : T(1); out = tmp.M / norm_val_b; } template inline void op_normalise_mat::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword p = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check( (p == 0), "normalise(): parameter 'p' must be greater than zero" ); arma_debug_check( (dim > 1), "normalise(): parameter 'dim' must be 0 or 1" ); const unwrap tmp(in.m); const Mat& A = tmp.M; const bool alias = ( (&out) == (&A) ); if(alias) { Mat out2; op_normalise_mat::apply(out2, A, p, dim); out.steal_mem(out2); } else { op_normalise_mat::apply(out, A, p, dim); } } template inline void op_normalise_mat::apply(Mat& out, const Mat& A, const uword p, const uword dim) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; out.copy_size(A); if(A.n_elem == 0) { return; } if(dim == 0) { const uword n_cols = A.n_cols; for(uword i=0; i arma_inline const Glue kron(const Base& A, const Base& B) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref()); } //! \brief //! kronecker product of two matrices, //! with the matrices having different element types template inline Mat::eT> kron(const Base,T1>& X, const Base& Y) { arma_extra_debug_sigprint(); typedef typename std::complex eT1; promote_type::check(); const unwrap tmp1(X.get_ref()); const unwrap tmp2(Y.get_ref()); const Mat& A = tmp1.M; const Mat& B = tmp2.M; Mat out; glue_kron::direct_kron(out, A, B); return out; } //! \brief //! kronecker product of two matrices, //! with the matrices having different element types template inline Mat::eT> kron(const Base& X, const Base,T2>& Y) { arma_extra_debug_sigprint(); typedef typename std::complex eT2; promote_type::check(); const unwrap tmp1(X.get_ref()); const unwrap tmp2(Y.get_ref()); const Mat& A = tmp1.M; const Mat& B = tmp2.M; Mat out; glue_kron::direct_kron(out, A, B); return out; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_conv_to.hpp0000666000000000000000000003615512620272703021623 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_conv_to //! @{ //! conversion from Armadillo Base and BaseCube objects to scalars //! (kept only for compatibility with old code; use as_scalar() instead for Base objects like Mat) template class conv_to { public: template inline static out_eT from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static out_eT from(const Base& in, const typename arma_cx_only::result* junk = 0); template inline static out_eT from(const BaseCube& in, const typename arma_not_cx::result* junk = 0); template inline static out_eT from(const BaseCube& in, const typename arma_cx_only::result* junk = 0); }; template template inline out_eT conv_to::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_type_check(( is_supported_elem_type::value == false )); const Proxy P(in.get_ref()); arma_debug_check( (P.get_n_elem() != 1), "conv_to(): given object doesn't have exactly one element" ); return out_eT(Proxy::prefer_at_accessor ? P.at(0,0) : P[0]); } template template inline out_eT conv_to::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_type_check(( is_supported_elem_type::value == false )); const Proxy P(in.get_ref()); arma_debug_check( (P.get_n_elem() != 1), "conv_to(): given object doesn't have exactly one element" ); out_eT out; arrayops::convert_cx_scalar(out, (Proxy::prefer_at_accessor ? P.at(0,0) : P[0])); return out; } template template inline out_eT conv_to::from(const BaseCube& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_type_check(( is_supported_elem_type::value == false )); const ProxyCube P(in.get_ref()); arma_debug_check( (P.get_n_elem() != 1), "conv_to(): given object doesn't have exactly one element" ); return out_eT(ProxyCube::prefer_at_accessor ? P.at(0,0,0) : P[0]); } template template inline out_eT conv_to::from(const BaseCube& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_type_check(( is_supported_elem_type::value == false )); const ProxyCube P(in.get_ref()); arma_debug_check( (P.get_n_elem() != 1), "conv_to(): given object doesn't have exactly one element" ); out_eT out; arrayops::convert_cx_scalar(out, (ProxyCube::prefer_at_accessor ? P.at(0,0,0) : P[0])); return out; } //! conversion to Armadillo matrices from Armadillo Base objects, as well as from std::vector template class conv_to< Mat > { public: template inline static Mat from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static Mat from(const Base& in, const typename arma_cx_only::result* junk = 0); template inline static Mat from(const SpBase& in); template inline static Mat from(const std::vector& in, const typename arma_not_cx::result* junk = 0); template inline static Mat from(const std::vector& in, const typename arma_cx_only::result* junk = 0); }; template template inline Mat conv_to< Mat >::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const quasi_unwrap tmp(in.get_ref()); const Mat& X = tmp.M; Mat out(X.n_rows, X.n_cols); arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); return out; } template template inline Mat conv_to< Mat >::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const quasi_unwrap tmp(in.get_ref()); const Mat& X = tmp.M; Mat out(X.n_rows, X.n_cols); arrayops::convert_cx( out.memptr(), X.memptr(), X.n_elem ); return out; } template template inline Mat conv_to< Mat >::from(const SpBase& in) { arma_extra_debug_sigprint(); return Mat(in.get_ref()); } template template inline Mat conv_to< Mat >::from(const std::vector& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword N = uword( in.size() ); Mat out(N, 1); if(N > 0) { arrayops::convert( out.memptr(), &(in[0]), N ); } return out; } template template inline Mat conv_to< Mat >::from(const std::vector& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword N = uword( in.size() ); Mat out(N, 1); if(N > 0) { arrayops::convert_cx( out.memptr(), &(in[0]), N ); } return out; } //! conversion to Armadillo row vectors from Armadillo Base objects, as well as from std::vector template class conv_to< Row > { public: template inline static Row from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static Row from(const Base& in, const typename arma_cx_only::result* junk = 0); template inline static Row from(const std::vector& in, const typename arma_not_cx::result* junk = 0); template inline static Row from(const std::vector& in, const typename arma_cx_only::result* junk = 0); }; template template inline Row conv_to< Row >::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const quasi_unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); Row out(X.n_elem); arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); return out; } template template inline Row conv_to< Row >::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const quasi_unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); Row out(X.n_rows, X.n_cols); arrayops::convert_cx( out.memptr(), X.memptr(), X.n_elem ); return out; } template template inline Row conv_to< Row >::from(const std::vector& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword N = uword( in.size() ); Row out(N); if(N > 0) { arrayops::convert( out.memptr(), &(in[0]), N ); } return out; } template template inline Row conv_to< Row >::from(const std::vector& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword N = uword( in.size() ); Row out(N); if(N > 0) { arrayops::convert_cx( out.memptr(), &(in[0]), N ); } return out; } //! conversion to Armadillo column vectors from Armadillo Base objects, as well as from std::vector template class conv_to< Col > { public: template inline static Col from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static Col from(const Base& in, const typename arma_cx_only::result* junk = 0); template inline static Col from(const std::vector& in, const typename arma_not_cx::result* junk = 0); template inline static Col from(const std::vector& in, const typename arma_cx_only::result* junk = 0); }; template template inline Col conv_to< Col >::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const quasi_unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); Col out(X.n_elem); arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); return out; } template template inline Col conv_to< Col >::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const quasi_unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); Col out(X.n_rows, X.n_cols); arrayops::convert_cx( out.memptr(), X.memptr(), X.n_elem ); return out; } template template inline Col conv_to< Col >::from(const std::vector& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword N = uword( in.size() ); Col out(N); if(N > 0) { arrayops::convert( out.memptr(), &(in[0]), N ); } return out; } template template inline Col conv_to< Col >::from(const std::vector& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword N = uword( in.size() ); Col out(N); if(N > 0) { arrayops::convert_cx( out.memptr(), &(in[0]), N ); } return out; } template class conv_to< SpMat > { public: template inline static SpMat from(const Base& in); }; template template inline SpMat conv_to< SpMat >::from(const Base& in) { arma_extra_debug_sigprint(); return SpMat(in.get_ref()); } //! conversion to Armadillo cubes from Armadillo BaseCube objects template class conv_to< Cube > { public: template inline static Cube from(const BaseCube& in, const typename arma_not_cx::result* junk = 0); template inline static Cube from(const BaseCube& in, const typename arma_cx_only::result* junk = 0); }; template template inline Cube conv_to< Cube >::from(const BaseCube& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap_cube tmp( in.get_ref() ); const Cube& X = tmp.M; Cube out(X.n_rows, X.n_cols, X.n_slices); arrayops::convert( out.memptr(), X.memptr(), X.n_elem ); return out; } template template inline Cube conv_to< Cube >::from(const BaseCube& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const unwrap_cube tmp( in.get_ref() ); const Cube& X = tmp.M; Cube out(X.n_rows, X.n_cols, X.n_slices); arrayops::convert_cx( out.memptr(), X.memptr(), X.n_elem ); return out; } //! conversion to std::vector from Armadillo Base objects template class conv_to< std::vector > { public: template inline static std::vector from(const Base& in, const typename arma_not_cx::result* junk = 0); template inline static std::vector from(const Base& in, const typename arma_cx_only::result* junk = 0); }; template template inline std::vector conv_to< std::vector >::from(const Base& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const quasi_unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); const uword N = X.n_elem; std::vector out(N); if(N > 0) { arrayops::convert( &(out[0]), X.memptr(), N ); } return out; } template template inline std::vector conv_to< std::vector >::from(const Base& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const quasi_unwrap tmp(in.get_ref()); const Mat& X = tmp.M; arma_debug_check( ( (X.is_vec() == false) && (X.is_empty() == false) ), "conv_to(): given object can't be interpreted as a vector" ); const uword N = X.n_elem; std::vector out(N); if(N > 0) { arrayops::convert_cx( &(out[0]), X.memptr(), N ); } return out; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_unique.hpp0000666000000000000000000000125412620272703021452 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Arnold Wiliem //! \addtogroup fn_unique //! @{ template inline typename enable_if2 < is_arma_type::value, const Op >::result unique(const T1& A) { arma_extra_debug_sigprint(); return Op(A); } //! @} armadillo-6.500.5/include/armadillo_bits/diskio_meat.hpp0000666000000000000000000030656212622013021021747 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ian Cullinan // Written by Ryan Curtin // Written by Szabolcs Horvat //! \addtogroup diskio //! @{ //! Generate the first line of the header used for saving matrices in text format. //! Format: "ARMA_MAT_TXT_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_txt_header(const Mat& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value) { return std::string("ARMA_MAT_TXT_IU001"); } else if(is_s8::value) { return std::string("ARMA_MAT_TXT_IS001"); } else if(is_u16::value) { return std::string("ARMA_MAT_TXT_IU002"); } else if(is_s16::value) { return std::string("ARMA_MAT_TXT_IS002"); } else if(is_u32::value) { return std::string("ARMA_MAT_TXT_IU004"); } else if(is_s32::value) { return std::string("ARMA_MAT_TXT_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value) { return std::string("ARMA_MAT_TXT_IU008"); } else if(is_s64::value) { return std::string("ARMA_MAT_TXT_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value) { return std::string("ARMA_MAT_TXT_IU004"); } else if(is_slng_t_32::value) { return std::string("ARMA_MAT_TXT_IS004"); } else if(is_ulng_t_64::value) { return std::string("ARMA_MAT_TXT_IU008"); } else if(is_slng_t_64::value) { return std::string("ARMA_MAT_TXT_IS008"); } #endif else if(is_float::value) { return std::string("ARMA_MAT_TXT_FN004"); } else if(is_double::value) { return std::string("ARMA_MAT_TXT_FN008"); } else if(is_complex_float::value) { return std::string("ARMA_MAT_TXT_FC008"); } else if(is_complex_double::value) { return std::string("ARMA_MAT_TXT_FC016"); } else { return std::string(); } } //! Generate the first line of the header used for saving matrices in binary format. //! Format: "ARMA_MAT_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_bin_header(const Mat& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value) { return std::string("ARMA_MAT_BIN_IU001"); } else if(is_s8::value) { return std::string("ARMA_MAT_BIN_IS001"); } else if(is_u16::value) { return std::string("ARMA_MAT_BIN_IU002"); } else if(is_s16::value) { return std::string("ARMA_MAT_BIN_IS002"); } else if(is_u32::value) { return std::string("ARMA_MAT_BIN_IU004"); } else if(is_s32::value) { return std::string("ARMA_MAT_BIN_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value) { return std::string("ARMA_MAT_BIN_IU008"); } else if(is_s64::value) { return std::string("ARMA_MAT_BIN_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value) { return std::string("ARMA_MAT_BIN_IU004"); } else if(is_slng_t_32::value) { return std::string("ARMA_MAT_BIN_IS004"); } else if(is_ulng_t_64::value) { return std::string("ARMA_MAT_BIN_IU008"); } else if(is_slng_t_64::value) { return std::string("ARMA_MAT_BIN_IS008"); } #endif else if(is_float::value) { return std::string("ARMA_MAT_BIN_FN004"); } else if(is_double::value) { return std::string("ARMA_MAT_BIN_FN008"); } else if(is_complex_float::value) { return std::string("ARMA_MAT_BIN_FC008"); } else if(is_complex_double::value) { return std::string("ARMA_MAT_BIN_FC016"); } else { return std::string(); } } //! Generate the first line of the header used for saving matrices in binary format. //! Format: "ARMA_SPM_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_bin_header(const SpMat& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value) { return std::string("ARMA_SPM_BIN_IU001"); } else if(is_s8::value) { return std::string("ARMA_SPM_BIN_IS001"); } else if(is_u16::value) { return std::string("ARMA_SPM_BIN_IU002"); } else if(is_s16::value) { return std::string("ARMA_SPM_BIN_IS002"); } else if(is_u32::value) { return std::string("ARMA_SPM_BIN_IU004"); } else if(is_s32::value) { return std::string("ARMA_SPM_BIN_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value) { return std::string("ARMA_SPM_BIN_IU008"); } else if(is_s64::value) { return std::string("ARMA_SPM_BIN_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value) { return std::string("ARMA_SPM_BIN_IU004"); } else if(is_slng_t_32::value) { return std::string("ARMA_SPM_BIN_IS004"); } else if(is_ulng_t_64::value) { return std::string("ARMA_SPM_BIN_IU008"); } else if(is_slng_t_64::value) { return std::string("ARMA_SPM_BIN_IS008"); } #endif else if(is_float::value) { return std::string("ARMA_SPM_BIN_FN004"); } else if(is_double::value) { return std::string("ARMA_SPM_BIN_FN008"); } else if(is_complex_float::value) { return std::string("ARMA_SPM_BIN_FC008"); } else if(is_complex_double::value) { return std::string("ARMA_SPM_BIN_FC016"); } else { return std::string(); } } //! Generate the first line of the header used for saving cubes in text format. //! Format: "ARMA_CUB_TXT_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_txt_header(const Cube& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value) { return std::string("ARMA_CUB_TXT_IU001"); } else if(is_s8::value) { return std::string("ARMA_CUB_TXT_IS001"); } else if(is_u16::value) { return std::string("ARMA_CUB_TXT_IU002"); } else if(is_s16::value) { return std::string("ARMA_CUB_TXT_IS002"); } else if(is_u32::value) { return std::string("ARMA_CUB_TXT_IU004"); } else if(is_s32::value) { return std::string("ARMA_CUB_TXT_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value) { return std::string("ARMA_CUB_TXT_IU008"); } else if(is_s64::value) { return std::string("ARMA_CUB_TXT_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value) { return std::string("ARMA_CUB_TXT_IU004"); } else if(is_slng_t_32::value) { return std::string("ARMA_CUB_TXT_IS004"); } else if(is_ulng_t_64::value) { return std::string("ARMA_CUB_TXT_IU008"); } else if(is_slng_t_64::value) { return std::string("ARMA_CUB_TXT_IS008"); } #endif else if(is_float::value) { return std::string("ARMA_CUB_TXT_FN004"); } else if(is_double::value) { return std::string("ARMA_CUB_TXT_FN008"); } else if(is_complex_float::value) { return std::string("ARMA_CUB_TXT_FC008"); } else if(is_complex_double::value) { return std::string("ARMA_CUB_TXT_FC016"); } else { return std::string(); } } //! Generate the first line of the header used for saving cubes in binary format. //! Format: "ARMA_CUB_BIN_ABXYZ". //! A is one of: I (for integral types) or F (for floating point types). //! B is one of: U (for unsigned types), S (for signed types), N (for not applicable) or C (for complex types). //! XYZ specifies the width of each element in terms of bytes, e.g. "008" indicates eight bytes. template inline std::string diskio::gen_bin_header(const Cube& x) { arma_type_check(( is_supported_elem_type::value == false )); arma_ignore(x); if(is_u8::value) { return std::string("ARMA_CUB_BIN_IU001"); } else if(is_s8::value) { return std::string("ARMA_CUB_BIN_IS001"); } else if(is_u16::value) { return std::string("ARMA_CUB_BIN_IU002"); } else if(is_s16::value) { return std::string("ARMA_CUB_BIN_IS002"); } else if(is_u32::value) { return std::string("ARMA_CUB_BIN_IU004"); } else if(is_s32::value) { return std::string("ARMA_CUB_BIN_IS004"); } #if defined(ARMA_USE_U64S64) else if(is_u64::value) { return std::string("ARMA_CUB_BIN_IU008"); } else if(is_s64::value) { return std::string("ARMA_CUB_BIN_IS008"); } #endif #if defined(ARMA_ALLOW_LONG) else if(is_ulng_t_32::value) { return std::string("ARMA_CUB_BIN_IU004"); } else if(is_slng_t_32::value) { return std::string("ARMA_CUB_BIN_IS004"); } else if(is_ulng_t_64::value) { return std::string("ARMA_CUB_BIN_IU008"); } else if(is_slng_t_64::value) { return std::string("ARMA_CUB_BIN_IS008"); } #endif else if(is_float::value) { return std::string("ARMA_CUB_BIN_FN004"); } else if(is_double::value) { return std::string("ARMA_CUB_BIN_FN008"); } else if(is_complex_float::value) { return std::string("ARMA_CUB_BIN_FC008"); } else if(is_complex_double::value) { return std::string("ARMA_CUB_BIN_FC016"); } else { return std::string(); } } inline file_type diskio::guess_file_type(std::istream& f) { arma_extra_debug_sigprint(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); f.clear(); f.seekg(0, ios::end); f.clear(); const std::fstream::pos_type pos2 = f.tellg(); const uword N = ( (pos1 >= 0) && (pos2 >= 0) && (pos2 > pos1) ) ? uword(pos2 - pos1) : 0; f.clear(); f.seekg(pos1); if(N == 0) { return file_type_unknown; } podarray data(N); data.zeros(); unsigned char* ptr = data.memptr(); f.clear(); f.read( reinterpret_cast(ptr), std::streamsize(N) ); const bool load_okay = f.good(); f.clear(); f.seekg(pos1); bool has_binary = false; bool has_bracket = false; bool has_comma = false; if(load_okay == true) { for(uword i=0; i= 123) ) { has_binary = true; break; } // the range checking can be made more elaborate if( (val == '(') || (val == ')') ) { has_bracket = true; } if( (val == ',') ) { has_comma = true; } } } else { return file_type_unknown; } if(has_binary) { return raw_binary; } if(has_comma && (has_bracket == false)) { return csv_ascii; } return raw_ascii; } //! Append a quasi-random string to the given filename. //! The rand() function is deliberately not used, //! as rand() has an internal state that changes //! from call to call. Such states should not be //! modified in scientific applications, where the //! results should be reproducable and not affected //! by saving data. inline arma_cold std::string diskio::gen_tmp_name(const std::string& x) { union { uword val; void* ptr; } u; u.val = uword(0); u.ptr = const_cast(&x); std::stringstream ss; ss << x << ".tmp_" << std::hex << std::noshowbase << (u.val) << (std::clock()); return ss.str(); } //! Safely rename a file. //! Before renaming, test if we can write to the final file. //! This should prevent: //! (i) overwriting files that are write protected, //! (ii) overwriting directories. inline arma_cold bool diskio::safe_rename(const std::string& old_name, const std::string& new_name) { std::fstream f(new_name.c_str(), std::fstream::out | std::fstream::app); f.put(' '); bool save_okay = f.good(); f.close(); if(save_okay == true) { std::remove(new_name.c_str()); const int mv_result = std::rename(old_name.c_str(), new_name.c_str()); save_okay = (mv_result == 0); } return save_okay; } template inline bool diskio::convert_naninf(eT& val, const std::string& token) { // see if the token represents a NaN or Inf if( (token.length() == 3) || (token.length() == 4) ) { const bool neg = (token[0] == '-'); const bool pos = (token[0] == '+'); const size_t offset = ( (neg || pos) && (token.length() == 4) ) ? 1 : 0; const std::string token2 = token.substr(offset, 3); if( (token2 == "inf") || (token2 == "Inf") || (token2 == "INF") ) { val = neg ? cond_rel< is_signed::value >::make_neg(Datum::inf) : Datum::inf; return true; } else if( (token2 == "nan") || (token2 == "Nan") || (token2 == "NaN") || (token2 == "NAN") ) { val = Datum::nan; return true; } } return false; } template inline bool diskio::convert_naninf(std::complex& val, const std::string& token) { if( token.length() >= 5 ) { std::stringstream ss( token.substr(1, token.length()-2) ); // strip '(' at the start and ')' at the end std::string token_real; std::string token_imag; std::getline(ss, token_real, ','); std::getline(ss, token_imag); std::stringstream ss_real(token_real); std::stringstream ss_imag(token_imag); T val_real = T(0); T val_imag = T(0); ss_real >> val_real; ss_imag >> val_imag; bool success_real = true; bool success_imag = true; if(ss_real.fail() == true) { success_real = diskio::convert_naninf( val_real, token_real ); } if(ss_imag.fail() == true) { success_imag = diskio::convert_naninf( val_imag, token_imag ); } val = std::complex(val_real, val_imag); return (success_real && success_imag); } return false; } //! Save a matrix as raw text (no header, human readable). //! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements. template inline bool diskio::save_raw_ascii(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::fstream f(tmp_name.c_str(), std::fstream::out); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_raw_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix as raw text (no header, human readable). //! Matrices can be loaded in Matlab and Octave, as long as they don't have complex elements. template inline bool diskio::save_raw_ascii(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); uword cell_width; // TODO: need sane values for complex numbers if( (is_float::value) || (is_double::value) ) { f.setf(ios::scientific); f.precision(12); cell_width = 20; } for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float::value) || (is_double::value) ) { f.width(cell_width); } arma_ostream::print_elem(f, x.at(row,col), false); } f.put('\n'); } return f.good(); } //! Save a matrix as raw binary (no header) template inline bool diskio::save_raw_binary(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_raw_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_raw_binary(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); f.write( reinterpret_cast(x.mem), std::streamsize(x.n_elem*sizeof(eT)) ); return f.good(); } //! Save a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::save_arma_ascii(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::save_arma_ascii(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); f << diskio::gen_txt_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << '\n'; uword cell_width; // TODO: need sane values for complex numbers if( (is_float::value) || (is_double::value) ) { f.setf(ios::scientific); f.precision(12); cell_width = 20; } for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float::value) || (is_double::value) ) { f.width(cell_width); } arma_ostream::print_elem(f, x.at(row,col), false); } f.put('\n'); } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a matrix in CSV text format (human readable) template inline bool diskio::save_csv_ascii(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_csv_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in CSV text format (human readable) template inline bool diskio::save_csv_ascii(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); // TODO: need sane values for complex numbers if( (is_float::value) || (is_double::value) ) { f.setf(ios::scientific); f.precision(12); } uword x_n_rows = x.n_rows; uword x_n_cols = x.n_cols; for(uword row=0; row < x_n_rows; ++row) { for(uword col=0; col < x_n_cols; ++col) { arma_ostream::print_elem(f, x.at(row,col), false); if( col < (x_n_cols-1) ) { f.put(','); } } f.put('\n'); } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions template inline bool diskio::save_arma_binary(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions template inline bool diskio::save_arma_binary(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); f << diskio::gen_bin_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << '\n'; f.write( reinterpret_cast(x.mem), std::streamsize(x.n_elem*sizeof(eT)) ); return f.good(); } //! Save a matrix as a PGM greyscale image template inline bool diskio::save_pgm_binary(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::fstream f(tmp_name.c_str(), std::fstream::out | std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_pgm_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } // // TODO: // add functionality to save the image in a normalised format, // i.e. scaled so that every value falls in the [0,255] range. //! Save a matrix as a PGM greyscale image template inline bool diskio::save_pgm_binary(const Mat& x, std::ostream& f) { arma_extra_debug_sigprint(); f << "P5" << '\n'; f << x.n_cols << ' ' << x.n_rows << '\n'; f << 255 << '\n'; const uword n_elem = x.n_rows * x.n_cols; podarray tmp(n_elem); uword i = 0; for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { tmp[i] = u8( x.at(row,col) ); // TODO: add round() ? ++i; } } f.write(reinterpret_cast(tmp.mem), std::streamsize(n_elem) ); return f.good(); } //! Save a matrix as a PGM greyscale image template inline bool diskio::save_pgm_binary(const Mat< std::complex >& x, const std::string& final_name) { arma_extra_debug_sigprint(); const uchar_mat tmp = conv_to::from(x); return diskio::save_pgm_binary(tmp, final_name); } //! Save a matrix as a PGM greyscale image template inline bool diskio::save_pgm_binary(const Mat< std::complex >& x, std::ostream& f) { arma_extra_debug_sigprint(); const uchar_mat tmp = conv_to::from(x); return diskio::save_pgm_binary(tmp, f); } //! Save a matrix as part of a HDF5 file template inline bool diskio::save_hdf5_binary(const Mat& x, const std::string& final_name) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) { #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Disable annoying HDF5 error messages. arma_H5Eset_auto(H5E_DEFAULT, NULL, NULL); } #endif bool save_okay = false; const std::string tmp_name = diskio::gen_tmp_name(final_name); // Set up the file according to HDF5's preferences hid_t file = arma_H5Fcreate(tmp_name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); // We need to create a dataset, datatype, and dataspace hsize_t dims[2]; dims[1] = x.n_rows; dims[0] = x.n_cols; hid_t dataspace = arma_H5Screate_simple(2, dims, NULL); // treat the matrix as a 2d array dataspace hid_t datatype = hdf5_misc::get_hdf5_type(); // If this returned something invalid, well, it's time to crash. arma_check(datatype == -1, "Mat::save(): unknown datatype for HDF5"); // MATLAB forces the users to specify a name at save time for HDF5; Octave // will use the default of 'dataset' unless otherwise specified, so we will // use that. hid_t dataset = arma_H5Dcreate(file, "dataset", datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); // H5Dwrite does not make a distinction between row-major and column-major; // it just writes the memory. MATLAB and Octave store HDF5 matrices as // column-major, though, so we can save ours like that too and not need to // transpose. herr_t status = arma_H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, x.mem); save_okay = (status >= 0); arma_H5Dclose(dataset); arma_H5Tclose(datatype); arma_H5Sclose(dataspace); arma_H5Fclose(file); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } return save_okay; } #else { arma_ignore(x); arma_ignore(final_name); arma_stop("Mat::save(): use of HDF5 needs to be enabled"); return false; } #endif } //! Load a matrix as raw text (no header, human readable). //! Can read matrices saved as text in Matlab and Octave. //! NOTE: this is much slower than reading a file with a header. template inline bool diskio::load_raw_ascii(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_raw_ascii(x, f, err_msg); f.close(); } return load_okay; } //! Load a matrix as raw text (no header, human readable). //! Can read matrices saved as text in Matlab and Octave. //! NOTE: this is much slower than reading a file with a header. template inline bool diskio::load_raw_ascii(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = f.good(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; bool f_n_cols_found = false; std::string line_string; std::string token; std::stringstream line_stream; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_n_cols = 0; while (line_stream >> token) { ++line_n_cols; } if(f_n_cols_found == false) { f_n_cols = line_n_cols; f_n_cols_found = true; } else { if(line_n_cols != f_n_cols) { err_msg = "inconsistent number of columns in "; load_okay = false; } } ++f_n_rows; } if(load_okay == true) { f.clear(); f.seekg(pos1); x.set_size(f_n_rows, f_n_cols); std::stringstream ss; for(uword row=0; (row < x.n_rows) && (load_okay == true); ++row) { for(uword col=0; (col < x.n_cols) && (load_okay == true); ++col) { f >> token; if( (is_signed::value == false) && (token.length() > 0) && (token[0] == '-') ) { x.at(row,col) = eT(0); } else { ss.clear(); ss.str(token); eT val = eT(0); ss >> val; if(ss.fail() == false) { x.at(row,col) = val; } else { const bool success = diskio::convert_naninf( x.at(row,col), token ); if(success == false) { load_okay = false; err_msg = "couldn't interpret data in "; } } } } } } // an empty file indicates an empty matrix if( (f_n_cols_found == false) && (load_okay == true) ) { x.reset(); } return load_okay; } //! Load a matrix in binary format (no header); //! the matrix is assumed to have one column template inline bool diskio::load_raw_binary(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_raw_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_raw_binary(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(err_msg); f.clear(); const std::streampos pos1 = f.tellg(); f.clear(); f.seekg(0, ios::end); f.clear(); const std::streampos pos2 = f.tellg(); const uword N = ( (pos1 >= 0) && (pos2 >= 0) ) ? uword(pos2 - pos1) : 0; f.clear(); //f.seekg(0, ios::beg); f.seekg(pos1); x.set_size(N / sizeof(eT), 1); f.clear(); f.read( reinterpret_cast(x.memptr()), std::streamsize(N) ); return f.good(); } //! Load a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::load_arma_ascii(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f(name.c_str()); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_ascii(x, f, err_msg); f.close(); } return load_okay; } //! Load a matrix in text format (human readable), //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::load_arma_ascii(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); std::streampos pos = f.tellg(); bool load_okay = true; std::string f_header; uword f_n_rows; uword f_n_cols; f >> f_header; f >> f_n_rows; f >> f_n_cols; if(f_header == diskio::gen_txt_header(x)) { x.zeros(f_n_rows, f_n_cols); std::string token; std::stringstream ss; for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f >> token; ss.clear(); ss.str(token); eT val = eT(0); ss >> val; if(ss.fail() == false) { x.at(row,col) = val; } else { diskio::convert_naninf( x.at(row,col), token ); } } } load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } // allow automatic conversion of u32/s32 matrices into u64/s64 matrices if(load_okay == false) { if( (sizeof(eT) == 8) && is_same_type::yes ) { Mat tmp; std::string junk; f.clear(); f.seekg(pos); load_okay = diskio::load_arma_ascii(tmp, f, junk); if(load_okay) { x = conv_to< Mat >::from(tmp); } } else if( (sizeof(eT) == 8) && is_same_type::yes ) { Mat tmp; std::string junk; f.clear(); f.seekg(pos); load_okay = diskio::load_arma_ascii(tmp, f, junk); if(load_okay) { x = conv_to< Mat >::from(tmp); } } } return load_okay; } //! Load a matrix in CSV text format (human readable) template inline bool diskio::load_csv_ascii(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_csv_ascii(x, f, err_msg); f.close(); } return load_okay; } //! Load a matrix in CSV text format (human readable) template inline bool diskio::load_csv_ascii(Mat& x, std::istream& f, std::string&) { arma_extra_debug_sigprint(); bool load_okay = f.good(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; std::string line_string; std::string token; std::stringstream line_stream; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_n_cols = 0; while(line_stream.good() == true) { std::getline(line_stream, token, ','); ++line_n_cols; } if(f_n_cols < line_n_cols) { f_n_cols = line_n_cols; } ++f_n_rows; } f.clear(); f.seekg(pos1); x.zeros(f_n_rows, f_n_cols); uword row = 0; std::stringstream ss; while(f.good() == true) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword col = 0; while(line_stream.good() == true) { std::getline(line_stream, token, ','); if( (is_signed::value == false) && (token.length() > 0) && (token[0] == '-') ) { x.at(row,col) = eT(0); } else { ss.clear(); ss.str(token); eT val = eT(0); ss >> val; if(ss.fail() == false) { x.at(row,col) = val; } else { diskio::convert_naninf( x.at(row,col), token ); } } ++col; } ++row; } return load_okay; } //! Load a matrix in binary format, //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::load_arma_binary(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_arma_binary(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); std::streampos pos = f.tellg(); bool load_okay = true; std::string f_header; uword f_n_rows; uword f_n_cols; f >> f_header; f >> f_n_rows; f >> f_n_cols; if(f_header == diskio::gen_bin_header(x)) { //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Windows machine a newline could be two characters f.get(); x.set_size(f_n_rows,f_n_cols); f.read( reinterpret_cast(x.memptr()), std::streamsize(x.n_elem*sizeof(eT)) ); load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } // allow automatic conversion of u32/s32 matrices into u64/s64 matrices if(load_okay == false) { if( (sizeof(eT) == 8) && is_same_type::yes ) { Mat tmp; std::string junk; f.clear(); f.seekg(pos); load_okay = diskio::load_arma_binary(tmp, f, junk); if(load_okay) { x = conv_to< Mat >::from(tmp); } } else if( (sizeof(eT) == 8) && is_same_type::yes ) { Mat tmp; std::string junk; f.clear(); f.seekg(pos); load_okay = diskio::load_arma_binary(tmp, f, junk); if(load_okay) { x = conv_to< Mat >::from(tmp); } } } return load_okay; } inline void diskio::pnm_skip_comments(std::istream& f) { while( isspace(f.peek()) ) { while( isspace(f.peek()) ) { f.get(); } if(f.peek() == '#') { while( (f.peek() != '\r') && (f.peek()!='\n') ) { f.get(); } } } } //! Load a PGM greyscale image as a matrix template inline bool diskio::load_pgm_binary(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_pgm_binary(x, f, err_msg); f.close(); } return load_okay; } //! Load a PGM greyscale image as a matrix template inline bool diskio::load_pgm_binary(Mat& x, std::istream& f, std::string& err_msg) { bool load_okay = true; std::string f_header; f >> f_header; if(f_header == "P5") { uword f_n_rows = 0; uword f_n_cols = 0; int f_maxval = 0; diskio::pnm_skip_comments(f); f >> f_n_cols; diskio::pnm_skip_comments(f); f >> f_n_rows; diskio::pnm_skip_comments(f); f >> f_maxval; f.get(); if( (f_maxval > 0) || (f_maxval <= 65535) ) { x.set_size(f_n_rows,f_n_cols); if(f_maxval <= 255) { const uword n_elem = f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(n_elem) ); uword i = 0; //cout << "f_n_cols = " << f_n_cols << endl; //cout << "f_n_rows = " << f_n_rows << endl; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { x.at(row,col) = eT(tmp[i]); ++i; } } } else { const uword n_elem = f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(n_elem*2) ); uword i = 0; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { x.at(row,col) = eT(tmp[i]); ++i; } } } } else { load_okay = false; err_msg = "currently no code available to handle loading "; } if(f.good() == false) { load_okay = false; } } else { load_okay = false; err_msg = "unsupported header in "; } return load_okay; } //! Load a PGM greyscale image as a matrix template inline bool diskio::load_pgm_binary(Mat< std::complex >& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); uchar_mat tmp; const bool load_okay = diskio::load_pgm_binary(tmp, name, err_msg); x = conv_to< Mat< std::complex > >::from(tmp); return load_okay; } //! Load a PGM greyscale image as a matrix template inline bool diskio::load_pgm_binary(Mat< std::complex >& x, std::istream& is, std::string& err_msg) { arma_extra_debug_sigprint(); uchar_mat tmp; const bool load_okay = diskio::load_pgm_binary(tmp, is, err_msg); x = conv_to< Mat< std::complex > >::from(tmp); return load_okay; } //! Load a HDF5 file as a matrix template inline bool diskio::load_hdf5_binary(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) { // These may be necessary to store the error handler (if we need to). herr_t (*old_func)(hid_t, void*); void *old_client_data; #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Save old error handler. arma_H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data); // Disable annoying HDF5 error messages. arma_H5Eset_auto(H5E_DEFAULT, NULL, NULL); } #endif bool load_okay = false; hid_t fid = arma_H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); if(fid >= 0) { // MATLAB HDF5 dataset names are user-specified; // Octave tends to store the datasets in a group, with the actual dataset being referred to as "value". // So we will search for "dataset" and "value", and if those are not found we will take the first dataset we do find. std::vector searchNames; searchNames.push_back("dataset"); searchNames.push_back("value"); hid_t dataset = hdf5_misc::search_hdf5_file(searchNames, fid, 2, false); if(dataset >= 0) { hid_t filespace = arma_H5Dget_space(dataset); // This must be <= 2 due to our search rules. const int ndims = arma_H5Sget_simple_extent_ndims(filespace); hsize_t dims[2]; const herr_t query_status = arma_H5Sget_simple_extent_dims(filespace, dims, NULL); // arma_check(query_status < 0, "Mat::load(): cannot get size of HDF5 dataset"); if(query_status < 0) { err_msg = "cannot get size of HDF5 dataset in "; arma_H5Sclose(filespace); arma_H5Dclose(dataset); arma_H5Fclose(fid); #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Restore HDF5 error handler. arma_H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); } #endif return false; } if(ndims == 1) { dims[1] = 1; } // Vector case; fake second dimension (one column). x.set_size(dims[1], dims[0]); // Now we have to see what type is stored to figure out how to load it. hid_t datatype = arma_H5Dget_type(dataset); hid_t mat_type = hdf5_misc::get_hdf5_type(); // If these are the same type, it is simple. if(arma_H5Tequal(datatype, mat_type) > 0) { // Load directly; H5S_ALL used so that we load the entire dataset. hid_t read_status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(x.memptr())); if(read_status >= 0) { load_okay = true; } } else { // Load into another array and convert its type accordingly. hid_t read_status = hdf5_misc::load_and_convert_hdf5(x.memptr(), dataset, datatype, x.n_elem); if(read_status >= 0) { load_okay = true; } } // Now clean up. arma_H5Tclose(datatype); arma_H5Tclose(mat_type); arma_H5Sclose(filespace); } arma_H5Dclose(dataset); arma_H5Fclose(fid); if(load_okay == false) { err_msg = "unsupported or incorrect HDF5 data in "; } } else { err_msg = "cannot open file "; } #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Restore HDF5 error handler. arma_H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); } #endif return load_okay; } #else { arma_ignore(x); arma_ignore(name); arma_ignore(err_msg); arma_stop("Mat::load(): use of HDF5 needs to be enabled"); return false; } #endif } //! Try to load a matrix by automatically determining its type template inline bool diskio::load_auto_detect(Mat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) // We're currently using the C bindings for the HDF5 library, which don't support C++ streams if( arma_H5Fis_hdf5(name.c_str()) ) { return load_hdf5_binary(x, name, err_msg); } #endif std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_auto_detect(x, f, err_msg); f.close(); } return load_okay; } //! Try to load a matrix by automatically determining its type template inline bool diskio::load_auto_detect(Mat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); static const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT"; static const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN"; static const std::string P5 = "P5"; podarray raw_header( uword(ARMA_MAT_TXT.length()) + 1); std::streampos pos = f.tellg(); f.read( raw_header.memptr(), std::streamsize(ARMA_MAT_TXT.length()) ); raw_header[uword(ARMA_MAT_TXT.length())] = '\0'; f.clear(); f.seekg(pos); const std::string header = raw_header.mem; if(ARMA_MAT_TXT == header.substr(0,ARMA_MAT_TXT.length())) { return load_arma_ascii(x, f, err_msg); } else if(ARMA_MAT_BIN == header.substr(0,ARMA_MAT_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(P5 == header.substr(0,P5.length())) { return load_pgm_binary(x, f, err_msg); } else { const file_type ft = guess_file_type(f); switch(ft) { case csv_ascii: return load_csv_ascii(x, f, err_msg); break; case raw_binary: return load_raw_binary(x, f, err_msg); break; case raw_ascii: return load_raw_ascii(x, f, err_msg); break; default: err_msg = "unknown data in "; return false; } } return false; } // // sparse matrices // //! Save a matrix in ASCII coord format template inline bool diskio::save_coord_ascii(const SpMat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_coord_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in ASCII coord format template inline bool diskio::save_coord_ascii(const SpMat& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); typename SpMat::const_iterator iter = x.begin(); typename SpMat::const_iterator iter_end = x.end(); for(; iter != iter_end; ++iter) { f.setf(ios::fixed); f << iter.row() << ' ' << iter.col() << ' '; if( (is_float::value) || (is_double::value) ) { f.setf(ios::scientific); f.precision(12); } f << (*iter) << '\n'; } // make sure it's possible to figure out the matrix size later if( (x.n_rows > 0) && (x.n_cols > 0) ) { const uword max_row = (x.n_rows > 0) ? x.n_rows-1 : 0; const uword max_col = (x.n_cols > 0) ? x.n_cols-1 : 0; if( x.at(max_row, max_col) == eT(0) ) { f.setf(ios::fixed); f << max_row << ' ' << max_col << " 0\n"; } } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a matrix in ASCII coord format (complex numbers) template inline bool diskio::save_coord_ascii(const SpMat< std::complex >& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); typedef typename std::complex eT; typename SpMat::const_iterator iter = x.begin(); typename SpMat::const_iterator iter_end = x.end(); for(; iter != iter_end; ++iter) { f.setf(ios::fixed); f << iter.row() << ' ' << iter.col() << ' '; if( (is_float::value) || (is_double::value) ) { f.setf(ios::scientific); f.precision(12); } const eT val = (*iter); f << val.real() << ' ' << val.imag() << '\n'; } // make sure it's possible to figure out the matrix size later if( (x.n_rows > 0) && (x.n_cols > 0) ) { const uword max_row = (x.n_rows > 0) ? x.n_rows-1 : 0; const uword max_col = (x.n_cols > 0) ? x.n_cols-1 : 0; if( x.at(max_row, max_col) == eT(0) ) { f.setf(ios::fixed); f << max_row << ' ' << max_col << " 0 0\n"; } } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions template inline bool diskio::save_arma_binary(const SpMat& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a matrix in binary format, //! with a header that stores the matrix type as well as its dimensions template inline bool diskio::save_arma_binary(const SpMat& x, std::ostream& f) { arma_extra_debug_sigprint(); f << diskio::gen_bin_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_nonzero << '\n'; f.write( reinterpret_cast(x.values), std::streamsize(x.n_nonzero*sizeof(eT)) ); f.write( reinterpret_cast(x.row_indices), std::streamsize(x.n_nonzero*sizeof(uword)) ); f.write( reinterpret_cast(x.col_ptrs), std::streamsize((x.n_cols+1)*sizeof(uword)) ); return f.good(); } template inline bool diskio::load_coord_ascii(SpMat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_coord_ascii(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_coord_ascii(SpMat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(err_msg); bool load_okay = f.good(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; uword f_n_nz = 0; bool size_found = false; std::string line_string; std::string token; std::stringstream line_stream; std::stringstream ss; uword last_line_row = 0; uword last_line_col = 0; bool first_line = true; bool weird_format = false; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_row = 0; uword line_col = 0; // a valid line in co-ord format has at least 2 entries line_stream >> line_row; if(line_stream.good() == false) { load_okay = false; break; } line_stream >> line_col; size_found = true; if(f_n_rows < line_row) f_n_rows = line_row; if(f_n_cols < line_col) f_n_cols = line_col; if(first_line == true) { first_line = false; } else { if( (line_col < last_line_col) || ((line_row <= last_line_row) && (line_col <= last_line_col)) ) { weird_format = true; } } last_line_row = line_row; last_line_col = line_col; if(line_stream.good() == true) { eT final_val = eT(0); line_stream >> token; if(line_stream.fail() == false) { eT val = eT(0); ss.clear(); ss.str(token); ss >> val; if(ss.fail() == false) { final_val = val; } else { val = eT(0); const bool success = diskio::convert_naninf( val, token ); if(success == true) { final_val = val; } } } if(final_val != eT(0)) { ++f_n_nz; } } } if(size_found == true) { // take into account that indices start at 0 f_n_rows++; f_n_cols++; } if(load_okay == true) { f.clear(); f.seekg(pos1); x.set_size(f_n_rows, f_n_cols); if(weird_format == false) { x.mem_resize(f_n_nz); } uword pos = 0; while(f.good() == true) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_row = 0; uword line_col = 0; line_stream >> line_row; line_stream >> line_col; eT final_val = eT(0); line_stream >> token; if(line_stream.fail() == false) { eT val = eT(0); ss.clear(); ss.str(token); ss >> val; if(ss.fail() == false) { final_val = val; } else { val = eT(0); const bool success = diskio::convert_naninf( val, token ); if(success == true) { final_val = val; } } } if(final_val != eT(0)) { if(weird_format == false) { access::rw(x.row_indices[pos]) = line_row; access::rw(x.values[pos]) = final_val; ++access::rw(x.col_ptrs[line_col + 1]); ++pos; } else { x.at(line_row,line_col) = final_val; } } } if(weird_format == false) { for(uword c = 1; c <= f_n_cols; ++c) { access::rw(x.col_ptrs[c]) += x.col_ptrs[c - 1]; } } } return load_okay; } template inline bool diskio::load_coord_ascii(SpMat< std::complex >& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(err_msg); bool load_okay = f.good(); f.clear(); const std::fstream::pos_type pos1 = f.tellg(); // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; uword f_n_nz = 0; bool size_found = false; std::string line_string; std::string token_real; std::string token_imag; std::stringstream line_stream; std::stringstream ss; uword last_line_row = 0; uword last_line_col = 0; bool first_line = true; bool weird_format = false; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_row = 0; uword line_col = 0; // a valid line in co-ord format has at least 2 entries line_stream >> line_row; if(line_stream.good() == false) { load_okay = false; break; } line_stream >> line_col; size_found = true; if(f_n_rows < line_row) f_n_rows = line_row; if(f_n_cols < line_col) f_n_cols = line_col; if(first_line == true) { first_line = false; } else { if( (line_col < last_line_col) || ((line_row <= last_line_row) && (line_col <= last_line_col)) ) { weird_format = true; } } last_line_row = line_row; last_line_col = line_col; if(line_stream.good() == true) { T final_val_real = T(0); T final_val_imag = T(0); line_stream >> token_real; if(line_stream.fail() == false) { T val_real = T(0); ss.clear(); ss.str(token_real); ss >> val_real; if(ss.fail() == false) { final_val_real = val_real; } else { val_real = T(0); const bool success = diskio::convert_naninf( val_real, token_real ); if(success == true) { final_val_real = val_real; } } } line_stream >> token_imag; if(line_stream.fail() == false) { T val_imag = T(0); ss.clear(); ss.str(token_imag); ss >> val_imag; if(ss.fail() == false) { final_val_imag = val_imag; } else { val_imag = T(0); const bool success = diskio::convert_naninf( val_imag, token_imag ); if(success == true) { final_val_imag = val_imag; } } } if( (final_val_real != T(0)) || (final_val_imag != T(0)) ) { ++f_n_nz; } } } if(size_found == true) { // take into account that indices start at 0 f_n_rows++; f_n_cols++; } if(load_okay == true) { f.clear(); f.seekg(pos1); x.set_size(f_n_rows, f_n_cols); if(weird_format == false) { x.mem_resize(f_n_nz); } uword pos = 0; while(f.good() == true) { std::getline(f, line_string); if(line_string.size() == 0) { break; } line_stream.clear(); line_stream.str(line_string); uword line_row = 0; uword line_col = 0; line_stream >> line_row; line_stream >> line_col; T final_val_real = T(0); T final_val_imag = T(0); line_stream >> token_real; if(line_stream.fail() == false) { T val_real = T(0); ss.clear(); ss.str(token_real); ss >> val_real; if(ss.fail() == false) { final_val_real = val_real; } else { val_real = T(0); const bool success = diskio::convert_naninf( val_real, token_real ); if(success == true) { final_val_real = val_real; } } } line_stream >> token_imag; if(line_stream.fail() == false) { T val_imag = T(0); ss.clear(); ss.str(token_imag); ss >> val_imag; if(ss.fail() == false) { final_val_imag = val_imag; } else { val_imag = T(0); const bool success = diskio::convert_naninf( val_imag, token_imag ); if(success == true) { final_val_imag = val_imag; } } } if( (final_val_real != T(0)) || (final_val_imag != T(0)) ) { if(weird_format == false) { access::rw(x.row_indices[pos]) = line_row; access::rw(x.values[pos]) = std::complex(final_val_real, final_val_imag); ++access::rw(x.col_ptrs[line_col + 1]); ++pos; } else { x.at(line_row,line_col) = std::complex(final_val_real, final_val_imag); } } } if(weird_format == false) { for(uword c = 1; c <= f_n_cols; ++c) { access::rw(x.col_ptrs[c]) += x.col_ptrs[c - 1]; } } } return load_okay; } //! Load a matrix in binary format, //! with a header that indicates the matrix type as well as its dimensions template inline bool diskio::load_arma_binary(SpMat& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_arma_binary(SpMat& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; f >> f_header; if(f_header == diskio::gen_bin_header(x)) { uword f_n_rows; uword f_n_cols; uword f_n_nz; f >> f_n_rows; f >> f_n_cols; f >> f_n_nz; //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Windows machine a newline could be two characters f.get(); x.set_size(f_n_rows, f_n_cols); x.mem_resize(f_n_nz); f.read( reinterpret_cast(access::rwp(x.values)), std::streamsize(x.n_nonzero*sizeof(eT)) ); std::streampos pos = f.tellg(); f.read( reinterpret_cast(access::rwp(x.row_indices)), std::streamsize(x.n_nonzero*sizeof(uword)) ); f.read( reinterpret_cast(access::rwp(x.col_ptrs)), std::streamsize((x.n_cols+1)*sizeof(uword)) ); bool check1 = true; for(uword i=0; i < x.n_nonzero; ++i) { if(x.values[i] == eT(0)) { check1 = false; break; } } bool check2 = true; for(uword i=0; i < x.n_cols; ++i) { if(x.col_ptrs[i+1] < x.col_ptrs[i]) { check2 = false; break; } } bool check3 = (x.col_ptrs[x.n_cols] == x.n_nonzero); if((check1 == true) && ((check2 == false) || (check3 == false))) { if(sizeof(uword) == 8) { arma_extra_debug_print("detected inconsistent data while loading; re-reading integer parts as u32"); // inconstency could be due to a different uword size used during saving, // so try loading the row_indices and col_ptrs under the assumption of 32 bit unsigned integers f.clear(); f.seekg(pos); podarray tmp_a(x.n_nonzero ); tmp_a.zeros(); podarray tmp_b(x.n_cols + 1); tmp_b.zeros(); f.read( reinterpret_cast(tmp_a.memptr()), std::streamsize( x.n_nonzero * sizeof(u32)) ); f.read( reinterpret_cast(tmp_b.memptr()), std::streamsize((x.n_cols + 1) * sizeof(u32)) ); check2 = true; for(uword i=0; i < x.n_cols; ++i) { if(tmp_b[i+1] < tmp_b[i]) { check2 = false; break; } } check3 = (tmp_b[x.n_cols] == x.n_nonzero); load_okay = f.good(); if( load_okay && (check2 == true) && (check3 == true) ) { arma_extra_debug_print("reading integer parts as u32 succeeded"); arrayops::convert(access::rwp(x.row_indices), tmp_a.memptr(), x.n_nonzero ); arrayops::convert(access::rwp(x.col_ptrs), tmp_b.memptr(), x.n_cols + 1); } else { arma_extra_debug_print("reading integer parts as u32 failed"); } } } if((check1 == false) || (check2 == false) || (check3 == false)) { load_okay = false; err_msg = "inconsistent data in "; } else { load_okay = f.good(); } } else { load_okay = false; err_msg = "incorrect header in "; } return load_okay; } // cubes //! Save a cube as raw text (no header, human readable). template inline bool diskio::save_raw_ascii(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::fstream f(tmp_name.c_str(), std::fstream::out); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = save_raw_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a cube as raw text (no header, human readable). template inline bool diskio::save_raw_ascii(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); uword cell_width; // TODO: need sane values for complex numbers if( (is_float::value) || (is_double::value) ) { f.setf(ios::scientific); f.precision(12); cell_width = 20; } for(uword slice=0; slice < x.n_slices; ++slice) { for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float::value) || (is_double::value) ) { f.width(cell_width); } arma_ostream::print_elem(f, x.at(row,col,slice), false); } f.put('\n'); } } return f.good(); } //! Save a cube as raw binary (no header) template inline bool diskio::save_raw_binary(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_raw_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_raw_binary(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); f.write( reinterpret_cast(x.mem), std::streamsize(x.n_elem*sizeof(eT)) ); return f.good(); } //! Save a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::save_arma_ascii(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str()); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_ascii(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::save_arma_ascii(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); const ios::fmtflags orig_flags = f.flags(); f << diskio::gen_txt_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n'; uword cell_width; // TODO: need sane values for complex numbers if( (is_float::value) || (is_double::value) ) { f.setf(ios::scientific); f.precision(12); cell_width = 20; } for(uword slice=0; slice < x.n_slices; ++slice) { for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f.put(' '); if( (is_float::value) || (is_double::value) ) { f.width(cell_width); } arma_ostream::print_elem(f, x.at(row,col,slice), false); } f.put('\n'); } } const bool save_okay = f.good(); f.flags(orig_flags); return save_okay; } //! Save a cube in binary format, //! with a header that stores the cube type as well as its dimensions template inline bool diskio::save_arma_binary(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f(tmp_name.c_str(), std::fstream::binary); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } //! Save a cube in binary format, //! with a header that stores the cube type as well as its dimensions template inline bool diskio::save_arma_binary(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); f << diskio::gen_bin_header(x) << '\n'; f << x.n_rows << ' ' << x.n_cols << ' ' << x.n_slices << '\n'; f.write( reinterpret_cast(x.mem), std::streamsize(x.n_elem*sizeof(eT)) ); return f.good(); } //! Save a cube as part of a HDF5 file template inline bool diskio::save_hdf5_binary(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) { #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Disable annoying HDF5 error messages. arma_H5Eset_auto(H5E_DEFAULT, NULL, NULL); } #endif bool save_okay = false; const std::string tmp_name = diskio::gen_tmp_name(final_name); // Set up the file according to HDF5's preferences hid_t file = arma_H5Fcreate(tmp_name.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); // We need to create a dataset, datatype, and dataspace hsize_t dims[3]; dims[2] = x.n_rows; dims[1] = x.n_cols; dims[0] = x.n_slices; hid_t dataspace = arma_H5Screate_simple(3, dims, NULL); // treat the cube as a 3d array dataspace hid_t datatype = hdf5_misc::get_hdf5_type(); // If this returned something invalid, well, it's time to crash. arma_check(datatype == -1, "Cube::save(): unknown datatype for HDF5"); // MATLAB forces the users to specify a name at save time for HDF5; Octave // will use the default of 'dataset' unless otherwise specified, so we will // use that. hid_t dataset = arma_H5Dcreate(file, "dataset", datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); herr_t status = arma_H5Dwrite(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, x.mem); save_okay = (status >= 0); arma_H5Dclose(dataset); arma_H5Tclose(datatype); arma_H5Sclose(dataspace); arma_H5Fclose(file); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } return save_okay; } #else { arma_ignore(x); arma_ignore(final_name); arma_stop("Cube::save(): use of HDF5 needs to be enabled"); return false; } #endif } //! Load a cube as raw text (no header, human readable). //! NOTE: this is much slower than reading a file with a header. template inline bool diskio::load_raw_ascii(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); Mat tmp; const bool load_okay = diskio::load_raw_ascii(tmp, name, err_msg); if(load_okay == true) { if(tmp.is_empty() == false) { x.set_size(tmp.n_rows, tmp.n_cols, 1); x.slice(0) = tmp; } else { x.reset(); } } return load_okay; } //! Load a cube as raw text (no header, human readable). //! NOTE: this is much slower than reading a file with a header. template inline bool diskio::load_raw_ascii(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); Mat tmp; const bool load_okay = diskio::load_raw_ascii(tmp, f, err_msg); if(load_okay == true) { if(tmp.is_empty() == false) { x.set_size(tmp.n_rows, tmp.n_cols, 1); x.slice(0) = tmp; } else { x.reset(); } } return load_okay; } //! Load a cube in binary format (no header); //! the cube is assumed to have one slice with one column template inline bool diskio::load_raw_binary(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_raw_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_raw_binary(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(err_msg); f.clear(); const std::streampos pos1 = f.tellg(); f.clear(); f.seekg(0, ios::end); f.clear(); const std::streampos pos2 = f.tellg(); const uword N = ( (pos1 >= 0) && (pos2 >= 0) ) ? uword(pos2 - pos1) : 0; f.clear(); //f.seekg(0, ios::beg); f.seekg(pos1); x.set_size(N / sizeof(eT), 1, 1); f.clear(); f.read( reinterpret_cast(x.memptr()), std::streamsize(N) ); return f.good(); } //! Load a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::load_arma_ascii(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f(name.c_str()); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_ascii(x, f, err_msg); f.close(); } return load_okay; } //! Load a cube in text format (human readable), //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::load_arma_ascii(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); std::streampos pos = f.tellg(); bool load_okay = true; std::string f_header; uword f_n_rows; uword f_n_cols; uword f_n_slices; f >> f_header; f >> f_n_rows; f >> f_n_cols; f >> f_n_slices; if(f_header == diskio::gen_txt_header(x)) { x.set_size(f_n_rows, f_n_cols, f_n_slices); for(uword slice=0; slice < x.n_slices; ++slice) { for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f >> x.at(row,col,slice); } } } load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } // allow automatic conversion of u32/s32 cubes into u64/s64 cubes if(load_okay == false) { if( (sizeof(eT) == 8) && is_same_type::yes ) { Cube tmp; std::string junk; f.clear(); f.seekg(pos); load_okay = diskio::load_arma_ascii(tmp, f, junk); if(load_okay) { x = conv_to< Cube >::from(tmp); } } else if( (sizeof(eT) == 8) && is_same_type::yes ) { Cube tmp; std::string junk; f.clear(); f.seekg(pos); load_okay = diskio::load_arma_ascii(tmp, f, junk); if(load_okay) { x = conv_to< Cube >::from(tmp); } } } return load_okay; } //! Load a cube in binary format, //! with a header that indicates the cube type as well as its dimensions template inline bool diskio::load_arma_binary(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f; f.open(name.c_str(), std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_arma_binary(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); std::streampos pos = f.tellg(); bool load_okay = true; std::string f_header; uword f_n_rows; uword f_n_cols; uword f_n_slices; f >> f_header; f >> f_n_rows; f >> f_n_cols; f >> f_n_slices; if(f_header == diskio::gen_bin_header(x)) { //f.seekg(1, ios::cur); // NOTE: this may not be portable, as on a Windows machine a newline could be two characters f.get(); x.set_size(f_n_rows, f_n_cols, f_n_slices); f.read( reinterpret_cast(x.memptr()), std::streamsize(x.n_elem*sizeof(eT)) ); load_okay = f.good(); } else { load_okay = false; err_msg = "incorrect header in "; } // allow automatic conversion of u32/s32 cubes into u64/s64 cubes if(load_okay == false) { if( (sizeof(eT) == 8) && is_same_type::yes ) { Cube tmp; std::string junk; f.clear(); f.seekg(pos); load_okay = diskio::load_arma_binary(tmp, f, junk); if(load_okay) { x = conv_to< Cube >::from(tmp); } } else if( (sizeof(eT) == 8) && is_same_type::yes ) { Cube tmp; std::string junk; f.clear(); f.seekg(pos); load_okay = diskio::load_arma_binary(tmp, f, junk); if(load_okay) { x = conv_to< Cube >::from(tmp); } } } return load_okay; } //! Load a HDF5 file as a cube template inline bool diskio::load_hdf5_binary(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) { // These may be necessary to store the error handler (if we need to). herr_t (*old_func)(hid_t, void*); void *old_client_data; #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Save old error handler. arma_H5Eget_auto(H5E_DEFAULT, &old_func, &old_client_data); // Disable annoying HDF5 error messages. arma_H5Eset_auto(H5E_DEFAULT, NULL, NULL); } #endif bool load_okay = false; hid_t fid = arma_H5Fopen(name.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); if(fid >= 0) { // MATLAB HDF5 dataset names are user-specified; // Octave tends to store the datasets in a group, with the actual dataset being referred to as "value". // So we will search for "dataset" and "value", and if those are not found we will take the first dataset we do find. std::vector searchNames; searchNames.push_back("dataset"); searchNames.push_back("value"); hid_t dataset = hdf5_misc::search_hdf5_file(searchNames, fid, 3, false); if(dataset >= 0) { hid_t filespace = arma_H5Dget_space(dataset); // This must be <= 3 due to our search rules. const int ndims = arma_H5Sget_simple_extent_ndims(filespace); hsize_t dims[3]; const herr_t query_status = arma_H5Sget_simple_extent_dims(filespace, dims, NULL); // arma_check(query_status < 0, "Cube::load(): cannot get size of HDF5 dataset"); if(query_status < 0) { err_msg = "cannot get size of HDF5 dataset in "; arma_H5Sclose(filespace); arma_H5Dclose(dataset); arma_H5Fclose(fid); #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Restore HDF5 error handler. arma_H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); } #endif return false; } if (ndims == 1) { dims[1] = 1; dims[2] = 1; } // Vector case; one row/colum, several slices if (ndims == 2) { dims[2] = 1; } // Matrix case; one column, several rows/slices x.set_size(dims[2], dims[1], dims[0]); // Now we have to see what type is stored to figure out how to load it. hid_t datatype = arma_H5Dget_type(dataset); hid_t mat_type = hdf5_misc::get_hdf5_type(); // If these are the same type, it is simple. if(arma_H5Tequal(datatype, mat_type) > 0) { // Load directly; H5S_ALL used so that we load the entire dataset. hid_t read_status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(x.memptr())); if(read_status >= 0) { load_okay = true; } } else { // Load into another array and convert its type accordingly. hid_t read_status = hdf5_misc::load_and_convert_hdf5(x.memptr(), dataset, datatype, x.n_elem); if(read_status >= 0) { load_okay = true; } } // Now clean up. arma_H5Tclose(datatype); arma_H5Tclose(mat_type); arma_H5Sclose(filespace); } arma_H5Dclose(dataset); arma_H5Fclose(fid); if(load_okay == false) { err_msg = "unsupported or incorrect HDF5 data in "; } } else { err_msg = "cannot open file "; } #if !defined(ARMA_PRINT_HDF5_ERRORS) { // Restore HDF5 error handler. arma_H5Eset_auto(H5E_DEFAULT, old_func, old_client_data); } #endif return load_okay; } #else { arma_ignore(x); arma_ignore(name); arma_ignore(err_msg); arma_stop("Cube::load(): use of HDF5 needs to be enabled"); return false; } #endif } //! Try to load a cube by automatically determining its type template inline bool diskio::load_auto_detect(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); #if defined(ARMA_USE_HDF5) // We're currently using the C bindings for the HDF5 library, which don't support C++ streams if( arma_H5Fis_hdf5(name.c_str()) ) { return load_hdf5_binary(x, name, err_msg); } #endif std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_auto_detect(x, f, err_msg); f.close(); } return load_okay; } //! Try to load a cube by automatically determining its type template inline bool diskio::load_auto_detect(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); static const std::string ARMA_CUB_TXT = "ARMA_CUB_TXT"; static const std::string ARMA_CUB_BIN = "ARMA_CUB_BIN"; static const std::string P6 = "P6"; podarray raw_header(uword(ARMA_CUB_TXT.length()) + 1); std::streampos pos = f.tellg(); f.read( raw_header.memptr(), std::streamsize(ARMA_CUB_TXT.length()) ); raw_header[uword(ARMA_CUB_TXT.length())] = '\0'; f.clear(); f.seekg(pos); const std::string header = raw_header.mem; if(ARMA_CUB_TXT == header.substr(0, ARMA_CUB_TXT.length())) { return load_arma_ascii(x, f, err_msg); } else if(ARMA_CUB_BIN == header.substr(0, ARMA_CUB_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(P6 == header.substr(0, P6.length())) { return load_ppm_binary(x, f, err_msg); } else { const file_type ft = guess_file_type(f); switch(ft) { // case csv_ascii: // return load_csv_ascii(x, f, err_msg); // break; case raw_binary: return load_raw_binary(x, f, err_msg); break; case raw_ascii: return load_raw_ascii(x, f, err_msg); break; default: err_msg = "unknown data in "; return false; } } return false; } // fields template inline bool diskio::save_arma_binary(const field& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_arma_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_arma_binary(const field& x, std::ostream& f) { arma_extra_debug_sigprint(); arma_type_check(( (is_Mat::value == false) && (is_Cube::value == false) )); if(x.n_slices <= 1) { f << "ARMA_FLD_BIN" << '\n'; f << x.n_rows << '\n'; f << x.n_cols << '\n'; } else { f << "ARMA_FL3_BIN" << '\n'; f << x.n_rows << '\n'; f << x.n_cols << '\n'; f << x.n_slices << '\n'; } bool save_okay = true; for(uword i=0; i inline bool diskio::load_arma_binary(field& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f( name.c_str(), std::fstream::binary ); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_arma_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_arma_binary(field& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_type_check(( (is_Mat::value == false) && (is_Cube::value == false) )); bool load_okay = true; std::string f_type; f >> f_type; if(f_type == "ARMA_FLD_BIN") { uword f_n_rows; uword f_n_cols; f >> f_n_rows; f >> f_n_cols; x.set_size(f_n_rows, f_n_cols); f.get(); for(uword i=0; i> f_n_rows; f >> f_n_cols; f >> f_n_slices; x.set_size(f_n_rows, f_n_cols, f_n_slices); f.get(); for(uword i=0; i& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_std_string(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } inline bool diskio::save_std_string(const field& x, std::ostream& f) { arma_extra_debug_sigprint(); for(uword row=0; row& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::ifstream f( name.c_str() ); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_std_string(x, f, err_msg); f.close(); } return load_okay; } inline bool diskio::load_std_string(field& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; // // work out the size uword f_n_rows = 0; uword f_n_cols = 0; bool f_n_cols_found = false; std::string line_string; std::string token; while( (f.good() == true) && (load_okay == true) ) { std::getline(f, line_string); if(line_string.size() == 0) break; std::stringstream line_stream(line_string); uword line_n_cols = 0; while (line_stream >> token) line_n_cols++; if(f_n_cols_found == false) { f_n_cols = line_n_cols; f_n_cols_found = true; } else { if(line_n_cols != f_n_cols) { load_okay = false; err_msg = "inconsistent number of columns in "; } } ++f_n_rows; } if(load_okay == true) { f.clear(); f.seekg(0, ios::beg); //f.seekg(start); x.set_size(f_n_rows, f_n_cols); for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { f >> x.at(row,col); } } } if(f.good() == false) { load_okay = false; } return load_okay; } //! Try to load a field by automatically determining its type template inline bool diskio::load_auto_detect(field& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_auto_detect(x, f, err_msg); f.close(); } return load_okay; } //! Try to load a field by automatically determining its type template inline bool diskio::load_auto_detect(field& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_type_check(( is_Mat::value == false )); static const std::string ARMA_FLD_BIN = "ARMA_FLD_BIN"; static const std::string ARMA_FL3_BIN = "ARMA_FL3_BIN"; static const std::string P6 = "P6"; podarray raw_header(uword(ARMA_FLD_BIN.length()) + 1); std::streampos pos = f.tellg(); f.read( raw_header.memptr(), std::streamsize(ARMA_FLD_BIN.length()) ); f.clear(); f.seekg(pos); raw_header[uword(ARMA_FLD_BIN.length())] = '\0'; const std::string header = raw_header.mem; if(ARMA_FLD_BIN == header.substr(0, ARMA_FLD_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(ARMA_FL3_BIN == header.substr(0, ARMA_FL3_BIN.length())) { return load_arma_binary(x, f, err_msg); } else if(P6 == header.substr(0, P6.length())) { return load_ppm_binary(x, f, err_msg); } else { err_msg = "unsupported header in "; return false; } } // // handling of PPM images by cubes template inline bool diskio::load_ppm_binary(Cube& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_ppm_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_ppm_binary(Cube& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); bool load_okay = true; std::string f_header; f >> f_header; if(f_header == "P6") { uword f_n_rows = 0; uword f_n_cols = 0; int f_maxval = 0; diskio::pnm_skip_comments(f); f >> f_n_cols; diskio::pnm_skip_comments(f); f >> f_n_rows; diskio::pnm_skip_comments(f); f >> f_maxval; f.get(); if( (f_maxval > 0) || (f_maxval <= 65535) ) { x.set_size(f_n_rows, f_n_cols, 3); if(f_maxval <= 255) { const uword n_elem = 3*f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(n_elem) ); uword i = 0; //cout << "f_n_cols = " << f_n_cols << endl; //cout << "f_n_rows = " << f_n_rows << endl; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { x.at(row,col,0) = eT(tmp[i+0]); x.at(row,col,1) = eT(tmp[i+1]); x.at(row,col,2) = eT(tmp[i+2]); i+=3; } } } else { const uword n_elem = 3*f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(2*n_elem) ); uword i = 0; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { x.at(row,col,0) = eT(tmp[i+0]); x.at(row,col,1) = eT(tmp[i+1]); x.at(row,col,2) = eT(tmp[i+2]); i+=3; } } } } else { load_okay = false; err_msg = "currently no code available to handle loading "; } if(f.good() == false) { load_okay = false; } } else { load_okay = false; err_msg = "unsupported header in "; } return load_okay; } template inline bool diskio::save_ppm_binary(const Cube& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_ppm_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_ppm_binary(const Cube& x, std::ostream& f) { arma_extra_debug_sigprint(); arma_debug_check( (x.n_slices != 3), "diskio::save_ppm_binary(): given cube must have exactly 3 slices" ); const uword n_elem = 3 * x.n_rows * x.n_cols; podarray tmp(n_elem); uword i = 0; for(uword row=0; row < x.n_rows; ++row) { for(uword col=0; col < x.n_cols; ++col) { tmp[i+0] = u8( access::tmp_real( x.at(row,col,0) ) ); tmp[i+1] = u8( access::tmp_real( x.at(row,col,1) ) ); tmp[i+2] = u8( access::tmp_real( x.at(row,col,2) ) ); i+=3; } } f << "P6" << '\n'; f << x.n_cols << '\n'; f << x.n_rows << '\n'; f << 255 << '\n'; f.write( reinterpret_cast(tmp.mem), std::streamsize(n_elem) ); return f.good(); } // // handling of PPM images by fields template inline bool diskio::load_ppm_binary(field& x, const std::string& name, std::string& err_msg) { arma_extra_debug_sigprint(); std::fstream f; f.open(name.c_str(), std::fstream::in | std::fstream::binary); bool load_okay = f.is_open(); if(load_okay == true) { load_okay = diskio::load_ppm_binary(x, f, err_msg); f.close(); } return load_okay; } template inline bool diskio::load_ppm_binary(field& x, std::istream& f, std::string& err_msg) { arma_extra_debug_sigprint(); arma_type_check(( is_Mat::value == false )); typedef typename T1::elem_type eT; bool load_okay = true; std::string f_header; f >> f_header; if(f_header == "P6") { uword f_n_rows = 0; uword f_n_cols = 0; int f_maxval = 0; diskio::pnm_skip_comments(f); f >> f_n_cols; diskio::pnm_skip_comments(f); f >> f_n_rows; diskio::pnm_skip_comments(f); f >> f_maxval; f.get(); if( (f_maxval > 0) || (f_maxval <= 65535) ) { x.set_size(3); Mat& R = x(0); Mat& G = x(1); Mat& B = x(2); R.set_size(f_n_rows,f_n_cols); G.set_size(f_n_rows,f_n_cols); B.set_size(f_n_rows,f_n_cols); if(f_maxval <= 255) { const uword n_elem = 3*f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(n_elem) ); uword i = 0; //cout << "f_n_cols = " << f_n_cols << endl; //cout << "f_n_rows = " << f_n_rows << endl; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { R.at(row,col) = eT(tmp[i+0]); G.at(row,col) = eT(tmp[i+1]); B.at(row,col) = eT(tmp[i+2]); i+=3; } } } else { const uword n_elem = 3*f_n_cols*f_n_rows; podarray tmp(n_elem); f.read( reinterpret_cast(tmp.memptr()), std::streamsize(2*n_elem) ); uword i = 0; for(uword row=0; row < f_n_rows; ++row) { for(uword col=0; col < f_n_cols; ++col) { R.at(row,col) = eT(tmp[i+0]); G.at(row,col) = eT(tmp[i+1]); B.at(row,col) = eT(tmp[i+2]); i+=3; } } } } else { load_okay = false; err_msg = "currently no code available to handle loading "; } if(f.good() == false) { load_okay = false; } } else { load_okay = false; err_msg = "unsupported header in "; } return load_okay; } template inline bool diskio::save_ppm_binary(const field& x, const std::string& final_name) { arma_extra_debug_sigprint(); const std::string tmp_name = diskio::gen_tmp_name(final_name); std::ofstream f( tmp_name.c_str(), std::fstream::binary ); bool save_okay = f.is_open(); if(save_okay == true) { save_okay = diskio::save_ppm_binary(x, f); f.flush(); f.close(); if(save_okay == true) { save_okay = diskio::safe_rename(tmp_name, final_name); } } return save_okay; } template inline bool diskio::save_ppm_binary(const field& x, std::ostream& f) { arma_extra_debug_sigprint(); arma_type_check(( is_Mat::value == false )); typedef typename T1::elem_type eT; arma_debug_check( (x.n_elem != 3), "diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" ); bool same_size = true; for(uword i=1; i<3; ++i) { if( (x(0).n_rows != x(i).n_rows) || (x(0).n_cols != x(i).n_cols) ) { same_size = false; break; } } arma_debug_check( (same_size != true), "diskio::save_ppm_binary(): given field must have exactly 3 matrices of equal size" ); const Mat& R = x(0); const Mat& G = x(1); const Mat& B = x(2); f << "P6" << '\n'; f << R.n_cols << '\n'; f << R.n_rows << '\n'; f << 255 << '\n'; const uword n_elem = 3 * R.n_rows * R.n_cols; podarray tmp(n_elem); uword i = 0; for(uword row=0; row < R.n_rows; ++row) { for(uword col=0; col < R.n_cols; ++col) { tmp[i+0] = u8( access::tmp_real( R.at(row,col) ) ); tmp[i+1] = u8( access::tmp_real( G.at(row,col) ) ); tmp[i+2] = u8( access::tmp_real( B.at(row,col) ) ); i+=3; } } f.write( reinterpret_cast(tmp.mem), std::streamsize(n_elem) ); return f.good(); } //! @} armadillo-6.500.5/include/armadillo_bits/op_vectorise_bones.hpp0000666000000000000000000000253012620272703023346 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_vectorise //! @{ class op_vectorise_col { public: template inline static void apply( Mat& out, const Op& in); template inline static void apply_proxy( Mat& out, const Proxy& P); }; class op_vectorise_row { public: template inline static void apply( Mat& out, const Op& in); template inline static void apply_proxy( Mat& out, const Proxy& P); }; class op_vectorise_all { public: template inline static void apply( Mat& out, const Op& in); }; class op_vectorise_cube_col { public: template inline static void apply( Mat& out, const BaseCube& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/spglue_times_bones.hpp0000666000000000000000000000171112620272703023345 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spglue_times //! @{ class spglue_times { public: template inline static void apply(SpMat& out, const SpGlue& X); template arma_hot inline static void apply_noalias(SpMat& c, const SpProxy& pa, const SpProxy& pb); }; class spglue_times2 { public: template inline static void apply(SpMat& out, const SpGlue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/eGlueCube_bones.hpp0000666000000000000000000000320212620272703022502 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eGlueCube //! @{ template class eGlueCube : public BaseCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); static const bool has_subview = (ProxyCube::has_subview || ProxyCube::has_subview ); arma_aligned const ProxyCube P1; arma_aligned const ProxyCube P2; arma_inline ~eGlueCube(); arma_inline eGlueCube(const T1& in_A, const T2& in_B); arma_inline uword get_n_rows() const; arma_inline uword get_n_cols() const; arma_inline uword get_n_elem_slice() const; arma_inline uword get_n_slices() const; arma_inline uword get_n_elem() const; arma_inline elem_type operator[] (const uword i) const; arma_inline elem_type at (const uword row, const uword col, const uword slice) const; arma_inline elem_type at_alt (const uword i) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/operator_ostream.hpp0000666000000000000000000000426512620272703023053 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup operator_ostream //! @{ template inline std::ostream& operator<< (std::ostream& o, const Base& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); arma_ostream::print(o, tmp.M, true); return o; } template inline std::ostream& operator<< (std::ostream& o, const SpBase& X) { arma_extra_debug_sigprint(); const unwrap_spmat tmp(X.get_ref()); arma_ostream::print(o, tmp.M, true); return o; } template inline std::ostream& operator<< (std::ostream& o, const SpValProxy& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; o << eT(X); return o; } template inline std::ostream& operator<< (std::ostream& o, const BaseCube& X) { arma_extra_debug_sigprint(); const unwrap_cube tmp(X.get_ref()); arma_ostream::print(o, tmp.M, true); return o; } //! Print the contents of a field to the specified stream. template inline std::ostream& operator<< (std::ostream& o, const field& X) { arma_extra_debug_sigprint(); arma_ostream::print(o, X); return o; } //! Print the contents of a subfield to the specified stream template inline std::ostream& operator<< (std::ostream& o, const subview_field& X) { arma_extra_debug_sigprint(); arma_ostream::print(o, X); return o; } inline std::ostream& operator<< (std::ostream& o, const SizeMat& S) { arma_extra_debug_sigprint(); arma_ostream::print(o, S); return o; } inline std::ostream& operator<< (std::ostream& o, const SizeCube& S) { arma_extra_debug_sigprint(); arma_ostream::print(o, S); return o; } //! @} armadillo-6.500.5/include/armadillo_bits/op_trimat_bones.hpp0000666000000000000000000000224612620272703022647 0ustar rootroot// Copyright (C) 2010-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup op_trimat //! @{ class op_trimat { public: template inline static void fill_zeros(Mat& A, const bool upper); // template inline static void apply(Mat& out, const Op& in); template inline static void apply(Mat& out, const Op, op_trimat>& in); // template inline static void apply_htrans(Mat& out, const Mat& A, const bool upper, const typename arma_not_cx::result* junk = 0); template inline static void apply_htrans(Mat& out, const Mat& A, const bool upper, const typename arma_cx_only::result* junk = 0); }; //! @} armadillo-6.500.5/include/armadillo_bits/config.hpp.cmake0000666000000000000000000001625112620272703022010 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin #if !defined(ARMA_USE_LAPACK) #cmakedefine ARMA_USE_LAPACK //// Comment out the above line if you don't have LAPACK or a high-speed replacement for LAPACK, //// such as Intel MKL, AMD ACML, or the Accelerate framework. //// LAPACK is required for matrix decompositions (eg. SVD) and matrix inverse. #endif #if !defined(ARMA_USE_BLAS) #cmakedefine ARMA_USE_BLAS //// Comment out the above line if you don't have BLAS or a high-speed replacement for BLAS, //// such as OpenBLAS, GotoBLAS, Intel MKL, AMD ACML, or the Accelerate framework. //// BLAS is used for matrix multiplication. //// Without BLAS, matrix multiplication will still work, but might be slower. #endif #if !defined(ARMA_USE_ARPACK) #cmakedefine ARMA_USE_ARPACK //// Uncomment the above line if you have ARPACK or a high-speed replacement for ARPACK. //// ARPACK is required for eigendecompositions of sparse matrices, eg. eigs_sym(), svds() #endif #if !defined(ARMA_USE_SUPERLU) #cmakedefine ARMA_USE_SUPERLU //// Uncomment the above line if you have SuperLU. //// SuperLU is used for solving sparse linear systems via spsolve() //// Caveat: only SuperLU version 4.3 can be used! #endif #if !defined(ARMA_SUPERLU_INCLUDE_DIR) #define ARMA_SUPERLU_INCLUDE_DIR ${ARMA_SUPERLU_INCLUDE_DIR}/ //// If you're using SuperLU and want to explicitly include the SuperLU headers, //// uncomment the above define and specify the appropriate include directory. //// Make sure the directory has a trailing / #endif #cmakedefine ARMA_USE_WRAPPER //// Comment out the above line if you're getting linking errors when compiling your programs, //// or if you prefer to directly link with LAPACK, BLAS + etc instead of the Armadillo runtime library. //// You will then need to link your programs directly with -llapack -lblas instead of -larmadillo // #define ARMA_BLAS_CAPITALS //// Uncomment the above line if your BLAS and LAPACK libraries have capitalised function names (eg. ACML on 64-bit Windows) #define ARMA_BLAS_UNDERSCORE //// Uncomment the above line if your BLAS and LAPACK libraries have function names with a trailing underscore. //// Conversely, comment it out if the function names don't have a trailing underscore. // #define ARMA_BLAS_LONG //// Uncomment the above line if your BLAS and LAPACK libraries use "long" instead of "int" // #define ARMA_BLAS_LONG_LONG //// Uncomment the above line if your BLAS and LAPACK libraries use "long long" instead of "int" // #define ARMA_USE_TBB_ALLOC //// Uncomment the above line if you want to use Intel TBB scalable_malloc() and scalable_free() instead of standard malloc() and free() // #define ARMA_USE_MKL_ALLOC //// Uncomment the above line if you want to use Intel MKL mkl_malloc() and mkl_free() instead of standard malloc() and free() #cmakedefine ARMA_USE_ATLAS #define ARMA_ATLAS_INCLUDE_DIR ${ARMA_ATLAS_INCLUDE_DIR}/ //// If you're using ATLAS and the compiler can't find cblas.h and/or clapack.h //// uncomment the above define and specify the appropriate include directory. //// Make sure the directory has a trailing / #if !defined(ARMA_USE_CXX11) // #define ARMA_USE_CXX11 //// Uncomment the above line to forcefully enable use of C++11 features (eg. initialiser lists). //// Note that ARMA_USE_CXX11 is automatically enabled when a C++11 compiler is detected #endif #if !defined(ARMA_64BIT_WORD) // #define ARMA_64BIT_WORD //// Uncomment the above line if you require matrices/vectors capable of holding more than 4 billion elements. //// Your machine and compiler must have support for 64 bit integers (eg. via "long" or "long long") //// Note that ARMA_64BIT_WORD is automatically enabled when a C++11 compiler is detected #endif #if !defined(ARMA_USE_HDF5) // #define ARMA_USE_HDF5 //// Uncomment the above line to allow the ability to save and load matrices stored in HDF5 format; //// the hdf5.h header file must be available on your system, //// and you will need to link with the hdf5 library (eg. -lhdf5) #endif #cmakedefine ARMA_USE_HDF5_ALT #if defined(ARMA_USE_HDF5_ALT) && defined(ARMA_USE_WRAPPER) #undef ARMA_USE_HDF5 #define ARMA_USE_HDF5 #define ARMA_HDF5_INCLUDE_DIR ${ARMA_HDF5_INCLUDE_DIR}/ #endif #if !defined(ARMA_MAT_PREALLOC) #define ARMA_MAT_PREALLOC 16 #endif //// This is the number of preallocated elements used by matrices and vectors; //// it must be an integer that is at least 1. //// If you mainly use lots of very small vectors (eg. <= 4 elements), //// change the number to the size of your vectors. #if !defined(ARMA_SPMAT_CHUNKSIZE) #define ARMA_SPMAT_CHUNKSIZE 256 #endif //// This is the minimum increase in the amount of memory (in terms of elements) allocated by a sparse matrix; //// it must be an integer that is at least 1. //// The minimum recommended size is 16. // #define ARMA_NO_DEBUG //// Uncomment the above line if you want to disable all run-time checks. //// This will result in faster code, but you first need to make sure that your code runs correctly! //// We strongly recommend to have the run-time checks enabled during development, //// as this greatly aids in finding mistakes in your code, and hence speeds up development. //// We recommend that run-time checks be disabled _only_ for the shipped version of your program. // #define ARMA_EXTRA_DEBUG //// Uncomment the above line if you want to see the function traces of how Armadillo evaluates expressions. //// This is mainly useful for debugging of the library. #if !defined(ARMA_DEFAULT_OSTREAM) #define ARMA_DEFAULT_OSTREAM std::cout #endif #if !defined(ARMA_PRINT_ERRORS) #define ARMA_PRINT_ERRORS //// Comment out the above line if you don't want errors and warnings printed (eg. failed decompositions) #endif #if !defined(ARMA_PRINT_HDF5_ERRORS) // #define ARMA_PRINT_HDF5_ERRORS #endif #if defined(ARMA_DONT_USE_LAPACK) #undef ARMA_USE_LAPACK #endif #if defined(ARMA_DONT_USE_BLAS) #undef ARMA_USE_BLAS #endif #if defined(ARMA_DONT_USE_ARPACK) #undef ARMA_USE_ARPACK #endif #if defined(ARMA_DONT_USE_SUPERLU) #undef ARMA_USE_SUPERLU #undef ARMA_SUPERLU_INCLUDE_DIR #endif #if defined(ARMA_DONT_USE_ATLAS) #undef ARMA_USE_ATLAS #undef ARMA_ATLAS_INCLUDE_DIR #endif #if defined(ARMA_DONT_USE_WRAPPER) #undef ARMA_USE_WRAPPER #undef ARMA_USE_HDF5_ALT #endif #if defined(ARMA_DONT_USE_CXX11) #undef ARMA_USE_CXX11 #undef ARMA_USE_EXTERN_CXX11_RNG #endif #if defined(ARMA_USE_WRAPPER) #if defined(ARMA_USE_CXX11) #if !defined(ARMA_USE_EXTERN_CXX11_RNG) #cmakedefine ARMA_USE_EXTERN_CXX11_RNG #endif #endif #endif #if defined(ARMA_DONT_USE_EXTERN_CXX11_RNG) #undef ARMA_USE_EXTERN_CXX11_RNG #endif #if defined(ARMA_32BIT_WORD) #undef ARMA_64BIT_WORD #endif #if defined(ARMA_DONT_USE_HDF5) #undef ARMA_USE_HDF5 #endif #if defined(ARMA_DONT_PRINT_ERRORS) #undef ARMA_PRINT_ERRORS #endif #if defined(ARMA_DONT_PRINT_HDF5_ERRORS) #undef ARMA_PRINT_HDF5_ERRORS #endif armadillo-6.500.5/include/armadillo_bits/running_stat_meat.hpp0000666000000000000000000001760312620272703023207 0ustar rootroot// Copyright (C) 2009-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup running_stat //! @{ template inline arma_counter::~arma_counter() { arma_extra_debug_sigprint_this(this); } template inline arma_counter::arma_counter() : d_count( eT(0)) , i_count(uword(0)) { arma_extra_debug_sigprint_this(this); } template inline const arma_counter& arma_counter::operator++() { if(i_count < ARMA_MAX_UWORD) { i_count++; } else { d_count += eT(ARMA_MAX_UWORD); i_count = 1; } return *this; } template inline void arma_counter::operator++(int) { operator++(); } template inline void arma_counter::reset() { d_count = eT(0); i_count = uword(0); } template inline eT arma_counter::value() const { return d_count + eT(i_count); } template inline eT arma_counter::value_plus_1() const { if(i_count < ARMA_MAX_UWORD) { return d_count + eT(i_count + 1); } else { return d_count + eT(ARMA_MAX_UWORD) + eT(1); } } template inline eT arma_counter::value_minus_1() const { if(i_count > 0) { return d_count + eT(i_count - 1); } else { return d_count - eT(1); } } // template inline running_stat::~running_stat() { arma_extra_debug_sigprint_this(this); } template inline running_stat::running_stat() : r_mean ( eT(0)) , r_var (typename running_stat::T(0)) , min_val ( eT(0)) , max_val ( eT(0)) , min_val_norm(typename running_stat::T(0)) , max_val_norm(typename running_stat::T(0)) { arma_extra_debug_sigprint_this(this); } //! update statistics to reflect new sample template inline void running_stat::operator() (const typename running_stat::T sample) { arma_extra_debug_sigprint(); if( arma_isfinite(sample) == false ) { arma_debug_warn("running_stat: sample ignored as it is non-finite" ); return; } running_stat_aux::update_stats(*this, sample); } //! update statistics to reflect new sample (version for complex numbers) template inline void running_stat::operator() (const std::complex< typename running_stat::T >& sample) { arma_extra_debug_sigprint(); if( arma_isfinite(sample) == false ) { arma_debug_warn("running_stat: sample ignored as it is non-finite" ); return; } running_stat_aux::update_stats(*this, sample); } //! set all statistics to zero template inline void running_stat::reset() { arma_extra_debug_sigprint(); // typedef typename running_stat::T T; counter.reset(); r_mean = eT(0); r_var = T(0); min_val = eT(0); max_val = eT(0); min_val_norm = T(0); max_val_norm = T(0); } //! mean or average value template inline eT running_stat::mean() const { arma_extra_debug_sigprint(); return r_mean; } //! variance template inline typename running_stat::T running_stat::var(const uword norm_type) const { arma_extra_debug_sigprint(); const T N = counter.value(); if(N > T(1)) { if(norm_type == 0) { return r_var; } else { const T N_minus_1 = counter.value_minus_1(); return (N_minus_1/N) * r_var; } } else { return T(0); } } //! standard deviation template inline typename running_stat::T running_stat::stddev(const uword norm_type) const { arma_extra_debug_sigprint(); return std::sqrt( (*this).var(norm_type) ); } //! minimum value template inline eT running_stat::min() const { arma_extra_debug_sigprint(); return min_val; } //! maximum value template inline eT running_stat::max() const { arma_extra_debug_sigprint(); return max_val; } //! number of samples so far template inline typename get_pod_type::result running_stat::count() const { arma_extra_debug_sigprint(); return counter.value(); } //! update statistics to reflect new sample (version for non-complex numbers, non-complex sample) template inline void running_stat_aux::update_stats(running_stat& x, const eT sample, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat::T T; const T N = x.counter.value(); if(N > T(0)) { if(sample < x.min_val) { x.min_val = sample; } if(sample > x.max_val) { x.max_val = sample; } const T N_plus_1 = x.counter.value_plus_1(); const T N_minus_1 = x.counter.value_minus_1(); // note: variance has to be updated before the mean const eT tmp = sample - x.r_mean; x.r_var = N_minus_1/N * x.r_var + (tmp*tmp)/N_plus_1; x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1; //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1; //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1; } else { x.r_mean = sample; x.min_val = sample; x.max_val = sample; // r_var is initialised to zero // in the constructor and reset() } x.counter++; } //! update statistics to reflect new sample (version for non-complex numbers, complex sample) template inline void running_stat_aux::update_stats(running_stat& x, const std::complex& sample, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); running_stat_aux::update_stats(x, std::real(sample)); } //! update statistics to reflect new sample (version for complex numbers, non-complex sample) template inline void running_stat_aux::update_stats(running_stat& x, const typename eT::value_type sample, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename eT::value_type T; running_stat_aux::update_stats(x, std::complex(sample)); } //! alter statistics to reflect new sample (version for complex numbers, complex sample) template inline void running_stat_aux::update_stats(running_stat& x, const eT& sample, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename eT::value_type T; const T sample_norm = std::norm(sample); const T N = x.counter.value(); if(N > T(0)) { if(sample_norm < x.min_val_norm) { x.min_val_norm = sample_norm; x.min_val = sample; } if(sample_norm > x.max_val_norm) { x.max_val_norm = sample_norm; x.max_val = sample; } const T N_plus_1 = x.counter.value_plus_1(); const T N_minus_1 = x.counter.value_minus_1(); x.r_var = N_minus_1/N * x.r_var + std::norm(sample - x.r_mean)/N_plus_1; x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1; //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1; //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1; } else { x.r_mean = sample; x.min_val = sample; x.max_val = sample; x.min_val_norm = sample_norm; x.max_val_norm = sample_norm; // r_var is initialised to zero // in the constructor and reset() } x.counter++; } //! @} armadillo-6.500.5/include/armadillo_bits/Proxy.hpp0000666000000000000000000020263012622551211020577 0ustar rootroot// Copyright (C) 2010-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Proxy //! @{ // ea_type is the "element accessor" type, // which can provide access to elements via operator[] template struct Proxy_default { inline Proxy_default(const T1&) { arma_type_check(( is_arma_type::value == false )); } }; template struct Proxy_fixed { typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef T1 stored_type; typedef const elem_type* ea_type; typedef const T1& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = T1::is_row; static const bool is_col = T1::is_col; arma_aligned const T1& Q; inline explicit Proxy_fixed(const T1& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline static uword get_n_rows() { return T1::n_rows; } arma_inline static uword get_n_cols() { return T1::n_cols; } arma_inline static uword get_n_elem() { return T1::n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) return true; #else return memory::is_aligned(Q.memptr()); #endif } }; template struct Proxy_redirect {}; template struct Proxy_redirect { typedef Proxy_default result; }; template struct Proxy_redirect { typedef Proxy_fixed result; }; template class Proxy : public Proxy_redirect::value >::result { public: inline Proxy(const T1& A) : Proxy_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template class Proxy< Mat > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const eT* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat& Q; inline explicit Proxy(const Mat& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< Col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Col stored_type; typedef const eT* ea_type; typedef const Col& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const Col& Q; inline explicit Proxy(const Col& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< Row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Row stored_type; typedef const eT* ea_type; typedef const Row& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = true; static const bool is_col = false; arma_aligned const Row& Q; inline explicit Proxy(const Row& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword, const uword col) const { return Q[col]; } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&Q) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< Gen > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Gen stored_type; typedef const Gen& ea_type; typedef const Gen& aligned_ea_type; static const bool prefer_at_accessor = Gen::prefer_at_accessor; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = Gen::is_row; static const bool is_col = Gen::is_col; arma_aligned const Gen& Q; inline explicit Proxy(const Gen& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return (is_row ? 1 : Q.n_rows); } arma_inline uword get_n_cols() const { return (is_col ? 1 : Q.n_cols); } arma_inline uword get_n_elem() const { return (is_row ? 1 : Q.n_rows) * (is_col ? 1 : Q.n_cols); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return Gen::is_simple; } }; template class Proxy< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = Op::is_row; static const bool is_col = Op::is_col; arma_aligned const Mat Q; inline explicit Proxy(const Op& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy_diagvec_mat { inline Proxy_diagvec_mat(const T1&) {} }; template class Proxy_diagvec_mat< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef diagview stored_type; typedef const diagview& ea_type; typedef const diagview& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const Mat& R; arma_aligned const diagview Q; inline explicit Proxy_diagvec_mat(const Op& A) : R(A.m), Q( R.diag( (A.aux_uword_b > 0) ? -sword(A.aux_uword_a) : sword(A.aux_uword_a) ) ) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q.at(row, 0); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&R) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy_diagvec_expr { inline Proxy_diagvec_expr(const T1&) {} }; template class Proxy_diagvec_expr< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const Mat Q; inline explicit Proxy_diagvec_expr(const Op& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q.at(row, 0); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template struct Proxy_diagvec_redirect {}; template struct Proxy_diagvec_redirect< Op, true > { typedef Proxy_diagvec_mat < Op > result; }; template struct Proxy_diagvec_redirect< Op, false> { typedef Proxy_diagvec_expr< Op > result; }; template class Proxy< Op > : public Proxy_diagvec_redirect< Op, is_Mat::value >::result { public: typedef typename Proxy_diagvec_redirect< Op, is_Mat::value >::result Proxy_diagvec; inline explicit Proxy(const Op& A) : Proxy_diagvec(A) { arma_extra_debug_sigprint(); } }; template struct Proxy_xtrans_default { inline Proxy_xtrans_default(const T1&) {} }; template struct Proxy_xtrans_default< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef xtrans_mat stored_type; typedef const xtrans_mat& ea_type; typedef const xtrans_mat& aligned_ea_type; static const bool prefer_at_accessor = true; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; const unwrap U; const xtrans_mat Q; inline explicit Proxy_xtrans_default(const Op& A) : U(A.m) , Q(U.M) { arma_extra_debug_sigprint(); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return void_ptr(&(U.M)) == void_ptr(&X); } arma_inline bool is_aligned() const { return false; } }; template struct Proxy_xtrans_default< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef xtrans_mat stored_type; typedef const xtrans_mat& ea_type; typedef const xtrans_mat& aligned_ea_type; static const bool prefer_at_accessor = true; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; const unwrap U; const xtrans_mat Q; inline explicit Proxy_xtrans_default(const Op& A) : U(A.m) , Q(U.M) { arma_extra_debug_sigprint(); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return void_ptr(&(U.M)) == void_ptr(&X); } arma_inline bool is_aligned() const { return false; } }; template struct Proxy_xtrans_vector { inline Proxy_xtrans_vector(const T1&) {} }; template struct Proxy_xtrans_vector< Op > { typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = quasi_unwrap::has_subview; static const bool fake_mat = true; // NOTE: the Op class takes care of swapping row and col for op_htrans static const bool is_row = Op::is_row; static const bool is_col = Op::is_col; arma_aligned const quasi_unwrap U; // avoid copy if T1 is a Row, Col or subview_col arma_aligned const Mat Q; inline Proxy_xtrans_vector(const Op& A) : U(A.m) , Q(const_cast(U.M.memptr()), U.M.n_cols, U.M.n_rows, false, false) { arma_extra_debug_sigprint(); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return U.is_alias(X); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template struct Proxy_xtrans_vector< Op > { typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = quasi_unwrap::has_subview; static const bool fake_mat = true; // NOTE: the Op class takes care of swapping row and col for op_htrans static const bool is_row = Op::is_row; static const bool is_col = Op::is_col; arma_aligned const quasi_unwrap U; // avoid copy if T1 is a Row, Col or subview_col arma_aligned const Mat Q; inline Proxy_xtrans_vector(const Op& A) : U(A.m) , Q(const_cast(U.M.memptr()), U.M.n_cols, U.M.n_rows, false, false) { arma_extra_debug_sigprint(); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return U.is_alias(X); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template struct Proxy_xtrans_redirect {}; template struct Proxy_xtrans_redirect { typedef Proxy_xtrans_default result; }; template struct Proxy_xtrans_redirect { typedef Proxy_xtrans_vector result; }; template class Proxy< Op > : public Proxy_xtrans_redirect < Op, ((is_complex::value == false) && ((Op::is_row) || (Op::is_col)) ) >::result { public: typedef typename Proxy_xtrans_redirect < Op, ((is_complex::value == false) && ((Op::is_row) || (Op::is_col)) ) >::result Proxy_xtrans; typedef typename Proxy_xtrans::elem_type elem_type; typedef typename Proxy_xtrans::pod_type pod_type; typedef typename Proxy_xtrans::stored_type stored_type; typedef typename Proxy_xtrans::ea_type ea_type; typedef typename Proxy_xtrans::aligned_ea_type aligned_ea_type; static const bool prefer_at_accessor = Proxy_xtrans::prefer_at_accessor; static const bool has_subview = Proxy_xtrans::has_subview; static const bool fake_mat = Proxy_xtrans::fake_mat; static const bool is_row = Proxy_xtrans::is_row; static const bool is_col = Proxy_xtrans::is_col; using Proxy_xtrans::Q; inline explicit Proxy(const Op& A) : Proxy_xtrans(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Proxy_xtrans::get_ea(); } arma_inline aligned_ea_type get_aligned_ea() const { return Proxy_xtrans::get_aligned_ea(); } template arma_inline bool is_alias(const Mat& X) const { return Proxy_xtrans::is_alias(X); } arma_inline bool is_aligned() const { return Proxy_xtrans::is_aligned(); } }; template class Proxy< Op > : public Proxy_xtrans_redirect < Op, ( (Op::is_row) || (Op::is_col) ) >::result { public: typedef typename Proxy_xtrans_redirect < Op, ( (Op::is_row) || (Op::is_col) ) >::result Proxy_xtrans; typedef typename Proxy_xtrans::elem_type elem_type; typedef typename Proxy_xtrans::pod_type pod_type; typedef typename Proxy_xtrans::stored_type stored_type; typedef typename Proxy_xtrans::ea_type ea_type; typedef typename Proxy_xtrans::aligned_ea_type aligned_ea_type; static const bool prefer_at_accessor = Proxy_xtrans::prefer_at_accessor; static const bool has_subview = Proxy_xtrans::has_subview; static const bool fake_mat = Proxy_xtrans::fake_mat; static const bool is_row = Proxy_xtrans::is_row; static const bool is_col = Proxy_xtrans::is_col; using Proxy_xtrans::Q; inline explicit Proxy(const Op& A) : Proxy_xtrans(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Proxy_xtrans::get_ea(); } arma_inline aligned_ea_type get_aligned_ea() const { return Proxy_xtrans::get_aligned_ea(); } template arma_inline bool is_alias(const Mat& X) const { return Proxy_xtrans::is_alias(X); } arma_inline bool is_aligned() const { return Proxy_xtrans::is_aligned(); } }; template struct Proxy_subview_row_htrans_cx { typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_htrans stored_type; typedef const subview_row_htrans& ea_type; typedef const subview_row_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_htrans Q; inline explicit Proxy_subview_row_htrans_cx(const Op, op_htrans>& A) : Q(A.m) { arma_extra_debug_sigprint(); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } }; template struct Proxy_subview_row_htrans_non_cx { typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_strans stored_type; typedef const subview_row_strans& ea_type; typedef const subview_row_strans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_strans Q; inline explicit Proxy_subview_row_htrans_non_cx(const Op, op_htrans>& A) : Q(A.m) { arma_extra_debug_sigprint(); } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } }; template struct Proxy_subview_row_htrans_redirect {}; template struct Proxy_subview_row_htrans_redirect { typedef Proxy_subview_row_htrans_cx result; }; template struct Proxy_subview_row_htrans_redirect { typedef Proxy_subview_row_htrans_non_cx result; }; template class Proxy< Op, op_htrans> > : public Proxy_subview_row_htrans_redirect < eT, is_complex::value >::result { public: typedef typename Proxy_subview_row_htrans_redirect < eT, is_complex::value >::result Proxy_sv_row_ht; typedef typename Proxy_sv_row_ht::elem_type elem_type; typedef typename Proxy_sv_row_ht::pod_type pod_type; typedef typename Proxy_sv_row_ht::stored_type stored_type; typedef typename Proxy_sv_row_ht::ea_type ea_type; typedef typename Proxy_sv_row_ht::ea_type aligned_ea_type; static const bool prefer_at_accessor = Proxy_sv_row_ht::prefer_at_accessor; static const bool has_subview = Proxy_sv_row_ht::has_subview; static const bool fake_mat = Proxy_sv_row_ht::fake_mat; static const bool is_row = false; static const bool is_col = true; using Proxy_sv_row_ht::Q; inline explicit Proxy(const Op, op_htrans>& A) : Proxy_sv_row_ht(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return Proxy_sv_row_ht::is_alias(X); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< Op, op_strans> > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_strans stored_type; typedef const subview_row_strans& ea_type; typedef const subview_row_strans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_strans Q; inline explicit Proxy(const Op, op_strans>& A) : Q(A.m) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< Op< Row< std::complex >, op_htrans> > { public: typedef typename std::complex eT; typedef typename std::complex elem_type; typedef T pod_type; typedef xvec_htrans stored_type; typedef const xvec_htrans& ea_type; typedef const xvec_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; const xvec_htrans Q; const Row& src; inline explicit Proxy(const Op< Row< std::complex >, op_htrans>& A) : Q (A.m.memptr(), A.m.n_rows, A.m.n_cols) , src(A.m) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return void_ptr(&src) == void_ptr(&X); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< Op< Col< std::complex >, op_htrans> > { public: typedef typename std::complex eT; typedef typename std::complex elem_type; typedef T pod_type; typedef xvec_htrans stored_type; typedef const xvec_htrans& ea_type; typedef const xvec_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = true; static const bool is_col = false; const xvec_htrans Q; const Col& src; inline explicit Proxy(const Op< Col< std::complex >, op_htrans>& A) : Q (A.m.memptr(), A.m.n_rows, A.m.n_cols) , src(A.m) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword, const uword col) const { return Q[col]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return void_ptr(&src) == void_ptr(&X); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< Op< subview_col< std::complex >, op_htrans> > { public: typedef typename std::complex eT; typedef typename std::complex elem_type; typedef T pod_type; typedef xvec_htrans stored_type; typedef const xvec_htrans& ea_type; typedef const xvec_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = true; static const bool is_col = false; const xvec_htrans Q; const subview_col& src; inline explicit Proxy(const Op< subview_col< std::complex >, op_htrans>& A) : Q (A.m.colptr(0), A.m.n_rows, A.m.n_cols) , src(A.m) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword, const uword col) const { return Q[col]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return void_ptr(&src.m) == void_ptr(&X); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eOp< Op, eop_scalar_times> stored_type; typedef const eOp< Op, eop_scalar_times>& ea_type; typedef const eOp< Op, eop_scalar_times>& aligned_ea_type; static const bool prefer_at_accessor = eOp< Op, eop_scalar_times>::prefer_at_accessor; static const bool has_subview = eOp< Op, eop_scalar_times>::has_subview; static const bool fake_mat = eOp< Op, eop_scalar_times>::fake_mat; // NOTE: the Op class takes care of swapping row and col for op_htrans static const bool is_row = eOp< Op, eop_scalar_times>::is_row; static const bool is_col = eOp< Op, eop_scalar_times>::is_col; arma_aligned const Op R; arma_aligned const eOp< Op, eop_scalar_times > Q; inline explicit Proxy(const Op& A) : R(A.m) , Q(R, A.aux) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.get_n_rows(); } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.get_n_cols(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return Q.P.is_alias(X); } arma_inline bool is_aligned() const { return Q.P.is_aligned(); } }; template class Proxy< Op > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = true; static const bool is_row = false; static const bool is_col = true; arma_aligned const unwrap U; arma_aligned const Mat Q; inline explicit Proxy(const Op& A) : U(A.m) , Q(const_cast(U.M.memptr()), U.M.n_elem, 1, false, false) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return ( void_ptr(&X) == void_ptr(&(U.M)) ); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< Glue > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = Glue::is_row; static const bool is_col = Glue::is_col; arma_aligned const Mat Q; inline explicit Proxy(const Glue& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< subview > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview stored_type; typedef const subview& ea_type; typedef const subview& aligned_ea_type; static const bool prefer_at_accessor = true; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const subview& Q; inline explicit Proxy(const subview& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< subview_col > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_col stored_type; typedef const eT* ea_type; typedef const subview_col& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_col& Q; inline explicit Proxy(const subview_col& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.colmem; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return memory::is_aligned(Q.colmem); } }; template class Proxy< subview_row > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row stored_type; typedef const subview_row& ea_type; typedef const subview_row& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = true; static const bool is_col = false; arma_aligned const subview_row& Q; inline explicit Proxy(const subview_row& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return 1; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword, const uword col) const { return Q[col]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< subview_row_strans > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_strans stored_type; typedef const subview_row_strans& ea_type; typedef const subview_row_strans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_strans& Q; inline explicit Proxy(const subview_row_strans& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< subview_row_htrans > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_row_htrans stored_type; typedef const subview_row_htrans& ea_type; typedef const subview_row_htrans& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row_htrans& Q; inline explicit Proxy(const subview_row_htrans& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q[row]; } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.sv_row.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< xtrans_mat > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const eT* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat Q; inline explicit Proxy(const xtrans_mat& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< xvec_htrans > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const eT* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat Q; inline explicit Proxy(const xvec_htrans& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< subview_elem1 > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef subview_elem1 stored_type; typedef const Proxy< subview_elem1 >& ea_type; typedef const Proxy< subview_elem1 >& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_elem1& Q; arma_aligned const Proxy R; inline explicit Proxy(const subview_elem1& A) : Q(A) , R(A.a.get_ref()) { arma_extra_debug_sigprint(); const bool R_is_vec = ((R.get_n_rows() == 1) || (R.get_n_cols() == 1)); const bool R_is_empty = (R.get_n_elem() == 0); arma_debug_check( ((R_is_vec == false) && (R_is_empty == false)), "Mat::elem(): given object is not a vector" ); } arma_inline uword get_n_rows() const { return R.get_n_elem(); } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return R.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { const uword ii = (Proxy::prefer_at_accessor) ? R.at(i, 0) : R[i ]; arma_debug_check( (ii >= Q.m.n_elem), "Mat::elem(): index out of bounds" ); return Q.m[ii]; } arma_inline elem_type at (const uword row, const uword) const { const uword ii = (Proxy::prefer_at_accessor) ? R.at(row,0) : R[row]; arma_debug_check( (ii >= Q.m.n_elem), "Mat::elem(): index out of bounds" ); return Q.m[ii]; } arma_inline elem_type at_alt (const uword i) const { const uword ii = (Proxy::prefer_at_accessor) ? R.at(i, 0) : R[i ]; arma_debug_check( (ii >= Q.m.n_elem), "Mat::elem(): index out of bounds" ); return Q.m[ii]; } arma_inline ea_type get_ea() const { return (*this); } arma_inline aligned_ea_type get_aligned_ea() const { return (*this); } template arma_inline bool is_alias(const Mat& X) const { return ( (void_ptr(&X) == void_ptr(&(Q.m))) || (R.is_alias(X)) ); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< subview_elem2 > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const eT* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat Q; inline explicit Proxy(const subview_elem2& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< diagview > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef diagview stored_type; typedef const diagview& ea_type; typedef const diagview& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = true; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const diagview& Q; inline explicit Proxy(const diagview& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q.at(row, 0); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(Q.m)) == void_ptr(&X)); } arma_inline bool is_aligned() const { return false; } }; template class Proxy< spdiagview > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; typedef spdiagview stored_type; typedef const spdiagview& ea_type; typedef const spdiagview& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = false; static const bool is_col = true; arma_aligned const spdiagview& Q; inline explicit Proxy(const spdiagview& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return Q.n_rows; } arma_inline uword get_n_cols() const { return 1; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword) const { return Q.at(row, 0); } arma_inline elem_type at_alt (const uword i) const { return Q[i]; } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return false; } }; template class Proxy< eOp > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eOp stored_type; typedef const eOp& ea_type; typedef const eOp& aligned_ea_type; static const bool prefer_at_accessor = eOp::prefer_at_accessor; static const bool has_subview = eOp::has_subview; static const bool fake_mat = eOp::fake_mat; static const bool is_row = eOp::is_row; static const bool is_col = eOp::is_col; arma_aligned const eOp& Q; inline explicit Proxy(const eOp& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.get_n_rows(); } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.get_n_cols(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return Q.P.is_alias(X); } arma_inline bool is_aligned() const { return Q.P.is_aligned(); } }; template class Proxy< eGlue > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; typedef eGlue stored_type; typedef const eGlue& ea_type; typedef const eGlue& aligned_ea_type; static const bool prefer_at_accessor = eGlue::prefer_at_accessor; static const bool has_subview = eGlue::has_subview; static const bool fake_mat = eGlue::fake_mat; static const bool is_row = eGlue::is_row; static const bool is_col = eGlue::is_col; arma_aligned const eGlue& Q; inline explicit Proxy(const eGlue& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.get_n_rows(); } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.get_n_cols(); } arma_inline uword get_n_elem() const { return Q.get_n_elem(); } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row, col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q; } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat& X) const { return (Q.P1.is_alias(X) || Q.P2.is_alias(X)); } arma_inline bool is_aligned() const { return (Q.P1.is_aligned() && Q.P2.is_aligned()); } }; template class Proxy< mtOp > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = mtOp::is_row; static const bool is_col = mtOp::is_col; arma_aligned const Mat Q; inline explicit Proxy(const mtOp& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; template class Proxy< mtGlue > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef Mat stored_type; typedef const elem_type* ea_type; typedef const Mat& aligned_ea_type; static const bool prefer_at_accessor = false; static const bool has_subview = false; static const bool fake_mat = false; static const bool is_row = mtGlue::is_row; static const bool is_col = mtGlue::is_col; arma_aligned const Mat Q; inline explicit Proxy(const mtGlue& A) : Q(A) { arma_extra_debug_sigprint(); } arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } arma_inline uword get_n_elem() const { return Q.n_elem; } arma_inline elem_type operator[] (const uword i) const { return Q[i]; } arma_inline elem_type at (const uword row, const uword col) const { return Q.at(row,col); } arma_inline elem_type at_alt (const uword i) const { return Q.at_alt(i); } arma_inline ea_type get_ea() const { return Q.memptr(); } arma_inline aligned_ea_type get_aligned_ea() const { return Q; } template arma_inline bool is_alias(const Mat&) const { return false; } arma_inline bool is_aligned() const { return memory::is_aligned(Q.memptr()); } }; //! @} armadillo-6.500.5/include/armadillo_bits/constants_compat.hpp0000666000000000000000000001311312620272703023035 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup constants_compat //! @{ // the Math and Phy classes are kept for compatibility with old code; // for new code, use the Datum class instead // eg. instead of math::pi(), use datum::pi template class Math { public: // the long lengths of the constants are for future support of "long double" // and any smart compiler that does high-precision computation at compile-time //! ratio of any circle's circumference to its diameter static eT pi() { return eT(3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679); } //! base of the natural logarithm static eT e() { return eT(2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274); } //! Euler's constant, aka Euler-Mascheroni constant static eT euler() { return eT(0.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495); } //! golden ratio static eT gratio() { return eT(1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911374); } //! square root of 2 static eT sqrt2() { return eT(1.4142135623730950488016887242096980785696718753769480731766797379907324784621070388503875343276415727); } //! the difference between 1 and the least value greater than 1 that is representable static eT eps() { return std::numeric_limits::epsilon(); } //! log of the minimum representable value static eT log_min() { static const eT out = std::log(std::numeric_limits::min()); return out; } //! log of the maximum representable value static eT log_max() { static const eT out = std::log(std::numeric_limits::max()); return out; } //! "not a number" static eT nan() { return priv::Datum_helper::nan(); } //! infinity static eT inf() { return priv::Datum_helper::inf(); } }; //! Physical constants taken from NIST 2010 CODATA values, and some from WolframAlpha (values provided as of 2009-06-23) //! http://physics.nist.gov/cuu/Constants //! http://www.wolframalpha.com //! See also http://en.wikipedia.org/wiki/Physical_constant template class Phy { public: //! atomic mass constant (in kg) static eT m_u() { return eT(1.660539040e-27); } //! Avogadro constant static eT N_A() { return eT(6.022140857e23); } //! Boltzmann constant (in joules per kelvin) static eT k() { return eT(1.38064852e-23); } //! Boltzmann constant (in eV/K) static eT k_evk() { return eT(8.6173303e-5); } //! Bohr radius (in meters) static eT a_0() { return eT(0.52917721067e-10); } //! Bohr magneton static eT mu_B() { return eT(927.4009994e-26); } //! characteristic impedance of vacuum (in ohms) static eT Z_0() { return eT(376.730313461771); } //! conductance quantum (in siemens) static eT G_0() { return eT(7.7480917310e-5); } //! Coulomb's constant (in meters per farad) static eT k_e() { return eT(8.9875517873681764e9); } //! electric constant (in farads per meter) static eT eps_0() { return eT(8.85418781762039e-12); } //! electron mass (in kg) static eT m_e() { return eT(9.10938356e-31); } //! electron volt (in joules) static eT eV() { return eT(1.6021766208e-19); } //! elementary charge (in coulombs) static eT e() { return eT(1.6021766208e-19); } //! Faraday constant (in coulombs) static eT F() { return eT(96485.33289); } //! fine-structure constant static eT alpha() { return eT(7.2973525664e-3); } //! inverse fine-structure constant static eT alpha_inv() { return eT(137.035999139); } //! Josephson constant static eT K_J() { return eT(483597.8525e9); } //! magnetic constant (in henries per meter) static eT mu_0() { return eT(1.25663706143592e-06); } //! magnetic flux quantum (in webers) static eT phi_0() { return eT(2.067833667e-15); } //! molar gas constant (in joules per mole kelvin) static eT R() { return eT(8.3144598); } //! Newtonian constant of gravitation (in newton square meters per kilogram squared) static eT G() { return eT(6.67408e-11); } //! Planck constant (in joule seconds) static eT h() { return eT(6.626070040e-34); } //! Planck constant over 2 pi, aka reduced Planck constant (in joule seconds) static eT h_bar() { return eT(1.054571800e-34); } //! proton mass (in kg) static eT m_p() { return eT(1.672621898e-27); } //! Rydberg constant (in reciprocal meters) static eT R_inf() { return eT(10973731.568508); } //! speed of light in vacuum (in meters per second) static eT c_0() { return eT(299792458.0); } //! Stefan-Boltzmann constant static eT sigma() { return eT(5.670367e-8); } //! von Klitzing constant (in ohms) static eT R_k() { return eT(25812.8074555); } //! Wien wavelength displacement law constant static eT b() { return eT(2.8977729e-3); } }; typedef Math fmath; typedef Math math; typedef Phy fphy; typedef Phy phy; //! @} armadillo-6.500.5/include/armadillo_bits/subview_elem2_meat.hpp0000666000000000000000000004466612634230273023256 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_elem2 //! @{ template inline subview_elem2::~subview_elem2() { arma_extra_debug_sigprint(); } template arma_inline subview_elem2::subview_elem2 ( const Mat& in_m, const Base& in_ri, const Base& in_ci, const bool in_all_rows, const bool in_all_cols ) : m (in_m ) , base_ri (in_ri ) , base_ci (in_ci ) , all_rows (in_all_rows) , all_cols (in_all_cols) { arma_extra_debug_sigprint(); } template template inline void subview_elem2::inplace_op(const eT val) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); const uword m_n_rows = m_local.n_rows; const uword m_n_cols = m_local.n_cols; if( (all_rows == false) && (all_cols == false) ) { const unwrap_check_mixed tmp1(base_ri.get_ref(), m_local); const unwrap_check_mixed tmp2(base_ci.get_ref(), m_local); const umat& ri = tmp1.M; const umat& ci = tmp2.M; arma_debug_check ( ( ((ri.is_vec() == false) && (ri.is_empty() == false)) || ((ci.is_vec() == false) && (ci.is_empty() == false)) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col >= m_n_cols), "Mat::elem(): index out of bounds" ); for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row >= m_n_rows), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_local.at(row,col) = val; } if(is_same_type::yes) { m_local.at(row,col) += val; } if(is_same_type::yes) { m_local.at(row,col) -= val; } if(is_same_type::yes) { m_local.at(row,col) *= val; } if(is_same_type::yes) { m_local.at(row,col) /= val; } } } } else if( (all_rows == true) && (all_cols == false) ) { const unwrap_check_mixed tmp2(base_ci.get_ref(), m_local); const umat& ci = tmp2.M; arma_debug_check ( ( (ci.is_vec() == false) && (ci.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col >= m_n_cols), "Mat::elem(): index out of bounds" ); eT* colptr = m_local.colptr(col); if(is_same_type::yes) { arrayops::inplace_set (colptr, val, m_n_rows); } if(is_same_type::yes) { arrayops::inplace_plus (colptr, val, m_n_rows); } if(is_same_type::yes) { arrayops::inplace_minus(colptr, val, m_n_rows); } if(is_same_type::yes) { arrayops::inplace_mul (colptr, val, m_n_rows); } if(is_same_type::yes) { arrayops::inplace_div (colptr, val, m_n_rows); } } } else if( (all_rows == false) && (all_cols == true) ) { const unwrap_check_mixed tmp1(base_ri.get_ref(), m_local); const umat& ri = tmp1.M; arma_debug_check ( ( (ri.is_vec() == false) && (ri.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; for(uword col=0; col < m_n_cols; ++col) { for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row >= m_n_rows), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_local.at(row,col) = val; } if(is_same_type::yes) { m_local.at(row,col) += val; } if(is_same_type::yes) { m_local.at(row,col) -= val; } if(is_same_type::yes) { m_local.at(row,col) *= val; } if(is_same_type::yes) { m_local.at(row,col) /= val; } } } } } template template inline void subview_elem2::inplace_op(const Base& x) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); const uword m_n_rows = m_local.n_rows; const uword m_n_cols = m_local.n_cols; const unwrap_check tmp(x.get_ref(), m_local); const Mat& X = tmp.M; if( (all_rows == false) && (all_cols == false) ) { const unwrap_check_mixed tmp1(base_ri.get_ref(), m_local); const unwrap_check_mixed tmp2(base_ci.get_ref(), m_local); const umat& ri = tmp1.M; const umat& ci = tmp2.M; arma_debug_check ( ( ((ri.is_vec() == false) && (ri.is_empty() == false)) || ((ci.is_vec() == false) && (ci.is_empty() == false)) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; arma_debug_assert_same_size( ri_n_elem, ci_n_elem, X.n_rows, X.n_cols, "Mat::elem()" ); for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col >= m_n_cols), "Mat::elem(): index out of bounds" ); for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row >= m_n_rows), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_local.at(row,col) = X.at(ri_count, ci_count); } if(is_same_type::yes) { m_local.at(row,col) += X.at(ri_count, ci_count); } if(is_same_type::yes) { m_local.at(row,col) -= X.at(ri_count, ci_count); } if(is_same_type::yes) { m_local.at(row,col) *= X.at(ri_count, ci_count); } if(is_same_type::yes) { m_local.at(row,col) /= X.at(ri_count, ci_count); } } } } else if( (all_rows == true) && (all_cols == false) ) { const unwrap_check_mixed tmp2(base_ci.get_ref(), m_local); const umat& ci = tmp2.M; arma_debug_check ( ( (ci.is_vec() == false) && (ci.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; arma_debug_assert_same_size( m_n_rows, ci_n_elem, X.n_rows, X.n_cols, "Mat::elem()" ); for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col >= m_n_cols), "Mat::elem(): index out of bounds" ); eT* m_colptr = m_local.colptr(col); const eT* X_colptr = X.colptr(ci_count); if(is_same_type::yes) { arrayops::copy (m_colptr, X_colptr, m_n_rows); } if(is_same_type::yes) { arrayops::inplace_plus (m_colptr, X_colptr, m_n_rows); } if(is_same_type::yes) { arrayops::inplace_minus(m_colptr, X_colptr, m_n_rows); } if(is_same_type::yes) { arrayops::inplace_mul (m_colptr, X_colptr, m_n_rows); } if(is_same_type::yes) { arrayops::inplace_div (m_colptr, X_colptr, m_n_rows); } } } else if( (all_rows == false) && (all_cols == true) ) { const unwrap_check_mixed tmp1(base_ri.get_ref(), m_local); const umat& ri = tmp1.M; arma_debug_check ( ( (ri.is_vec() == false) && (ri.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; arma_debug_assert_same_size( ri_n_elem, m_n_cols, X.n_rows, X.n_cols, "Mat::elem()" ); for(uword col=0; col < m_n_cols; ++col) { for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row >= m_n_rows), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_local.at(row,col) = X.at(ri_count, col); } if(is_same_type::yes) { m_local.at(row,col) += X.at(ri_count, col); } if(is_same_type::yes) { m_local.at(row,col) -= X.at(ri_count, col); } if(is_same_type::yes) { m_local.at(row,col) *= X.at(ri_count, col); } if(is_same_type::yes) { m_local.at(row,col) /= X.at(ri_count, col); } } } } } // // template inline void subview_elem2::fill(const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem2::zeros() { arma_extra_debug_sigprint(); inplace_op(eT(0)); } template inline void subview_elem2::ones() { arma_extra_debug_sigprint(); inplace_op(eT(1)); } template inline void subview_elem2::operator+= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem2::operator-= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem2::operator*= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem2::operator/= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } // // template template inline void subview_elem2::operator_equ(const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator= (const subview_elem2& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } //! work around compiler bugs template inline void subview_elem2::operator= (const subview_elem2& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } template template inline void subview_elem2::operator+= (const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator-= (const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator%= (const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator/= (const subview_elem2& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator+= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator-= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator%= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem2::operator/= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } // // template inline void subview_elem2::extract(Mat& actual_out, const subview_elem2& in) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(in.m); const uword m_n_rows = m_local.n_rows; const uword m_n_cols = m_local.n_cols; const bool alias = (&actual_out == &m_local); if(alias) { arma_extra_debug_print("subview_elem2::extract(): aliasing detected"); } Mat* tmp_out = alias ? new Mat() : 0; Mat& out = alias ? *tmp_out : actual_out; if( (in.all_rows == false) && (in.all_cols == false) ) { const unwrap_check_mixed tmp1(in.base_ri.get_ref(), actual_out); const unwrap_check_mixed tmp2(in.base_ci.get_ref(), actual_out); const umat& ri = tmp1.M; const umat& ci = tmp2.M; arma_debug_check ( ( ((ri.is_vec() == false) && (ri.is_empty() == false)) || ((ci.is_vec() == false) && (ci.is_empty() == false)) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; out.set_size(ri_n_elem, ci_n_elem); eT* out_mem = out.memptr(); uword out_count = 0; for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col >= m_n_cols), "Mat::elem(): index out of bounds" ); for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row >= m_n_rows), "Mat::elem(): index out of bounds" ); out_mem[out_count] = m_local.at(row,col); ++out_count; } } } else if( (in.all_rows == true) && (in.all_cols == false) ) { const unwrap_check_mixed tmp2(in.base_ci.get_ref(), m_local); const umat& ci = tmp2.M; arma_debug_check ( ( (ci.is_vec() == false) && (ci.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; out.set_size(m_n_rows, ci_n_elem); for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col >= m_n_cols), "Mat::elem(): index out of bounds" ); arrayops::copy( out.colptr(ci_count), m_local.colptr(col), m_n_rows ); } } else if( (in.all_rows == false) && (in.all_cols == true) ) { const unwrap_check_mixed tmp1(in.base_ri.get_ref(), m_local); const umat& ri = tmp1.M; arma_debug_check ( ( (ri.is_vec() == false) && (ri.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; out.set_size(ri_n_elem, m_n_cols); for(uword col=0; col < m_n_cols; ++col) { for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row >= m_n_rows), "Mat::elem(): index out of bounds" ); out.at(ri_count,col) = m_local.at(row,col); } } } if(alias) { actual_out.steal_mem(out); delete tmp_out; } } // TODO: implement a dedicated function instead of creating a temporary (but lots of potential aliasing issues) template inline void subview_elem2::plus_inplace(Mat& out, const subview_elem2& in) { arma_extra_debug_sigprint(); const Mat tmp(in); out += tmp; } template inline void subview_elem2::minus_inplace(Mat& out, const subview_elem2& in) { arma_extra_debug_sigprint(); const Mat tmp(in); out -= tmp; } template inline void subview_elem2::schur_inplace(Mat& out, const subview_elem2& in) { arma_extra_debug_sigprint(); const Mat tmp(in); out %= tmp; } template inline void subview_elem2::div_inplace(Mat& out, const subview_elem2& in) { arma_extra_debug_sigprint(); const Mat tmp(in); out /= tmp; } //! @} armadillo-6.500.5/include/armadillo_bits/running_stat_vec_meat.hpp0000666000000000000000000003266412620272703024050 0ustar rootroot// Copyright (C) 2009-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup running_stat_vec //! @{ template inline running_stat_vec::~running_stat_vec() { arma_extra_debug_sigprint_this(this); } template inline running_stat_vec::running_stat_vec(const bool in_calc_cov) : calc_cov(in_calc_cov) { arma_extra_debug_sigprint_this(this); } template inline running_stat_vec::running_stat_vec(const running_stat_vec& in_rsv) : calc_cov (in_rsv.calc_cov) , counter (in_rsv.counter) , r_mean (in_rsv.r_mean) , r_var (in_rsv.r_var) , r_cov (in_rsv.r_cov) , min_val (in_rsv.min_val) , max_val (in_rsv.max_val) , min_val_norm(in_rsv.min_val_norm) , max_val_norm(in_rsv.max_val_norm) { arma_extra_debug_sigprint_this(this); } template inline const running_stat_vec& running_stat_vec::operator=(const running_stat_vec& in_rsv) { arma_extra_debug_sigprint(); access::rw(calc_cov) = in_rsv.calc_cov; counter = in_rsv.counter; r_mean = in_rsv.r_mean; r_var = in_rsv.r_var; r_cov = in_rsv.r_cov; min_val = in_rsv.min_val; max_val = in_rsv.max_val; min_val_norm = in_rsv.min_val_norm; max_val_norm = in_rsv.max_val_norm; return *this; } //! update statistics to reflect new sample template template arma_hot inline void running_stat_vec::operator() (const Base::T, T1>& X) { arma_extra_debug_sigprint(); const quasi_unwrap tmp(X.get_ref()); const Mat& sample = tmp.M; if( sample.is_empty() ) { return; } if( sample.is_finite() == false ) { arma_debug_warn("running_stat_vec: sample ignored as it has non-finite elements"); return; } running_stat_vec_aux::update_stats(*this, sample); } template template arma_hot inline void running_stat_vec::operator() (const Base< std::complex::T>, T1>& X) { arma_extra_debug_sigprint(); const quasi_unwrap tmp(X.get_ref()); const Mat< std::complex >& sample = tmp.M; if( sample.is_empty() ) { return; } if( sample.is_finite() == false ) { arma_debug_warn("running_stat_vec: sample ignored as it has non-finite elements"); return; } running_stat_vec_aux::update_stats(*this, sample); } //! set all statistics to zero template inline void running_stat_vec::reset() { arma_extra_debug_sigprint(); counter.reset(); r_mean.reset(); r_var.reset(); r_cov.reset(); min_val.reset(); max_val.reset(); min_val_norm.reset(); max_val_norm.reset(); r_var_dummy.reset(); r_cov_dummy.reset(); tmp1.reset(); tmp2.reset(); } //! mean or average value template inline const Mat< typename running_stat_vec::eT >& running_stat_vec::mean() const { arma_extra_debug_sigprint(); return r_mean; } //! variance template inline const Mat< typename running_stat_vec::T >& running_stat_vec::var(const uword norm_type) { arma_extra_debug_sigprint(); const T N = counter.value(); if(N > T(1)) { if(norm_type == 0) { return r_var; } else { const T N_minus_1 = counter.value_minus_1(); r_var_dummy = (N_minus_1/N) * r_var; return r_var_dummy; } } else { r_var_dummy.zeros(r_mean.n_rows, r_mean.n_cols); return r_var_dummy; } } //! standard deviation template inline Mat< typename running_stat_vec::T > running_stat_vec::stddev(const uword norm_type) const { arma_extra_debug_sigprint(); const T N = counter.value(); if(N > T(1)) { if(norm_type == 0) { return sqrt(r_var); } else { const T N_minus_1 = counter.value_minus_1(); return sqrt( (N_minus_1/N) * r_var ); } } else { return Mat(); } } //! covariance template inline const Mat< typename running_stat_vec::eT >& running_stat_vec::cov(const uword norm_type) { arma_extra_debug_sigprint(); if(calc_cov == true) { const T N = counter.value(); if(N > T(1)) { if(norm_type == 0) { return r_cov; } else { const T N_minus_1 = counter.value_minus_1(); r_cov_dummy = (N_minus_1/N) * r_cov; return r_cov_dummy; } } else { r_cov_dummy.zeros(r_mean.n_rows, r_mean.n_cols); return r_cov_dummy; } } else { r_cov_dummy.reset(); return r_cov_dummy; } } //! vector with minimum values template inline const Mat< typename running_stat_vec::eT >& running_stat_vec::min() const { arma_extra_debug_sigprint(); return min_val; } //! vector with maximum values template inline const Mat< typename running_stat_vec::eT >& running_stat_vec::max() const { arma_extra_debug_sigprint(); return max_val; } //! number of samples so far template inline typename running_stat_vec::T running_stat_vec::count() const { arma_extra_debug_sigprint(); return counter.value(); } // //! update statistics to reflect new sample (version for non-complex numbers) template inline void running_stat_vec_aux::update_stats ( running_stat_vec& x, const Mat::eT>& sample, const typename arma_not_cx::eT>::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat_vec::eT eT; typedef typename running_stat_vec::T T; const T N = x.counter.value(); if(N > T(0)) { arma_debug_assert_same_size(x.r_mean, sample, "running_stat_vec(): dimensionality mismatch"); const uword n_elem = sample.n_elem; const eT* sample_mem = sample.memptr(); eT* r_mean_mem = x.r_mean.memptr(); T* r_var_mem = x.r_var.memptr(); eT* min_val_mem = x.min_val.memptr(); eT* max_val_mem = x.max_val.memptr(); const T N_plus_1 = x.counter.value_plus_1(); const T N_minus_1 = x.counter.value_minus_1(); if(x.calc_cov == true) { Mat& tmp1 = x.tmp1; Mat& tmp2 = x.tmp2; tmp1 = sample - x.r_mean; if(sample.n_cols == 1) { tmp2 = tmp1*trans(tmp1); } else { tmp2 = trans(tmp1)*tmp1; } x.r_cov *= (N_minus_1/N); x.r_cov += tmp2 / N_plus_1; } for(uword i=0; i max_val_mem[i]) { max_val_mem[i] = val; } const eT r_mean_val = r_mean_mem[i]; const eT tmp = val - r_mean_val; r_var_mem[i] = N_minus_1/N * r_var_mem[i] + (tmp*tmp)/N_plus_1; r_mean_mem[i] = r_mean_val + (val - r_mean_val)/N_plus_1; } } else { arma_debug_check( (sample.is_vec() == false), "running_stat_vec(): given sample is not a vector"); x.r_mean.set_size(sample.n_rows, sample.n_cols); x.r_var.zeros(sample.n_rows, sample.n_cols); if(x.calc_cov == true) { x.r_cov.zeros(sample.n_elem, sample.n_elem); } x.min_val.set_size(sample.n_rows, sample.n_cols); x.max_val.set_size(sample.n_rows, sample.n_cols); const uword n_elem = sample.n_elem; const eT* sample_mem = sample.memptr(); eT* r_mean_mem = x.r_mean.memptr(); eT* min_val_mem = x.min_val.memptr(); eT* max_val_mem = x.max_val.memptr(); for(uword i=0; i inline void running_stat_vec_aux::update_stats ( running_stat_vec& x, const Mat::T > >& sample, const typename arma_not_cx::eT>::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat_vec::eT eT; running_stat_vec_aux::update_stats(x, conv_to< Mat >::from(sample)); } //! update statistics to reflect new sample (version for complex numbers, non-complex sample) template inline void running_stat_vec_aux::update_stats ( running_stat_vec& x, const Mat::T >& sample, const typename arma_cx_only::eT>::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat_vec::eT eT; running_stat_vec_aux::update_stats(x, conv_to< Mat >::from(sample)); } //! alter statistics to reflect new sample (version for complex numbers, complex sample) template inline void running_stat_vec_aux::update_stats ( running_stat_vec& x, const Mat::eT>& sample, const typename arma_cx_only::eT>::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename running_stat_vec::eT eT; typedef typename running_stat_vec::T T; const T N = x.counter.value(); if(N > T(0)) { arma_debug_assert_same_size(x.r_mean, sample, "running_stat_vec(): dimensionality mismatch"); const uword n_elem = sample.n_elem; const eT* sample_mem = sample.memptr(); eT* r_mean_mem = x.r_mean.memptr(); T* r_var_mem = x.r_var.memptr(); eT* min_val_mem = x.min_val.memptr(); eT* max_val_mem = x.max_val.memptr(); T* min_val_norm_mem = x.min_val_norm.memptr(); T* max_val_norm_mem = x.max_val_norm.memptr(); const T N_plus_1 = x.counter.value_plus_1(); const T N_minus_1 = x.counter.value_minus_1(); if(x.calc_cov == true) { Mat& tmp1 = x.tmp1; Mat& tmp2 = x.tmp2; tmp1 = sample - x.r_mean; if(sample.n_cols == 1) { tmp2 = arma::conj(tmp1)*strans(tmp1); } else { tmp2 = trans(tmp1)*tmp1; //tmp2 = strans(conj(tmp1))*tmp1; } x.r_cov *= (N_minus_1/N); x.r_cov += tmp2 / N_plus_1; } for(uword i=0; i max_val_norm_mem[i]) { max_val_norm_mem[i] = val_norm; max_val_mem[i] = val; } const eT& r_mean_val = r_mean_mem[i]; r_var_mem[i] = N_minus_1/N * r_var_mem[i] + std::norm(val - r_mean_val)/N_plus_1; r_mean_mem[i] = r_mean_val + (val - r_mean_val)/N_plus_1; } } else { arma_debug_check( (sample.is_vec() == false), "running_stat_vec(): given sample is not a vector"); x.r_mean.set_size(sample.n_rows, sample.n_cols); x.r_var.zeros(sample.n_rows, sample.n_cols); if(x.calc_cov == true) { x.r_cov.zeros(sample.n_elem, sample.n_elem); } x.min_val.set_size(sample.n_rows, sample.n_cols); x.max_val.set_size(sample.n_rows, sample.n_cols); x.min_val_norm.set_size(sample.n_rows, sample.n_cols); x.max_val_norm.set_size(sample.n_rows, sample.n_cols); const uword n_elem = sample.n_elem; const eT* sample_mem = sample.memptr(); eT* r_mean_mem = x.r_mean.memptr(); eT* min_val_mem = x.min_val.memptr(); eT* max_val_mem = x.max_val.memptr(); T* min_val_norm_mem = x.min_val_norm.memptr(); T* max_val_norm_mem = x.max_val_norm.memptr(); for(uword i=0; i inline typename enable_if2 < is_Mat::value, vec_type >::result linspace ( const typename vec_type::pod_type start, const typename vec_type::pod_type end, const uword num = 100u ) { arma_extra_debug_sigprint(); typedef typename vec_type::elem_type eT; typedef typename vec_type::pod_type T; vec_type x; if(num >= 2) { x.set_size(num); eT* x_mem = x.memptr(); const uword num_m1 = num - 1; if(is_non_integral::value == true) { const T delta = (end-start)/T(num_m1); for(uword i=0; i= start) ? double(end-start)/double(num_m1) : -double(start-end)/double(num_m1); for(uword i=0; i(start, end, num); } // // log_exp_add template inline typename arma_real_only::result log_add_exp(eT log_a, eT log_b) { if(log_a < log_b) { std::swap(log_a, log_b); } const eT negdelta = log_b - log_a; if( (negdelta < Datum::log_min) || (arma_isfinite(negdelta) == false) ) { return log_a; } else { return (log_a + arma_log1p(std::exp(negdelta))); } } // for compatibility with earlier versions template inline typename arma_real_only::result log_add(eT log_a, eT log_b) { return log_add_exp(log_a, log_b); } template arma_inline arma_warn_unused bool is_finite(const eT x, const typename arma_scalar_only::result* junk = 0) { arma_ignore(junk); return arma_isfinite(x); } template inline arma_warn_unused typename enable_if2 < is_arma_type::value, bool >::result is_finite(const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); const bool have_direct_mem = (is_Mat::stored_type>::value) || (is_subview_col::stored_type>::value); if(have_direct_mem) { const quasi_unwrap::stored_type> tmp(P.Q); return tmp.M.is_finite(); } if(Proxy::prefer_at_accessor == false) { const typename Proxy::ea_type Pea = P.get_ea(); const uword n_elem = P.get_n_elem(); uword i,j; for(i=0, j=1; j inline arma_warn_unused bool is_finite(const SpBase& X) { arma_extra_debug_sigprint(); const SpProxy P(X.get_ref()); if(is_SpMat::stored_type>::value) { const unwrap_spmat::stored_type> tmp(P.Q); return tmp.M.is_finite(); } else { typename SpProxy::const_iterator_type it = P.begin(); typename SpProxy::const_iterator_type it_end = P.end(); while(it != it_end) { if(arma_isfinite(*it) == false) { return false; } ++it; } } return true; } template inline arma_warn_unused bool is_finite(const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.get_ref()); const Cube& A = tmp.M; return A.is_finite(); } //! DO NOT USE IN NEW CODE; change instances of inv(sympd(X)) to inv_sympd(X) template arma_deprecated inline const T1& sympd(const Base& X) { arma_extra_debug_sigprint(); arma_debug_warn("sympd() is deprecated and will be removed; change inv(sympd(X)) to inv_sympd(X)"); return X.get_ref(); } template inline void swap(Mat& A, Mat& B) { arma_extra_debug_sigprint(); A.swap(B); } template inline void swap(Cube& A, Cube& B) { arma_extra_debug_sigprint(); A.swap(B); } template arma_inline const Op orth(const Base& X, const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; return Op(X.get_ref(), eT(tol)); } template inline bool orth(Mat& out, const Base& X, const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = orth(X,tol); } catch (std::runtime_error&) { return false; } return true; } template arma_inline const Op null(const Base& X, const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; return Op(X.get_ref(), eT(tol)); } template inline bool null(Mat& out, const Base& X, const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = null(X,tol); } catch (std::runtime_error&) { return false; } return true; } inline uvec ind2sub(const SizeMat& s, const uword i) { arma_extra_debug_sigprint(); arma_debug_check( (i >= (s.n_rows * s.n_cols) ), "ind2sub(): index out of range" ); uvec out(2); out[0] = i % s.n_rows; out[1] = i / s.n_rows; return out; } inline uvec ind2sub(const SizeCube& s, const uword i) { arma_extra_debug_sigprint(); arma_debug_check( (i >= (s.n_rows * s.n_cols * s.n_slices) ), "ind2sub(): index out of range" ); const uword n_elem_slice = s.n_rows * s.n_cols; const uword slice = i / n_elem_slice; const uword j = i - (slice * n_elem_slice); const uword row = j % s.n_rows; const uword col = j / s.n_rows; uvec out(3); out[0] = row; out[1] = col; out[2] = slice; return out; } arma_inline uword sub2ind(const SizeMat& s, const uword row, const uword col) { arma_extra_debug_sigprint(); arma_debug_check( ((row >= s.n_rows) || (col >= s.n_cols)), "sub2ind(): subscript out of range" ); return uword(row + col*s.n_rows); } arma_inline uword sub2ind(const SizeCube& s, const uword row, const uword col, const uword slice) { arma_extra_debug_sigprint(); arma_debug_check( ((row >= s.n_rows) || (col >= s.n_cols) || (slice >= s.n_slices)), "sub2ind(): subscript out of range" ); return uword( (slice * s.n_rows * s.n_cols) + (col * s.n_rows) + row ); } //! @} armadillo-6.500.5/include/armadillo_bits/op_stddev_bones.hpp0000666000000000000000000000123312620272703022633 0ustar rootroot// Copyright (C) 2009-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_stddev //! @{ //! Class for finding the standard deviation class op_stddev { public: template inline static void apply(Mat& out, const mtOp& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/def_superlu.hpp0000666000000000000000000000707612627351654022020 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/ // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin #if defined(ARMA_USE_SUPERLU) extern "C" { extern void arma_wrapper(sgssv)(superlu::superlu_options_t*, superlu::SuperMatrix*, int*, int*, superlu::SuperMatrix*, superlu::SuperMatrix*, superlu::SuperMatrix*, superlu::SuperLUStat_t*, int*); extern void arma_wrapper(dgssv)(superlu::superlu_options_t*, superlu::SuperMatrix*, int*, int*, superlu::SuperMatrix*, superlu::SuperMatrix*, superlu::SuperMatrix*, superlu::SuperLUStat_t*, int*); extern void arma_wrapper(cgssv)(superlu::superlu_options_t*, superlu::SuperMatrix*, int*, int*, superlu::SuperMatrix*, superlu::SuperMatrix*, superlu::SuperMatrix*, superlu::SuperLUStat_t*, int*); extern void arma_wrapper(zgssv)(superlu::superlu_options_t*, superlu::SuperMatrix*, int*, int*, superlu::SuperMatrix*, superlu::SuperMatrix*, superlu::SuperMatrix*, superlu::SuperLUStat_t*, int*); extern void arma_wrapper(sgssvx)(superlu::superlu_options_t*, superlu::SuperMatrix*, int*, int*, int*, char*, float*, float*, superlu::SuperMatrix*, superlu::SuperMatrix*, void*, int, superlu::SuperMatrix*, superlu::SuperMatrix*, float*, float*, float*, float*, superlu::mem_usage_t*, superlu::SuperLUStat_t*, int*); extern void arma_wrapper(dgssvx)(superlu::superlu_options_t*, superlu::SuperMatrix*, int*, int*, int*, char*, double*, double*, superlu::SuperMatrix*, superlu::SuperMatrix*, void*, int, superlu::SuperMatrix*, superlu::SuperMatrix*, double*, double*, double*, double*, superlu::mem_usage_t*, superlu::SuperLUStat_t*, int*); extern void arma_wrapper(cgssvx)(superlu::superlu_options_t*, superlu::SuperMatrix*, int*, int*, int*, char*, float*, float*, superlu::SuperMatrix*, superlu::SuperMatrix*, void*, int, superlu::SuperMatrix*, superlu::SuperMatrix*, float*, float*, float*, float*, superlu::mem_usage_t*, superlu::SuperLUStat_t*, int*); extern void arma_wrapper(zgssvx)(superlu::superlu_options_t*, superlu::SuperMatrix*, int*, int*, int*, char*, double*, double*, superlu::SuperMatrix*, superlu::SuperMatrix*, void*, int, superlu::SuperMatrix*, superlu::SuperMatrix*, double*, double*, double*, double*, superlu::mem_usage_t*, superlu::SuperLUStat_t*, int*); extern void arma_wrapper(StatInit)(superlu::SuperLUStat_t*); extern void arma_wrapper(StatFree)(superlu::SuperLUStat_t*); extern void arma_wrapper(set_default_options)(superlu::superlu_options_t*); extern void arma_wrapper(Destroy_SuperNode_Matrix)(superlu::SuperMatrix*); extern void arma_wrapper(Destroy_CompCol_Matrix)(superlu::SuperMatrix*); extern void arma_wrapper(Destroy_SuperMatrix_Store)(superlu::SuperMatrix*); // We also need superlu_malloc() and superlu_free(). // When using the original SuperLU code directly, you (the user) may // define USER_MALLOC and USER_FREE, but the joke is on you because // if you are linking against SuperLU and not compiling from scratch, // it won't actually make a difference anyway! If you've compiled // SuperLU against a custom USER_MALLOC and USER_FREE, you're probably up // shit creek about a thousand different ways before you even get to this // code, so, don't do that! extern void* arma_wrapper(superlu_malloc)(size_t); extern void arma_wrapper(superlu_free)(void*); } #endif armadillo-6.500.5/include/armadillo_bits/sp_auxlib_bones.hpp0000666000000000000000000000615112627476623022654 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup sp_auxlib //! @{ //! wrapper for accesing external functions for sparse matrices defined in ARPACK class sp_auxlib { public: enum form_type { form_none, form_lm, form_sm, form_lr, form_la, form_sr, form_li, form_si, form_sa }; inline static form_type interpret_form_str(const char* form_str); // // eigs_sym() via ARPACK template inline static bool eigs_sym(Col& eigval, Mat& eigvec, const SpBase& X, const uword n_eigvals, const char* form_str, const eT default_tol); // // eigs_gen() via ARPACK template inline static bool eigs_gen(Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase& X, const uword n_eigvals, const char* form_str, const T default_tol); template inline static bool eigs_gen(Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase< std::complex, T1>& X, const uword n_eigvals, const char* form_str, const T default_tol); // // spsolve() via SuperLU template inline static bool spsolve_simple(Mat& out, const SpBase& A, const Base& B, const superlu_opts& user_opts); template inline static bool spsolve_refine(Mat& out, typename T1::pod_type& out_rcond, const SpBase& A, const Base& B, const superlu_opts& user_opts); #if defined(ARMA_USE_SUPERLU) inline static void set_superlu_opts(superlu::superlu_options_t& options, const superlu_opts& user_opts); template inline static bool copy_to_supermatrix(superlu::SuperMatrix& out, const SpMat& A); template inline static bool wrap_to_supermatrix(superlu::SuperMatrix& out, const Mat& A); inline static void destroy_supermatrix(superlu::SuperMatrix& out); #endif private: // calls arpack saupd()/naupd() because the code is so similar for each // all of the extra variables are later used by seupd()/neupd(), but those // functions are very different and we can't combine their code template inline static void run_aupd ( const uword n_eigvals, char* which, const SpProxy& p, const bool sym, blas_int& n, eT& tol, podarray& resid, blas_int& ncv, podarray& v, blas_int& ldv, podarray& iparam, podarray& ipntr, podarray& workd, podarray& workl, blas_int& lworkl, podarray& rwork, blas_int& info ); }; armadillo-6.500.5/include/armadillo_bits/op_reshape_bones.hpp0000666000000000000000000000233012620272703022770 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_reshape //! @{ class op_reshape { public: template inline static void apply_unwrap(Mat& out, const Mat& A, const uword in_n_rows, const uword in_n_cols, const uword in_dim); template inline static void apply_proxy (Mat& out, const Proxy& P, const uword in_n_rows, const uword in_n_cols); template inline static void apply (Mat& out, const Op& in); }; class op_reshape_ext { public: template inline static void apply( Mat& out, const Op& in); template inline static void apply(Cube& out, const OpCube& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_any_bones.hpp0000666000000000000000000000301412620272703022130 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_any //! @{ class op_any { public: template static inline bool any_vec_helper(const Base& X); template static inline bool any_vec_helper ( const mtOp& X, const typename arma_op_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0 ); template static inline bool any_vec_helper ( const mtGlue& X, const typename arma_glue_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0, const typename arma_not_cx::result junk3 = 0 ); template static inline bool any_vec(T1& X); template static inline void apply_helper(Mat& out, const Proxy& P, const uword dim); template static inline void apply(Mat& out, const mtOp& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/SpMat_bones.hpp0000666000000000000000000007033412620272703021700 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin // Written by Matthew Amidon //! \addtogroup SpMat //! @{ //! Sparse matrix class, with data stored in compressed sparse column (CSC) format template class SpMat : public SpBase< eT, SpMat > { public: typedef eT elem_type; //!< the type of elements stored in the matrix typedef typename get_pod_type::result pod_type; //!< if eT is std::complex, pod_type is T; otherwise pod_type is eT static const bool is_row = false; static const bool is_col = false; const uword n_rows; //!< number of rows (read-only) const uword n_cols; //!< number of columns (read-only) const uword n_elem; //!< number of elements (read-only) const uword n_nonzero; //!< number of nonzero elements (read-only) const uword vec_state; //!< 0: matrix; 1: column vector; 2: row vector // so that SpValProxy can call add_element() and delete_element() friend class SpValProxy >; friend class SpSubview; /** * The memory used to store the values of the matrix. * In accordance with the CSC format, this stores only the actual values. * The correct locations of the values are assembled from the row indices * and the column pointers. * * The length of this array is (n_nonzero + 1); the final value ensures * the integrity of iterators. If you are planning on resizing this vector, * it's probably best to use mem_resize() instead, which automatically sets * the length to (n_nonzero + 1). If you need to allocate the memory yourself * for some reason, be sure to set values[n_nonzero] to 0. */ arma_aligned const eT* const values; /** * The row indices of each value. row_indices[i] is the row of values[i]. * * The length of this array is (n_nonzero + 1); the final value ensures * the integrity of iterators. If you are planning on resizing this vector, * it's probably best to use mem_resize() instead. If you need to allocate * the memory yourself for some reason, be sure to set row_indices[n_nonzero] to 0. */ arma_aligned const uword* const row_indices; /** * The column pointers. This stores the index of the first item in column i. * That is, values[col_ptrs[i]] is the first value in column i, and it is in * the row indicated by row_indices[col_ptrs[i]]. * * This array is of length (n_cols + 2); the element col_ptrs[n_cols] should * be equal to n_nonzero, and the element col_ptrs[n_cols + 1] is an invalid * very large value that ensures the integrity of iterators. * * The col_ptrs array is set by the init() function (which is called by the * constructors and set_size() and other functions that set the size of the * matrix), so allocating col_ptrs by hand should not be necessary. */ arma_aligned const uword* const col_ptrs; inline SpMat(); inline ~SpMat(); inline explicit SpMat(const uword in_rows, const uword in_cols); inline explicit SpMat(const SizeMat& s); inline SpMat(const char* text); inline const SpMat& operator=(const char* text); inline SpMat(const std::string& text); inline const SpMat& operator=(const std::string& text); inline SpMat(const SpMat& x); #if defined(ARMA_USE_CXX11) inline SpMat(SpMat&& m); inline const SpMat& operator=(SpMat&& m); #endif template inline SpMat(const Base& rowind, const Base& colptr, const Base& values, const uword n_rows, const uword n_cols); template inline SpMat(const Base& locations, const Base& values, const bool sort_locations = true); template inline SpMat(const Base& locations, const Base& values, const uword n_rows, const uword n_cols, const bool sort_locations = true, const bool check_for_zeros = true); template inline SpMat(const bool add_values, const Base& locations, const Base& values, const uword n_rows, const uword n_cols, const bool sort_locations = true, const bool check_for_zeros = true); inline const SpMat& operator=(const eT val); //! sets size to 1x1 inline const SpMat& operator*=(const eT val); inline const SpMat& operator/=(const eT val); // operator+=(val) and operator-=(val) are not defined as they don't make sense for sparse matrices inline const SpMat& operator=(const SpMat& m); inline const SpMat& operator+=(const SpMat& m); inline const SpMat& operator-=(const SpMat& m); inline const SpMat& operator*=(const SpMat& m); inline const SpMat& operator%=(const SpMat& m); inline const SpMat& operator/=(const SpMat& m); template inline explicit SpMat(const Base& m); template inline const SpMat& operator=(const Base& m); template inline const SpMat& operator+=(const Base& m); template inline const SpMat& operator-=(const Base& m); template inline const SpMat& operator*=(const Base& m); template inline const SpMat& operator/=(const Base& m); template inline const SpMat& operator%=(const Base& m); //! construction of complex matrix out of two non-complex matrices template inline explicit SpMat(const SpBase& A, const SpBase& B); inline SpMat(const SpSubview& X); inline const SpMat& operator=(const SpSubview& X); inline const SpMat& operator+=(const SpSubview& X); inline const SpMat& operator-=(const SpSubview& X); inline const SpMat& operator*=(const SpSubview& X); inline const SpMat& operator%=(const SpSubview& X); inline const SpMat& operator/=(const SpSubview& X); // delayed unary ops template inline SpMat(const SpOp& X); template inline const SpMat& operator=(const SpOp& X); template inline const SpMat& operator+=(const SpOp& X); template inline const SpMat& operator-=(const SpOp& X); template inline const SpMat& operator*=(const SpOp& X); template inline const SpMat& operator%=(const SpOp& X); template inline const SpMat& operator/=(const SpOp& X); // delayed binary ops template inline SpMat(const SpGlue& X); template inline const SpMat& operator=(const SpGlue& X); template inline const SpMat& operator+=(const SpGlue& X); template inline const SpMat& operator-=(const SpGlue& X); template inline const SpMat& operator*=(const SpGlue& X); template inline const SpMat& operator%=(const SpGlue& X); template inline const SpMat& operator/=(const SpGlue& X); // delayed mixed-type unary ops template inline SpMat(const mtSpOp& X); template inline const SpMat& operator=(const mtSpOp& X); template inline const SpMat& operator+=(const mtSpOp& X); template inline const SpMat& operator-=(const mtSpOp& X); template inline const SpMat& operator*=(const mtSpOp& X); template inline const SpMat& operator%=(const mtSpOp& X); template inline const SpMat& operator/=(const mtSpOp& X); arma_inline SpSubview row(const uword row_num); arma_inline const SpSubview row(const uword row_num) const; inline SpSubview operator()(const uword row_num, const span& col_span); inline const SpSubview operator()(const uword row_num, const span& col_span) const; arma_inline SpSubview col(const uword col_num); arma_inline const SpSubview col(const uword col_num) const; inline SpSubview operator()(const span& row_span, const uword col_num); inline const SpSubview operator()(const span& row_span, const uword col_num) const; arma_inline SpSubview rows(const uword in_row1, const uword in_row2); arma_inline const SpSubview rows(const uword in_row1, const uword in_row2) const; arma_inline SpSubview cols(const uword in_col1, const uword in_col2); arma_inline const SpSubview cols(const uword in_col1, const uword in_col2) const; arma_inline SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); arma_inline const SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; arma_inline SpSubview submat(const uword in_row1, const uword in_col1, const SizeMat& s); arma_inline const SpSubview submat(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline SpSubview submat (const span& row_span, const span& col_span); inline const SpSubview submat (const span& row_span, const span& col_span) const; inline SpSubview operator()(const span& row_span, const span& col_span); inline const SpSubview operator()(const span& row_span, const span& col_span) const; arma_inline SpSubview operator()(const uword in_row1, const uword in_col1, const SizeMat& s); arma_inline const SpSubview operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline SpSubview head_rows(const uword N); inline const SpSubview head_rows(const uword N) const; inline SpSubview tail_rows(const uword N); inline const SpSubview tail_rows(const uword N) const; inline SpSubview head_cols(const uword N); inline const SpSubview head_cols(const uword N) const; inline SpSubview tail_cols(const uword N); inline const SpSubview tail_cols(const uword N) const; inline spdiagview diag(const sword in_id = 0); inline const spdiagview diag(const sword in_id = 0) const; inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_cols(const uword in_col1, const uword in_col2); inline void shed_row(const uword row_num); inline void shed_col(const uword col_num); inline void shed_rows(const uword in_row1, const uword in_row2); inline void shed_cols(const uword in_col1, const uword in_col2); // access the i-th element; if there is nothing at element i, 0 is returned arma_inline arma_warn_unused SpValProxy > operator[] (const uword i); arma_inline arma_warn_unused eT operator[] (const uword i) const; arma_inline arma_warn_unused SpValProxy > at (const uword i); arma_inline arma_warn_unused eT at (const uword i) const; arma_inline arma_warn_unused SpValProxy > operator() (const uword i); arma_inline arma_warn_unused eT operator() (const uword i) const; // access the element at the given row and column; if there is nothing at that position, 0 is returned arma_inline arma_warn_unused SpValProxy > at (const uword in_row, const uword in_col); arma_inline arma_warn_unused eT at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused SpValProxy > operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused eT operator() (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused bool is_empty() const; arma_inline arma_warn_unused bool is_vec() const; arma_inline arma_warn_unused bool is_rowvec() const; arma_inline arma_warn_unused bool is_colvec() const; arma_inline arma_warn_unused bool is_square() const; inline arma_warn_unused bool is_finite() const; inline arma_warn_unused bool has_inf() const; inline arma_warn_unused bool has_nan() const; arma_inline arma_warn_unused bool in_range(const uword i) const; arma_inline arma_warn_unused bool in_range(const span& x) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const SizeMat& s) const; inline void impl_print( const std::string& extra_text) const; inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_raw_print( const std::string& extra_text) const; inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_print_dense( const std::string& extra_text) const; inline void impl_print_dense(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_raw_print_dense( const std::string& extra_text) const; inline void impl_raw_print_dense(std::ostream& user_stream, const std::string& extra_text) const; template inline void copy_size(const SpMat& m); template inline void copy_size(const Mat& m); inline void set_size(const uword in_elem); inline void set_size(const uword in_rows, const uword in_cols); inline void set_size(const SizeMat& s); inline void resize(const uword in_rows, const uword in_cols); inline void resize(const SizeMat& s); inline void reshape(const uword in_rows, const uword in_cols); inline void reshape(const SizeMat& s); inline void reshape(const uword in_rows, const uword in_cols, const uword dim); // this form is deprecated: don't use it inline const SpMat& zeros(); inline const SpMat& zeros(const uword in_elem); inline const SpMat& zeros(const uword in_rows, const uword in_cols); inline const SpMat& zeros(const SizeMat& s); inline const SpMat& eye(); inline const SpMat& eye(const uword in_rows, const uword in_cols); inline const SpMat& eye(const SizeMat& s); inline const SpMat& speye(); inline const SpMat& speye(const uword in_rows, const uword in_cols); inline const SpMat& speye(const SizeMat& s); inline const SpMat& sprandu(const uword in_rows, const uword in_cols, const double density); inline const SpMat& sprandu(const SizeMat& s, const double density); inline const SpMat& sprandn(const uword in_rows, const uword in_cols, const double density); inline const SpMat& sprandn(const SizeMat& s, const double density); inline void reset(); template inline void set_real(const SpBase& X); template inline void set_imag(const SpBase& X); // saving and loading inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const; inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const; inline bool load(const std::string name, const file_type type = arma_binary, const bool print_status = true); inline bool load( std::istream& is, const file_type type = arma_binary, const bool print_status = true); inline bool quiet_save(const std::string name, const file_type type = arma_binary) const; inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const; inline bool quiet_load(const std::string name, const file_type type = arma_binary); inline bool quiet_load( std::istream& is, const file_type type = arma_binary); // TODO: speed up loading of sparse matrices stored as text files (ie. raw_ascii and coord_ascii) // TODO: implement auto_detect for sparse matrices // TODO: modify docs to specify which formats are not applicable to sparse matrices // necessary forward declarations class iterator_base; class iterator; class const_iterator; class row_iterator; class const_row_iterator; // iterator_base provides basic operators but not how to compare or how to iterate class iterator_base { public: inline iterator_base(); inline iterator_base(const SpMat& in_M); inline iterator_base(const SpMat& in_M, const uword col, const uword pos); inline arma_hot eT operator*() const; // don't hold location internally; call "dummy" methods to get that information arma_inline uword row() const { return M->row_indices[internal_pos]; } arma_inline uword col() const { return internal_col; } arma_inline uword pos() const { return internal_pos; } arma_aligned const SpMat* M; arma_aligned uword internal_col; arma_aligned uword internal_pos; // so that we satisfy the STL iterator types typedef std::bidirectional_iterator_tag iterator_category; typedef eT value_type; typedef uword difference_type; // not certain on this one typedef const eT* pointer; typedef const eT& reference; }; class const_iterator : public iterator_base { public: inline const_iterator(); inline const_iterator(const SpMat& in_M, uword initial_pos = 0); // assumes initial_pos is valid //! once initialised, will be at the first nonzero value after the given position (using forward columnwise traversal) inline const_iterator(const SpMat& in_M, uword in_row, uword in_col); //! if you know the exact position of the iterator; in_row is a dummy argument inline const_iterator(const SpMat& in_M, uword in_row, uword in_col, uword in_pos); inline const_iterator(const const_iterator& other); inline arma_hot const_iterator& operator++(); inline arma_hot const_iterator operator++(int); inline arma_hot const_iterator& operator--(); inline arma_hot const_iterator operator--(int); inline arma_hot bool operator==(const const_iterator& rhs) const; inline arma_hot bool operator!=(const const_iterator& rhs) const; inline arma_hot bool operator==(const typename SpSubview::const_iterator& rhs) const; inline arma_hot bool operator!=(const typename SpSubview::const_iterator& rhs) const; inline arma_hot bool operator==(const const_row_iterator& rhs) const; inline arma_hot bool operator!=(const const_row_iterator& rhs) const; inline arma_hot bool operator==(const typename SpSubview::const_row_iterator& rhs) const; inline arma_hot bool operator!=(const typename SpSubview::const_row_iterator& rhs) const; }; /** * So that we can iterate over nonzero values, we need an iterator implementation. * This can't be as simple as for Mat, which is just a pointer to an eT. * If a value is set to 0 using this iterator, the iterator is no longer valid! */ class iterator : public const_iterator { public: inline iterator() : const_iterator() { } inline iterator(SpMat& in_M, uword initial_pos = 0) : const_iterator(in_M, initial_pos) { } inline iterator(SpMat& in_M, uword in_row, uword in_col) : const_iterator(in_M, in_row, in_col) { } inline iterator(SpMat& in_M, uword in_row, uword in_col, uword in_pos) : const_iterator(in_M, in_row, in_col, in_pos) { } inline iterator(const const_iterator& other) : const_iterator(other) { } inline arma_hot SpValProxy > operator*(); // overloads needed for return type correctness inline arma_hot iterator& operator++(); inline arma_hot iterator operator++(int); inline arma_hot iterator& operator--(); inline arma_hot iterator operator--(int); // this has a different value_type than iterator_base typedef SpValProxy > value_type; typedef const SpValProxy >* pointer; typedef const SpValProxy >& reference; }; class const_row_iterator : public iterator_base { public: inline const_row_iterator(); inline const_row_iterator(const SpMat& in_M, uword initial_pos = 0); //! once initialised, will be at the first nonzero value after the given position (using forward row-wise traversal) inline const_row_iterator(const SpMat& in_M, uword in_row, uword in_col); inline const_row_iterator(const const_row_iterator& other); inline arma_hot const_row_iterator& operator++(); inline arma_hot const_row_iterator operator++(int); inline arma_hot const_row_iterator& operator--(); inline arma_hot const_row_iterator operator--(int); uword internal_row; // hold row internally because we use internal_pos differently uword actual_pos; // actual position in matrix arma_inline eT operator*() const { return iterator_base::M->values[actual_pos]; } arma_inline uword row() const { return internal_row; } inline arma_hot bool operator==(const const_iterator& rhs) const; inline arma_hot bool operator!=(const const_iterator& rhs) const; inline arma_hot bool operator==(const typename SpSubview::const_iterator& rhs) const; inline arma_hot bool operator!=(const typename SpSubview::const_iterator& rhs) const; inline arma_hot bool operator==(const const_row_iterator& rhs) const; inline arma_hot bool operator!=(const const_row_iterator& rhs) const; inline arma_hot bool operator==(const typename SpSubview::const_row_iterator& rhs) const; inline arma_hot bool operator!=(const typename SpSubview::const_row_iterator& rhs) const; }; class row_iterator : public const_row_iterator { public: inline row_iterator() : const_row_iterator() {} inline row_iterator(SpMat& in_M, uword initial_pos = 0) : const_row_iterator(in_M, initial_pos) { } //! once initialised, will be at the first nonzero value after the given position (using forward row-wise traversal) inline row_iterator(SpMat& in_M, uword in_row, uword in_col) : const_row_iterator(in_M, in_row, in_col) { } inline row_iterator(const row_iterator& other) : const_row_iterator(other) { } inline arma_hot SpValProxy > operator*(); // overloads required for return type correctness inline arma_hot row_iterator& operator++(); inline arma_hot row_iterator operator++(int); inline arma_hot row_iterator& operator--(); inline arma_hot row_iterator operator--(int); // this has a different value_type than iterator_base typedef SpValProxy > value_type; typedef const SpValProxy >* pointer; typedef const SpValProxy >& reference; }; typedef iterator row_col_iterator; typedef const_iterator const_row_col_iterator; inline iterator begin(); inline const_iterator begin() const; inline iterator end(); inline const_iterator end() const; inline iterator begin_col(const uword col_num); inline const_iterator begin_col(const uword col_num) const; inline iterator end_col(const uword col_num); inline const_iterator end_col(const uword col_num) const; inline row_iterator begin_row(const uword row_num = 0); inline const_row_iterator begin_row(const uword row_num = 0) const; inline row_iterator end_row(); inline const_row_iterator end_row() const; inline row_iterator end_row(const uword row_num); inline const_row_iterator end_row(const uword row_num) const; inline row_col_iterator begin_row_col(); inline const_row_col_iterator begin_row_col() const; inline row_col_iterator end_row_col(); inline const_row_col_iterator end_row_col() const; inline void clear(); inline bool empty() const; inline uword size() const; /** * Resize memory. * You are responsible for updating the column pointers and filling the new memory (if the new size is larger). * If the new size is smaller, the first new_n_nonzero elements will be copied. * n_nonzero is updated. */ inline void mem_resize(const uword new_n_nonzero); //! don't use this unless you're writing internal Armadillo code inline void remove_zeros(); //! don't use this unless you're writing internal Armadillo code inline void steal_mem(SpMat& X); //! don't use this unless you're writing internal Armadillo code template< typename T1, typename Functor> arma_hot inline void init_xform (const SpBase& x, const Functor& func); template arma_hot inline void init_xform_mt(const SpBase& x, const Functor& func); protected: inline void init(uword in_rows, uword in_cols); inline void init(const std::string& text); inline void init(const SpMat& x); inline void init_batch_std(const Mat& locations, const Mat& values, const bool sort_locations); inline void init_batch_add(const Mat& locations, const Mat& values, const bool sort_locations); private: inline arma_hot arma_warn_unused SpValProxy > get_value(const uword i); inline arma_hot arma_warn_unused eT get_value(const uword i) const; inline arma_hot arma_warn_unused SpValProxy > get_value(const uword in_row, const uword in_col); inline arma_hot arma_warn_unused eT get_value(const uword in_row, const uword in_col) const; arma_inline arma_hot arma_warn_unused uword get_position(const uword i) const; arma_inline arma_hot void get_position(const uword i, uword& row_of_i, uword& col_of_i) const; /** * Add an element at the given position, and return a reference to it. * The element will be set to 0 (unless otherwise specified). * If the element already exists, its value will be overwritten. */ inline arma_hot arma_warn_unused eT& add_element(const uword in_row, const uword in_col, const eT in_val = eT(0)); inline arma_hot void delete_element(const uword in_row, const uword in_col); public: #ifdef ARMA_EXTRA_SPMAT_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPMAT_PROTO) #endif }; class SpMat_aux { public: template inline static void set_real(SpMat& out, const SpBase& X); template inline static void set_real(SpMat< std::complex >& out, const SpBase< T,T1>& X); template inline static void set_imag(SpMat& out, const SpBase& X); template inline static void set_imag(SpMat< std::complex >& out, const SpBase< T,T1>& X); }; #define ARMA_HAS_SPMAT //! @} armadillo-6.500.5/include/armadillo_bits/auxlib_bones.hpp0000666000000000000000000002320312656144025022135 0ustar rootroot// Copyright (C) 2008-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by James Sanders // Written by Eric Jon Sundstrom //! \addtogroup auxlib //! @{ //! interface functions for accessing decompositions in LAPACK and ATLAS class auxlib { public: template struct pos { static const uword n2 = row + col*2; static const uword n3 = row + col*3; static const uword n4 = row + col*4; }; // // inv template inline static bool inv(Mat& out, const Base& X); template inline static bool inv(Mat& out, const Mat& A); template inline static bool inv_noalias_tinymat(Mat& out, const Mat& X, const uword N); template inline static bool inv_inplace_lapack(Mat& out); // // inv_tr template inline static bool inv_tr(Mat& out, const Base& X, const uword layout); // // inv_sym template inline static bool inv_sym(Mat& out, const Base& X, const uword layout); // // inv_sympd template inline static bool inv_sympd(Mat& out, const Base& X); // // det template inline static eT det(const Base& X); template inline static eT det_tinymat(const Mat& X, const uword N); template inline static eT det_lapack(const Mat& X, const bool make_copy); // // log_det template inline static bool log_det(eT& out_val, typename get_pod_type::result& out_sign, const Base& X); // // lu template inline static bool lu(Mat& L, Mat& U, podarray& ipiv, const Base& X); template inline static bool lu(Mat& L, Mat& U, Mat& P, const Base& X); template inline static bool lu(Mat& L, Mat& U, const Base& X); // // eig_gen template inline static bool eig_gen(Mat< std::complex >& vals, Mat< std::complex >& vecs, const bool vecs_on, const Base& expr); template inline static bool eig_gen(Mat< std::complex >& vals, Mat< std::complex >& vecs, const bool vecs_on, const Base< std::complex, T1 >& expr); // // eig_pair template inline static bool eig_pair(Mat< std::complex >& vals, Mat< std::complex >& vecs, const bool vecs_on, const Base& A_expr, const Base& B_expr); template inline static bool eig_pair(Mat< std::complex >& vals, Mat< std::complex >& vecs, const bool vecs_on, const Base< std::complex, T1 >& A_expr, const Base< std::complex, T2 >& B_expr); // // eig_sym template inline static bool eig_sym(Col& eigval, const Base& X); template inline static bool eig_sym(Col& eigval, const Base,T1>& X); template inline static bool eig_sym(Col& eigval, Mat& eigvec, const Base& X); template inline static bool eig_sym(Col& eigval, Mat< std::complex >& eigvec, const Base,T1>& X); template inline static bool eig_sym_dc(Col& eigval, Mat& eigvec, const Base& X); template inline static bool eig_sym_dc(Col& eigval, Mat< std::complex >& eigvec, const Base,T1>& X); // // chol template inline static bool chol(Mat& out, const Base& X, const uword layout); // // qr template inline static bool qr(Mat& Q, Mat& R, const Base& X); template inline static bool qr_econ(Mat& Q, Mat& R, const Base& X); // // svd template inline static bool svd(Col& S, const Base& X, uword& n_rows, uword& n_cols); template inline static bool svd(Col& S, const Base, T1>& X, uword& n_rows, uword& n_cols); template inline static bool svd(Col& S, const Base& X); template inline static bool svd(Col& S, const Base, T1>& X); template inline static bool svd(Mat& U, Col& S, Mat& V, const Base& X); template inline static bool svd(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X); template inline static bool svd_econ(Mat& U, Col& S, Mat& V, const Base& X, const char mode); template inline static bool svd_econ(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X, const char mode); template inline static bool svd_dc(Col& S, const Base& X, uword& n_rows, uword& n_cols); template inline static bool svd_dc(Col& S, const Base, T1>& X, uword& n_rows, uword& n_cols); template inline static bool svd_dc(Col& S, const Base& X); template inline static bool svd_dc(Col& S, const Base, T1>& X); template inline static bool svd_dc(Mat& U, Col& S, Mat& V, const Base& X); template inline static bool svd_dc(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X); template inline static bool svd_dc_econ(Mat& U, Col& S, Mat& V, const Base& X); template inline static bool svd_dc_econ(Mat< std::complex >& U, Col& S, Mat< std::complex >& V, const Base< std::complex, T1>& X); // // solve template inline static bool solve_square_fast(Mat& out, Mat& A, const Base& B_expr); template inline static bool solve_square_refine(Mat& out, typename T1::pod_type& out_rcond, Mat& A, const Base& B_expr, const bool equilibrate); template inline static bool solve_square_refine(Mat< std::complex >& out, typename T1::pod_type& out_rcond, Mat< std::complex >& A, const Base,T1>& B_expr, const bool equilibrate); template inline static bool solve_approx_fast(Mat& out, Mat& A, const Base& B_expr); template inline static bool solve_approx_svd(Mat& out, Mat& A, const Base& B_expr); template inline static bool solve_approx_svd(Mat< std::complex >& out, Mat< std::complex >& A, const Base,T1>& B_expr); template inline static bool solve_tri(Mat& out, const Mat& A, const Base& B_expr, const uword layout); // // Schur decomposition template inline static bool schur(Mat& U, Mat& S, const Base& X, const bool calc_U = true); template inline static bool schur(Mat >& U, Mat >& S, const Base,T1>& X, const bool calc_U = true); // // syl (solution of the Sylvester equation AX + XB = C) template inline static bool syl(Mat& X, const Mat& A, const Mat& B, const Mat& C); // // QZ decomposition template inline static bool qz(Mat& A, Mat& B, Mat& vsl, Mat& vsr, const Base& X_expr, const Base& Y_expr); template inline static bool qz(Mat< std::complex >& A, Mat< std::complex >& B, Mat< std::complex >& vsl, Mat< std::complex >& vsr, const Base< std::complex, T1 >& X_expr, const Base< std::complex, T2 >& Y_expr); // // rcond template inline static typename T1::pod_type rcond(const Base& A_expr); template inline static typename T1::pod_type rcond(const Base,T1>& A_expr); }; //! @} armadillo-6.500.5/include/armadillo_bits/memory.hpp0000666000000000000000000001224012620622641020766 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup memory //! @{ class memory { public: arma_inline static uword enlarge_to_mult_of_chunksize(const uword n_elem); template inline arma_malloc static eT* acquire(const uword n_elem); template inline arma_malloc static eT* acquire_chunked(const uword n_elem); template arma_inline static void release(eT* mem); template arma_inline static bool is_aligned(const eT* mem); template arma_inline static void mark_as_aligned( eT*& mem); template arma_inline static void mark_as_aligned(const eT*& mem); }; arma_inline uword memory::enlarge_to_mult_of_chunksize(const uword n_elem) { const uword chunksize = arma_config::spmat_chunksize; // this relies on integer division const uword n_elem_mod = (n_elem > 0) ? (((n_elem-1) / chunksize) + 1) * chunksize : uword(0); return n_elem_mod; } template inline arma_malloc eT* memory::acquire(const uword n_elem) { arma_debug_check ( ( size_t(n_elem) > (std::numeric_limits::max() / sizeof(eT)) ), "arma::memory::acquire(): requested size is too large" ); eT* out_memptr; #if defined(ARMA_USE_TBB_ALLOC) { out_memptr = (eT *) scalable_malloc(sizeof(eT)*n_elem); } #elif defined(ARMA_USE_MKL_ALLOC) { out_memptr = (eT *) mkl_malloc( sizeof(eT)*n_elem, 128 ); } #elif defined(ARMA_HAVE_POSIX_MEMALIGN) { eT* memptr; const size_t alignment = 16; // change the 16 to 64 if you wish to align to the cache line int status = posix_memalign((void **)&memptr, ( (alignment >= sizeof(void*)) ? alignment : sizeof(void*) ), sizeof(eT)*n_elem); out_memptr = (status == 0) ? memptr : NULL; } #elif defined(_MSC_VER) { //out_memptr = (eT *) malloc(sizeof(eT)*n_elem); out_memptr = (eT *) _aligned_malloc( sizeof(eT)*n_elem, 16 ); // lives in malloc.h } #else { //return ( new(std::nothrow) eT[n_elem] ); out_memptr = (eT *) malloc(sizeof(eT)*n_elem); } #endif // TODO: for mingw, use __mingw_aligned_malloc if(n_elem > 0) { arma_check_bad_alloc( (out_memptr == NULL), "arma::memory::acquire(): out of memory" ); } return out_memptr; } //! get memory in multiples of chunks, holding at least n_elem template inline arma_malloc eT* memory::acquire_chunked(const uword n_elem) { const uword n_elem_mod = memory::enlarge_to_mult_of_chunksize(n_elem); return memory::acquire(n_elem_mod); } template arma_inline void memory::release(eT* mem) { #if defined(ARMA_USE_TBB_ALLOC) { scalable_free( (void *)(mem) ); } #elif defined(ARMA_USE_MKL_ALLOC) { mkl_free( (void *)(mem) ); } #elif defined(ARMA_HAVE_POSIX_MEMALIGN) { free( (void *)(mem) ); } #elif defined(_MSC_VER) { //free( (void *)(mem) ); _aligned_free( (void *)(mem) ); } #else { //delete [] mem; free( (void *)(mem) ); } #endif // TODO: for mingw, use __mingw_aligned_free } template arma_inline bool memory::is_aligned(const eT* mem) { #if (defined(ARMA_HAVE_ICC_ASSUME_ALIGNED) || defined(ARMA_HAVE_GCC_ASSUME_ALIGNED)) && !defined(ARMA_DONT_CHECK_ALIGNMENT) { return (sizeof(std::size_t) >= sizeof(eT*)) ? ((std::size_t(mem) & 0x0F) == 0) : false; } #else { arma_ignore(mem); return false; } #endif } template arma_inline void memory::mark_as_aligned(eT*& mem) { #if defined(ARMA_HAVE_ICC_ASSUME_ALIGNED) { __assume_aligned(mem, 16); } #elif defined(ARMA_HAVE_GCC_ASSUME_ALIGNED) { mem = (eT*)__builtin_assume_aligned(mem, 16); } #else { arma_ignore(mem); } #endif // TODO: MSVC? __assume( (mem & 0x0F) == 0 ); // // http://comments.gmane.org/gmane.comp.gcc.patches/239430 // GCC __builtin_assume_aligned is similar to ICC's __assume_aligned, // so for lvalue first argument ICC's __assume_aligned can be emulated using // #define __assume_aligned(lvalueptr, align) lvalueptr = __builtin_assume_aligned (lvalueptr, align) // // http://www.inf.ethz.ch/personal/markusp/teaching/263-2300-ETH-spring11/slides/class19.pdf // http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/cpp/lin/index.htm // http://d3f8ykwhia686p.cloudfront.net/1live/intel/CompilerAutovectorizationGuide.pdf } template arma_inline void memory::mark_as_aligned(const eT*& mem) { #if defined(ARMA_HAVE_ICC_ASSUME_ALIGNED) { __assume_aligned(mem, 16); } #elif defined(ARMA_HAVE_GCC_ASSUME_ALIGNED) { mem = (const eT*)__builtin_assume_aligned(mem, 16); } #else { arma_ignore(mem); } #endif } //! @} armadillo-6.500.5/include/armadillo_bits/Mat_bones.hpp0000666000000000000000000011401112633571173021373 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup Mat //! @{ //! Dense matrix class template class Mat : public Base< eT, Mat > { public: typedef eT elem_type; //!< the type of elements stored in the matrix typedef typename get_pod_type::result pod_type; //!< if eT is std::complex, pod_type is T; otherwise pod_type is eT const uword n_rows; //!< number of rows (read-only) const uword n_cols; //!< number of columns (read-only) const uword n_elem; //!< number of elements (read-only) const uhword vec_state; //!< 0: matrix layout; 1: column vector layout; 2: row vector layout const uhword mem_state; // mem_state = 0: normal matrix which manages its own memory // mem_state = 1: use auxiliary memory until a size change // mem_state = 2: use auxiliary memory and don't allow the number of elements to be changed // mem_state = 3: fixed size (eg. via template based size specification) arma_aligned const eT* const mem; //!< pointer to the memory used for storing elements (memory is read-only) protected: arma_align_mem eT mem_local[ arma_config::mat_prealloc ]; // local storage, for small vectors and matrices public: static const bool is_col = false; static const bool is_row = false; inline ~Mat(); inline Mat(); inline explicit Mat(const uword in_rows, const uword in_cols); inline explicit Mat(const SizeMat& s); template inline Mat(const uword in_rows, const uword in_cols, const fill::fill_class& f); template inline Mat(const SizeMat& s, const fill::fill_class& f); inline Mat(const char* text); inline const Mat& operator=(const char* text); inline Mat(const std::string& text); inline const Mat& operator=(const std::string& text); inline Mat(const std::vector& x); inline const Mat& operator=(const std::vector& x); #if defined(ARMA_USE_CXX11) inline Mat(const std::initializer_list& list); inline const Mat& operator=(const std::initializer_list& list); inline Mat(const std::initializer_list< std::initializer_list >& list); inline const Mat& operator=(const std::initializer_list< std::initializer_list >& list); inline Mat(Mat&& m); inline const Mat& operator=(Mat&& m); #endif inline Mat( eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const bool copy_aux_mem = true, const bool strict = false); inline Mat(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols); arma_inline const Mat& operator=(const eT val); arma_inline const Mat& operator+=(const eT val); arma_inline const Mat& operator-=(const eT val); arma_inline const Mat& operator*=(const eT val); arma_inline const Mat& operator/=(const eT val); inline Mat(const Mat& m); inline const Mat& operator=(const Mat& m); inline const Mat& operator+=(const Mat& m); inline const Mat& operator-=(const Mat& m); inline const Mat& operator*=(const Mat& m); inline const Mat& operator%=(const Mat& m); inline const Mat& operator/=(const Mat& m); template inline Mat(const BaseCube& X); template inline const Mat& operator=(const BaseCube& X); template inline const Mat& operator+=(const BaseCube& X); template inline const Mat& operator-=(const BaseCube& X); template inline const Mat& operator*=(const BaseCube& X); template inline const Mat& operator%=(const BaseCube& X); template inline const Mat& operator/=(const BaseCube& X); template inline explicit Mat(const Base& A, const Base& B); inline Mat(const subview& X); inline const Mat& operator=(const subview& X); inline const Mat& operator+=(const subview& X); inline const Mat& operator-=(const subview& X); inline const Mat& operator*=(const subview& X); inline const Mat& operator%=(const subview& X); inline const Mat& operator/=(const subview& X); inline Mat(const subview_row_strans& X); // subview_row_strans can only be generated by the Proxy class inline Mat(const subview_row_htrans& X); // subview_row_htrans can only be generated by the Proxy class inline Mat(const xvec_htrans& X); // xvec_htrans can only be generated by the Proxy class template inline Mat(const xtrans_mat& X); // xtrans_mat can only be generated by the Proxy class inline Mat(const subview_cube& X); inline const Mat& operator=(const subview_cube& X); inline const Mat& operator+=(const subview_cube& X); inline const Mat& operator-=(const subview_cube& X); inline const Mat& operator*=(const subview_cube& X); inline const Mat& operator%=(const subview_cube& X); inline const Mat& operator/=(const subview_cube& X); inline Mat(const diagview& X); inline const Mat& operator=(const diagview& X); inline const Mat& operator+=(const diagview& X); inline const Mat& operator-=(const diagview& X); inline const Mat& operator*=(const diagview& X); inline const Mat& operator%=(const diagview& X); inline const Mat& operator/=(const diagview& X); inline Mat(const spdiagview& X); inline const Mat& operator=(const spdiagview& X); inline const Mat& operator+=(const spdiagview& X); inline const Mat& operator-=(const spdiagview& X); inline const Mat& operator*=(const spdiagview& X); inline const Mat& operator%=(const spdiagview& X); inline const Mat& operator/=(const spdiagview& X); template inline Mat(const subview_elem1& X); template inline const Mat& operator= (const subview_elem1& X); template inline const Mat& operator+=(const subview_elem1& X); template inline const Mat& operator-=(const subview_elem1& X); template inline const Mat& operator*=(const subview_elem1& X); template inline const Mat& operator%=(const subview_elem1& X); template inline const Mat& operator/=(const subview_elem1& X); template inline Mat(const subview_elem2& X); template inline const Mat& operator= (const subview_elem2& X); template inline const Mat& operator+=(const subview_elem2& X); template inline const Mat& operator-=(const subview_elem2& X); template inline const Mat& operator*=(const subview_elem2& X); template inline const Mat& operator%=(const subview_elem2& X); template inline const Mat& operator/=(const subview_elem2& X); // Operators on sparse matrices (and subviews) template inline explicit Mat(const SpBase& m); template inline const Mat& operator=(const SpBase& m); template inline const Mat& operator+=(const SpBase& m); template inline const Mat& operator-=(const SpBase& m); template inline const Mat& operator*=(const SpBase& m); template inline const Mat& operator%=(const SpBase& m); template inline const Mat& operator/=(const SpBase& m); inline mat_injector operator<<(const eT val); inline mat_injector operator<<(const injector_end_of_row<>& x); arma_inline subview_row row(const uword row_num); arma_inline const subview_row row(const uword row_num) const; inline subview_row operator()(const uword row_num, const span& col_span); inline const subview_row operator()(const uword row_num, const span& col_span) const; arma_inline subview_col col(const uword col_num); arma_inline const subview_col col(const uword col_num) const; inline subview_col operator()(const span& row_span, const uword col_num); inline const subview_col operator()(const span& row_span, const uword col_num) const; inline Col unsafe_col(const uword col_num); inline const Col unsafe_col(const uword col_num) const; arma_inline subview rows(const uword in_row1, const uword in_row2); arma_inline const subview rows(const uword in_row1, const uword in_row2) const; arma_inline subview cols(const uword in_col1, const uword in_col2); arma_inline const subview cols(const uword in_col1, const uword in_col2) const; inline subview rows(const span& row_span); inline const subview rows(const span& row_span) const; arma_inline subview cols(const span& col_span); arma_inline const subview cols(const span& col_span) const; arma_inline subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); arma_inline const subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; arma_inline subview submat(const uword in_row1, const uword in_col1, const SizeMat& s); arma_inline const subview submat(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline subview submat (const span& row_span, const span& col_span); inline const subview submat (const span& row_span, const span& col_span) const; inline subview operator()(const span& row_span, const span& col_span); inline const subview operator()(const span& row_span, const span& col_span) const; inline subview operator()(const uword in_row1, const uword in_col1, const SizeMat& s); inline const subview operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline subview head_rows(const uword N); inline const subview head_rows(const uword N) const; inline subview tail_rows(const uword N); inline const subview tail_rows(const uword N) const; inline subview head_cols(const uword N); inline const subview head_cols(const uword N) const; inline subview tail_cols(const uword N); inline const subview tail_cols(const uword N) const; template arma_inline subview_elem1 elem(const Base& a); template arma_inline const subview_elem1 elem(const Base& a) const; template arma_inline subview_elem1 operator()(const Base& a); template arma_inline const subview_elem1 operator()(const Base& a) const; template arma_inline subview_elem2 elem(const Base& ri, const Base& ci); template arma_inline const subview_elem2 elem(const Base& ri, const Base& ci) const; template arma_inline subview_elem2 submat(const Base& ri, const Base& ci); template arma_inline const subview_elem2 submat(const Base& ri, const Base& ci) const; template arma_inline subview_elem2 operator()(const Base& ri, const Base& ci); template arma_inline const subview_elem2 operator()(const Base& ri, const Base& ci) const; template arma_inline subview_elem2 rows(const Base& ri); template arma_inline const subview_elem2 rows(const Base& ri) const; template arma_inline subview_elem2 cols(const Base& ci); template arma_inline const subview_elem2 cols(const Base& ci) const; arma_inline subview_each1< Mat, 0 > each_col(); arma_inline subview_each1< Mat, 1 > each_row(); arma_inline const subview_each1< Mat, 0 > each_col() const; arma_inline const subview_each1< Mat, 1 > each_row() const; template inline subview_each2< Mat, 0, T1 > each_col(const Base& indices); template inline subview_each2< Mat, 1, T1 > each_row(const Base& indices); template inline const subview_each2< Mat, 0, T1 > each_col(const Base& indices) const; template inline const subview_each2< Mat, 1, T1 > each_row(const Base& indices) const; #if defined(ARMA_USE_CXX11) inline const Mat& each_col(const std::function< void( Col&) >& F); inline const Mat& each_col(const std::function< void(const Col&) >& F) const; inline const Mat& each_row(const std::function< void( Row&) >& F); inline const Mat& each_row(const std::function< void(const Row&) >& F) const; #endif arma_inline diagview diag(const sword in_id = 0); arma_inline const diagview diag(const sword in_id = 0) const; inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_cols(const uword in_col1, const uword in_col2); inline void shed_row(const uword row_num); inline void shed_col(const uword col_num); inline void shed_rows(const uword in_row1, const uword in_row2); inline void shed_cols(const uword in_col1, const uword in_col2); inline void insert_rows(const uword row_num, const uword N, const bool set_to_zero = true); inline void insert_cols(const uword col_num, const uword N, const bool set_to_zero = true); template inline void insert_rows(const uword row_num, const Base& X); template inline void insert_cols(const uword col_num, const Base& X); template inline Mat(const Gen& X); template inline const Mat& operator=(const Gen& X); template inline const Mat& operator+=(const Gen& X); template inline const Mat& operator-=(const Gen& X); template inline const Mat& operator*=(const Gen& X); template inline const Mat& operator%=(const Gen& X); template inline const Mat& operator/=(const Gen& X); template inline Mat(const Op& X); template inline const Mat& operator=(const Op& X); template inline const Mat& operator+=(const Op& X); template inline const Mat& operator-=(const Op& X); template inline const Mat& operator*=(const Op& X); template inline const Mat& operator%=(const Op& X); template inline const Mat& operator/=(const Op& X); template inline Mat(const eOp& X); template inline const Mat& operator=(const eOp& X); template inline const Mat& operator+=(const eOp& X); template inline const Mat& operator-=(const eOp& X); template inline const Mat& operator*=(const eOp& X); template inline const Mat& operator%=(const eOp& X); template inline const Mat& operator/=(const eOp& X); template inline Mat(const mtOp& X); template inline const Mat& operator=(const mtOp& X); template inline const Mat& operator+=(const mtOp& X); template inline const Mat& operator-=(const mtOp& X); template inline const Mat& operator*=(const mtOp& X); template inline const Mat& operator%=(const mtOp& X); template inline const Mat& operator/=(const mtOp& X); template inline Mat(const Glue& X); template inline const Mat& operator=(const Glue& X); template inline const Mat& operator+=(const Glue& X); template inline const Mat& operator-=(const Glue& X); template inline const Mat& operator*=(const Glue& X); template inline const Mat& operator%=(const Glue& X); template inline const Mat& operator/=(const Glue& X); template inline const Mat& operator+=(const Glue& X); template inline const Mat& operator-=(const Glue& X); template inline Mat(const eGlue& X); template inline const Mat& operator=(const eGlue& X); template inline const Mat& operator+=(const eGlue& X); template inline const Mat& operator-=(const eGlue& X); template inline const Mat& operator*=(const eGlue& X); template inline const Mat& operator%=(const eGlue& X); template inline const Mat& operator/=(const eGlue& X); template inline Mat(const mtGlue& X); template inline const Mat& operator=(const mtGlue& X); template inline const Mat& operator+=(const mtGlue& X); template inline const Mat& operator-=(const mtGlue& X); template inline const Mat& operator*=(const mtGlue& X); template inline const Mat& operator%=(const mtGlue& X); template inline const Mat& operator/=(const mtGlue& X); arma_inline arma_warn_unused const eT& at_alt (const uword ii) const; arma_inline arma_warn_unused eT& operator[] (const uword ii); arma_inline arma_warn_unused const eT& operator[] (const uword ii) const; arma_inline arma_warn_unused eT& at (const uword ii); arma_inline arma_warn_unused const eT& at (const uword ii) const; arma_inline arma_warn_unused eT& operator() (const uword ii); arma_inline arma_warn_unused const eT& operator() (const uword ii) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; arma_inline const Mat& operator++(); arma_inline void operator++(int); arma_inline const Mat& operator--(); arma_inline void operator--(int); arma_inline arma_warn_unused bool is_empty() const; arma_inline arma_warn_unused bool is_vec() const; arma_inline arma_warn_unused bool is_rowvec() const; arma_inline arma_warn_unused bool is_colvec() const; arma_inline arma_warn_unused bool is_square() const; inline arma_warn_unused bool is_finite() const; inline arma_warn_unused bool has_inf() const; inline arma_warn_unused bool has_nan() const; inline arma_warn_unused bool is_sorted(const char* direction = "ascend") const; inline arma_warn_unused bool is_sorted(const char* direction, const uword dim) const; arma_inline arma_warn_unused bool in_range(const uword ii) const; arma_inline arma_warn_unused bool in_range(const span& x ) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const SizeMat& s) const; arma_inline arma_warn_unused eT* colptr(const uword in_col); arma_inline arma_warn_unused const eT* colptr(const uword in_col) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; inline void impl_print( const std::string& extra_text) const; inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_raw_print( const std::string& extra_text) const; inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const; template inline void copy_size(const Base& X); inline void set_size(const uword in_elem); inline void set_size(const uword in_rows, const uword in_cols); inline void set_size(const SizeMat& s); inline void resize(const uword in_elem); inline void resize(const uword in_rows, const uword in_cols); inline void resize(const SizeMat& s); inline void reshape(const uword in_rows, const uword in_cols); inline void reshape(const SizeMat& s); arma_deprecated inline void reshape(const uword in_rows, const uword in_cols, const uword dim); //!< NOTE: don't use this form: it's deprecated template inline const Mat& for_each(functor F); template inline const Mat& for_each(functor F) const; template inline const Mat& transform(functor F); template inline const Mat& imbue(functor F); arma_hot inline const Mat& fill(const eT val); template arma_hot inline const Mat& fill(const fill::fill_class& f); inline const Mat& zeros(); inline const Mat& zeros(const uword in_elem); inline const Mat& zeros(const uword in_rows, const uword in_cols); inline const Mat& zeros(const SizeMat& s); inline const Mat& ones(); inline const Mat& ones(const uword in_elem); inline const Mat& ones(const uword in_rows, const uword in_cols); inline const Mat& ones(const SizeMat& s); inline const Mat& randu(); inline const Mat& randu(const uword in_elem); inline const Mat& randu(const uword in_rows, const uword in_cols); inline const Mat& randu(const SizeMat& s); inline const Mat& randn(); inline const Mat& randn(const uword in_elem); inline const Mat& randn(const uword in_rows, const uword in_cols); inline const Mat& randn(const SizeMat& s); inline const Mat& eye(); inline const Mat& eye(const uword in_rows, const uword in_cols); inline const Mat& eye(const SizeMat& s); inline void reset(); template inline void set_real(const Base& X); template inline void set_imag(const Base& X); inline arma_warn_unused eT min() const; inline arma_warn_unused eT max() const; inline eT min(uword& index_of_min_val) const; inline eT max(uword& index_of_max_val) const; inline eT min(uword& row_of_min_val, uword& col_of_min_val) const; inline eT max(uword& row_of_max_val, uword& col_of_max_val) const; inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const; inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const; inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true); inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true); inline bool quiet_save(const std::string name, const file_type type = arma_binary) const; inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const; inline bool quiet_load(const std::string name, const file_type type = auto_detect); inline bool quiet_load( std::istream& is, const file_type type = auto_detect); // for container-like functionality typedef eT value_type; typedef uword size_type; typedef eT* iterator; typedef const eT* const_iterator; typedef eT* col_iterator; typedef const eT* const_col_iterator; class row_iterator { public: inline row_iterator(Mat& in_M, const uword in_row); inline eT& operator* (); inline row_iterator& operator++(); inline void operator++(int); inline row_iterator& operator--(); inline void operator--(int); inline bool operator!=(const row_iterator& X) const; inline bool operator==(const row_iterator& X) const; arma_aligned Mat& M; arma_aligned uword row; arma_aligned uword col; }; class const_row_iterator { public: const_row_iterator(const Mat& in_M, const uword in_row); const_row_iterator(const row_iterator& X); inline eT operator*() const; inline const_row_iterator& operator++(); inline void operator++(int); inline const_row_iterator& operator--(); inline void operator--(int); inline bool operator!=(const const_row_iterator& X) const; inline bool operator==(const const_row_iterator& X) const; arma_aligned const Mat& M; arma_aligned uword row; arma_aligned uword col; }; class const_row_col_iterator; class row_col_iterator { public: inline row_col_iterator(); inline row_col_iterator(const row_col_iterator& in_it); inline row_col_iterator(Mat& in_M, const uword row = 0, const uword col = 0); inline arma_hot eT& operator*(); inline arma_hot row_col_iterator& operator++(); inline arma_hot row_col_iterator operator++(int); inline arma_hot row_col_iterator& operator--(); inline arma_hot row_col_iterator operator--(int); inline uword row() const; inline uword col() const; inline arma_hot bool operator==(const row_col_iterator& rhs) const; inline arma_hot bool operator!=(const row_col_iterator& rhs) const; inline arma_hot bool operator==(const const_row_col_iterator& rhs) const; inline arma_hot bool operator!=(const const_row_col_iterator& rhs) const; // So that we satisfy the STL iterator types. typedef std::bidirectional_iterator_tag iterator_category; typedef eT value_type; typedef uword difference_type; // not certain on this one typedef const eT* pointer; typedef const eT& reference; arma_aligned Mat* M; arma_aligned eT* current_pos; arma_aligned uword internal_col; arma_aligned uword internal_row; }; class const_row_col_iterator { public: inline const_row_col_iterator(); inline const_row_col_iterator(const row_col_iterator& in_it); inline const_row_col_iterator(const const_row_col_iterator& in_it); inline const_row_col_iterator(const Mat& in_M, const uword row = 0, const uword col = 0); inline arma_hot const eT& operator*() const; inline arma_hot const_row_col_iterator& operator++(); inline arma_hot const_row_col_iterator operator++(int); inline arma_hot const_row_col_iterator& operator--(); inline arma_hot const_row_col_iterator operator--(int); inline uword row() const; inline uword col() const; inline arma_hot bool operator==(const const_row_col_iterator& rhs) const; inline arma_hot bool operator!=(const const_row_col_iterator& rhs) const; inline arma_hot bool operator==(const row_col_iterator& rhs) const; inline arma_hot bool operator!=(const row_col_iterator& rhs) const; // So that we satisfy the STL iterator types. typedef std::bidirectional_iterator_tag iterator_category; typedef eT value_type; typedef uword difference_type; // not certain on this one typedef const eT* pointer; typedef const eT& reference; arma_aligned const Mat* M; arma_aligned const eT* current_pos; arma_aligned uword internal_col; arma_aligned uword internal_row; }; inline iterator begin(); inline const_iterator begin() const; inline const_iterator cbegin() const; inline iterator end(); inline const_iterator end() const; inline const_iterator cend() const; inline col_iterator begin_col(const uword col_num); inline const_col_iterator begin_col(const uword col_num) const; inline col_iterator end_col (const uword col_num); inline const_col_iterator end_col (const uword col_num) const; inline row_iterator begin_row(const uword row_num); inline const_row_iterator begin_row(const uword row_num) const; inline row_iterator end_row (const uword row_num); inline const_row_iterator end_row (const uword row_num) const; inline row_col_iterator begin_row_col(); inline const_row_col_iterator begin_row_col() const; inline row_col_iterator end_row_col(); inline const_row_col_iterator end_row_col() const; inline void clear(); inline bool empty() const; inline uword size() const; inline void swap(Mat& B); inline void steal_mem(Mat& X); //!< don't use this unless you're writing code internal to Armadillo inline void steal_mem_col(Mat& X, const uword max_n_rows); template class fixed; protected: inline void init_cold(); inline void init_warm(uword in_rows, uword in_cols); inline void init(const std::string& text); #if defined(ARMA_USE_CXX11) inline void init(const std::initializer_list& list); inline void init(const std::initializer_list< std::initializer_list >& list); #endif template inline void init(const Base& A, const Base& B); inline Mat(const char junk, const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols); inline Mat(const arma_vec_indicator&, const uhword in_vec_state); inline Mat(const arma_vec_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state); inline Mat(const arma_fixed_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state, const eT* in_mem); friend class Cube; friend class subview_cube; friend class glue_join; friend class op_strans; friend class op_htrans; friend class op_resize; public: #ifdef ARMA_EXTRA_MAT_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_PROTO) #endif }; template template class Mat::fixed : public Mat { private: static const uword fixed_n_elem = fixed_n_rows * fixed_n_cols; static const bool use_extra = (fixed_n_elem > arma_config::mat_prealloc); arma_align_mem eT mem_local_extra[ (use_extra) ? fixed_n_elem : 1 ]; public: typedef fixed Mat_fixed_type; typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_col = (fixed_n_cols == 1) ? true : false; static const bool is_row = (fixed_n_rows == 1) ? true : false; static const uword n_rows = fixed_n_rows; static const uword n_cols = fixed_n_cols; static const uword n_elem = fixed_n_elem; arma_inline fixed(); arma_inline fixed(const fixed& X); template inline fixed(const fill::fill_class& f); template inline fixed(const Base& A); template inline fixed(const Base& A, const Base& B); inline fixed(const eT* aux_mem); inline fixed(const char* text); inline fixed(const std::string& text); using Mat::operator=; using Mat::operator(); #if defined(ARMA_USE_CXX11) inline fixed(const std::initializer_list& list); inline const Mat& operator=(const std::initializer_list& list); inline fixed(const std::initializer_list< std::initializer_list >& list); inline const Mat& operator=(const std::initializer_list< std::initializer_list >& list); #endif arma_inline const Mat& operator=(const fixed& X); #if defined(ARMA_GOOD_COMPILER) template inline const Mat& operator=(const eOp& X); template inline const Mat& operator=(const eGlue& X); #endif arma_inline const Op< Mat_fixed_type, op_htrans > t() const; arma_inline const Op< Mat_fixed_type, op_htrans > ht() const; arma_inline const Op< Mat_fixed_type, op_strans > st() const; arma_inline arma_warn_unused const eT& at_alt (const uword i) const; arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at (const uword i); arma_inline arma_warn_unused const eT& at (const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col) const; arma_inline arma_warn_unused eT* colptr(const uword in_col); arma_inline arma_warn_unused const eT* colptr(const uword in_col) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; arma_inline arma_warn_unused bool is_vec() const; arma_hot inline const Mat& fill(const eT val); arma_hot inline const Mat& zeros(); arma_hot inline const Mat& ones(); }; class Mat_aux { public: template arma_inline static void prefix_pp(Mat& x); template arma_inline static void prefix_pp(Mat< std::complex >& x); template arma_inline static void postfix_pp(Mat& x); template arma_inline static void postfix_pp(Mat< std::complex >& x); template arma_inline static void prefix_mm(Mat& x); template arma_inline static void prefix_mm(Mat< std::complex >& x); template arma_inline static void postfix_mm(Mat& x); template arma_inline static void postfix_mm(Mat< std::complex >& x); template inline static void set_real(Mat& out, const Base& X); template inline static void set_real(Mat< std::complex >& out, const Base< T,T1>& X); template inline static void set_imag(Mat& out, const Base& X); template inline static void set_imag(Mat< std::complex >& out, const Base< T,T1>& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/SpOp_bones.hpp0000666000000000000000000000323212620272703021526 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup SpOp //! @{ template class SpOp : public SpBase > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = (T1::is_row && is_spop_elem::value) || ( T1::is_col && (is_same_type::value || is_same_type::value) ); static const bool is_col = (T1::is_col && is_spop_elem::value) || ( T1::is_row && (is_same_type::value || is_same_type::value) ); inline explicit SpOp(const T1& in_m); inline SpOp(const T1& in_m, const elem_type in_aux); inline SpOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline ~SpOp(); arma_aligned const T1& m; //!< storage of reference to the operand (eg. a matrix) arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format }; //! @} armadillo-6.500.5/include/armadillo_bits/arrayops_meat.hpp0000666000000000000000000004233212650172354022335 0ustar rootroot// Copyright (C) 2011-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arrayops //! @{ template arma_hot arma_inline void arrayops::copy(eT* dest, const eT* src, const uword n_elem) { if( (n_elem <= 16) && (is_cx::no) ) { arrayops::copy_small(dest, src, n_elem); } else { std::memcpy(dest, src, n_elem*sizeof(eT)); } } template arma_hot inline void arrayops::copy_small(eT* dest, const eT* src, const uword n_elem) { switch(n_elem) { case 16: dest[15] = src[15]; case 15: dest[14] = src[14]; case 14: dest[13] = src[13]; case 13: dest[12] = src[12]; case 12: dest[11] = src[11]; case 11: dest[10] = src[10]; case 10: dest[ 9] = src[ 9]; case 9: dest[ 8] = src[ 8]; case 8: dest[ 7] = src[ 7]; case 7: dest[ 6] = src[ 6]; case 6: dest[ 5] = src[ 5]; case 5: dest[ 4] = src[ 4]; case 4: dest[ 3] = src[ 3]; case 3: dest[ 2] = src[ 2]; case 2: dest[ 1] = src[ 1]; case 1: dest[ 0] = src[ 0]; default: ; } } template arma_hot inline void arrayops::copy_forwards(eT* dest, const eT* src, const uword n_elem) { // can't use std::memcpy(), as we don't know how it copies data uword j; for(j=1; j < n_elem; j+=2) { const eT tmp_i = (*src); src++; const eT tmp_j = (*src); src++; (*dest) = tmp_i; dest++; (*dest) = tmp_j; dest++; } if((j-1) < n_elem) { (*dest) = (*src); } } template arma_hot inline void arrayops::copy_backwards(eT* dest, const eT* src, const uword n_elem) { // can't use std::memcpy(), as we don't know how it copies data // for(uword i=0; i < n_elem; ++i) // { // const uword j = n_elem-i-1; // // dest[j] = src[j]; // } if(n_elem > 0) { eT* dest_it = &(dest[n_elem-1]); const eT* src_it = &( src[n_elem-1]); uword j; for(j=1; j < n_elem; j+=2) { const eT tmp_i = (*src_it); src_it--; const eT tmp_j = (*src_it); src_it--; (*dest_it) = tmp_i; dest_it--; (*dest_it) = tmp_j; dest_it--; } if((j-1) < n_elem) { (*dest_it) = (*src_it); } } } template arma_hot inline void arrayops::fill_zeros(eT* dest, const uword n_elem) { arrayops::inplace_set(dest, eT(0), n_elem); } template arma_hot arma_inline void arrayops::convert_cx_scalar ( out_eT& out, const in_eT& in, const typename arma_not_cx::result* junk1, const typename arma_not_cx< in_eT>::result* junk2 ) { arma_ignore(junk1); arma_ignore(junk2); out = out_eT(in); } template arma_hot arma_inline void arrayops::convert_cx_scalar ( out_eT& out, const std::complex& in, const typename arma_not_cx::result* junk ) { arma_ignore(junk); out = out_eT( in.real() ); } template arma_hot arma_inline void arrayops::convert_cx_scalar ( std::complex& out, const std::complex< in_T>& in ) { typedef std::complex out_eT; out = out_eT(in); } template arma_hot inline void arrayops::convert(out_eT* dest, const in_eT* src, const uword n_elem) { if(is_same_type::value) { const out_eT* src2 = (const out_eT*)src; if(dest != src2) { arrayops::copy(dest, src2, n_elem); } return; } uword j; for(j=1; j::value) ? out_eT( tmp_i ) : ( cond_rel< is_signed::value >::lt(tmp_i, in_eT(0)) ? out_eT(0) : out_eT(tmp_i) ); dest++; (*dest) = (is_signed::value) ? out_eT( tmp_j ) : ( cond_rel< is_signed::value >::lt(tmp_j, in_eT(0)) ? out_eT(0) : out_eT(tmp_j) ); dest++; } if((j-1) < n_elem) { const in_eT tmp_i = (*src); // dest[i] = out_eT( tmp_i ); (*dest) = (is_signed::value) ? out_eT( tmp_i ) : ( cond_rel< is_signed::value >::lt(tmp_i, in_eT(0)) ? out_eT(0) : out_eT(tmp_i) ); } } template arma_hot inline void arrayops::convert_cx(out_eT* dest, const in_eT* src, const uword n_elem) { uword j; for(j=1; j arma_hot inline void arrayops::inplace_plus(eT* dest, const eT* src, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_plus_base(dest, src, n_elem); } else { arrayops::inplace_plus_base(dest, src, n_elem); } } else { if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_plus_base(dest, src, n_elem); } else { arrayops::inplace_plus_base(dest, src, n_elem); } } } template arma_hot inline void arrayops::inplace_minus(eT* dest, const eT* src, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_minus_base(dest, src, n_elem); } else { arrayops::inplace_minus_base(dest, src, n_elem); } } else { if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_minus_base(dest, src, n_elem); } else { arrayops::inplace_minus_base(dest, src, n_elem); } } } template arma_hot inline void arrayops::inplace_mul(eT* dest, const eT* src, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_mul_base(dest, src, n_elem); } else { arrayops::inplace_mul_base(dest, src, n_elem); } } else { if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_mul_base(dest, src, n_elem); } else { arrayops::inplace_mul_base(dest, src, n_elem); } } } template arma_hot inline void arrayops::inplace_div(eT* dest, const eT* src, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_div_base(dest, src, n_elem); } else { arrayops::inplace_div_base(dest, src, n_elem); } } else { if(memory::is_aligned(src)) { memory::mark_as_aligned(src); arrayops::inplace_div_base(dest, src, n_elem); } else { arrayops::inplace_div_base(dest, src, n_elem); } } } template arma_hot inline void arrayops::inplace_plus_base(eT* dest, const eT* src, const uword n_elem) { #if defined(ARMA_SIMPLE_LOOPS) { for(uword i=0; i arma_hot inline void arrayops::inplace_minus_base(eT* dest, const eT* src, const uword n_elem) { #if defined(ARMA_SIMPLE_LOOPS) { for(uword i=0; i arma_hot inline void arrayops::inplace_mul_base(eT* dest, const eT* src, const uword n_elem) { #if defined(ARMA_SIMPLE_LOOPS) { for(uword i=0; i arma_hot inline void arrayops::inplace_div_base(eT* dest, const eT* src, const uword n_elem) { #if defined(ARMA_SIMPLE_LOOPS) { for(uword i=0; i arma_hot inline void arrayops::inplace_set(eT* dest, const eT val, const uword n_elem) { typedef typename get_pod_type::result pod_type; if( (n_elem <= 16) && (is_cx::no) ) { arrayops::inplace_set_small(dest, val, n_elem); } else { if( (val == eT(0)) && (std::numeric_limits::is_integer || (std::numeric_limits::is_iec559 && is_real::value)) ) { std::memset(dest, 0, sizeof(eT)*n_elem); } else { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); arrayops::inplace_set_base(dest, val, n_elem); } else { arrayops::inplace_set_base(dest, val, n_elem); } } } } template arma_hot inline void arrayops::inplace_set_base(eT* dest, const eT val, const uword n_elem) { #if defined(ARMA_SIMPLE_LOOPS) { for(uword i=0; i arma_hot inline void arrayops::inplace_set_small(eT* dest, const eT val, const uword n_elem) { switch(n_elem) { case 16: dest[15] = val; case 15: dest[14] = val; case 14: dest[13] = val; case 13: dest[12] = val; case 12: dest[11] = val; case 11: dest[10] = val; case 10: dest[ 9] = val; case 9: dest[ 8] = val; case 8: dest[ 7] = val; case 7: dest[ 6] = val; case 6: dest[ 5] = val; case 5: dest[ 4] = val; case 4: dest[ 3] = val; case 3: dest[ 2] = val; case 2: dest[ 1] = val; case 1: dest[ 0] = val; default:; } } template arma_hot inline void arrayops::inplace_set_fixed(eT* dest, const eT val) { for(uword i=0; i arma_hot inline void arrayops::inplace_plus(eT* dest, const eT val, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); arrayops::inplace_plus_base(dest, val, n_elem); } else { arrayops::inplace_plus_base(dest, val, n_elem); } } template arma_hot inline void arrayops::inplace_minus(eT* dest, const eT val, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); arrayops::inplace_minus_base(dest, val, n_elem); } else { arrayops::inplace_minus_base(dest, val, n_elem); } } template arma_hot inline void arrayops::inplace_mul(eT* dest, const eT val, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); arrayops::inplace_mul_base(dest, val, n_elem); } else { arrayops::inplace_mul_base(dest, val, n_elem); } } template arma_hot inline void arrayops::inplace_div(eT* dest, const eT val, const uword n_elem) { if(memory::is_aligned(dest)) { memory::mark_as_aligned(dest); arrayops::inplace_div_base(dest, val, n_elem); } else { arrayops::inplace_div_base(dest, val, n_elem); } } template arma_hot inline void arrayops::inplace_plus_base(eT* dest, const eT val, const uword n_elem) { #if defined(ARMA_SIMPLE_LOOPS) { for(uword i=0; i arma_hot inline void arrayops::inplace_minus_base(eT* dest, const eT val, const uword n_elem) { #if defined(ARMA_SIMPLE_LOOPS) { for(uword i=0; i arma_hot inline void arrayops::inplace_mul_base(eT* dest, const eT val, const uword n_elem) { #if defined(ARMA_SIMPLE_LOOPS) { for(uword i=0; i arma_hot inline void arrayops::inplace_div_base(eT* dest, const eT val, const uword n_elem) { #if defined(ARMA_SIMPLE_LOOPS) { for(uword i=0; i arma_hot inline eT arrayops::accumulate(const eT* src, const uword n_elem) { #if defined(__FINITE_MATH_ONLY__) && (__FINITE_MATH_ONLY__ > 0) { eT acc = eT(0); if(memory::is_aligned(src)) { memory::mark_as_aligned(src); for(uword i=0; i arma_hot inline eT arrayops::product(const eT* src, const uword n_elem) { eT val1 = eT(1); eT val2 = eT(1); uword i,j; for(i=0, j=1; j arma_hot inline bool arrayops::is_finite(const eT* src, const uword n_elem) { uword j; for(j=1; j arma_hot inline bool arrayops::has_inf(const eT* src, const uword n_elem) { uword j; for(j=1; j arma_hot inline bool arrayops::has_nan(const eT* src, const uword n_elem) { uword j; for(j=1; j struct SpBase_eval_SpMat { inline const derived& eval() const; }; template struct SpBase_eval_expr { inline SpMat eval() const; //!< force the immediate evaluation of a delayed expression }; template struct SpBase_eval {}; template struct SpBase_eval { typedef SpBase_eval_SpMat result; }; template struct SpBase_eval { typedef SpBase_eval_expr result; }; template struct SpBase : public SpBase_eval::value>::result { arma_inline const derived& get_ref() const; inline const SpOp t() const; //!< Hermitian transpose inline const SpOp ht() const; //!< Hermitian transpose inline const SpOp st() const; //!< simple transpose inline void print( const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const; inline void raw_print( const std::string extra_text = "") const; inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const; inline void print_dense( const std::string extra_text = "") const; inline void print_dense(std::ostream& user_stream, const std::string extra_text = "") const; inline void raw_print_dense( const std::string extra_text = "") const; inline void raw_print_dense(std::ostream& user_stream, const std::string extra_text = "") const; inline arma_warn_unused elem_type min() const; inline arma_warn_unused elem_type max() const; inline elem_type min(uword& index_of_min_val) const; inline elem_type max(uword& index_of_max_val) const; inline elem_type min(uword& row_of_min_val, uword& col_of_min_val) const; inline elem_type max(uword& row_of_max_val, uword& col_of_max_val) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_eig_pair.hpp0000666000000000000000000000511412650152164021723 0ustar rootroot// Copyright (C) 2015-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_eig_pair //! @{ template inline typename enable_if2< is_supported_blas_type::value, Col< std::complex > >::result eig_pair ( const Base& A_expr, const Base& B_expr ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; Col< std::complex > eigvals; Mat< std::complex > eigvecs; const bool status = auxlib::eig_pair(eigvals, eigvecs, false, A_expr.get_ref(), B_expr.get_ref()); if(status == false) { eigvals.reset(); arma_bad("eig_pair(): decomposition failed"); } return eigvals; } template inline typename enable_if2< is_supported_blas_type::value, bool >::result eig_pair ( Col< std::complex >& eigvals, const Base< typename T1::elem_type, T1 >& A_expr, const Base< typename T1::elem_type, T2 >& B_expr ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; Mat< std::complex > eigvecs; const bool status = auxlib::eig_pair(eigvals, eigvecs, false, A_expr.get_ref(), B_expr.get_ref()); if(status == false) { eigvals.reset(); arma_debug_warn("eig_pair(): decomposition failed"); } return status; } template inline typename enable_if2< is_supported_blas_type::value, bool >::result eig_pair ( Col< std::complex >& eigvals, Mat< std::complex >& eigvecs, const Base< typename T1::elem_type, T1 >& A_expr, const Base< typename T1::elem_type, T2 >& B_expr ) { arma_extra_debug_sigprint(); arma_debug_check( (void_ptr(&eigvals) == void_ptr(&eigvecs)), "eig_pair(): parameter 'eigval' is an alias of parameter 'eigvec'" ); const bool status = auxlib::eig_pair(eigvals, eigvecs, true, A_expr.get_ref(), B_expr.get_ref()); if(status == false) { eigvals.reset(); eigvecs.reset(); arma_debug_warn("eig_pair(): decomposition failed"); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_fft.hpp0000666000000000000000000000445112620272703020725 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_fft //! @{ // 1D FFT & 1D IFFT template inline typename enable_if2 < (is_arma_type::value && is_real::value), const mtOp, T1, op_fft_real> >::result fft(const T1& A) { arma_extra_debug_sigprint(); return mtOp, T1, op_fft_real>(A, uword(0), uword(1)); } template inline typename enable_if2 < (is_arma_type::value && is_real::value), const mtOp, T1, op_fft_real> >::result fft(const T1& A, const uword N) { arma_extra_debug_sigprint(); return mtOp, T1, op_fft_real>(A, N, uword(0)); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), const Op >::result fft(const T1& A) { arma_extra_debug_sigprint(); return Op(A, uword(0), uword(1)); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), const Op >::result fft(const T1& A, const uword N) { arma_extra_debug_sigprint(); return Op(A, N, uword(0)); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), const Op >::result ifft(const T1& A) { arma_extra_debug_sigprint(); return Op(A, uword(0), uword(1)); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), const Op >::result ifft(const T1& A, const uword N) { arma_extra_debug_sigprint(); return Op(A, N, uword(0)); } //! @} armadillo-6.500.5/include/armadillo_bits/op_nonzeros_bones.hpp0000666000000000000000000000163012620272703023220 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_nonzeros //! @{ class op_nonzeros { public: // for dense matrices template static inline void apply_noalias(Mat& out, const Proxy& P); template static inline void apply(Mat& out, const Op& X); // for sparse matrices template static inline void apply_noalias(Mat& out, const SpBase& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/gmm_misc_meat.hpp0000666000000000000000000001055312646454123022272 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup gmm_diag //! @{ namespace gmm_priv { template inline running_mean_scalar::running_mean_scalar() : counter(uword(0)) , r_mean ( eT(0)) { arma_extra_debug_sigprint_this(this); } template inline running_mean_scalar::running_mean_scalar(const running_mean_scalar& in) : counter(in.counter) , r_mean (in.r_mean ) { arma_extra_debug_sigprint_this(this); } template inline const running_mean_scalar& running_mean_scalar::operator=(const running_mean_scalar& in) { arma_extra_debug_sigprint(); counter = in.counter; r_mean = in.r_mean; return *this; } template arma_hot inline void running_mean_scalar::operator() (const eT X) { arma_extra_debug_sigprint(); counter++; if(counter > 1) { const eT old_r_mean = r_mean; r_mean = old_r_mean + (X - old_r_mean)/counter; } else { r_mean = X; } } template inline void running_mean_scalar::reset() { arma_extra_debug_sigprint(); counter = 0; r_mean = eT(0); } template inline uword running_mean_scalar::count() const { return counter; } template inline eT running_mean_scalar::mean() const { return r_mean; } // // // template inline running_mean_vec::running_mean_vec() : last_i (0) , counter(0) { arma_extra_debug_sigprint_this(this); } template inline running_mean_vec::running_mean_vec(const running_mean_vec& in) : last_i (in.last_i ) , counter(in.counter) , r_mean (in.r_mean ) { arma_extra_debug_sigprint_this(this); } template inline const running_mean_vec& running_mean_vec::operator=(const running_mean_vec& in) { arma_extra_debug_sigprint(); last_i = in.last_i; counter = in.counter; r_mean = in.r_mean; return *this; } template arma_hot inline void running_mean_vec::operator() (const Col& X, const uword index) { arma_extra_debug_sigprint(); last_i = index; counter++; if(counter > 1) { const uword n_elem = r_mean.n_elem; eT* r_mean_mem = r_mean.memptr(); const eT* X_mem = X.memptr(); for(uword i=0; i inline void running_mean_vec::reset() { arma_extra_debug_sigprint(); last_i = 0; counter = 0; r_mean.reset(); } template inline uword running_mean_vec::last_index() const { return last_i; } template inline uword running_mean_vec::count() const { return counter; } template inline const Col& running_mean_vec::mean() const { return r_mean; } // // // template arma_inline arma_hot eT distance::eval(const uword N, const eT* A, const eT* B, const eT*) { eT acc1 = eT(0); eT acc2 = eT(0); uword i,j; for(i=0, j=1; j arma_inline arma_hot eT distance::eval(const uword N, const eT* A, const eT* B, const eT* C) { eT acc1 = eT(0); eT acc2 = eT(0); uword i,j; for(i=0, j=1; j inline hid_t get_hdf5_type() { return -1; // Return invalid. } //! Specializations for each valid element type //! (taken from all the possible typedefs of {u8, s8, ..., u64, s64} and the other native types. //! We can't use the actual u8/s8 typedefs because their relations to the H5T_... types are unclear. template<> inline hid_t get_hdf5_type< unsigned char >() { return arma_H5Tcopy(arma_H5T_NATIVE_UCHAR); } template<> inline hid_t get_hdf5_type< char >() { return arma_H5Tcopy(arma_H5T_NATIVE_CHAR); } template<> inline hid_t get_hdf5_type< short >() { return arma_H5Tcopy(arma_H5T_NATIVE_SHORT); } template<> inline hid_t get_hdf5_type< unsigned short >() { return arma_H5Tcopy(arma_H5T_NATIVE_USHORT); } template<> inline hid_t get_hdf5_type< int >() { return arma_H5Tcopy(arma_H5T_NATIVE_INT); } template<> inline hid_t get_hdf5_type< unsigned int >() { return arma_H5Tcopy(arma_H5T_NATIVE_UINT); } template<> inline hid_t get_hdf5_type< long >() { return arma_H5Tcopy(arma_H5T_NATIVE_LONG); } template<> inline hid_t get_hdf5_type< unsigned long >() { return arma_H5Tcopy(arma_H5T_NATIVE_ULONG); } #if defined(ARMA_USE_U64S64) && defined(ULLONG_MAX) template<> inline hid_t get_hdf5_type< long long >() { return arma_H5Tcopy(arma_H5T_NATIVE_LLONG); } template<> inline hid_t get_hdf5_type< unsigned long long >() { return arma_H5Tcopy(arma_H5T_NATIVE_ULLONG); } #endif template<> inline hid_t get_hdf5_type< float >() { return arma_H5Tcopy(arma_H5T_NATIVE_FLOAT); } template<> inline hid_t get_hdf5_type< double >() { return arma_H5Tcopy(arma_H5T_NATIVE_DOUBLE); } //! Utility hid_t since HOFFSET() won't work with std::complex. template struct hdf5_complex_t { eT real; eT imag; }; template<> inline hid_t get_hdf5_type< std::complex >() { hid_t type = arma_H5Tcreate(H5T_COMPOUND, sizeof(hdf5_complex_t)); arma_H5Tinsert(type, "real", HOFFSET(hdf5_complex_t, real), arma_H5T_NATIVE_FLOAT); arma_H5Tinsert(type, "imag", HOFFSET(hdf5_complex_t, imag), arma_H5T_NATIVE_FLOAT); return type; } template<> inline hid_t get_hdf5_type< std::complex >() { hid_t type = arma_H5Tcreate(H5T_COMPOUND, sizeof(hdf5_complex_t)); arma_H5Tinsert(type, "real", HOFFSET(hdf5_complex_t, real), arma_H5T_NATIVE_DOUBLE); arma_H5Tinsert(type, "imag", HOFFSET(hdf5_complex_t, imag), arma_H5T_NATIVE_DOUBLE); return type; } // Compare datatype against all supported types. inline bool is_supported_arma_hdf5_type(hid_t datatype) { hid_t search_type; bool is_equal; // start with most likely used types: double, complex, float, complex search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type< std::complex >(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type< std::complex >(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } // remaining supported types: u8, s8, u16, s16, u32, s32, u64, s64, ulng_t, slng_t search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } #if defined(ARMA_USE_U64S64) { search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } } #endif #if defined(ARMA_ALLOW_LONG) { search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } search_type = get_hdf5_type(); is_equal = ( arma_H5Tequal(datatype, search_type) > 0 ); arma_H5Tclose(search_type); if (is_equal) { return true; } } #endif return false; } //! Auxiliary functions and structs for search_hdf5_file. struct hdf5_search_info { const std::vector& names; int num_dims; bool exact; hid_t best_match; size_t best_match_position; // Position of best match in names vector. }; inline herr_t hdf5_search_callback ( hid_t loc_id, const char* name, const H5O_info_t* info, void* operator_data // hdf5_search_info ) { hdf5_search_info* search_info = (hdf5_search_info*) operator_data; // We are looking for datasets. if (info->type == H5O_TYPE_DATASET) { // Check type of dataset to see if we could even load it. hid_t dataset = arma_H5Dopen(loc_id, name, H5P_DEFAULT); hid_t datatype = arma_H5Dget_type(dataset); const bool is_supported = is_supported_arma_hdf5_type(datatype); arma_H5Tclose(datatype); arma_H5Dclose(dataset); if(is_supported == false) { // Forget about it and move on. return 0; } // Now we have to check against our set of names. // Only check names which could be better. for (size_t string_pos = 0; string_pos < search_info->best_match_position; ++string_pos) { // name is the full path (/path/to/dataset); names[string_pos] may be // "dataset", "/to/dataset", or "/path/to/dataset". // So if we count the number of forward slashes in names[string_pos], // and then simply take the last substring of name containing that number of slashes, // we can do the comparison. // Count the number of forward slashes in names[string_pos]. uword count = 0; for (uword i = 0; i < search_info->names[string_pos].length(); ++i) { if ((search_info->names[string_pos])[i] == '/') { ++count; } } // Count the number of forward slashes in the full name. uword name_count = 0; const std::string str = std::string(name); for (uword i = 0; i < str.length(); ++i) { if (str[i] == '/') { ++count; } } // If we are asking for more slashes than we have, this can't be a match. // Skip to below, where we decide whether or not to keep it anyway based // on the exactness condition of the search. if (count <= name_count) { size_t start_pos = (count == 0) ? 0 : std::string::npos; while (count > 0) { // Move pointer to previous slash. start_pos = str.rfind('/', start_pos); // Break if we've run out of slashes. if (start_pos == std::string::npos) { break; } --count; } // Now take the substring (this may end up being the full string). const std::string substring = str.substr(start_pos); // Are they the same? if (substring == search_info->names[string_pos]) { // We have found the object; it must be better than our existing match. hid_t match_candidate = arma_H5Dopen(loc_id, name, H5P_DEFAULT); // arma_check(match_candidate < 0, "Mat::load(): cannot open an HDF5 dataset"); if(match_candidate < 0) { return -1; } // Ensure that the dataset is valid and of the correct dimensionality. hid_t filespace = arma_H5Dget_space(match_candidate); int num_dims = arma_H5Sget_simple_extent_ndims(filespace); if (num_dims <= search_info->num_dims) { // Valid dataset -- we'll keep it. // If we already have an existing match we have to close it. if (search_info->best_match != -1) { arma_H5Dclose(search_info->best_match); } search_info->best_match_position = string_pos; search_info->best_match = match_candidate; } arma_H5Sclose(filespace); } } // If they are not the same, but we have not found anything and we don't need an exact match, take this. if ((search_info->exact == false) && (search_info->best_match == -1)) { hid_t match_candidate = arma_H5Dopen(loc_id, name, H5P_DEFAULT); // arma_check(match_candidate < 0, "Mat::load(): cannot open an HDF5 dataset"); if(match_candidate < 0) { return -1; } hid_t filespace = arma_H5Dget_space(match_candidate); int num_dims = arma_H5Sget_simple_extent_ndims(filespace); if (num_dims <= search_info->num_dims) { // Valid dataset -- we'll keep it. search_info->best_match = arma_H5Dopen(loc_id, name, H5P_DEFAULT); } arma_H5Sclose(filespace); } } } return 0; } //! Search an HDF5 file for the given dataset names. //! If 'exact' is true, failure to find a dataset in the list of names means that -1 is returned. //! If 'exact' is false and no datasets are found, -1 is returned. //! The number of dimensions is used to help prune down invalid datasets; //! 2 dimensions is a matrix, 1 dimension is a vector, and 3 dimensions is a cube. //! If the number of dimensions in a dataset is less than or equal to num_dims, //! it will be considered -- for instance, a one-dimensional HDF5 vector can be loaded as a single-column matrix. inline hid_t search_hdf5_file ( const std::vector& names, hid_t hdf5_file, int num_dims = 2, bool exact = false ) { hdf5_search_info search_info = { names, num_dims, exact, -1, names.size() }; // We'll use the H5Ovisit to track potential entries. herr_t status = arma_H5Ovisit(hdf5_file, H5_INDEX_NAME, H5_ITER_NATIVE, hdf5_search_callback, void_ptr(&search_info)); // Return the best match; it will be -1 if there was a problem. return (status < 0) ? -1 : search_info.best_match; } //! Load an HDF5 matrix into an array of type specified by datatype, //! then convert that into the desired array 'dest'. //! This should only be called when eT is not the datatype. template inline hid_t load_and_convert_hdf5 ( eT *dest, hid_t dataset, hid_t datatype, uword n_elem ) { // We can't use nice template specializations here // as the determination of the type of 'datatype' must be done at runtime. // So we end up with this ugliness... hid_t search_type; bool is_equal; // u8 search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // s8 search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // u16 search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // s16 search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // u32 search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // s32 search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } #if defined(ARMA_USE_U64S64) { // u64 search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // s64 search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } } #endif #if defined(ARMA_ALLOW_LONG) { // ulng_t search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // slng_t search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } } #endif // float search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // double search_type = get_hdf5_type(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { Col v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert(dest, v.memptr(), n_elem); return status; } // complex float search_type = get_hdf5_type< std::complex >(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { if(is_complex::value == false) { return -1; // can't read complex data into non-complex matrix/cube } Col< std::complex > v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert_cx(dest, v.memptr(), n_elem); return status; } // complex double search_type = get_hdf5_type< std::complex >(); is_equal = (arma_H5Tequal(datatype, search_type) > 0); arma_H5Tclose(search_type); if(is_equal) { if(is_complex::value == false) { return -1; // can't read complex data into non-complex matrix/cube } Col< std::complex > v(n_elem); hid_t status = arma_H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, void_ptr(v.memptr())); arrayops::convert_cx(dest, v.memptr(), n_elem); return status; } return -1; // Failure. } } // namespace hdf5_misc #endif // #if defined(ARMA_USE_HDF5) //! @} armadillo-6.500.5/include/armadillo_bits/BaseCube_bones.hpp0000666000000000000000000000337012620272703022321 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup BaseCube //! @{ template struct BaseCube_eval_Cube { arma_inline const derived& eval() const; }; template struct BaseCube_eval_expr { arma_inline Cube eval() const; //!< force the immediate evaluation of a delayed expression }; template struct BaseCube_eval {}; template struct BaseCube_eval { typedef BaseCube_eval_Cube result; }; template struct BaseCube_eval { typedef BaseCube_eval_expr result; }; //! Analog of the Base class, intended for cubes template struct BaseCube : public BaseCube_eval::value>::result { arma_inline const derived& get_ref() const; inline void print( const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const; inline void raw_print( const std::string extra_text = "") const; inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const; }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_accu.hpp0000666000000000000000000002452112650172354021065 0ustar rootroot// Copyright (C) 2008-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup fn_accu //! @{ template arma_hot inline typename T1::elem_type accu_proxy_linear(const Proxy& P) { typedef typename T1::elem_type eT; const uword n_elem = P.get_n_elem(); #if defined(__FINITE_MATH_ONLY__) && (__FINITE_MATH_ONLY__ > 0) { eT val = eT(0); if(P.is_aligned()) { typename Proxy::aligned_ea_type A = P.get_aligned_ea(); for(uword i=0; i::ea_type A = P.get_ea(); for(uword i=0; i::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { val1 += A[i]; val2 += A[j]; } if(i < n_elem) { val1 += A[i]; // equivalent to: val1 += A[n_elem-1]; } return (val1 + val2); } #endif } template arma_hot inline typename T1::elem_type accu_proxy_mat(const Proxy& P) { const quasi_unwrap::stored_type> tmp(P.Q); return arrayops::accumulate(tmp.M.memptr(), tmp.M.n_elem); } template arma_hot inline typename T1::elem_type accu_proxy_at(const Proxy& P) { typedef typename T1::elem_type eT; const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); eT val = eT(0); if(n_rows != 1) { eT val1 = eT(0); eT val2 = eT(0); for(uword col=0; col < n_cols; ++col) { uword i,j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { val1 += P.at(i,col); val2 += P.at(j,col); } if(i < n_rows) { val1 += P.at(i,col); } } val = val1 + val2; } else { for(uword col=0; col < n_cols; ++col) { val += P.at(0,col); } } return val; } //! accumulate the elements of a matrix template arma_hot arma_warn_unused inline typename enable_if2< is_arma_type::value, typename T1::elem_type >::result accu(const T1& X) { arma_extra_debug_sigprint(); const Proxy P(X); const bool have_direct_mem = (is_Mat::stored_type>::value) || (is_subview_col::stored_type>::value); return (Proxy::prefer_at_accessor) ? accu_proxy_at(P) : (have_direct_mem ? accu_proxy_mat(P) : accu_proxy_linear(P)); } //! explicit handling of multiply-and-accumulate template arma_warn_unused inline typename T1::elem_type accu(const eGlue& expr) { arma_extra_debug_sigprint(); typedef eGlue expr_type; typedef typename expr_type::proxy1_type::stored_type P1_stored_type; typedef typename expr_type::proxy2_type::stored_type P2_stored_type; const bool have_direct_mem_1 = (is_Mat::value) || (is_subview_col::value); const bool have_direct_mem_2 = (is_Mat::value) || (is_subview_col::value); if(have_direct_mem_1 && have_direct_mem_2) { const quasi_unwrap tmp1(expr.P1.Q); const quasi_unwrap tmp2(expr.P2.Q); return op_dot::direct_dot(tmp1.M.n_elem, tmp1.M.memptr(), tmp2.M.memptr()); } const Proxy P(expr); return (Proxy::prefer_at_accessor) ? accu_proxy_at(P) : accu_proxy_linear(P); } //! explicit handling of Hamming norm (also known as zero norm) template arma_warn_unused inline uword accu(const mtOp& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy P(X.m); uword n_nonzero = 0; if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); const uword n_elem = P.get_n_elem(); for(uword i=0; i arma_warn_unused inline uword accu(const mtOp& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy P(X.m); uword n_nonzero = 0; if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); const uword n_elem = P.get_n_elem(); for(uword i=0; i arma_hot arma_warn_unused inline eT accu(const subview& X) { arma_extra_debug_sigprint(); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; eT val = eT(0); if(X_n_rows == 1) { typedef subview_row sv_type; const sv_type& sv = reinterpret_cast(X); // subview_row is a child class of subview and has no extra data const Proxy P(sv); val = accu_proxy_linear(P); } else if(X_n_cols == 1) { val = arrayops::accumulate( X.colptr(0), X_n_rows ); } else { for(uword col=0; col < X_n_cols; ++col) { val += arrayops::accumulate( X.colptr(col), X_n_rows ); } } return val; } template arma_hot arma_warn_unused inline eT accu(const subview_col& X) { arma_extra_debug_sigprint(); return arrayops::accumulate( X.colptr(0), X.n_rows ); } template arma_hot inline typename T1::elem_type accu_cube_proxy(const ProxyCube& P) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename ProxyCube::ea_type ea_type; if(ProxyCube::prefer_at_accessor == false) { ea_type Pea = P.get_ea(); const uword n_elem = P.get_n_elem(); eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j arma_hot arma_warn_unused inline typename T1::elem_type accu(const BaseCube& X) { arma_extra_debug_sigprint(); const ProxyCube P(X.get_ref()); if(is_Cube::stored_type>::value) { unwrap_cube::stored_type> tmp(P.Q); return arrayops::accumulate(tmp.M.memptr(), tmp.M.n_elem); } return accu_cube_proxy(P); } //! explicit handling of multiply-and-accumulate (cube version) template arma_warn_unused inline typename T1::elem_type accu(const eGlueCube& expr) { arma_extra_debug_sigprint(); typedef eGlueCube expr_type; typedef typename ProxyCube::stored_type P1_stored_type; typedef typename ProxyCube::stored_type P2_stored_type; if(is_Cube::value && is_Cube::value) { const unwrap_cube tmp1(expr.P1.Q); const unwrap_cube tmp2(expr.P2.Q); return op_dot::direct_dot(tmp1.M.n_elem, tmp1.M.memptr(), tmp2.M.memptr()); } const ProxyCube P(expr); return accu_cube_proxy(P); } template arma_warn_unused inline const typename arma_scalar_only::result & accu(const T& x) { return x; } //! accumulate values in a sparse object template arma_hot arma_warn_unused inline typename enable_if2::value, typename T1::elem_type>::result accu(const T1& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy p(x); if(SpProxy::must_use_iterator == false) { // direct counting return arrayops::accumulate(p.get_values(), p.get_n_nonzero()); } else { typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); eT result = eT(0); while(it != it_end) { result += (*it); ++it; } return result; } } //! @} armadillo-6.500.5/include/armadillo_bits/running_stat_vec_bones.hpp0000666000000000000000000000746512620272703024231 0ustar rootroot// Copyright (C) 2009-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup running_stat_vec //! @{ template struct rsv_get_elem_type { }; template struct rsv_get_elem_type { typedef obj_type elem_type; }; template struct rsv_get_elem_type { typedef typename obj_type::elem_type elem_type; }; //! Class for keeping statistics of a continuously sampled process / signal. //! Useful if the storage of individual samples is not necessary or desired. //! Also useful if the number of samples is not known beforehand or exceeds //! available memory. template class running_stat_vec { public: // voodoo for compatibility with old user code typedef typename rsv_get_elem_type::value>::elem_type eT; typedef typename get_pod_type::result T; inline ~running_stat_vec(); inline running_stat_vec(const bool in_calc_cov = false); // TODO: investigate char* overload, eg. "calc_cov", "no_calc_cov" inline running_stat_vec(const running_stat_vec& in_rsv); inline const running_stat_vec& operator=(const running_stat_vec& in_rsv); template arma_hot inline void operator() (const Base< T, T1>& X); template arma_hot inline void operator() (const Base, T1>& X); inline void reset(); inline const Mat& mean() const; inline const Mat< T>& var (const uword norm_type = 0); inline Mat< T> stddev(const uword norm_type = 0) const; inline const Mat& cov (const uword norm_type = 0); inline const Mat& min() const; inline const Mat& max() const; inline T count() const; // // private: const bool calc_cov; arma_aligned arma_counter counter; arma_aligned Mat r_mean; arma_aligned Mat< T> r_var; arma_aligned Mat r_cov; arma_aligned Mat min_val; arma_aligned Mat max_val; arma_aligned Mat< T> min_val_norm; arma_aligned Mat< T> max_val_norm; arma_aligned Mat< T> r_var_dummy; arma_aligned Mat r_cov_dummy; arma_aligned Mat tmp1; arma_aligned Mat tmp2; friend class running_stat_vec_aux; }; class running_stat_vec_aux { public: template inline static void update_stats ( running_stat_vec& x, const Mat::eT>& sample, const typename arma_not_cx::eT>::result* junk = 0 ); template inline static void update_stats ( running_stat_vec& x, const Mat::T > >& sample, const typename arma_not_cx::eT>::result* junk = 0 ); template inline static void update_stats ( running_stat_vec& x, const Mat< typename running_stat_vec::T >& sample, const typename arma_cx_only::eT>::result* junk = 0 ); template inline static void update_stats ( running_stat_vec& x, const Mat::eT>& sample, const typename arma_cx_only::eT>::result* junk = 0 ); }; //! @} armadillo-6.500.5/include/armadillo_bits/subview_elem2_bones.hpp0000666000000000000000000000611212620272703023415 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_elem2 //! @{ template class subview_elem2 : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat& m; arma_aligned const Base& base_ri; arma_aligned const Base& base_ci; const bool all_rows; const bool all_cols; protected: arma_inline subview_elem2(const Mat& in_m, const Base& in_ri, const Base& in_ci, const bool in_all_rows, const bool in_all_cols); public: inline ~subview_elem2(); template inline void inplace_op(const eT val); template inline void inplace_op(const Base& x); inline void fill(const eT val); inline void zeros(); inline void ones(); inline void operator+= (const eT val); inline void operator-= (const eT val); inline void operator*= (const eT val); inline void operator/= (const eT val); // deliberately returning void template inline void operator_equ(const subview_elem2& x); template inline void operator= (const subview_elem2& x); inline void operator= (const subview_elem2& x); template inline void operator+= (const subview_elem2& x); template inline void operator-= (const subview_elem2& x); template inline void operator%= (const subview_elem2& x); template inline void operator/= (const subview_elem2& x); template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); inline static void extract(Mat& out, const subview_elem2& in); inline static void plus_inplace(Mat& out, const subview_elem2& in); inline static void minus_inplace(Mat& out, const subview_elem2& in); inline static void schur_inplace(Mat& out, const subview_elem2& in); inline static void div_inplace(Mat& out, const subview_elem2& in); private: friend class Mat; subview_elem2(); }; //! @} armadillo-6.500.5/include/armadillo_bits/operator_times.hpp0000666000000000000000000002675312620272703022530 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup operator_times //! @{ //! Base * scalar template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator* (const T1& X, const typename T1::elem_type k) { arma_extra_debug_sigprint(); return eOp(X,k); } //! scalar * Base template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator* (const typename T1::elem_type k, const T1& X) { arma_extra_debug_sigprint(); return eOp(X,k); // NOTE: order is swapped } //! non-complex Base * complex scalar template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_times> >::result operator* ( const T1& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_times>('j', X, k); } //! complex scalar * non-complex Base template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_times> >::result operator* ( const std::complex& k, const T1& X ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_times>('j', X, k); } //! scalar * trans(T1) template arma_inline const Op operator* (const typename T1::elem_type k, const Op& X) { arma_extra_debug_sigprint(); return Op(X.m, k); } //! trans(T1) * scalar template arma_inline const Op operator* (const Op& X, const typename T1::elem_type k) { arma_extra_debug_sigprint(); return Op(X.m, k); } //! Base * diagmat template arma_inline typename enable_if2 < (is_arma_type::value && is_same_type::value), const Glue, glue_times_diag> >::result operator* (const T1& X, const Op& Y) { arma_extra_debug_sigprint(); return Glue, glue_times_diag>(X, Y); } //! diagmat * Base template arma_inline typename enable_if2 < (is_arma_type::value && is_same_type::value), const Glue, T2, glue_times_diag> >::result operator* (const Op& X, const T2& Y) { arma_extra_debug_sigprint(); return Glue, T2, glue_times_diag>(X, Y); } //! diagmat * diagmat template inline Mat< typename promote_type::result > operator* (const Op& X, const Op& Y) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const diagmat_proxy A(X.m); const diagmat_proxy B(Y.m); arma_debug_assert_mul_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matrix multiplication"); Mat out(A.n_rows, B.n_cols, fill::zeros); const uword A_length = (std::min)(A.n_rows, A.n_cols); const uword B_length = (std::min)(B.n_rows, B.n_cols); const uword N = (std::min)(A_length, B_length); for(uword i=0; i::apply( A[i] ) * upgrade_val::apply( B[i] ); } return out; } //! multiplication of Base objects with same element type template arma_inline typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, const Glue >::result operator* (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return Glue(X, Y); } //! multiplication of Base objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue< typename promote_type::result, T1, T2, glue_mixed_times > >::result operator* ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! sparse multiplied by scalar template inline typename enable_if2 < is_arma_sparse_type::value, SpOp >::result operator* ( const T1& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return SpOp(X, k); } template inline typename enable_if2 < is_arma_sparse_type::value, SpOp >::result operator* ( const typename T1::elem_type k, const T1& X ) { arma_extra_debug_sigprint(); return SpOp(X, k); } //! multiplication of two sparse objects template inline arma_hot typename enable_if2 < (is_arma_sparse_type::value && is_arma_sparse_type::value && is_same_type::value), const SpGlue >::result operator* ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); return SpGlue(x, y); } //! convert "(sparse + sparse) * scalar" to specialised operation "scalar * (sparse + sparse)" template inline const SpGlue operator* ( const SpGlue& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "scalar * (sparse + sparse)" to specialised operation template inline const SpGlue operator* ( const typename T1::elem_type k, const SpGlue& X ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "(sparse - sparse) * scalar" to specialised operation "scalar * (sparse - sparse)" template inline const SpGlue operator* ( const SpGlue& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "scalar * (sparse - sparse)" to specialised operation template inline const SpGlue operator* ( const typename T1::elem_type k, const SpGlue& X ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "(sparse*sparse) * scalar" to specialised operation "scalar * (sparse*sparse)" template inline const SpGlue operator* ( const SpGlue& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "scalar * (sparse*sparse)" to specialised operation template inline const SpGlue operator* ( const typename T1::elem_type k, const SpGlue& X ) { arma_extra_debug_sigprint(); return SpGlue(X.A, X.B, k); } //! convert "(scalar*sparse) * sparse" to specialised operation "scalar * (sparse*sparse)" template inline typename enable_if2 < is_arma_sparse_type::value, const SpGlue >::result operator* ( const SpOp& X, const T2& Y ) { arma_extra_debug_sigprint(); return SpGlue(X.m, Y, X.aux); } //! convert "sparse * (scalar*sparse)" to specialised operation "scalar * (sparse*sparse)" template inline typename enable_if2 < is_arma_sparse_type::value, const SpGlue >::result operator* ( const T1& X, const SpOp& Y ) { arma_extra_debug_sigprint(); return SpGlue(X, Y.m, Y.aux); } //! multiplication of one sparse and one dense object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), Mat >::result operator* ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const SpProxy pa(x); const Proxy pb(y); arma_debug_assert_mul_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "matrix multiplication"); Mat result(pa.get_n_rows(), pb.get_n_cols()); result.zeros(); if( (pa.get_n_nonzero() > 0) && (pb.get_n_elem() > 0) ) { typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type x_it_end = pa.end(); const uword result_n_cols = result.n_cols; while(x_it != x_it_end) { for(uword col = 0; col < result_n_cols; ++col) { result.at(x_it.row(), col) += (*x_it) * pb.at(x_it.col(), col); } ++x_it; } } return result; } //! multiplication of one dense and one sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), Mat >::result operator* ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const Proxy pa(x); const SpProxy pb(y); arma_debug_assert_mul_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "matrix multiplication"); Mat result(pa.get_n_rows(), pb.get_n_cols()); result.zeros(); if( (pa.get_n_elem() > 0) && (pb.get_n_nonzero() > 0) ) { typename SpProxy::const_iterator_type y_col_it = pb.begin(); typename SpProxy::const_iterator_type y_col_it_end = pb.end(); const uword result_n_rows = result.n_rows; while(y_col_it != y_col_it_end) { for(uword row = 0; row < result_n_rows; ++row) { result.at(row, y_col_it.col()) += pa.at(row, y_col_it.row()) * (*y_col_it); } ++y_col_it; } } return result; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_all.hpp0000666000000000000000000000371712620272703020722 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_all //! @{ template arma_inline const mtOp all ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtOp(X, dim, 0); } template arma_inline const mtOp all ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOp(X, dim, 0); } template inline arma_warn_unused bool all ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_all::all_vec(X); } template inline arma_warn_unused bool all(const mtOp& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("all(): two consecutive calls to all() detected"); return op_all::all_vec(in.m); } template arma_inline const Op< mtOp, op_all> all(const mtOp& in, const uword dim) { arma_extra_debug_sigprint(); return mtOp, op_all>(in, dim, 0); } //! @} armadillo-6.500.5/include/armadillo_bits/op_princomp_meat.hpp0000666000000000000000000003623112620272703023017 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas // Written by Stanislav Funiak //! \addtogroup op_princomp //! @{ //! \brief //! principal component analysis -- 4 arguments version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors //! tsquared_out -> Hotelling's T^2 statistic template inline bool op_princomp::direct_princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, Col& tsquared_out, const Base& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); //Col s_tmp = zeros< Col >(n_cols); Col s_tmp(n_cols); s_tmp.zeros(); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; // compute the Hotelling's T-squared s_tmp.rows(0,n_rows-2) = eT(1) / s_tmp.rows(0,n_rows-2); const Mat S = score_out * diagmat(Col(s_tmp)); tsquared_out = sum(S%S,1); } else { // compute the Hotelling's T-squared const Mat S = score_out * diagmat(Col( eT(1) / s)); tsquared_out = sum(S%S,1); } // compute the eigenvalues of the principal vectors latent_out = s%s; } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); latent_out.set_size(n_cols); latent_out.zeros(); tsquared_out.set_size(n_rows); tsquared_out.zeros(); } return true; } //! \brief //! principal component analysis -- 3 arguments version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors template inline bool op_princomp::direct_princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, const Base& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); Col s_tmp = zeros< Col >(n_cols); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; } // compute the eigenvalues of the principal vectors latent_out = s%s; } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); latent_out.set_size(n_cols); latent_out.zeros(); } return true; } //! \brief //! principal component analysis -- 2 arguments version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples template inline bool op_princomp::direct_princomp ( Mat& coeff_out, Mat& score_out, const Base& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); Col s_tmp = zeros< Col >(n_cols); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; } } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); } return true; } //! \brief //! principal component analysis -- 1 argument version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients template inline bool op_princomp::direct_princomp ( Mat& coeff_out, const Base& X, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap Y( X.get_ref() ); const Mat& in = Y.M; if(in.n_elem != 0) { Mat tmp = in; tmp.each_row() -= mean(in); // singular value decomposition Mat U; Col s; const bool svd_ok = svd(U, s, coeff_out, tmp); if(svd_ok == false) { return false; } } else { coeff_out.eye(in.n_cols, in.n_cols); } return true; } //! \brief //! principal component analysis -- 4 arguments complex version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors //! tsquared_out -> Hotelling's T^2 statistic template inline bool op_princomp::direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, Col< typename T1::pod_type >& latent_out, Col< std::complex >& tsquared_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef std::complex eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col< T> s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); Col s_tmp = zeros< Col >(n_cols); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; // compute the Hotelling's T-squared s_tmp.rows(0,n_rows-2) = 1.0 / s_tmp.rows(0,n_rows-2); const Mat S = score_out * diagmat(Col(s_tmp)); tsquared_out = sum(S%S,1); } else { // compute the Hotelling's T-squared const Mat S = score_out * diagmat(Col(T(1) / s)); tsquared_out = sum(S%S,1); } // compute the eigenvalues of the principal vectors latent_out = s%s; } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); latent_out.set_size(n_cols); latent_out.zeros(); tsquared_out.set_size(n_rows); tsquared_out.zeros(); } return true; } //! \brief //! principal component analysis -- 3 arguments complex version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples //! latent_out -> eigenvalues of principal vectors template inline bool op_princomp::direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, Col< typename T1::pod_type >& latent_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef std::complex eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col< T> s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); Col s_tmp = zeros< Col >(n_cols); s_tmp.rows(0,n_rows-2) = s.rows(0,n_rows-2); s = s_tmp; } // compute the eigenvalues of the principal vectors latent_out = s%s; } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); latent_out.set_size(n_cols); latent_out.zeros(); } return true; } //! \brief //! principal component analysis -- 2 arguments complex version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients //! score_out -> projected samples template inline bool op_princomp::direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef std::complex eT; const unwrap_check Y( X.get_ref(), score_out ); const Mat& in = Y.M; const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; if(n_rows > 1) // more than one sample { // subtract the mean - use score_out as temporary matrix score_out = in; score_out.each_row() -= mean(in); // singular value decomposition Mat U; Col< T> s; const bool svd_ok = svd(U, s, coeff_out, score_out); if(svd_ok == false) { return false; } // normalize the eigenvalues s /= std::sqrt( double(n_rows - 1) ); // project the samples to the principals score_out *= coeff_out; if(n_rows <= n_cols) // number of samples is less than their dimensionality { score_out.cols(n_rows-1,n_cols-1).zeros(); } } else // 0 or 1 samples { coeff_out.eye(n_cols, n_cols); score_out.copy_size(in); score_out.zeros(); } return true; } //! \brief //! principal component analysis -- 1 argument complex version //! computation is done via singular value decomposition //! coeff_out -> principal component coefficients template inline bool op_princomp::direct_princomp ( Mat< std::complex >& coeff_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef std::complex eT; const unwrap Y( X.get_ref() ); const Mat& in = Y.M; if(in.n_elem != 0) { // singular value decomposition Mat U; Col< T> s; Mat tmp = in; tmp.each_row() -= mean(in); const bool svd_ok = svd(U, s, coeff_out, tmp); if(svd_ok == false) { return false; } } else { coeff_out.eye(in.n_cols, in.n_cols); } return true; } template inline void op_princomp::apply ( Mat& out, const Op& in ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& A = tmp.M; const bool status = op_princomp::direct_princomp(out, A); if(status == false) { out.reset(); arma_bad("princomp(): decomposition failed"); } } //! @} armadillo-6.500.5/include/armadillo_bits/glue_hist_meat.hpp0000666000000000000000000001316312620272703022454 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_hist //! @{ template inline void glue_hist::apply_noalias(Mat& out, const Mat& X, const Mat& C, const uword dim) { arma_extra_debug_sigprint(); arma_debug_check( ((C.is_vec() == false) && (C.is_empty() == false)), "hist(): parameter 'centers' must be a vector" ); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword C_n_elem = C.n_elem; if( C_n_elem == 0 ) { out.reset(); return; } const eT* C_mem = C.memptr(); const eT center_0 = C_mem[0]; if(dim == 0) { out.zeros(C_n_elem, X_n_cols); for(uword col=0; col < X_n_cols; ++col) { const eT* X_coldata = X.colptr(col); uword* out_coldata = out.colptr(col); for(uword row=0; row < X_n_rows; ++row) { const eT val = X_coldata[row]; if(arma_isfinite(val)) { eT opt_dist = (center_0 >= val) ? (center_0 - val) : (val - center_0); uword opt_index = 0; for(uword j=1; j < C_n_elem; ++j) { const eT center = C_mem[j]; const eT dist = (center >= val) ? (center - val) : (val - center); if(dist < opt_dist) { opt_dist = dist; opt_index = j; } else { break; } } out_coldata[opt_index]++; } else { // -inf if(val < eT(0)) { out_coldata[0]++; } // +inf if(val > eT(0)) { out_coldata[C_n_elem-1]++; } // ignore NaN } } } } else if(dim == 1) { out.zeros(X_n_rows, C_n_elem); if(X_n_rows == 1) { const uword X_n_elem = X.n_elem; const eT* X_mem = X.memptr(); uword* out_mem = out.memptr(); for(uword i=0; i < X_n_elem; ++i) { const eT val = X_mem[i]; if(is_finite(val)) { eT opt_dist = (val >= center_0) ? (val - center_0) : (center_0 - val); uword opt_index = 0; for(uword j=1; j < C_n_elem; ++j) { const eT center = C_mem[j]; const eT dist = (val >= center) ? (val - center) : (center - val); if(dist < opt_dist) { opt_dist = dist; opt_index = j; } else { break; } } out_mem[opt_index]++; } else { // -inf if(val < eT(0)) { out_mem[0]++; } // +inf if(val > eT(0)) { out_mem[C_n_elem-1]++; } // ignore NaN } } } else { for(uword row=0; row < X_n_rows; ++row) { for(uword col=0; col < X_n_cols; ++col) { const eT val = X.at(row,col); if(arma_isfinite(val)) { eT opt_dist = (center_0 >= val) ? (center_0 - val) : (val - center_0); uword opt_index = 0; for(uword j=1; j < C_n_elem; ++j) { const eT center = C_mem[j]; const eT dist = (center >= val) ? (center - val) : (val - center); if(dist < opt_dist) { opt_dist = dist; opt_index = j; } else { break; } } out.at(row,opt_index)++; } else { // -inf if(val < eT(0)) { out.at(row,0)++; } // +inf if(val > eT(0)) { out.at(row,C_n_elem-1)++; } // ignore NaN } } } } } } template inline void glue_hist::apply(Mat& out, const mtGlue& expr) { arma_extra_debug_sigprint(); const uword dim = expr.aux_uword; arma_debug_check( (dim > 1), "hist(): parameter 'dim' must be 0 or 1" ); const quasi_unwrap UA(expr.A); const quasi_unwrap UB(expr.B); if(UA.is_alias(out) || UB.is_alias(out)) { Mat tmp; glue_hist::apply_noalias(tmp, UA.M, UB.M, dim); out.steal_mem(tmp); } else { glue_hist::apply_noalias(out, UA.M, UB.M, dim); } } template inline void glue_hist_default::apply(Mat& out, const mtGlue& expr) { arma_extra_debug_sigprint(); const quasi_unwrap UA(expr.A); const quasi_unwrap UB(expr.B); //const uword dim = ( (T1::is_row) || ((UA.M.vec_state == 0) && (UA.M.n_elem <= 1) && (out.vec_state == 2)) ) ? 1 : 0; const uword dim = (T1::is_row) ? 1 : 0; if(UA.is_alias(out) || UB.is_alias(out)) { Mat tmp; glue_hist::apply_noalias(tmp, UA.M, UB.M, dim); out.steal_mem(tmp); } else { glue_hist::apply_noalias(out, UA.M, UB.M, dim); } } //! @} armadillo-6.500.5/include/armadillo_bits/eOpCube_meat.hpp0000666000000000000000000000660712620272703022020 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eOpCube //! @{ template eOpCube::eOpCube(const BaseCube& in_m) : P (in_m.get_ref()) { arma_extra_debug_sigprint(); } template eOpCube::eOpCube(const BaseCube& in_m, const typename T1::elem_type in_aux) : P (in_m.get_ref()) , aux (in_aux) { arma_extra_debug_sigprint(); } template eOpCube::eOpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : P (in_m.get_ref()) , aux_uword_a (in_aux_uword_a) , aux_uword_b (in_aux_uword_b) { arma_extra_debug_sigprint(); } template eOpCube::eOpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : P (in_m.get_ref()) , aux_uword_a (in_aux_uword_a) , aux_uword_b (in_aux_uword_b) , aux_uword_c (in_aux_uword_c) { arma_extra_debug_sigprint(); } template eOpCube::eOpCube(const BaseCube& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c) : P (in_m.get_ref()) , aux (in_aux) , aux_uword_a (in_aux_uword_a) , aux_uword_b (in_aux_uword_b) , aux_uword_c (in_aux_uword_c) { arma_extra_debug_sigprint(); } template eOpCube::~eOpCube() { arma_extra_debug_sigprint(); } template arma_inline uword eOpCube::get_n_rows() const { return P.get_n_rows(); } template arma_inline uword eOpCube::get_n_cols() const { return P.get_n_cols(); } template arma_inline uword eOpCube::get_n_elem_slice() const { return P.get_n_elem_slice(); } template arma_inline uword eOpCube::get_n_slices() const { return P.get_n_slices(); } template arma_inline uword eOpCube::get_n_elem() const { return P.get_n_elem(); } template arma_inline typename T1::elem_type eOpCube::operator[] (const uword i) const { return eop_core::process(P[i], aux); } template arma_inline typename T1::elem_type eOpCube::at(const uword row, const uword col, const uword slice) const { return eop_core::process(P.at(row, col, slice), aux); } template arma_inline typename T1::elem_type eOpCube::at_alt(const uword i) const { return eop_core::process(P.at_alt(i), aux); } //! @} armadillo-6.500.5/include/armadillo_bits/debug.hpp0000666000000000000000000007234612650111756020564 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Stanislav Funiak //! \addtogroup debug //! @{ template inline std::ostream& arma_stream_err1(std::ostream* user_stream) { static std::ostream* stream_err1 = &(ARMA_DEFAULT_OSTREAM); if(user_stream != NULL) { stream_err1 = user_stream; } return *stream_err1; } template inline std::ostream& arma_stream_err2(std::ostream* user_stream) { static std::ostream* stream_err2 = &(ARMA_DEFAULT_OSTREAM); if(user_stream != NULL) { stream_err2 = user_stream; } return *stream_err2; } inline void set_stream_err1(std::ostream& user_stream) { arma_stream_err1(&user_stream); } inline void set_stream_err2(std::ostream& user_stream) { arma_stream_err2(&user_stream); } inline std::ostream& get_stream_err1() { return arma_stream_err1(NULL); } inline std::ostream& get_stream_err2() { return arma_stream_err2(NULL); } // // arma_stop //! print a message to get_stream_err1() and/or throw a logic_error exception template arma_cold arma_noinline static void arma_stop(const T1& x) { #if defined(ARMA_PRINT_ERRORS) { get_stream_err1() << "\nerror: " << x << '\n'; } #endif throw std::logic_error( std::string(x) ); } template arma_cold arma_noinline static void arma_stop_bad_alloc(const T1& x) { #if defined(ARMA_PRINT_ERRORS) { get_stream_err2() << "\nerror: " << x << '\n'; } #else { arma_ignore(x); } #endif throw std::bad_alloc(); } // // arma_bad //! print a message to get_stream_err2() and/or throw a run-time error exception template arma_cold arma_noinline static void arma_bad(const T1& x) { #if defined(ARMA_PRINT_ERRORS) { get_stream_err2() << "\nerror: " << x << '\n'; } #endif throw std::runtime_error( std::string(x) ); } // // arma_print arma_cold inline void arma_print() { get_stream_err1() << std::endl; } template arma_cold arma_noinline static void arma_print(const T1& x) { get_stream_err1() << x << std::endl; } template arma_cold arma_noinline static void arma_print(const T1& x, const T2& y) { get_stream_err1() << x << y << std::endl; } template arma_cold arma_noinline static void arma_print(const T1& x, const T2& y, const T3& z) { get_stream_err1() << x << y << z << std::endl; } // // arma_sigprint //! print a message the the log stream with a preceding @ character. //! by default the log stream is cout. //! used for printing the signature of a function //! (see the arma_extra_debug_sigprint macro) inline void arma_sigprint(const char* x) { get_stream_err1() << "@ " << x; } // // arma_bktprint inline void arma_bktprint() { get_stream_err1() << std::endl; } template inline void arma_bktprint(const T1& x) { get_stream_err1() << " [" << x << ']' << std::endl; } template inline void arma_bktprint(const T1& x, const T2& y) { get_stream_err1() << " [" << x << y << ']' << std::endl; } // // arma_thisprint inline void arma_thisprint(const void* this_ptr) { get_stream_err1() << " [this = " << this_ptr << ']' << std::endl; } // // arma_warn //! print a message to the warn stream template arma_cold arma_noinline static void arma_warn(const T1& x) { #if defined(ARMA_PRINT_ERRORS) { get_stream_err2() << "\nwarning: " << x << '\n'; } #else { arma_ignore(x); } #endif } template arma_cold arma_noinline static void arma_warn(const T1& x, const T2& y) { #if defined(ARMA_PRINT_ERRORS) { get_stream_err2() << "\nwarning: " << x << y << '\n'; } #else { arma_ignore(x); arma_ignore(y); } #endif } template arma_cold arma_noinline static void arma_warn(const T1& x, const T2& y, const T3& z) { #if defined(ARMA_PRINT_ERRORS) { get_stream_err2() << "\nwarning: " << x << y << z << '\n'; } #else { arma_ignore(x); arma_ignore(y); arma_ignore(z); } #endif } // // arma_check //! if state is true, abort program template arma_hot inline void arma_check(const bool state, const T1& x) { if(state==true) { arma_stop(arma_str::str_wrapper(x)); } } template arma_hot inline void arma_check(const bool state, const T1& x, const T2& y) { if(state==true) { arma_stop( std::string(x) + std::string(y) ); } } template arma_hot inline void arma_check_bad_alloc(const bool state, const T1& x) { if(state==true) { arma_stop_bad_alloc(x); } } // // arma_set_error arma_hot arma_inline void arma_set_error(bool& err_state, char*& err_msg, const bool expression, const char* message) { if(expression == true) { err_state = true; err_msg = const_cast(message); } } // // functions for generating strings indicating size errors arma_cold arma_noinline static std::string arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) { std::stringstream tmp; tmp << x << ": incompatible matrix dimensions: " << A_n_rows << 'x' << A_n_cols << " and " << B_n_rows << 'x' << B_n_cols; return tmp.str(); } arma_cold arma_noinline static std::string arma_incompat_size_string(const uword A_n_rows, const uword A_n_cols, const uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_slices, const char* x) { std::stringstream tmp; tmp << x << ": incompatible cube dimensions: " << A_n_rows << 'x' << A_n_cols << 'x' << A_n_slices << " and " << B_n_rows << 'x' << B_n_cols << 'x' << B_n_slices; return tmp.str(); } template arma_cold arma_noinline static std::string arma_incompat_size_string(const subview_cube& Q, const Mat& A, const char* x) { std::stringstream tmp; tmp << x << ": interpreting matrix as cube with dimensions: " << A.n_rows << 'x' << A.n_cols << 'x' << 1 << " or " << A.n_rows << 'x' << 1 << 'x' << A.n_cols << " or " << 1 << 'x' << A.n_rows << 'x' << A.n_cols << " is incompatible with cube dimensions: " << Q.n_rows << 'x' << Q.n_cols << 'x' << Q.n_slices; return tmp.str(); } // // functions for checking whether two dense matrices have the same dimensions arma_inline arma_hot void arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) { if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } //! stop if given matrices have different sizes template arma_hot inline void arma_assert_same_size(const Mat& A, const Mat& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } //! stop if given proxies have different sizes template arma_hot inline void arma_assert_same_size(const Proxy& A, const Proxy& B, const char* x) { const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const subview& A, const subview& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const Mat& A, const subview& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const subview& A, const Mat& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const Mat& A, const Proxy& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const Proxy& A, const Mat& B, const char* x) { const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const Proxy& A, const subview& B, const char* x) { const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } template arma_hot inline void arma_assert_same_size(const subview& A, const Proxy& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } // // functions for checking whether two sparse matrices have the same dimensions template arma_hot inline void arma_assert_same_size(const SpMat& A, const SpMat& B, const char* x) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } // // functions for checking whether two cubes have the same dimensions arma_hot inline void arma_assert_same_size(const uword A_n_rows, const uword A_n_cols, const uword A_n_slices, const uword B_n_rows, const uword B_n_cols, const uword B_n_slices, const char* x) { if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices) ) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B_n_cols, B_n_slices, x) ); } } //! stop if given cubes have different sizes template arma_hot inline void arma_assert_same_size(const Cube& A, const Cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); } } template arma_hot inline void arma_assert_same_size(const Cube& A, const subview_cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); } } template arma_hot inline void arma_assert_same_size(const subview_cube& A, const Cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); } } template arma_hot inline void arma_assert_same_size(const subview_cube& A, const subview_cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != B.n_slices)) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, B.n_slices, x) ); } } //! stop if given cube proxies have different sizes template arma_hot inline void arma_assert_same_size(const ProxyCube& A, const ProxyCube& B, const char* x) { const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword A_n_slices = A.get_n_slices(); const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); const uword B_n_slices = B.get_n_slices(); if( (A_n_rows != B_n_rows) || (A_n_cols != B_n_cols) || (A_n_slices != B_n_slices)) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, A_n_slices, B_n_rows, B_n_cols, B_n_slices, x) ); } } // // functions for checking whether a cube or subcube can be interpreted as a matrix (i.e. single slice) template arma_hot inline void arma_assert_same_size(const Cube& A, const Mat& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) ); } } template arma_hot inline void arma_assert_same_size(const Mat& A, const Cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) ); } } template arma_hot inline void arma_assert_same_size(const subview_cube& A, const Mat& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (A.n_slices != 1) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, A.n_slices, B.n_rows, B.n_cols, 1, x) ); } } template arma_hot inline void arma_assert_same_size(const Mat& A, const subview_cube& B, const char* x) { if( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) || (1 != B.n_slices) ) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, 1, B.n_rows, B.n_cols, B.n_slices, x) ); } } template inline void arma_assert_cube_as_mat(const Mat& M, const T1& Q, const char* x, const bool check_compat_size) { const uword Q_n_rows = Q.n_rows; const uword Q_n_cols = Q.n_cols; const uword Q_n_slices = Q.n_slices; const uword M_vec_state = M.vec_state; if(M_vec_state == 0) { if( ( (Q_n_rows == 1) || (Q_n_cols == 1) || (Q_n_slices == 1) ) == false ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a matrix; one of the dimensions must be 1"; arma_stop( tmp.str() ); } } else { if(Q_n_slices == 1) { if( (M_vec_state == 1) && (Q_n_cols != 1) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a column vector"; arma_stop( tmp.str() ); } if( (M_vec_state == 2) && (Q_n_rows != 1) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a row vector"; arma_stop( tmp.str() ); } } else { if( (Q_n_cols != 1) && (Q_n_rows != 1) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a vector"; arma_stop( tmp.str() ); } } } if(check_compat_size == true) { const uword M_n_rows = M.n_rows; const uword M_n_cols = M.n_cols; if(M_vec_state == 0) { if( ( ( (Q_n_rows == M_n_rows) && (Q_n_cols == M_n_cols) ) || ( (Q_n_rows == M_n_rows) && (Q_n_slices == M_n_cols) ) || ( (Q_n_cols == M_n_rows) && (Q_n_slices == M_n_cols) ) ) == false ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a matrix with dimensions " << M_n_rows << 'x' << M_n_cols; arma_stop( tmp.str() ); } } else { if(Q_n_slices == 1) { if( (M_vec_state == 1) && (Q_n_rows != M_n_rows) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a column vector with dimensions " << M_n_rows << 'x' << M_n_cols; arma_stop( tmp.str() ); } if( (M_vec_state == 2) && (Q_n_cols != M_n_cols) ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a row vector with dimensions " << M_n_rows << 'x' << M_n_cols; arma_stop( tmp.str() ); } } else { if( ( (M_n_cols == Q_n_slices) || (M_n_rows == Q_n_slices) ) == false ) { std::stringstream tmp; tmp << x << ": can't interpret cube with dimensions " << Q_n_rows << 'x' << Q_n_cols << 'x' << Q_n_slices << " as a vector with dimensions " << M_n_rows << 'x' << M_n_cols; arma_stop( tmp.str() ); } } } } } // // functions for checking whether two matrices have dimensions that are compatible with the matrix multiply operation arma_hot inline void arma_assert_mul_size(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) { if(A_n_cols != B_n_rows) { arma_stop( arma_incompat_size_string(A_n_rows, A_n_cols, B_n_rows, B_n_cols, x) ); } } //! stop if given matrices are incompatible for multiplication template arma_hot inline void arma_assert_mul_size(const Mat& A, const Mat& B, const char* x) { const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; if(A_n_cols != B_n_rows) { arma_stop( arma_incompat_size_string(A.n_rows, A_n_cols, B_n_rows, B.n_cols, x) ); } } //! stop if given matrices are incompatible for multiplication template arma_hot inline void arma_assert_mul_size(const Mat& A, const Mat& B, const bool do_trans_A, const bool do_trans_B, const char* x) { const uword final_A_n_cols = (do_trans_A == false) ? A.n_cols : A.n_rows; const uword final_B_n_rows = (do_trans_B == false) ? B.n_rows : B.n_cols; if(final_A_n_cols != final_B_n_rows) { const uword final_A_n_rows = (do_trans_A == false) ? A.n_rows : A.n_cols; const uword final_B_n_cols = (do_trans_B == false) ? B.n_cols : B.n_rows; arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) ); } } template arma_hot inline void arma_assert_trans_mul_size(const uword A_n_rows, const uword A_n_cols, const uword B_n_rows, const uword B_n_cols, const char* x) { const uword final_A_n_cols = (do_trans_A == false) ? A_n_cols : A_n_rows; const uword final_B_n_rows = (do_trans_B == false) ? B_n_rows : B_n_cols; if(final_A_n_cols != final_B_n_rows) { const uword final_A_n_rows = (do_trans_A == false) ? A_n_rows : A_n_cols; const uword final_B_n_cols = (do_trans_B == false) ? B_n_cols : B_n_rows; arma_stop( arma_incompat_size_string(final_A_n_rows, final_A_n_cols, final_B_n_rows, final_B_n_cols, x) ); } } template arma_hot inline void arma_assert_mul_size(const Mat& A, const subview& B, const char* x) { if(A.n_cols != B.n_rows) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); } } template arma_hot inline void arma_assert_mul_size(const subview& A, const Mat& B, const char* x) { if(A.n_cols != B.n_rows) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); } } template arma_hot inline void arma_assert_mul_size(const subview& A, const subview& B, const char* x) { if(A.n_cols != B.n_rows) { arma_stop( arma_incompat_size_string(A.n_rows, A.n_cols, B.n_rows, B.n_cols, x) ); } } template arma_hot inline void arma_assert_blas_size(const T1& A) { if(sizeof(uword) >= sizeof(blas_int)) { bool overflow; overflow = (A.n_rows > ARMA_MAX_BLAS_INT); overflow = (A.n_cols > ARMA_MAX_BLAS_INT) || overflow; if(overflow) { arma_bad("integer overflow: matrix dimensions are too large for integer type used by BLAS and LAPACK"); } } } template arma_hot inline void arma_assert_blas_size(const T1& A, const T2& B) { if(sizeof(uword) >= sizeof(blas_int)) { bool overflow; overflow = (A.n_rows > ARMA_MAX_BLAS_INT); overflow = (A.n_cols > ARMA_MAX_BLAS_INT) || overflow; overflow = (B.n_rows > ARMA_MAX_BLAS_INT) || overflow; overflow = (B.n_cols > ARMA_MAX_BLAS_INT) || overflow; if(overflow) { arma_bad("integer overflow: matrix dimensions are too large for integer type used by BLAS and LAPACK"); } } } template arma_hot inline void arma_assert_atlas_size(const T1& A) { if(sizeof(uword) >= sizeof(int)) { bool overflow; overflow = (A.n_rows > INT_MAX); overflow = (A.n_cols > INT_MAX) || overflow; if(overflow) { arma_bad("integer overflow: matrix dimensions are too large for integer type used by ATLAS"); } } } template arma_hot inline void arma_assert_atlas_size(const T1& A, const T2& B) { if(sizeof(uword) >= sizeof(int)) { bool overflow; overflow = (A.n_rows > INT_MAX); overflow = (A.n_cols > INT_MAX) || overflow; overflow = (B.n_rows > INT_MAX) || overflow; overflow = (B.n_cols > INT_MAX) || overflow; if(overflow) { arma_bad("integer overflow: matrix dimensions are too large for integer type used by ATLAS"); } } } // // macros // #define ARMA_STRING1(x) #x // #define ARMA_STRING2(x) ARMA_STRING1(x) // #define ARMA_FILELINE __FILE__ ": " ARMA_STRING2(__LINE__) #if defined(ARMA_NO_DEBUG) #undef ARMA_EXTRA_DEBUG #define arma_debug_print true ? (void)0 : arma_print #define arma_debug_warn true ? (void)0 : arma_warn #define arma_debug_check true ? (void)0 : arma_check #define arma_debug_set_error true ? (void)0 : arma_set_error #define arma_debug_assert_same_size true ? (void)0 : arma_assert_same_size #define arma_debug_assert_mul_size true ? (void)0 : arma_assert_mul_size #define arma_debug_assert_trans_mul_size true ? (void)0 : arma_assert_trans_mul_size #define arma_debug_assert_cube_as_mat true ? (void)0 : arma_assert_cube_as_mat #define arma_debug_assert_blas_size true ? (void)0 : arma_assert_blas_size #define arma_debug_assert_atlas_size true ? (void)0 : arma_assert_atlas_size #else #define arma_debug_print arma_print #define arma_debug_warn arma_warn #define arma_debug_check arma_check #define arma_debug_set_error arma_set_error #define arma_debug_assert_same_size arma_assert_same_size #define arma_debug_assert_mul_size arma_assert_mul_size #define arma_debug_assert_trans_mul_size arma_assert_trans_mul_size #define arma_debug_assert_cube_as_mat arma_assert_cube_as_mat #define arma_debug_assert_blas_size arma_assert_blas_size #define arma_debug_assert_atlas_size arma_assert_atlas_size #endif #if defined(ARMA_EXTRA_DEBUG) #define arma_extra_debug_sigprint arma_sigprint(ARMA_FNSIG); arma_bktprint #define arma_extra_debug_sigprint_this arma_sigprint(ARMA_FNSIG); arma_thisprint #define arma_extra_debug_print arma_print #define arma_extra_debug_warn arma_warn #define arma_extra_debug_check arma_check #else #define arma_extra_debug_sigprint true ? (void)0 : arma_bktprint #define arma_extra_debug_sigprint_this true ? (void)0 : arma_thisprint #define arma_extra_debug_print true ? (void)0 : arma_print #define arma_extra_debug_warn true ? (void)0 : arma_warn #define arma_extra_debug_check true ? (void)0 : arma_check #endif #if defined(ARMA_EXTRA_DEBUG) namespace junk { class arma_first_extra_debug_message { public: inline arma_first_extra_debug_message() { union { unsigned short a; unsigned char b[sizeof(unsigned short)]; } endian_test; endian_test.a = 1; const bool little_endian = (endian_test.b[0] == 1); const char* nickname = ARMA_VERSION_NAME; std::ostream& out = get_stream_err1(); out << "@ ---" << '\n'; out << "@ Armadillo " << arma_version::major << '.' << arma_version::minor << '.' << arma_version::patch << " (" << nickname << ")\n"; out << "@ arma_config::use_wrapper = " << arma_config::use_wrapper << '\n'; out << "@ arma_config::use_cxx11 = " << arma_config::use_cxx11 << '\n'; out << "@ arma_config::openmp = " << arma_config::openmp << '\n'; out << "@ arma_config::lapack = " << arma_config::lapack << '\n'; out << "@ arma_config::blas = " << arma_config::blas << '\n'; out << "@ arma_config::arpack = " << arma_config::arpack << '\n'; out << "@ arma_config::superlu = " << arma_config::superlu << '\n'; out << "@ arma_config::atlas = " << arma_config::atlas << '\n'; out << "@ arma_config::hdf5 = " << arma_config::hdf5 << '\n'; out << "@ arma_config::good_comp = " << arma_config::good_comp << '\n'; out << "@ arma_config::extra_code = " << arma_config::extra_code << '\n'; out << "@ arma_config::mat_prealloc = " << arma_config::mat_prealloc << '\n'; out << "@ sizeof(void*) = " << sizeof(void*) << '\n'; out << "@ sizeof(int) = " << sizeof(int) << '\n'; out << "@ sizeof(long) = " << sizeof(long) << '\n'; out << "@ sizeof(uword) = " << sizeof(uword) << '\n'; out << "@ sizeof(blas_int) = " << sizeof(blas_int) << '\n'; out << "@ little_endian = " << little_endian << '\n'; out << "@ ---" << std::endl; } }; static arma_first_extra_debug_message arma_first_extra_debug_message_run; } #endif //! @} armadillo-6.500.5/include/armadillo_bits/arma_version.hpp0000666000000000000000000000214512656373513022160 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arma_version //! @{ #define ARMA_VERSION_MAJOR 6 #define ARMA_VERSION_MINOR 500 #define ARMA_VERSION_PATCH 5 #define ARMA_VERSION_NAME "Gourmet Electron Jumper" struct arma_version { static const unsigned int major = ARMA_VERSION_MAJOR; static const unsigned int minor = ARMA_VERSION_MINOR; static const unsigned int patch = ARMA_VERSION_PATCH; static inline std::string as_string() { const char* nickname = ARMA_VERSION_NAME; std::stringstream ss; ss << arma_version::major << '.' << arma_version::minor << '.' << arma_version::patch << " (" << nickname << ')'; return ss.str(); } }; //! @} armadillo-6.500.5/include/armadillo_bits/spglue_join_meat.hpp0000666000000000000000000000642612620272703023013 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spglue_join //! @{ template inline void spglue_join_cols::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_spmat A_tmp(X.A); const unwrap_spmat B_tmp(X.B); const SpMat& A = A_tmp.M; const SpMat& B = B_tmp.M; if( (&out != &A) && (&out != &B) ) { spglue_join_cols::apply_noalias(out, A, B); } else { SpMat tmp; spglue_join_cols::apply_noalias(tmp, A, B); out.steal_mem(tmp); } } template inline void spglue_join_cols::apply_noalias(SpMat& out, const SpMat& A, const SpMat& B) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; arma_debug_check ( ( (A_n_cols != B_n_cols) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), "join_cols() / join_vert(): number of columns must be the same" ); out.set_size( A_n_rows + B_n_rows, (std::max)(A_n_cols, B_n_cols) ); if( out.n_elem > 0 ) { if(A.is_empty() == false) { out.submat(0, 0, A_n_rows-1, out.n_cols-1) = A; } if(B.is_empty() == false) { out.submat(A_n_rows, 0, out.n_rows-1, out.n_cols-1) = B; } } } template inline void spglue_join_rows::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_spmat A_tmp(X.A); const unwrap_spmat B_tmp(X.B); const SpMat& A = A_tmp.M; const SpMat& B = B_tmp.M; if( (&out != &A) && (&out != &B) ) { spglue_join_rows::apply_noalias(out, A, B); } else { SpMat tmp; spglue_join_rows::apply_noalias(tmp, A, B); out.steal_mem(tmp); } } template inline void spglue_join_rows::apply_noalias(SpMat& out, const SpMat& A, const SpMat& B) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; arma_debug_check ( ( (A_n_rows != B.n_rows) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), "join_rows() / join_horiz(): number of rows must be the same" ); out.set_size( (std::max)(A_n_rows, B_n_rows), A_n_cols + B_n_cols ); if( out.n_elem > 0 ) { if(A.is_empty() == false) { out.submat(0, 0, out.n_rows-1, A.n_cols-1) = A; } if(B.is_empty() == false) { out.submat(0, A_n_cols, out.n_rows-1, out.n_cols-1) = B; } } } //! @} armadillo-6.500.5/include/armadillo_bits/def_atlas.hpp0000666000000000000000000001546712620272703021416 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au #ifdef ARMA_USE_ATLAS //! \namespace atlas namespace for ATLAS functions (imported from the global namespace) namespace atlas { using ::CblasColMajor; using ::CblasNoTrans; using ::CblasTrans; using ::CblasConjTrans; using ::CblasLower; using ::CblasUpper; #if defined(ARMA_USE_WRAPPER) extern "C" { float wrapper_cblas_sasum(const int N, const float *X, const int incX); double wrapper_cblas_dasum(const int N, const double *X, const int incX); float wrapper_cblas_snrm2(const int N, const float *X, const int incX); double wrapper_cblas_dnrm2(const int N, const double *X, const int incX); float wrapper_cblas_sdot(const int N, const float *X, const int incX, const float *Y, const int incY); double wrapper_cblas_ddot(const int N, const double *X, const int incX, const double *Y, const int incY); void wrapper_cblas_cdotu_sub(const int N, const void *X, const int incX, const void *Y, const int incY, void *dotu); void wrapper_cblas_zdotu_sub(const int N, const void *X, const int incX, const void *Y, const int incY, void *dotu); void wrapper_cblas_sgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const float alpha, const float *A, const int lda, const float *X, const int incX, const float beta, float *Y, const int incY); void wrapper_cblas_dgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const double alpha, const double *A, const int lda, const double *X, const int incX, const double beta, double *Y, const int incY); void wrapper_cblas_cgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const void *alpha, const void *A, const int lda, const void *X, const int incX, const void *beta, void *Y, const int incY); void wrapper_cblas_zgemv(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const int M, const int N, const void *alpha, const void *A, const int lda, const void *X, const int incX, const void *beta, void *Y, const int incY); void wrapper_cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const float alpha, const float *A, const int lda, const float *B, const int ldb, const float beta, float *C, const int ldc); void wrapper_cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const double alpha, const double *A, const int lda, const double *B, const int ldb, const double beta, double *C, const int ldc); void wrapper_cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const void *alpha, const void *A, const int lda, const void *B, const int ldb, const void *beta, void *C, const int ldc); void wrapper_cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_TRANSPOSE TransB, const int M, const int N, const int K, const void *alpha, const void *A, const int lda, const void *B, const int ldb, const void *beta, void *C, const int ldc); void wrapper_cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const float alpha, const float *A, const int lda, const float beta, float *C, const int ldc); void wrapper_cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const double alpha, const double *A, const int lda, const double beta, double *C, const int ldc); void wrapper_cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const float alpha, const void *A, const int lda, const float beta, void *C, const int ldc); void wrapper_cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE Trans, const int N, const int K, const double alpha, const void *A, const int lda, const double beta, void *C, const int ldc); int wrapper_clapack_sgetrf(const enum CBLAS_ORDER Order, const int M, const int N, float *A, const int lda, int *ipiv); int wrapper_clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N, double *A, const int lda, int *ipiv); int wrapper_clapack_cgetrf(const enum CBLAS_ORDER Order, const int M, const int N, void *A, const int lda, int *ipiv); int wrapper_clapack_zgetrf(const enum CBLAS_ORDER Order, const int M, const int N, void *A, const int lda, int *ipiv); int wrapper_clapack_sgetri(const enum CBLAS_ORDER Order, const int N, float *A, const int lda, const int *ipiv); int wrapper_clapack_dgetri(const enum CBLAS_ORDER Order, const int N, double *A, const int lda, const int *ipiv); int wrapper_clapack_cgetri(const enum CBLAS_ORDER Order, const int N, void *A, const int lda, const int *ipiv); int wrapper_clapack_zgetri(const enum CBLAS_ORDER Order, const int N, void *A, const int lda, const int *ipiv); int wrapper_clapack_sgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, float *A, const int lda, int *ipiv, float *B, const int ldb); int wrapper_clapack_dgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, double *A, const int lda, int *ipiv, double *B, const int ldb); int wrapper_clapack_cgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, void *A, const int lda, int *ipiv, void *B, const int ldb); int wrapper_clapack_zgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS, void *A, const int lda, int *ipiv, void *B, const int ldb); } #endif } #endif armadillo-6.500.5/include/armadillo_bits/glue_join_meat.hpp0000666000000000000000000001037412620272703022445 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_join //! @{ template inline void glue_join_cols::apply_noalias(Mat& out, const Proxy& A, const Proxy& B) { arma_extra_debug_sigprint(); const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); arma_debug_check ( ( (A_n_cols != B_n_cols) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), "join_cols() / join_vert(): number of columns must be the same" ); out.set_size( A_n_rows + B_n_rows, (std::max)(A_n_cols, B_n_cols) ); if( out.n_elem > 0 ) { if(A.get_n_elem() > 0) { out.submat(0, 0, A_n_rows-1, out.n_cols-1) = A.Q; } if(B.get_n_elem() > 0) { out.submat(A_n_rows, 0, out.n_rows-1, out.n_cols-1) = B.Q; } } } template inline void glue_join_cols::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy A(X.A); const Proxy B(X.B); if( (A.is_alias(out) == false) && (B.is_alias(out) == false) ) { glue_join_cols::apply_noalias(out, A, B); } else { Mat tmp; glue_join_cols::apply_noalias(tmp, A, B); out.steal_mem(tmp); } } template inline void glue_join_rows::apply_noalias(Mat& out, const Proxy& A, const Proxy& B) { arma_extra_debug_sigprint(); const uword A_n_rows = A.get_n_rows(); const uword A_n_cols = A.get_n_cols(); const uword B_n_rows = B.get_n_rows(); const uword B_n_cols = B.get_n_cols(); arma_debug_check ( ( (A_n_rows != B_n_rows) && ( (A_n_rows > 0) || (A_n_cols > 0) ) && ( (B_n_rows > 0) || (B_n_cols > 0) ) ), "join_rows() / join_horiz(): number of rows must be the same" ); out.set_size( (std::max)(A_n_rows, B_n_rows), A_n_cols + B_n_cols ); if( out.n_elem > 0 ) { if(A.get_n_elem() > 0) { out.submat(0, 0, out.n_rows-1, A_n_cols-1) = A.Q; } if(B.get_n_elem() > 0) { out.submat(0, A_n_cols, out.n_rows-1, out.n_cols-1) = B.Q; } } } template inline void glue_join_rows::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy A(X.A); const Proxy B(X.B); if( (A.is_alias(out) == false) && (B.is_alias(out) == false) ) { glue_join_rows::apply_noalias(out, A, B); } else { Mat tmp; glue_join_rows::apply_noalias(tmp, A, B); out.steal_mem(tmp); } } template inline void glue_join_slices::apply(Cube& out, const GlueCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube A_tmp(X.A); const unwrap_cube B_tmp(X.B); const Cube& A = A_tmp.M; const Cube& B = B_tmp.M; if(A.n_elem == 0) { out = B; return; } if(B.n_elem == 0) { out = A; return; } arma_debug_check( ( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols) ), "join_slices(): size of slices must be the same" ); if( (&out != &A) && (&out != &B) ) { out.set_size(A.n_rows, A.n_cols, A.n_slices + B.n_slices); out.slices(0, A.n_slices-1 ) = A; out.slices(A.n_slices, out.n_slices-1) = B; } else // we have aliasing { Cube C(A.n_rows, A.n_cols, A.n_slices + B.n_slices); C.slices(0, A.n_slices-1) = A; C.slices(A.n_slices, C.n_slices-1) = B; out.steal_mem(C); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_shuffle_bones.hpp0000666000000000000000000000162212620272703023000 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_shuffle //! @{ class op_shuffle { public: template inline static void apply_direct(Mat& out, const Mat& X, const uword dim); template inline static void apply(Mat& out, const Op& in); }; class op_shuffle_default { public: template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/BaseCube_meat.hpp0000666000000000000000000000423412620272703022141 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup BaseCube //! @{ template arma_inline const derived& BaseCube::get_ref() const { return static_cast(*this); } template inline void BaseCube::print(const std::string extra_text) const { const unwrap_cube tmp( (*this).get_ref() ); tmp.M.impl_print(extra_text); } template inline void BaseCube::print(std::ostream& user_stream, const std::string extra_text) const { const unwrap_cube tmp( (*this).get_ref() ); tmp.M.impl_print(user_stream, extra_text); } template inline void BaseCube::raw_print(const std::string extra_text) const { const unwrap_cube tmp( (*this).get_ref() ); tmp.M.impl_raw_print(extra_text); } template inline void BaseCube::raw_print(std::ostream& user_stream, const std::string extra_text) const { const unwrap_cube tmp( (*this).get_ref() ); tmp.M.impl_raw_print(user_stream, extra_text); } // // extra functions defined in BaseCube_eval_Cube template arma_inline const derived& BaseCube_eval_Cube::eval() const { arma_extra_debug_sigprint(); return static_cast(*this); } // // extra functions defined in BaseCube_eval_expr template arma_inline Cube BaseCube_eval_expr::eval() const { arma_extra_debug_sigprint(); return Cube( static_cast(*this) ); } //! @} armadillo-6.500.5/include/armadillo_bits/op_toeplitz_meat.hpp0000666000000000000000000000447712620272703023051 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_toeplitz //! @{ template inline void op_toeplitz::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; arma_debug_check( ((X.is_vec() == false) && (X.is_empty() == false)), "toeplitz(): given object is not a vector" ); const uword N = X.n_elem; const eT* X_mem = X.memptr(); out.set_size(N,N); for(uword col=0; col < N; ++col) { eT* col_mem = out.colptr(col); uword i; i = col; for(uword row=0; row < col; ++row, --i) { col_mem[row] = X_mem[i]; } i = 0; for(uword row=col; row < N; ++row, ++i) { col_mem[row] = X_mem[i]; } } } template inline void op_toeplitz_c::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& X = tmp.M; arma_debug_check( ((X.is_vec() == false) && (X.is_empty() == false)), "circ_toeplitz(): given object is not a vector" ); const uword N = X.n_elem; const eT* X_mem = X.memptr(); out.set_size(N,N); if(X.is_rowvec() == true) { for(uword row=0; row < N; ++row) { uword i; i = row; for(uword col=0; col < row; ++col, --i) { out.at(row,col) = X_mem[N-i]; } i = 0; for(uword col=row; col < N; ++col, ++i) { out.at(row,col) = X_mem[i]; } } } else { for(uword col=0; col < N; ++col) { eT* col_mem = out.colptr(col); uword i; i = col; for(uword row=0; row < col; ++row, --i) { col_mem[row] = X_mem[N-i]; } i = 0; for(uword row=col; row < N; ++row, ++i) { col_mem[row] = X_mem[i]; } } } } //! @} armadillo-6.500.5/include/armadillo_bits/op_cumsum_meat.hpp0000666000000000000000000000627012620272703022501 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_cumsum //! @{ template inline void op_cumsum::apply_noalias(Mat& out, const Mat& X, const uword dim) { arma_extra_debug_sigprint(); uword n_rows = X.n_rows; uword n_cols = X.n_cols; out.set_size(n_rows,n_cols); if(dim == 0) { if(n_cols == 1) { const eT* X_mem = X.memptr(); eT* out_mem = out.memptr(); eT acc = eT(0); for(uword row=0; row < n_rows; ++row) { acc += X_mem[row]; out_mem[row] = acc; } } else { for(uword col=0; col < n_cols; ++col) { const eT* X_colmem = X.colptr(col); eT* out_colmem = out.colptr(col); eT acc = eT(0); for(uword row=0; row < n_rows; ++row) { acc += X_colmem[row]; out_colmem[row] = acc; } } } } else if(dim == 1) { if(n_rows == 1) { const eT* X_mem = X.memptr(); eT* out_mem = out.memptr(); eT acc = eT(0); for(uword col=0; col < n_cols; ++col) { acc += X_mem[col]; out_mem[col] = acc; } } else { if(n_cols > 0) { arrayops::copy( out.colptr(0), X.colptr(0), n_rows ); for(uword col=1; col < n_cols; ++col) { const eT* out_colmem_prev = out.colptr(col-1); eT* out_colmem = out.colptr(col ); const eT* X_colmem = X.colptr(col ); for(uword row=0; row < n_rows; ++row) { out_colmem[row] = out_colmem_prev[row] + X_colmem[row]; } } } } } } template inline void op_cumsum::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "cumsum(): parameter 'dim' must be 0 or 1" ); const quasi_unwrap U(in.m); if(U.is_alias(out)) { Mat tmp; op_cumsum::apply_noalias(tmp, U.M, dim); out.steal_mem(tmp); } else { op_cumsum::apply_noalias(out, U.M, dim); } } template inline void op_cumsum_default::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const quasi_unwrap U(in.m); const uword dim = (T1::is_row) ? 1 : 0; if(U.is_alias(out)) { Mat tmp; op_cumsum::apply_noalias(tmp, U.M, dim); out.steal_mem(tmp); } else { op_cumsum::apply_noalias(out, U.M, dim); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_normalise_bones.hpp0000666000000000000000000000160512620272703023336 0ustar rootroot// Copyright (C) 2014-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_normalise //! @{ class op_normalise_vec { public: template inline static void apply(Mat& out, const Op& in); }; class op_normalise_mat { public: template inline static void apply(Mat& out, const Op& in); template inline static void apply(Mat& out, const Mat& A, const uword p, const uword dim); }; //! @} armadillo-6.500.5/include/armadillo_bits/glue_relational_meat.hpp0000666000000000000000000001712612620272703023642 0ustar rootroot// Copyright (C) 2009-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_relational //! @{ #undef operator_rel #undef operator_str #undef arma_applier_mat #undef arma_applier_cube #define arma_applier_mat(operator_rel, operator_str) \ {\ const Proxy P1(X.A);\ const Proxy P2(X.B);\ \ arma_debug_assert_same_size(P1, P2, operator_str);\ \ const bool bad_alias = (Proxy::has_subview && P1.is_alias(out)) || (Proxy::has_subview && P2.is_alias(out));\ \ if(bad_alias == false)\ {\ \ const uword n_rows = P1.get_n_rows();\ const uword n_cols = P1.get_n_cols();\ \ out.set_size(n_rows, n_cols);\ \ uword* out_mem = out.memptr();\ \ const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor);\ \ if(prefer_at_accessor == false)\ {\ typename Proxy::ea_type A = P1.get_ea();\ typename Proxy::ea_type B = P2.get_ea();\ \ const uword n_elem = out.n_elem;\ \ for(uword i=0; i::stored_type> tmp1(P1.Q, P1.is_alias(out));\ const unwrap_check::stored_type> tmp2(P2.Q, P2.is_alias(out));\ \ out = (tmp1.M) operator_rel (tmp2.M);\ }\ } #define arma_applier_cube(operator_rel, operator_str) \ {\ const ProxyCube P1(X.A);\ const ProxyCube P2(X.B);\ \ arma_debug_assert_same_size(P1, P2, operator_str);\ \ const bool bad_alias = (ProxyCube::has_subview && P1.is_alias(out)) || (ProxyCube::has_subview && P2.is_alias(out));\ \ if(bad_alias == false)\ {\ \ const uword n_rows = P1.get_n_rows();\ const uword n_cols = P1.get_n_cols();\ const uword n_slices = P1.get_n_slices();\ \ out.set_size(n_rows, n_cols, n_slices);\ \ uword* out_mem = out.memptr();\ \ const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor);\ \ if(prefer_at_accessor == false)\ {\ typename ProxyCube::ea_type A = P1.get_ea();\ typename ProxyCube::ea_type B = P2.get_ea();\ \ const uword n_elem = out.n_elem;\ \ for(uword i=0; i::stored_type> tmp1(P1.Q);\ const unwrap_cube::stored_type> tmp2(P2.Q);\ \ out = (tmp1.M) operator_rel (tmp2.M);\ }\ } template inline void glue_rel_lt::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(<, "operator<"); } template inline void glue_rel_gt::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(>, "operator>"); } template inline void glue_rel_lteq::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(<=, "operator<="); } template inline void glue_rel_gteq::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(>=, "operator>="); } template inline void glue_rel_eq::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(==, "operator=="); } template inline void glue_rel_noteq::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(!=, "operator!="); } template inline void glue_rel_and::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(&&, "operator&&"); } template inline void glue_rel_or::apply ( Mat & out, const mtGlue& X ) { arma_extra_debug_sigprint(); arma_applier_mat(||, "operator||"); } // // // template inline void glue_rel_lt::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(<, "operator<"); } template inline void glue_rel_gt::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(>, "operator>"); } template inline void glue_rel_lteq::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(<=, "operator<="); } template inline void glue_rel_gteq::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(>=, "operator>="); } template inline void glue_rel_eq::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(==, "operator=="); } template inline void glue_rel_noteq::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(!=, "operator!="); } template inline void glue_rel_and::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(&&, "operator&&"); } template inline void glue_rel_or::apply ( Cube & out, const mtGlueCube& X ) { arma_extra_debug_sigprint(); arma_applier_cube(||, "operator||"); } #undef arma_applier_mat #undef arma_applier_cube //! @} armadillo-6.500.5/include/armadillo_bits/glue_histc_bones.hpp0000666000000000000000000000164612620272703023002 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_histc //! @{ class glue_histc { public: template inline static void apply_noalias(Mat& C, const Mat& A, const Mat& B, const uword dim); template inline static void apply(Mat& C, const mtGlue& expr); }; class glue_histc_default { public: template inline static void apply(Mat& C, const mtGlue& expr); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_normalise.hpp0000666000000000000000000000256612620272703022144 0ustar rootroot// Copyright (C) 2014-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_normalise //! @{ template inline typename enable_if2 < (is_arma_type::value && (resolves_to_vector::value == true)), const Op >::result normalise ( const T1& X, const uword p = uword(2), const arma_empty_class junk1 = arma_empty_class(), const typename arma_real_or_cx_only::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, p, 0); } template inline typename enable_if2 < (is_arma_type::value && (resolves_to_vector::value == false)), const Op >::result normalise ( const T1& X, const uword p = uword(2), const uword dim = 0, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, p, dim); } //! @} armadillo-6.500.5/include/armadillo_bits/unwrap.hpp0000666000000000000000000016540712620272703021010 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup unwrap //! @{ template struct unwrap_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline unwrap_default(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap_fixed { typedef T1 stored_type; inline explicit unwrap_fixed(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const T1& M; }; template struct unwrap_redirect {}; template struct unwrap_redirect { typedef unwrap_default result; }; template struct unwrap_redirect { typedef unwrap_fixed result; }; template struct unwrap : public unwrap_redirect::value >::result { inline unwrap(const T1& A) : unwrap_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct unwrap< Mat > { typedef Mat stored_type; inline unwrap(const Mat& A) : M(A) { arma_extra_debug_sigprint(); } const Mat& M; }; template struct unwrap< Row > { typedef Row stored_type; inline unwrap(const Row& A) : M(A) { arma_extra_debug_sigprint(); } const Row& M; }; template struct unwrap< Col > { typedef Col stored_type; inline unwrap(const Col& A) : M(A) { arma_extra_debug_sigprint(); } const Col& M; }; template struct unwrap< mtGlue > { typedef Mat stored_type; inline unwrap(const mtGlue& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap< mtOp > { typedef Mat stored_type; inline unwrap(const mtOp& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; // // // template struct quasi_unwrap_default { typedef typename T1::elem_type eT; static const bool has_subview = false; inline quasi_unwrap_default(const T1& A) : M(A) { arma_extra_debug_sigprint(); } // NOTE: DO NOT DIRECTLY CHECK FOR ALIASING BY TAKING THE ADDRESS OF THE "M" OBJECT IN ANY quasi_unwrap CLASS !!! const Mat M; template arma_inline bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap_fixed { typedef typename T1::elem_type eT; static const bool has_subview = false; inline explicit quasi_unwrap_fixed(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const Mat& M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap_redirect {}; template struct quasi_unwrap_redirect { typedef quasi_unwrap_default result; }; template struct quasi_unwrap_redirect { typedef quasi_unwrap_fixed result; }; template struct quasi_unwrap : public quasi_unwrap_redirect::value >::result { typedef typename quasi_unwrap_redirect::value >::result quasi_unwrap_extra; static const bool has_subview = quasi_unwrap_extra::has_subview; inline quasi_unwrap(const T1& A) : quasi_unwrap_extra(A) { } using quasi_unwrap_extra::M; using quasi_unwrap_extra::is_alias; }; template struct quasi_unwrap< Mat > { static const bool has_subview = false; inline quasi_unwrap(const Mat& A) : M(A) { arma_extra_debug_sigprint(); } const Mat& M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< Row > { static const bool has_subview = false; inline quasi_unwrap(const Row& A) : M(A) { arma_extra_debug_sigprint(); } const Row& M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< Col > { static const bool has_subview = false; inline quasi_unwrap(const Col& A) : M(A) { arma_extra_debug_sigprint(); } const Col& M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< subview_row > { static const bool has_subview = false; inline quasi_unwrap(const subview_row& A) : M(A) { arma_extra_debug_sigprint(); } const Row M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&M) == void_ptr(&X)); } }; template struct quasi_unwrap< subview_col > { static const bool has_subview = true; inline quasi_unwrap(const subview_col& A) : orig( A.m ) , M ( const_cast( A.colptr(0) ), A.n_rows, false, false ) { arma_extra_debug_sigprint(); } const Mat& orig; const Col M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&orig) == void_ptr(&X)); } }; template struct quasi_unwrap< mtGlue > { static const bool has_subview = false; inline quasi_unwrap(const mtGlue& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; template arma_inline bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap< mtOp > { static const bool has_subview = false; inline quasi_unwrap(const mtOp& A) : M(A) { arma_extra_debug_sigprint(); } const Mat M; template arma_inline bool is_alias(const Mat&) const { return false; } }; template struct quasi_unwrap< Op > { static const bool has_subview = true; typedef typename T1::elem_type eT; inline quasi_unwrap(const Op& A) : U( A.m ) , M( const_cast(U.M.memptr()), U.M.n_elem, 1, false, false ) { arma_extra_debug_sigprint(); } const unwrap U; const Mat M; template arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&(U.M)) == void_ptr(&X)); } }; // // // template struct unwrap_check_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline unwrap_check_default(const T1& A, const Mat&) : M(A) { arma_extra_debug_sigprint(); } inline unwrap_check_default(const T1& A, const bool) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap_check_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline unwrap_check_fixed(const T1& A, const Mat& B) : M_local( (&A == &B) ? new T1(A) : 0 ) , M ( (&A == &B) ? *M_local : A ) { arma_extra_debug_sigprint(); } inline unwrap_check_fixed(const T1& A, const bool is_alias) : M_local( is_alias ? new T1(A) : 0 ) , M ( is_alias ? *M_local : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const T1* M_local; const T1& M; }; template struct unwrap_check_redirect {}; template struct unwrap_check_redirect { typedef unwrap_check_default result; }; template struct unwrap_check_redirect { typedef unwrap_check_fixed result; }; template struct unwrap_check : public unwrap_check_redirect::value >::result { inline unwrap_check(const T1& A, const Mat& B) : unwrap_check_redirect< T1, is_Mat_fixed::value >::result(A, B) { } inline unwrap_check(const T1& A, const bool is_alias) : unwrap_check_redirect< T1, is_Mat_fixed::value >::result(A, is_alias) { } }; template struct unwrap_check< Mat > { typedef Mat stored_type; inline unwrap_check(const Mat& A, const Mat& B) : M_local( (&A == &B) ? new Mat(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline unwrap_check(const Mat& A, const bool is_alias) : M_local( is_alias ? new Mat(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Mat* M_local; const Mat& M; }; template struct unwrap_check< Row > { typedef Row stored_type; inline unwrap_check(const Row& A, const Mat& B) : M_local( (&A == &B) ? new Row(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline unwrap_check(const Row& A, const bool is_alias) : M_local( is_alias ? new Row(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Row* M_local; const Row& M; }; template struct unwrap_check< Col > { typedef Col stored_type; inline unwrap_check(const Col& A, const Mat& B) : M_local( (&A == &B) ? new Col(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline unwrap_check(const Col& A, const bool is_alias) : M_local( is_alias ? new Col(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Col* M_local; const Col& M; }; // // // template struct unwrap_check_mixed { typedef typename T1::elem_type eT1; template inline unwrap_check_mixed(const T1& A, const Mat&) : M(A) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const T1& A, const bool) : M(A) { arma_extra_debug_sigprint(); } const Mat M; }; template struct unwrap_check_mixed< Mat > { template inline unwrap_check_mixed(const Mat& A, const Mat& B) : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Mat(A) : 0 ) , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const Mat& A, const bool is_alias) : M_local( is_alias ? new Mat(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_mixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Mat* M_local; const Mat& M; }; template struct unwrap_check_mixed< Row > { template inline unwrap_check_mixed(const Row& A, const Mat& B) : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Row(A) : 0 ) , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const Row& A, const bool is_alias) : M_local( is_alias ? new Row(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_mixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Row* M_local; const Row& M; }; template struct unwrap_check_mixed< Col > { template inline unwrap_check_mixed(const Col& A, const Mat& B) : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Col(A) : 0 ) , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } //template inline unwrap_check_mixed(const Col& A, const bool is_alias) : M_local( is_alias ? new Col(A) : 0 ) , M ( is_alias ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_check_mixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Col* M_local; const Col& M; }; // // // template struct partial_unwrap_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_default(const T1& A) : M(A) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = false; static const bool do_times = false; const Mat M; }; template struct partial_unwrap_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_fixed(const T1& A) : M(A) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = false; const T1& M; }; template struct partial_unwrap_redirect {}; template struct partial_unwrap_redirect { typedef partial_unwrap_default result; }; template struct partial_unwrap_redirect { typedef partial_unwrap_fixed result; }; template struct partial_unwrap : public partial_unwrap_redirect::value >::result { inline partial_unwrap(const T1& A) : partial_unwrap_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< Mat > { typedef Mat stored_type; inline partial_unwrap(const Mat& A) : M(A) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return ((&X) == (&M)); } static const bool do_trans = false; static const bool do_times = false; const Mat& M; }; template struct partial_unwrap< Row > { typedef Row stored_type; inline partial_unwrap(const Row& A) : M(A) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = false; const Row& M; }; template struct partial_unwrap< Col > { typedef Col stored_type; inline partial_unwrap(const Col& A) : M(A) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = false; const Col& M; }; template struct partial_unwrap< subview_col > { typedef Col stored_type; inline partial_unwrap(const subview_col& A) : orig( A.m ) , M ( const_cast( A.colptr(0) ), A.n_rows, false, false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static const bool do_trans = false; static const bool do_times = false; const Mat& orig; const Col M; }; template struct partial_unwrap< subview_row > { typedef Row stored_type; inline partial_unwrap(const subview_row& A) : M(A) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = false; static const bool do_times = false; const Row M; }; template struct partial_unwrap_htrans_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_htrans_default(const Op& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = true; static const bool do_times = false; const Mat M; }; template struct partial_unwrap_htrans_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_htrans_fixed(const Op& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = true; static const bool do_times = false; const T1& M; }; template struct partial_unwrap_htrans_redirect {}; template struct partial_unwrap_htrans_redirect { typedef partial_unwrap_htrans_default result; }; template struct partial_unwrap_htrans_redirect { typedef partial_unwrap_htrans_fixed result; }; template struct partial_unwrap< Op > : public partial_unwrap_htrans_redirect::value >::result { inline partial_unwrap(const Op& A) : partial_unwrap_htrans_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< Op< Mat, op_htrans> > { typedef Mat stored_type; inline partial_unwrap(const Op< Mat, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = true; static const bool do_times = false; const Mat& M; }; template struct partial_unwrap< Op< Row, op_htrans> > { typedef Row stored_type; inline partial_unwrap(const Op< Row, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = true; static const bool do_times = false; const Row& M; }; template struct partial_unwrap< Op< Col, op_htrans> > { typedef Col stored_type; inline partial_unwrap(const Op< Col, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = true; static const bool do_times = false; const Col& M; }; template struct partial_unwrap< Op< subview_col, op_htrans> > { typedef Col stored_type; inline partial_unwrap(const Op< subview_col, op_htrans>& A) : orig( A.m.m ) , M ( const_cast( A.m.colptr(0) ), A.m.n_rows, false, false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static const bool do_trans = true; static const bool do_times = false; const Mat& orig; const Col M; }; template struct partial_unwrap< Op< subview_row, op_htrans> > { typedef Row stored_type; inline partial_unwrap(const Op< subview_row, op_htrans>& A) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = true; static const bool do_times = false; const Row M; }; template struct partial_unwrap_htrans2_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_htrans2_default(const Op& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_htrans2_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_htrans2_fixed(const Op& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = true; static const bool do_times = true; const eT val; const T1& M; }; template struct partial_unwrap_htrans2_redirect {}; template struct partial_unwrap_htrans2_redirect { typedef partial_unwrap_htrans2_default result; }; template struct partial_unwrap_htrans2_redirect { typedef partial_unwrap_htrans2_fixed result; }; template struct partial_unwrap< Op > : public partial_unwrap_htrans2_redirect::value >::result { inline partial_unwrap(const Op& A) : partial_unwrap_htrans2_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< Op< Mat, op_htrans2> > { typedef Mat stored_type; inline partial_unwrap(const Op< Mat, op_htrans2>& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = true; static const bool do_times = true; const eT val; const Mat& M; }; template struct partial_unwrap< Op< Row, op_htrans2> > { typedef Row stored_type; inline partial_unwrap(const Op< Row, op_htrans2>& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = true; static const bool do_times = true; const eT val; const Row& M; }; template struct partial_unwrap< Op< Col, op_htrans2> > { typedef Col stored_type; inline partial_unwrap(const Op< Col, op_htrans2>& A) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = true; static const bool do_times = true; const eT val; const Col& M; }; template struct partial_unwrap< Op< subview_col, op_htrans2> > { typedef Col stored_type; inline partial_unwrap(const Op< subview_col, op_htrans2>& A) : orig( A.m.m ) , val ( A.aux ) , M ( const_cast( A.m.colptr(0) ), A.m.n_rows, false, false ) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static const bool do_trans = true; static const bool do_times = true; const Mat& orig; const eT val; const Col M; }; template struct partial_unwrap< Op< subview_row, op_htrans2> > { typedef Row stored_type; inline partial_unwrap(const Op< subview_row, op_htrans2>& A) : val(A.aux) , M (A.m ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Row M; }; template struct partial_unwrap_scalar_times_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_scalar_times_default(const eOp& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_scalar_times_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_scalar_times_fixed(const eOp& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = true; const eT val; const T1& M; }; template struct partial_unwrap_scalar_times_redirect {}; template struct partial_unwrap_scalar_times_redirect { typedef partial_unwrap_scalar_times_default result; }; template struct partial_unwrap_scalar_times_redirect { typedef partial_unwrap_scalar_times_fixed result; }; template struct partial_unwrap< eOp > : public partial_unwrap_scalar_times_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap(const eOp& A) : partial_unwrap_scalar_times_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Mat stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = true; const eT val; const Mat& M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Row stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = true; const eT val; const Row& M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Col stored_type; inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = true; const eT val; const Col& M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Col stored_type; arma_hot inline partial_unwrap(const eOp,eop_scalar_times>& A) : orig( A.P.Q.m ) , val ( A.aux ) , M ( const_cast( A.P.Q.colptr(0) ), A.P.Q.n_rows, false, false ) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } arma_hot arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static const bool do_trans = false; static const bool do_times = true; const Mat& orig; const eT val; const Col M; }; template struct partial_unwrap< eOp, eop_scalar_times> > { typedef Row stored_type; arma_hot inline partial_unwrap(const eOp,eop_scalar_times>& A) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return val; } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Row M; }; template struct partial_unwrap_neg_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_neg_default(const eOp& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(-1); } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = false; static const bool do_times = true; const Mat M; }; template struct partial_unwrap_neg_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_neg_fixed(const eOp& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(-1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = true; const T1& M; }; template struct partial_unwrap_neg_redirect {}; template struct partial_unwrap_neg_redirect { typedef partial_unwrap_neg_default result; }; template struct partial_unwrap_neg_redirect { typedef partial_unwrap_neg_fixed result; }; template struct partial_unwrap< eOp > : public partial_unwrap_neg_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap(const eOp& A) : partial_unwrap_neg_redirect< T1, is_Mat_fixed::value >::result(A) { } }; template struct partial_unwrap< eOp, eop_neg> > { typedef Mat stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(-1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = true; const Mat& M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Row stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(-1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = true; const Row& M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Col stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(-1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&M)); } static const bool do_trans = false; static const bool do_times = true; const Col& M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Col stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : orig( A.P.Q.m ) , M ( const_cast( A.P.Q.colptr(0) ), A.P.Q.n_rows, false, false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(-1); } arma_inline bool is_alias(const Mat& X) const { return (void_ptr(&X) == void_ptr(&orig)); } static const bool do_trans = false; static const bool do_times = true; const Mat& orig; const Col M; }; template struct partial_unwrap< eOp, eop_neg> > { typedef Row stored_type; inline partial_unwrap(const eOp,eop_neg>& A) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(-1); } arma_inline bool is_alias(const Mat&) const { return false; } static const bool do_trans = false; static const bool do_times = true; const Row M; }; // template struct partial_unwrap_check_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_default(const T1& A, const Mat&) : M(A) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const Mat M; }; template struct partial_unwrap_check_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_fixed(const T1& A, const Mat& B) : M_local( (&A == &B) ? new T1(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_redirect {}; template struct partial_unwrap_check_redirect { typedef partial_unwrap_check_default result; }; template struct partial_unwrap_check_redirect { typedef partial_unwrap_check_fixed result; }; template struct partial_unwrap_check : public partial_unwrap_check_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const T1& A, const Mat& B) : partial_unwrap_check_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< Mat > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const Mat& A, const Mat& B) : M_local ( (&A == &B) ? new Mat(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; // the order below is important const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< Row > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const Row& A, const Mat& B) : M_local ( (&A == &B) ? new Row(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; // the order below is important const Row* M_local; const Row& M; }; template struct partial_unwrap_check< Col > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Col& A, const Mat& B) : M_local ( (&A == &B) ? new Col(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; // the order below is important const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< subview_col > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const subview_col& A, const Mat& B) : M ( const_cast( A.colptr(0) ), A.n_rows, (&(A.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = false; static const bool do_times = false; const Col M; }; template struct partial_unwrap_check_htrans_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_htrans_default(const Op& A, const Mat&) : M(A.m) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const Mat M; }; template struct partial_unwrap_check_htrans_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_htrans_fixed(const Op& A, const Mat& B) : M_local( (&(A.m) == &B) ? new T1(A.m) : 0 ) , M ( (&(A.m) == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_htrans_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_htrans_redirect {}; template struct partial_unwrap_check_htrans_redirect { typedef partial_unwrap_check_htrans_default result; }; template struct partial_unwrap_check_htrans_redirect { typedef partial_unwrap_check_htrans_fixed result; }; template struct partial_unwrap_check< Op > : public partial_unwrap_check_htrans_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const Op& A, const Mat& B) : partial_unwrap_check_htrans_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< Op< Mat, op_htrans> > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const Op< Mat, op_htrans>& A, const Mat& B) : M_local ( (&A.m == &B) ? new Mat(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; // the order below is important const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< Op< Row, op_htrans> > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const Op< Row, op_htrans>& A, const Mat& B) : M_local ( (&A.m == &B) ? new Row(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; // the order below is important const Row* M_local; const Row& M; }; template struct partial_unwrap_check< Op< Col, op_htrans> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Op< Col, op_htrans>& A, const Mat& B) : M_local ( (&A.m == &B) ? new Col(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; // the order below is important const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< Op< subview_col, op_htrans> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Op< subview_col, op_htrans>& A, const Mat& B) : M ( const_cast( A.m.colptr(0) ), A.m.n_rows, (&(A.m.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(1); } static const bool do_trans = true; static const bool do_times = false; const Col M; }; template struct partial_unwrap_check_htrans2_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_htrans2_default(const Op& A, const Mat&) : val(A.aux) , M (A.m) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_check_htrans2_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_htrans2_fixed(const Op& A, const Mat& B) : val (A.aux) , M_local( (&(A.m) == &B) ? new T1(A.m) : 0 ) , M ( (&(A.m) == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_htrans2_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_htrans2_redirect {}; template struct partial_unwrap_check_htrans2_redirect { typedef partial_unwrap_check_htrans2_default result; }; template struct partial_unwrap_check_htrans2_redirect { typedef partial_unwrap_check_htrans2_fixed result; }; template struct partial_unwrap_check< Op > : public partial_unwrap_check_htrans2_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const Op& A, const Mat& B) : partial_unwrap_check_htrans2_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< Op< Mat, op_htrans2> > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const Op< Mat, op_htrans2>& A, const Mat& B) : val (A.aux) , M_local ( (&A.m == &B) ? new Mat(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; // the order below is important const eT val; const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< Op< Row, op_htrans2> > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const Op< Row, op_htrans2>& A, const Mat& B) : val (A.aux) , M_local ( (&A.m == &B) ? new Row(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; // the order below is important const eT val; const Row* M_local; const Row& M; }; template struct partial_unwrap_check< Op< Col, op_htrans2> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Op< Col, op_htrans2>& A, const Mat& B) : val (A.aux) , M_local ( (&A.m == &B) ? new Col(A.m) : 0 ) , M ( (&A.m == &B) ? (*M_local) : A.m ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; // the order below is important const eT val; const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< Op< subview_col, op_htrans2> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const Op< subview_col, op_htrans2>& A, const Mat& B) : val( A.aux ) , M ( const_cast( A.m.colptr(0) ), A.m.n_rows, (&(A.m.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = true; static const bool do_times = true; const eT val; const Col M; }; template struct partial_unwrap_check_scalar_times_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_scalar_times_default(const eOp& A, const Mat&) : val(A.aux) , M (A.P.Q) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Mat M; }; template struct partial_unwrap_check_scalar_times_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_scalar_times_fixed(const eOp& A, const Mat& B) : val ( A.aux ) , M_local( (&(A.P.Q) == &B) ? new T1(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? (*M_local) : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_scalar_times_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_scalar_times_redirect {}; template struct partial_unwrap_check_scalar_times_redirect { typedef partial_unwrap_check_scalar_times_default result; }; template struct partial_unwrap_check_scalar_times_redirect { typedef partial_unwrap_check_scalar_times_fixed result; }; template struct partial_unwrap_check< eOp > : public partial_unwrap_check_scalar_times_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const eOp& A, const Mat& B) : partial_unwrap_check_scalar_times_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val (A.aux) , M_local( (&(A.P.Q) == &B) ? new Mat(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val(A.aux) , M_local( (&(A.P.Q) == &B) ? new Row(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Row* M_local; const Row& M; }; template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val ( A.aux ) , M_local( (&(A.P.Q) == &B) ? new Col(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< eOp, eop_scalar_times> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_scalar_times>& A, const Mat& B) : val( A.aux ) , M ( const_cast( A.P.Q.colptr(0) ), A.P.Q.n_rows, (&(A.P.Q.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_hot arma_inline eT get_val() const { return val; } static const bool do_trans = false; static const bool do_times = true; const eT val; const Col M; }; template struct partial_unwrap_check_neg_default { typedef typename T1::elem_type eT; typedef Mat stored_type; inline partial_unwrap_check_neg_default(const eOp& A, const Mat&) : M(A.P.Q) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Mat M; }; template struct partial_unwrap_check_neg_fixed { typedef typename T1::elem_type eT; typedef T1 stored_type; inline explicit partial_unwrap_check_neg_fixed(const eOp& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new T1(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? (*M_local) : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check_neg_fixed() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const T1* M_local; const T1& M; }; template struct partial_unwrap_check_neg_redirect {}; template struct partial_unwrap_check_neg_redirect { typedef partial_unwrap_check_neg_default result; }; template struct partial_unwrap_check_neg_redirect { typedef partial_unwrap_check_neg_fixed result; }; template struct partial_unwrap_check< eOp > : public partial_unwrap_check_neg_redirect::value >::result { typedef typename T1::elem_type eT; inline partial_unwrap_check(const eOp& A, const Mat& B) : partial_unwrap_check_neg_redirect< T1, is_Mat_fixed::value >::result(A, B) { } }; template struct partial_unwrap_check< eOp, eop_neg> > { typedef Mat stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new Mat(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Mat* M_local; const Mat& M; }; template struct partial_unwrap_check< eOp, eop_neg> > { typedef Row stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new Row(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Row* M_local; const Row& M; }; template struct partial_unwrap_check< eOp, eop_neg> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M_local( (&(A.P.Q) == &B) ? new Col(A.P.Q) : 0 ) , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) { arma_extra_debug_sigprint(); } inline ~partial_unwrap_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Col* M_local; const Col& M; }; // NOTE: we can get away with this shortcut as the partial_unwrap_check class is only used by the glue_times class, // NOTE: which relies on partial_unwrap_check to check for aliasing template struct partial_unwrap_check< eOp, eop_neg> > { typedef Col stored_type; arma_hot inline partial_unwrap_check(const eOp,eop_neg>& A, const Mat& B) : M ( const_cast( A.P.Q.colptr(0) ), A.P.Q.n_rows, (&(A.P.Q.m) == &B), false ) { arma_extra_debug_sigprint(); } arma_inline eT get_val() const { return eT(-1); } static const bool do_trans = false; static const bool do_times = true; const Col M; }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_var.hpp0000666000000000000000000000603112620272703020732 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_var //! @{ template inline const mtOp var ( const T1& X, const uword norm_type = 0, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtOp(X, norm_type, dim); } template inline const mtOp var ( const T1& X, const uword norm_type, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOp(X, norm_type, dim); } template inline arma_warn_unused typename T1::pod_type var ( const T1& X, const uword norm_type = 0, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_var::var_vec( X, norm_type ); } template arma_inline arma_warn_unused const typename arma_scalar_only::result var(const T&) { return T(0); } template inline const mtSpOp var ( const T1& X, const uword norm_type = 0, const uword dim = 0, const typename enable_if< is_arma_sparse_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_sparse_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtSpOp(X, norm_type, dim); } template inline const mtSpOp var ( const T1& X, const uword norm_type, const uword dim = 0, const typename enable_if::value == true>::result* junk1 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); return mtSpOp(X, norm_type, dim); } template inline typename T1::pod_type var ( const T1& X, const uword norm_type = 0, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return spop_var::var_vec(X, norm_type); } //! @} armadillo-6.500.5/include/armadillo_bits/Cube_bones.hpp0000666000000000000000000005521212633721645021540 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Cube //! @{ struct Cube_prealloc { static const uword mat_ptrs_size = 4; static const uword mem_n_elem = 64; }; //! Dense cube class template class Cube : public BaseCube< eT, Cube > { public: typedef eT elem_type; //!< the type of elements stored in the cube typedef typename get_pod_type::result pod_type; //!< if eT is std::complex, pod_type is T; otherwise pod_type is eT const uword n_rows; //!< number of rows in each slice (read-only) const uword n_cols; //!< number of columns in each slice (read-only) const uword n_elem_slice; //!< number of elements in each slice (read-only) const uword n_slices; //!< number of slices in the cube (read-only) const uword n_elem; //!< number of elements in the cube (read-only) const uword mem_state; // mem_state = 0: normal cube which manages its own memory // mem_state = 1: use auxiliary memory until a size change // mem_state = 2: use auxiliary memory and don't allow the number of elements to be changed // mem_state = 3: fixed size (eg. via template based size specification) arma_aligned const eT* const mem; //!< pointer to the memory used for storing elements (memory is read-only) protected: arma_aligned const Mat** const mat_ptrs; arma_align_mem Mat* mat_ptrs_local[ Cube_prealloc::mat_ptrs_size ]; arma_align_mem eT mem_local[ Cube_prealloc::mem_n_elem ]; // local storage, for small cubes public: inline ~Cube(); inline Cube(); inline explicit Cube(const uword in_rows, const uword in_cols, const uword in_slices); inline explicit Cube(const SizeCube& s); template inline Cube(const uword in_rows, const uword in_cols, const uword in_slices, const fill::fill_class& f); template inline Cube(const SizeCube& s, const fill::fill_class& f); #if defined(ARMA_USE_CXX11) inline Cube(Cube&& m); inline const Cube& operator=(Cube&& m); #endif inline Cube( eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices, const bool copy_aux_mem = true, const bool strict = false, const bool prealloc_mat = false); inline Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices); arma_inline const Cube& operator=(const eT val); arma_inline const Cube& operator+=(const eT val); arma_inline const Cube& operator-=(const eT val); arma_inline const Cube& operator*=(const eT val); arma_inline const Cube& operator/=(const eT val); inline Cube(const Cube& m); inline const Cube& operator=(const Cube& m); inline const Cube& operator+=(const Cube& m); inline const Cube& operator-=(const Cube& m); inline const Cube& operator%=(const Cube& m); inline const Cube& operator/=(const Cube& m); template inline explicit Cube(const BaseCube& A, const BaseCube& B); inline Cube(const subview_cube& X); inline const Cube& operator=(const subview_cube& X); inline const Cube& operator+=(const subview_cube& X); inline const Cube& operator-=(const subview_cube& X); inline const Cube& operator%=(const subview_cube& X); inline const Cube& operator/=(const subview_cube& X); arma_inline Mat& slice(const uword in_slice); arma_inline const Mat& slice(const uword in_slice) const; arma_inline subview_cube slices(const uword in_slice1, const uword in_slice2); arma_inline const subview_cube slices(const uword in_slice1, const uword in_slice2) const; arma_inline subview_cube subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2); arma_inline const subview_cube subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) const; inline subview_cube subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s); inline const subview_cube subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const; inline subview_cube subcube(const span& row_span, const span& col_span, const span& slice_span); inline const subview_cube subcube(const span& row_span, const span& col_span, const span& slice_span) const; inline subview_cube operator()(const span& row_span, const span& col_span, const span& slice_span); inline const subview_cube operator()(const span& row_span, const span& col_span, const span& slice_span) const; inline subview_cube operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s); inline const subview_cube operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const; arma_inline subview_cube tube(const uword in_row1, const uword in_col1); arma_inline const subview_cube tube(const uword in_row1, const uword in_col1) const; arma_inline subview_cube tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); arma_inline const subview_cube tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; arma_inline subview_cube tube(const uword in_row1, const uword in_col1, const SizeMat& s); arma_inline const subview_cube tube(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline subview_cube tube(const span& row_span, const span& col_span); inline const subview_cube tube(const span& row_span, const span& col_span) const; template arma_inline subview_elem1 elem(const Base& a); template arma_inline const subview_elem1 elem(const Base& a) const; template arma_inline subview_elem1 operator()(const Base& a); template arma_inline const subview_elem1 operator()(const Base& a) const; arma_inline subview_cube_each1 each_slice(); arma_inline const subview_cube_each1 each_slice() const; template inline subview_cube_each2 each_slice(const Base& indices); template inline const subview_cube_each2 each_slice(const Base& indices) const; #if defined(ARMA_USE_CXX11) inline const Cube& each_slice(const std::function< void( Mat&) >& F); inline const Cube& each_slice(const std::function< void(const Mat&) >& F) const; #endif inline void shed_slice(const uword slice_num); inline void shed_slices(const uword in_slice1, const uword in_slice2); inline void insert_slices(const uword slice_num, const uword N, const bool set_to_zero = true); template inline void insert_slices(const uword row_num, const BaseCube& X); template inline Cube(const GenCube& X); template inline const Cube& operator=(const GenCube& X); template inline const Cube& operator+=(const GenCube& X); template inline const Cube& operator-=(const GenCube& X); template inline const Cube& operator%=(const GenCube& X); template inline const Cube& operator/=(const GenCube& X); template inline Cube(const OpCube& X); template inline const Cube& operator=(const OpCube& X); template inline const Cube& operator+=(const OpCube& X); template inline const Cube& operator-=(const OpCube& X); template inline const Cube& operator%=(const OpCube& X); template inline const Cube& operator/=(const OpCube& X); template inline Cube(const eOpCube& X); template inline const Cube& operator=(const eOpCube& X); template inline const Cube& operator+=(const eOpCube& X); template inline const Cube& operator-=(const eOpCube& X); template inline const Cube& operator%=(const eOpCube& X); template inline const Cube& operator/=(const eOpCube& X); template inline Cube(const mtOpCube& X); template inline const Cube& operator=(const mtOpCube& X); template inline const Cube& operator+=(const mtOpCube& X); template inline const Cube& operator-=(const mtOpCube& X); template inline const Cube& operator%=(const mtOpCube& X); template inline const Cube& operator/=(const mtOpCube& X); template inline Cube(const GlueCube& X); template inline const Cube& operator=(const GlueCube& X); template inline const Cube& operator+=(const GlueCube& X); template inline const Cube& operator-=(const GlueCube& X); template inline const Cube& operator%=(const GlueCube& X); template inline const Cube& operator/=(const GlueCube& X); template inline Cube(const eGlueCube& X); template inline const Cube& operator=(const eGlueCube& X); template inline const Cube& operator+=(const eGlueCube& X); template inline const Cube& operator-=(const eGlueCube& X); template inline const Cube& operator%=(const eGlueCube& X); template inline const Cube& operator/=(const eGlueCube& X); template inline Cube(const mtGlueCube& X); template inline const Cube& operator=(const mtGlueCube& X); template inline const Cube& operator+=(const mtGlueCube& X); template inline const Cube& operator-=(const mtGlueCube& X); template inline const Cube& operator%=(const mtGlueCube& X); template inline const Cube& operator/=(const mtGlueCube& X); arma_inline arma_warn_unused const eT& at_alt (const uword i) const; arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at(const uword i); arma_inline arma_warn_unused const eT& at(const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col, const uword in_slice) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col, const uword in_slice) const; arma_inline const Cube& operator++(); arma_inline void operator++(int); arma_inline const Cube& operator--(); arma_inline void operator--(int); arma_inline arma_warn_unused bool is_finite() const; arma_inline arma_warn_unused bool is_empty() const; inline arma_warn_unused bool has_inf() const; inline arma_warn_unused bool has_nan() const; arma_inline arma_warn_unused bool in_range(const uword i) const; arma_inline arma_warn_unused bool in_range(const span& x) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice) const; inline arma_warn_unused bool in_range(const span& row_span, const span& col_span, const span& slice_span) const; inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice, const SizeCube& s) const; arma_inline arma_warn_unused eT* memptr(); arma_inline arma_warn_unused const eT* memptr() const; arma_inline arma_warn_unused eT* slice_memptr(const uword slice); arma_inline arma_warn_unused const eT* slice_memptr(const uword slice) const; arma_inline arma_warn_unused eT* slice_colptr(const uword in_slice, const uword in_col); arma_inline arma_warn_unused const eT* slice_colptr(const uword in_slice, const uword in_col) const; inline void impl_print( const std::string& extra_text) const; inline void impl_print(std::ostream& user_stream, const std::string& extra_text) const; inline void impl_raw_print( const std::string& extra_text) const; inline void impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const; inline void set_size(const uword in_rows, const uword in_cols, const uword in_slices); inline void reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim = 0); inline void resize(const uword in_rows, const uword in_cols, const uword in_slices); inline void set_size(const SizeCube& s); inline void reshape(const SizeCube& s); inline void resize(const SizeCube& s); template inline void copy_size(const Cube& m); template inline const Cube& for_each(functor F); template inline const Cube& for_each(functor F) const; template inline const Cube& transform(functor F); template inline const Cube& imbue(functor F); inline const Cube& fill(const eT val); inline const Cube& zeros(); inline const Cube& zeros(const uword in_rows, const uword in_cols, const uword in_slices); inline const Cube& zeros(const SizeCube& s); inline const Cube& ones(); inline const Cube& ones(const uword in_rows, const uword in_cols, const uword in_slices); inline const Cube& ones(const SizeCube& s); inline const Cube& randu(); inline const Cube& randu(const uword in_rows, const uword in_cols, const uword in_slices); inline const Cube& randu(const SizeCube& s); inline const Cube& randn(); inline const Cube& randn(const uword in_rows, const uword in_cols, const uword in_slices); inline const Cube& randn(const SizeCube& s); inline void reset(); template inline void set_real(const BaseCube& X); template inline void set_imag(const BaseCube& X); inline arma_warn_unused eT min() const; inline arma_warn_unused eT max() const; inline eT min(uword& index_of_min_val) const; inline eT max(uword& index_of_max_val) const; inline eT min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const; inline eT max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const; inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const; inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const; inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true); inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true); inline bool quiet_save(const std::string name, const file_type type = arma_binary) const; inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const; inline bool quiet_load(const std::string name, const file_type type = auto_detect); inline bool quiet_load( std::istream& is, const file_type type = auto_detect); // iterators typedef eT* iterator; typedef const eT* const_iterator; typedef eT* slice_iterator; typedef const eT* const_slice_iterator; inline iterator begin(); inline const_iterator begin() const; inline const_iterator cbegin() const; inline iterator end(); inline const_iterator end() const; inline const_iterator cend() const; inline slice_iterator begin_slice(const uword slice_num); inline const_slice_iterator begin_slice(const uword slice_num) const; inline slice_iterator end_slice(const uword slice_num); inline const_slice_iterator end_slice(const uword slice_num) const; inline void clear(); inline bool empty() const; inline uword size() const; inline void swap(Cube& B); inline void steal_mem(Cube& X); //!< don't use this unless you're writing code internal to Armadillo template class fixed; protected: inline void init_cold(); inline void init_warm(const uword in_rows, const uword in_cols, const uword in_slices); template inline void init(const BaseCube& A, const BaseCube& B); inline void delete_mat(); inline void create_mat(); friend class glue_join; friend class op_reshape; friend class op_resize; friend class subview_cube; public: #ifdef ARMA_EXTRA_CUBE_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_PROTO) #endif }; template template class Cube::fixed : public Cube { private: static const uword fixed_n_elem = fixed_n_rows * fixed_n_cols * fixed_n_slices; static const uword fixed_n_elem_slice = fixed_n_rows * fixed_n_cols; static const bool use_extra = (fixed_n_elem > Cube_prealloc::mem_n_elem); arma_aligned Mat* mat_ptrs_local_extra[ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? fixed_n_slices : 1 ]; arma_align_mem eT mem_local_extra [ use_extra ? fixed_n_elem : 1 ]; arma_inline void mem_setup(); public: inline fixed(); inline fixed(const fixed& X); template inline fixed(const fill::fill_class& f); template inline fixed(const BaseCube& A); template inline fixed(const BaseCube& A, const BaseCube& B); using Cube::operator=; using Cube::operator(); inline const Cube& operator=(const fixed& X); arma_inline arma_warn_unused eT& operator[] (const uword i); arma_inline arma_warn_unused const eT& operator[] (const uword i) const; arma_inline arma_warn_unused eT& at (const uword i); arma_inline arma_warn_unused const eT& at (const uword i) const; arma_inline arma_warn_unused eT& operator() (const uword i); arma_inline arma_warn_unused const eT& operator() (const uword i) const; arma_inline arma_warn_unused eT& at (const uword in_row, const uword in_col, const uword in_slice); arma_inline arma_warn_unused const eT& at (const uword in_row, const uword in_col, const uword in_slice) const; arma_inline arma_warn_unused eT& operator() (const uword in_row, const uword in_col, const uword in_slice); arma_inline arma_warn_unused const eT& operator() (const uword in_row, const uword in_col, const uword in_slice) const; }; class Cube_aux { public: template arma_inline static void prefix_pp(Cube& x); template arma_inline static void prefix_pp(Cube< std::complex >& x); template arma_inline static void postfix_pp(Cube& x); template arma_inline static void postfix_pp(Cube< std::complex >& x); template arma_inline static void prefix_mm(Cube& x); template arma_inline static void prefix_mm(Cube< std::complex >& x); template arma_inline static void postfix_mm(Cube& x); template arma_inline static void postfix_mm(Cube< std::complex >& x); template inline static void set_real(Cube& out, const BaseCube& X); template inline static void set_imag(Cube& out, const BaseCube& X); template inline static void set_real(Cube< std::complex >& out, const BaseCube< T,T1>& X); template inline static void set_imag(Cube< std::complex >& out, const BaseCube< T,T1>& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/mul_gemm.hpp0000666000000000000000000003005412650111756021266 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup gemm //! @{ //! for tiny square matrices, size <= 4x4 template class gemm_emul_tinysq { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); switch(A.n_rows) { case 4: gemv_emul_tinysq::apply( C.colptr(3), A, B.colptr(3), alpha, beta ); case 3: gemv_emul_tinysq::apply( C.colptr(2), A, B.colptr(2), alpha, beta ); case 2: gemv_emul_tinysq::apply( C.colptr(1), A, B.colptr(1), alpha, beta ); case 1: gemv_emul_tinysq::apply( C.colptr(0), A, B.colptr(0), alpha, beta ); default: ; } } }; //! emulation of gemm(), for non-complex matrices only, as it assumes only simple transposes (ie. doesn't do hermitian transposes) template class gemm_emul_large { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (do_trans_A == false) && (do_trans_B == false) ) { arma_aligned podarray tmp(A_n_cols); eT* A_rowdata = tmp.memptr(); for(uword row_A=0; row_A < A_n_rows; ++row_A) { tmp.copy_row(A, row_A); for(uword col_B=0; col_B < B_n_cols; ++col_B) { const eT acc = op_dot::direct_dot_arma(B_n_rows, A_rowdata, B.colptr(col_B)); if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(row_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(row_A,col_B) = acc + beta*C.at(row_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(row_A,col_B) = alpha*acc + beta*C.at(row_A,col_B); } } } } else if( (do_trans_A == true) && (do_trans_B == false) ) { for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const eT* A_coldata = A.colptr(col_A); for(uword col_B=0; col_B < B_n_cols; ++col_B) { const eT acc = op_dot::direct_dot_arma(B_n_rows, A_coldata, B.colptr(col_B)); if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,col_B) = acc + beta*C.at(col_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,col_B) = alpha*acc + beta*C.at(col_A,col_B); } } } } else if( (do_trans_A == false) && (do_trans_B == true) ) { Mat BB; op_strans::apply_mat_noalias(BB, B); gemm_emul_large::apply(C, A, BB, alpha, beta); } else if( (do_trans_A == true) && (do_trans_B == true) ) { // mat B_tmp = trans(B); // dgemm_arma::apply(C, A, B_tmp, alpha, beta); // By using the trans(A)*trans(B) = trans(B*A) equivalency, // transpose operations are not needed arma_aligned podarray tmp(B.n_cols); eT* B_rowdata = tmp.memptr(); for(uword row_B=0; row_B < B_n_rows; ++row_B) { tmp.copy_row(B, row_B); for(uword col_A=0; col_A < A_n_cols; ++col_A) { const eT acc = op_dot::direct_dot_arma(A_n_rows, B_rowdata, A.colptr(col_A)); if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,row_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,row_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,row_B) = acc + beta*C.at(col_A,row_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,row_B) = alpha*acc + beta*C.at(col_A,row_B); } } } } } }; template class gemm_emul { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0), const typename arma_not_cx::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); gemm_emul_large::apply(C, A, B, alpha, beta); } template arma_hot inline static void apply ( Mat& C, const Mat& A, const Mat& B, const eT alpha = eT(1), const eT beta = eT(0), const typename arma_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); // "better than nothing" handling of hermitian transposes for complex number matrices Mat tmp_A; Mat tmp_B; if(do_trans_A) { op_htrans::apply_mat_noalias(tmp_A, A); } if(do_trans_B) { op_htrans::apply_mat_noalias(tmp_B, B); } const Mat& AA = (do_trans_A == false) ? A : tmp_A; const Mat& BB = (do_trans_B == false) ? B : tmp_B; gemm_emul_large::apply(C, AA, BB, alpha, beta); } }; //! \brief //! Wrapper for ATLAS/BLAS dgemm function, using template arguments to control the arguments passed to dgemm. //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) template class gemm { public: template inline static void apply_blas_type( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); if( (A.n_rows <= 4) && (A.n_rows == A.n_cols) && (A.n_rows == B.n_rows) && (B.n_rows == B.n_cols) && (is_cx::no) ) { if(do_trans_B == false) { gemm_emul_tinysq::apply(C, A, B, alpha, beta); } else { Mat BB(B.n_rows, B.n_rows); op_strans::apply_mat_noalias_tinysq(BB, B); gemm_emul_tinysq::apply(C, A, BB, alpha, beta); } } else { #if defined(ARMA_USE_ATLAS) { arma_extra_debug_print("atlas::cblas_gemm()"); arma_debug_assert_atlas_size(A,B); atlas::cblas_gemm ( atlas::CblasColMajor, (do_trans_A) ? ( is_cx::yes ? CblasConjTrans : atlas::CblasTrans ) : atlas::CblasNoTrans, (do_trans_B) ? ( is_cx::yes ? CblasConjTrans : atlas::CblasTrans ) : atlas::CblasNoTrans, C.n_rows, C.n_cols, (do_trans_A) ? A.n_rows : A.n_cols, (use_alpha) ? alpha : eT(1), A.mem, (do_trans_A) ? A.n_rows : C.n_rows, B.mem, (do_trans_B) ? C.n_cols : ( (do_trans_A) ? A.n_rows : A.n_cols ), (use_beta) ? beta : eT(0), C.memptr(), C.n_rows ); } #elif defined(ARMA_USE_BLAS) { arma_extra_debug_print("blas::gemm()"); arma_debug_assert_blas_size(A,B); const char trans_A = (do_trans_A) ? ( is_cx::yes ? 'C' : 'T' ) : 'N'; const char trans_B = (do_trans_B) ? ( is_cx::yes ? 'C' : 'T' ) : 'N'; const blas_int m = blas_int(C.n_rows); const blas_int n = blas_int(C.n_cols); const blas_int k = (do_trans_A) ? blas_int(A.n_rows) : blas_int(A.n_cols); const eT local_alpha = (use_alpha) ? alpha : eT(1); const blas_int lda = (do_trans_A) ? k : m; const blas_int ldb = (do_trans_B) ? n : k; const eT local_beta = (use_beta) ? beta : eT(0); arma_extra_debug_print( arma_str::format("blas::gemm(): trans_A = %c") % trans_A ); arma_extra_debug_print( arma_str::format("blas::gemm(): trans_B = %c") % trans_B ); blas::gemm ( &trans_A, &trans_B, &m, &n, &k, &local_alpha, A.mem, &lda, B.mem, &ldb, &local_beta, C.memptr(), &m ); } #else { gemm_emul::apply(C,A,B,alpha,beta); } #endif } } //! immediate multiplication of matrices A and B, storing the result in C template inline static void apply( Mat& C, const TA& A, const TB& B, const eT alpha = eT(1), const eT beta = eT(0) ) { gemm_emul::apply(C,A,B,alpha,beta); } template arma_inline static void apply ( Mat& C, const TA& A, const TB& B, const float alpha = float(1), const float beta = float(0) ) { gemm::apply_blas_type(C,A,B,alpha,beta); } template arma_inline static void apply ( Mat& C, const TA& A, const TB& B, const double alpha = double(1), const double beta = double(0) ) { gemm::apply_blas_type(C,A,B,alpha,beta); } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const TB& B, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { gemm::apply_blas_type(C,A,B,alpha,beta); } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const TB& B, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { gemm::apply_blas_type(C,A,B,alpha,beta); } }; //! @} armadillo-6.500.5/include/armadillo_bits/op_sort_index_bones.hpp0000666000000000000000000000314412620272703023523 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_sort_index //! @{ class op_sort_index { public: template static inline bool apply_noalias(Mat& out, const Proxy& P, const uword sort_type); template static inline void apply(Mat& out, const mtOp& in); }; class op_stable_sort_index { public: template static inline bool apply_noalias(Mat& out, const Proxy& P, const uword sort_type); template static inline void apply(Mat& out, const mtOp& in); }; template struct arma_sort_index_packet { T1 val; T2 index; }; class arma_sort_index_helper_ascend { public: template arma_inline bool operator() (const arma_sort_index_packet& A, const arma_sort_index_packet& B) const { return (A.val < B.val); } }; class arma_sort_index_helper_descend { public: template arma_inline bool operator() (const arma_sort_index_packet& A, const arma_sort_index_packet& B) const { return (A.val > B.val); } }; //! @} armadillo-6.500.5/include/armadillo_bits/spop_misc_meat.hpp0000666000000000000000000001334012620272703022462 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spop_misc //! @{ namespace priv { template struct functor_scalar_times { const eT k; functor_scalar_times(const eT in_k) : k(in_k) {} arma_inline eT operator()(const eT val) const { return val * k; } }; } template inline void spop_scalar_times::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; if(in.aux != eT(0)) { out.init_xform(in.m, priv::functor_scalar_times(in.aux)); } else { const SpProxy P(in.m); out.zeros( P.get_n_rows(), P.get_n_cols() ); } } namespace priv { struct functor_square { template arma_inline eT operator()(const eT val) const { return val*val; } }; } template inline void spop_square::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); out.init_xform(in.m, priv::functor_square()); } namespace priv { struct functor_sqrt { template arma_inline eT operator()(const eT val) const { return eop_aux::sqrt(val); } }; } template inline void spop_sqrt::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); out.init_xform(in.m, priv::functor_sqrt()); } namespace priv { struct functor_abs { template arma_inline eT operator()(const eT val) const { return eop_aux::arma_abs(val); } }; } template inline void spop_abs::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); out.init_xform(in.m, priv::functor_abs()); } namespace priv { struct functor_cx_abs { template arma_inline T operator()(const std::complex& val) const { return std::abs(val); } }; } template inline void spop_cx_abs::apply(SpMat& out, const mtSpOp& in) { arma_extra_debug_sigprint(); out.init_xform_mt(in.m, priv::functor_cx_abs()); } namespace priv { struct functor_real { template arma_inline T operator()(const std::complex& val) const { return val.real(); } }; } template inline void spop_real::apply(SpMat& out, const mtSpOp& in) { arma_extra_debug_sigprint(); out.init_xform_mt(in.m, priv::functor_real()); } namespace priv { struct functor_imag { template arma_inline T operator()(const std::complex& val) const { return val.imag(); } }; } template inline void spop_imag::apply(SpMat& out, const mtSpOp& in) { arma_extra_debug_sigprint(); out.init_xform_mt(in.m, priv::functor_imag()); } namespace priv { struct functor_conj { template arma_inline eT operator()(const eT val) const { return eop_aux::conj(val); } }; } template inline void spop_conj::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); out.init_xform(in.m, priv::functor_conj()); } template inline void spop_repmat::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_spmat U(in.m); const SpMat& X = U.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword copies_per_row = in.aux_uword_a; const uword copies_per_col = in.aux_uword_b; // out.set_size(X_n_rows * copies_per_row, X_n_cols * copies_per_col); // // const uword out_n_rows = out.n_rows; // const uword out_n_cols = out.n_cols; // // if( (out_n_rows > 0) && (out_n_cols > 0) ) // { // for(uword col = 0; col < out_n_cols; col += X_n_cols) // for(uword row = 0; row < out_n_rows; row += X_n_rows) // { // out.submat(row, col, row+X_n_rows-1, col+X_n_cols-1) = X; // } // } SpMat tmp(X_n_rows * copies_per_row, X_n_cols); if(tmp.n_elem > 0) { for(uword row = 0; row < tmp.n_rows; row += X_n_rows) { tmp.submat(row, 0, row+X_n_rows-1, X_n_cols-1) = X; } } // tmp contains copies of the input matrix, so no need to check for aliasing out.set_size(X_n_rows * copies_per_row, X_n_cols * copies_per_col); const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; if( (out_n_rows > 0) && (out_n_cols > 0) ) { for(uword col = 0; col < out_n_cols; col += X_n_cols) { out.submat(0, col, out_n_rows-1, col+X_n_cols-1) = tmp; } } } template inline void spop_reshape::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); out = in.m; out.reshape(in.aux_uword_a, in.aux_uword_b); } template inline void spop_resize::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); out = in.m; out.resize(in.aux_uword_a, in.aux_uword_b); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_det.hpp0000666000000000000000000000621112624457506020730 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_det //! @{ template inline arma_warn_unused typename enable_if2< is_supported_blas_type::value, typename T1::elem_type >::result det ( const Base& X ) { arma_extra_debug_sigprint(); return auxlib::det(X.get_ref()); } template inline arma_warn_unused typename T1::elem_type det ( const Op& X ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const diagmat_proxy A(X.m); arma_debug_check( (A.n_rows != A.n_cols), "det(): given matrix must be square sized" ); const uword N = (std::min)(A.n_rows, A.n_cols); eT val1 = eT(1); eT val2 = eT(1); uword i,j; for(i=0, j=1; j inline arma_warn_unused typename T1::elem_type det ( const Op& X ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.m); const uword N = P.get_n_rows(); arma_debug_check( (N != P.get_n_cols()), "det(): given matrix must be square sized" ); eT val1 = eT(1); eT val2 = eT(1); uword i,j; for(i=0, j=1; j inline arma_warn_unused typename enable_if2< is_supported_blas_type::value, typename T1::elem_type >::result det ( const Op& X ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const eT tmp = det(X.m); if(tmp == eT(0)) { arma_debug_warn("det(): denominator is zero" ); } return eT(1) / tmp; } template inline arma_warn_unused typename enable_if2< is_supported_blas_type::value, typename T1::elem_type >::result det ( const Base& X, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return det(X.get_ref()); } template inline arma_warn_unused typename enable_if2< is_supported_blas_type::value, typename T1::elem_type >::result det ( const Base& X, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return det(X.get_ref()); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & det(const T& x) { return x; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_norm.hpp0000666000000000000000000001517412620272703021125 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_norm //! @{ template inline arma_warn_unused typename enable_if2< is_arma_type::value, typename T1::pod_type >::result norm ( const T1& X, const uword k = uword(2), const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; const Proxy P(X); if(P.get_n_elem() == 0) { return T(0); } const bool is_vec = (T1::is_row) || (T1::is_col) || (P.get_n_rows() == 1) || (P.get_n_cols() == 1); if(is_vec) { switch(k) { case 1: return op_norm::vec_norm_1(P); break; case 2: return op_norm::vec_norm_2(P); break; default: { arma_debug_check( (k == 0), "norm(): k must be greater than zero" ); return op_norm::vec_norm_k(P, int(k)); } } } else { switch(k) { case 1: return op_norm::mat_norm_1(P); break; case 2: return op_norm::mat_norm_2(P); break; default: arma_stop("norm(): unsupported matrix norm type"); return T(0); } } return T(0); // prevent erroneous compiler warnings } template inline arma_warn_unused typename enable_if2< is_arma_type::value, typename T1::pod_type >::result norm ( const T1& X, const char* method, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; const Proxy P(X); if(P.get_n_elem() == 0) { return T(0); } const char sig = (method != NULL) ? method[0] : char(0); const bool is_vec = (T1::is_row) || (T1::is_col) || (P.get_n_rows() == 1) || (P.get_n_cols() == 1); if(is_vec) { if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // max norm { return op_norm::vec_norm_max(P); } else if(sig == '-') // min norm { return op_norm::vec_norm_min(P); } else if( (sig == 'f') || (sig == 'F') ) { return op_norm::vec_norm_2(P); } else { arma_stop("norm(): unsupported vector norm type"); return T(0); } } else { if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // inf norm { return op_norm::mat_norm_inf(P); } else if( (sig == 'f') || (sig == 'F') ) { return op_norm::vec_norm_2(P); } else { arma_stop("norm(): unsupported matrix norm type"); return T(0); } } } // // norms for sparse matrices template inline arma_warn_unused typename enable_if2< is_arma_sparse_type::value, typename T1::pod_type >::result norm ( const T1& X, const uword k = uword(2), const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const SpProxy P(X); if(P.get_n_nonzero() == 0) { return T(0); } const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1); if(is_vec == true) { const unwrap_spmat::stored_type> tmp(P.Q); const SpMat& A = tmp.M; // create a fake dense vector to allow reuse of code for dense vectors Col fake_vector( access::rwp(A.values), A.n_nonzero, false ); const Proxy< Col > P_fake_vector(fake_vector); switch(k) { case 1: return op_norm::vec_norm_1(P_fake_vector); break; case 2: return op_norm::vec_norm_2(P_fake_vector); break; default: { arma_debug_check( (k == 0), "norm(): k must be greater than zero" ); return op_norm::vec_norm_k(P_fake_vector, int(k)); } } } else { switch(k) { case 1: return op_norm::mat_norm_1(P); break; case 2: return op_norm::mat_norm_2(P); break; default: arma_stop("norm(): unsupported or unimplemented norm type for sparse matrices"); return T(0); } } } template inline arma_warn_unused typename enable_if2< is_arma_sparse_type::value, typename T1::pod_type >::result norm ( const T1& X, const char* method, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const SpProxy P(X); if(P.get_n_nonzero() == 0) { return T(0); } const unwrap_spmat::stored_type> tmp(P.Q); const SpMat& A = tmp.M; // create a fake dense vector to allow reuse of code for dense vectors Col fake_vector( access::rwp(A.values), A.n_nonzero, false ); const Proxy< Col > P_fake_vector(fake_vector); const char sig = (method != NULL) ? method[0] : char(0); const bool is_vec = (P.get_n_rows() == 1) || (P.get_n_cols() == 1); // TODO: (T1::is_row) || (T1::is_col) || ... if(is_vec == true) { if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // max norm { return op_norm::vec_norm_max(P_fake_vector); } else if(sig == '-') // min norm { const T val = op_norm::vec_norm_min(P_fake_vector); if( P.get_n_nonzero() < P.get_n_elem() ) { return (std::min)(T(0), val); } else { return val; } } else if( (sig == 'f') || (sig == 'F') ) { return op_norm::vec_norm_2(P_fake_vector); } else { arma_stop("norm(): unsupported vector norm type"); return T(0); } } else { if( (sig == 'i') || (sig == 'I') || (sig == '+') ) // inf norm { return op_norm::mat_norm_inf(P); } else if( (sig == 'f') || (sig == 'F') ) { return op_norm::vec_norm_2(P_fake_vector); } else { arma_stop("norm(): unsupported matrix norm type"); return T(0); } } } //! @} armadillo-6.500.5/include/armadillo_bits/op_toeplitz_bones.hpp0000666000000000000000000000137512620272703023223 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_toeplitz //! @{ class op_toeplitz { public: template inline static void apply(Mat& out, const Op& in); }; class op_toeplitz_c { public: template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_cumsum.hpp0000666000000000000000000000204612620272703021455 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_cumsum //! @{ template arma_inline typename enable_if2 < is_arma_type::value, const Op >::result cumsum(const T1& X) { arma_extra_debug_sigprint(); return Op(X); } template arma_inline typename enable_if2 < is_arma_type::value, const Op >::result cumsum(const T1& X, const uword dim) { arma_extra_debug_sigprint(); return Op(X, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & cumsum(const T& x) { return x; } //! @} armadillo-6.500.5/include/armadillo_bits/op_diff_bones.hpp0000666000000000000000000000156412620272703022261 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_diff //! @{ class op_diff { public: template inline static void apply_noalias(Mat& out, const Mat& X, const uword k, const uword dim); template inline static void apply(Mat& out, const Op& in); }; class op_diff_default { public: template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_hist_bones.hpp0000666000000000000000000000132712620272703022315 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_hist //! @{ class op_hist { public: template inline static void apply_noalias(Mat& out, const Mat& A, const uword n_bins, const bool A_is_row); template inline static void apply(Mat& out, const mtOp& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_sort_meat.hpp0000666000000000000000000001046212620272703022155 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_sort //! @{ template inline void op_sort::direct_sort(eT* X, const uword n_elem, const uword sort_type) { arma_extra_debug_sigprint(); if(sort_type == 0) { arma_ascend_sort_helper comparator; std::sort(&X[0], &X[n_elem], comparator); } else { arma_descend_sort_helper comparator; std::sort(&X[0], &X[n_elem], comparator); } } template inline void op_sort::direct_sort_ascending(eT* X, const uword n_elem) { arma_extra_debug_sigprint(); arma_ascend_sort_helper comparator; std::sort(&X[0], &X[n_elem], comparator); } template inline void op_sort::copy_row(eT* X, const Mat& A, const uword row) { const uword N = A.n_cols; uword i,j; for(i=0, j=1; j inline void op_sort::copy_row(Mat& A, const eT* X, const uword row) { const uword N = A.n_cols; uword i,j; for(i=0, j=1; j inline void op_sort::apply_noalias(Mat& out, const Mat& X, const uword sort_type, const uword dim) { arma_extra_debug_sigprint(); if( (X.n_rows * X.n_cols) <= 1 ) { out = X; return; } arma_debug_check( (sort_type > 1), "sort(): parameter 'sort_type' must be 0 or 1" ); arma_debug_check( (X.has_nan()), "sort(): detected NaN" ); if(dim == 0) // sort the contents of each column { arma_extra_debug_print("op_sort::apply(): dim = 0"); out = X; const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; for(uword col=0; col < n_cols; ++col) { op_sort::direct_sort( out.colptr(col), n_rows, sort_type ); } } else if(dim == 1) // sort the contents of each row { if(X.n_rows == 1) // a row vector { arma_extra_debug_print("op_sort::apply(): dim = 1, vector specific"); out = X; op_sort::direct_sort(out.memptr(), out.n_elem, sort_type); } else // not a row vector { arma_extra_debug_print("op_sort::apply(): dim = 1, generic"); out.copy_size(X); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; podarray tmp_array(n_cols); for(uword row=0; row < n_rows; ++row) { op_sort::copy_row(tmp_array.memptr(), X, row); op_sort::direct_sort( tmp_array.memptr(), n_cols, sort_type ); op_sort::copy_row(out, tmp_array.memptr(), row); } } } } template inline void op_sort::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const quasi_unwrap U(in.m); const Mat& X = U.M; const uword sort_type = in.aux_uword_a; const uword dim = in.aux_uword_b; if(U.is_alias(out)) { Mat tmp; op_sort::apply_noalias(tmp, X, sort_type, dim); out.steal_mem(tmp); } else { op_sort::apply_noalias(out, X, sort_type, dim); } } template inline void op_sort_default::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const quasi_unwrap U(in.m); const Mat& X = U.M; const uword sort_type = in.aux_uword_a; const uword dim = (T1::is_row) ? 1 : 0; if(U.is_alias(out)) { Mat tmp; op_sort::apply_noalias(tmp, X, sort_type, dim); out.steal_mem(tmp); } else { op_sort::apply_noalias(out, X, sort_type, dim); } } //! @} armadillo-6.500.5/include/armadillo_bits/gmm_diag_bones.hpp0000666000000000000000000002105012646450677022427 0ustar rootroot// Copyright (C) 2014-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup gmm_diag //! @{ struct gmm_dist_mode { const uword id; inline explicit gmm_dist_mode(const uword in_id) : id(in_id) {} }; inline bool operator==(const gmm_dist_mode& a, const gmm_dist_mode& b) { return (a.id == b.id); } inline bool operator!=(const gmm_dist_mode& a, const gmm_dist_mode& b) { return (a.id != b.id); } struct gmm_dist_eucl : public gmm_dist_mode { inline gmm_dist_eucl() : gmm_dist_mode(1) {} }; struct gmm_dist_maha : public gmm_dist_mode { inline gmm_dist_maha() : gmm_dist_mode(2) {} }; struct gmm_dist_prob : public gmm_dist_mode { inline gmm_dist_prob() : gmm_dist_mode(3) {} }; static const gmm_dist_eucl eucl_dist; static const gmm_dist_maha maha_dist; static const gmm_dist_prob prob_dist; struct gmm_seed_mode { const uword id; inline explicit gmm_seed_mode(const uword in_id) : id(in_id) {} }; inline bool operator==(const gmm_seed_mode& a, const gmm_seed_mode& b) { return (a.id == b.id); } inline bool operator!=(const gmm_seed_mode& a, const gmm_seed_mode& b) { return (a.id != b.id); } struct gmm_seed_keep_existing : public gmm_seed_mode { inline gmm_seed_keep_existing() : gmm_seed_mode(1) {} }; struct gmm_seed_static_subset : public gmm_seed_mode { inline gmm_seed_static_subset() : gmm_seed_mode(2) {} }; struct gmm_seed_static_spread : public gmm_seed_mode { inline gmm_seed_static_spread() : gmm_seed_mode(3) {} }; struct gmm_seed_random_subset : public gmm_seed_mode { inline gmm_seed_random_subset() : gmm_seed_mode(4) {} }; struct gmm_seed_random_spread : public gmm_seed_mode { inline gmm_seed_random_spread() : gmm_seed_mode(5) {} }; static const gmm_seed_keep_existing keep_existing; static const gmm_seed_static_subset static_subset; static const gmm_seed_static_spread static_spread; static const gmm_seed_random_subset random_subset; static const gmm_seed_random_spread random_spread; namespace gmm_priv { struct gmm_empty_arg {}; #if defined(_OPENMP) struct arma_omp_state { const int orig_dynamic_state; inline arma_omp_state() : orig_dynamic_state(omp_get_dynamic()) { omp_set_dynamic(0); } inline ~arma_omp_state() { omp_set_dynamic(orig_dynamic_state); } }; #else struct arma_omp_state {}; #endif template class gmm_diag { public: arma_aligned const Mat means; arma_aligned const Mat dcovs; arma_aligned const Row hefts; // // inline ~gmm_diag(); inline gmm_diag(); inline gmm_diag(const gmm_diag& x); inline const gmm_diag& operator=(const gmm_diag& x); inline gmm_diag(const uword in_n_dims, const uword in_n_gaus); inline void reset(const uword in_n_dims, const uword in_n_gaus); inline void reset(); template inline void set_params(const Base& in_means, const Base& in_dcovs, const Base& in_hefts); template inline void set_means(const Base& in_means); template inline void set_dcovs(const Base& in_dcovs); template inline void set_hefts(const Base& in_hefts); inline uword n_dims() const; inline uword n_gaus() const; inline bool load(const std::string name); inline bool save(const std::string name) const; inline Col generate() const; inline Mat generate(const uword N) const; template inline eT log_p(const T1& expr, const gmm_empty_arg& junk1 = gmm_empty_arg(), typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == true ))>::result* junk2 = 0) const; template inline eT log_p(const T1& expr, const uword gaus_id, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == true ))>::result* junk2 = 0) const; template inline Row log_p(const T1& expr, const gmm_empty_arg& junk1 = gmm_empty_arg(), typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == false))>::result* junk2 = 0) const; template inline Row log_p(const T1& expr, const uword gaus_id, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == false))>::result* junk2 = 0) const; template inline eT avg_log_p(const Base& expr) const; template inline eT avg_log_p(const Base& expr, const uword gaus_id) const; template inline uword assign(const T1& expr, const gmm_dist_mode& dist, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == true ))>::result* junk = 0) const; template inline urowvec assign(const T1& expr, const gmm_dist_mode& dist, typename enable_if<((is_arma_type::value) && (resolves_to_colvector::value == false))>::result* junk = 0) const; template inline urowvec raw_hist(const Base& expr, const gmm_dist_mode& dist_mode) const; template inline Row norm_hist(const Base& expr, const gmm_dist_mode& dist_mode) const; template inline bool learn ( const Base& data, const uword n_gaus, const gmm_dist_mode& dist_mode, const gmm_seed_mode& seed_mode, const uword km_iter, const uword em_iter, const eT var_floor, const bool print_mode ); template inline bool kmeans_wrapper ( Mat& user_means, const Base& data, const uword n_gaus, const gmm_seed_mode& seed_mode, const uword km_iter, const bool print_mode ); // protected: arma_aligned Row log_det_etc; arma_aligned Row log_hefts; arma_aligned Col mah_aux; // inline void init(const gmm_diag& x); inline void init(const uword in_n_dim, const uword in_n_gaus); inline void init_constants(); inline umat internal_gen_boundaries(const uword N) const; inline eT internal_scalar_log_p(const eT* x ) const; inline eT internal_scalar_log_p(const eT* x, const uword gaus_id) const; template inline Row internal_vec_log_p(const T1& X ) const; template inline Row internal_vec_log_p(const T1& X, const uword gaus_id) const; template inline eT internal_avg_log_p(const T1& X ) const; template inline eT internal_avg_log_p(const T1& X, const uword gaus_id) const; template inline uword internal_scalar_assign(const T1& X, const gmm_dist_mode& dist_mode) const; template inline void internal_vec_assign(urowvec& out, const T1& X, const gmm_dist_mode& dist_mode) const; inline void internal_raw_hist(urowvec& hist, const Mat& X, const gmm_dist_mode& dist_mode) const; // template inline void generate_initial_means(const Mat& X, const gmm_seed_mode& seed); template inline void generate_initial_dcovs_and_hefts(const Mat& X, const eT var_floor); template inline bool km_iterate(const Mat& X, const uword max_iter, const bool verbose, const char* signature); template inline void km_update_stats(const Mat& X, const uword start_index, const uword end_index, const Mat& old_means, field< running_mean_vec >& running_means) const; // inline bool em_iterate(const Mat& X, const uword max_iter, const eT var_floor, const bool verbose); inline void em_update_params(const Mat& X, const umat& boundaries, field< Mat >& t_acc_means, field< Mat >& t_acc_dcovs, field< Col >& t_acc_norm_lhoods, field< Col >& t_gaus_log_lhoods, Col& t_progress_log_lhoods); inline void em_generate_acc(const Mat& X, const uword start_index, const uword end_index, Mat& acc_means, Mat& acc_dcovs, Col& acc_norm_lhoods, Col& gaus_log_lhoods, eT& progress_log_lhood) const; inline void em_fix_params(const eT var_floor); }; } typedef gmm_priv::gmm_diag gmm_diag; typedef gmm_priv::gmm_diag fgmm_diag; //! @} armadillo-6.500.5/include/armadillo_bits/fn_spones.hpp0000666000000000000000000000162512620272703021455 0ustar rootroot// Copyright (C) 2012-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_spones //! @{ //! Generate a sparse matrix with the non-zero values in the same locations as in the given sparse matrix X, //! with the non-zero values set to one template inline SpMat spones(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; SpMat out( X.get_ref() ); arrayops::inplace_set( access::rwp(out.values), eT(1), out.n_nonzero ); return out; } //! @} armadillo-6.500.5/include/armadillo_bits/xvec_htrans_meat.hpp0000666000000000000000000000333412620272703023014 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup xvec_htrans //! @{ template inline xvec_htrans::xvec_htrans(const eT* const in_mem, const uword in_n_rows, const uword in_n_cols) : mem (in_mem ) , n_rows(in_n_cols ) // deliberately swapped , n_cols(in_n_rows ) , n_elem(in_n_rows*in_n_cols) { arma_extra_debug_sigprint(); } template inline void xvec_htrans::extract(Mat& out) const { arma_extra_debug_sigprint(); // NOTE: this function assumes that matrix 'out' has already been set to the correct size const eT* in_mem = mem; eT* out_mem = out.memptr(); const uword N = n_elem; for(uword ii=0; ii < N; ++ii) { out_mem[ii] = access::alt_conj( in_mem[ii] ); } } template inline eT xvec_htrans::operator[](const uword ii) const { return access::alt_conj( mem[ii] ); } template inline eT xvec_htrans::at_alt(const uword ii) const { return access::alt_conj( mem[ii] ); } template inline eT xvec_htrans::at(const uword in_row, const uword in_col) const { //return (n_rows == 1) ? access::alt_conj( mem[in_col] ) : access::alt_conj( mem[in_row] ); return access::alt_conj( mem[in_row + in_col] ); // either in_row or in_col must be zero, as we're storing a vector } //! @} armadillo-6.500.5/include/armadillo_bits/field_meat.hpp0000666000000000000000000016773212650111756021573 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ian Cullinan //! \addtogroup field //! @{ template inline field::~field() { arma_extra_debug_sigprint_this(this); delete_objects(); if(n_elem > field_prealloc_n_elem::val) { delete [] mem; } if(arma_config::debug == true) { // try to expose buggy user code that accesses deleted objects mem = 0; } } template inline field::field() : n_rows(0) , n_cols(0) , n_slices(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); } //! construct a field from a given field template inline field::field(const field& x) : n_rows(0) , n_cols(0) , n_slices(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint(arma_str::format("this = %x x = %x") % this % &x); init(x); } //! construct a field from a given field template inline const field& field::operator=(const field& x) { arma_extra_debug_sigprint(); init(x); return *this; } //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation) template inline field::field(const subview_field& X) : n_rows(0) , n_cols(0) , n_slices(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); this->operator=(X); } //! construct a field from subview_field (e.g. construct a field from a delayed subfield operation) template inline const field& field::operator=(const subview_field& X) { arma_extra_debug_sigprint(); subview_field::extract(*this, X); return *this; } //! construct the field with the specified number of elements, //! assuming a column-major layout template inline field::field(const uword n_elem_in) : n_rows(0) , n_cols(0) , n_slices(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); init(n_elem_in, 1); } //! construct the field with the specified dimensions template inline field::field(const uword n_rows_in, const uword n_cols_in) : n_rows(0) , n_cols(0) , n_slices(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); init(n_rows_in, n_cols_in); } //! construct the field with the specified dimensions template inline field::field(const uword n_rows_in, const uword n_cols_in, const uword n_slices_in) : n_rows(0) , n_cols(0) , n_slices(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); init(n_rows_in, n_cols_in, n_slices_in); } template inline field::field(const SizeMat& s) : n_rows(0) , n_cols(0) , n_slices(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); init(s.n_rows, s.n_cols); } template inline field::field(const SizeCube& s) : n_rows(0) , n_cols(0) , n_slices(0) , n_elem(0) , mem(0) { arma_extra_debug_sigprint_this(this); init(s.n_rows, s.n_cols, s.n_slices); } //! change the field to have the specified number of elements, //! assuming a column-major layout (data is not preserved) template inline void field::set_size(const uword n_elem_in) { arma_extra_debug_sigprint(arma_str::format("n_elem_in = %d") % n_elem_in); init(n_elem_in, 1); } //! change the field to have the specified dimensions (data is not preserved) template inline void field::set_size(const uword n_rows_in, const uword n_cols_in) { arma_extra_debug_sigprint(arma_str::format("n_rows_in = %d, n_cols_in = %d") % n_rows_in % n_cols_in); init(n_rows_in, n_cols_in); } //! change the field to have the specified dimensions (data is not preserved) template inline void field::set_size(const uword n_rows_in, const uword n_cols_in, const uword n_slices_in) { arma_extra_debug_sigprint(arma_str::format("n_rows_in = %d, n_cols_in = %d, n_slices_in = %d") % n_rows_in % n_cols_in % n_slices_in); init(n_rows_in, n_cols_in, n_slices_in); } template inline void field::set_size(const SizeMat& s) { init(s.n_rows, s.n_cols); } template inline void field::set_size(const SizeCube& s) { init(s.n_rows, s.n_cols, s.n_slices); } #if defined(ARMA_USE_CXX11) template inline field::field(const std::initializer_list& list) : n_rows (0) , n_cols (0) , n_slices(0) , n_elem (0) { arma_extra_debug_sigprint_this(this); (*this).operator=(list); } template inline const field& field::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); const uword N = uword(list.size()); set_size(1, N); const oT* item_ptr = list.begin(); for(uword i=0; i inline field::field(const std::initializer_list< std::initializer_list >& list) : n_rows (0) , n_cols (0) , n_slices(0) , n_elem (0) { arma_extra_debug_sigprint_this(this); (*this).operator=(list); } template inline const field& field::operator=(const std::initializer_list< std::initializer_list >& list) { arma_extra_debug_sigprint(); uword x_n_rows = uword(list.size()); uword x_n_cols = 0; bool x_n_cols_found = false; auto it = list.begin(); auto it_end = list.end(); for(; it != it_end; ++it) { if(x_n_cols_found == false) { x_n_cols = uword( (*it).size() ); x_n_cols_found = true; } else { arma_check( (uword((*it).size()) != x_n_cols), "Mat::init(): inconsistent number of columns in initialiser list" ); } } field& t = (*this); t.set_size(x_n_rows, x_n_cols); uword row_num = 0; auto row_it = list.begin(); auto row_it_end = list.end(); for(; row_it != row_it_end; ++row_it) { uword col_num = 0; auto col_it = (*row_it).begin(); auto col_it_end = (*row_it).end(); for(; col_it != col_it_end; ++col_it) { t.at(row_num, col_num) = (*col_it); ++col_num; } ++row_num; } return *this; } template inline field::field(field&& X) : n_rows (X.n_rows ) , n_cols (X.n_cols ) , n_slices(X.n_slices) , n_elem (X.n_elem ) { arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); if(n_elem > field_prealloc_n_elem::val) { mem = X.mem; } else { arrayops::copy(&mem_local[0], &X.mem_local[0], n_elem); mem = mem_local; } access::rw(X.n_rows ) = 0; access::rw(X.n_cols ) = 0; access::rw(X.n_slices) = 0; access::rw(X.n_elem ) = 0; access::rw(X.mem ) = 0; } template inline const field& field::operator=(field&& X) { arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); access::rw(n_rows ) = X.n_rows; access::rw(n_cols ) = X.n_cols; access::rw(n_slices) = X.n_slices; access::rw(n_elem ) = X.n_elem; if(n_elem > field_prealloc_n_elem::val) { mem = X.mem; } else { arrayops::copy(&mem_local[0], &X.mem_local[0], n_elem); mem = mem_local; } access::rw(X.n_rows ) = 0; access::rw(X.n_cols ) = 0; access::rw(X.n_elem ) = 0; access::rw(X.n_slices) = 0; access::rw(X.mem ) = 0; return *this; } #endif //! change the field to have the specified dimensions (data is not preserved) template template inline void field::copy_size(const field& x) { arma_extra_debug_sigprint(); init(x.n_rows, x.n_cols, x.n_slices); } //! linear element accessor (treats the field as a vector); no bounds check template arma_inline oT& field::operator[] (const uword i) { return (*mem[i]); } //! linear element accessor (treats the field as a vector); no bounds check template arma_inline const oT& field::operator[] (const uword i) const { return (*mem[i]); } //! linear element accessor (treats the field as a vector); no bounds check template arma_inline oT& field::at(const uword i) { return (*mem[i]); } //! linear element accessor (treats the field as a vector); no bounds check template arma_inline const oT& field::at(const uword i) const { return (*mem[i]); } //! linear element accessor (treats the field as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline oT& field::operator() (const uword i) { arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds"); return (*mem[i]); } //! linear element accessor (treats the field as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline const oT& field::operator() (const uword i) const { arma_debug_check( (i >= n_elem), "field::operator(): index out of bounds"); return (*mem[i]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline oT& field::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds"); return (*mem[in_row + in_col*n_rows]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline const oT& field::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "field::operator(): index out of bounds"); return (*mem[in_row + in_col*n_rows]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline oT& field::operator() (const uword in_row, const uword in_col, const uword in_slice) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices)), "field::operator(): index out of bounds"); return (*mem[in_row + in_col*n_rows + in_slice*(n_rows*n_cols)]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline const oT& field::operator() (const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices)), "field::operator(): index out of bounds"); return (*mem[in_row + in_col*n_rows + in_slice*(n_rows*n_cols)]); } //! element accessor; no bounds check template arma_inline oT& field::at(const uword in_row, const uword in_col) { return (*mem[in_row + in_col*n_rows]); } //! element accessor; no bounds check template arma_inline const oT& field::at(const uword in_row, const uword in_col) const { return (*mem[in_row + in_col*n_rows]); } //! element accessor; no bounds check template arma_inline oT& field::at(const uword in_row, const uword in_col, const uword in_slice) { return (*mem[in_row + in_col*n_rows + in_slice*(n_rows*n_cols)]); } //! element accessor; no bounds check template arma_inline const oT& field::at(const uword in_row, const uword in_col, const uword in_slice) const { return (*mem[in_row + in_col*n_rows + in_slice*(n_rows*n_cols)]); } template inline field_injector< field > field::operator<<(const oT& val) { return field_injector< field >(*this, val); } template inline field_injector< field > field::operator<<(const injector_end_of_row<>& x) { return field_injector< field >(*this, x); } //! creation of subview_field (row of a field) template inline subview_field field::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::row(): field must be 2D" ); arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" ); return subview_field(*this, row_num, 0, 1, n_cols); } //! creation of subview_field (row of a field) template inline const subview_field field::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::row(): field must be 2D" ); arma_debug_check( (row_num >= n_rows), "field::row(): row out of bounds" ); return subview_field(*this, row_num, 0, 1, n_cols); } //! creation of subview_field (column of a field) template inline subview_field field::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::col(): field must be 2D" ); arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); return subview_field(*this, 0, col_num, n_rows, 1); } //! creation of subview_field (column of a field) template inline const subview_field field::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::col(): field must be 2D" ); arma_debug_check( (col_num >= n_cols), "field::col(): out of bounds"); return subview_field(*this, 0, col_num, n_rows, 1); } //! creation of subview_field (slice of a field) template inline subview_field field::slice(const uword slice_num) { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "field::slice(): out of bounds"); return subview_field(*this, 0, 0, slice_num, n_rows, n_cols, 1); } //! creation of subview_field (slice of a field) template inline const subview_field field::slice(const uword slice_num) const { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "field::slice(): out of bounds"); return subview_field(*this, 0, 0, slice_num, n_rows, n_cols, 1); } //! creation of subview_field (subfield comprised of specified rows) template inline subview_field field::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::rows(): field must be 2D" ); arma_debug_check ( ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), "field::rows(): indicies out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; return subview_field(*this, in_row1, 0, sub_n_rows, n_cols); } //! creation of subview_field (subfield comprised of specified rows) template inline const subview_field field::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::rows(): field must be 2D" ); arma_debug_check ( ( (in_row1 > in_row2) || (in_row2 >= n_rows) ), "field::rows(): indicies out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; return subview_field(*this, in_row1, 0, sub_n_rows, n_cols); } //! creation of subview_field (subfield comprised of specified columns) template inline subview_field field::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::cols(): field must be 2D" ); arma_debug_check ( ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), "field::cols(): indicies out of bounds or incorrectly used" ); const uword sub_n_cols = in_col2 - in_col1 + 1; return subview_field(*this, 0, in_col1, n_rows, sub_n_cols); } //! creation of subview_field (subfield comprised of specified columns) template inline const subview_field field::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::cols(): field must be 2D" ); arma_debug_check ( ( (in_col1 > in_col2) || (in_col2 >= n_cols) ), "field::cols(): indicies out of bounds or incorrectly used" ); const uword sub_n_cols = in_col2 - in_col1 + 1; return subview_field(*this, 0, in_col1, n_rows, sub_n_cols); } //! creation of subview_field (subfield comprised of specified slices) template inline subview_field field::slices(const uword in_slice1, const uword in_slice2) { arma_extra_debug_sigprint(); arma_debug_check ( ( (in_slice1 > in_slice2) || (in_slice2 >= n_slices) ), "field::slices(): indicies out of bounds or incorrectly used" ); const uword sub_n_slices = in_slice2 - in_slice1 + 1; return subview_field(*this, 0, 0, in_slice1, n_rows, n_cols, sub_n_slices); } //! creation of subview_field (subfield comprised of specified slices) template inline const subview_field field::slices(const uword in_slice1, const uword in_slice2) const { arma_extra_debug_sigprint(); arma_debug_check ( ( (in_slice1 > in_slice2) || (in_slice2 >= n_slices) ), "field::slices(): indicies out of bounds or incorrectly used" ); const uword sub_n_slices = in_slice2 - in_slice1 + 1; return subview_field(*this, 0, 0, in_slice1, n_rows, n_cols, sub_n_slices); } //! creation of subview_field (subfield with arbitrary dimensions) template inline subview_field field::subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::subfield(): field must be 2D" ); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "field::subfield(): indices out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; const uword sub_n_cols = in_col2 - in_col1 + 1; return subview_field(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline const subview_field field::subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::subfield(): field must be 2D" ); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "field::subfield(): indices out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; const uword sub_n_cols = in_col2 - in_col1 + 1; return subview_field(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline subview_field field::subfield(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) || (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices), "field::subfield(): indices out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; const uword sub_n_cols = in_col2 - in_col1 + 1; const uword sub_n_slices = in_slice2 - in_slice1 + 1; return subview_field(*this, in_row1, in_col1, in_slice1, sub_n_rows, sub_n_cols, sub_n_slices); } //! creation of subview_field (subfield with arbitrary dimensions) template inline const subview_field field::subfield(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) || (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices), "field::subfield(): indices out of bounds or incorrectly used" ); const uword sub_n_rows = in_row2 - in_row1 + 1; const uword sub_n_cols = in_col2 - in_col1 + 1; const uword sub_n_slices = in_slice2 - in_slice1 + 1; return subview_field(*this, in_row1, in_col1, in_slice1, sub_n_rows, sub_n_cols, sub_n_slices); } //! creation of subview_field (subfield with arbitrary dimensions) template inline subview_field field::subfield(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::subfield(): field must be 2D" ); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "field::subfield(): indices or size out of bounds" ); return subview_field(*this, in_row1, in_col1, s_n_rows, s_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline const subview_field field::subfield(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::subfield(): field must be 2D" ); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "field::subfield(): indices or size out of bounds" ); return subview_field(*this, in_row1, in_col1, s_n_rows, s_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline subview_field field::subfield(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword l_n_slices = n_slices; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; const uword sub_n_slices = s.n_slices; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || (in_slice1 >= l_n_slices) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols) || ((in_slice1 + sub_n_slices) > l_n_slices)), "field::subfield(): indices or size out of bounds" ); return subview_field(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n_cols, sub_n_slices); } //! creation of subview_field (subfield with arbitrary dimensions) template inline const subview_field field::subfield(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword l_n_slices = n_slices; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; const uword sub_n_slices = s.n_slices; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || (in_slice1 >= l_n_slices) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols) || ((in_slice1 + sub_n_slices) > l_n_slices)), "field::subfield(): indices or size out of bounds" ); return subview_field(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n_cols, sub_n_slices); } //! creation of subview_field (subfield with arbitrary dimensions) template inline subview_field field::subfield(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::subfield(): field must be 2D" ); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword sub_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword sub_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "field::subfield(): indices out of bounds or incorrectly used" ); return subview_field(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline const subview_field field::subfield(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); arma_debug_check( (n_slices >= 2), "field::subfield(): field must be 2D" ); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword sub_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword sub_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "field::subfield(): indices out of bounds or incorrectly used" ); return subview_field(*this, in_row1, in_col1, sub_n_rows, sub_n_cols); } //! creation of subview_field (subfield with arbitrary dimensions) template inline subview_field field::subfield(const span& row_span, const span& col_span, const span& slice_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const bool slice_all = slice_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword sub_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword sub_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword in_slice1 = slice_all ? 0 : slice_span.a; const uword in_slice2 = slice_span.b; const uword sub_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) || ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) ) , "field::subfield(): indices out of bounds or incorrectly used" ); return subview_field(*this, in_row1, in_col1, in_slice1, sub_n_rows, sub_n_cols, sub_n_slices); } //! creation of subview_field (subfield with arbitrary dimensions) template inline const subview_field field::subfield(const span& row_span, const span& col_span, const span& slice_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const bool slice_all = slice_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword sub_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword sub_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword in_slice1 = slice_all ? 0 : slice_span.a; const uword in_slice2 = slice_span.b; const uword sub_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) || ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) ) , "field::subfield(): indices out of bounds or incorrectly used" ); return subview_field(*this, in_row1, in_col1, in_slice1, sub_n_rows, sub_n_cols, sub_n_slices); } template inline subview_field field::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return (*this).subfield(row_span, col_span); } template inline const subview_field field::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return (*this).subfield(row_span, col_span); } template inline subview_field field::operator()(const span& row_span, const span& col_span, const span& slice_span) { arma_extra_debug_sigprint(); return (*this).subfield(row_span, col_span, slice_span); } template inline const subview_field field::operator()(const span& row_span, const span& col_span, const span& slice_span) const { arma_extra_debug_sigprint(); return (*this).subfield(row_span, col_span, slice_span); } template inline subview_field field::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).subfield(in_row1, in_col1, s); } template inline const subview_field field::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); return (*this).subfield(in_row1, in_col1, s); } template inline subview_field field::operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) { arma_extra_debug_sigprint(); return (*this).subfield(in_row1, in_col1, in_slice1, s); } template inline const subview_field field::operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const { arma_extra_debug_sigprint(); return (*this).subfield(in_row1, in_col1, in_slice1, s); } //! print contents of the field (to the cout stream), //! optionally preceding with a user specified line of text. //! the field class preserves the stream's flags //! but the associated operator<< function for type oT //! may still modify the stream's parameters. //! NOTE: this function assumes that type oT can be printed, //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" //! has been defined. template inline void field::print(const std::string extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this); } //! print contents of the field to a user specified stream, //! optionally preceding with a user specified line of text. //! the field class preserves the stream's flags //! but the associated operator<< function for type oT //! may still modify the stream's parameters. //! NOTE: this function assumes that type oT can be printed, //! i.e. the function "std::ostream& operator<< (std::ostream&, const oT&)" //! has been defined. template inline void field::print(std::ostream& user_stream, const std::string extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this); } #if defined(ARMA_USE_CXX11) //! apply a lambda function to each object template inline const field& field::for_each(const std::function< void(oT&) >& F) { arma_extra_debug_sigprint(); for(uword i=0; i < n_elem; ++i) { F(operator[](i)); } return *this; } template inline const field& field::for_each(const std::function< void(const oT&) >& F) const { arma_extra_debug_sigprint(); for(uword i=0; i < n_elem; ++i) { F(operator[](i)); } return *this; } #else //! apply a functor to each object template template inline const field& field::for_each(functor F) { arma_extra_debug_sigprint(); for(uword i=0; i < n_elem; ++i) { F(operator[](i)); } return *this; } template template inline const field& field::for_each(functor F) const { arma_extra_debug_sigprint(); for(uword i=0; i < n_elem; ++i) { F(operator[](i)); } return *this; } #endif //! fill the field with an object template inline const field& field::fill(const oT& x) { arma_extra_debug_sigprint(); field& t = *this; for(uword i=0; i inline void field::reset() { arma_extra_debug_sigprint(); init(0,0,0); } //! reset each object template inline void field::reset_objects() { arma_extra_debug_sigprint(); field_aux::reset_objects(*this); } //! returns true if the field has no objects template arma_inline bool field::is_empty() const { return (n_elem == 0); } //! returns true if the given index is currently in range template arma_inline arma_warn_unused bool field::in_range(const uword i) const { return (i < n_elem); } //! returns true if the given start and end indices are currently in range template arma_inline arma_warn_unused bool field::in_range(const span& x) const { arma_extra_debug_sigprint(); if(x.whole == true) { return true; } else { const uword a = x.a; const uword b = x.b; return ( (a <= b) && (b < n_elem) ); } } //! returns true if the given location is currently in range template arma_inline arma_warn_unused bool field::in_range(const uword in_row, const uword in_col) const { return ( (in_row < n_rows) && (in_col < n_cols) ); } template arma_inline arma_warn_unused bool field::in_range(const span& row_span, const uword in_col) const { arma_extra_debug_sigprint(); if(row_span.whole == true) { return (in_col < n_cols); } else { const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) ); } } template arma_inline arma_warn_unused bool field::in_range(const uword in_row, const span& col_span) const { arma_extra_debug_sigprint(); if(col_span.whole == true) { return (in_row < n_rows); } else { const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); } } template arma_inline arma_warn_unused bool field::in_range(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); return ( (rows_ok == true) && (cols_ok == true) ); } template arma_inline arma_warn_unused bool field::in_range(const uword in_row, const uword in_col, const SizeMat& s) const { const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) ) { return false; } else { return true; } } template arma_inline arma_warn_unused bool field::in_range(const uword in_row, const uword in_col, const uword in_slice) const { return ( (in_row < n_rows) && (in_col < n_cols) && (in_slice < n_slices) ); } template arma_inline arma_warn_unused bool field::in_range(const span& row_span, const span& col_span, const span& slice_span) const { arma_extra_debug_sigprint(); const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; const uword in_slice1 = slice_span.a; const uword in_slice2 = slice_span.b; const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2 ) && (in_row2 < n_rows ) ); const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2 ) && (in_col2 < n_cols ) ); const bool slices_ok = slice_span.whole ? true : ( (in_slice1 <= in_slice2) && (in_slice2 < n_slices) ); return ( (rows_ok == true) && (cols_ok == true) && (slices_ok == true) ); } template arma_inline arma_warn_unused bool field::in_range(const uword in_row, const uword in_col, const uword in_slice, const SizeCube& s) const { const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword l_n_slices = n_slices; if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || (in_slice >= l_n_slices) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) || ((in_slice + s.n_slices) > l_n_slices) ) { return false; } else { return true; } } template inline bool field::save(const std::string name, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); std::string err_msg; const bool save_okay = field_aux::save(*this, name, type, err_msg); if( (print_status == true) && (save_okay == false) ) { if(err_msg.length() > 0) { arma_debug_warn("field::save(): ", err_msg, name); } else { arma_debug_warn("field::save(): couldn't write to ", name); } } return save_okay; } template inline bool field::save(std::ostream& os, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); std::string err_msg; const bool save_okay = field_aux::save(*this, os, type, err_msg); if( (print_status == true) && (save_okay == false) ) { if(err_msg.length() > 0) { arma_debug_warn("field::save(): ", err_msg, "[ostream]"); } else { arma_debug_warn("field::save(): couldn't write to [ostream]"); } } return save_okay; } template inline bool field::load(const std::string name, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); std::string err_msg; const bool load_okay = field_aux::load(*this, name, type, err_msg); if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_debug_warn("field::load(): ", err_msg, name); } else { arma_debug_warn("field::load(): couldn't read from ", name); } } if(load_okay == false) { (*this).reset(); } return load_okay; } template inline bool field::load(std::istream& is, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); std::string err_msg; const bool load_okay = field_aux::load(*this, is, type, err_msg); if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_debug_warn("field::load(): ", err_msg, "[istream]"); } else { arma_debug_warn("field::load(): couldn't read from [istream]"); } } if(load_okay == false) { (*this).reset(); } return load_okay; } template inline bool field::quiet_save(const std::string name, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(name, type, false); } template inline bool field::quiet_save(std::ostream& os, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(os, type, false); } template inline bool field::quiet_load(const std::string name, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(name, type, false); } template inline bool field::quiet_load(std::istream& is, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(is, type, false); } //! construct a field from a given field template inline void field::init(const field& x) { arma_extra_debug_sigprint(); if(this != &x) { const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; const uword x_n_slices = x.n_slices; init(x_n_rows, x_n_cols, x_n_slices); field& t = *this; if(x_n_slices == 1) { for(uword ucol=0; ucol < x_n_cols; ++ucol) for(uword urow=0; urow < x_n_rows; ++urow) { t.at(urow,ucol) = x.at(urow,ucol); } } else { for(uword uslice=0; uslice < x_n_slices; ++uslice) for(uword ucol=0; ucol < x_n_cols; ++ucol ) for(uword urow=0; urow < x_n_rows; ++urow ) { t.at(urow,ucol,uslice) = x.at(urow,ucol,uslice); } } } } template inline void field::init(const uword n_rows_in, const uword n_cols_in) { (*this).init(n_rows_in, n_cols_in, 1); } template inline void field::init(const uword n_rows_in, const uword n_cols_in, const uword n_slices_in) { arma_extra_debug_sigprint( arma_str::format("n_rows_in = %d, n_cols_in = %d, n_slices_in = %d") % n_rows_in % n_cols_in % n_slices_in ); #if (defined(ARMA_USE_CXX11) || defined(ARMA_64BIT_WORD)) const char* error_message = "field::init(): requested size is too large"; #else const char* error_message = "field::init(): requested size is too large; suggest to compile in C++11 mode or enable ARMA_64BIT_WORD"; #endif arma_debug_check ( ( ( (n_rows_in > 0x0FFF) || (n_cols_in > 0x0FFF) || (n_slices_in > 0xFF) ) ? ( (double(n_rows_in) * double(n_cols_in) * double(n_slices_in)) > double(ARMA_MAX_UWORD) ) : false ), error_message ); const uword n_elem_new = n_rows_in * n_cols_in * n_slices_in; if(n_elem == n_elem_new) { // delete_objects(); // create_objects(); access::rw(n_rows) = n_rows_in; access::rw(n_cols) = n_cols_in; access::rw(n_slices) = n_slices_in; } else { delete_objects(); if(n_elem > field_prealloc_n_elem::val) { delete [] mem; } if(n_elem_new <= field_prealloc_n_elem::val) { mem = mem_local; } else { mem = new(std::nothrow) oT* [n_elem_new]; arma_check_bad_alloc( (mem == 0), "field::init(): out of memory" ); } access::rw(n_elem) = n_elem_new; if(n_elem_new == 0) { access::rw(n_rows) = 0; access::rw(n_cols) = 0; access::rw(n_slices) = 0; } else { access::rw(n_rows) = n_rows_in; access::rw(n_cols) = n_cols_in; access::rw(n_slices) = n_slices_in; } create_objects(); } } template inline void field::delete_objects() { arma_extra_debug_sigprint( arma_str::format("n_elem = %d") % n_elem ); for(uword i=0; i inline void field::create_objects() { arma_extra_debug_sigprint( arma_str::format("n_elem = %d") % n_elem ); for(uword i=0; i inline field::iterator::iterator(field& in_M, const bool at_end) : M(in_M) , i( (at_end == false) ? 0 : in_M.n_elem ) { arma_extra_debug_sigprint(); } template inline oT& field::iterator::operator*() { return M[i]; } template inline typename field::iterator& field::iterator::operator++() { ++i; return *this; } template inline void field::iterator::operator++(int) { operator++(); } template inline typename field::iterator& field::iterator::operator--() { if(i > 0) { --i; } return *this; } template inline void field::iterator::operator--(int) { operator--(); } template inline bool field::iterator::operator!=(const typename field::iterator& X) const { return (i != X.i); } template inline bool field::iterator::operator==(const typename field::iterator& X) const { return (i == X.i); } template inline field::const_iterator::const_iterator(const field& in_M, const bool at_end) : M(in_M) , i( (at_end == false) ? 0 : in_M.n_elem ) { arma_extra_debug_sigprint(); } template inline field::const_iterator::const_iterator(const typename field::iterator& X) : M(X.M) , i(X.i) { arma_extra_debug_sigprint(); } template inline const oT& field::const_iterator::operator*() const { return M[i]; } template inline typename field::const_iterator& field::const_iterator::operator++() { ++i; return *this; } template inline void field::const_iterator::operator++(int) { operator++(); } template inline typename field::const_iterator& field::const_iterator::operator--() { if(i > 0) { --i; } return *this; } template inline void field::const_iterator::operator--(int) { operator--(); } template inline bool field::const_iterator::operator!=(const typename field::const_iterator& X) const { return (i != X.i); } template inline bool field::const_iterator::operator==(const typename field::const_iterator& X) const { return (i == X.i); } template inline typename field::iterator field::begin() { arma_extra_debug_sigprint(); return field::iterator(*this); } template inline typename field::const_iterator field::begin() const { arma_extra_debug_sigprint(); return field::const_iterator(*this); } template inline typename field::const_iterator field::cbegin() const { arma_extra_debug_sigprint(); return field::const_iterator(*this); } template inline typename field::iterator field::end() { arma_extra_debug_sigprint(); return field::iterator(*this, true); } template inline typename field::const_iterator field::end() const { arma_extra_debug_sigprint(); return field::const_iterator(*this, true); } template inline typename field::const_iterator field::cend() const { arma_extra_debug_sigprint(); return field::const_iterator(*this, true); } template inline void field::clear() { reset(); } template inline bool field::empty() const { return (n_elem == 0); } template inline uword field::size() const { return n_elem; } // // // template inline void field_aux::reset_objects(field& x) { arma_extra_debug_sigprint(); x.delete_objects(); x.create_objects(); } template inline void field_aux::reset_objects(field< Mat >& x) { arma_extra_debug_sigprint(); for(uword i=0; i inline void field_aux::reset_objects(field< Col >& x) { arma_extra_debug_sigprint(); for(uword i=0; i inline void field_aux::reset_objects(field< Row >& x) { arma_extra_debug_sigprint(); for(uword i=0; i inline void field_aux::reset_objects(field< Cube >& x) { arma_extra_debug_sigprint(); for(uword i=0; i& x) { arma_extra_debug_sigprint(); for(uword i=0; i inline bool field_aux::save(const field&, const std::string&, const file_type, std::string& err_msg) { arma_extra_debug_sigprint(); err_msg = " [saving/loading this type of field is currently not supported] filename = "; return false; } template inline bool field_aux::save(const field&, std::ostream&, const file_type, std::string& err_msg) { arma_extra_debug_sigprint(); err_msg = " [saving/loading this type of field is currently not supported] filename = "; return false; } template inline bool field_aux::load(field&, const std::string&, const file_type, std::string& err_msg) { arma_extra_debug_sigprint(); err_msg = " [saving/loading this type of field is currently not supported] filename = "; return false; } template inline bool field_aux::load(field&, std::istream&, const file_type, std::string& err_msg) { arma_extra_debug_sigprint(); err_msg = " [saving/loading this type of field is currently not supported] filename = "; return false; } template inline bool field_aux::save(const field< Mat >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, name); break; case ppm_binary: return diskio::save_ppm_binary(x, name); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Mat >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, os); break; case ppm_binary: return diskio::save_ppm_binary(x, os); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Mat >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, name, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, name, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Mat >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, is, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, is, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, is, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Col >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, name); break; case ppm_binary: return diskio::save_ppm_binary(x, name); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Col >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, os); break; case ppm_binary: return diskio::save_ppm_binary(x, os); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Col >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, name, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, name, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Col >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, is, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, is, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, is, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Row >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, name); break; case ppm_binary: return diskio::save_ppm_binary(x, name); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Row >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, os); break; case ppm_binary: return diskio::save_ppm_binary(x, os); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Row >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, name, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, name, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Row >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: return diskio::load_auto_detect(x, is, err_msg); break; case arma_binary: return diskio::load_arma_binary(x, is, err_msg); break; case ppm_binary: return diskio::load_ppm_binary(x, is, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Cube >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, name); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::save(const field< Cube >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case arma_binary: return diskio::save_arma_binary(x, os); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Cube >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: case arma_binary: return diskio::load_arma_binary(x, name, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } template inline bool field_aux::load(field< Cube >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); switch(type) { case auto_detect: case arma_binary: return diskio::load_arma_binary(x, is, err_msg); break; default: err_msg = " [unsupported type] filename = "; return false; } } inline bool field_aux::save(const field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(type); err_msg.clear(); return diskio::save_std_string(x, name); } inline bool field_aux::save(const field< std::string >& x, std::ostream& os, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(type); err_msg.clear(); return diskio::save_std_string(x, os); } inline bool field_aux::load(field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(type); return diskio::load_std_string(x, name, err_msg); } inline bool field_aux::load(field< std::string >& x, std::istream& is, const file_type type, std::string& err_msg) { arma_extra_debug_sigprint(); arma_ignore(type); return diskio::load_std_string(x, is, err_msg); } #ifdef ARMA_EXTRA_FIELD_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_FIELD_MEAT) #endif //! @} armadillo-6.500.5/include/armadillo_bits/spdiagview_bones.hpp0000666000000000000000000000620512620272703023012 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spdiagview //! @{ //! Class for storing data required to extract and set the diagonals of a sparse matrix template class spdiagview : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; arma_aligned const SpMat& m; static const bool is_row = false; static const bool is_col = true; const uword row_offset; const uword col_offset; const uword n_rows; // equal to n_elem const uword n_elem; static const uword n_cols = 1; protected: arma_inline spdiagview(const SpMat& in_m, const uword in_row_offset, const uword in_col_offset, const uword len); public: inline ~spdiagview(); inline void operator=(const spdiagview& x); inline void operator+=(const eT val); inline void operator-=(const eT val); inline void operator*=(const eT val); inline void operator/=(const eT val); template inline void operator= (const Base& x); template inline void operator+=(const Base& x); template inline void operator-=(const Base& x); template inline void operator%=(const Base& x); template inline void operator/=(const Base& x); template inline void operator= (const SpBase& x); template inline void operator+=(const SpBase& x); template inline void operator-=(const SpBase& x); template inline void operator%=(const SpBase& x); template inline void operator/=(const SpBase& x); inline eT at_alt (const uword ii) const; inline SpValProxy< SpMat > operator[](const uword ii); inline eT operator[](const uword ii) const; inline SpValProxy< SpMat > at(const uword ii); inline eT at(const uword ii) const; inline SpValProxy< SpMat > operator()(const uword ii); inline eT operator()(const uword ii) const; inline SpValProxy< SpMat > at(const uword in_n_row, const uword); inline eT at(const uword in_n_row, const uword) const; inline SpValProxy< SpMat > operator()(const uword in_n_row, const uword in_n_col); inline eT operator()(const uword in_n_row, const uword in_n_col) const; inline void fill(const eT val); inline void zeros(); inline void ones(); inline void randu(); inline void randn(); inline static void extract(Mat& out, const spdiagview& in); private: friend class SpMat; spdiagview(); }; //! @} armadillo-6.500.5/include/armadillo_bits/diagview_bones.hpp0000666000000000000000000000626512620272703022455 0ustar rootroot// Copyright (C) 2008-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup diagview //! @{ //! Class for storing data required to extract and set the diagonals of a matrix template class diagview : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; arma_aligned const Mat& m; static const bool is_row = false; static const bool is_col = true; const uword row_offset; const uword col_offset; const uword n_rows; // equal to n_elem const uword n_elem; static const uword n_cols = 1; protected: arma_inline diagview(const Mat& in_m, const uword in_row_offset, const uword in_col_offset, const uword len); public: inline ~diagview(); inline void operator=(const diagview& x); inline void operator+=(const eT val); inline void operator-=(const eT val); inline void operator*=(const eT val); inline void operator/=(const eT val); template inline void operator= (const Base& x); template inline void operator+=(const Base& x); template inline void operator-=(const Base& x); template inline void operator%=(const Base& x); template inline void operator/=(const Base& x); arma_inline eT at_alt (const uword ii) const; arma_inline eT& operator[](const uword ii); arma_inline eT operator[](const uword ii) const; arma_inline eT& at(const uword ii); arma_inline eT at(const uword ii) const; arma_inline eT& operator()(const uword ii); arma_inline eT operator()(const uword ii) const; arma_inline eT& at(const uword in_n_row, const uword); arma_inline eT at(const uword in_n_row, const uword) const; arma_inline eT& operator()(const uword in_n_row, const uword in_n_col); arma_inline eT operator()(const uword in_n_row, const uword in_n_col) const; arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline void fill(const eT val); inline void zeros(); inline void ones(); inline void randu(); inline void randn(); inline static void extract(Mat& out, const diagview& in); inline static void plus_inplace(Mat& out, const diagview& in); inline static void minus_inplace(Mat& out, const diagview& in); inline static void schur_inplace(Mat& out, const diagview& in); inline static void div_inplace(Mat& out, const diagview& in); private: friend class Mat; friend class subview; diagview(); //diagview(const diagview&); // making this private causes an error under gcc 4.1/4.2, but not 4.3 }; //! @} armadillo-6.500.5/include/armadillo_bits/op_expmat_bones.hpp0000666000000000000000000000112712620272703022642 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_expmat //! @{ class op_expmat { public: template inline static void apply(Mat& out, const Op& expr); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_svd.hpp0000666000000000000000000001026712620272703020744 0ustar rootroot// Copyright (C) 2009-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_svd //! @{ template inline bool svd ( Col& S, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); // it doesn't matter if X is an alias of S, as auxlib::svd() makes a copy of X const bool status = auxlib::svd_dc(S, X); if(status == false) { S.reset(); arma_debug_warn("svd(): decomposition failed"); } return status; } template inline Col svd ( const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Col out; const bool status = auxlib::svd_dc(out, X); if(status == false) { out.reset(); arma_bad("svd(): decomposition failed"); } return out; } template inline bool svd ( Mat& U, Col& S, Mat& V, const Base& X, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check ( ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), "svd(): two or more output objects are the same object" ); const char sig = (method != NULL) ? method[0] : char(0); arma_debug_check( ((sig != 's') && (sig != 'd')), "svd(): unknown method specified" ); // auxlib::svd() makes an internal copy of X const bool status = (sig == 'd') ? auxlib::svd_dc(U, S, V, X) : auxlib::svd(U, S, V, X); if(status == false) { U.reset(); S.reset(); V.reset(); arma_debug_warn("svd(): decomposition failed"); } return status; } template inline bool svd_econ ( Mat& U, Col& S, Mat& V, const Base& X, const char mode, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check ( ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), "svd_econ(): two or more output objects are the same object" ); arma_debug_check ( ( (mode != 'l') && (mode != 'r') && (mode != 'b') ), "svd_econ(): parameter 'mode' is incorrect" ); const char sig = (method != NULL) ? method[0] : char(0); arma_debug_check( ((sig != 's') && (sig != 'd')), "svd_econ(): unknown method specified" ); const bool status = ((mode == 'b') && (sig == 'd')) ? auxlib::svd_dc_econ(U, S, V, X) : auxlib::svd_econ(U, S, V, X, mode); if(status == false) { U.reset(); S.reset(); V.reset(); arma_debug_warn("svd(): decomposition failed"); } return status; } template inline bool svd_econ ( Mat& U, Col& S, Mat& V, const Base& X, const char* mode = "both", const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return svd_econ(U, S, V, X, ((mode != NULL) ? mode[0] : char(0)), method); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_eig_sym.hpp0000666000000000000000000000610012620272703021573 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Stanislav Funiak //! \addtogroup fn_eig_sym //! @{ //! Eigenvalues of real/complex symmetric/hermitian matrix X template inline bool eig_sym ( Col& eigval, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); // unwrap_check not used as T1::elem_type and T1::pod_type may not be the same. // furthermore, it doesn't matter if X is an alias of eigval, as auxlib::eig_sym() makes a copy of X const bool status = auxlib::eig_sym(eigval, X); if(status == false) { eigval.reset(); arma_debug_warn("eig_sym(): decomposition failed"); } return status; } //! Eigenvalues of real/complex symmetric/hermitian matrix X template inline Col eig_sym ( const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Col out; const bool status = auxlib::eig_sym(out, X); if(status == false) { out.reset(); arma_bad("eig_sym(): decomposition failed"); } return out; } //! Eigenvalues and eigenvectors of real/complex symmetric/hermitian matrix X template inline bool eig_sym ( Col& eigval, Mat& eigvec, const Base& X, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const char sig = (method != NULL) ? method[0] : char(0); arma_debug_check( ((sig != 's') && (sig != 'd')), "eig_sym(): unknown method specified" ); arma_debug_check( void_ptr(&eigval) == void_ptr(&eigvec), "eig_sym(): parameter 'eigval' is an alias of parameter 'eigvec'" ); const Proxy P(X.get_ref()); const bool is_alias = P.is_alias(eigvec); Mat eigvec_tmp; Mat& eigvec_out = (is_alias == false) ? eigvec : eigvec_tmp; bool status = false; if(sig == 'd') { status = auxlib::eig_sym_dc(eigval, eigvec_out, P.Q); } if(status == false) { status = auxlib::eig_sym(eigval, eigvec_out, P.Q); } if(status == false) { eigval.reset(); eigvec.reset(); arma_debug_warn("eig_sym(): decomposition failed"); } else { if(is_alias) { eigvec.steal_mem(eigvec_tmp); } } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_repmat.hpp0000666000000000000000000000170712620272703021437 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup fn_repmat //! @{ template arma_inline typename enable_if2 < is_arma_type::value, const Op >::result repmat(const T1& A, const uword r, const uword c) { arma_extra_debug_sigprint(); return Op(A, r, c); } template arma_inline const SpOp repmat(const SpBase& A, const uword r, const uword c) { arma_extra_debug_sigprint(); return SpOp(A.get_ref(), r, c); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_sort.hpp0000666000000000000000000000417212620272703021135 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_sort //! @{ template arma_inline typename enable_if2 < (is_arma_type::value), const Op >::result sort ( const T1& X, const uword sort_type = 0 ) { arma_extra_debug_sigprint(); return Op(X, sort_type, 0); } //! kept for compatibility with old code template arma_inline typename enable_if2 < (is_arma_type::value), const Op >::result sort ( const T1& X, const uword sort_type, const uword dim ) { arma_extra_debug_sigprint(); return Op(X, sort_type, dim); } template arma_inline typename enable_if2 < ( (is_arma_type::value) && (is_same_type::value) ), const Op >::result sort ( const T1& X, const T2* sort_direction ) { arma_extra_debug_sigprint(); const char sig = (sort_direction != NULL) ? sort_direction[0] : char(0); arma_debug_check( (sig != 'a') && (sig != 'd'), "sort(): unknown sort direction"); const uword sort_type = (sig == 'a') ? 0 : 1; return Op(X, sort_type, 0); } template arma_inline typename enable_if2 < ( (is_arma_type::value) && (is_same_type::value) ), const Op >::result sort ( const T1& X, const T2* sort_direction, const uword dim ) { arma_extra_debug_sigprint(); const char sig = (sort_direction != NULL) ? sort_direction[0] : char(0); arma_debug_check( (sig != 'a') && (sig != 'd'), "sort(): unknown sort direction"); const uword sort_type = (sig == 'a') ? 0 : 1; return Op(X, sort_type, dim); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_any.hpp0000666000000000000000000000371712620272703020741 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_any //! @{ template arma_inline const mtOp any ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return mtOp(X, dim, 0); } template arma_inline const mtOp any ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOp(X, dim, 0); } template inline arma_warn_unused bool any ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_any::any_vec(X); } template inline arma_warn_unused bool any(const mtOp& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("any(): two consecutive calls to any() detected"); return op_any::any_vec(in.m); } template arma_inline const Op< mtOp, op_any> any(const mtOp& in, const uword dim) { arma_extra_debug_sigprint(); return mtOp, op_any>(in, dim, 0); } //! @} armadillo-6.500.5/include/armadillo_bits/subview_bones.hpp0000666000000000000000000003301612633721645022344 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by James Sanders //! \addtogroup subview //! @{ //! Class for storing data required to construct or apply operations to a submatrix //! (i.e. where the submatrix starts and ends as well as a reference/pointer to the original matrix), template class subview : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; arma_aligned const Mat& m; static const bool is_row = false; static const bool is_col = false; const uword aux_row1; const uword aux_col1; const uword n_rows; const uword n_cols; const uword n_elem; protected: arma_inline subview(const Mat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); public: inline ~subview(); template inline void inplace_op(const eT val ); template inline void inplace_op(const Base& x, const char* identifier); template inline void inplace_op(const subview& x, const char* identifier); // deliberately returning void inline void operator= (const eT val); inline void operator+= (const eT val); inline void operator-= (const eT val); inline void operator*= (const eT val); inline void operator/= (const eT val); inline void operator= (const subview& x); inline void operator+= (const subview& x); inline void operator-= (const subview& x); inline void operator%= (const subview& x); inline void operator/= (const subview& x); template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); template inline void operator= (const SpBase& x); template inline void operator+= (const SpBase& x); template inline void operator-= (const SpBase& x); template inline void operator%= (const SpBase& x); template inline void operator/= (const SpBase& x); template inline typename enable_if2< is_same_type::value, void>::result operator=(const Gen& x); inline static void extract(Mat& out, const subview& in); inline static void plus_inplace(Mat& out, const subview& in); inline static void minus_inplace(Mat& out, const subview& in); inline static void schur_inplace(Mat& out, const subview& in); inline static void div_inplace(Mat& out, const subview& in); template inline void for_each(functor F); template inline void for_each(functor F) const; template inline void transform(functor F); template inline void imbue(functor F); inline void fill(const eT val); inline void zeros(); inline void ones(); inline void eye(); inline void randu(); inline void randn(); inline eT at_alt (const uword ii) const; inline eT& operator[](const uword ii); inline eT operator[](const uword ii) const; inline eT& operator()(const uword ii); inline eT operator()(const uword ii) const; inline eT& operator()(const uword in_row, const uword in_col); inline eT operator()(const uword in_row, const uword in_col) const; inline eT& at(const uword in_row, const uword in_col); inline eT at(const uword in_row, const uword in_col) const; arma_inline eT* colptr(const uword in_col); arma_inline const eT* colptr(const uword in_col) const; inline bool check_overlap(const subview& x) const; inline arma_warn_unused bool is_vec() const; inline arma_warn_unused bool is_finite() const; inline arma_warn_unused bool has_inf() const; inline arma_warn_unused bool has_nan() const; inline subview_row row(const uword row_num); inline const subview_row row(const uword row_num) const; inline subview_row operator()(const uword row_num, const span& col_span); inline const subview_row operator()(const uword row_num, const span& col_span) const; inline subview_col col(const uword col_num); inline const subview_col col(const uword col_num) const; inline subview_col operator()(const span& row_span, const uword col_num); inline const subview_col operator()(const span& row_span, const uword col_num) const; inline Col unsafe_col(const uword col_num); inline const Col unsafe_col(const uword col_num) const; inline subview rows(const uword in_row1, const uword in_row2); inline const subview rows(const uword in_row1, const uword in_row2) const; inline subview cols(const uword in_col1, const uword in_col2); inline const subview cols(const uword in_col1, const uword in_col2) const; inline subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); inline const subview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; inline subview submat (const span& row_span, const span& col_span); inline const subview submat (const span& row_span, const span& col_span) const; inline subview operator()(const span& row_span, const span& col_span); inline const subview operator()(const span& row_span, const span& col_span) const; inline subview_each1< subview, 0 > each_col(); inline subview_each1< subview, 1 > each_row(); template inline subview_each2< subview, 0, T1 > each_col(const Base& indices); template inline subview_each2< subview, 1, T1 > each_row(const Base& indices); #if defined(ARMA_USE_CXX11) inline void each_col(const std::function< void( Col&) >& F); inline void each_col(const std::function< void(const Col&) >& F) const; inline void each_row(const std::function< void( Row&) >& F); inline void each_row(const std::function< void(const Row&) >& F) const; #endif inline diagview diag(const sword in_id = 0); inline const diagview diag(const sword in_id = 0) const; inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_cols(const uword in_col1, const uword in_col2); private: friend class Mat; subview(); }; template class subview_col : public subview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; const eT* colmem; inline void operator= (const subview& x); inline void operator= (const subview_col& x); inline void operator= (const eT val); template inline void operator= (const Base& x); template inline typename enable_if2< is_same_type::value, void>::result operator=(const Gen& x); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline void fill(const eT val); inline void zeros(); inline void ones(); arma_inline eT at_alt (const uword i) const; arma_inline eT& operator[](const uword i); arma_inline eT operator[](const uword i) const; inline eT& operator()(const uword i); inline eT operator()(const uword i) const; inline eT& operator()(const uword in_row, const uword in_col); inline eT operator()(const uword in_row, const uword in_col) const; inline eT& at(const uword in_row, const uword in_col); inline eT at(const uword in_row, const uword in_col) const; arma_inline eT* colptr(const uword in_col); arma_inline const eT* colptr(const uword in_col) const; inline subview_col rows(const uword in_row1, const uword in_row2); inline const subview_col rows(const uword in_row1, const uword in_row2) const; inline subview_col subvec(const uword in_row1, const uword in_row2); inline const subview_col subvec(const uword in_row1, const uword in_row2) const; inline subview_col head(const uword N); inline const subview_col head(const uword N) const; inline subview_col tail(const uword N); inline const subview_col tail(const uword N) const; protected: inline subview_col(const Mat& in_m, const uword in_col); inline subview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); private: friend class Mat; friend class Col; friend class subview; subview_col(); }; template class subview_row : public subview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = true; static const bool is_col = false; inline void operator= (const subview& x); inline void operator= (const subview_row& x); inline void operator= (const eT val); template inline void operator= (const Base& x); template inline typename enable_if2< is_same_type::value, void>::result operator=(const Gen& x); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline eT at_alt (const uword i) const; inline eT& operator[](const uword i); inline eT operator[](const uword i) const; inline eT& operator()(const uword i); inline eT operator()(const uword i) const; inline eT& operator()(const uword in_row, const uword in_col); inline eT operator()(const uword in_row, const uword in_col) const; inline eT& at(const uword in_row, const uword in_col); inline eT at(const uword in_row, const uword in_col) const; inline subview_row cols(const uword in_col1, const uword in_col2); inline const subview_row cols(const uword in_col1, const uword in_col2) const; inline subview_row subvec(const uword in_col1, const uword in_col2); inline const subview_row subvec(const uword in_col1, const uword in_col2) const; inline subview_row head(const uword N); inline const subview_row head(const uword N) const; inline subview_row tail(const uword N); inline const subview_row tail(const uword N) const; protected: inline subview_row(const Mat& in_m, const uword in_row); inline subview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); private: friend class Mat; friend class Row; friend class subview; subview_row(); }; template class subview_row_strans : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row& sv_row; const uword n_rows; // equal to n_elem const uword n_elem; static const uword n_cols = 1; inline explicit subview_row_strans(const subview_row& in_sv_row); inline void extract(Mat& out) const; inline eT at_alt (const uword i) const; inline eT operator[](const uword i) const; inline eT operator()(const uword i) const; inline eT operator()(const uword in_row, const uword in_col) const; inline eT at(const uword in_row, const uword in_col) const; }; template class subview_row_htrans : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; arma_aligned const subview_row& sv_row; const uword n_rows; // equal to n_elem const uword n_elem; static const uword n_cols = 1; inline explicit subview_row_htrans(const subview_row& in_sv_row); inline void extract(Mat& out) const; inline eT at_alt (const uword i) const; inline eT operator[](const uword i) const; inline eT operator()(const uword i) const; inline eT operator()(const uword in_row, const uword in_col) const; inline eT at(const uword in_row, const uword in_col) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/glue_conv_bones.hpp0000666000000000000000000000177212647117140022637 0ustar rootroot// Copyright (C) 2010-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_conv //! @{ class glue_conv { public: template inline static void apply(Mat& out, const Mat& A, const Mat& B, const bool A_is_col); template inline static void apply(Mat& out, const Glue& X); }; class glue_conv2 { public: template inline static void apply(Mat& out, const Mat& A, const Mat& B); template inline static void apply(Mat& out, const Glue& expr); }; //! @} armadillo-6.500.5/include/armadillo_bits/operator_minus.hpp0000666000000000000000000001647312620272703022540 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup operator_minus //! @{ //! unary - template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator- (const T1& X) { arma_extra_debug_sigprint(); return eOp(X); } //! cancellation of two consecutive negations: -(-T1) template arma_inline const typename Proxy::stored_type& operator- (const eOp& X) { arma_extra_debug_sigprint(); return X.P.Q; } //! Base - scalar template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator- ( const T1& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOp(X, k); } //! scalar - Base template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator- ( const typename T1::elem_type k, const T1& X ) { arma_extra_debug_sigprint(); return eOp(X, k); } //! complex scalar - non-complex Base template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_minus_pre> >::result operator- ( const std::complex& k, const T1& X ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_minus_pre>('j', X, k); } //! non-complex Base - complex scalar template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_minus_post> >::result operator- ( const T1& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_minus_post>('j', X, k); } //! subtraction of Base objects with same element type template arma_inline typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, const eGlue >::result operator- ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return eGlue(X, Y); } //! subtraction of Base objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue::result, T1, T2, glue_mixed_minus> >::result operator- ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! unary "-" for sparse objects template inline typename enable_if2 < is_arma_sparse_type::value && is_signed::value, SpOp >::result operator- (const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; return SpOp(X, eT(-1)); } //! subtraction of two sparse objects template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_sparse_type::value && is_same_type::value), const SpGlue >::result operator- ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return SpGlue(X,Y); } //! subtraction of one sparse and one dense object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), Mat >::result operator- ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); const SpProxy pa(x); Mat result(-y); arma_debug_assert_same_size( pa.get_n_rows(), pa.get_n_cols(), result.n_rows, result.n_cols, "subtraction" ); typename SpProxy::const_iterator_type it = pa.begin(); typename SpProxy::const_iterator_type it_end = pa.end(); while(it != it_end) { result.at(it.row(), it.col()) += (*it); ++it; } return result; } //! subtraction of one dense and one sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), Mat >::result operator- ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); Mat result(x); const SpProxy pb(y.get_ref()); arma_debug_assert_same_size( result.n_rows, result.n_cols, pb.get_n_rows(), pb.get_n_cols(), "subtraction" ); typename SpProxy::const_iterator_type it = pb.begin(); typename SpProxy::const_iterator_type it_end = pb.end(); while(it != it_end) { result.at(it.row(), it.col()) -= (*it); ++it; } return result; } template arma_inline Mat operator- ( const subview_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_each1_aux::operator_minus(X, Y.get_ref()); } template arma_inline Mat operator- ( const Base& X, const subview_each1& Y ) { arma_extra_debug_sigprint(); return subview_each1_aux::operator_minus(X.get_ref(), Y); } template arma_inline Mat operator- ( const subview_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_each2_aux::operator_minus(X, Y.get_ref()); } template arma_inline Mat operator- ( const Base& X, const subview_each2& Y ) { arma_extra_debug_sigprint(); return subview_each2_aux::operator_minus(X.get_ref(), Y); } //! @} armadillo-6.500.5/include/armadillo_bits/spop_htrans_meat.hpp0000666000000000000000000000327412620272703023033 0ustar rootroot// Copyright (C) 2012-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_htrans //! @{ template arma_hot inline void spop_htrans::apply(SpMat& out, const SpOp& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); spop_strans::apply(out, in); } template arma_hot inline void spop_htrans::apply(SpMat& out, const SpOp& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename umat::elem_type ueT; const SpProxy p(in.m); const uword N = p.get_n_nonzero(); if(N == uword(0)) { out.zeros(p.get_n_cols(), p.get_n_rows()); return; } umat locs(2, N); Col vals(N); eT* vals_ptr = vals.memptr(); typename SpProxy::const_iterator_type it = p.begin(); for(uword count = 0; count < N; ++count) { ueT* locs_ptr = locs.colptr(count); locs_ptr[0] = it.col(); locs_ptr[1] = it.row(); vals_ptr[count] = std::conj(*it); ++it; } SpMat tmp(locs, vals, p.get_n_cols(), p.get_n_rows()); out.steal_mem(tmp); } //! @} armadillo-6.500.5/include/armadillo_bits/op_htrans_meat.hpp0000666000000000000000000002646612620272703022500 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup op_htrans //! @{ template arma_hot arma_inline void op_htrans::apply_mat_noalias(Mat& out, const Mat& A, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans::apply_mat_noalias(out, A); } template arma_hot inline void op_htrans::apply_mat_noalias(Mat& out, const Mat& A, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; out.set_size(A_n_cols, A_n_rows); if( (A_n_cols == 1) || (A_n_rows == 1) ) { const uword n_elem = A.n_elem; const eT* A_mem = A.memptr(); eT* out_mem = out.memptr(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::conj(A_mem[i]); } } else { eT* outptr = out.memptr(); for(uword k=0; k < A_n_rows; ++k) { const eT* Aptr = &(A.at(k,0)); for(uword j=0; j < A_n_cols; ++j) { (*outptr) = std::conj(*Aptr); Aptr += A_n_rows; outptr++; } } } } template arma_hot arma_inline void op_htrans::apply_mat_inplace(Mat& out, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans::apply_mat_inplace(out); } template arma_hot inline void op_htrans::apply_mat_inplace(Mat& out, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; if(n_rows == n_cols) { arma_extra_debug_print("doing in-place hermitian transpose of a square matrix"); for(uword col=0; col < n_cols; ++col) { eT* coldata = out.colptr(col); out.at(col,col) = std::conj( out.at(col,col) ); for(uword row=(col+1); row < n_rows; ++row) { const eT val1 = std::conj(coldata[row]); const eT val2 = std::conj(out.at(col,row)); out.at(col,row) = val1; coldata[row] = val2; } } } else { Mat tmp; op_htrans::apply_mat_noalias(tmp, out); out.steal_mem(tmp); } } template arma_hot arma_inline void op_htrans::apply_mat(Mat& out, const Mat& A, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans::apply_mat(out, A); } template arma_hot inline void op_htrans::apply_mat(Mat& out, const Mat& A, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); if(&out != &A) { op_htrans::apply_mat_noalias(out, A); } else { op_htrans::apply_mat_inplace(out); } } template arma_hot inline void op_htrans::apply_proxy(Mat& out, const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); // allow detection of in-place transpose if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { const unwrap::stored_type> tmp(P.Q); op_htrans::apply_mat(out, tmp.M); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool is_alias = P.is_alias(out); if( (resolves_to_vector::value == true) && (Proxy::prefer_at_accessor == false) ) { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* out_mem = out.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::conj(Pea[i]); } } else // aliasing { Mat out2(n_cols, n_rows); eT* out_mem = out2.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = std::conj(Pea[i]); } out.steal_mem(out2); } } else { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* outptr = out.memptr(); for(uword k=0; k < n_rows; ++k) { for(uword j=0; j < n_cols; ++j) { (*outptr) = std::conj(P.at(k,j)); outptr++; } } } else // aliasing { Mat out2(n_cols, n_rows); eT* out2ptr = out2.memptr(); for(uword k=0; k < n_rows; ++k) { for(uword j=0; j < n_cols; ++j) { (*out2ptr) = std::conj(P.at(k,j)); out2ptr++; } } out.steal_mem(out2); } } } } template arma_hot inline void op_htrans::apply(Mat& out, const Op& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans::apply_proxy(out, in.m); } template arma_hot inline void op_htrans::apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_htrans::apply_proxy(out, in.m); } template arma_hot inline void op_htrans::apply(Mat& out, const Op< Op, op_htrans>& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m.m); const Mat& A = tmp.M; const bool upper = in.m.aux_uword_a; op_trimat::apply_htrans(out, A, upper); } // // op_htrans2 template arma_hot arma_inline void op_htrans2::apply_noalias(Mat& out, const Mat& A, const eT val) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; out.set_size(A_n_cols, A_n_rows); if( (A_n_cols == 1) || (A_n_rows == 1) ) { const uword n_elem = A.n_elem; const eT* A_mem = A.memptr(); eT* out_mem = out.memptr(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = val * std::conj(A_mem[i]); } } else { eT* outptr = out.memptr(); for(uword k=0; k < A_n_rows; ++k) { const eT* Aptr = &(A.at(k,0)); for(uword j=0; j < A_n_cols; ++j) { (*outptr) = val * std::conj(*Aptr); Aptr += A_n_rows; outptr++; } } } } template arma_hot inline void op_htrans2::apply(Mat& out, const Mat& A, const eT val) { arma_extra_debug_sigprint(); if(&out != &A) { op_htrans2::apply_noalias(out, A, val); } else { const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; if(n_rows == n_cols) { arma_extra_debug_print("doing in-place hermitian transpose of a square matrix"); // TODO: do multiplication while swapping for(uword col=0; col < n_cols; ++col) { eT* coldata = out.colptr(col); out.at(col,col) = std::conj( out.at(col,col) ); for(uword row=(col+1); row < n_rows; ++row) { const eT val1 = std::conj(coldata[row]); const eT val2 = std::conj(out.at(col,row)); out.at(col,row) = val1; coldata[row] = val2; } } arrayops::inplace_mul( out.memptr(), val, out.n_elem ); } else { Mat tmp; op_htrans2::apply_noalias(tmp, A, val); out.steal_mem(tmp); } } } template arma_hot inline void op_htrans2::apply_proxy(Mat& out, const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); // allow detection of in-place transpose if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { const unwrap::stored_type> tmp(P.Q); op_htrans2::apply(out, tmp.M, val); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool is_alias = P.is_alias(out); if( (resolves_to_vector::value == true) && (Proxy::prefer_at_accessor == false) ) { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* out_mem = out.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = val * std::conj(Pea[i]); } } else // aliasing { Mat out2(n_cols, n_rows); eT* out_mem = out2.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out_mem[i] = val * std::conj(Pea[i]); } out.steal_mem(out2); } } else { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* outptr = out.memptr(); for(uword k=0; k < n_rows; ++k) { for(uword j=0; j < n_cols; ++j) { (*outptr) = val * std::conj(P.at(k,j)); outptr++; } } } else // aliasing { Mat out2(n_cols, n_rows); eT* out2ptr = out2.memptr(); for(uword k=0; k < n_rows; ++k) { for(uword j=0; j < n_cols; ++j) { (*out2ptr) = val * std::conj(P.at(k,j)); out2ptr++; } } out.steal_mem(out2); } } } } template arma_hot inline void op_htrans2::apply(Mat& out, const Op& in, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_strans2::apply_proxy(out, in.m, in.aux); } template arma_hot inline void op_htrans2::apply(Mat& out, const Op& in, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); op_htrans2::apply_proxy(out, in.m, in.aux); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_svds.hpp0000666000000000000000000002120712620272703021123 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_svds //! @{ template inline bool svds_helper ( Mat& U, Col& S, Mat& V, const SpBase& X, const uword k, const typename T1::pod_type tol, const bool calc_UV, const typename arma_real_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; if(arma_config::arpack == false) { arma_stop("svds(): use of ARPACK must be enabled"); return false; } arma_debug_check ( ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), "svds(): two or more output objects are the same object" ); arma_debug_check( (tol < T(0)), "svds(): tol must be >= 0" ); const unwrap_spmat tmp(X.get_ref()); const SpMat& A = tmp.M; const uword kk = (std::min)( (std::min)(A.n_rows, A.n_cols), k ); const T A_max = (A.n_nonzero > 0) ? T(max(abs(Col(const_cast(A.values), A.n_nonzero, false)))) : T(0); if(A_max == T(0)) { // TODO: use reset instead ? S.zeros(kk); if(calc_UV) { U.eye(A.n_rows, kk); V.eye(A.n_cols, kk); } } else { SpMat C( (A.n_rows + A.n_cols), (A.n_rows + A.n_cols) ); SpMat B = A / A_max; SpMat Bt = B.t(); C(0, A.n_rows, size(B) ) = B; C(A.n_rows, 0, size(Bt)) = Bt; Bt.reset(); B.reset(); Col eigval; Mat eigvec; const bool status = sp_auxlib::eigs_sym(eigval, eigvec, C, kk, "la", (tol / Datum::sqrt2)); if(status == false) { U.reset(); S.reset(); V.reset(); return false; } const T A_norm = max(eigval); const T tol2 = tol / Datum::sqrt2 * A_norm; uvec indices = find(eigval > tol2); if(indices.n_elem > kk) { indices = indices.subvec(0,kk-1); } else if(indices.n_elem < kk) { const uvec indices2 = find(abs(eigval) <= tol2); const uword N_extra = (std::min)( indices2.n_elem, (kk - indices.n_elem) ); if(N_extra > 0) { indices = join_cols(indices, indices2.subvec(0,N_extra-1)); } } const uvec sorted_indices = sort_index(eigval, "descend"); S = eigval.elem(sorted_indices); S *= A_max; if(calc_UV) { uvec U_row_indices(A.n_rows); for(uword i=0; i < A.n_rows; ++i) { U_row_indices[i] = i; } uvec V_row_indices(A.n_cols); for(uword i=0; i < A.n_cols; ++i) { V_row_indices[i] = i + A.n_rows; } U = Datum::sqrt2 * eigvec(U_row_indices, sorted_indices); V = Datum::sqrt2 * eigvec(V_row_indices, sorted_indices); } } if(S.n_elem < k) { arma_debug_warn("svds(): found fewer singular values than specified"); } return true; } template inline bool svds_helper ( Mat& U, Col& S, Mat& V, const SpBase& X, const uword k, const typename T1::pod_type tol, const bool calc_UV, const typename arma_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; if(arma_config::arpack == false) { arma_stop("svds(): use of ARPACK must be enabled"); return false; } arma_debug_check ( ( ((void*)(&U) == (void*)(&S)) || (&U == &V) || ((void*)(&S) == (void*)(&V)) ), "svds(): two or more output objects are the same object" ); arma_debug_check( (tol < T(0)), "svds(): tol must be >= 0" ); const unwrap_spmat tmp(X.get_ref()); const SpMat& A = tmp.M; const uword kk = (std::min)( (std::min)(A.n_rows, A.n_cols), k ); const T A_max = (A.n_nonzero > 0) ? T(max(abs(Col(const_cast(A.values), A.n_nonzero, false)))) : T(0); if(A_max == T(0)) { // TODO: use reset instead ? S.zeros(kk); if(calc_UV) { U.eye(A.n_rows, kk); V.eye(A.n_cols, kk); } } else { SpMat C( (A.n_rows + A.n_cols), (A.n_rows + A.n_cols) ); SpMat B = A / A_max; SpMat Bt = B.t(); C(0, A.n_rows, size(B) ) = B; C(A.n_rows, 0, size(Bt)) = Bt; Bt.reset(); B.reset(); Col eigval_tmp; Mat eigvec; const bool status = sp_auxlib::eigs_gen(eigval_tmp, eigvec, C, kk, "lr", (tol / Datum::sqrt2)); if(status == false) { U.reset(); S.reset(); V.reset(); arma_debug_warn("svds(): decomposition failed"); return false; } const Col eigval = real(eigval_tmp); const T A_norm = max(eigval); const T tol2 = tol / Datum::sqrt2 * A_norm; uvec indices = find(eigval > tol2); if(indices.n_elem > kk) { indices = indices.subvec(0,kk-1); } else if(indices.n_elem < kk) { const uvec indices2 = find(abs(eigval) <= tol2); const uword N_extra = (std::min)( indices2.n_elem, (kk - indices.n_elem) ); if(N_extra > 0) { indices = join_cols(indices, indices2.subvec(0,N_extra-1)); } } const uvec sorted_indices = sort_index(eigval, "descend"); S = eigval.elem(sorted_indices); S *= A_max; if(calc_UV) { uvec U_row_indices(A.n_rows); for(uword i=0; i < A.n_rows; ++i) { U_row_indices[i] = i; } uvec V_row_indices(A.n_cols); for(uword i=0; i < A.n_cols; ++i) { V_row_indices[i] = i + A.n_rows; } U = Datum::sqrt2 * eigvec(U_row_indices, sorted_indices); V = Datum::sqrt2 * eigvec(V_row_indices, sorted_indices); } } if(S.n_elem < k) { arma_debug_warn("svds(): found fewer singular values than specified"); } return true; } //! find the k largest singular values and corresponding singular vectors of sparse matrix X template inline bool svds ( Mat& U, Col& S, Mat& V, const SpBase& X, const uword k, const typename T1::pod_type tol = 0.0, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const bool status = svds_helper(U, S, V, X.get_ref(), k, tol, true); if(status == false) { arma_debug_warn("svds(): decomposition failed"); } return status; } //! find the k largest singular values of sparse matrix X template inline bool svds ( Col& S, const SpBase& X, const uword k, const typename T1::pod_type tol = 0.0, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Mat U; Mat V; const bool status = svds_helper(U, S, V, X.get_ref(), k, tol, false); if(status == false) { arma_debug_warn("svds(): decomposition failed"); } return status; } //! find the k largest singular values of sparse matrix X template inline Col svds ( const SpBase& X, const uword k, const typename T1::pod_type tol = 0.0, const typename arma_real_or_cx_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); Col S; Mat U; Mat V; const bool status = svds_helper(U, S, V, X.get_ref(), k, tol, false); if(status == false) { arma_bad("svds(): decomposition failed"); } return S; } //! @} armadillo-6.500.5/include/armadillo_bits/access.hpp0000666000000000000000000000271212620272703020722 0ustar rootroot// Copyright (C) 2008-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup access //! @{ class access { public: //! internal function to allow modification of data declared as read-only (use with caution) template arma_inline static T1& rw (const T1& x) { return const_cast(x); } template arma_inline static T1*& rwp(const T1* const& x) { return const_cast(x); } //! internal function to obtain the real part of either a plain number or a complex number template arma_inline static const eT& tmp_real(const eT& X) { return X; } template arma_inline static const T tmp_real(const std::complex& X) { return X.real(); } //! internal function to work around braindead compilers template arma_inline static const typename enable_if2::value, const eT&>::result alt_conj(const eT& X) { return X; } template arma_inline static const typename enable_if2< is_complex::value, const eT >::result alt_conj(const eT& X) { return std::conj(X); } }; //! @} armadillo-6.500.5/include/armadillo_bits/op_shuffle_meat.hpp0000666000000000000000000001170512620272703022623 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_shuffle //! @{ template inline void op_shuffle::apply_direct(Mat& out, const Mat& X, const uword dim) { arma_extra_debug_sigprint(); if(X.is_empty()) { out.copy_size(X); return; } const uword N = (dim == 0) ? X.n_rows : X.n_cols; // see op_sort_index_bones.hpp for the definition of arma_sort_index_packet // and the associated comparison functor std::vector< arma_sort_index_packet > packet_vec(N); for(uword i=0; i()); packet_vec[i].index = i; } arma_sort_index_helper_ascend comparator; std::sort( packet_vec.begin(), packet_vec.end(), comparator ); const bool is_alias = (&out == &X); if(X.is_vec() == false) { if(is_alias == false) { arma_extra_debug_print("op_shuffle::apply(): matrix"); out.copy_size(X); if(dim == 0) { for(uword i=0; i 1) // i.e. column vector { for(uword i=0; i 1) // i.e. row vector { for(uword i=0; i 1) // i.e. column vector { for(uword i=0; i 1) // i.e. row vector { for(uword i=0; i inline void op_shuffle::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const unwrap U(in.m); const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "shuffle(): parameter 'dim' must be 0 or 1" ); op_shuffle::apply_direct(out, U.M, dim); } template inline void op_shuffle_default::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const unwrap U(in.m); const uword dim = (T1::is_row) ? 1 : 0; op_shuffle::apply_direct(out, U.M, dim); } //! @} armadillo-6.500.5/include/armadillo_bits/op_relational_meat.hpp0000666000000000000000000002331112620272703023315 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_relational //! @{ #undef operator_rel #undef arma_applier_mat_pre #undef arma_applier_mat_post #undef arma_applier_cube_pre #undef arma_applier_cube_post #define arma_applier_mat_pre(operator_rel) \ {\ typedef typename T1::elem_type eT;\ typedef typename Proxy::ea_type ea_type;\ \ const eT val = X.aux;\ \ const Proxy P(X.m);\ \ const uword n_rows = P.get_n_rows();\ const uword n_cols = P.get_n_cols();\ \ const bool bad_alias = ( Proxy::has_subview && P.is_alias(out) );\ \ if(bad_alias == false)\ {\ out.set_size(n_rows, n_cols);\ \ uword* out_mem = out.memptr();\ \ if(Proxy::prefer_at_accessor == false)\ {\ ea_type PA = P.get_ea();\ const uword n_elem = out.n_elem;\ \ for(uword i=0; i tmp(P.Q);\ \ out = (val) operator_rel (tmp);\ }\ } #define arma_applier_mat_post(operator_rel) \ {\ typedef typename T1::elem_type eT;\ typedef typename Proxy::ea_type ea_type;\ \ const eT val = X.aux;\ \ const Proxy P(X.m);\ \ const uword n_rows = P.get_n_rows();\ const uword n_cols = P.get_n_cols();\ \ const bool bad_alias = ( Proxy::has_subview && P.is_alias(out) );\ \ if(bad_alias == false)\ {\ out.set_size(n_rows, n_cols);\ \ uword* out_mem = out.memptr();\ \ if(Proxy::prefer_at_accessor == false)\ {\ ea_type PA = P.get_ea();\ const uword n_elem = out.n_elem;\ \ for(uword i=0; i tmp(P.Q);\ \ out = (tmp) operator_rel (val);\ }\ } #define arma_applier_cube_pre(operator_rel) \ {\ typedef typename T1::elem_type eT;\ typedef typename ProxyCube::ea_type ea_type;\ \ const eT val = X.aux;\ \ const ProxyCube P(X.m);\ \ const uword n_rows = P.get_n_rows();\ const uword n_cols = P.get_n_cols();\ const uword n_slices = P.get_n_slices();\ \ const bool bad_alias = ( ProxyCube::has_subview && P.is_alias(out) );\ \ if(bad_alias == false)\ {\ out.set_size(n_rows, n_cols, n_slices);\ \ uword* out_mem = out.memptr();\ \ if(ProxyCube::prefer_at_accessor == false)\ {\ ea_type PA = P.get_ea();\ const uword n_elem = out.n_elem;\ \ for(uword i=0; i::stored_type> tmp(P.Q);\ \ out = (val) operator_rel (tmp.M);\ }\ } #define arma_applier_cube_post(operator_rel) \ {\ typedef typename T1::elem_type eT;\ typedef typename ProxyCube::ea_type ea_type;\ \ const eT val = X.aux;\ \ const ProxyCube P(X.m);\ \ const uword n_rows = P.get_n_rows();\ const uword n_cols = P.get_n_cols();\ const uword n_slices = P.get_n_slices();\ \ const bool bad_alias = ( ProxyCube::has_subview && P.is_alias(out) );\ \ if(bad_alias == false)\ {\ out.set_size(n_rows, n_cols, n_slices);\ \ uword* out_mem = out.memptr();\ \ if(ProxyCube::prefer_at_accessor == false)\ {\ ea_type PA = P.get_ea();\ const uword n_elem = out.n_elem;\ \ for(uword i=0; i::stored_type> tmp(P.Q);\ \ out = (tmp.M) operator_rel (val);\ }\ } template inline void op_rel_lt_pre::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_pre( < ); } template inline void op_rel_gt_pre::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_pre( > ); } template inline void op_rel_lteq_pre::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_pre( <= ); } template inline void op_rel_gteq_pre::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_pre( >= ); } template inline void op_rel_lt_post::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( < ); } template inline void op_rel_gt_post::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( > ); } template inline void op_rel_lteq_post::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( <= ); } template inline void op_rel_gteq_post::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( >= ); } template inline void op_rel_eq::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( == ); } template inline void op_rel_noteq::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); arma_applier_mat_post( != ); } // // // template inline void op_rel_lt_pre::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_pre( < ); } template inline void op_rel_gt_pre::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_pre( > ); } template inline void op_rel_lteq_pre::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_pre( <= ); } template inline void op_rel_gteq_pre::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_pre( >= ); } template inline void op_rel_lt_post::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( < ); } template inline void op_rel_gt_post::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( > ); } template inline void op_rel_lteq_post::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( <= ); } template inline void op_rel_gteq_post::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( >= ); } template inline void op_rel_eq::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( == ); } template inline void op_rel_noteq::apply(Cube& out, const mtOpCube& X) { arma_extra_debug_sigprint(); arma_applier_cube_post( != ); } #undef arma_applier_mat_pre #undef arma_applier_mat_post #undef arma_applier_cube_pre #undef arma_applier_cube_post //! @} armadillo-6.500.5/include/armadillo_bits/op_cumsum_bones.hpp0000666000000000000000000000156412620272703022662 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_cumsum //! @{ class op_cumsum { public: template inline static void apply_noalias(Mat& out, const Mat& X, const uword dim); template inline static void apply(Mat& out, const Op& in); }; class op_cumsum_default { public: template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/operator_div.hpp0000666000000000000000000001641312620272703022161 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup operator_div //! @{ //! Base / scalar template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator/ ( const T1& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOp(X, k); } //! scalar / Base template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator/ ( const typename T1::elem_type k, const T1& X ) { arma_extra_debug_sigprint(); return eOp(X, k); } //! complex scalar / non-complex Base template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_div_pre> >::result operator/ ( const std::complex& k, const T1& X ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_div_pre>('j', X, k); } //! non-complex Base / complex scalar template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_div_post> >::result operator/ ( const T1& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_div_post>('j', X, k); } //! element-wise division of Base objects with same element type template arma_inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && is_same_type::value), const eGlue >::result operator/ ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return eGlue(X, Y); } //! element-wise division of Base objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue::result, T1, T2, glue_mixed_div> >::result operator/ ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! element-wise division of sparse matrix by scalar template inline typename enable_if2::value, SpMat >::result operator/ ( const T1& X, const typename T1::elem_type y ) { arma_extra_debug_sigprint(); SpMat result(X); result /= y; return result; } //! element-wise division of one sparse and one dense object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), SpMat >::result operator/ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(x); const Proxy pb(y); const uword n_rows = pa.get_n_rows(); const uword n_cols = pa.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, pb.get_n_rows(), pb.get_n_cols(), "element-wise division"); SpMat result(n_rows, n_cols); uword new_n_nonzero = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT val = pa.at(row,col) / pb.at(row, col); if(val != eT(0)) { ++new_n_nonzero; } } result.mem_resize(new_n_nonzero); uword cur_pos = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT val = pa.at(row,col) / pb.at(row, col); if(val != eT(0)) { access::rw(result.values[cur_pos]) = val; access::rw(result.row_indices[cur_pos]) = row; ++access::rw(result.col_ptrs[col + 1]); ++cur_pos; } } // Fix column pointers for(uword col = 1; col <= result.n_cols; ++col) { access::rw(result.col_ptrs[col]) += result.col_ptrs[col - 1]; } return result; } //! element-wise division of one dense and one sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), Mat >::result operator/ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy pa(x); const SpProxy pb(y); const uword n_rows = pa.get_n_rows(); const uword n_cols = pa.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, pb.get_n_rows(), pb.get_n_cols(), "element-wise division"); Mat result(n_rows, n_cols); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { result.at(row, col) = pa.at(row, col) / pb.at(row, col); } return result; } template arma_inline Mat operator/ ( const subview_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_each1_aux::operator_div(X, Y.get_ref()); } template arma_inline Mat operator/ ( const Base& X, const subview_each1& Y ) { arma_extra_debug_sigprint(); return subview_each1_aux::operator_div(X.get_ref(), Y); } template arma_inline Mat operator/ ( const subview_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_each2_aux::operator_div(X, Y.get_ref()); } template arma_inline Mat operator/ ( const Base& X, const subview_each2& Y ) { arma_extra_debug_sigprint(); return subview_each2_aux::operator_div(X.get_ref(), Y); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_randu.hpp0000666000000000000000000000730612620272703021261 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_randu //! @{ inline double randu() { return arma_rng::randu(); } template inline typename arma_scalar_only::result randu() { return eT(arma_rng::randu()); } //! Generate a vector with all elements set to random values in the [0,1] interval (uniform distribution) arma_inline const Gen randu(const uword n_elem) { arma_extra_debug_sigprint(); return Gen(n_elem, 1); } template arma_inline const Gen randu(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value == true) { return Gen(1, n_elem); } else { return Gen(n_elem, 1); } } //! Generate a dense matrix with all elements set to random values in the [0,1] interval (uniform distribution) arma_inline const Gen randu(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } arma_inline const Gen randu(const SizeMat& s) { arma_extra_debug_sigprint(); return Gen(s.n_rows, s.n_cols); } template arma_inline const Gen randu(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "randu(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "randu(): incompatible size" ); } return Gen(n_rows, n_cols); } template arma_inline const Gen randu(const SizeMat& s, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return randu(s.n_rows, s.n_cols); } arma_inline const GenCube randu(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return GenCube(n_rows, n_cols, n_slices); } arma_inline const GenCube randu(const SizeCube& s) { arma_extra_debug_sigprint(); return GenCube(s.n_rows, s.n_cols, s.n_slices); } template arma_inline const GenCube randu(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(n_rows, n_cols, n_slices); } template arma_inline const GenCube randu(const SizeCube& s, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(s.n_rows, s.n_cols, s.n_slices); } //! @} armadillo-6.500.5/include/armadillo_bits/arma_cmath.hpp0000666000000000000000000002130712620272703021556 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arma_cmath //! @{ // // wrappers for isfinite template arma_inline bool arma_isfinite(eT val) { arma_ignore(val); return true; } template<> arma_inline bool arma_isfinite(float x) { #if defined(ARMA_USE_CXX11) { return std::isfinite(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::isfinite(x); } #elif defined(ARMA_HAVE_ISFINITE) { return (std::isfinite(x) != 0); } #else { const float y = (std::numeric_limits::max)(); const volatile float xx = x; return (xx == xx) && (x >= -y) && (x <= y); } #endif } template<> arma_inline bool arma_isfinite(double x) { #if defined(ARMA_USE_CXX11) { return std::isfinite(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::isfinite(x); } #elif defined(ARMA_HAVE_ISFINITE) { return (std::isfinite(x) != 0); } #else { const double y = (std::numeric_limits::max)(); const volatile double xx = x; return (xx == xx) && (x >= -y) && (x <= y); } #endif } template arma_inline bool arma_isfinite(const std::complex& x) { if( (arma_isfinite(x.real()) == false) || (arma_isfinite(x.imag()) == false) ) { return false; } else { return true; } } // // wrappers for isinf template arma_inline bool arma_isinf(eT val) { arma_ignore(val); return false; } template<> arma_inline bool arma_isinf(float x) { #if defined(ARMA_USE_CXX11) { return std::isinf(x); } #elif defined(ARMA_HAVE_ISINF) { return (std::isinf(x) != 0); } #else { const float y = (std::numeric_limits::max)(); const volatile float xx = x; return (xx == xx) && ((x < -y) || (x > y)); } #endif } template<> arma_inline bool arma_isinf(double x) { #if defined(ARMA_USE_CXX11) { return std::isinf(x); } #elif defined(ARMA_HAVE_ISINF) { return (std::isinf(x) != 0); } #else { const double y = (std::numeric_limits::max)(); const volatile double xx = x; return (xx == xx) && ((x < -y) || (x > y)); } #endif } template arma_inline bool arma_isinf(const std::complex& x) { return ( arma_isinf(x.real()) || arma_isinf(x.imag()) ); } // // wrappers for isnan template arma_inline bool arma_isnan(eT val) { arma_ignore(val); return false; } template<> arma_inline bool arma_isnan(float x) { #if defined(ARMA_USE_CXX11) { return std::isnan(x); } #elif defined(ARMA_HAVE_ISNAN) { return (std::isnan(x) != 0); } #else { const volatile float xx = x; return (xx != xx); } #endif } template<> arma_inline bool arma_isnan(double x) { #if defined(ARMA_USE_CXX11) { return std::isnan(x); } #elif defined(ARMA_HAVE_ISNAN) { return (std::isnan(x) != 0); } #else { const volatile double xx = x; return (xx != xx); } #endif } template arma_inline bool arma_isnan(const std::complex& x) { return ( arma_isnan(x.real()) || arma_isnan(x.imag()) ); } // rudimentary wrappers for log1p() arma_inline float arma_log1p(const float x) { #if defined(ARMA_USE_CXX11) { return std::log1p(x); } #else { if((x >= float(0)) && (x < std::numeric_limits::epsilon())) { return x; } else if((x < float(0)) && (-x < std::numeric_limits::epsilon())) { return x; } else { return std::log(float(1) + x); } } #endif } arma_inline double arma_log1p(const double x) { #if defined(ARMA_USE_CXX11) { return std::log1p(x); } #elif defined(ARMA_HAVE_LOG1P) { return log1p(x); } #else { if((x >= double(0)) && (x < std::numeric_limits::epsilon())) { return x; } else if((x < double(0)) && (-x < std::numeric_limits::epsilon())) { return x; } else { return std::log(double(1) + x); } } #endif } // // wrappers for trigonometric functions // // wherever possible, try to use C++11 or TR1 versions of the following functions: // // complex acos // complex asin // complex atan // // real acosh // real asinh // real atanh // // complex acosh // complex asinh // complex atanh // // // if C++11 or TR1 are not available, we have rudimentary versions of: // // real acosh // real asinh // real atanh template arma_inline std::complex arma_acos(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::acos(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::acos(x); } #else { arma_ignore(x); arma_stop("acos(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline std::complex arma_asin(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::asin(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::asin(x); } #else { arma_ignore(x); arma_stop("asin(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline std::complex arma_atan(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::atan(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::atan(x); } #else { arma_ignore(x); arma_stop("atan(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline eT arma_acosh(const eT x) { #if defined(ARMA_USE_CXX11) { return std::acosh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::acosh(x); } #else { if(x >= eT(1)) { // http://functions.wolfram.com/ElementaryFunctions/ArcCosh/02/ return std::log( x + std::sqrt(x*x - eT(1)) ); } else { if(std::numeric_limits::has_quiet_NaN) { return -(std::numeric_limits::quiet_NaN()); } else { return eT(0); } } } #endif } template arma_inline eT arma_asinh(const eT x) { #if defined(ARMA_USE_CXX11) { return std::asinh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::asinh(x); } #else { // http://functions.wolfram.com/ElementaryFunctions/ArcSinh/02/ return std::log( x + std::sqrt(x*x + eT(1)) ); } #endif } template arma_inline eT arma_atanh(const eT x) { #if defined(ARMA_USE_CXX11) { return std::atanh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::atanh(x); } #else { if( (x >= eT(-1)) && (x <= eT(+1)) ) { // http://functions.wolfram.com/ElementaryFunctions/ArcTanh/02/ return std::log( ( eT(1)+x ) / ( eT(1)-x ) ) / eT(2); } else { if(std::numeric_limits::has_quiet_NaN) { return -(std::numeric_limits::quiet_NaN()); } else { return eT(0); } } } #endif } template arma_inline std::complex arma_acosh(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::acosh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::acosh(x); } #else { arma_ignore(x); arma_stop("acosh(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline std::complex arma_asinh(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::asinh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::asinh(x); } #else { arma_ignore(x); arma_stop("asinh(): need C++11 compiler"); return std::complex(0); } #endif } template arma_inline std::complex arma_atanh(const std::complex& x) { #if defined(ARMA_USE_CXX11) { return std::atanh(x); } #elif defined(ARMA_HAVE_TR1) { return std::tr1::atanh(x); } #else { arma_ignore(x); arma_stop("atanh(): need C++11 compiler"); return std::complex(0); } #endif } //! @} armadillo-6.500.5/include/armadillo_bits/glue_solve_bones.hpp0000666000000000000000000000545212626464473023034 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_solve //! @{ class glue_solve_gen { public: template inline static void apply(Mat& out, const Glue& X); template inline static bool apply(Mat& out, const Base& A_expr, const Base& B_expr, const uword flags); }; class glue_solve_tri { public: template inline static void apply(Mat& out, const Glue& X); template inline static bool apply(Mat& out, const Base& A_expr, const Base& B_expr, const uword flags); }; namespace solve_opts { struct opts { const uword flags; inline explicit opts(const uword in_flags); inline const opts operator+(const opts& rhs) const; }; inline opts::opts(const uword in_flags) : flags(in_flags) {} inline const opts opts::operator+(const opts& rhs) const { const opts result( flags | rhs.flags ); return result; } // The values below (eg. 1u << 1) are for internal Armadillo use only. // The values can change without notice. static const uword flag_none = uword(0 ); static const uword flag_fast = uword(1u << 0); static const uword flag_equilibrate = uword(1u << 1); static const uword flag_no_approx = uword(1u << 2); static const uword flag_triu = uword(1u << 3); static const uword flag_tril = uword(1u << 4); struct opts_none : public opts { inline opts_none() : opts(flag_none ) {} }; struct opts_fast : public opts { inline opts_fast() : opts(flag_fast ) {} }; struct opts_equilibrate : public opts { inline opts_equilibrate() : opts(flag_equilibrate) {} }; struct opts_no_approx : public opts { inline opts_no_approx() : opts(flag_no_approx ) {} }; struct opts_triu : public opts { inline opts_triu() : opts(flag_triu ) {} }; struct opts_tril : public opts { inline opts_tril() : opts(flag_tril ) {} }; static const opts_none none; static const opts_fast fast; static const opts_equilibrate equilibrate; static const opts_no_approx no_approx; static const opts_triu triu; static const opts_tril tril; } //! @} armadillo-6.500.5/include/armadillo_bits/op_unique_bones.hpp0000666000000000000000000000235512620272703022656 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Arnold Wiliem //! \addtogroup op_unique //! @{ class op_unique { public: template inline static bool apply_helper(Mat& out, const Proxy& P); template inline static void apply(Mat& out, const Op& in); }; template struct arma_unique_comparator { arma_inline bool operator() (const eT a, const eT b) const { return ( a < b ); } }; template struct arma_unique_comparator< std::complex > { arma_inline bool operator() (const std::complex& a, const std::complex& b) const { const T a_real = a.real(); const T b_real = b.real(); return ( (a_real < b_real) ? true : ((a_real == b_real) ? (a.imag() < b.imag()) : false) ); } }; //! @} armadillo-6.500.5/include/armadillo_bits/op_sum_bones.hpp0000666000000000000000000000202212620272703022143 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_sum //! @{ class op_sum { public: template arma_hot inline static void apply(Mat& out, const Op& in); template arma_hot inline static void apply_noalias(Mat& out, const Proxy& P, const uword dim); template arma_hot inline static void apply_noalias_unwrap(Mat& out, const Proxy& P, const uword dim); template arma_hot inline static void apply_noalias_proxy(Mat& out, const Proxy& P, const uword dim); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_sum.hpp0000666000000000000000000000725012620272703020752 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_sum //! @{ //! \brief //! Delayed sum of elements of a matrix along a specified dimension (either rows or columns). //! The result is stored in a dense matrix that has either one column or one row. //! For dim = 0, find the sum of each column (traverse across rows) //! For dim = 1, find the sum of each row (traverse across columns) //! The default is dim = 0. //! NOTE: the dim argument is different than in Matlab/Octave. template arma_inline const Op sum ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op sum ( const T1& X, const uword dim, const typename enable_if< resolves_to_vector::value == true >::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } //! \brief //! Immediate 'sum all values' operation for expressions which resolve to a vector template inline arma_warn_unused typename T1::elem_type sum ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if< resolves_to_vector::value == true >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return accu(X); } //! \brief //! Immediate 'sum all values' operation, //! invoked, for example, by: sum(sum(A)) template inline arma_warn_unused typename T1::elem_type sum(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("sum(): two consecutive sum() calls detected"); return accu(in.m); } template arma_inline const Op, op_sum> sum(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op, op_sum>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & sum(const T& x) { return x; } //! sum of sparse object template inline typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == true), typename T1::elem_type >::result sum(const T1& x) { arma_extra_debug_sigprint(); // sum elements return accu(x); } template inline typename enable_if2 < (is_arma_sparse_type::value == true) && (resolves_to_sparse_vector::value == false), const SpOp >::result sum(const T1& x, const uword dim = 0) { arma_extra_debug_sigprint(); return SpOp(x, dim, 0); } template inline arma_warn_unused typename T1::elem_type sum(const SpOp& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("sum(): two consecutive sum() calls detected"); return accu(in.m); } template arma_inline const SpOp, spop_sum> sum(const SpOp& in, const uword dim) { arma_extra_debug_sigprint(); return SpOp, spop_sum>(in, dim, 0); } //! @} armadillo-6.500.5/include/armadillo_bits/Op_meat.hpp0000666000000000000000000000336412620272703021051 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Op //! @{ template inline Op::Op(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline Op::Op(const T1& in_m, const typename T1::elem_type in_aux) : m(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline Op::Op(const T1& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline Op::Op(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline Op::Op(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c, const char) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) , aux_uword_c(in_aux_uword_c) { arma_extra_debug_sigprint(); } template inline Op::~Op() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/Col_meat.hpp0000666000000000000000000010331112650111756021204 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Col //! @{ //! construct an empty column vector template inline Col::Col() : Mat(arma_vec_indicator(), 1) { arma_extra_debug_sigprint(); } template inline Col::Col(const Col& X) : Mat(arma_vec_indicator(), X.n_elem, 1, 1) { arma_extra_debug_sigprint(); arrayops::copy((*this).memptr(), X.memptr(), X.n_elem); } //! construct a column vector with the specified number of n_elem template inline Col::Col(const uword in_n_elem) : Mat(arma_vec_indicator(), in_n_elem, 1, 1) { arma_extra_debug_sigprint(); } template inline Col::Col(const uword in_n_rows, const uword in_n_cols) : Mat(arma_vec_indicator(), 0, 0, 1) { arma_extra_debug_sigprint(); Mat::init_warm(in_n_rows, in_n_cols); } template inline Col::Col(const SizeMat& s) : Mat(arma_vec_indicator(), 0, 0, 1) { arma_extra_debug_sigprint(); Mat::init_warm(s.n_rows, s.n_cols); } template template inline Col::Col(const uword in_n_elem, const fill::fill_class& f) : Mat(arma_vec_indicator(), in_n_elem, 1, 1) { arma_extra_debug_sigprint(); (*this).fill(f); } template template inline Col::Col(const uword in_n_rows, const uword in_n_cols, const fill::fill_class& f) : Mat(arma_vec_indicator(), 0, 0, 1) { arma_extra_debug_sigprint(); Mat::init_warm(in_n_rows, in_n_cols); (*this).fill(f); } template template inline Col::Col(const SizeMat& s, const fill::fill_class& f) : Mat(arma_vec_indicator(), 0, 0, 1) { arma_extra_debug_sigprint(); Mat::init_warm(s.n_rows, s.n_cols); (*this).fill(f); } //! construct a column vector from specified text template inline Col::Col(const char* text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; } //! construct a column vector from specified text template inline const Col& Col::operator=(const char* text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; return *this; } //! construct a column vector from specified text template inline Col::Col(const std::string& text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; } //! construct a column vector from specified text template inline const Col& Col::operator=(const std::string& text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; return *this; } //! create a column vector from std::vector template inline Col::Col(const std::vector& x) : Mat(arma_vec_indicator(), uword(x.size()), 1, 1) { arma_extra_debug_sigprint_this(this); if(x.size() > 0) { arrayops::copy( Mat::memptr(), &(x[0]), uword(x.size()) ); } } //! create a column vector from std::vector template inline const Col& Col::operator=(const std::vector& x) { arma_extra_debug_sigprint(); Mat::init_warm(uword(x.size()), 1); if(x.size() > 0) { arrayops::copy( Mat::memptr(), &(x[0]), uword(x.size()) ); } return *this; } #if defined(ARMA_USE_CXX11) template inline Col::Col(const std::initializer_list& list) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(list); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; } template inline const Col& Col::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(list); std::swap( access::rw(Mat::n_rows), access::rw(Mat::n_cols) ); access::rw(Mat::vec_state) = 1; return *this; } template inline Col::Col(Col&& X) : Mat(arma_vec_indicator(), 1) { arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); access::rw(Mat::n_rows) = X.n_rows; access::rw(Mat::n_cols) = 1; access::rw(Mat::n_elem) = X.n_elem; if( ((X.mem_state == 0) && (X.n_elem > arma_config::mat_prealloc)) || (X.mem_state == 1) || (X.mem_state == 2) ) { access::rw(Mat::mem_state) = X.mem_state; access::rw(Mat::mem) = X.mem; access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 1; access::rw(X.n_elem) = 0; access::rw(X.mem_state) = 0; access::rw(X.mem) = 0; } else { (*this).init_cold(); arrayops::copy( (*this).memptr(), X.mem, X.n_elem ); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) ) { access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 1; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } } } template inline const Col& Col::operator=(Col&& X) { arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); (*this).steal_mem(X); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) && (this != &X) ) { access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 1; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } return *this; } #endif template inline Col::Col(const SpCol& X) : Mat(arma_vec_indicator(), X.n_elem, 1, 1) { arma_extra_debug_sigprint_this(this); arrayops::inplace_set(Mat::memptr(), eT(0), X.n_elem); for(typename SpCol::const_iterator it = X.begin(); it != X.end(); ++it) { at(it.row()) = (*it); } } template inline const Col& Col::operator=(const eT val) { arma_extra_debug_sigprint(); Mat::operator=(val); return *this; } template inline const Col& Col::operator=(const Col& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template template inline Col::Col(const Base& X) : Mat(arma_vec_indicator(), 1) { arma_extra_debug_sigprint(); Mat::operator=(X.get_ref()); } template template inline const Col& Col::operator=(const Base& X) { arma_extra_debug_sigprint(); Mat::operator=(X.get_ref()); return *this; } //! construct a column vector from a given auxiliary array of eTs template inline Col::Col(eT* aux_mem, const uword aux_length, const bool copy_aux_mem, const bool strict) : Mat(aux_mem, aux_length, 1, copy_aux_mem, strict) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; } //! construct a column vector from a given auxiliary array of eTs template inline Col::Col(const eT* aux_mem, const uword aux_length) : Mat(aux_mem, aux_length, 1) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; } template template inline Col::Col ( const Base::pod_type, T1>& A, const Base::pod_type, T2>& B ) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; Mat::init(A,B); } template template inline Col::Col(const BaseCube& X) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; Mat::operator=(X); } template template inline const Col& Col::operator=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template inline Col::Col(const subview_cube& X) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 1; Mat::operator=(X); } template inline const Col& Col::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template inline mat_injector< Col > Col::operator<<(const eT val) { return mat_injector< Col >(*this, val); } template arma_inline const Op,op_htrans> Col::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> Col::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> Col::st() const { return Op,op_strans>(*this); } template arma_inline subview_col Col::row(const uword in_row1) { arma_extra_debug_sigprint(); arma_debug_check( (in_row1 >= Mat::n_rows), "Col::row(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, 1); } template arma_inline const subview_col Col::row(const uword in_row1) const { arma_extra_debug_sigprint(); arma_debug_check( (in_row1 >= Mat::n_rows), "Col::row(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, 1); } template arma_inline subview_col Col::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows) ), "Col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline const subview_col Col::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows) ), "Col::rows(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline subview_col Col::subvec(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows) ), "Col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline const subview_col Col::subvec(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows) ), "Col::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview_col(*this, 0, in_row1, subview_n_rows); } template arma_inline subview_col Col::rows(const span& row_span) { arma_extra_debug_sigprint(); return subvec(row_span); } template arma_inline const subview_col Col::rows(const span& row_span) const { arma_extra_debug_sigprint(); return subvec(row_span); } template arma_inline subview_col Col::subvec(const span& row_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = Mat::n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subvec_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ), "Col::subvec(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, subvec_n_rows); } template arma_inline const subview_col Col::subvec(const span& row_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = Mat::n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subvec_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ), "Col::subvec(): indices out of bounds or incorrectly used"); return subview_col(*this, 0, in_row1, subvec_n_rows); } template arma_inline subview_col Col::operator()(const span& row_span) { arma_extra_debug_sigprint(); return subvec(row_span); } template arma_inline const subview_col Col::operator()(const span& row_span) const { arma_extra_debug_sigprint(); return subvec(row_span); } template arma_inline subview_col Col::head(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > Mat::n_rows), "Col::head(): size out of bounds"); return subview_col(*this, 0, 0, N); } template arma_inline const subview_col Col::head(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > Mat::n_rows), "Col::head(): size out of bounds"); return subview_col(*this, 0, 0, N); } template arma_inline subview_col Col::tail(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > Mat::n_rows), "Col::tail(): size out of bounds"); const uword start_row = Mat::n_rows - N; return subview_col(*this, 0, start_row, N); } template arma_inline const subview_col Col::tail(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > Mat::n_rows), "Col::tail(): size out of bounds"); const uword start_row = Mat::n_rows - N; return subview_col(*this, 0, start_row, N); } template arma_inline subview_col Col::head_rows(const uword N) { arma_extra_debug_sigprint(); return (*this).head(N); } template arma_inline const subview_col Col::head_rows(const uword N) const { arma_extra_debug_sigprint(); return (*this).head(N); } template arma_inline subview_col Col::tail_rows(const uword N) { arma_extra_debug_sigprint(); return (*this).tail(N); } template arma_inline const subview_col Col::tail_rows(const uword N) const { arma_extra_debug_sigprint(); return (*this).tail(N); } //! remove specified row template inline void Col::shed_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= Mat::n_rows, "Col::shed_row(): index out of bounds"); shed_rows(row_num, row_num); } //! remove specified rows template inline void Col::shed_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= Mat::n_rows), "Col::shed_rows(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_row1; const uword n_keep_back = Mat::n_rows - (in_row2 + 1); Col X(n_keep_front + n_keep_back); eT* X_mem = X.memptr(); const eT* t_mem = (*this).memptr(); if(n_keep_front > 0) { arrayops::copy( X_mem, t_mem, n_keep_front ); } if(n_keep_back > 0) { arrayops::copy( &(X_mem[n_keep_front]), &(t_mem[in_row2+1]), n_keep_back); } Mat::steal_mem(X); } //! insert N rows at the specified row position, //! optionally setting the elements of the inserted rows to zero template inline void Col::insert_rows(const uword row_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_rows = Mat::n_rows; const uword A_n_rows = row_num; const uword B_n_rows = t_n_rows - row_num; // insertion at row_num == n_rows is in effect an append operation arma_debug_check( (row_num > t_n_rows), "Col::insert_rows(): index out of bounds"); if(N > 0) { Col out(t_n_rows + N); eT* out_mem = out.memptr(); const eT* t_mem = (*this).memptr(); if(A_n_rows > 0) { arrayops::copy( out_mem, t_mem, A_n_rows ); } if(B_n_rows > 0) { arrayops::copy( &(out_mem[row_num + N]), &(t_mem[row_num]), B_n_rows ); } if(set_to_zero == true) { arrayops::inplace_set( &(out_mem[row_num]), eT(0), N ); } Mat::steal_mem(out); } } //! insert the given object at the specified row position; //! the given object must have one column template template inline void Col::insert_rows(const uword row_num, const Base& X) { arma_extra_debug_sigprint(); Mat::insert_rows(row_num, X); } template arma_inline arma_warn_unused eT& Col::at(const uword i) { return access::rw(Mat::mem[i]); } template arma_inline arma_warn_unused const eT& Col::at(const uword i) const { return Mat::mem[i]; } template arma_inline arma_warn_unused eT& Col::at(const uword in_row, const uword) { return access::rw( Mat::mem[in_row] ); } template arma_inline arma_warn_unused const eT& Col::at(const uword in_row, const uword) const { return Mat::mem[in_row]; } template inline typename Col::row_iterator Col::begin_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "Col::begin_row(): index out of bounds"); return Mat::memptr() + row_num; } template inline typename Col::const_row_iterator Col::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "Col::begin_row(): index out of bounds"); return Mat::memptr() + row_num; } template inline typename Col::row_iterator Col::end_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "Col::end_row(): index out of bounds"); return Mat::memptr() + row_num + 1; } template inline typename Col::const_row_iterator Col::end_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "Col::end_row(): index out of bounds"); return Mat::memptr() + row_num + 1; } template template arma_inline void Col::fixed::change_to_row() { arma_extra_debug_sigprint(); access::rw(Mat::n_cols) = fixed_n_elem; access::rw(Mat::n_rows) = 1; } template template arma_inline Col::fixed::fixed() : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); } template template arma_inline Col::fixed::fixed(const fixed& X) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } template template inline Col::fixed::fixed(const subview_cube& X) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Col::operator=(X); } template template template inline Col::fixed::fixed(const fill::fill_class&) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).eye(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); } template template template inline Col::fixed::fixed(const Base& A) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Col::operator=(A.get_ref()); } template template template inline Col::fixed::fixed(const Base& A, const Base& B) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Col::init(A,B); } template template inline Col::fixed::fixed(const eT* aux_mem) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; arrayops::copy( dest, aux_mem, fixed_n_elem ); } //! NOTE: this function relies on //! Col::operator=(text), to change vec_state as well as swapping n_rows and n_cols, //! and Mat::init(), to check that the given vector will not have a different size than fixed_n_elem. template template inline Col::fixed::fixed(const char* text) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); change_to_row(); Col::operator=(text); } //! NOTE: this function relies on //! Col::operator=(text), to change vec_state as well as swapping n_rows and n_cols, //! and Mat::init(), to check that the given vector will not have a different size than fixed_n_elem. template template inline Col::fixed::fixed(const std::string& text) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); change_to_row(); Col::operator=(text); } template template template const Col& Col::fixed::operator=(const Base& A) { arma_extra_debug_sigprint(); Col::operator=(A.get_ref()); return *this; } template template const Col& Col::fixed::operator=(const eT val) { arma_extra_debug_sigprint(); Col::operator=(val); return *this; } template template const Col& Col::fixed::operator=(const char* text) { arma_extra_debug_sigprint(); change_to_row(); Col::operator=(text); return *this; } template template const Col& Col::fixed::operator=(const std::string& text) { arma_extra_debug_sigprint(); change_to_row(); Col::operator=(text); return *this; } template template const Col& Col::fixed::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); Col::operator=(X); return *this; } #if defined(ARMA_USE_CXX11) template template inline Col::fixed::fixed(const std::initializer_list& list) : Col( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); (*this).operator=(list); } template template inline const Col& Col::fixed::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); const uword N = uword(list.size()); arma_debug_check( (N > fixed_n_elem), "Col::fixed: initialiser list is too long" ); eT* this_mem = (*this).memptr(); arrayops::copy( this_mem, list.begin(), N ); for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); } return *this; } #endif template template arma_inline const Col& Col::fixed::operator=(const fixed& X) { arma_extra_debug_sigprint(); if(this != &X) { eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } return *this; } #if defined(ARMA_GOOD_COMPILER) template template template inline const Col& Col::fixed::operator=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const bool bad_alias = (eOp::proxy_type::has_subview && X.P.is_alias(*this)); if(bad_alias == false) { arma_debug_assert_same_size(fixed_n_elem, uword(1), X.get_n_rows(), X.get_n_cols(), "Col::fixed::operator="); eop_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Col tmp(X); (*this) = tmp; } return *this; } template template template inline const Col& Col::fixed::operator=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const bool bad_alias = ( (eGlue::proxy1_type::has_subview && X.P1.is_alias(*this)) || (eGlue::proxy2_type::has_subview && X.P2.is_alias(*this)) ); if(bad_alias == false) { arma_debug_assert_same_size(fixed_n_elem, uword(1), X.get_n_rows(), X.get_n_cols(), "Col::fixed::operator="); eglue_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Col tmp(X); (*this) = tmp; } return *this; } #endif template template arma_inline const Op< typename Col::template fixed::Col_fixed_type, op_htrans > Col::fixed::t() const { return Op< typename Col::template fixed::Col_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Col::template fixed::Col_fixed_type, op_htrans > Col::fixed::ht() const { return Op< typename Col::template fixed::Col_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Col::template fixed::Col_fixed_type, op_strans > Col::fixed::st() const { return Op< typename Col::template fixed::Col_fixed_type, op_strans >(*this); } template template arma_inline arma_warn_unused const eT& Col::fixed::at_alt(const uword ii) const { #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; #else const eT* mem_aligned = (use_extra) ? mem_local_extra : Mat::mem_local; memory::mark_as_aligned(mem_aligned); return mem_aligned[ii]; #endif } template template arma_inline arma_warn_unused eT& Col::fixed::operator[] (const uword ii) { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Col::fixed::operator[] (const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Col::fixed::at(const uword ii) { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Col::fixed::at(const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Col::fixed::operator() (const uword ii) { arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Col::fixed::operator() (const uword ii) const { arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Col::fixed::at(const uword in_row, const uword) { return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } template template arma_inline arma_warn_unused const eT& Col::fixed::at(const uword in_row, const uword) const { return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } template template arma_inline arma_warn_unused eT& Col::fixed::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } template template arma_inline arma_warn_unused const eT& Col::fixed::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_row] : Mat::mem_local[in_row]; } template template arma_inline arma_warn_unused eT* Col::fixed::memptr() { return (use_extra) ? mem_local_extra : Mat::mem_local; } template template arma_inline arma_warn_unused const eT* Col::fixed::memptr() const { return (use_extra) ? mem_local_extra : Mat::mem_local; } template template arma_hot inline const Col& Col::fixed::fill(const eT val) { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, val ); return *this; } template template arma_hot inline const Col& Col::fixed::zeros() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(0) ); return *this; } template template arma_hot inline const Col& Col::fixed::ones() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(1) ); return *this; } template inline Col::Col(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem) : Mat(arma_fixed_indicator(), in_n_elem, 1, 1, in_mem) { arma_extra_debug_sigprint_this(this); } #ifdef ARMA_EXTRA_COL_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_COL_MEAT) #endif //! @} armadillo-6.500.5/include/armadillo_bits/op_fft_meat.hpp0000666000000000000000000002010312620272703021736 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_fft //! @{ // // op_fft_real template inline void op_fft_real::apply( Mat< std::complex >& out, const mtOp,T1,op_fft_real>& in ) { arma_extra_debug_sigprint(); typedef typename T1::pod_type in_eT; typedef typename std::complex out_eT; const Proxy P(in.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_elem = P.get_n_elem(); const bool is_vec = ( (n_rows == 1) || (n_cols == 1) ); const uword N_orig = (is_vec) ? n_elem : n_rows; const uword N_user = (in.aux_uword_b == 0) ? in.aux_uword_a : N_orig; fft_engine worker(N_user); // no need to worry about aliasing, as we're going from a real object to complex complex, which by definition cannot alias if(is_vec) { (n_cols == 1) ? out.set_size(N_user, 1) : out.set_size(1, N_user); if( (out.n_elem == 0) || (N_orig == 0) ) { out.zeros(); return; } if( (N_user == 1) && (N_orig >= 1) ) { out[0] = out_eT( P[0] ); return; } podarray data(N_user); out_eT* data_mem = data.memptr(); if(N_user > N_orig) { arrayops::fill_zeros( &data_mem[N_orig], (N_user - N_orig) ); } const uword N = (std::min)(N_user, N_orig); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type X = P.get_ea(); for(uword i=0; i < N; ++i) { data_mem[i] = out_eT( X[i], in_eT(0) ); } } else { if(n_cols == 1) { for(uword i=0; i < N; ++i) { data_mem[i] = out_eT( P.at(i,0), in_eT(0) ); } } else { for(uword i=0; i < N; ++i) { data_mem[i] = out_eT( P.at(0,i), in_eT(0) ); } } } worker.run( out.memptr(), data_mem ); } else { // process each column seperately out.set_size(N_user, n_cols); if( (out.n_elem == 0) || (N_orig == 0) ) { out.zeros(); return; } if( (N_user == 1) && (N_orig >= 1) ) { for(uword col=0; col < n_cols; ++col) { out.at(0,col) = out_eT( P.at(0,col) ); } return; } podarray data(N_user); out_eT* data_mem = data.memptr(); if(N_user > N_orig) { arrayops::fill_zeros( &data_mem[N_orig], (N_user - N_orig) ); } const uword N = (std::min)(N_user, N_orig); for(uword col=0; col < n_cols; ++col) { for(uword i=0; i < N; ++i) { data_mem[i] = P.at(i, col); } worker.run( out.colptr(col), data_mem ); } } } // // op_fft_cx template inline void op_fft_cx::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(in.m); if(P.is_alias(out) == false) { op_fft_cx::apply_noalias(out, P, in.aux_uword_a, in.aux_uword_b); } else { Mat tmp; op_fft_cx::apply_noalias(tmp, P, in.aux_uword_a, in.aux_uword_b); out.steal_mem(tmp); } } template inline void op_fft_cx::apply_noalias(Mat& out, const Proxy& P, const uword a, const uword b) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_elem = P.get_n_elem(); const bool is_vec = ( (n_rows == 1) || (n_cols == 1) ); const uword N_orig = (is_vec) ? n_elem : n_rows; const uword N_user = (b == 0) ? a : N_orig; fft_engine worker(N_user); if(is_vec) { (n_cols == 1) ? out.set_size(N_user, 1) : out.set_size(1, N_user); if( (out.n_elem == 0) || (N_orig == 0) ) { out.zeros(); return; } if( (N_user == 1) && (N_orig >= 1) ) { out[0] = P[0]; return; } if( (N_user > N_orig) || (is_Mat::stored_type>::value == false) ) { podarray data(N_user); eT* data_mem = data.memptr(); if(N_user > N_orig) { arrayops::fill_zeros( &data_mem[N_orig], (N_user - N_orig) ); } op_fft_cx::copy_vec( data_mem, P, (std::min)(N_user, N_orig) ); worker.run( out.memptr(), data_mem ); } else { const unwrap< typename Proxy::stored_type > tmp(P.Q); worker.run( out.memptr(), tmp.M.memptr() ); } } else { // process each column seperately out.set_size(N_user, n_cols); if( (out.n_elem == 0) || (N_orig == 0) ) { out.zeros(); return; } if( (N_user == 1) && (N_orig >= 1) ) { for(uword col=0; col < n_cols; ++col) { out.at(0,col) = P.at(0,col); } return; } if( (N_user > N_orig) || (is_Mat::stored_type>::value == false) ) { podarray data(N_user); eT* data_mem = data.memptr(); if(N_user > N_orig) { arrayops::fill_zeros( &data_mem[N_orig], (N_user - N_orig) ); } const uword N = (std::min)(N_user, N_orig); for(uword col=0; col < n_cols; ++col) { for(uword i=0; i < N; ++i) { data_mem[i] = P.at(i, col); } worker.run( out.colptr(col), data_mem ); } } else { const unwrap< typename Proxy::stored_type > tmp(P.Q); for(uword col=0; col < n_cols; ++col) { worker.run( out.colptr(col), tmp.M.colptr(col) ); } } } // correct the scaling for the inverse transform if(inverse == true) { typedef typename get_pod_type::result T; const T k = T(1) / T(N_user); eT* out_mem = out.memptr(); const uword out_n_elem = out.n_elem; for(uword i=0; i < out_n_elem; ++i) { out_mem[i] *= k; } } } template arma_hot inline void op_fft_cx::copy_vec(typename Proxy::elem_type* dest, const Proxy& P, const uword N) { arma_extra_debug_sigprint(); if(is_Mat< typename Proxy::stored_type >::value == true) { op_fft_cx::copy_vec_unwrap(dest, P, N); } else { op_fft_cx::copy_vec_proxy(dest, P, N); } } template arma_hot inline void op_fft_cx::copy_vec_unwrap(typename Proxy::elem_type* dest, const Proxy& P, const uword N) { arma_extra_debug_sigprint(); const unwrap< typename Proxy::stored_type > tmp(P.Q); arrayops::copy(dest, tmp.M.memptr(), N); } template arma_hot inline void op_fft_cx::copy_vec_proxy(typename Proxy::elem_type* dest, const Proxy& P, const uword N) { arma_extra_debug_sigprint(); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type X = P.get_ea(); for(uword i=0; i < N; ++i) { dest[i] = X[i]; } } else { if(P.get_n_cols() == 1) { for(uword i=0; i < N; ++i) { dest[i] = P.at(i,0); } } else { for(uword i=0; i < N; ++i) { dest[i] = P.at(0,i); } } } } // // op_ifft_cx template inline void op_ifft_cx::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(in.m); if(P.is_alias(out) == false) { op_fft_cx::apply_noalias(out, P, in.aux_uword_a, in.aux_uword_b); } else { Mat tmp; op_fft_cx::apply_noalias(tmp, P, in.aux_uword_a, in.aux_uword_b); out.steal_mem(tmp); } } //! @} armadillo-6.500.5/include/armadillo_bits/SizeMat_meat.hpp0000666000000000000000000000445712620272703022053 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup SizeMat //! @{ inline SizeMat::SizeMat(const uword in_n_rows, const uword in_n_cols) : n_rows(in_n_rows) , n_cols(in_n_cols) { arma_extra_debug_sigprint(); } inline uword SizeMat::operator[](const uword dim) const { if(dim == 0) { return n_rows; } if(dim == 1) { return n_cols; } return uword(1); } inline uword SizeMat::operator()(const uword dim) const { if(dim == 0) { return n_rows; } if(dim == 1) { return n_cols; } arma_debug_check(true, "size(): index out of bounds"); return uword(1); } inline bool SizeMat::operator==(const SizeMat& s) const { if(n_rows != s.n_rows) { return false; } if(n_cols != s.n_cols) { return false; } return true; } inline bool SizeMat::operator!=(const SizeMat& s) const { if(n_rows != s.n_rows) { return true; } if(n_cols != s.n_cols) { return true; } return false; } inline SizeMat SizeMat::operator+(const SizeMat& s) const { return SizeMat( (n_rows + s.n_rows), (n_cols + s.n_cols) ); } inline SizeMat SizeMat::operator-(const SizeMat& s) const { const uword out_n_rows = (n_rows > s.n_rows) ? (n_rows - s.n_rows) : uword(0); const uword out_n_cols = (n_cols > s.n_cols) ? (n_cols - s.n_cols) : uword(0); return SizeMat(out_n_rows, out_n_cols); } inline SizeMat SizeMat::operator+(const uword val) const { return SizeMat( (n_rows + val), (n_cols + val) ); } inline SizeMat SizeMat::operator-(const uword val) const { const uword out_n_rows = (n_rows > val) ? (n_rows - val) : uword(0); const uword out_n_cols = (n_cols > val) ? (n_cols - val) : uword(0); return SizeMat(out_n_rows, out_n_cols); } inline SizeMat SizeMat::operator*(const uword val) const { return SizeMat( (n_rows * val), (n_cols * val) ); } inline SizeMat SizeMat::operator/(const uword val) const { return SizeMat( (n_rows / val), (n_cols / val) ); } //! @} armadillo-6.500.5/include/armadillo_bits/op_nonzeros_meat.hpp0000666000000000000000000000505112620272703023041 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_nonzeros //! @{ template inline void op_nonzeros::apply_noalias(Mat& out, const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword N_max = P.get_n_elem(); Mat tmp(N_max, 1); eT* tmp_mem = tmp.memptr(); uword N_nz = 0; if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i inline void op_nonzeros::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.m); if(P.get_n_elem() == 0) { out.set_size(0,1); return; } if(P.is_alias(out)) { Mat out2; op_nonzeros::apply_noalias(out2, P); out.steal_mem(out2); } else { op_nonzeros::apply_noalias(out, P); } } template inline void op_nonzeros::apply_noalias(Mat& out, const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy P(X.get_ref()); const uword N = P.get_n_nonzero(); out.set_size(N,1); if(N > 0) { if(is_SpMat::stored_type>::value) { const unwrap_spmat::stored_type> U(P.Q); arrayops::copy(out.memptr(), U.M.values, N); } else { eT* out_mem = out.memptr(); typename SpProxy::const_iterator_type it = P.begin(); for(uword i=0; i inline obj_type randi(const uword n_rows, const uword n_cols, const distr_param& param = distr_param(), const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename obj_type::elem_type eT; if(is_Col::value == true) { arma_debug_check( (n_cols != 1), "randi(): incompatible size" ); } else if(is_Row::value == true) { arma_debug_check( (n_rows != 1), "randi(): incompatible size" ); } obj_type out(n_rows, n_cols); int a; int b; if(param.state == 0) { a = 0; b = arma_rng::randi::max_val(); } else if(param.state == 1) { a = param.a_int; b = param.b_int; } else { a = int(param.a_double); b = int(param.b_double); } arma_debug_check( (a > b), "randi(): incorrect distribution parameters: a must be less than b" ); arma_rng::randi::fill(out.memptr(), out.n_elem, a, b); return out; } template inline obj_type randi(const SizeMat& s, const distr_param& param = distr_param(), const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return randi(s.n_rows, s.n_cols, param); } template inline obj_type randi(const uword n_elem, const distr_param& param = distr_param(), const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value == true) { return randi(1, n_elem, param); } else { return randi(n_elem, 1, param); } } inline imat randi(const uword n_rows, const uword n_cols, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randi(n_rows, n_cols, param); } inline imat randi(const SizeMat& s, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randi(s.n_rows, s.n_cols, param); } inline ivec randi(const uword n_elem, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randi(n_elem, param); } template inline cube_type randi(const uword n_rows, const uword n_cols, const uword n_slices, const distr_param& param = distr_param(), const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename cube_type::elem_type eT; cube_type out(n_rows, n_cols, n_slices); int a; int b; if(param.state == 0) { a = 0; b = arma_rng::randi::max_val(); } else if(param.state == 1) { a = param.a_int; b = param.b_int; } else { a = int(param.a_double); b = int(param.b_double); } arma_debug_check( (a > b), "randi(): incorrect distribution parameters: a must be less than b" ); arma_rng::randi::fill(out.memptr(), out.n_elem, a, b); return out; } template inline cube_type randi(const SizeCube& s, const distr_param& param = distr_param(), const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return randi(s.n_rows, s.n_cols, s.n_slices, param); } inline icube randi(const uword n_rows, const uword n_cols, const uword n_slices, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randi(n_rows, n_cols, n_slices, param); } inline icube randi(const SizeCube& s, const distr_param& param = distr_param()) { arma_extra_debug_sigprint(); return randi(s.n_rows, s.n_cols, s.n_slices, param); } //! @} armadillo-6.500.5/include/armadillo_bits/def_arpack.hpp0000666000000000000000000001246012620272703021541 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Ryan Curtin #ifdef ARMA_USE_ARPACK // I'm not sure this is necessary. #if !defined(ARMA_BLAS_CAPITALS) #define arma_snaupd snaupd #define arma_dnaupd dnaupd #define arma_cnaupd cnaupd #define arma_znaupd znaupd #define arma_sneupd sneupd #define arma_dneupd dneupd #define arma_cneupd cneupd #define arma_zneupd zneupd #define arma_ssaupd ssaupd #define arma_dsaupd dsaupd #define arma_sseupd sseupd #define arma_dseupd dseupd #else #define arma_snaupd SNAUPD #define arma_dnaupd DNAUPD #define arma_cnaupd CNAUPD #define arma_znaupd ZNAUPD #define arma_sneupd SNEUPD #define arma_dneupd DNEUPD #define arma_cneupd CNEUPD #define arma_zneupd ZNEUPD #define arma_ssaupd SSAUPD #define arma_dsaupd DSAUPD #define arma_sseupd SSEUPD #define arma_dseupd DSEUPD #endif extern "C" { // eigendecomposition of non-symmetric positive semi-definite matrices void arma_fortran(arma_snaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_dnaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_cnaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, float* rwork, blas_int* info); void arma_fortran(arma_znaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, double* rwork, blas_int* info); // eigendecomposition of symmetric positive semi-definite matrices void arma_fortran(arma_ssaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_dsaupd)(blas_int* ido, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info); // recovery of eigenvectors after naupd(); uses blas_int for LOGICAL types void arma_fortran(arma_sneupd)(blas_int* rvec, char* howmny, blas_int* select, float* dr, float* di, float* z, blas_int* ldz, float* sigmar, float* sigmai, float* workev, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_dneupd)(blas_int* rvec, char* howmny, blas_int* select, double* dr, double* di, double* z, blas_int* ldz, double* sigmar, double* sigmai, double* workev, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_cneupd)(blas_int* rvec, char* howmny, blas_int* select, void* d, void* z, blas_int* ldz, void* sigma, void* workev, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, float* rwork, blas_int* info); void arma_fortran(arma_zneupd)(blas_int* rvec, char* howmny, blas_int* select, void* d, void* z, blas_int* ldz, void* sigma, void* workev, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, void* resid, blas_int* ncv, void* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, void* workd, void* workl, blas_int* lworkl, double* rwork, blas_int* info); // recovery of eigenvectors after saupd(); uses blas_int for LOGICAL types void arma_fortran(arma_sseupd)(blas_int* rvec, char* howmny, blas_int* select, float* d, float* z, blas_int* ldz, float* sigma, char* bmat, blas_int* n, char* which, blas_int* nev, float* tol, float* resid, blas_int* ncv, float* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, float* workd, float* workl, blas_int* lworkl, blas_int* info); void arma_fortran(arma_dseupd)(blas_int* rvec, char* howmny, blas_int* select, double* d, double* z, blas_int* ldz, double* sigma, char* bmat, blas_int* n, char* which, blas_int* nev, double* tol, double* resid, blas_int* ncv, double* v, blas_int* ldv, blas_int* iparam, blas_int* ipntr, double* workd, double* workl, blas_int* lworkl, blas_int* info); } #endif armadillo-6.500.5/include/armadillo_bits/fn_clamp.hpp0000666000000000000000000000167612620272703021250 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_clamp //! @{ template inline typename enable_if2 < is_arma_type::value && is_cx::no, const mtOp >::result clamp(const T1& X, const typename T1::elem_type min_val, const typename T1::elem_type max_val) { arma_extra_debug_sigprint(); arma_debug_check( (min_val > max_val), "clamp(): min_val has to be smaller than max_val" ); return mtOp(mtOp_dual_aux_indicator(), X, min_val, max_val); } //! @} armadillo-6.500.5/include/armadillo_bits/op_relational_bones.hpp0000666000000000000000000000620112620272703023474 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_relational //! @{ class op_rel_lt_pre { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_lt_post { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_gt_pre { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_gt_post { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_lteq_pre { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_lteq_post { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_gteq_pre { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_gteq_post { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_eq { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; class op_rel_noteq { public: template inline static void apply(Mat& out, const mtOp& X); template inline static void apply(Cube& out, const mtOpCube& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_cumprod_meat.hpp0000666000000000000000000000627612620272703022647 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_cumprod //! @{ template inline void op_cumprod::apply_noalias(Mat& out, const Mat& X, const uword dim) { arma_extra_debug_sigprint(); uword n_rows = X.n_rows; uword n_cols = X.n_cols; out.set_size(n_rows,n_cols); if(dim == 0) { if(n_cols == 1) { const eT* X_mem = X.memptr(); eT* out_mem = out.memptr(); eT acc = eT(1); for(uword row=0; row < n_rows; ++row) { acc *= X_mem[row]; out_mem[row] = acc; } } else { for(uword col=0; col < n_cols; ++col) { const eT* X_colmem = X.colptr(col); eT* out_colmem = out.colptr(col); eT acc = eT(1); for(uword row=0; row < n_rows; ++row) { acc *= X_colmem[row]; out_colmem[row] = acc; } } } } else if(dim == 1) { if(n_rows == 1) { const eT* X_mem = X.memptr(); eT* out_mem = out.memptr(); eT acc = eT(1); for(uword col=0; col < n_cols; ++col) { acc *= X_mem[col]; out_mem[col] = acc; } } else { if(n_cols > 0) { arrayops::copy( out.colptr(0), X.colptr(0), n_rows ); for(uword col=1; col < n_cols; ++col) { const eT* out_colmem_prev = out.colptr(col-1); eT* out_colmem = out.colptr(col ); const eT* X_colmem = X.colptr(col ); for(uword row=0; row < n_rows; ++row) { out_colmem[row] = out_colmem_prev[row] * X_colmem[row]; } } } } } } template inline void op_cumprod::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "cumprod(): parameter 'dim' must be 0 or 1" ); const quasi_unwrap U(in.m); if(U.is_alias(out)) { Mat tmp; op_cumprod::apply_noalias(tmp, U.M, dim); out.steal_mem(tmp); } else { op_cumprod::apply_noalias(out, U.M, dim); } } template inline void op_cumprod_default::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const quasi_unwrap U(in.m); const uword dim = (T1::is_row) ? 1 : 0; if(U.is_alias(out)) { Mat tmp; op_cumprod::apply_noalias(tmp, U.M, dim); out.steal_mem(tmp); } else { op_cumprod::apply_noalias(out, U.M, dim); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_dot_bones.hpp0000666000000000000000000000604212650172354022137 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_dot //! @{ //! \brief //! dot product operation class op_dot { public: template arma_hot arma_inline static typename arma_not_cx::result direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B); template arma_hot inline static typename arma_cx_only::result direct_dot_arma(const uword n_elem, const eT* const A, const eT* const B); template arma_hot inline static typename arma_real_only::result direct_dot(const uword n_elem, const eT* const A, const eT* const B); template arma_hot inline static typename arma_cx_only::result direct_dot(const uword n_elem, const eT* const A, const eT* const B); template arma_hot inline static typename arma_integral_only::result direct_dot(const uword n_elem, const eT* const A, const eT* const B); template arma_hot inline static eT direct_dot(const uword n_elem, const eT* const A, const eT* const B, const eT* C); template arma_hot inline static typename T1::elem_type apply(const T1& X, const T2& Y); template arma_hot inline static typename arma_not_cx::result apply_proxy(const Proxy& PA, const Proxy& PB); template arma_hot inline static typename arma_cx_only::result apply_proxy(const Proxy& PA, const Proxy& PB); }; //! \brief //! normalised dot product operation class op_norm_dot { public: template arma_hot inline static typename T1::elem_type apply(const T1& X, const T2& Y); }; //! \brief //! complex conjugate dot product operation class op_cdot { public: template arma_hot inline static eT direct_cdot_arma(const uword n_elem, const eT* const A, const eT* const B); template arma_hot inline static eT direct_cdot(const uword n_elem, const eT* const A, const eT* const B); template arma_hot inline static typename T1::elem_type apply (const T1& X, const T2& Y); template arma_hot inline static typename T1::elem_type apply_unwrap(const T1& X, const T2& Y); template arma_hot inline static typename T1::elem_type apply_proxy (const T1& X, const T2& Y); }; class op_dot_mixed { public: template arma_hot inline static typename promote_type::result apply(const T1& A, const T2& B); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_prod_meat.hpp0000666000000000000000000000760712620272703022141 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_prod //! @{ template inline void op_prod::apply_noalias(Mat& out, const Mat& X, const uword dim) { arma_extra_debug_sigprint(); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) // traverse across rows (i.e. find the product in each column) { out.set_size(1, X_n_cols); eT* out_mem = out.memptr(); for(uword col=0; col < X_n_cols; ++col) { out_mem[col] = arrayops::product(X.colptr(col), X_n_rows); } } else // traverse across columns (i.e. find the product in each row) { out.ones(X_n_rows, 1); eT* out_mem = out.memptr(); for(uword col=0; col < X_n_cols; ++col) { const eT* X_col_mem = X.colptr(col); for(uword row=0; row < X_n_rows; ++row) { out_mem[row] *= X_col_mem[row]; } } } } template inline void op_prod::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "prod(): parameter 'dim' must be 0 or 1" ); const quasi_unwrap U(in.m); if(U.is_alias(out)) { Mat tmp; op_prod::apply_noalias(tmp, U.M, dim); out.steal_mem(tmp); } else { op_prod::apply_noalias(out, U.M, dim); } } template inline eT op_prod::prod(const subview& X) { arma_extra_debug_sigprint(); eT val = eT(1); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(X_n_rows == 1) { const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X_n_cols; uword i,j; for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) { val *= A.at(start_row, i); val *= A.at(start_row, j); } if(i < end_col_p1) { val *= A.at(start_row, i); } } else { for(uword col=0; col < X_n_cols; ++col) { val *= arrayops::product( X.colptr(col), X_n_rows ); } } return val; } template inline typename T1::elem_type op_prod::prod(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); eT val = eT(1); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; const ea_type A = P.get_ea(); const uword n_elem = P.get_n_elem(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { val *= A[i]; val *= A[j]; } if(i < n_elem) { val *= A[i]; } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { val *= P.at(0,i); val *= P.at(0,j); } if(i < n_cols) { val *= P.at(0,i); } } else { for(uword col=0; col < n_cols; ++col) { uword i,j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { val *= P.at(i,col); val *= P.at(j,col); } if(i < n_rows) { val *= P.at(i,col); } } } } return val; } //! @} armadillo-6.500.5/include/armadillo_bits/op_cor_bones.hpp0000666000000000000000000000161112620272703022125 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_cor //! @{ class op_cor { public: template inline static void direct_cor(Mat& out, const Mat& X, const uword norm_type); template inline static void direct_cor(Mat< std::complex >& out, const Mat< std::complex >& X, const uword norm_type); template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_n_unique.hpp0000666000000000000000000000561712620272703021776 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup fn_n_unique //! @{ //! \brief //! Get the number of unique nonzero elements in two sparse matrices. //! This is very useful for determining the amount of memory necessary before //! a sparse matrix operation on two matrices. template inline uword n_unique ( const SpBase& x, const SpBase& y, const op_n_unique_type junk ) { arma_extra_debug_sigprint(); const SpProxy pa(x.get_ref()); const SpProxy pb(y.get_ref()); return n_unique(pa,pb,junk); } template arma_hot inline uword n_unique ( const SpProxy& pa, const SpProxy& pb, const op_n_unique_type junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type x_it_end = pa.end(); typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type y_it_end = pb.end(); uword total_n_nonzero = 0; while( (x_it != x_it_end) || (y_it != y_it_end) ) { if(x_it == y_it) { if(op_n_unique_type::eval((*x_it), (*y_it)) != typename T1::elem_type(0)) { ++total_n_nonzero; } ++x_it; ++y_it; } else { if((x_it.col() < y_it.col()) || ((x_it.col() == y_it.col()) && (x_it.row() < y_it.row()))) // if y is closer to the end { if(op_n_unique_type::eval((*x_it), typename T1::elem_type(0)) != typename T1::elem_type(0)) { ++total_n_nonzero; } ++x_it; } else // x is closer to the end { if(op_n_unique_type::eval(typename T1::elem_type(0), (*y_it)) != typename T1::elem_type(0)) { ++total_n_nonzero; } ++y_it; } } } return total_n_nonzero; } // Simple operators. struct op_n_unique_add { template inline static eT eval(const eT& l, const eT& r) { return (l + r); } }; struct op_n_unique_sub { template inline static eT eval(const eT& l, const eT& r) { return (l - r); } }; struct op_n_unique_mul { template inline static eT eval(const eT& l, const eT& r) { return (l * r); } }; struct op_n_unique_count { template inline static eT eval(const eT&, const eT&) { return eT(1); } }; //! @} armadillo-6.500.5/include/armadillo_bits/mul_syrk.hpp0000666000000000000000000003000512650111756021325 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup syrk //! @{ class syrk_helper { public: template inline static void inplace_copy_upper_tri_to_lower_tri(Mat& C) { // under the assumption that C is a square matrix const uword N = C.n_rows; for(uword k=0; k < N; ++k) { eT* colmem = C.colptr(k); uword i, j; for(i=(k+1), j=(k+2); j < N; i+=2, j+=2) { const eT tmp_i = C.at(k,i); const eT tmp_j = C.at(k,j); colmem[i] = tmp_i; colmem[j] = tmp_j; } if(i < N) { colmem[i] = C.at(k,i); } } } }; //! partial emulation of BLAS function syrk(), specialised for A being a vector template class syrk_vec { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); const uword A_n1 = (do_trans_A == false) ? A.n_rows : A.n_cols; const uword A_n2 = (do_trans_A == false) ? A.n_cols : A.n_rows; const eT* A_mem = A.memptr(); if(A_n1 == 1) { const eT acc1 = op_dot::direct_dot(A_n2, A_mem, A_mem); if( (use_alpha == false) && (use_beta == false) ) { C[0] = acc1; } else if( (use_alpha == true ) && (use_beta == false) ) { C[0] = alpha*acc1; } else if( (use_alpha == false) && (use_beta == true ) ) { C[0] = acc1 + beta*C[0]; } else if( (use_alpha == true ) && (use_beta == true ) ) { C[0] = alpha*acc1 + beta*C[0]; } } else for(uword k=0; k < A_n1; ++k) { const eT A_k = A_mem[k]; uword i,j; for(i=(k), j=(k+1); j < A_n1; i+=2, j+=2) { const eT acc1 = A_k * A_mem[i]; const eT acc2 = A_k * A_mem[j]; if( (use_alpha == false) && (use_beta == false) ) { C.at(k, i) = acc1; C.at(k, j) = acc2; C.at(i, k) = acc1; C.at(j, k) = acc2; } else if( (use_alpha == true ) && (use_beta == false) ) { const eT val1 = alpha*acc1; const eT val2 = alpha*acc2; C.at(k, i) = val1; C.at(k, j) = val2; C.at(i, k) = val1; C.at(j, k) = val2; } else if( (use_alpha == false) && (use_beta == true) ) { C.at(k, i) = acc1 + beta*C.at(k, i); C.at(k, j) = acc2 + beta*C.at(k, j); if(i != k) { C.at(i, k) = acc1 + beta*C.at(i, k); } C.at(j, k) = acc2 + beta*C.at(j, k); } else if( (use_alpha == true ) && (use_beta == true) ) { const eT val1 = alpha*acc1; const eT val2 = alpha*acc2; C.at(k, i) = val1 + beta*C.at(k, i); C.at(k, j) = val2 + beta*C.at(k, j); if(i != k) { C.at(i, k) = val1 + beta*C.at(i, k); } C.at(j, k) = val2 + beta*C.at(j, k); } } if(i < A_n1) { const eT acc1 = A_k * A_mem[i]; if( (use_alpha == false) && (use_beta == false) ) { C.at(k, i) = acc1; C.at(i, k) = acc1; } else if( (use_alpha == true) && (use_beta == false) ) { const eT val1 = alpha*acc1; C.at(k, i) = val1; C.at(i, k) = val1; } else if( (use_alpha == false) && (use_beta == true) ) { C.at(k, i) = acc1 + beta*C.at(k, i); if(i != k) { C.at(i, k) = acc1 + beta*C.at(i, k); } } else if( (use_alpha == true) && (use_beta == true) ) { const eT val1 = alpha*acc1; C.at(k, i) = val1 + beta*C.at(k, i); if(i != k) { C.at(i, k) = val1 + beta*C.at(i, k); } } } } } }; //! partial emulation of BLAS function syrk() template class syrk_emul { public: template arma_hot inline static void apply ( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); // do_trans_A == false -> C = alpha * A * A^T + beta*C // do_trans_A == true -> C = alpha * A^T * A + beta*C if(do_trans_A == false) { Mat AA; op_strans::apply_mat_noalias(AA, A); syrk_emul::apply(C, AA, alpha, beta); } else if(do_trans_A == true) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const eT* A_coldata = A.colptr(col_A); for(uword k=col_A; k < A_n_cols; ++k) { const eT acc = op_dot::direct_dot_arma(A_n_rows, A_coldata, A.colptr(k)); if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A, k) = acc; C.at(k, col_A) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { const eT val = alpha*acc; C.at(col_A, k) = val; C.at(k, col_A) = val; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A, k) = acc + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = acc + beta*C.at(k, col_A); } } else if( (use_alpha == true ) && (use_beta == true ) ) { const eT val = alpha*acc; C.at(col_A, k) = val + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = val + beta*C.at(k, col_A); } } } } } } }; template class syrk { public: template inline static void apply_blas_type( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0) ) { arma_extra_debug_sigprint(); if(A.is_vec()) { // work around poor handling of vectors by syrk() in ATLAS 3.8.4 and standard BLAS syrk_vec::apply(C,A,alpha,beta); return; } const uword threshold = (is_cx::yes ? 16u : 48u); if( A.n_elem <= threshold ) { syrk_emul::apply(C,A,alpha,beta); } else { #if defined(ARMA_USE_ATLAS) { if(use_beta == true) { // use a temporary matrix, as we can't assume that matrix C is already symmetric Mat D(C.n_rows, C.n_cols); syrk::apply_blas_type(D,A,alpha); // NOTE: assuming beta=1; this is okay for now, as currently glue_times only uses beta=1 arrayops::inplace_plus(C.memptr(), D.memptr(), C.n_elem); return; } atlas::cblas_syrk ( atlas::CblasColMajor, atlas::CblasUpper, (do_trans_A) ? atlas::CblasTrans : atlas::CblasNoTrans, C.n_cols, (do_trans_A) ? A.n_rows : A.n_cols, (use_alpha) ? alpha : eT(1), A.mem, (do_trans_A) ? A.n_rows : C.n_cols, (use_beta) ? beta : eT(0), C.memptr(), C.n_cols ); syrk_helper::inplace_copy_upper_tri_to_lower_tri(C); } #elif defined(ARMA_USE_BLAS) { if(use_beta == true) { // use a temporary matrix, as we can't assume that matrix C is already symmetric Mat D(C.n_rows, C.n_cols); syrk::apply_blas_type(D,A,alpha); // NOTE: assuming beta=1; this is okay for now, as currently glue_times only uses beta=1 arrayops::inplace_plus(C.memptr(), D.memptr(), C.n_elem); return; } arma_extra_debug_print("blas::syrk()"); const char uplo = 'U'; const char trans_A = (do_trans_A) ? 'T' : 'N'; const blas_int n = blas_int(C.n_cols); const blas_int k = (do_trans_A) ? blas_int(A.n_rows) : blas_int(A.n_cols); const eT local_alpha = (use_alpha) ? alpha : eT(1); const eT local_beta = (use_beta) ? beta : eT(0); const blas_int lda = (do_trans_A) ? k : n; arma_extra_debug_print( arma_str::format("blas::syrk(): trans_A = %c") % trans_A ); blas::syrk ( &uplo, &trans_A, &n, &k, &local_alpha, A.mem, &lda, &local_beta, C.memptr(), &n // &ldc ); syrk_helper::inplace_copy_upper_tri_to_lower_tri(C); } #else { syrk_emul::apply(C,A,alpha,beta); } #endif } } template inline static void apply( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0) ) { if(is_cx::no) { if(A.is_vec()) { syrk_vec::apply(C,A,alpha,beta); } else { syrk_emul::apply(C,A,alpha,beta); } } else { // handling of complex matrix by syrk_emul() is not yet implemented return; } } template arma_inline static void apply ( Mat& C, const TA& A, const float alpha = float(1), const float beta = float(0) ) { syrk::apply_blas_type(C,A,alpha,beta); } template arma_inline static void apply ( Mat& C, const TA& A, const double alpha = double(1), const double beta = double(0) ) { syrk::apply_blas_type(C,A,alpha,beta); } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { arma_ignore(C); arma_ignore(A); arma_ignore(alpha); arma_ignore(beta); // handling of complex matrix by syrk() is not yet implemented return; } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const std::complex alpha = std::complex(1), const std::complex beta = std::complex(0) ) { arma_ignore(C); arma_ignore(A); arma_ignore(alpha); arma_ignore(beta); // handling of complex matrix by syrk() is not yet implemented return; } }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_eye.hpp0000666000000000000000000000444712620272703020735 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_eye //! @{ arma_inline const Gen eye(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } arma_inline const Gen eye(const SizeMat& s) { arma_extra_debug_sigprint(); return Gen(s.n_rows, s.n_cols); } template arma_inline const Gen eye(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value) { arma_debug_check( (n_cols != 1), "eye(): incompatible size" ); } else if(is_Row::value) { arma_debug_check( (n_rows != 1), "eye(): incompatible size" ); } return Gen(n_rows, n_cols); } template arma_inline const Gen eye(const SizeMat& s, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return eye(s.n_rows, s.n_cols); } template inline obj_type eye(const uword n_rows, const uword n_cols, const typename arma_SpMat_SpCol_SpRow_only::result* junk = NULL) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_SpCol::value == true) { arma_debug_check( (n_cols != 1), "eye(): incompatible size" ); } else if(is_SpRow::value == true) { arma_debug_check( (n_rows != 1), "eye(): incompatible size" ); } obj_type out; out.eye(n_rows, n_cols); return out; } template inline obj_type eye(const SizeMat& s, const typename arma_SpMat_SpCol_SpRow_only::result* junk = NULL) { arma_extra_debug_sigprint(); arma_ignore(junk); return eye(s.n_rows, s.n_cols); } //! @} armadillo-6.500.5/include/armadillo_bits/op_find_bones.hpp0000666000000000000000000000505312620272703022266 0ustar rootroot// Copyright (C) 2010-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_find //! @{ class op_find { public: template inline static uword helper ( Mat& indices, const Base& X ); template inline static uword helper ( Mat& indices, const mtOp& X, const typename arma_op_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0 ); template inline static uword helper ( Mat& indices, const mtOp& X, const typename arma_op_rel_only::result junk1 = 0, const typename arma_cx_only::result junk2 = 0 ); template inline static uword helper ( Mat& indices, const mtGlue& X, const typename arma_glue_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0, const typename arma_not_cx::result junk3 = 0 ); template inline static uword helper ( Mat& indices, const mtGlue& X, const typename arma_glue_rel_only::result junk1 = 0, const typename arma_cx_only::result junk2 = 0, const typename arma_cx_only::result junk3 = 0 ); template inline static void apply(Mat& out, const mtOp& X); }; class op_find_simple { public: template inline static void apply(Mat& out, const mtOp& X); }; class op_find_finite { public: template inline static void apply(Mat& out, const mtOp& X); }; class op_find_nonfinite { public: template inline static void apply(Mat& out, const mtOp& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_mean_bones.hpp0000666000000000000000000000416512620272703022271 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_mean //! @{ //! Class for finding mean values of a matrix class op_mean { public: template inline static void apply(Mat& out, const Op& in); template inline static void apply_noalias(Mat& out, const Proxy& P, const uword dim); template inline static void apply_noalias_unwrap(Mat& out, const Proxy& P, const uword dim); template inline static void apply_noalias_proxy(Mat& out, const Proxy& P, const uword dim); // template inline static eT direct_mean(const eT* const X, const uword N); template inline static eT direct_mean_robust(const eT* const X, const uword N); // template inline static eT direct_mean(const Mat& X, const uword row); template inline static eT direct_mean_robust(const Mat& X, const uword row); // template inline static eT mean_all(const subview& X); template inline static eT mean_all_robust(const subview& X); // template inline static eT mean_all(const diagview& X); template inline static eT mean_all_robust(const diagview& X); // template inline static typename T1::elem_type mean_all(const Base& X); // template arma_inline static eT robust_mean(const eT A, const eT B); template arma_inline static std::complex robust_mean(const std::complex& A, const std::complex& B); }; //! @} armadillo-6.500.5/include/armadillo_bits/typedef_elem.hpp0000666000000000000000000000562012620272703022124 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup typedef_elem //! @{ #if (defined(ARMA_U8_TYPE) && defined(ARMA_S8_TYPE)) typedef ARMA_U8_TYPE u8; typedef ARMA_S8_TYPE s8; #else #if UCHAR_MAX >= 0xff typedef unsigned char u8; typedef char s8; #elif defined(UINT8_MAX) typedef uint8_t u8; typedef int8_t s8; #else #error "don't know how to typedef 'u8' on this system" #endif #endif // NOTE: // "char" is not guaranteed to be the same as "signed char" // https://en.wikipedia.org/wiki/C_data_types #if USHRT_MAX >= 0xffff typedef unsigned short u16; typedef short s16; #elif defined(UINT16_MAX) typedef uint16_t u16; typedef int16_t s16; #else #error "don't know how to typedef 'u16' on this system" #endif #if UINT_MAX >= 0xffffffff typedef unsigned int u32; typedef int s32; #elif defined(UINT32_MAX) typedef uint32_t u32; typedef int32_t s32; #else #error "don't know how to typedef 'u32' on this system" #endif #if defined(ARMA_USE_U64S64) #if ULLONG_MAX >= 0xffffffffffffffff typedef unsigned long long u64; typedef long long s64; #elif ULONG_MAX >= 0xffffffffffffffff typedef unsigned long u64; typedef long s64; #define ARMA_U64_IS_LONG #elif defined(UINT64_MAX) typedef uint64_t u64; typedef int64_t s64; #else #error "don't know how to typedef 'u64' on this system; please disable ARMA_64BIT_WORD" #endif #endif #if !defined(ARMA_USE_U64S64) || (defined(ARMA_USE_U64S64) && !defined(ARMA_U64_IS_LONG)) #define ARMA_ALLOW_LONG #endif typedef unsigned long ulng_t; typedef long slng_t; #if defined(ARMA_64BIT_WORD) typedef u64 uword; typedef s64 sword; typedef u32 uhword; typedef s32 shword; #define ARMA_MAX_UWORD 0xffffffffffffffff #define ARMA_MAX_UHWORD 0xffffffff #else typedef u32 uword; typedef s32 sword; typedef u16 uhword; typedef s16 shword; #define ARMA_MAX_UWORD 0xffffffff #define ARMA_MAX_UHWORD 0xffff #endif #if defined(ARMA_BLAS_LONG_LONG) typedef long long blas_int; #define ARMA_MAX_BLAS_INT 0x7fffffffffffffffULL #elif defined(ARMA_BLAS_LONG) typedef long blas_int; #define ARMA_MAX_BLAS_INT 0x7fffffffffffffffUL #else typedef int blas_int; #define ARMA_MAX_BLAS_INT 0x7fffffffU #endif typedef std::complex cx_float; typedef std::complex cx_double; typedef void* void_ptr; //! @} armadillo-6.500.5/include/armadillo_bits/arma_ostream_bones.hpp0000666000000000000000000000501712620272703023322 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arma_ostream //! @{ class arma_ostream_state { private: const ios::fmtflags orig_flags; const std::streamsize orig_precision; const std::streamsize orig_width; const char orig_fill; public: inline arma_ostream_state(const std::ostream& o); inline void restore(std::ostream& o) const; }; class arma_ostream { public: template inline static std::streamsize modify_stream(std::ostream& o, const eT* data, const uword n_elem); template inline static std::streamsize modify_stream(std::ostream& o, const std::complex* data, const uword n_elem); template inline static std::streamsize modify_stream(std::ostream& o, typename SpMat::const_iterator begin, const uword n_elem, const typename arma_not_cx::result* junk = 0); template inline static std::streamsize modify_stream(std::ostream& o, typename SpMat::const_iterator begin, const uword n_elem, const typename arma_cx_only::result* junk = 0); template inline static void print_elem_zero(std::ostream& o, const bool modify); template arma_inline static void print_elem(std::ostream& o, const eT& x, const bool modify); template inline static void print_elem(std::ostream& o, const std::complex& x, const bool modify); template inline static void print(std::ostream& o, const Mat& m, const bool modify); template inline static void print(std::ostream& o, const Cube& m, const bool modify); template inline static void print(std::ostream& o, const field& m); template inline static void print(std::ostream& o, const subview_field& m); template inline static void print_dense(std::ostream& o, const SpMat& m, const bool modify); template inline static void print(std::ostream& o, const SpMat& m, const bool modify); inline static void print(std::ostream& o, const SizeMat& S); inline static void print(std::ostream& o, const SizeCube& S); }; //! @} armadillo-6.500.5/include/armadillo_bits/Base_bones.hpp0000666000000000000000000001001512626006611021513 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Base //! @{ template struct Base_inv_yes { arma_inline const Op i() const; //!< matrix inverse arma_inline const Op i(const bool ) const; //!< kept only for compatibility with old user code arma_inline const Op i(const char*) const; //!< kept only for compatibility with old user code }; template struct Base_inv_no { }; template struct Base_inv {}; template struct Base_inv { typedef Base_inv_yes result; }; template struct Base_inv { typedef Base_inv_no result; }; template struct Base_eval_Mat { arma_inline const derived& eval() const; }; template struct Base_eval_expr { arma_inline Mat eval() const; //!< force the immediate evaluation of a delayed expression }; template struct Base_eval {}; template struct Base_eval { typedef Base_eval_Mat result; }; template struct Base_eval { typedef Base_eval_expr result; }; template struct Base_trans_cx { arma_inline const Op t() const; arma_inline const Op ht() const; arma_inline const Op st() const; // simple transpose: no complex conjugates }; template struct Base_trans_default { arma_inline const Op t() const; arma_inline const Op ht() const; arma_inline const Op st() const; // return op_htrans instead of op_strans, as it's handled better by matrix multiplication code }; template struct Base_trans {}; template struct Base_trans { typedef Base_trans_cx result; }; template struct Base_trans { typedef Base_trans_default result; }; //! Class for static polymorphism, modelled after the "Curiously Recurring Template Pattern" (CRTP). //! Used for type-safe downcasting in functions that restrict their input(s) to be classes that are //! derived from Base (e.g. Mat, Op, Glue, diagview, subview). //! A Base object can be converted to a Mat object by the unwrap class. template struct Base : public Base_inv::value>::result , public Base_eval::value>::result , public Base_trans::value>::result { arma_inline const derived& get_ref() const; inline void print( const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const; inline void raw_print( const std::string extra_text = "") const; inline void raw_print(std::ostream& user_stream, const std::string extra_text = "") const; inline arma_warn_unused elem_type min() const; inline arma_warn_unused elem_type max() const; inline elem_type min(uword& index_of_min_val) const; inline elem_type max(uword& index_of_max_val) const; inline elem_type min(uword& row_of_min_val, uword& col_of_min_val) const; inline elem_type max(uword& row_of_max_val, uword& col_of_max_val) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/compiler_setup_post.hpp0000666000000000000000000000071112620272703023555 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au #if defined(_MSC_VER) #pragma warning(pop) #endif armadillo-6.500.5/include/armadillo_bits/operator_plus.hpp0000666000000000000000000001467012620272703022365 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup operator_plus //! @{ //! unary plus operation (does nothing, but is required for completeness) template arma_inline typename enable_if2< is_arma_type::value, const T1& >::result operator+ (const T1& X) { arma_extra_debug_sigprint(); return X; } //! Base + scalar template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator+ (const T1& X, const typename T1::elem_type k) { arma_extra_debug_sigprint(); return eOp(X, k); } //! scalar + Base template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result operator+ (const typename T1::elem_type k, const T1& X) { arma_extra_debug_sigprint(); return eOp(X, k); // NOTE: order is swapped } //! non-complex Base + complex scalar template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_plus> >::result operator+ ( const T1& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_plus>('j', X, k); } //! complex scalar + non-complex Base template arma_inline typename enable_if2 < (is_arma_type::value && is_cx::no), const mtOp, T1, op_cx_scalar_plus> >::result operator+ ( const std::complex& k, const T1& X ) { arma_extra_debug_sigprint(); return mtOp, T1, op_cx_scalar_plus>('j', X, k); // NOTE: order is swapped } //! addition of user-accessible Armadillo objects with same element type template arma_inline typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, const eGlue >::result operator+ ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return eGlue(X, Y); } //! addition of user-accessible Armadillo objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue::result, T1, T2, glue_mixed_plus> >::result operator+ ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! addition of two sparse objects template inline arma_hot typename enable_if2 < (is_arma_sparse_type::value && is_arma_sparse_type::value && is_same_type::value), SpGlue >::result operator+ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); return SpGlue(x, y); } //! addition of sparse and non-sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), Mat >::result operator+ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); Mat result(x); const SpProxy pb(y); arma_debug_assert_same_size( result.n_rows, result.n_cols, pb.get_n_rows(), pb.get_n_cols(), "addition" ); typename SpProxy::const_iterator_type it = pb.begin(); typename SpProxy::const_iterator_type it_end = pb.end(); while(it != it_end) { result.at(it.row(), it.col()) += (*it); ++it; } return result; } //! addition of sparse and non-sparse object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), Mat >::result operator+ ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); // Just call the other order (these operations are commutative) return (y + x); } template arma_inline Mat operator+ ( const subview_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_each1_aux::operator_plus(X, Y.get_ref()); } template arma_inline Mat operator+ ( const Base& X, const subview_each1& Y ) { arma_extra_debug_sigprint(); return subview_each1_aux::operator_plus(Y, X.get_ref()); // NOTE: swapped order } template arma_inline Mat operator+ ( const subview_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_each2_aux::operator_plus(X, Y.get_ref()); } template arma_inline Mat operator+ ( const Base& X, const subview_each2& Y ) { arma_extra_debug_sigprint(); return subview_each2_aux::operator_plus(Y, X.get_ref()); // NOTE: swapped order } //! @} armadillo-6.500.5/include/armadillo_bits/SpValProxy_meat.hpp0000666000000000000000000001252212620272703022556 0ustar rootroot// Copyright (C) 2011-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup SpValProxy //! @{ //! SpValProxy implementation. template arma_inline SpValProxy::SpValProxy(uword in_row, uword in_col, T1& in_parent, eT* in_val_ptr) : row(in_row) , col(in_col) , val_ptr(in_val_ptr) , parent(in_parent) { // Nothing to do. } template arma_inline SpValProxy& SpValProxy::operator=(const SpValProxy& rhs) { return (*this).operator=(eT(rhs)); } template template arma_inline SpValProxy& SpValProxy::operator=(const SpValProxy& rhs) { return (*this).operator=(eT(rhs)); } template arma_inline SpValProxy& SpValProxy::operator=(const eT rhs) { if (rhs != eT(0)) // A nonzero element is being assigned. { if (val_ptr) { // The value exists and merely needs to be updated. *val_ptr = rhs; } else { // The value is nonzero and must be added. val_ptr = &parent.add_element(row, col, rhs); } } else // A zero is being assigned.~ { if (val_ptr) { // The element exists, but we need to remove it, because it is being set to 0. parent.delete_element(row, col); val_ptr = NULL; } // If the element does not exist, we do not need to do anything at all. } return *this; } template arma_inline SpValProxy& SpValProxy::operator+=(const eT rhs) { if (val_ptr) { // The value already exists and merely needs to be updated. *val_ptr += rhs; check_zero(); } else { if (rhs != eT(0)) { // The value does not exist and must be added. val_ptr = &parent.add_element(row, col, rhs); } } return *this; } template arma_inline SpValProxy& SpValProxy::operator-=(const eT rhs) { if (val_ptr) { // The value already exists and merely needs to be updated. *val_ptr -= rhs; check_zero(); } else { if (rhs != eT(0)) { // The value does not exist and must be added. val_ptr = &parent.add_element(row, col, -rhs); } } return *this; } template arma_inline SpValProxy& SpValProxy::operator*=(const eT rhs) { if (rhs != eT(0)) { if (val_ptr) { // The value already exists and merely needs to be updated. *val_ptr *= rhs; check_zero(); } } else { if (val_ptr) { // Since we are multiplying by zero, the value can be deleted. parent.delete_element(row, col); val_ptr = NULL; } } return *this; } template arma_inline SpValProxy& SpValProxy::operator/=(const eT rhs) { if (rhs != eT(0)) // I hope this is true! { if (val_ptr) { *val_ptr /= rhs; check_zero(); } } else { if (val_ptr) { *val_ptr /= rhs; // That is where it gets ugly. // Now check if it's 0. if (*val_ptr == eT(0)) { parent.delete_element(row, col); val_ptr = NULL; } } else { eT val = eT(0) / rhs; // This may vary depending on type and implementation. if (val != eT(0)) { // Ok, now we have to add it. val_ptr = &parent.add_element(row, col, val); } } } return *this; } template arma_inline SpValProxy& SpValProxy::operator++() { if (val_ptr) { (*val_ptr) += eT(1); check_zero(); } else { val_ptr = &parent.add_element(row, col, eT(1)); } return *this; } template arma_inline SpValProxy& SpValProxy::operator--() { if (val_ptr) { (*val_ptr) -= eT(1); check_zero(); } else { val_ptr = &parent.add_element(row, col, eT(-1)); } return *this; } template arma_inline typename T1::elem_type SpValProxy::operator++(const int) { if (val_ptr) { (*val_ptr) += eT(1); check_zero(); } else { val_ptr = &parent.add_element(row, col, eT(1)); } if (val_ptr) // It may have changed to now be 0. { return *(val_ptr) - eT(1); } else { return eT(0); } } template arma_inline typename T1::elem_type SpValProxy::operator--(const int) { if (val_ptr) { (*val_ptr) -= eT(1); check_zero(); } else { val_ptr = &parent.add_element(row, col, eT(-1)); } if (val_ptr) // It may have changed to now be 0. { return *(val_ptr) + eT(1); } else { return eT(0); } } template arma_inline SpValProxy::operator eT() const { if (val_ptr) { return *val_ptr; } else { return eT(0); } } template arma_inline arma_hot void SpValProxy::check_zero() { if (*val_ptr == eT(0)) { parent.delete_element(row, col); val_ptr = NULL; } } //! @} armadillo-6.500.5/include/armadillo_bits/glue_relational_bones.hpp0000666000000000000000000000556412620272703024025 0ustar rootroot// Copyright (C) 2009-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_relational //! @{ class glue_rel_lt { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_gt { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_lteq { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_gteq { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_eq { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_noteq { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_and { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; class glue_rel_or { public: template inline static void apply(Mat & out, const mtGlue& X); template inline static void apply(Cube & out, const mtGlueCube& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/cond_rel_meat.hpp0000666000000000000000000000315412620272703022255 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup cond_rel //! @{ template<> template arma_inline bool cond_rel::lt(const eT A, const eT B) { return (A < B); } template<> template arma_inline bool cond_rel::lt(const eT, const eT) { return false; } template<> template arma_inline bool cond_rel::gt(const eT A, const eT B) { return (A > B); } template<> template arma_inline bool cond_rel::gt(const eT, const eT) { return false; } template<> template arma_inline bool cond_rel::leq(const eT A, const eT B) { return (A <= B); } template<> template arma_inline bool cond_rel::leq(const eT, const eT) { return false; } template<> template arma_inline bool cond_rel::geq(const eT A, const eT B) { return (A >= B); } template<> template arma_inline bool cond_rel::geq(const eT, const eT) { return false; } template<> template arma_inline eT cond_rel::make_neg(const eT val) { return -val; } template<> template arma_inline eT cond_rel::make_neg(const eT) { return eT(0); } //! @} armadillo-6.500.5/include/armadillo_bits/wrapper_lapack.hpp0000666000000000000000000010140612627061342022456 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by James Sanders // Written by Eric Jon Sundstrom #ifdef ARMA_USE_LAPACK //! \namespace lapack namespace for LAPACK functions namespace lapack { template inline void getrf(blas_int* m, blas_int* n, eT* a, blas_int* lda, blas_int* ipiv, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgetrf)(m, n, (T*)a, lda, ipiv, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgetrf)(m, n, (T*)a, lda, ipiv, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_cgetrf)(m, n, (T*)a, lda, ipiv, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zgetrf)(m, n, (T*)a, lda, ipiv, info); } } template inline void getri(blas_int* n, eT* a, blas_int* lda, blas_int* ipiv, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgetri)(n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgetri)(n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_cgetri)(n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zgetri)(n, (T*)a, lda, ipiv, (T*)work, lwork, info); } } template inline void trtri(char* uplo, char* diag, blas_int* n, eT* a, blas_int* lda, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_strtri)(uplo, diag, n, (T*)a, lda, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dtrtri)(uplo, diag, n, (T*)a, lda, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_ctrtri)(uplo, diag, n, (T*)a, lda, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_ztrtri)(uplo, diag, n, (T*)a, lda, info); } } template inline void geev(char* jobvl, char* jobvr, blas_int* N, eT* a, blas_int* lda, eT* wr, eT* wi, eT* vl, blas_int* ldvl, eT* vr, blas_int* ldvr, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgeev)(jobvl, jobvr, N, (T*)a, lda, (T*)wr, (T*)wi, (T*)vl, ldvl, (T*)vr, ldvr, (T*)work, lwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgeev)(jobvl, jobvr, N, (T*)a, lda, (T*)wr, (T*)wi, (T*)vl, ldvl, (T*)vr, ldvr, (T*)work, lwork, info); } } template inline void cx_geev(char* jobvl, char* jobvr, blas_int* N, eT* a, blas_int* lda, eT* w, eT* vl, blas_int* ldvl, eT* vr, blas_int* ldvr, eT* work, blas_int* lwork, typename eT::value_type* rwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value) { typedef float T; typedef typename std::complex cx_T; arma_fortran(arma_cgeev)(jobvl, jobvr, N, (cx_T*)a, lda, (cx_T*)w, (cx_T*)vl, ldvl, (cx_T*)vr, ldvr, (cx_T*)work, lwork, (T*)rwork, info); } else if(is_supported_complex_double::value) { typedef double T; typedef typename std::complex cx_T; arma_fortran(arma_zgeev)(jobvl, jobvr, N, (cx_T*)a, lda, (cx_T*)w, (cx_T*)vl, ldvl, (cx_T*)vr, ldvr, (cx_T*)work, lwork, (T*)rwork, info); } } template inline void syev(char* jobz, char* uplo, blas_int* n, eT* a, blas_int* lda, eT* w, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_ssyev)(jobz, uplo, n, (T*)a, lda, (T*)w, (T*)work, lwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dsyev)(jobz, uplo, n, (T*)a, lda, (T*)w, (T*)work, lwork, info); } } template inline void syevd(char* jobz, char* uplo, blas_int* n, eT* a, blas_int* lda, eT* w, eT* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_ssyevd)(jobz, uplo, n, (T*)a, lda, (T*)w, (T*)work, lwork, iwork, liwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dsyevd)(jobz, uplo, n, (T*)a, lda, (T*)w, (T*)work, lwork, iwork, liwork, info); } } template inline void heev ( char* jobz, char* uplo, blas_int* n, eT* a, blas_int* lda, typename eT::value_type* w, eT* work, blas_int* lwork, typename eT::value_type* rwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value) { typedef float T; typedef typename std::complex cx_T; arma_fortran(arma_cheev)(jobz, uplo, n, (cx_T*)a, lda, (T*)w, (cx_T*)work, lwork, (T*)rwork, info); } else if(is_supported_complex_double::value) { typedef double T; typedef typename std::complex cx_T; arma_fortran(arma_zheev)(jobz, uplo, n, (cx_T*)a, lda, (T*)w, (cx_T*)work, lwork, (T*)rwork, info); } } template inline void heevd ( char* jobz, char* uplo, blas_int* n, eT* a, blas_int* lda, typename eT::value_type* w, eT* work, blas_int* lwork, typename eT::value_type* rwork, blas_int* lrwork, blas_int* iwork, blas_int* liwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value) { typedef float T; typedef typename std::complex cx_T; arma_fortran(arma_cheevd)(jobz, uplo, n, (cx_T*)a, lda, (T*)w, (cx_T*)work, lwork, (T*)rwork, lrwork, iwork, liwork, info); } else if(is_supported_complex_double::value) { typedef double T; typedef typename std::complex cx_T; arma_fortran(arma_zheevd)(jobz, uplo, n, (cx_T*)a, lda, (T*)w, (cx_T*)work, lwork, (T*)rwork, lrwork, iwork, liwork, info); } } template inline void ggev ( char* jobvl, char* jobvr, blas_int* n, eT* a, blas_int* lda, eT* b, blas_int* ldb, eT* alphar, eT* alphai, eT* beta, eT* vl, blas_int* ldvl, eT* vr, blas_int* ldvr, eT* work, blas_int* lwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sggev)(jobvl, jobvr, n, (T*)a, lda, (T*)b, ldb, (T*)alphar, (T*)alphai, (T*)beta, (T*)vl, ldvl, (T*)vr, ldvr, (T*)work, lwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dggev)(jobvl, jobvr, n, (T*)a, lda, (T*)b, ldb, (T*)alphar, (T*)alphai, (T*)beta, (T*)vl, ldvl, (T*)vr, ldvr, (T*)work, lwork, info); } } template inline void cx_ggev ( char* jobvl, char* jobvr, blas_int* n, eT* a, blas_int* lda, eT* b, blas_int* ldb, eT* alpha, eT* beta, eT* vl, blas_int* ldvl, eT* vr, blas_int* ldvr, eT* work, blas_int* lwork, typename eT::value_type* rwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value) { typedef float T; typedef typename std::complex cx_T; arma_fortran(arma_cggev)(jobvl, jobvr, n, (cx_T*)a, lda, (cx_T*)b, ldb, (cx_T*)alpha, (cx_T*)beta, (cx_T*)vl, ldvl, (cx_T*)vr, ldvr, (cx_T*)work, lwork, (T*)rwork, info); } else if(is_supported_complex_double::value) { typedef double T; typedef typename std::complex cx_T; arma_fortran(arma_zggev)(jobvl, jobvr, n, (cx_T*)a, lda, (cx_T*)b, ldb, (cx_T*)alpha, (cx_T*)beta, (cx_T*)vl, ldvl, (cx_T*)vr, ldvr, (cx_T*)work, lwork, (T*)rwork, info); } } template inline void potrf(char* uplo, blas_int* n, eT* a, blas_int* lda, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_spotrf)(uplo, n, (T*)a, lda, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dpotrf)(uplo, n, (T*)a, lda, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_cpotrf)(uplo, n, (T*)a, lda, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zpotrf)(uplo, n, (T*)a, lda, info); } } template inline void potri(char* uplo, blas_int* n, eT* a, blas_int* lda, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_spotri)(uplo, n, (T*)a, lda, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dpotri)(uplo, n, (T*)a, lda, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_cpotri)(uplo, n, (T*)a, lda, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zpotri)(uplo, n, (T*)a, lda, info); } } template inline void geqrf(blas_int* m, blas_int* n, eT* a, blas_int* lda, eT* tau, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgeqrf)(m, n, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgeqrf)(m, n, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_cgeqrf)(m, n, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zgeqrf)(m, n, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } } template inline void orgqr(blas_int* m, blas_int* n, blas_int* k, eT* a, blas_int* lda, eT* tau, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sorgqr)(m, n, k, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dorgqr)(m, n, k, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } } template inline void ungqr(blas_int* m, blas_int* n, blas_int* k, eT* a, blas_int* lda, eT* tau, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value) { typedef float T; arma_fortran(arma_cungqr)(m, n, k, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } else if(is_supported_complex_double::value) { typedef double T; arma_fortran(arma_zungqr)(m, n, k, (T*)a, lda, (T*)tau, (T*)work, lwork, info); } } template inline void gesvd ( char* jobu, char* jobvt, blas_int* m, blas_int* n, eT* a, blas_int* lda, eT* s, eT* u, blas_int* ldu, eT* vt, blas_int* ldvt, eT* work, blas_int* lwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgesvd)(jobu, jobvt, m, n, (T*)a, lda, (T*)s, (T*)u, ldu, (T*)vt, ldvt, (T*)work, lwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgesvd)(jobu, jobvt, m, n, (T*)a, lda, (T*)s, (T*)u, ldu, (T*)vt, ldvt, (T*)work, lwork, info); } } template inline void cx_gesvd ( char* jobu, char* jobvt, blas_int* m, blas_int* n, std::complex* a, blas_int* lda, T* s, std::complex* u, blas_int* ldu, std::complex* vt, blas_int* ldvt, std::complex* work, blas_int* lwork, T* rwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); arma_type_check(( is_supported_blas_type< std::complex >::value == false )); if(is_float::value) { typedef float bT; arma_fortran(arma_cgesvd) ( jobu, jobvt, m, n, (std::complex*)a, lda, (bT*)s, (std::complex*)u, ldu, (std::complex*)vt, ldvt, (std::complex*)work, lwork, (bT*)rwork, info ); } else if(is_double::value) { typedef double bT; arma_fortran(arma_zgesvd) ( jobu, jobvt, m, n, (std::complex*)a, lda, (bT*)s, (std::complex*)u, ldu, (std::complex*)vt, ldvt, (std::complex*)work, lwork, (bT*)rwork, info ); } } template inline void gesdd ( char* jobz, blas_int* m, blas_int* n, eT* a, blas_int* lda, eT* s, eT* u, blas_int* ldu, eT* vt, blas_int* ldvt, eT* work, blas_int* lwork, blas_int* iwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgesdd)(jobz, m, n, (T*)a, lda, (T*)s, (T*)u, ldu, (T*)vt, ldvt, (T*)work, lwork, iwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgesdd)(jobz, m, n, (T*)a, lda, (T*)s, (T*)u, ldu, (T*)vt, ldvt, (T*)work, lwork, iwork, info); } } template inline void cx_gesdd ( char* jobz, blas_int* m, blas_int* n, std::complex* a, blas_int* lda, T* s, std::complex* u, blas_int* ldu, std::complex* vt, blas_int* ldvt, std::complex* work, blas_int* lwork, T* rwork, blas_int* iwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); arma_type_check(( is_supported_blas_type< std::complex >::value == false )); if(is_float::value) { typedef float bT; arma_fortran(arma_cgesdd) ( jobz, m, n, (std::complex*)a, lda, (bT*)s, (std::complex*)u, ldu, (std::complex*)vt, ldvt, (std::complex*)work, lwork, (bT*)rwork, iwork, info ); } else if(is_double::value) { typedef double bT; arma_fortran(arma_zgesdd) ( jobz, m, n, (std::complex*)a, lda, (bT*)s, (std::complex*)u, ldu, (std::complex*)vt, ldvt, (std::complex*)work, lwork, (bT*)rwork, iwork, info ); } } template inline void gesv(blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, blas_int* ipiv, eT* b, blas_int* ldb, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgesv)(n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgesv)(n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_cgesv)(n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zgesv)(n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info); } } template inline void gesvx(char* fact, char* trans, blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, eT* af, blas_int* ldaf, blas_int* ipiv, char* equed, eT* r, eT* c, eT* b, blas_int* ldb, eT* x, blas_int* ldx, eT* rcond, eT* ferr, eT* berr, eT* work, blas_int* iwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgesvx)(fact, trans, n, nrhs, (T*)a, lda, (T*)af, ldaf, ipiv, equed, (T*)r, (T*)c, (T*)b, ldb, (T*)x, ldx, (T*)rcond, (T*)ferr, (T*)berr, (T*)work, iwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgesvx)(fact, trans, n, nrhs, (T*)a, lda, (T*)af, ldaf, ipiv, equed, (T*)r, (T*)c, (T*)b, ldb, (T*)x, ldx, (T*)rcond, (T*)ferr, (T*)berr, (T*)work, iwork, info); } } template inline void cx_gesvx(char* fact, char* trans, blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, eT* af, blas_int* ldaf, blas_int* ipiv, char* equed, T* r, T* c, eT* b, blas_int* ldb, eT* x, blas_int* ldx, T* rcond, T* ferr, T* berr, eT* work, T* rwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value) { typedef float pod_T; typedef std::complex cx_T; arma_fortran(arma_cgesvx)(fact, trans, n, nrhs, (cx_T*)a, lda, (cx_T*)af, ldaf, ipiv, equed, (pod_T*)r, (pod_T*)c, (cx_T*)b, ldb, (cx_T*)x, ldx, (pod_T*)rcond, (pod_T*)ferr, (pod_T*)berr, (cx_T*)work, (pod_T*)rwork, info); } else if(is_supported_complex_double::value) { typedef double pod_T; typedef std::complex cx_T; arma_fortran(arma_zgesvx)(fact, trans, n, nrhs, (cx_T*)a, lda, (cx_T*)af, ldaf, ipiv, equed, (pod_T*)r, (pod_T*)c, (cx_T*)b, ldb, (cx_T*)x, ldx, (pod_T*)rcond, (pod_T*)ferr, (pod_T*)berr, (cx_T*)work, (pod_T*)rwork, info); } } template inline void gels(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, eT* b, blas_int* ldb, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgels)(trans, m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)work, lwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgels)(trans, m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)work, lwork, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_cgels)(trans, m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)work, lwork, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zgels)(trans, m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)work, lwork, info); } } template inline void gelsd(blas_int* m, blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, eT* b, blas_int* ldb, eT* S, eT* rcond, blas_int* rank, eT* work, blas_int* lwork, blas_int* iwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgelsd)(m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)S, (T*)rcond, rank, (T*)work, lwork, iwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgelsd)(m, n, nrhs, (T*)a, lda, (T*)b, ldb, (T*)S, (T*)rcond, rank, (T*)work, lwork, iwork, info); } } template inline void cx_gelsd(blas_int* m, blas_int* n, blas_int* nrhs, std::complex* a, blas_int* lda, std::complex* b, blas_int* ldb, T* S, T* rcond, blas_int* rank, std::complex* work, blas_int* lwork, T* rwork, blas_int* iwork, blas_int* info) { typedef typename std::complex eT; arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value) { typedef float pod_T; typedef std::complex cx_T; arma_fortran(arma_cgelsd)(m, n, nrhs, (cx_T*)a, lda, (cx_T*)b, ldb, (pod_T*)S, (pod_T*)rcond, rank, (cx_T*)work, lwork, (pod_T*)rwork, iwork, info); } else if(is_supported_complex_double::value) { typedef double pod_T; typedef std::complex cx_T; arma_fortran(arma_zgelsd)(m, n, nrhs, (cx_T*)a, lda, (cx_T*)b, ldb, (pod_T*)S, (pod_T*)rcond, rank, (cx_T*)work, lwork, (pod_T*)rwork, iwork, info); } } template inline void trtrs(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const eT* a, blas_int* lda, eT* b, blas_int* ldb, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_strtrs)(uplo, trans, diag, n, nrhs, (T*)a, lda, (T*)b, ldb, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dtrtrs)(uplo, trans, diag, n, nrhs, (T*)a, lda, (T*)b, ldb, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_ctrtrs)(uplo, trans, diag, n, nrhs, (T*)a, lda, (T*)b, ldb, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_ztrtrs)(uplo, trans, diag, n, nrhs, (T*)a, lda, (T*)b, ldb, info); } } template inline void gees(char* jobvs, char* sort, void* select, blas_int* n, eT* a, blas_int* lda, blas_int* sdim, eT* wr, eT* wi, eT* vs, blas_int* ldvs, eT* work, blas_int* lwork, blas_int* bwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgees)(jobvs, sort, select, n, (T*)a, lda, sdim, (T*)wr, (T*)wi, (T*)vs, ldvs, (T*)work, lwork, bwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgees)(jobvs, sort, select, n, (T*)a, lda, sdim, (T*)wr, (T*)wi, (T*)vs, ldvs, (T*)work, lwork, bwork, info); } } template inline void cx_gees(char* jobvs, char* sort, void* select, blas_int* n, std::complex* a, blas_int* lda, blas_int* sdim, std::complex* w, std::complex* vs, blas_int* ldvs, std::complex* work, blas_int* lwork, T* rwork, blas_int* bwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); arma_type_check(( is_supported_blas_type< std::complex >::value == false )); if(is_float::value) { typedef float bT; typedef std::complex cT; arma_fortran(arma_cgees)(jobvs, sort, select, n, (cT*)a, lda, sdim, (cT*)w, (cT*)vs, ldvs, (cT*)work, lwork, (bT*)rwork, bwork, info); } else if(is_double::value) { typedef double bT; typedef std::complex cT; arma_fortran(arma_zgees)(jobvs, sort, select, n, (cT*)a, lda, sdim, (cT*)w, (cT*)vs, ldvs, (cT*)work, lwork, (bT*)rwork, bwork, info); } } template inline void trsyl(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const eT* a, blas_int* lda, const eT* b, blas_int* ldb, eT* c, blas_int* ldc, eT* scale, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_strsyl)(transa, transb, isgn, m, n, (T*)a, lda, (T*)b, ldb, (T*)c, ldc, (T*)scale, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dtrsyl)(transa, transb, isgn, m, n, (T*)a, lda, (T*)b, ldb, (T*)c, ldc, (T*)scale, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_ctrsyl)(transa, transb, isgn, m, n, (T*)a, lda, (T*)b, ldb, (T*)c, ldc, (float*)scale, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_ztrsyl)(transa, transb, isgn, m, n, (T*)a, lda, (T*)b, ldb, (T*)c, ldc, (double*)scale, info); } } template inline void sytrf(char* uplo, blas_int* n, eT* a, blas_int* lda, blas_int* ipiv, eT* work, blas_int* lwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_ssytrf)(uplo, n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dsytrf)(uplo, n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_csytrf)(uplo, n, (T*)a, lda, ipiv, (T*)work, lwork, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zsytrf)(uplo, n, (T*)a, lda, ipiv, (T*)work, lwork, info); } } template inline void sytri(char* uplo, blas_int* n, eT* a, blas_int* lda, blas_int* ipiv, eT* work, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_ssytri)(uplo, n, (T*)a, lda, ipiv, (T*)work, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dsytri)(uplo, n, (T*)a, lda, ipiv, (T*)work, info); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_csytri)(uplo, n, (T*)a, lda, ipiv, (T*)work, info); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zsytri)(uplo, n, (T*)a, lda, ipiv, (T*)work, info); } } template inline void gges ( char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, eT* a, blas_int* lda, eT* b, blas_int* ldb, blas_int* sdim, eT* alphar, eT* alphai, eT* beta, eT* vsl, blas_int* ldvsl, eT* vsr, blas_int* ldvsr, eT* work, blas_int* lwork, eT* bwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgges)(jobvsl, jobvsr, sort, selctg, n, (T*)a, lda, (T*)b, ldb, sdim, (T*)alphar, (T*)alphai, (T*)beta, (T*)vsl, ldvsl, (T*)vsr, ldvsr, (T*)work, lwork, (T*)bwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgges)(jobvsl, jobvsr, sort, selctg, n, (T*)a, lda, (T*)b, ldb, sdim, (T*)alphar, (T*)alphai, (T*)beta, (T*)vsl, ldvsl, (T*)vsr, ldvsr, (T*)work, lwork, (T*)bwork, info); } } template inline void cx_gges ( char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, eT* a, blas_int* lda, eT* b, blas_int* ldb, blas_int* sdim, eT* alpha, eT* beta, eT* vsl, blas_int* ldvsl, eT* vsr, blas_int* ldvsr, eT* work, blas_int* lwork, typename eT::value_type* rwork, typename eT::value_type* bwork, blas_int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value) { typedef float T; typedef typename std::complex cx_T; arma_fortran(arma_cgges)(jobvsl, jobvsr, sort, selctg, n, (cx_T*)a, lda, (cx_T*)b, ldb, sdim, (cx_T*)alpha, (cx_T*)beta, (cx_T*)vsl, ldvsl, (cx_T*)vsr, ldvsr, (cx_T*)work, lwork, (T*)rwork, (T*)bwork, info); } else if(is_supported_complex_double::value) { typedef double T; typedef typename std::complex cx_T; arma_fortran(arma_zgges)(jobvsl, jobvsr, sort, selctg, n, (cx_T*)a, lda, (cx_T*)b, ldb, sdim, (cx_T*)alpha, (cx_T*)beta, (cx_T*)vsl, ldvsl, (cx_T*)vsr, ldvsr, (cx_T*)work, lwork, (T*)rwork, (T*)bwork, info); } } template inline typename get_pod_type::result lange(char* norm, blas_int* m, blas_int* n, eT* a, blas_int* lda, typename get_pod_type::result* work) { arma_type_check(( is_supported_blas_type::value == false )); typedef typename get_pod_type::result out_T; if(is_float::value) { typedef float pod_T; typedef float T; return out_T( arma_fortran(arma_slange)(norm, m, n, (T*)a, lda, (pod_T*)work) ); } else if(is_double::value) { typedef double pod_T; typedef double T; return out_T( arma_fortran(arma_dlange)(norm, m, n, (T*)a, lda, (pod_T*)work) ); } else if(is_supported_complex_float::value) { typedef float pod_T; typedef std::complex T; return out_T( arma_fortran(arma_clange)(norm, m, n, (T*)a, lda, (pod_T*)work) ); } else if(is_supported_complex_double::value) { typedef double pod_T; typedef std::complex T; return out_T( arma_fortran(arma_zlange)(norm, m, n, (T*)a, lda, (pod_T*)work) ); } } template inline void gecon(char* norm, blas_int* n, eT* a, blas_int* lda, eT* anorm, eT* rcond, eT* work, blas_int* iwork, blas_int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_fortran(arma_sgecon)(norm, n, (T*)a, lda, (T*)anorm, (T*)rcond, (T*)work, iwork, info); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgecon)(norm, n, (T*)a, lda, (T*)anorm, (T*)rcond, (T*)work, iwork, info); } } template inline void cx_gecon(char* norm, blas_int* n, std::complex* a, blas_int* lda, T* anorm, T* rcond, std::complex* work, T* rwork, blas_int* info) { typedef typename std::complex eT; arma_type_check(( is_supported_blas_type::value == false )); if(is_supported_complex_float::value) { typedef float pod_T; typedef typename std::complex cx_T; arma_fortran(arma_cgecon)(norm, n, (cx_T*)a, lda, (pod_T*)anorm, (pod_T*)rcond, (cx_T*)work, (pod_T*)rwork, info); } else if(is_supported_complex_double::value) { typedef double pod_T; typedef typename std::complex cx_T; arma_fortran(arma_zgecon)(norm, n, (cx_T*)a, lda, (pod_T*)anorm, (pod_T*)rcond, (cx_T*)work, (pod_T*)rwork, info); } } inline blas_int laenv(blas_int* ispec, char* name, char* opts, blas_int* n1, blas_int* n2, blas_int* n3, blas_int* n4) { return arma_fortran(arma_ilaenv)(ispec, name, opts, n1, n2, n3, n4); } } #endif armadillo-6.500.5/include/armadillo_bits/op_max_meat.hpp0000666000000000000000000004000712650172354021755 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_max //! @{ template inline void op_max::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "max(): parameter 'dim' must be 0 or 1"); const unwrap U(in.m); const Mat& X = U.M; if(&out != &X) { op_max::apply_noalias(out, X, dim); } else { Mat tmp; op_max::apply_noalias(tmp, X, dim); out.steal_mem(tmp); } } template inline void op_max::apply_noalias(Mat& out, const Mat& X, const uword dim, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_max::apply(): dim = 0"); out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col 0) ? 1 : 0); if(X_n_cols == 0) { return; } eT* out_mem = out.memptr(); arrayops::copy(out_mem, X.colptr(0), X_n_rows); for(uword col=1; col out_mem[row]) { out_mem[row] = col_val; } } } } } template inline void op_max::apply_noalias(Mat& out, const Mat& X, const uword dim, const typename arma_cx_only::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_max::apply(): dim = 0"); out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col 0) ? 1 : 0); if(X_n_cols == 0) { return; } eT* out_mem = out.memptr(); for(uword row=0; row inline eT op_max::direct_max(const eT* const X, const uword n_elem) { arma_extra_debug_sigprint(); eT max_val = priv::most_neg(); uword i,j; for(i=0, j=1; j max_val) { max_val = X_i; } if(X_j > max_val) { max_val = X_j; } } if(i < n_elem) { const eT X_i = X[i]; if(X_i > max_val) { max_val = X_i; } } return max_val; } template inline eT op_max::direct_max(const eT* const X, const uword n_elem, uword& index_of_max_val) { arma_extra_debug_sigprint(); eT max_val = priv::most_neg(); uword best_index = 0; uword i,j; for(i=0, j=1; j max_val) { max_val = X_i; best_index = i; } if(X_j > max_val) { max_val = X_j; best_index = j; } } if(i < n_elem) { const eT X_i = X[i]; if(X_i > max_val) { max_val = X_i; best_index = i; } } index_of_max_val = best_index; return max_val; } template inline eT op_max::direct_max(const Mat& X, const uword row) { arma_extra_debug_sigprint(); const uword X_n_cols = X.n_cols; eT max_val = priv::most_neg(); uword i,j; for(i=0, j=1; j < X_n_cols; i+=2, j+=2) { const eT tmp_i = X.at(row,i); const eT tmp_j = X.at(row,j); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < X_n_cols) { const eT tmp_i = X.at(row,i); if(tmp_i > max_val) { max_val = tmp_i; } } return max_val; } template inline eT op_max::max(const subview& X) { arma_extra_debug_sigprint(); if(X.n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; eT max_val = priv::most_neg(); if(X_n_rows == 1) { const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X_n_cols; uword i,j; for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) { const eT tmp_i = A.at(start_row, i); const eT tmp_j = A.at(start_row, j); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < end_col_p1) { const eT tmp_i = A.at(start_row, i); if(tmp_i > max_val) { max_val = tmp_i; } } } else { for(uword col=0; col < X_n_cols; ++col) { max_val = (std::max)(max_val, op_max::direct_max(X.colptr(col), X_n_rows)); } } return max_val; } template inline typename arma_not_cx::result op_max::max(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } eT max_val = priv::most_neg(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < n_elem) { const eT tmp_i = A[i]; if(tmp_i > max_val) { max_val = tmp_i; } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp_i = P.at(0,i); const eT tmp_j = P.at(0,j); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < n_cols) { const eT tmp_i = P.at(0,i); if(tmp_i > max_val) { max_val = tmp_i; } } } else { for(uword col=0; col < n_cols; ++col) { uword i,j; for(i=0, j=1; j < n_rows; i+=2, j+=2) { const eT tmp_i = P.at(i,col); const eT tmp_j = P.at(j,col); if(tmp_i > max_val) { max_val = tmp_i; } if(tmp_j > max_val) { max_val = tmp_j; } } if(i < n_rows) { const eT tmp_i = P.at(i,col); if(tmp_i > max_val) { max_val = tmp_i; } } } } } return max_val; } template inline typename arma_not_cx::result op_max::max_with_index(const Proxy& P, uword& index_of_max_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } eT best_val = priv::most_neg(); uword best_index = 0; if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); for(uword i=0; i best_val) { best_val = tmp; best_index = i; } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { for(uword i=0; i < n_cols; ++i) { const eT tmp = P.at(0,i); if(tmp > best_val) { best_val = tmp; best_index = i; } } } else if(n_cols == 1) { for(uword i=0; i < n_rows; ++i) { const eT tmp = P.at(i,0); if(tmp > best_val) { best_val = tmp; best_index = i; } } } else { uword count = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT tmp = P.at(row,col); if(tmp > best_val) { best_val = tmp; best_index = count; } ++count; } } } index_of_max_val = best_index; return best_val; } template inline std::complex op_max::direct_max(const std::complex* const X, const uword n_elem) { arma_extra_debug_sigprint(); uword index = 0; T max_val = priv::most_neg(); for(uword i=0; i max_val) { max_val = tmp_val; index = i; } } return X[index]; } template inline std::complex op_max::direct_max(const std::complex* const X, const uword n_elem, uword& index_of_max_val) { arma_extra_debug_sigprint(); uword index = 0; T max_val = priv::most_neg(); for(uword i=0; i max_val) { max_val = tmp_val; index = i; } } index_of_max_val = index; return X[index]; } template inline std::complex op_max::direct_max(const Mat< std::complex >& X, const uword row) { arma_extra_debug_sigprint(); const uword X_n_cols = X.n_cols; uword index = 0; T max_val = priv::most_neg(); for(uword col=0; col max_val) { max_val = tmp_val; index = col; } } return X.at(row,index); } template inline std::complex op_max::max(const subview< std::complex >& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(X.n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } const Mat& A = X.m; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_row_p1 = start_row + X_n_rows; const uword end_col_p1 = start_col + X_n_cols; T max_val = priv::most_neg(); uword best_row = 0; uword best_col = 0; if(X_n_rows == 1) { best_col = 0; for(uword col=start_col; col < end_col_p1; ++col) { const T tmp_val = std::abs( A.at(start_row, col) ); if(tmp_val > max_val) { max_val = tmp_val; best_col = col; } } best_row = start_row; } else { for(uword col=start_col; col < end_col_p1; ++col) for(uword row=start_row; row < end_row_p1; ++row) { const T tmp_val = std::abs( A.at(row, col) ); if(tmp_val > max_val) { max_val = tmp_val; best_row = row; best_col = col; } } } return A.at(best_row, best_col); } template inline typename arma_cx_only::result op_max::max(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } T max_val = priv::most_neg(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword index = 0; for(uword i=0; i max_val) { max_val = tmp; index = i; } } return( A[index] ); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); uword best_row = 0; uword best_col = 0; if(n_rows == 1) { for(uword col=0; col < n_cols; ++col) { const T tmp = std::abs(P.at(0,col)); if(tmp > max_val) { max_val = tmp; best_col = col; } } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const T tmp = std::abs(P.at(row,col)); if(tmp > max_val) { max_val = tmp; best_row = row; best_col = col; } } } return P.at(best_row, best_col); } } template inline typename arma_cx_only::result op_max::max_with_index(const Proxy& P, uword& index_of_max_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const uword n_elem = P.get_n_elem(); if(n_elem == 0) { arma_debug_check(true, "max(): object has no elements"); return Datum::nan; } T best_val = priv::most_neg(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); uword best_index = 0; for(uword i=0; i best_val) { best_val = tmp; best_index = i; } } index_of_max_val = best_index; return( A[best_index] ); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); uword best_row = 0; uword best_col = 0; uword best_index = 0; if(n_rows == 1) { for(uword col=0; col < n_cols; ++col) { const T tmp = std::abs(P.at(0,col)); if(tmp > best_val) { best_val = tmp; best_col = col; } } best_index = best_col; } else if(n_cols == 1) { for(uword row=0; row < n_rows; ++row) { const T tmp = std::abs(P.at(row,0)); if(tmp > best_val) { best_val = tmp; best_row = row; } } best_index = best_row; } else { uword count = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const T tmp = std::abs(P.at(row,col)); if(tmp > best_val) { best_val = tmp; best_row = row; best_col = col; best_index = count; } ++count; } } index_of_max_val = best_index; return P.at(best_row, best_col); } } //! @} armadillo-6.500.5/include/armadillo_bits/glue_mixed_meat.hpp0000666000000000000000000003367512620272703022625 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_mixed //! @{ //! matrix multiplication with different element types template inline void glue_mixed_times::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_times>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; const unwrap_check_mixed tmp1(X.A, out); const unwrap_check_mixed tmp2(X.B, out); const Mat& A = tmp1.M; const Mat& B = tmp2.M; arma_debug_assert_mul_size(A, B, "matrix multiplication"); out.set_size(A.n_rows, B.n_cols); gemm_mixed<>::apply(out, A, B); } //! matrix addition with different element types template inline void glue_mixed_plus::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_plus>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "addition"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { typename Proxy::ea_type AA = A.get_ea(); typename Proxy::ea_type BB = B.get_ea(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); for(uword i=0; i::apply(AA[i]) + upgrade_val::apply(BB[i]); } } else { for(uword i=0; i::apply(AA[i]) + upgrade_val::apply(BB[i]); } } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { (*out_mem) = upgrade_val::apply(A.at(row,col)) + upgrade_val::apply(B.at(row,col)); out_mem++; } } } //! matrix subtraction with different element types template inline void glue_mixed_minus::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_minus>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "subtraction"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { typename Proxy::ea_type AA = A.get_ea(); typename Proxy::ea_type BB = B.get_ea(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); for(uword i=0; i::apply(AA[i]) - upgrade_val::apply(BB[i]); } } else { for(uword i=0; i::apply(AA[i]) - upgrade_val::apply(BB[i]); } } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { (*out_mem) = upgrade_val::apply(A.at(row,col)) - upgrade_val::apply(B.at(row,col)); out_mem++; } } } //! element-wise matrix division with different element types template inline void glue_mixed_div::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_div>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "element-wise division"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { typename Proxy::ea_type AA = A.get_ea(); typename Proxy::ea_type BB = B.get_ea(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); for(uword i=0; i::apply(AA[i]) / upgrade_val::apply(BB[i]); } } else { for(uword i=0; i::apply(AA[i]) / upgrade_val::apply(BB[i]); } } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { (*out_mem) = upgrade_val::apply(A.at(row,col)) / upgrade_val::apply(B.at(row,col)); out_mem++; } } } //! element-wise matrix multiplication with different element types template inline void glue_mixed_schur::apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_schur>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "element-wise multiplication"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); out.set_size(n_rows, n_cols); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (Proxy::prefer_at_accessor || Proxy::prefer_at_accessor); if(prefer_at_accessor == false) { typename Proxy::ea_type AA = A.get_ea(); typename Proxy::ea_type BB = B.get_ea(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); for(uword i=0; i::apply(AA[i]) * upgrade_val::apply(BB[i]); } } else { for(uword i=0; i::apply(AA[i]) * upgrade_val::apply(BB[i]); } } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { (*out_mem) = upgrade_val::apply(A.at(row,col)) * upgrade_val::apply(B.at(row,col)); out_mem++; } } } // // // //! cube addition with different element types template inline void glue_mixed_plus::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_plus>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const ProxyCube A(X.A); const ProxyCube B(X.B); arma_debug_assert_same_size(A, B, "addition"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { typename ProxyCube::ea_type AA = A.get_ea(); typename ProxyCube::ea_type BB = B.get_ea(); for(uword i=0; i::apply(AA[i]) + upgrade_val::apply(BB[i]); } } else { for(uword slice = 0; slice < n_slices; ++slice) for(uword col = 0; col < n_cols; ++col ) for(uword row = 0; row < n_rows; ++row ) { (*out_mem) = upgrade_val::apply(A.at(row,col,slice)) + upgrade_val::apply(B.at(row,col,slice)); out_mem++; } } } //! cube subtraction with different element types template inline void glue_mixed_minus::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_minus>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const ProxyCube A(X.A); const ProxyCube B(X.B); arma_debug_assert_same_size(A, B, "subtraction"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { typename ProxyCube::ea_type AA = A.get_ea(); typename ProxyCube::ea_type BB = B.get_ea(); for(uword i=0; i::apply(AA[i]) - upgrade_val::apply(BB[i]); } } else { for(uword slice = 0; slice < n_slices; ++slice) for(uword col = 0; col < n_cols; ++col ) for(uword row = 0; row < n_rows; ++row ) { (*out_mem) = upgrade_val::apply(A.at(row,col,slice)) - upgrade_val::apply(B.at(row,col,slice)); out_mem++; } } } //! element-wise cube division with different element types template inline void glue_mixed_div::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_div>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const ProxyCube A(X.A); const ProxyCube B(X.B); arma_debug_assert_same_size(A, B, "element-wise division"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { typename ProxyCube::ea_type AA = A.get_ea(); typename ProxyCube::ea_type BB = B.get_ea(); for(uword i=0; i::apply(AA[i]) / upgrade_val::apply(BB[i]); } } else { for(uword slice = 0; slice < n_slices; ++slice) for(uword col = 0; col < n_cols; ++col ) for(uword row = 0; row < n_rows; ++row ) { (*out_mem) = upgrade_val::apply(A.at(row,col,slice)) / upgrade_val::apply(B.at(row,col,slice)); out_mem++; } } } //! element-wise cube multiplication with different element types template inline void glue_mixed_schur::apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_schur>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); const ProxyCube A(X.A); const ProxyCube B(X.B); arma_debug_assert_same_size(A, B, "element-wise multiplication"); const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); const uword n_slices = A.get_n_slices(); out.set_size(n_rows, n_cols, n_slices); out_eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; const bool prefer_at_accessor = (ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor); if(prefer_at_accessor == false) { typename ProxyCube::ea_type AA = A.get_ea(); typename ProxyCube::ea_type BB = B.get_ea(); for(uword i=0; i::apply(AA[i]) * upgrade_val::apply(BB[i]); } } else { for(uword slice = 0; slice < n_slices; ++slice) for(uword col = 0; col < n_cols; ++col ) for(uword row = 0; row < n_rows; ++row ) { (*out_mem) = upgrade_val::apply(A.at(row,col,slice)) * upgrade_val::apply(B.at(row,col,slice)); out_mem++; } } } //! @} armadillo-6.500.5/include/armadillo_bits/fn_sprandn.hpp0000666000000000000000000000457412620272703021621 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_sprandn //! @{ //! Generate a sparse matrix with a randomly selected subset of the elements //! set to random values from a Gaussian distribution with zero mean and unit variance template inline obj_type sprandn ( const uword n_rows, const uword n_cols, const double density, const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_SpCol::value == true) { arma_debug_check( (n_cols != 1), "sprandn(): incompatible size" ); } else if(is_SpRow::value == true) { arma_debug_check( (n_rows != 1), "sprandn(): incompatible size" ); } obj_type out; out.sprandn(n_rows, n_cols, density); return out; } template inline obj_type sprandn(const SizeMat& s, const double density, const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return sprandn(s.n_rows, s.n_cols, density); } inline sp_mat sprandn(const uword n_rows, const uword n_cols, const double density) { arma_extra_debug_sigprint(); sp_mat out; out.sprandn(n_rows, n_cols, density); return out; } inline sp_mat sprandn(const SizeMat& s, const double density) { arma_extra_debug_sigprint(); sp_mat out; out.sprandn(s.n_rows, s.n_cols, density); return out; } //! Generate a sparse matrix with the non-zero values in the same locations as in the given sparse matrix X, //! with the non-zero values set to random values from a Gaussian distribution with zero mean and unit variance template inline SpMat sprandn(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; SpMat out( X.get_ref() ); arma_rng::randn::fill( access::rwp(out.values), out.n_nonzero ); return out; } //! @} armadillo-6.500.5/include/armadillo_bits/mtOp_meat.hpp0000666000000000000000000000417012620272703021406 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup mtOp //! @{ template inline mtOp::mtOp(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline mtOp::mtOp(const T1& in_m, const typename T1::elem_type in_aux) : m(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline mtOp::mtOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline mtOp::mtOp(const T1& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline mtOp::mtOp(const char junk, const T1& in_m, const out_eT in_aux) : m(in_m) , aux_out_eT(in_aux) { arma_ignore(junk); arma_extra_debug_sigprint(); } template inline mtOp::mtOp(const mtOp_dual_aux_indicator&, const T1& in_m, const typename T1::elem_type in_aux_a, const out_eT in_aux_b) : m (in_m ) , aux (in_aux_a) , aux_out_eT(in_aux_b) { arma_extra_debug_sigprint(); } template inline mtOp::~mtOp() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_resize.hpp0000666000000000000000000000370512620272703021450 0ustar rootroot// Copyright (C) 2011-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_resize //! @{ template inline const Op resize(const Base& X, const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); return Op(X.get_ref(), in_n_rows, in_n_cols); } template inline const Op resize(const Base& X, const SizeMat& s) { arma_extra_debug_sigprint(); return Op(X.get_ref(), s.n_rows, s.n_cols); } template inline const OpCube resize(const BaseCube& X, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) { arma_extra_debug_sigprint(); return OpCube(X.get_ref(), in_n_rows, in_n_cols, in_n_slices); } template inline const OpCube resize(const BaseCube& X, const SizeCube& s) { arma_extra_debug_sigprint(); return OpCube(X.get_ref(), s.n_rows, s.n_cols, s.n_slices); } template inline const SpOp resize(const SpBase& X, const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); return SpOp(X.get_ref(), in_n_rows, in_n_cols); } template inline const SpOp resize(const SpBase& X, const SizeMat& s) { arma_extra_debug_sigprint(); return SpOp(X.get_ref(), s.n_rows, s.n_cols); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_fft2.hpp0000666000000000000000000000507712620272703021014 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_fft2 //! @{ // 2D FFT & 2D IFFT template inline typename enable_if2 < is_arma_type::value, Mat< std::complex > >::result fft2(const T1& A) { arma_extra_debug_sigprint(); // not exactly efficient, but "better-than-nothing" implementation typedef typename T1::pod_type T; Mat< std::complex > B = fft(A); // for square matrices, strans() will work out that an inplace transpose can be done, // hence we can potentially avoid creating a temporary matrix B = strans(B); return strans( fft(B) ); } template inline typename enable_if2 < is_arma_type::value, Mat< std::complex > >::result fft2(const T1& A, const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(A); const Mat& B = tmp.M; const bool do_resize = (B.n_rows != n_rows) || (B.n_cols != n_cols); return fft2( do_resize ? resize(B,n_rows,n_cols) : B ); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), Mat< std::complex > >::result ifft2(const T1& A) { arma_extra_debug_sigprint(); // not exactly efficient, but "better-than-nothing" implementation typedef typename T1::pod_type T; Mat< std::complex > B = ifft(A); // for square matrices, strans() will work out that an inplace transpose can be done, // hence we can potentially avoid creating a temporary matrix B = strans(B); return strans( ifft(B) ); } template inline typename enable_if2 < (is_arma_type::value && is_complex_strict::value), Mat< std::complex > >::result ifft2(const T1& A, const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(A); const Mat& B = tmp.M; const bool do_resize = (B.n_rows != n_rows) || (B.n_cols != n_cols); return ifft2( do_resize ? resize(B,n_rows,n_cols) : B ); } //! @} armadillo-6.500.5/include/armadillo_bits/eop_core_bones.hpp0000666000000000000000000001125712650723436022455 0ustar rootroot// Copyright (C) 2010-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eop_core //! @{ template class eop_core { public: // matrices template arma_hot inline static void apply(outT& out, const eOp& x); template arma_hot inline static void apply_inplace_plus (Mat& out, const eOp& x); template arma_hot inline static void apply_inplace_minus(Mat& out, const eOp& x); template arma_hot inline static void apply_inplace_schur(Mat& out, const eOp& x); template arma_hot inline static void apply_inplace_div (Mat& out, const eOp& x); // cubes template arma_hot inline static void apply(Cube& out, const eOpCube& x); template arma_hot inline static void apply_inplace_plus (Cube& out, const eOpCube& x); template arma_hot inline static void apply_inplace_minus(Cube& out, const eOpCube& x); template arma_hot inline static void apply_inplace_schur(Cube& out, const eOpCube& x); template arma_hot inline static void apply_inplace_div (Cube& out, const eOpCube& x); // common template arma_hot arma_inline static eT process(const eT val, const eT k); }; class eop_neg : public eop_core {}; class eop_scalar_plus : public eop_core {}; class eop_scalar_minus_pre : public eop_core {}; class eop_scalar_minus_post : public eop_core {}; class eop_scalar_times : public eop_core {}; class eop_scalar_div_pre : public eop_core {}; class eop_scalar_div_post : public eop_core {}; class eop_square : public eop_core {}; class eop_sqrt : public eop_core {}; class eop_log : public eop_core {}; class eop_log2 : public eop_core {}; class eop_log10 : public eop_core {}; class eop_trunc_log : public eop_core {}; class eop_exp : public eop_core {}; class eop_exp2 : public eop_core {}; class eop_exp10 : public eop_core {}; class eop_trunc_exp : public eop_core {}; class eop_cos : public eop_core {}; class eop_sin : public eop_core {}; class eop_tan : public eop_core {}; class eop_acos : public eop_core {}; class eop_asin : public eop_core {}; class eop_atan : public eop_core {}; class eop_cosh : public eop_core {}; class eop_sinh : public eop_core {}; class eop_tanh : public eop_core {}; class eop_acosh : public eop_core {}; class eop_asinh : public eop_core {}; class eop_atanh : public eop_core {}; class eop_eps : public eop_core {}; class eop_abs : public eop_core {}; class eop_conj : public eop_core {}; class eop_pow : public eop_core {}; class eop_floor : public eop_core {}; class eop_ceil : public eop_core {}; class eop_round : public eop_core {}; class eop_trunc : public eop_core {}; class eop_sign : public eop_core {}; //! @} armadillo-6.500.5/include/armadillo_bits/fn_median.hpp0000666000000000000000000000316712620272703021406 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_median //! @{ template arma_inline const Op median ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op median ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type median ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_median::median_vec(X); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & median(const T& x) { return x; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_syl_lyap.hpp0000666000000000000000000000424112620272703021777 0ustar rootroot// Copyright (C) 2011-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_syl_lyap //! @{ //! find the solution of the Sylvester equation AX + XB = C template inline bool syl ( Mat & out, const Base& in_A, const Base& in_B, const Base& in_C, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap_check tmp_A(in_A.get_ref(), out); const unwrap_check tmp_B(in_B.get_ref(), out); const unwrap_check tmp_C(in_C.get_ref(), out); const Mat& A = tmp_A.M; const Mat& B = tmp_B.M; const Mat& C = tmp_C.M; const bool status = auxlib::syl(out, A, B, C); if(status == false) { out.reset(); arma_debug_warn("syl(): solution not found"); } return status; } template inline Mat syl ( const Base& in_A, const Base& in_B, const Base& in_C, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const unwrap tmp_A( in_A.get_ref() ); const unwrap tmp_B( in_B.get_ref() ); const unwrap tmp_C( in_C.get_ref() ); const Mat& A = tmp_A.M; const Mat& B = tmp_B.M; const Mat& C = tmp_C.M; Mat out; const bool status = auxlib::syl(out, A, B, C); if(status == false) { out.reset(); arma_bad("syl(): solution not found"); } return out; } //! @} armadillo-6.500.5/include/armadillo_bits/op_princomp_bones.hpp0000666000000000000000000000706612620272703023203 0ustar rootroot// Copyright (C) 2010-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_princomp //! @{ class op_princomp { public: // // real element versions template inline static bool direct_princomp ( Mat& coeff_out, const Base& X, const typename arma_not_cx::result* junk = 0 ); template inline static bool direct_princomp ( Mat& coeff_out, Mat& score_out, const Base& X, const typename arma_not_cx::result* junk = 0 ); template inline static bool direct_princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, const Base& X, const typename arma_not_cx::result* junk = 0 ); template inline static bool direct_princomp ( Mat& coeff_out, Mat& score_out, Col& latent_out, Col& tsquared_out, const Base& X, const typename arma_not_cx::result* junk = 0 ); // // complex element versions template inline static bool direct_princomp ( Mat< std::complex >& coeff_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk = 0 ); template inline static bool direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk = 0 ); template inline static bool direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, Col< typename T1::pod_type >& latent_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk = 0 ); template inline static bool direct_princomp ( Mat< std::complex >& coeff_out, Mat< std::complex >& score_out, Col< typename T1::pod_type >& latent_out, Col< std::complex >& tsquared_out, const Base< std::complex, T1 >& X, const typename arma_cx_only::result* junk = 0 ); template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/spglue_plus_meat.hpp0000666000000000000000000001047612620272703023037 0ustar rootroot// Copyright (C) 2012-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spglue_plus //! @{ template arma_hot inline void spglue_plus::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_plus::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_plus::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } } template arma_hot inline void spglue_plus::apply_noalias(SpMat& out, const SpProxy& pa, const SpProxy& pb) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "addition"); if( (pa.get_n_nonzero() != 0) && (pb.get_n_nonzero() != 0) ) { out.zeros(pa.get_n_rows(), pa.get_n_cols()); // Resize memory to correct size. out.mem_resize(n_unique(pa, pb, op_n_unique_add())); // Now iterate across both matrices. typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type x_end = pa.end(); typename SpProxy::const_iterator_type y_end = pb.end(); uword cur_val = 0; while( (x_it != x_end) || (y_it != y_end) ) { if(x_it == y_it) { const eT val = (*x_it) + (*y_it); if(val != eT(0)) { access::rw(out.values[cur_val]) = val; access::rw(out.row_indices[cur_val]) = x_it.row(); ++access::rw(out.col_ptrs[x_it.col() + 1]); ++cur_val; } ++x_it; ++y_it; } else { const uword x_it_row = x_it.row(); const uword x_it_col = x_it.col(); const uword y_it_row = y_it.row(); const uword y_it_col = y_it.col(); if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end { const eT val = (*x_it); if(val != eT(0)) { access::rw(out.values[cur_val]) = val; access::rw(out.row_indices[cur_val]) = x_it_row; ++access::rw(out.col_ptrs[x_it_col + 1]); ++cur_val; } ++x_it; } else { const eT val = (*y_it); if(val != eT(0)) { access::rw(out.values[cur_val]) = val; access::rw(out.row_indices[cur_val]) = y_it_row; ++access::rw(out.col_ptrs[y_it_col + 1]); ++cur_val; } ++y_it; } } } const uword out_n_cols = out.n_cols; uword* col_ptrs = access::rwp(out.col_ptrs); // Fix column pointers to be cumulative. for(uword c = 1; c <= out_n_cols; ++c) { col_ptrs[c] += col_ptrs[c - 1]; } } else { if(pa.get_n_nonzero() == 0) { out = pb.Q; return; } if(pb.get_n_nonzero() == 0) { out = pa.Q; return; } } } // // // spglue_plus2: scalar*(A + B) template arma_hot inline void spglue_plus2::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_plus::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_plus::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } out *= X.aux; } //! @} armadillo-6.500.5/include/armadillo_bits/include_atlas.hpp0000666000000000000000000000200012620272703022256 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au #if defined(ARMA_USE_ATLAS) #if !defined(ARMA_ATLAS_INCLUDE_DIR) extern "C" { #include #include } #else #define ARMA_STR1(x) x #define ARMA_STR2(x) ARMA_STR1(x) #define ARMA_CBLAS ARMA_STR2(ARMA_ATLAS_INCLUDE_DIR)ARMA_STR2(cblas.h) #define ARMA_CLAPACK ARMA_STR2(ARMA_ATLAS_INCLUDE_DIR)ARMA_STR2(clapack.h) extern "C" { #include ARMA_INCFILE_WRAP(ARMA_CBLAS) #include ARMA_INCFILE_WRAP(ARMA_CLAPACK) } #undef ARMA_STR1 #undef ARMA_STR2 #undef ARMA_CBLAS #undef ARMA_CLAPACK #endif #endif armadillo-6.500.5/include/armadillo_bits/glue_max_meat.hpp0000666000000000000000000000613212620272703022270 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_max //! @{ template inline void glue_max::apply(Mat& out, const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); const uword n_rows = PA.get_n_rows(); const uword n_cols = PA.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, PB.get_n_rows(), PB.get_n_cols(), "max(): given matrices must have the same size"); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const uword N = PA.get_n_elem(); for(uword i=0; i inline void glue_max::apply(Mat< std::complex >& out, const Proxy& PA, const Proxy& PB) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const uword n_rows = PA.get_n_rows(); const uword n_cols = PA.get_n_cols(); arma_debug_assert_same_size(n_rows, n_cols, PB.get_n_rows(), PB.get_n_cols(), "max(): given matrices must have the same size"); out.set_size(n_rows, n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const uword N = PA.get_n_elem(); for(uword i=0; i std::abs(B_val) ) ? A_val : B_val; } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT A_val = PA.at(row,col); const eT B_val = PB.at(row,col); *out_mem = ( std::abs(A_val) > std::abs(B_val) ) ? A_val : B_val; ++out_mem; } } } template inline void glue_max::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy PA(X.A); const Proxy PB(X.B); if(PA.is_alias(out) || PB.is_alias(out)) { Mat tmp; glue_max::apply(tmp, PA, PB); out.steal_mem(tmp); } else { glue_max::apply(out, PA, PB); } } //! @} armadillo-6.500.5/include/armadillo_bits/fn_elem.hpp0000666000000000000000000003233612650723436021102 0ustar rootroot// Copyright (C) 2008-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_elem //! @{ // // real template arma_inline typename enable_if2< (is_arma_type::value && is_cx::no), const T1& >::result real(const T1& X) { arma_extra_debug_sigprint(); return X; } template arma_inline const T1& real(const BaseCube& X) { arma_extra_debug_sigprint(); return X.get_ref(); } template arma_inline const T1& real(const SpBase& A) { arma_extra_debug_sigprint(); return A.get_ref(); } template inline typename enable_if2< (is_arma_type::value && is_cx::yes), const mtOp >::result real(const T1& X) { arma_extra_debug_sigprint(); return mtOp( X ); } template inline const mtOpCube real(const BaseCube, T1>& X) { arma_extra_debug_sigprint(); return mtOpCube( X.get_ref() ); } template arma_inline const mtSpOp real(const SpBase,T1>& A) { arma_extra_debug_sigprint(); return mtSpOp(A.get_ref()); } // // imag template inline const Gen< Mat, gen_zeros > imag(const Base& X) { arma_extra_debug_sigprint(); const Proxy A(X.get_ref()); return Gen< Mat, gen_zeros>(A.get_n_rows(), A.get_n_cols()); } template inline const GenCube imag(const BaseCube& X) { arma_extra_debug_sigprint(); const ProxyCube A(X.get_ref()); return GenCube(A.get_n_rows(), A.get_n_cols(), A.get_n_slices()); } template inline SpMat imag(const SpBase& A) { arma_extra_debug_sigprint(); const SpProxy P(A.get_ref()); return SpMat(P.get_n_rows(), P.get_n_cols()); } template inline typename enable_if2< (is_arma_type::value && is_cx::yes), const mtOp >::result imag(const T1& X) { arma_extra_debug_sigprint(); return mtOp( X ); } template inline const mtOpCube imag(const BaseCube,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube( X.get_ref() ); } template arma_inline const mtSpOp imag(const SpBase,T1>& A) { arma_extra_debug_sigprint(); return mtSpOp(A.get_ref()); } // // log template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result log(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube log(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // log2 template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result log2(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube log2(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // log10 template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result log10(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube log10(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // exp template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result exp(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube exp(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // exp2 template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result exp2(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube exp2(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // exp10 template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result exp10(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube exp10(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // abs template arma_inline typename enable_if2< (is_arma_type::value && is_cx::no), const eOp >::result abs(const T1& X) { arma_extra_debug_sigprint(); return eOp(X); } template arma_inline const eOpCube abs(const BaseCube& X, const typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return eOpCube(X.get_ref()); } template inline typename enable_if2< (is_arma_type::value && is_cx::yes), const mtOp >::result abs(const T1& X) { arma_extra_debug_sigprint(); return mtOp(X); } template inline const mtOpCube abs(const BaseCube< std::complex,T1>& X, const typename arma_cx_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtOpCube( X.get_ref() ); } template arma_inline const SpOp abs(const SpBase& X, const typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return SpOp(X.get_ref()); } template arma_inline const mtSpOp abs(const SpBase< std::complex, T1>& X, const typename arma_cx_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return mtSpOp(X.get_ref()); } // // square template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result square(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube square(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } template arma_inline const SpOp square(const SpBase& A) { arma_extra_debug_sigprint(); return SpOp(A.get_ref()); } // // sqrt template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result sqrt(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube sqrt(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } template arma_inline const SpOp sqrt(const SpBase& A) { arma_extra_debug_sigprint(); return SpOp(A.get_ref()); } // // conj template arma_inline const T1& conj(const Base& A) { arma_extra_debug_sigprint(); return A.get_ref(); } template arma_inline const T1& conj(const BaseCube& A) { arma_extra_debug_sigprint(); return A.get_ref(); } template arma_inline const T1& conj(const SpBase& A) { arma_extra_debug_sigprint(); return A.get_ref(); } template arma_inline const eOp conj(const Base,T1>& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube conj(const BaseCube,T1>& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } template arma_inline const SpOp conj(const SpBase,T1>& A) { arma_extra_debug_sigprint(); return SpOp(A.get_ref()); } // pow template arma_inline const eOp pow(const Base& A, const typename T1::elem_type exponent) { arma_extra_debug_sigprint(); return eOp(A.get_ref(), exponent); } template arma_inline const eOpCube pow(const BaseCube& A, const typename T1::elem_type exponent) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref(), exponent); } // pow, specialised handling (non-complex exponent for complex matrices) template arma_inline const eOp pow(const Base& A, const typename T1::elem_type::value_type exponent) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; return eOp(A.get_ref(), eT(exponent)); } template arma_inline const eOpCube pow(const BaseCube& A, const typename T1::elem_type::value_type exponent) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; return eOpCube(A.get_ref(), eT(exponent)); } // // floor template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result floor(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube floor(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // ceil template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result ceil(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube ceil(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // round template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result round(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube round(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // trunc template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result trunc(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube trunc(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } // // sign template arma_inline typename enable_if2< is_arma_type::value, const eOp >::result sign(const T1& A) { arma_extra_debug_sigprint(); return eOp(A); } template arma_inline const eOpCube sign(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } //! @} armadillo-6.500.5/include/armadillo_bits/arma_forward.hpp0000666000000000000000000001763612627351654022152 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au using std::cout; using std::cerr; using std::endl; using std::ios; using std::size_t; template struct Base; template struct BaseCube; template class Mat; template class Col; template class Row; template class Cube; template class xvec_htrans; template class field; template class xtrans_mat; template class subview; template class subview_col; template class subview_row; template class subview_row_strans; template class subview_row_htrans; template class subview_cube; template class subview_field; template class SpValProxy; template class SpMat; template class SpCol; template class SpRow; template class SpSubview; template class diagview; template class spdiagview; template class subview_elem1; template class subview_elem2; template class subview_each1; template class subview_each2; template class subview_cube_each1; template class subview_cube_each2; class SizeMat; class SizeCube; class arma_empty_class {}; class diskio; class op_min; class op_max; class op_strans; class op_htrans; class op_htrans2; class op_inv; class op_sum; class op_abs; class op_diagmat; class op_trimat; class op_diagvec; class op_vectorise_col; class op_normalise_vec; class op_clamp; class op_cumsum_default; class op_cumprod_default; class op_shuffle; class op_shuffle_default; class op_sort; class op_sort_default; class op_find; class op_find_simple; class op_find_unique; class op_flipud; class op_fliplr; class op_real; class op_imag; class op_nonzeros; class op_sort_index; class op_stable_sort_index; class op_unique; class op_unique_index; class op_diff_default; class op_hist; class eop_conj; class glue_times; class glue_times_diag; class glue_conv; class glue_join_cols; class glue_join_rows; class glue_rel_lt; class glue_rel_gt; class glue_rel_lteq; class glue_rel_gteq; class glue_rel_eq; class glue_rel_noteq; class glue_rel_and; class glue_rel_or; class op_rel_lt_pre; class op_rel_lt_post; class op_rel_gt_pre; class op_rel_gt_post; class op_rel_lteq_pre; class op_rel_lteq_post; class op_rel_gteq_pre; class op_rel_gteq_post; class op_rel_eq; class op_rel_noteq; class gen_eye; class gen_ones; class gen_zeros; class gen_randu; class gen_randn; class glue_mixed_plus; class glue_mixed_minus; class glue_mixed_div; class glue_mixed_schur; class glue_mixed_times; class glue_hist; class glue_hist_default; class glue_histc; class glue_histc_default; class op_cx_scalar_times; class op_cx_scalar_plus; class op_cx_scalar_minus_pre; class op_cx_scalar_minus_post; class op_cx_scalar_div_pre; class op_cx_scalar_div_post; class op_internal_equ; class op_internal_plus; class op_internal_minus; class op_internal_schur; class op_internal_div; template class gemm; template class gemv; template< typename eT, typename gen_type> class Gen; template< typename T1, typename op_type> class Op; template< typename T1, typename eop_type> class eOp; template class mtOp; template< typename T1, typename T2, typename glue_type> class Glue; template< typename T1, typename T2, typename eglue_type> class eGlue; template class mtGlue; template< typename eT, typename gen_type> class GenCube; template< typename T1, typename op_type> class OpCube; template< typename T1, typename eop_type> class eOpCube; template class mtOpCube; template< typename T1, typename T2, typename glue_type> class GlueCube; template< typename T1, typename T2, typename eglue_type> class eGlueCube; template class mtGlueCube; template class Proxy; template class ProxyCube; class spop_strans; class spop_htrans; class spop_scalar_times; class spglue_plus; class spglue_plus2; class spglue_minus; class spglue_minus2; class spglue_times; class spglue_times2; template< typename T1, typename spop_type> class SpOp; template class mtSpOp; template class SpGlue; template class SpProxy; struct arma_vec_indicator {}; struct arma_fixed_indicator {}; //! \addtogroup injector //! @{ template struct injector_end_of_row {}; static const injector_end_of_row<> endr = injector_end_of_row<>(); //!< endr indicates "end of row" when using the << operator; //!< similar conceptual meaning to std::endl //! @} //! \addtogroup diskio //! @{ enum file_type { file_type_unknown, auto_detect, //!< Automatically detect the file type raw_ascii, //!< ASCII format (text), without any other information. arma_ascii, //!< Armadillo ASCII format (text), with information about matrix type and size csv_ascii, //!< comma separated values (CSV), without any other information raw_binary, //!< raw binary format, without any other information. arma_binary, //!< Armadillo binary format, with information about matrix type and size pgm_binary, //!< Portable Grey Map (greyscale image) ppm_binary, //!< Portable Pixel Map (colour image), used by the field and cube classes hdf5_binary, //!< Open binary format, not specific to Armadillo, which can store arbitrary data coord_ascii //!< simple co-ordinate format for sparse matrices }; //! @} //! \addtogroup fill //! @{ namespace fill { struct fill_none {}; struct fill_zeros {}; struct fill_ones {}; struct fill_eye {}; struct fill_randu {}; struct fill_randn {}; template struct fill_class { inline fill_class() {} }; static const fill_class none; static const fill_class zeros; static const fill_class ones; static const fill_class eye; static const fill_class randu; static const fill_class randn; } //! @} //! \addtogroup fn_spsolve //! @{ struct spsolve_opts_base { const unsigned int id; inline spsolve_opts_base(const unsigned int in_id) : id(in_id) {} }; struct spsolve_opts_none : public spsolve_opts_base { inline spsolve_opts_none() : spsolve_opts_base(0) {} }; struct superlu_opts : public spsolve_opts_base { typedef enum {NATURAL, MMD_ATA, MMD_AT_PLUS_A, COLAMD} permutation_type; typedef enum {REF_NONE, REF_SINGLE, REF_DOUBLE, REF_EXTRA} refine_type; bool equilibrate; bool symmetric; double pivot_thresh; permutation_type permutation; refine_type refine; inline superlu_opts() : spsolve_opts_base(1) { equilibrate = false; symmetric = false; pivot_thresh = 1.0; permutation = COLAMD; refine = REF_DOUBLE; } }; //! @} armadillo-6.500.5/include/armadillo_bits/operator_schur.hpp0000666000000000000000000001700712620272703022523 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup operator_schur //! @{ // operator %, which we define it to do a schur product (element-wise multiplication) //! element-wise multiplication of user-accessible Armadillo objects with same element type template arma_inline typename enable_if2 < is_arma_type::value && is_arma_type::value && is_same_type::value, const eGlue >::result operator% ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); return eGlue(X, Y); } //! element-wise multiplication of user-accessible Armadillo objects with different element types template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_same_type::no)), const mtGlue::result, T1, T2, glue_mixed_schur> >::result operator% ( const T1& X, const T2& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlue( X, Y ); } //! element-wise multiplication of two sparse matrices template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_sparse_type::value && is_same_type::value), SpMat >::result operator% ( const SpBase& x, const SpBase& y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(x.get_ref()); const SpProxy pb(y.get_ref()); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "element-wise multiplication"); SpMat result(pa.get_n_rows(), pa.get_n_cols()); if( (pa.get_n_nonzero() != 0) && (pb.get_n_nonzero() != 0) ) { // Resize memory to correct size. result.mem_resize(n_unique(x, y, op_n_unique_mul())); // Now iterate across both matrices. typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type x_end = pa.end(); typename SpProxy::const_iterator_type y_end = pb.end(); uword cur_val = 0; while((x_it != x_end) || (y_it != y_end)) { if(x_it == y_it) { const eT val = (*x_it) * (*y_it); if (val != eT(0)) { access::rw(result.values[cur_val]) = val; access::rw(result.row_indices[cur_val]) = x_it.row(); ++access::rw(result.col_ptrs[x_it.col() + 1]); ++cur_val; } ++x_it; ++y_it; } else { const uword x_it_row = x_it.row(); const uword x_it_col = x_it.col(); const uword y_it_row = y_it.row(); const uword y_it_col = y_it.col(); if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end { ++x_it; } else { ++y_it; } } } // Fix column pointers to be cumulative. for(uword c = 1; c <= result.n_cols; ++c) { access::rw(result.col_ptrs[c]) += result.col_ptrs[c - 1]; } } return result; } //! element-wise multiplication of one dense and one sparse object template inline typename enable_if2 < (is_arma_type::value && is_arma_sparse_type::value && is_same_type::value), SpMat >::result operator% ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy pa(x); const SpProxy pb(y); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "element-wise multiplication"); SpMat result(pa.get_n_rows(), pa.get_n_cols()); // count new size uword new_n_nonzero = 0; typename SpProxy::const_iterator_type it = pb.begin(); typename SpProxy::const_iterator_type it_end = pb.end(); while(it != it_end) { if( ((*it) * pa.at(it.row(), it.col())) != eT(0) ) { ++new_n_nonzero; } ++it; } // Resize memory accordingly. result.mem_resize(new_n_nonzero); uword cur_val = 0; typename SpProxy::const_iterator_type it2 = pb.begin(); while(it2 != it_end) { const uword it2_row = it2.row(); const uword it2_col = it2.col(); const eT val = (*it2) * pa.at(it2_row, it2_col); if(val != eT(0)) { access::rw(result.values[cur_val]) = val; access::rw(result.row_indices[cur_val]) = it2_row; ++access::rw(result.col_ptrs[it2_col + 1]); ++cur_val; } ++it2; } // Fix column pointers. for(uword c = 1; c <= result.n_cols; ++c) { access::rw(result.col_ptrs[c]) += result.col_ptrs[c - 1]; } return result; } //! element-wise multiplication of one sparse and one dense object template inline typename enable_if2 < (is_arma_sparse_type::value && is_arma_type::value && is_same_type::value), SpMat >::result operator% ( const T1& x, const T2& y ) { arma_extra_debug_sigprint(); // This operation is commutative. return (y % x); } template inline Mat operator% ( const subview_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_each1_aux::operator_schur(X, Y.get_ref()); } template arma_inline Mat operator% ( const Base& X, const subview_each1& Y ) { arma_extra_debug_sigprint(); return subview_each1_aux::operator_schur(Y, X.get_ref()); // NOTE: swapped order } template inline Mat operator% ( const subview_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_each2_aux::operator_schur(X, Y.get_ref()); } template arma_inline Mat operator% ( const Base& X, const subview_each2& Y ) { arma_extra_debug_sigprint(); return subview_each2_aux::operator_schur(Y, X.get_ref()); // NOTE: swapped order } //! @} armadillo-6.500.5/include/armadillo_bits/fn_histc.hpp0000666000000000000000000000246412620272703021262 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_histc //! @{ template arma_inline typename enable_if2 < (is_arma_type::value) && (is_arma_type::value) && (is_not_complex::value) && (is_same_type::value), const mtGlue >::result histc(const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue(X, Y); } template arma_inline typename enable_if2 < (is_arma_type::value) && (is_arma_type::value) && (is_not_complex::value) && (is_same_type::value), const mtGlue >::result histc(const T1& X, const T2& Y, const uword dim) { arma_extra_debug_sigprint(); return mtGlue(X, Y, dim); } //! @} armadillo-6.500.5/include/armadillo_bits/op_cumprod_bones.hpp0000666000000000000000000000156412620272703023022 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_cumprod //! @{ class op_cumprod { public: template inline static void apply_noalias(Mat& out, const Mat& X, const uword dim); template inline static void apply(Mat& out, const Op& in); }; class op_cumprod_default { public: template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_diff.hpp0000666000000000000000000000171612620272703021057 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_diff //! @{ template arma_inline typename enable_if2 < is_arma_type::value, const Op >::result diff ( const T1& X, const uword k = 1 ) { arma_extra_debug_sigprint(); return Op(X, k, 0); } template arma_inline typename enable_if2 < is_arma_type::value, const Op >::result diff ( const T1& X, const uword k, const uword dim ) { arma_extra_debug_sigprint(); return Op(X, k, dim); } //! @} armadillo-6.500.5/include/armadillo_bits/SpSubview_iterators_meat.hpp0000666000000000000000000006016712620272703024522 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup SpSubview //! @{ /////////////////////////////////////////////////////////////////////////////// // SpSubview::iterator_base implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpSubview::iterator_base::iterator_base(const SpSubview& in_M) : M(in_M) , internal_col(0) , internal_pos(0) , skip_pos(0) { // Technically this iterator is invalid (it may not point to a real element). } template inline SpSubview::iterator_base::iterator_base(const SpSubview& in_M, const uword in_col, const uword in_pos, const uword in_skip_pos) : M(in_M) , internal_col(in_col) , internal_pos(in_pos) , skip_pos (in_skip_pos) { // Nothing to do. } template inline eT SpSubview::iterator_base::operator*() const { return M.m.values[internal_pos + skip_pos]; } /////////////////////////////////////////////////////////////////////////////// // SpSubview::const_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpSubview::const_iterator::const_iterator(const SpSubview& in_M, const uword initial_pos) : iterator_base(in_M, 0, initial_pos, 0) { // Corner case for empty subviews. if(in_M.n_nonzero == 0) { iterator_base::internal_col = in_M.n_cols; iterator_base::skip_pos = in_M.m.n_nonzero; return; } // Figure out the row and column of the position. // lskip_pos holds the number of values which aren't part of this subview. const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_rows = iterator_base::M.n_rows; const uword ln_cols = iterator_base::M.n_cols; uword cur_pos = 0; // off by one because we might be searching for pos 0 uword lskip_pos = iterator_base::M.m.col_ptrs[aux_col]; uword cur_col = 0; while(cur_pos < (iterator_base::internal_pos + 1)) { // Have we stepped forward a column (or multiple columns)? while(((lskip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } // See if the current position is in the subview. const uword row_index = iterator_base::M.m.row_indices[cur_pos + lskip_pos]; if(row_index < aux_row) { ++lskip_pos; // not valid } else if(row_index < (aux_row + ln_rows)) { ++cur_pos; // valid, in the subview } else { // skip to end of column const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; lskip_pos += (next_colptr - (cur_pos + lskip_pos)); } } iterator_base::internal_col = cur_col; iterator_base::skip_pos = lskip_pos; } template inline SpSubview::const_iterator::const_iterator(const SpSubview& in_M, const uword in_row, const uword in_col) : iterator_base(in_M, in_col, 0, 0) { // Corner case for empty subviews. if(in_M.n_nonzero == 0) { // We must be at the last position. iterator_base::internal_col = in_M.n_cols; iterator_base::skip_pos = in_M.m.n_nonzero; return; } // We have a destination we want to be just after, but don't know what position that is. // Because we have to count the points in this subview and not in this subview, this becomes a little difficult and slow. const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_rows = iterator_base::M.n_rows; const uword ln_cols = iterator_base::M.n_cols; uword cur_pos = 0; uword skip_pos = iterator_base::M.m.col_ptrs[aux_col]; uword cur_col = 0; // Skip any empty columns. while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } while(cur_col < in_col) { // See if the current position is in the subview. const uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; if(row_index < aux_row) { ++skip_pos; } else if(row_index < (aux_row + ln_rows)) { ++cur_pos; } else { // skip to end of column const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; skip_pos += (next_colptr - (cur_pos + skip_pos)); } // Have we stepped forward a column (or multiple columns)? while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } } // Now we are either on the right column or ahead of it. if(cur_col == in_col) { // We have to find the right row index. uword row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; while((row_index < (in_row + aux_row))) { if(row_index < aux_row) { ++skip_pos; } else { ++cur_pos; } // Ensure we didn't step forward a column; if we did, we need to stop. while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } if(cur_col != in_col) { break; } row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; } } // Now we need to find the next valid position in the subview. uword row_index; while(true) { const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; // Are we at the last position? if(cur_col >= ln_cols) { cur_col = ln_cols; // Make sure we will be pointing at the last element in the parent matrix. skip_pos = iterator_base::M.m.n_nonzero - iterator_base::M.n_nonzero; break; } if(row_index < aux_row) { ++skip_pos; } else if(row_index < (aux_row + ln_rows)) { break; // found } else { skip_pos += (next_colptr - (cur_pos + skip_pos)); } // Did we move any columns? while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } } // It is possible we have moved another column. while(((skip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]) && (cur_col < ln_cols)) { ++cur_col; } iterator_base::internal_pos = cur_pos; iterator_base::skip_pos = skip_pos; iterator_base::internal_col = cur_col; } template inline SpSubview::const_iterator::const_iterator(const SpSubview& in_M, uword in_row, uword in_col, uword in_pos, uword in_skip_pos) : iterator_base(in_M, in_col, in_pos, in_skip_pos) { arma_ignore(in_row); // Nothing to do. } template inline SpSubview::const_iterator::const_iterator(const const_iterator& other) : iterator_base(other.M, other.internal_col, other.internal_pos, other.skip_pos) { // Nothing to do. } template inline typename SpSubview::const_iterator& SpSubview::const_iterator::operator++() { const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_rows = iterator_base::M.n_rows; const uword ln_cols = iterator_base::M.n_cols; uword cur_col = iterator_base::internal_col; uword cur_pos = iterator_base::internal_pos + 1; uword lskip_pos = iterator_base::skip_pos; uword row_index; while(true) { const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; row_index = iterator_base::M.m.row_indices[cur_pos + lskip_pos]; // Did we move any columns? while((cur_col < ln_cols) && ((lskip_pos + cur_pos) >= iterator_base::M.m.col_ptrs[cur_col + aux_col + 1])) { ++cur_col; } // Are we at the last position? if(cur_col >= ln_cols) { cur_col = ln_cols; // Make sure we will be pointing at the last element in the parent matrix. lskip_pos = iterator_base::M.m.n_nonzero - iterator_base::M.n_nonzero; break; } if(row_index < aux_row) { ++lskip_pos; } else if(row_index < (aux_row + ln_rows)) { break; // found } else { lskip_pos += (next_colptr - (cur_pos + lskip_pos)); } } iterator_base::internal_pos = cur_pos; iterator_base::internal_col = cur_col; iterator_base::skip_pos = lskip_pos; return *this; } template inline typename SpSubview::const_iterator SpSubview::const_iterator::operator++(int) { typename SpSubview::const_iterator tmp(*this); ++(*this); return tmp; } template inline typename SpSubview::const_iterator& SpSubview::const_iterator::operator--() { const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_rows = iterator_base::M.n_rows; uword cur_col = iterator_base::internal_col; uword cur_pos = iterator_base::internal_pos - 1; uword skip_pos = iterator_base::skip_pos; // Special condition for end of iterator. if((skip_pos + cur_pos + 1) == iterator_base::M.m.n_nonzero) { // We are at the last element. So we need to set skip_pos back to what it // would be if we didn't manually modify it back in operator++(). skip_pos = iterator_base::M.m.col_ptrs[cur_col + aux_col] - iterator_base::internal_pos; } uword row_index; while(true) { const uword colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col]; row_index = iterator_base::M.m.row_indices[cur_pos + skip_pos]; // Did we move back any columns? while((skip_pos + cur_pos) < iterator_base::M.m.col_ptrs[cur_col + aux_col]) { --cur_col; } if(row_index < aux_row) { skip_pos -= (colptr - (cur_pos + skip_pos) + 1); } else if(row_index < (aux_row + ln_rows)) { break; // found } else { --skip_pos; } } iterator_base::internal_pos = cur_pos; iterator_base::skip_pos = skip_pos; iterator_base::internal_col = cur_col; return *this; } template inline typename SpSubview::const_iterator SpSubview::const_iterator::operator--(int) { typename SpSubview::const_iterator tmp(*this); --(*this); return tmp; } template inline bool SpSubview::const_iterator::operator==(const const_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator!=(const const_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator==(const typename SpMat::const_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator!=(const typename SpMat::const_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator==(const const_row_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator!=(const const_row_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator==(const typename SpMat::const_row_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_iterator::operator!=(const typename SpMat::const_row_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } /////////////////////////////////////////////////////////////////////////////// // SpSubview::iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpValProxy > SpSubview::iterator::operator*() { return SpValProxy >( iterator_base::row(), iterator_base::col(), access::rw(iterator_base::M), &(access::rw(iterator_base::M.m.values[iterator_base::internal_pos + iterator_base::skip_pos]))); } template inline typename SpSubview::iterator& SpSubview::iterator::operator++() { const_iterator::operator++(); return *this; } template inline typename SpSubview::iterator SpSubview::iterator::operator++(int) { typename SpSubview::iterator tmp(*this); const_iterator::operator++(); return tmp; } template inline typename SpSubview::iterator& SpSubview::iterator::operator--() { const_iterator::operator--(); return *this; } template inline typename SpSubview::iterator SpSubview::iterator::operator--(int) { typename SpSubview::iterator tmp(*this); const_iterator::operator--(); return tmp; } /////////////////////////////////////////////////////////////////////////////// // SpSubview::const_row_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpSubview::const_row_iterator::const_row_iterator(const SpSubview& in_M, uword initial_pos) : iterator_base(in_M, 0, initial_pos, 0) , internal_row(0) , actual_pos(0) { // Corner case for empty subviews. if(in_M.n_nonzero == 0) { iterator_base::internal_col = 0; internal_row = in_M.n_rows; iterator_base::skip_pos = in_M.m.n_nonzero; return; } const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_cols = iterator_base::M.n_cols; // We don't know where the elements are in each row. What we will do is // loop across all valid columns looking for elements in row 0 (and add to // our sum), then in row 1, and so forth, until we get to the desired // position. uword cur_pos = -1; // TODO: HACK: -1 is not a valid unsigned integer; using -1 is relying on wraparound/overflow, which is not portable uword cur_row = 0; uword cur_col = 0; while(true) { // Is there anything in the column we are looking at? const uword colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col]; const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; for(uword ind = colptr; (ind < next_colptr) && (iterator_base::M.m.row_indices[ind] <= (cur_row + aux_row)); ++ind) { // There is something in this column. Is it in the row we are looking at? const uword row_index = iterator_base::M.m.row_indices[ind]; if(row_index == (cur_row + aux_row)) { // Yes, it is in the right row. if(++cur_pos == iterator_base::internal_pos) // TODO: HACK: if cur_pos is std::numeric_limits::max(), ++cur_pos relies on a wraparound/overflow, which is not portable { iterator_base::internal_col = cur_col; internal_row = cur_row; actual_pos = ind; return; } // We are done with this column. Break to the column incrementing code (directly below). break; } else if(row_index > (cur_row + aux_row)) { break; // Can't be in this column. } } cur_col++; // Done with the column. Move on. if(cur_col == ln_cols) { // Out of columns. Loop back to the beginning and look on the next row. cur_col = 0; cur_row++; } } } template inline SpSubview::const_row_iterator::const_row_iterator(const SpSubview& in_M, uword in_row, uword in_col) : iterator_base(in_M, in_col, 0, 0) , internal_row(0) , actual_pos(0) { // We have a destination we want to be just after, but don't know what that // position is. Because we will have to loop over everything anyway, create // another iterator and loop it until it is at the right place, then take its // information. const_row_iterator it(in_M, 0); while((it.row() < in_row) || ((it.row() == in_row) && (it.col() < in_col))) { ++it; } iterator_base::internal_col = it.col(); iterator_base::internal_pos = it.pos(); iterator_base::skip_pos = it.skip_pos; internal_row = it.internal_row; actual_pos = it.actual_pos; } template inline SpSubview::const_row_iterator::const_row_iterator(const const_row_iterator& other) : iterator_base(other.M, other.internal_col, other.internal_pos, other.skip_pos) , internal_row(other.internal_row) , actual_pos(other.actual_pos) { // Nothing to do. } template inline typename SpSubview::const_row_iterator& SpSubview::const_row_iterator::operator++() { // We just need to find the next nonzero element. ++iterator_base::internal_pos; // If we have exceeded the bounds, update accordingly. if(iterator_base::internal_pos >= iterator_base::M.n_nonzero) { internal_row = iterator_base::M.n_rows; iterator_base::internal_col = 0; actual_pos = iterator_base::M.m.n_nonzero; return *this; } // Otherwise, we need to search. uword cur_col = iterator_base::internal_col; uword cur_row = internal_row; const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_cols = iterator_base::M.n_cols; while(true) { // Increment the current column and see if we are on a new row. if(++cur_col == ln_cols) { cur_col = 0; ++cur_row; } // Is there anything in this new column? const uword colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col]; const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; for(uword ind = colptr; (ind < next_colptr) && (iterator_base::M.m.row_indices[ind] <= (cur_row + aux_row)); ++ind) { const uword row_index = iterator_base::M.m.row_indices[ind]; if((row_index - aux_row) == cur_row) { // We have successfully incremented. internal_row = cur_row; actual_pos = ind; iterator_base::internal_col = cur_col; return *this; } } } } template inline typename SpSubview::const_row_iterator SpSubview::const_row_iterator::operator++(int) { typename SpSubview::const_row_iterator tmp(*this); ++(*this); return tmp; } template inline typename SpSubview::const_row_iterator& SpSubview::const_row_iterator::operator--() { // We just need to find the previous element. // if(iterator_base::pos == 0) // { // // We cannot decrement. // return *this; // } // else if(iterator_base::pos == iterator_base::M.n_nonzero) // { // // We will be coming off the last element. We need to reset the row correctly, because we set row = 0 in the last matrix position. // iterator_base::row = iterator_base::M.n_rows - 1; // } // else if(iterator_base::pos > iterator_base::M.n_nonzero) // { // // This shouldn't happen... // iterator_base::pos--; // return *this; // } iterator_base::internal_pos--; // We have to search backwards. uword cur_col = iterator_base::internal_col; uword cur_row = internal_row; const uword aux_col = iterator_base::M.aux_col1; const uword aux_row = iterator_base::M.aux_row1; const uword ln_cols = iterator_base::M.n_cols; while(true) { // Decrement the current column and see if we are on a new row. if(--cur_col > ln_cols) { cur_col = ln_cols - 1; cur_row--; } // Is there anything in this new column? const uword colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col]; const uword next_colptr = iterator_base::M.m.col_ptrs[cur_col + aux_col + 1]; for(uword ind = colptr; (ind < next_colptr) && (iterator_base::M.m.row_indices[ind] <= (cur_row + aux_row)); ++ind) { const uword row_index = iterator_base::M.m.row_indices[ind]; if((row_index - aux_row) == cur_row) { iterator_base::internal_col = cur_col; internal_row = cur_row; actual_pos = ind; return *this; } } } } template inline typename SpSubview::const_row_iterator SpSubview::const_row_iterator::operator--(int) { typename SpSubview::const_row_iterator tmp(*this); --(*this); return tmp; } template inline bool SpSubview::const_row_iterator::operator==(const const_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator!=(const const_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator==(const typename SpMat::const_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator!=(const typename SpMat::const_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator==(const const_row_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator!=(const const_row_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator==(const typename SpMat::const_row_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline bool SpSubview::const_row_iterator::operator!=(const typename SpMat::const_row_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } /////////////////////////////////////////////////////////////////////////////// // SpSubview::row_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpValProxy > SpSubview::row_iterator::operator*() { return SpValProxy >( const_row_iterator::internal_row, iterator_base::internal_col, access::rw(iterator_base::M), &access::rw(iterator_base::M.m.values[const_row_iterator::actual_pos])); } template inline typename SpSubview::row_iterator& SpSubview::row_iterator::operator++() { const_row_iterator::operator++(); return *this; } template inline typename SpSubview::row_iterator SpSubview::row_iterator::operator++(int) { typename SpSubview::row_iterator tmp(*this); ++(*this); return tmp; } template inline typename SpSubview::row_iterator& SpSubview::row_iterator::operator--() { const_row_iterator::operator--(); return *this; } template inline typename SpSubview::row_iterator SpSubview::row_iterator::operator--(int) { typename SpSubview::row_iterator tmp(*this); --(*this); return tmp; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_diagmat.hpp0000666000000000000000000000336012620272703021552 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_diagmat //! @{ //! interpret a matrix or a vector as a diagonal matrix (i.e. off-diagonal entries are zero) template arma_inline typename enable_if2 < is_arma_type::value, const Op >::result diagmat(const T1& X) { arma_extra_debug_sigprint(); return Op(X); } //! create a matrix with the k-th diagonal set to the given vector template arma_inline typename enable_if2 < is_arma_type::value, const Op >::result diagmat(const T1& X, const sword k) { arma_extra_debug_sigprint(); const uword row_offset = (k < 0) ? uword(-k) : uword(0); const uword col_offset = (k > 0) ? uword( k) : uword(0); return Op(X, row_offset, col_offset); } template inline const SpOp diagmat(const SpBase& X) { arma_extra_debug_sigprint(); return SpOp(X.get_ref()); } template inline const SpOp diagmat(const SpBase& X, const sword k) { arma_extra_debug_sigprint(); const uword row_offset = (k < 0) ? uword(-k) : uword(0); const uword col_offset = (k > 0) ? uword( k) : uword(0); return SpOp(X.get_ref(), row_offset, col_offset); } //! @} armadillo-6.500.5/include/armadillo_bits/mul_gemm_mixed.hpp0000666000000000000000000002767412620272703022467 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup gemm_mixed //! @{ //! \brief //! Matrix multplication where the matrices have differing element types. //! Uses caching for speedup. //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) template class gemm_mixed_large { public: template arma_hot inline static void apply ( Mat& C, const Mat& A, const Mat& B, const out_eT alpha = out_eT(1), const out_eT beta = out_eT(0) ) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (do_trans_A == false) && (do_trans_B == false) ) { podarray tmp(A_n_cols); in_eT1* A_rowdata = tmp.memptr(); for(uword row_A=0; row_A < A_n_rows; ++row_A) { tmp.copy_row(A, row_A); for(uword col_B=0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(uword i=0; i < B_n_rows; ++i) { acc += upgrade_val::apply(A_rowdata[i]) * upgrade_val::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(row_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(row_A,col_B) = acc + beta*C.at(row_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(row_A,col_B) = alpha*acc + beta*C.at(row_A,col_B); } } } } else if( (do_trans_A == true) && (do_trans_B == false) ) { for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const in_eT1* A_coldata = A.colptr(col_A); for(uword col_B=0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(uword i=0; i < B_n_rows; ++i) { acc += upgrade_val::apply(A_coldata[i]) * upgrade_val::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,col_B) = acc + beta*C.at(col_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,col_B) = alpha*acc + beta*C.at(col_A,col_B); } } } } else if( (do_trans_A == false) && (do_trans_B == true) ) { Mat B_tmp; op_strans::apply_mat_noalias(B_tmp, B); gemm_mixed_large::apply(C, A, B_tmp, alpha, beta); } else if( (do_trans_A == true) && (do_trans_B == true) ) { // mat B_tmp = trans(B); // dgemm_arma::apply(C, A, B_tmp, alpha, beta); // By using the trans(A)*trans(B) = trans(B*A) equivalency, // transpose operations are not needed podarray tmp(B_n_cols); in_eT2* B_rowdata = tmp.memptr(); for(uword row_B=0; row_B < B_n_rows; ++row_B) { tmp.copy_row(B, row_B); for(uword col_A=0; col_A < A_n_cols; ++col_A) { const in_eT1* A_coldata = A.colptr(col_A); out_eT acc = out_eT(0); for(uword i=0; i < A_n_rows; ++i) { acc += upgrade_val::apply(B_rowdata[i]) * upgrade_val::apply(A_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,row_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,row_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,row_B) = acc + beta*C.at(col_A,row_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,row_B) = alpha*acc + beta*C.at(col_A,row_B); } } } } } }; //! Matrix multplication where the matrices have different element types. //! Simple version (no caching). //! Matrix 'C' is assumed to have been set to the correct size (i.e. taking into account transposes) template class gemm_mixed_small { public: template arma_hot inline static void apply ( Mat& C, const Mat& A, const Mat& B, const out_eT alpha = out_eT(1), const out_eT beta = out_eT(0) ) { arma_extra_debug_sigprint(); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; if( (do_trans_A == false) && (do_trans_B == false) ) { for(uword row_A = 0; row_A < A_n_rows; ++row_A) { for(uword col_B = 0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(uword i = 0; i < B_n_rows; ++i) { const out_eT val1 = upgrade_val::apply(A.at(row_A,i)); const out_eT val2 = upgrade_val::apply(B_coldata[i]); acc += val1 * val2; //acc += upgrade_val::apply(A.at(row_A,i)) * upgrade_val::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(row_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(row_A,col_B) = acc + beta*C.at(row_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(row_A,col_B) = alpha*acc + beta*C.at(row_A,col_B); } } } } else if( (do_trans_A == true) && (do_trans_B == false) ) { for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const in_eT1* A_coldata = A.colptr(col_A); for(uword col_B=0; col_B < B_n_cols; ++col_B) { const in_eT2* B_coldata = B.colptr(col_B); out_eT acc = out_eT(0); for(uword i=0; i < B_n_rows; ++i) { acc += upgrade_val::apply(A_coldata[i]) * upgrade_val::apply(B_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,col_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,col_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,col_B) = acc + beta*C.at(col_A,col_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,col_B) = alpha*acc + beta*C.at(col_A,col_B); } } } } else if( (do_trans_A == false) && (do_trans_B == true) ) { for(uword row_A = 0; row_A < A_n_rows; ++row_A) { for(uword row_B = 0; row_B < B_n_rows; ++row_B) { out_eT acc = out_eT(0); for(uword i = 0; i < B_n_cols; ++i) { acc += upgrade_val::apply(A.at(row_A,i)) * upgrade_val::apply(B.at(row_B,i)); } if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A,row_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(row_A,row_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(row_A,row_B) = acc + beta*C.at(row_A,row_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(row_A,row_B) = alpha*acc + beta*C.at(row_A,row_B); } } } } else if( (do_trans_A == true) && (do_trans_B == true) ) { for(uword row_B=0; row_B < B_n_rows; ++row_B) { for(uword col_A=0; col_A < A_n_cols; ++col_A) { const in_eT1* A_coldata = A.colptr(col_A); out_eT acc = out_eT(0); for(uword i=0; i < A_n_rows; ++i) { acc += upgrade_val::apply(B.at(row_B,i)) * upgrade_val::apply(A_coldata[i]); } if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A,row_B) = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C.at(col_A,row_B) = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A,row_B) = acc + beta*C.at(col_A,row_B); } else if( (use_alpha == true ) && (use_beta == true ) ) { C.at(col_A,row_B) = alpha*acc + beta*C.at(col_A,row_B); } } } } } }; //! \brief //! Matrix multplication where the matrices have differing element types. template class gemm_mixed { public: //! immediate multiplication of matrices A and B, storing the result in C template inline static void apply ( Mat& C, const Mat& A, const Mat& B, const out_eT alpha = out_eT(1), const out_eT beta = out_eT(0) ) { arma_extra_debug_sigprint(); Mat tmp_A; Mat tmp_B; const bool predo_trans_A = ( (do_trans_A == true) && (is_cx::yes) ); const bool predo_trans_B = ( (do_trans_B == true) && (is_cx::yes) ); if(do_trans_A) { op_htrans::apply_mat_noalias(tmp_A, A); } if(do_trans_B) { op_htrans::apply_mat_noalias(tmp_B, B); } const Mat& AA = (predo_trans_A == false) ? A : tmp_A; const Mat& BB = (predo_trans_B == false) ? B : tmp_B; if( (AA.n_elem <= 64u) && (BB.n_elem <= 64u) ) { gemm_mixed_small<((predo_trans_A) ? false : do_trans_A), ((predo_trans_B) ? false : do_trans_B), use_alpha, use_beta>::apply(C, AA, BB, alpha, beta); } else { gemm_mixed_large<((predo_trans_A) ? false : do_trans_A), ((predo_trans_B) ? false : do_trans_B), use_alpha, use_beta>::apply(C, AA, BB, alpha, beta); } } }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_prod.hpp0000666000000000000000000000510512620272703021107 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_prod //! @{ //! \brief //! Delayed product of elements of a matrix along a specified dimension (either rows or columns). //! The result is stored in a dense matrix that has either one column or one row. //! For dim = 0, find the sum of each column (i.e. traverse across rows) //! For dim = 1, find the sum of each row (i.e. traverse across columns) //! The default is dim = 0. //! NOTE: this function works differently than in Matlab/Octave. template arma_inline const Op prod ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op prod ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type prod ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_prod::prod( X ); } //! \brief //! Immediate 'product of all values' operation, //! invoked, for example, by: prod(prod(A)) template inline arma_warn_unused typename T1::elem_type prod(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("prod(): two consecutive prod() calls detected"); return op_prod::prod( in.m ); } template inline const Op, op_prod> prod(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op, op_prod>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & prod(const T& x) { return x; } //! @} armadillo-6.500.5/include/armadillo_bits/podarray_meat.hpp0000666000000000000000000001431412620272703022311 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup podarray //! @{ template arma_hot inline podarray::~podarray() { arma_extra_debug_sigprint_this(this); if(n_elem > podarray_prealloc_n_elem::val ) { memory::release( mem ); } } template inline podarray::podarray() : n_elem(0) , mem (0) { arma_extra_debug_sigprint_this(this); } template inline podarray::podarray(const podarray& x) : n_elem(x.n_elem) { arma_extra_debug_sigprint(); const uword x_n_elem = x.n_elem; init_cold(x_n_elem); arrayops::copy( memptr(), x.memptr(), x_n_elem ); } template inline const podarray& podarray::operator=(const podarray& x) { arma_extra_debug_sigprint(); if(this != &x) { const uword x_n_elem = x.n_elem; init_warm(x_n_elem); arrayops::copy( memptr(), x.memptr(), x_n_elem ); } return *this; } template arma_hot arma_inline podarray::podarray(const uword new_n_elem) : n_elem(new_n_elem) { arma_extra_debug_sigprint_this(this); init_cold(new_n_elem); } template arma_inline podarray::podarray(const eT* X, const uword new_n_elem) : n_elem(new_n_elem) { arma_extra_debug_sigprint_this(this); init_cold(new_n_elem); arrayops::copy( memptr(), X, new_n_elem ); } template template inline podarray::podarray(const Proxy& P) : n_elem(P.get_n_elem()) { arma_extra_debug_sigprint_this(this); const uword P_n_elem = P.get_n_elem(); init_cold(P_n_elem); eT* out_mem = (*this).memptr(); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j < P_n_elem; i+=2, j+=2) { const eT val_i = A[i]; const eT val_j = A[j]; out_mem[i] = val_i; out_mem[j] = val_j; } if(i < P_n_elem) { out_mem[i] = A[i]; } } else { const uword P_n_rows = P.get_n_rows(); const uword P_n_cols = P.get_n_cols(); if(P_n_rows != 1) { uword count = 0; for(uword col=0; col < P_n_cols; ++col) for(uword row=0; row < P_n_rows; ++row, ++count) { out_mem[count] = P.at(row,col); } } else { for(uword col=0; col < P_n_cols; ++col) { out_mem[col] = P.at(0,col); } } } } template arma_inline eT podarray::operator[] (const uword i) const { return mem[i]; } template arma_inline eT& podarray::operator[] (const uword i) { return access::rw(mem[i]); } template arma_inline eT podarray::operator() (const uword i) const { arma_debug_check( (i >= n_elem), "podarray::operator(): index out of bounds"); return mem[i]; } template arma_inline eT& podarray::operator() (const uword i) { arma_debug_check( (i >= n_elem), "podarray::operator(): index out of bounds"); return access::rw(mem[i]); } template inline void podarray::set_min_size(const uword min_n_elem) { arma_extra_debug_sigprint(); if(min_n_elem > n_elem) { init_warm(min_n_elem); } } template inline void podarray::set_size(const uword new_n_elem) { arma_extra_debug_sigprint(); init_warm(new_n_elem); } template inline void podarray::reset() { arma_extra_debug_sigprint(); init_warm(0); } template inline void podarray::fill(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_set(memptr(), val, n_elem); } template inline void podarray::zeros() { arma_extra_debug_sigprint(); arrayops::fill_zeros(memptr(), n_elem); } template inline void podarray::zeros(const uword new_n_elem) { arma_extra_debug_sigprint(); init_warm(new_n_elem); arrayops::fill_zeros(memptr(), n_elem); } template arma_inline eT* podarray::memptr() { return mem; } template arma_inline const eT* podarray::memptr() const { return mem; } template arma_hot inline void podarray::copy_row(const Mat& A, const uword row) { const uword cols = A.n_cols; // note: this function assumes that the podarray has been set to the correct size beforehand eT* out = memptr(); switch(cols) { default: { uword i,j; for(i=0, j=1; j < cols; i+=2, j+=2) { const eT tmp_i = A.at(row, i); const eT tmp_j = A.at(row, j); out[i] = tmp_i; out[j] = tmp_j; } if(i < cols) { out[i] = A.at(row, i); } } break; case 8: out[7] = A.at(row, 7); case 7: out[6] = A.at(row, 6); case 6: out[5] = A.at(row, 5); case 5: out[4] = A.at(row, 4); case 4: out[3] = A.at(row, 3); case 3: out[2] = A.at(row, 2); case 2: out[1] = A.at(row, 1); case 1: out[0] = A.at(row, 0); case 0: ; } } template arma_hot inline void podarray::init_cold(const uword new_n_elem) { arma_extra_debug_sigprint(); if(new_n_elem <= podarray_prealloc_n_elem::val ) { mem = mem_local; } else { mem = memory::acquire(new_n_elem); } } template inline void podarray::init_warm(const uword new_n_elem) { arma_extra_debug_sigprint(); if(n_elem == new_n_elem) { return; } if(n_elem > podarray_prealloc_n_elem::val ) { memory::release( mem ); } if(new_n_elem <= podarray_prealloc_n_elem::val ) { mem = mem_local; } else { mem = memory::acquire(new_n_elem); } access::rw(n_elem) = new_n_elem; } //! @} armadillo-6.500.5/include/armadillo_bits/SpGlue_bones.hpp0000666000000000000000000000261312620272703022046 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup SpGlue //! @{ template class SpGlue : public SpBase > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = ( (T1::is_row || T2::is_row) && is_spglue_elem::value ) || ( (is_spglue_times::value || is_spglue_times2::value) ? T1::is_row : false ); static const bool is_col = ( (T1::is_col || T2::is_col) && is_spglue_elem::value ) || ( (is_spglue_times::value || is_spglue_times2::value) ? T2::is_col : false ); arma_inline SpGlue(const T1& in_A, const T2& in_B); arma_inline SpGlue(const T1& in_A, const T2& in_B, const elem_type in_aux); arma_inline ~SpGlue(); const T1& A; //!< first operand const T2& B; //!< second operand elem_type aux; }; //! @} armadillo-6.500.5/include/armadillo_bits/op_resize_bones.hpp0000666000000000000000000000131512620272703022644 0ustar rootroot// Copyright (C) 2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_resize //! @{ class op_resize { public: template inline static void apply( Mat& out, const Op& in); template inline static void apply(Cube& out, const OpCube& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/SpBase_meat.hpp0000666000000000000000000001264712620272703021654 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup SpBase //! @{ template arma_inline const derived& SpBase::get_ref() const { return static_cast(*this); } template inline const SpOp SpBase::t() const { return SpOp( (*this).get_ref() ); } template inline const SpOp SpBase::ht() const { return SpOp( (*this).get_ref() ); } template inline const SpOp SpBase::st() const { return SpOp( (*this).get_ref() ); } template inline void SpBase::print(const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_print(extra_text); } template inline void SpBase::print(std::ostream& user_stream, const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_print(user_stream, extra_text); } template inline void SpBase::raw_print(const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_raw_print(extra_text); } template inline void SpBase::raw_print(std::ostream& user_stream, const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_raw_print(user_stream, extra_text); } template inline void SpBase::print_dense(const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_print_dense(extra_text); } template inline void SpBase::print_dense(std::ostream& user_stream, const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_print_dense(user_stream, extra_text); } template inline void SpBase::raw_print_dense(const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_raw_print_dense(extra_text); } template inline void SpBase::raw_print_dense(std::ostream& user_stream, const std::string extra_text) const { const unwrap_spmat tmp( (*this).get_ref() ); tmp.M.impl_raw_print_dense(user_stream, extra_text); } // // extra functions defined in SpBase_eval_SpMat template inline const derived& SpBase_eval_SpMat::eval() const { arma_extra_debug_sigprint(); return static_cast(*this); } // // extra functions defined in SpBase_eval_expr template inline SpMat SpBase_eval_expr::eval() const { arma_extra_debug_sigprint(); return SpMat( static_cast(*this) ); } template inline arma_warn_unused elem_type SpBase::min() const { return spop_min::min( (*this).get_ref() ); } template inline arma_warn_unused elem_type SpBase::max() const { return spop_max::max( (*this).get_ref() ); } template inline elem_type SpBase::min(uword& index_of_min_val) const { const SpProxy P( (*this).get_ref() ); return spop_min::min_with_index(P, index_of_min_val); } template inline elem_type SpBase::max(uword& index_of_max_val) const { const SpProxy P( (*this).get_ref() ); return spop_max::max_with_index(P, index_of_max_val); } template inline elem_type SpBase::min(uword& row_of_min_val, uword& col_of_min_val) const { const SpProxy P( (*this).get_ref() ); uword index; const elem_type val = spop_min::min_with_index(P, index); const uword local_n_rows = P.get_n_rows(); row_of_min_val = index % local_n_rows; col_of_min_val = index / local_n_rows; return val; } template inline elem_type SpBase::max(uword& row_of_max_val, uword& col_of_max_val) const { const SpProxy P( (*this).get_ref() ); uword index; const elem_type val = spop_max::max_with_index(P, index); const uword local_n_rows = P.get_n_rows(); row_of_max_val = index % local_n_rows; col_of_max_val = index / local_n_rows; return val; } //! @} armadillo-6.500.5/include/armadillo_bits/op_sort_index_meat.hpp0000666000000000000000000001377212620272703023353 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_sort_index //! @{ template inline bool arma_sort_index_helper(Mat& out, const Proxy& P, const uword sort_type, typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const uword n_elem = P.get_n_elem(); out.set_size(n_elem, 1); std::vector< arma_sort_index_packet > packet_vec(n_elem); if(Proxy::prefer_at_accessor == false) { for(uword i=0; i inline bool arma_sort_index_helper(Mat& out, const Proxy& P, const uword sort_type, typename arma_cx_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const uword n_elem = P.get_n_elem(); out.set_size(n_elem, 1); std::vector< arma_sort_index_packet > packet_vec(n_elem); if(Proxy::prefer_at_accessor == false) { for(uword i=0; i inline bool op_sort_index::apply_noalias(Mat& out, const Proxy& P, const uword sort_type) { arma_extra_debug_sigprint(); return arma_sort_index_helper(out, P, sort_type); } template inline void op_sort_index::apply(Mat& out, const mtOp& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); if(P.get_n_elem() == 0) { out.set_size(0,1); return; } const uword sort_type = in.aux_uword_a; bool all_non_nan = false; if(P.is_alias(out)) { Mat out2; all_non_nan = op_sort_index::apply_noalias(out2, P, sort_type); out.steal_mem(out2); } else { all_non_nan = op_sort_index::apply_noalias(out, P, sort_type); } arma_debug_check( (all_non_nan == false), "sort_index(): detected NaN" ); } template inline bool op_stable_sort_index::apply_noalias(Mat& out, const Proxy& P, const uword sort_type) { arma_extra_debug_sigprint(); return arma_sort_index_helper(out, P, sort_type); } template inline void op_stable_sort_index::apply(Mat& out, const mtOp& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); if(P.get_n_elem() == 0) { out.set_size(0,1); return; } const uword sort_type = in.aux_uword_a; bool all_non_nan = false; if(P.is_alias(out)) { Mat out2; all_non_nan = op_stable_sort_index::apply_noalias(out2, P, sort_type); out.steal_mem(out2); } else { all_non_nan = op_stable_sort_index::apply_noalias(out, P, sort_type); } arma_debug_check( (all_non_nan == false), "stable_sort_index(): detected NaN" ); } //! @} armadillo-6.500.5/include/armadillo_bits/arma_ostream_meat.hpp0000666000000000000000000004435612656371157023167 0ustar rootroot// Copyright (C) 2008-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup arma_ostream //! @{ inline arma_ostream_state::arma_ostream_state(const std::ostream& o) : orig_flags (o.flags()) , orig_precision(o.precision()) , orig_width (o.width()) , orig_fill (o.fill()) { } inline void arma_ostream_state::restore(std::ostream& o) const { o.flags (orig_flags); o.precision(orig_precision); o.width (orig_width); o.fill (orig_fill); } // // template inline std::streamsize arma_ostream::modify_stream(std::ostream& o, const eT* data, const uword n_elem) { o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.unsetf(ios::showpos); o.fill(' '); std::streamsize cell_width; bool use_layout_B = false; bool use_layout_C = false; bool use_layout_D = false; for(uword i=0; i 4) && (is_same_type::yes || is_same_type::yes) >::geq(val, eT(+10000000000)) ) || ( cond_rel< (sizeof(eT) > 4) && is_same_type::yes >::leq(val, eT(-10000000000)) ) ) { use_layout_D = true; break; } if( ( val >= eT(+100) ) || //( (is_signed::value == true) && (val <= eT(-100)) ) || //( (is_non_integral::value == true) && (val > eT(0)) && (val <= eT(+1e-4)) ) || //( (is_non_integral::value == true) && (is_signed::value == true) && (val < eT(0)) && (val >= eT(-1e-4)) ) ( cond_rel< is_signed::value >::leq(val, eT(-100)) ) || ( cond_rel< is_non_integral::value >::gt(val, eT(0)) && cond_rel< is_non_integral::value >::leq(val, eT(+1e-4)) ) || ( cond_rel< is_non_integral::value && is_signed::value >::lt(val, eT(0)) && cond_rel< is_non_integral::value && is_signed::value >::geq(val, eT(-1e-4)) ) ) { use_layout_C = true; break; } if( // (val >= eT(+10)) || ( (is_signed::value == true) && (val <= eT(-10)) ) (val >= eT(+10)) || ( cond_rel< is_signed::value >::leq(val, eT(-10)) ) ) { use_layout_B = true; } } if(use_layout_D) { o.setf(ios::scientific); o.setf(ios::right); o.unsetf(ios::fixed); o.precision(4); cell_width = 21; } else if(use_layout_C) { o.setf(ios::scientific); o.setf(ios::right); o.unsetf(ios::fixed); o.precision(4); cell_width = 13; } else if(use_layout_B) { o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(4); cell_width = 10; } else { o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(4); cell_width = 9; } return cell_width; } //! "better than nothing" settings for complex numbers template inline std::streamsize arma_ostream::modify_stream(std::ostream& o, const std::complex* data, const uword n_elem) { arma_ignore(data); arma_ignore(n_elem); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.fill(' '); o.setf(ios::scientific); o.setf(ios::showpos); o.setf(ios::right); o.unsetf(ios::fixed); std::streamsize cell_width; o.precision(3); cell_width = 2 + 2*(1 + 3 + o.precision() + 5) + 1; return cell_width; } template inline std::streamsize arma_ostream::modify_stream(std::ostream& o, typename SpMat::const_iterator begin, const uword n_elem, const typename arma_not_cx::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.unsetf(ios::showpos); o.fill(' '); std::streamsize cell_width; bool use_layout_B = false; bool use_layout_C = false; for(typename SpMat::const_iterator it = begin; it.pos() < n_elem; ++it) { const eT val = *it; if( val >= eT(+100) || ( (is_signed::value == true) && (val <= eT(-100)) ) || ( (is_non_integral::value == true) && (val > eT(0)) && (val <= eT(+1e-4)) ) || ( (is_non_integral::value == true) && (is_signed::value == true) && (val < eT(0)) && (val >= eT(-1e-4)) ) ) { use_layout_C = true; break; } if( (val >= eT(+10)) || ( (is_signed::value == true) && (val <= eT(-10)) ) ) { use_layout_B = true; } } if(use_layout_C) { o.setf(ios::scientific); o.setf(ios::right); o.unsetf(ios::fixed); o.precision(4); cell_width = 13; } else if(use_layout_B) { o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(4); cell_width = 10; } else { o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(4); cell_width = 9; } return cell_width; } //! "better than nothing" settings for complex numbers template inline std::streamsize arma_ostream::modify_stream(std::ostream& o, typename SpMat::const_iterator begin, const uword n_elem, const typename arma_cx_only::result* junk) { arma_ignore(begin); arma_ignore(n_elem); arma_ignore(junk); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.fill(' '); o.setf(ios::scientific); o.setf(ios::showpos); o.setf(ios::right); o.unsetf(ios::fixed); std::streamsize cell_width; o.precision(3); cell_width = 2 + 2*(1 + 3 + o.precision() + 5) + 1; return cell_width; } template inline void arma_ostream::print_elem_zero(std::ostream& o, const bool modify) { if(modify == true) { const ios::fmtflags save_flags = o.flags(); const std::streamsize save_precision = o.precision(); o.unsetf(ios::scientific); o.setf(ios::fixed); o.precision(0); o << eT(0); o.flags(save_flags); o.precision(save_precision); } else { o << eT(0); } } //! Print an element to the specified stream template arma_inline void arma_ostream::print_elem(std::ostream& o, const eT& x, const bool modify) { if(is_signed::value) { typedef typename promote_type::result promoted_eT; if(x != eT(0)) { if(arma_isfinite(x)) { o << promoted_eT(x); } else { o << ( arma_isinf(x) ? ((x <= eT(0)) ? "-inf" : "inf") : "nan" ); } } else { arma_ostream::print_elem_zero(o, modify); } } else { typedef typename promote_type::result promoted_eT; if(x != eT(0)) { o << promoted_eT(x); } else { arma_ostream::print_elem_zero(o, modify); } } } //! Print a complex element to the specified stream template inline void arma_ostream::print_elem(std::ostream& o, const std::complex& x, const bool modify) { if( (x.real() != T(0)) || (x.imag() != T(0)) || (modify == false) ) { std::ostringstream ss; ss.flags(o.flags()); //ss.imbue(o.getloc()); ss.precision(o.precision()); ss << '('; const T a = x.real(); if(arma_isfinite(a)) { ss << a; } else { ss << ( arma_isinf(a) ? ((a <= T(0)) ? "-inf" : "+inf") : "nan" ); } ss << ','; const T b = x.imag(); if(arma_isfinite(b)) { ss << b; } else { ss << ( arma_isinf(b) ? ((b <= T(0)) ? "-inf" : "+inf") : "nan" ); } ss << ')'; o << ss.str(); } else { o << "(0,0)"; } } //! Print a matrix to the specified stream template inline void arma_ostream::print(std::ostream& o, const Mat& m, const bool modify) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, m.memptr(), m.n_elem) : o.width(); const uword m_n_rows = m.n_rows; const uword m_n_cols = m.n_cols; if(m.is_empty() == false) { if(m_n_cols > 0) { if(cell_width > 0) { for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols; ++col) { // the cell width appears to be reset after each element is printed, // hence we need to restore it o.width(cell_width); arma_ostream::print_elem(o, m.at(row,col), modify); } o << '\n'; } } else { for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols-1; ++col) { arma_ostream::print_elem(o, m.at(row,col), modify); o << ' '; } arma_ostream::print_elem(o, m.at(row, m_n_cols-1), modify); o << '\n'; } } } } else { o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n"; } o.flush(); stream_state.restore(o); } //! Print a cube to the specified stream template inline void arma_ostream::print(std::ostream& o, const Cube& x, const bool modify) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, x.memptr(), x.n_elem) : o.width(); if(x.is_empty() == false) { for(uword slice=0; slice < x.n_slices; ++slice) { const Mat tmp(const_cast(x.slice_memptr(slice)), x.n_rows, x.n_cols, false); o << "[cube slice " << slice << ']' << '\n'; o.width(cell_width); arma_ostream::print(o, tmp, false); o << '\n'; } } else { o << "[cube size: " << x.n_rows << 'x' << x.n_cols << 'x' << x.n_slices << "]\n"; } stream_state.restore(o); } //! Print a field to the specified stream //! Assumes type oT can be printed, i.e. oT has std::ostream& operator<< (std::ostream&, const oT&) template inline void arma_ostream::print(std::ostream& o, const field& x) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const std::streamsize cell_width = o.width(); const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; const uword x_n_slices = x.n_slices; if(x.is_empty() == false) { if(x_n_slices == 1) { for(uword col=0; col inline void arma_ostream::print(std::ostream& o, const subview_field& x) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const std::streamsize cell_width = o.width(); const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; const uword x_n_slices = x.n_slices; if(x_n_slices == 1) { for(uword col=0; col inline void arma_ostream::print_dense(std::ostream& o, const SpMat& m, const bool modify) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); const uword m_n_rows = m.n_rows; const uword m_n_cols = m.n_cols; if(m.n_nonzero > 0) { const std::streamsize cell_width = modify ? modify_stream(o, m.begin(), m.n_nonzero) : o.width(); typename SpMat::const_iterator begin = m.begin(); if(m_n_cols > 0) { if(cell_width > 0) { // An efficient row_iterator would make this simpler and faster for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols; ++col) { // the cell width appears to be reset after each element is printed, // hence we need to restore it o.width(cell_width); eT val = eT(0); for(typename SpMat::const_iterator it = begin; it.pos() < m.n_nonzero; ++it) { if(it.row() == row && it.col() == col) { val = *it; break; } } arma_ostream::print_elem(o,eT(val), modify); } o << '\n'; } } else { // An efficient row_iterator would make this simpler and faster for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols; ++col) { eT val = eT(0); for(typename SpMat::const_iterator it = begin; it.pos() < m.n_nonzero; ++it) { if(it.row() == row && it.col() == col) { val = *it; break; } } arma_ostream::print_elem(o,eT(val), modify); o << ' '; } o << '\n'; } } } } else { if(m.n_elem == 0) { o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n"; } else { eT tmp[1]; tmp[0] = eT(0); const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, &tmp[0], 1) : o.width(); for(uword row=0; row < m_n_rows; ++row) { for(uword col=0; col < m_n_cols; ++col) { o.width(cell_width); arma_ostream::print_elem_zero(o, modify); o << ' '; } o << '\n'; } } } o.flush(); stream_state.restore(o); } template inline void arma_ostream::print(std::ostream& o, const SpMat& m, const bool modify) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.unsetf(ios::showpos); o.unsetf(ios::scientific); o.setf(ios::right); o.setf(ios::fixed); o.precision(2); const uword m_n_nonzero = m.n_nonzero; o << "[matrix size: " << m.n_rows << 'x' << m.n_cols << "; n_nonzero: " << m_n_nonzero << "; density: " << ((m.n_elem > 0) ? (double(m_n_nonzero) / double(m.n_elem) * double(100)) : double(0)) << "%]\n\n"; if(modify == false) { stream_state.restore(o); } if(m_n_nonzero > 0) { const std::streamsize cell_width = modify ? modify_stream(o, m.begin(), m_n_nonzero) : o.width(); typename SpMat::const_iterator begin = m.begin(); typename SpMat::const_iterator m_end = m.end(); while(begin != m_end) { const uword row = begin.row(); // TODO: change the maximum number of spaces before and after each location to be dependent on n_rows and n_cols if(row < 10) { o << " "; } else if(row < 100) { o << " "; } else if(row < 1000) { o << " "; } else if(row < 10000) { o << " "; } else if(row < 100000) { o << ' '; } const uword col = begin.col(); o << '(' << row << ", " << col << ") "; if(col < 10) { o << " "; } else if(col < 100) { o << " "; } else if(col < 1000) { o << " "; } else if(col < 10000) { o << " "; } else if(col < 100000) { o << ' '; } if(cell_width > 0) { o.width(cell_width); } arma_ostream::print_elem(o, eT(*begin), modify); o << '\n'; ++begin; } o << '\n'; } o.flush(); stream_state.restore(o); } inline void arma_ostream::print(std::ostream& o, const SizeMat& S) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.unsetf(ios::showpos); o.setf(ios::fixed); o << S.n_rows << 'x' << S.n_cols; stream_state.restore(o); } inline void arma_ostream::print(std::ostream& o, const SizeCube& S) { arma_extra_debug_sigprint(); const arma_ostream_state stream_state(o); o.unsetf(ios::showbase); o.unsetf(ios::uppercase); o.unsetf(ios::showpos); o.setf(ios::fixed); o << S.n_rows << 'x' << S.n_cols << 'x' << S.n_slices; stream_state.restore(o); } //! @} armadillo-6.500.5/include/armadillo_bits/Base_meat.hpp0000666000000000000000000001534312627477235021363 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Base //! @{ template arma_inline const derived& Base::get_ref() const { return static_cast(*this); } template inline void Base::print(const std::string extra_text) const { if(is_op_strans::value || is_op_htrans::value) { const Proxy P( (*this).get_ref() ); const quasi_unwrap< typename Proxy::stored_type > tmp(P.Q); tmp.M.impl_print(extra_text); } else { const quasi_unwrap tmp( (*this).get_ref() ); tmp.M.impl_print(extra_text); } } template inline void Base::print(std::ostream& user_stream, const std::string extra_text) const { if(is_op_strans::value || is_op_htrans::value) { const Proxy P( (*this).get_ref() ); const quasi_unwrap< typename Proxy::stored_type > tmp(P.Q); tmp.M.impl_print(user_stream, extra_text); } else { const quasi_unwrap tmp( (*this).get_ref() ); tmp.M.impl_print(user_stream, extra_text); } } template inline void Base::raw_print(const std::string extra_text) const { if(is_op_strans::value || is_op_htrans::value) { const Proxy P( (*this).get_ref() ); const quasi_unwrap< typename Proxy::stored_type > tmp(P.Q); tmp.M.impl_raw_print(extra_text); } else { const quasi_unwrap tmp( (*this).get_ref() ); tmp.M.impl_raw_print(extra_text); } } template inline void Base::raw_print(std::ostream& user_stream, const std::string extra_text) const { if(is_op_strans::value || is_op_htrans::value) { const Proxy P( (*this).get_ref() ); const quasi_unwrap< typename Proxy::stored_type > tmp(P.Q); tmp.M.impl_raw_print(user_stream, extra_text); } else { const quasi_unwrap tmp( (*this).get_ref() ); tmp.M.impl_raw_print(user_stream, extra_text); } } template inline arma_warn_unused elem_type Base::min() const { return op_min::min( (*this).get_ref() ); } template inline arma_warn_unused elem_type Base::max() const { return op_max::max( (*this).get_ref() ); } template inline elem_type Base::min(uword& index_of_min_val) const { const Proxy P( (*this).get_ref() ); return op_min::min_with_index(P, index_of_min_val); } template inline elem_type Base::max(uword& index_of_max_val) const { const Proxy P( (*this).get_ref() ); return op_max::max_with_index(P, index_of_max_val); } template inline elem_type Base::min(uword& row_of_min_val, uword& col_of_min_val) const { const Proxy P( (*this).get_ref() ); uword index; const elem_type val = op_min::min_with_index(P, index); const uword local_n_rows = P.get_n_rows(); row_of_min_val = index % local_n_rows; col_of_min_val = index / local_n_rows; return val; } template inline elem_type Base::max(uword& row_of_max_val, uword& col_of_max_val) const { const Proxy P( (*this).get_ref() ); uword index; const elem_type val = op_max::max_with_index(P, index); const uword local_n_rows = P.get_n_rows(); row_of_max_val = index % local_n_rows; col_of_max_val = index / local_n_rows; return val; } // // extra functions defined in Base_inv_yes template arma_inline const Op Base_inv_yes::i() const { return Op(static_cast(*this)); } template arma_inline const Op Base_inv_yes::i(const bool) const // argument kept only for compatibility with old user code { return Op(static_cast(*this)); } template arma_inline const Op Base_inv_yes::i(const char*) const // argument kept only for compatibility with old user code { return Op(static_cast(*this)); } // // extra functions defined in Base_eval_Mat template arma_inline const derived& Base_eval_Mat::eval() const { arma_extra_debug_sigprint(); return static_cast(*this); } // // extra functions defined in Base_eval_expr template arma_inline Mat Base_eval_expr::eval() const { arma_extra_debug_sigprint(); return Mat( static_cast(*this) ); } // // extra functions defined in Base_trans_cx template arma_inline const Op Base_trans_cx::t() const { return Op( static_cast(*this) ); } template arma_inline const Op Base_trans_cx::ht() const { return Op( static_cast(*this) ); } template arma_inline const Op Base_trans_cx::st() const { return Op( static_cast(*this) ); } // // extra functions defined in Base_trans_default template arma_inline const Op Base_trans_default::t() const { return Op( static_cast(*this) ); } template arma_inline const Op Base_trans_default::ht() const { return Op( static_cast(*this) ); } template arma_inline const Op Base_trans_default::st() const { return Op( static_cast(*this) ); } //! @} armadillo-6.500.5/include/armadillo_bits/SpValProxy_bones.hpp0000666000000000000000000000422212620272703022734 0ustar rootroot// Copyright (C) 2011-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup SpValProxy //! @{ /** * Sparse value proxy class, meant to prevent 0s from being added to sparse * matrices. T1 should be either SpMat or SpSubview, and if it's not, bad news * is probably coming. This class only uses T1::add_element() and * T1::delete_element(). */ template class SpValProxy { public: typedef typename T1::elem_type eT; // Convenience typedef friend class SpMat; friend class SpSubview; /** * Create the sparse value proxy. * Otherwise, pass a pointer to a reference of the value. */ arma_inline SpValProxy(uword row, uword col, T1& in_parent, eT* in_val_ptr = NULL); //! For swapping operations. arma_inline SpValProxy& operator=(const SpValProxy& rhs); template arma_inline SpValProxy& operator=(const SpValProxy& rhs); //! Overload all of the potential operators. //! First, the ones that could modify a value. arma_inline SpValProxy& operator=(const eT rhs); arma_inline SpValProxy& operator+=(const eT rhs); arma_inline SpValProxy& operator-=(const eT rhs); arma_inline SpValProxy& operator*=(const eT rhs); arma_inline SpValProxy& operator/=(const eT rhs); arma_inline SpValProxy& operator++(); arma_inline SpValProxy& operator--(); arma_inline eT operator++(const int); arma_inline eT operator--(const int); //! This will work for any other operations that do not modify a value. arma_inline operator eT() const; private: // Deletes the element if it is zero. Does not check if val_ptr == NULL! arma_inline arma_hot void check_zero(); uword row; uword col; eT* val_ptr; T1& parent; // We will call this object if we need to insert or delete an element. }; //! @} armadillo-6.500.5/include/armadillo_bits/spop_diagmat_meat.hpp0000666000000000000000000001140312620272703023133 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spop_diagmat //! @{ template inline void spop_diagmat::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy p(in.m); if(p.is_alias(out) == false) { spop_diagmat::apply_noalias(out, p); } else { SpMat tmp; spop_diagmat::apply_noalias(tmp, p); out.steal_mem(tmp); } } template inline void spop_diagmat::apply_noalias(SpMat& out, const SpProxy& p) { arma_extra_debug_sigprint(); const uword n_rows = p.get_n_rows(); const uword n_cols = p.get_n_cols(); const bool p_is_vec = (n_rows == 1) || (n_cols == 1); if(p_is_vec) // generate a diagonal matrix out of a vector { const uword N = (n_rows == 1) ? n_cols : n_rows; out.zeros(N, N); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); if(n_cols == 1) { while(it != it_end) { const uword row = it.row(); out.at(row,row) = (*it); ++it; } } else if(n_rows == 1) { while(it != it_end) { const uword col = it.col(); out.at(col,col) = (*it); ++it; } } } else // generate a diagonal matrix out of a matrix { out.zeros(n_rows, n_cols); if(p.get_n_nonzero() == 0) { return; } typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { const uword row = it.row(); const uword col = it.col(); if(row == col) { out.at(row,row) = (*it); } ++it; } } } template inline void spop_diagmat2::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword row_offset = in.aux_uword_a; const uword col_offset = in.aux_uword_b; const unwrap_spmat U(in.m); if(&(U.M) == &out) { SpMat tmp; spop_diagmat2::apply_noalias(tmp, U.M, row_offset, col_offset); out.steal_mem(tmp); } else { spop_diagmat2::apply_noalias(out, U.M, row_offset, col_offset); } } template inline void spop_diagmat2::apply_noalias(SpMat& out, const SpMat& X, const uword row_offset, const uword col_offset) { arma_extra_debug_sigprint(); const uword n_rows = X.n_rows; const uword n_cols = X.n_cols; const uword n_elem = X.n_elem; if(n_elem == 0) { out.reset(); return; } const bool X_is_vec = (n_rows == 1) || (n_cols == 1); if(X_is_vec) // generate a diagonal matrix out of a vector { const uword n_pad = (std::max)(row_offset, col_offset); out.zeros(n_elem + n_pad, n_elem + n_pad); if(X.n_nonzero == 0) { return; } typename SpMat::const_iterator it = X.begin(); typename SpMat::const_iterator it_end = X.end(); if(n_cols == 1) { while(it != it_end) { const uword row = it.row(); out.at(row_offset + row, col_offset + row) = (*it); ++it; } } else if(n_rows == 1) { while(it != it_end) { const uword col = it.col(); out.at(row_offset + col, col_offset + col) = (*it); ++it; } } } else // generate a diagonal matrix out of a matrix { arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "diagmat(): requested diagonal out of bounds" ); out.zeros(n_rows, n_cols); if(X.n_nonzero == 0) { return; } // TODO: this is a rudimentary implementation; replace with a faster version using iterators const uword N = (std::min)(n_rows - row_offset, n_cols - col_offset); for(uword i=0; i inline static void copy_row(eT* X, const Mat& A, const uword row); template inline static void copy_row(Mat& A, const eT* X, const uword row); template inline static void direct_sort(eT* X, const uword N, const uword sort_type = 0); template inline static void direct_sort_ascending(eT* X, const uword N); template inline static void apply_noalias(Mat& out, const Mat& X, const uword sort_type, const uword dim); template inline static void apply(Mat& out, const Op& in); }; class op_sort_default { public: template inline static void apply(Mat& out, const Op& in); }; template struct arma_ascend_sort_helper { arma_inline bool operator() (const eT a, const eT b) const { return (a < b); } }; template struct arma_descend_sort_helper { arma_inline bool operator() (const eT a, const eT b) const { return (a > b); } }; template struct arma_ascend_sort_helper< std::complex > { typedef typename std::complex eT; inline bool operator() (const eT& a, const eT& b) const { return (std::abs(a) < std::abs(b)); } }; template struct arma_descend_sort_helper< std::complex > { typedef typename std::complex eT; inline bool operator() (const eT& a, const eT& b) const { return (std::abs(a) > std::abs(b)); } }; //! @} armadillo-6.500.5/include/armadillo_bits/spop_sum_meat.hpp0000666000000000000000000000376112620272703022341 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_sum //! @{ template arma_hot inline void spop_sum::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "sum(): parameter 'dim' must be 0 or 1" ); const SpProxy p(in.m); const uword p_n_rows = p.get_n_rows(); const uword p_n_cols = p.get_n_cols(); if(p.get_n_nonzero() == 0) { if(dim == 0) { out.zeros(1,p_n_cols); } if(dim == 1) { out.zeros(p_n_rows,1); } return; } if(dim == 0) // find the sum in each column { Row acc(p_n_cols, fill::zeros); if(SpProxy::must_use_iterator) { typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { acc[it.col()] += (*it); ++it; } } else { for(uword col = 0; col < p_n_cols; ++col) { acc[col] = arrayops::accumulate ( &p.get_values()[p.get_col_ptrs()[col]], p.get_col_ptrs()[col + 1] - p.get_col_ptrs()[col] ); } } out = acc; } else if(dim == 1) // find the sum in each row { Col acc(p_n_rows, fill::zeros); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { acc[it.row()] += (*it); ++it; } out = acc; } } //! @} armadillo-6.500.5/include/armadillo_bits/op_find_unique_meat.hpp0000666000000000000000000000517412620272703023500 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_find_unique //! @{ template inline bool op_find_unique::apply_helper(Mat& out, const Proxy& P, const bool ascending_indices) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_elem = P.get_n_elem(); if(n_elem == 0) { out.set_size(0,1); return true; } if(n_elem == 1) { out.set_size(1,1); out[0] = 0; return true; } uvec indices(n_elem); std::vector< arma_find_unique_packet > packet_vec(n_elem); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i comparator; std::sort( packet_vec.begin(), packet_vec.end(), comparator ); uword* indices_mem = indices.memptr(); indices_mem[0] = packet_vec[0].index; uword count = 1; for(uword i=1; i < n_elem; ++i) { const eT diff = packet_vec[i-1].val - packet_vec[i].val; if(diff != eT(0)) { indices_mem[count] = packet_vec[i].index; ++count; } } out.steal_mem_col(indices,count); if(ascending_indices) { std::sort(out.begin(), out.end()); } return true; } template inline void op_find_unique::apply(Mat& out, const mtOp& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); const bool ascending_indices = (in.aux_uword_a == uword(1)); const bool all_non_nan = op_find_unique::apply_helper(out, P, ascending_indices); if(all_non_nan == false) { arma_debug_check( true, "find_unique(): detected NaN" ); out.reset(); } } //! @} armadillo-6.500.5/include/armadillo_bits/subview_each_meat.hpp0000666000000000000000000007243312634226112023140 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_each //! @{ // // // subview_each_common template inline subview_each_common::subview_each_common(const parent& in_P) : P(in_P) { arma_extra_debug_sigprint(); } template arma_inline const Mat& subview_each_common::get_mat_ref_helper(const Mat& X) const { return X; } template arma_inline const Mat& subview_each_common::get_mat_ref_helper(const subview& X) const { return X.m; } template arma_inline const Mat& subview_each_common::get_mat_ref() const { return get_mat_ref_helper(P); } template inline void subview_each_common::check_size(const Mat& A) const { if(arma_config::debug == true) { if(mode == 0) { if( (A.n_rows != P.n_rows) || (A.n_cols != 1) ) { arma_stop( incompat_size_string(A) ); } } else { if( (A.n_rows != 1) || (A.n_cols != P.n_cols) ) { arma_stop( incompat_size_string(A) ); } } } } template arma_cold inline const std::string subview_each_common::incompat_size_string(const Mat& A) const { std::stringstream tmp; if(mode == 0) { tmp << "each_col(): incompatible size; expected " << P.n_rows << "x1" << ", got " << A.n_rows << 'x' << A.n_cols; } else { tmp << "each_row(): incompatible size; expected 1x" << P.n_cols << ", got " << A.n_rows << 'x' << A.n_cols; } return tmp.str(); } // // // subview_each1 template inline subview_each1::~subview_each1() { arma_extra_debug_sigprint(); } template inline subview_each1::subview_each1(const parent& in_P) : subview_each_common::subview_each_common(in_P) { arma_extra_debug_sigprint(); } template template inline void subview_each1::operator= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::copy( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_set( p.colptr(i), A_mem[i], p_n_rows); } } } template template inline void subview_each1::operator+= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_plus( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_plus( p.colptr(i), A_mem[i], p_n_rows); } } } template template inline void subview_each1::operator-= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_minus( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_minus( p.colptr(i), A_mem[i], p_n_rows); } } } template template inline void subview_each1::operator%= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_mul( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_mul( p.colptr(i), A_mem[i], p_n_rows); } } } template template inline void subview_each1::operator/= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_div( p.colptr(i), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < p_n_cols; ++i) { arrayops::inplace_div( p.colptr(i), A_mem[i], p_n_rows); } } } // // // subview_each2 template inline subview_each2::~subview_each2() { arma_extra_debug_sigprint(); } template inline subview_each2::subview_each2(const parent& in_P, const Base& in_indices) : subview_each_common::subview_each_common(in_P) , base_indices(in_indices) { arma_extra_debug_sigprint(); } template inline void subview_each2::check_indices(const Mat& indices) const { if(mode == 0) { arma_debug_check( ((indices.is_vec() == false) && (indices.is_empty() == false)), "each_col(): list of indices must be a vector" ); } else { arma_debug_check( ((indices.is_vec() == false) && (indices.is_empty() == false)), "each_row(): list of indices must be a vector" ); } } template template inline void subview_each2::operator= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed U( base_indices.get_ref(), (*this).get_mat_ref() ); check_indices(U.M); const eT* A_mem = A.memptr(); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // each column { for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); arrayops::copy( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); for(uword col=0; col < p_n_cols; ++col) { p.at(row,col) = A_mem[col]; } } } } template template inline void subview_each2::operator+= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed U( base_indices.get_ref(), (*this).get_mat_ref() ); check_indices(U.M); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // each column { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_plus( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); p.row(row) += A; } } } template template inline void subview_each2::operator-= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed U( base_indices.get_ref(), (*this).get_mat_ref() ); check_indices(U.M); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // each column { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_minus( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); p.row(row) -= A; } } } template template inline void subview_each2::operator%= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed U( base_indices.get_ref(), (*this).get_mat_ref() ); check_indices(U.M); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // each column { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_mul( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); p.row(row) %= A; } } } template template inline void subview_each2::operator/= (const Base& in) { arma_extra_debug_sigprint(); parent& p = access::rw(subview_each_common::P); const unwrap_check tmp( in.get_ref(), (*this).get_mat_ref() ); const Mat& A = tmp.M; subview_each_common::check_size(A); const unwrap_check_mixed U( base_indices.get_ref(), (*this).get_mat_ref() ); check_indices(U.M); const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // each column { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_div( p.colptr(col), A_mem, p_n_rows ); } } else // each row { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); p.row(row) /= A; } } } // // // subview_each1_aux template inline Mat subview_each1_aux::operator_plus ( const subview_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out(p_n_rows, p_n_cols); const quasi_unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; X.check_size(A); const eT* A_mem = A.memptr(); if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = p_mem[row] + A_mem[row]; } } } if(mode == 1) // each row { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); const eT A_val = A_mem[i]; for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = p_mem[row] + A_val; } } } return out; } template inline Mat subview_each1_aux::operator_minus ( const subview_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out(p_n_rows, p_n_cols); const quasi_unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; X.check_size(A); const eT* A_mem = A.memptr(); if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = p_mem[row] - A_mem[row]; } } } if(mode == 1) // each row { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); const eT A_val = A_mem[i]; for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = p_mem[row] - A_val; } } } return out; } template inline Mat subview_each1_aux::operator_minus ( const Base& X, const subview_each1& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = Y.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out(p_n_rows, p_n_cols); const quasi_unwrap tmp(X.get_ref()); const Mat& A = tmp.M; Y.check_size(A); const eT* A_mem = A.memptr(); if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = A_mem[row] - p_mem[row]; } } } if(mode == 1) // each row { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); const eT A_val = A_mem[i]; for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = A_val - p_mem[row]; } } } return out; } template inline Mat subview_each1_aux::operator_schur ( const subview_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out(p_n_rows, p_n_cols); const quasi_unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; X.check_size(A); const eT* A_mem = A.memptr(); if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = p_mem[row] * A_mem[row]; } } } if(mode == 1) // each row { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); const eT A_val = A_mem[i]; for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = p_mem[row] * A_val; } } } return out; } template inline Mat subview_each1_aux::operator_div ( const subview_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out(p_n_rows, p_n_cols); const quasi_unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; X.check_size(A); const eT* A_mem = A.memptr(); if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = p_mem[row] / A_mem[row]; } } } if(mode == 1) // each row { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); const eT A_val = A_mem[i]; for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = p_mem[row] / A_val; } } } return out; } template inline Mat subview_each1_aux::operator_div ( const Base& X, const subview_each1& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = Y.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out(p_n_rows, p_n_cols); const quasi_unwrap tmp(X.get_ref()); const Mat& A = tmp.M; Y.check_size(A); const eT* A_mem = A.memptr(); if(mode == 0) // each column { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = A_mem[row] / p_mem[row]; } } } if(mode == 1) // each row { for(uword i=0; i < p_n_cols; ++i) { const eT* p_mem = p.colptr(i); eT* out_mem = out.colptr(i); const eT A_val = A_mem[i]; for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = A_val / p_mem[row]; } } } return out; } // // // subview_each2_aux template inline Mat subview_each2_aux::operator_plus ( const subview_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out = p; const quasi_unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; const unwrap U(X.base_indices.get_ref()); X.check_size(A); X.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // process columns { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_plus( out.colptr(col), A_mem, p_n_rows ); } } if(mode == 1) // process rows { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); out.row(row) += A; } } return out; } template inline Mat subview_each2_aux::operator_minus ( const subview_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out = p; const quasi_unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; const unwrap U(X.base_indices.get_ref()); X.check_size(A); X.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // process columns { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_minus( out.colptr(col), A_mem, p_n_rows ); } } if(mode == 1) // process rows { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); out.row(row) -= A; } } return out; } template inline Mat subview_each2_aux::operator_minus ( const Base& X, const subview_each2& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = Y.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out = p; const quasi_unwrap tmp(X.get_ref()); const Mat& A = tmp.M; const unwrap U(Y.base_indices.get_ref()); Y.check_size(A); Y.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // process columns { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); const eT* p_mem = p.colptr(col); eT* out_mem = out.colptr(col); for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = A_mem[row] - p_mem[row]; } } } if(mode == 1) // process rows { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); out.row(row) = A - p.row(row); } } return out; } template inline Mat subview_each2_aux::operator_schur ( const subview_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out = p; const quasi_unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; const unwrap U(X.base_indices.get_ref()); X.check_size(A); X.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // process columns { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_mul( out.colptr(col), A_mem, p_n_rows ); } } if(mode == 1) // process rows { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); out.row(row) %= A; } } return out; } template inline Mat subview_each2_aux::operator_div ( const subview_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out = p; const quasi_unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; const unwrap U(X.base_indices.get_ref()); X.check_size(A); X.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // process columns { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); arrayops::inplace_div( out.colptr(col), A_mem, p_n_rows ); } } if(mode == 1) // process rows { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); out.row(row) /= A; } } return out; } template inline Mat subview_each2_aux::operator_div ( const Base& X, const subview_each2& Y ) { arma_extra_debug_sigprint(); typedef typename parent::elem_type eT; const parent& p = Y.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; Mat out = p; const quasi_unwrap tmp(X.get_ref()); const Mat& A = tmp.M; const unwrap U(Y.base_indices.get_ref()); Y.check_size(A); Y.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; if(mode == 0) // process columns { const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword col = indices_mem[i]; arma_debug_check( (col >= p_n_cols), "each_col(): index out of bounds" ); const eT* p_mem = p.colptr(col); eT* out_mem = out.colptr(col); for(uword row=0; row < p_n_rows; ++row) { out_mem[row] = A_mem[row] / p_mem[row]; } } } if(mode == 1) // process rows { for(uword i=0; i < N; ++i) { const uword row = indices_mem[i]; arma_debug_check( (row >= p_n_rows), "each_row(): index out of bounds" ); out.row(row) = A / p.row(row); } } return out; } //! @} armadillo-6.500.5/include/armadillo_bits/op_min_bones.hpp0000666000000000000000000000463312620272703022134 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_min //! @{ class op_min { public: template inline static void apply(Mat& out, const Op& in); template inline static void apply_noalias(Mat& out, const Mat& X, const uword dim, const typename arma_not_cx::result* junk = 0); template inline static void apply_noalias(Mat& out, const Mat& X, const uword dim, const typename arma_cx_only::result* junk = 0); // // for non-complex numbers template inline static eT direct_min(const eT* const X, const uword N); template inline static eT direct_min(const eT* const X, const uword N, uword& index_of_min_val); template inline static eT direct_min(const Mat& X, const uword row); template inline static eT min(const subview& X); template inline static typename arma_not_cx::result min(const Base& X); template inline static typename arma_not_cx::result min_with_index(const Proxy& P, uword& index_of_min_val); // // for complex numbers template inline static std::complex direct_min(const std::complex* const X, const uword n_elem); template inline static std::complex direct_min(const std::complex* const X, const uword n_elem, uword& index_of_min_val); template inline static std::complex direct_min(const Mat< std::complex >& X, const uword row); template inline static std::complex min(const subview< std::complex >&X); template inline static typename arma_cx_only::result min(const Base& X); template inline static typename arma_cx_only::result min_with_index(const Proxy& P, uword& index_of_min_val); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_trimat_meat.hpp0000666000000000000000000001273212621122620022461 0ustar rootroot// Copyright (C) 2010-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup op_trimat //! @{ template inline void op_trimat::fill_zeros(Mat& out, const bool upper) { arma_extra_debug_sigprint(); const uword N = out.n_rows; if(upper) { // upper triangular: set all elements below the diagonal to zero for(uword i=0; i inline void op_trimat::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat& A = tmp.M; arma_debug_check( (A.is_square() == false), "trimatu()/trimatl(): given matrix must be square sized" ); const uword N = A.n_rows; const bool upper = (in.aux_uword_a == 0); if(&out != &A) { out.copy_size(A); if(upper) { // upper triangular: copy the diagonal and the elements above the diagonal for(uword i=0; i inline void op_trimat::apply(Mat& out, const Op, op_trimat>& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m.m); const Mat& A = tmp.M; const bool upper = (in.aux_uword_a == 0); op_trimat::apply_htrans(out, A, upper); } template inline void op_trimat::apply_htrans ( Mat& out, const Mat& A, const bool upper, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); // This specialisation is for trimatl(trans(X)) = trans(trimatu(X)) and also // trimatu(trans(X)) = trans(trimatl(X)). We want to avoid the creation of an // extra temporary. // It doesn't matter if the input and output matrices are the same; we will // pull data from the upper or lower triangular to the lower or upper // triangular (respectively) and then set the rest to 0, so overwriting issues // aren't present. arma_debug_check( (A.is_square() == false), "trimatu()/trimatl(): given matrix must be square sized" ); const uword N = A.n_rows; if(&out != &A) { out.copy_size(A); } // We can't really get away with any array copy operations here, // unfortunately... if(upper) { // Upper triangular: but since we're transposing, we're taking the lower // triangular and putting it in the upper half. for(uword row = 0; row < N; ++row) { eT* out_colptr = out.colptr(row); for(uword col = 0; col <= row; ++col) { //out.at(col, row) = A.at(row, col); out_colptr[col] = A.at(row, col); } } } else { // Lower triangular: but since we're transposing, we're taking the upper // triangular and putting it in the lower half. for(uword row = 0; row < N; ++row) { for(uword col = row; col < N; ++col) { out.at(col, row) = A.at(row, col); } } } op_trimat::fill_zeros(out, upper); } template inline void op_trimat::apply_htrans ( Mat& out, const Mat& A, const bool upper, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( (A.is_square() == false), "trimatu()/trimatl(): given matrix must be square sized" ); const uword N = A.n_rows; if(&out != &A) { out.copy_size(A); } if(upper) { // Upper triangular: but since we're transposing, we're taking the lower // triangular and putting it in the upper half. for(uword row = 0; row < N; ++row) { eT* out_colptr = out.colptr(row); for(uword col = 0; col <= row; ++col) { //out.at(col, row) = std::conj( A.at(row, col) ); out_colptr[col] = std::conj( A.at(row, col) ); } } } else { // Lower triangular: but since we're transposing, we're taking the upper // triangular and putting it in the lower half. for(uword row = 0; row < N; ++row) { for(uword col = row; col < N; ++col) { out.at(col, row) = std::conj( A.at(row, col) ); } } } op_trimat::fill_zeros(out, upper); } //! @} armadillo-6.500.5/include/armadillo_bits/op_expmat_meat.hpp0000666000000000000000000000460712620272703022470 0ustar rootroot// Copyright (C) 2014-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_expmat //! @{ //! implementation based on: //! Cleve Moler, Charles Van Loan. //! Nineteen Dubious Ways to Compute the Exponential of a Matrix, Twenty-Five Years Later. //! SIAM Review, Vol. 45, No. 1, 2003, pp. 3-49. //! http://dx.doi.org/10.1137/S00361445024180 template inline void op_expmat::apply(Mat& out, const Op& expr) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; if(is_op_diagmat::value) { out = expr.m; // force the evaluation of diagmat() arma_debug_check( (out.is_square() == false), "expmat(): given matrix must be square sized" ); const uword N = (std::min)(out.n_rows, out.n_cols); for(uword i=0; i tmp(expr.m); const Mat& A = tmp.M; arma_debug_check( (A.is_square() == false), "expmat(): given matrix must be square sized" ); const T norm_val = arma::norm(A, "inf"); const double log2_val = (norm_val > T(0)) ? double(eop_aux::log2(norm_val)) : double(0); int exponent = int(0); std::frexp(log2_val, &exponent); const uword s = uword( (std::max)(int(0), exponent + int(1)) ); const Mat AA = A / eT(eop_aux::pow(double(2), double(s))); T c = T(0.5); Mat E(AA.n_rows, AA.n_rows, fill::eye); E += c * AA; Mat D(AA.n_rows, AA.n_rows, fill::eye); D -= c * AA; Mat X = AA; bool positive = true; const uword N = 6; for(uword i = 2; i <= N; ++i) { c = c * T(N - i + 1) / T(i * (2*N - i + 1)); X = AA * X; E += c * X; if(positive) { D += c * X; } else { D -= c * X; } positive = (positive) ? false : true; } out = solve(D, E); for(uword i=0; i < s; ++i) { out = out * out; } } } //! @} armadillo-6.500.5/include/armadillo_bits/spop_strans_bones.hpp0000666000000000000000000000203512620272703023220 0ustar rootroot// Copyright (C) 2012-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spop_strans //! @{ //! simple transpose operation (no complex conjugates) for sparse matrices class spop_strans { public: template arma_hot inline static void apply_spmat(SpMat& out, const SpMat& X); template arma_hot inline static void apply_proxy(SpMat& out, const T1& X); template arma_hot inline static void apply(SpMat& out, const SpOp& in); template arma_hot inline static void apply(SpMat& out, const SpOp& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/span.hpp0000666000000000000000000000240712620272703020423 0ustar rootroot// Copyright (C) 2010-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Stanislav Funiak //! \addtogroup span //! @{ struct span_alt {}; template class span_base { public: static const span_alt all; }; template const span_alt span_base::all = span_alt(); class span : public span_base<> { public: uword a; uword b; bool whole; inline span() : whole(true) { } inline span(const span_alt&) : whole(true) { } inline explicit span(const uword in_a) : a(in_a) , b(in_a) , whole(false) { } // the "explicit" keyword is required here to prevent a C++11 compiler // automatically converting {a,b} into an instance of span() when submatrices are specified inline explicit span(const uword in_a, const uword in_b) : a(in_a) , b(in_b) , whole(false) { } }; //! @} armadillo-6.500.5/include/armadillo_bits/spglue_minus_bones.hpp0000666000000000000000000000174012620272703023361 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spglue_minus //! @{ class spglue_minus { public: template arma_hot inline static void apply(SpMat& out, const SpGlue& X); template arma_hot inline static void apply_noalias(SpMat& result, const SpProxy& pa, const SpProxy& pb); }; class spglue_minus2 { public: template arma_hot inline static void apply(SpMat& out, const SpGlue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/SizeCube_bones.hpp0000666000000000000000000000224412620272703022360 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup SizeCube //! @{ class SizeCube { public: const uword n_rows; const uword n_cols; const uword n_slices; inline explicit SizeCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices); inline uword operator[](const uword dim) const; inline uword operator()(const uword dim) const; inline bool operator==(const SizeCube& s) const; inline bool operator!=(const SizeCube& s) const; inline SizeCube operator+(const SizeCube& s) const; inline SizeCube operator-(const SizeCube& s) const; inline SizeCube operator+(const uword val) const; inline SizeCube operator-(const uword val) const; inline SizeCube operator*(const uword val) const; inline SizeCube operator/(const uword val) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/SpSubview_meat.hpp0000666000000000000000000010475112620272703022424 0ustar rootroot// Copyright (C) 2011-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin // Written by Matthew Amidon //! \addtogroup SpSubview //! @{ template arma_inline SpSubview::SpSubview(const SpMat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols) : m(in_m) , aux_row1(in_row1) , aux_col1(in_col1) , n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows * in_n_cols) , n_nonzero(0) { arma_extra_debug_sigprint(); // There must be a O(1) way to do this uword lend = m.col_ptrs[in_col1 + in_n_cols]; uword lend_row = in_row1 + in_n_rows; uword count = 0; for(uword i = m.col_ptrs[in_col1]; i < lend; ++i) { const uword m_row_indices_i = m.row_indices[i]; const bool condition = (m_row_indices_i >= in_row1) && (m_row_indices_i < lend_row); count += condition ? uword(1) : uword(0); } access::rw(n_nonzero) = count; } template arma_inline SpSubview::SpSubview(SpMat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols) : m(in_m) , aux_row1(in_row1) , aux_col1(in_col1) , n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows * in_n_cols) , n_nonzero(0) { arma_extra_debug_sigprint(); // There must be a O(1) way to do this uword lend = m.col_ptrs[in_col1 + in_n_cols]; uword lend_row = in_row1 + in_n_rows; uword count = 0; for(uword i = m.col_ptrs[in_col1]; i < lend; ++i) { const uword m_row_indices_i = m.row_indices[i]; const bool condition = (m_row_indices_i >= in_row1) && (m_row_indices_i < lend_row); count += condition ? uword(1) : uword(0); } access::rw(n_nonzero) = count; } template inline SpSubview::~SpSubview() { arma_extra_debug_sigprint(); } template inline const SpSubview& SpSubview::operator+=(const eT val) { arma_extra_debug_sigprint(); if(val == eT(0)) { return *this; } Mat tmp( (*this).n_rows, (*this).n_cols ); tmp.fill(val); return (*this).operator=( (*this) + tmp ); } template inline const SpSubview& SpSubview::operator-=(const eT val) { arma_extra_debug_sigprint(); if(val == eT(0)) { return *this; } Mat tmp( (*this).n_rows, (*this).n_cols ); tmp.fill(val); return (*this).operator=( (*this) - tmp ); } template inline const SpSubview& SpSubview::operator*=(const eT val) { arma_extra_debug_sigprint(); const uword lstart_row = aux_row1; const uword lend_row = aux_row1 + n_rows; const uword lstart_col = aux_col1; const uword lend_col = aux_col1 + n_cols; const uword* m_row_indices = m.row_indices; eT* m_values = access::rwp(m.values); for(uword c = lstart_col; c < lend_col; ++c) { const uword r_start = m.col_ptrs[c ]; const uword r_end = m.col_ptrs[c + 1]; for(uword r = r_start; r < r_end; ++r) { const uword m_row_indices_r = m_row_indices[r]; if( (m_row_indices_r >= lstart_row) && (m_row_indices_r < lend_row) ) { m_values[r] *= val; } } } const uword old_m_n_nonzero = m.n_nonzero; access::rw(m).remove_zeros(); if(m.n_nonzero != old_m_n_nonzero) { access::rw(n_nonzero) = n_nonzero - (old_m_n_nonzero - m.n_nonzero); } return *this; } template inline const SpSubview& SpSubview::operator/=(const eT val) { arma_extra_debug_sigprint(); arma_debug_check( (val == eT(0)), "element-wise division: division by zero" ); const uword lstart_row = aux_row1; const uword lend_row = aux_row1 + n_rows; const uword lstart_col = aux_col1; const uword lend_col = aux_col1 + n_cols; const uword* m_row_indices = m.row_indices; eT* m_values = access::rwp(m.values); for(uword c = lstart_col; c < lend_col; ++c) { const uword r_start = m.col_ptrs[c ]; const uword r_end = m.col_ptrs[c + 1]; for(uword r = r_start; r < r_end; ++r) { const uword m_row_indices_r = m_row_indices[r]; if( (m_row_indices_r >= lstart_row) && (m_row_indices_r < lend_row) ) { m_values[r] /= val; } } } const uword old_m_n_nonzero = m.n_nonzero; access::rw(m).remove_zeros(); if(m.n_nonzero != old_m_n_nonzero) { access::rw(n_nonzero) = n_nonzero - (old_m_n_nonzero - m.n_nonzero); } return *this; } template template inline const SpSubview& SpSubview::operator=(const Base& in) { arma_extra_debug_sigprint(); // this is a modified version of SpSubview::operator_equ_common(const SpBase) const SpProxy< SpMat > pa((*this).m); const unwrap b_tmp(in.get_ref()); const Mat& b = b_tmp.M; arma_debug_assert_same_size(n_rows, n_cols, b.n_rows, b.n_cols, "insertion into sparse submatrix"); const uword pa_start_row = (*this).aux_row1; const uword pa_start_col = (*this).aux_col1; const uword pa_end_row = pa_start_row + (*this).n_rows - 1; const uword pa_end_col = pa_start_col + (*this).n_cols - 1; const uword pa_n_rows = pa.get_n_rows(); const uword b_n_elem = b.n_elem; const eT* b_mem = b.memptr(); uword box_count = 0; for(uword i=0; i out(pa.get_n_rows(), pa.get_n_cols()); const uword alt_count = pa.get_n_nonzero() - (*this).n_nonzero + box_count; // Resize memory to correct size. out.mem_resize(alt_count); typename SpProxy< SpMat >::const_iterator_type x_it = pa.begin(); typename SpProxy< SpMat >::const_iterator_type x_end = pa.end(); uword b_row = 0; uword b_col = 0; bool x_it_ok = (x_it != x_end); bool y_it_ok = ( (b_row < b.n_rows) && (b_col < b.n_cols) ); uword x_it_row = (x_it_ok) ? x_it.row() : 0; uword x_it_col = (x_it_ok) ? x_it.col() : 0; uword y_it_row = (y_it_ok) ? b_row + pa_start_row : 0; uword y_it_col = (y_it_ok) ? b_col + pa_start_col : 0; uword cur_val = 0; while(x_it_ok || y_it_ok) { const bool x_inside_box = (x_it_row >= pa_start_row) && (x_it_row <= pa_end_row) && (x_it_col >= pa_start_col) && (x_it_col <= pa_end_col); const bool y_inside_box = (y_it_row >= pa_start_row) && (y_it_row <= pa_end_row) && (y_it_col >= pa_start_col) && (y_it_col <= pa_end_col); const eT x_val = x_inside_box ? eT(0) : ( x_it_ok ? (*x_it) : eT(0) ); const eT y_val = y_inside_box ? ( y_it_ok ? b.at(b_row,b_col) : eT(0) ) : eT(0); if( (x_it_row == y_it_row) && (x_it_col == y_it_col) ) { if( (x_val != eT(0)) || (y_val != eT(0)) ) { access::rw(out.values[cur_val]) = (x_val != eT(0)) ? x_val : y_val; access::rw(out.row_indices[cur_val]) = x_it_row; ++access::rw(out.col_ptrs[x_it_col + 1]); ++cur_val; } if(x_it_ok) { ++x_it; if(x_it == x_end) { x_it_ok = false; } } if(x_it_ok) { x_it_row = x_it.row(); x_it_col = x_it.col(); } else { x_it_row++; if(x_it_row >= pa_n_rows) { x_it_row = 0; x_it_col++; } } if(y_it_ok) { b_row++; if(b_row >= b.n_rows) { b_row = 0; b_col++; } if( (b_row > b.n_rows) || (b_col > b.n_cols) ) { y_it_ok = false; } } if(y_it_ok) { y_it_row = b_row + pa_start_row; y_it_col = b_col + pa_start_col; } else { y_it_row++; if(y_it_row >= pa_n_rows) { y_it_row = 0; y_it_col++; } } } else { if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end { if(x_val != eT(0)) { access::rw(out.values[cur_val]) = x_val; access::rw(out.row_indices[cur_val]) = x_it_row; ++access::rw(out.col_ptrs[x_it_col + 1]); ++cur_val; } if(x_it_ok) { ++x_it; if(x_it == x_end) { x_it_ok = false; } } if(x_it_ok) { x_it_row = x_it.row(); x_it_col = x_it.col(); } else { x_it_row++; if(x_it_row >= pa_n_rows) { x_it_row = 0; x_it_col++; } } } else { if(y_val != eT(0)) { access::rw(out.values[cur_val]) = y_val; access::rw(out.row_indices[cur_val]) = y_it_row; ++access::rw(out.col_ptrs[y_it_col + 1]); ++cur_val; } if(y_it_ok) { b_row++; if(b_row >= b.n_rows) { b_row = 0; b_col++; } if( (b_row > b.n_rows) || (b_col > b.n_cols) ) { y_it_ok = false; } } if(y_it_ok) { y_it_row = b_row + pa_start_row; y_it_col = b_col + pa_start_col; } else { y_it_row++; if(y_it_row >= pa_n_rows) { y_it_row = 0; y_it_col++; } } } } } const uword out_n_cols = out.n_cols; uword* col_ptrs = access::rwp(out.col_ptrs); // Fix column pointers to be cumulative. for(uword c = 1; c <= out_n_cols; ++c) { col_ptrs[c] += col_ptrs[c - 1]; } access::rw((*this).m).steal_mem(out); access::rw(n_nonzero) = box_count; return *this; } template template inline const SpSubview& SpSubview::operator+=(const Base& x) { arma_extra_debug_sigprint(); return (*this).operator=( (*this) + x.get_ref() ); } template template inline const SpSubview& SpSubview::operator-=(const Base& x) { arma_extra_debug_sigprint(); return (*this).operator=( (*this) - x.get_ref() ); } template template inline const SpSubview& SpSubview::operator*=(const Base& x) { arma_extra_debug_sigprint(); SpMat tmp(*this); tmp *= x.get_ref(); return (*this).operator=(tmp); } template template inline const SpSubview& SpSubview::operator%=(const Base& x) { arma_extra_debug_sigprint(); return (*this).operator=( (*this) % x.get_ref() ); } template template inline const SpSubview& SpSubview::operator/=(const Base& x) { arma_extra_debug_sigprint(); return (*this).operator=( (*this) / x.get_ref() ); } template inline const SpSubview& SpSubview::operator=(const SpSubview& x) { arma_extra_debug_sigprint(); return (*this).operator_equ_common(x); } template template inline const SpSubview& SpSubview::operator=(const SpBase& x) { arma_extra_debug_sigprint(); return (*this).operator_equ_common( x.get_ref() ); } template template inline const SpSubview& SpSubview::operator_equ_common(const SpBase& in) { arma_extra_debug_sigprint(); // algorithm: // instead of directly inserting values into the matrix underlying the subview, // create a new matrix by merging the underlying matrix with the input object, // and then replacing the underlying matrix with the created matrix. // // the merging process requires pretending that the input object // has the same size as the underlying matrix. // while iterating through the elements of the input object, // this requires adjusting the row and column locations of each element, // as well as providing fake zero elements. // in effect there is a proxy for a proxy. const SpProxy< SpMat > pa((*this).m ); const SpProxy< T1 > pb(in.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, pb.get_n_rows(), pb.get_n_cols(), "insertion into sparse submatrix"); const uword pa_start_row = (*this).aux_row1; const uword pa_start_col = (*this).aux_col1; const uword pa_end_row = pa_start_row + (*this).n_rows - 1; const uword pa_end_col = pa_start_col + (*this).n_cols - 1; const uword pa_n_rows = pa.get_n_rows(); SpMat out(pa.get_n_rows(), pa.get_n_cols()); const uword alt_count = pa.get_n_nonzero() - (*this).n_nonzero + pb.get_n_nonzero(); // Resize memory to correct size. out.mem_resize(alt_count); typename SpProxy< SpMat >::const_iterator_type x_it = pa.begin(); typename SpProxy< SpMat >::const_iterator_type x_end = pa.end(); typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type y_end = pb.end(); bool x_it_ok = (x_it != x_end); bool y_it_ok = (y_it != y_end); uword x_it_row = (x_it_ok) ? x_it.row() : 0; uword x_it_col = (x_it_ok) ? x_it.col() : 0; uword y_it_row = (y_it_ok) ? y_it.row() + pa_start_row : 0; uword y_it_col = (y_it_ok) ? y_it.col() + pa_start_col : 0; uword cur_val = 0; while(x_it_ok || y_it_ok) { const bool x_inside_box = (x_it_row >= pa_start_row) && (x_it_row <= pa_end_row) && (x_it_col >= pa_start_col) && (x_it_col <= pa_end_col); const bool y_inside_box = (y_it_row >= pa_start_row) && (y_it_row <= pa_end_row) && (y_it_col >= pa_start_col) && (y_it_col <= pa_end_col); const eT x_val = x_inside_box ? eT(0) : ( x_it_ok ? (*x_it) : eT(0) ); const eT y_val = y_inside_box ? ( y_it_ok ? (*y_it) : eT(0) ) : eT(0); if( (x_it_row == y_it_row) && (x_it_col == y_it_col) ) { if( (x_val != eT(0)) || (y_val != eT(0)) ) { access::rw(out.values[cur_val]) = (x_val != eT(0)) ? x_val : y_val; access::rw(out.row_indices[cur_val]) = x_it_row; ++access::rw(out.col_ptrs[x_it_col + 1]); ++cur_val; } if(x_it_ok) { ++x_it; if(x_it == x_end) { x_it_ok = false; } } if(x_it_ok) { x_it_row = x_it.row(); x_it_col = x_it.col(); } else { x_it_row++; if(x_it_row >= pa_n_rows) { x_it_row = 0; x_it_col++; } } if(y_it_ok) { ++y_it; if(y_it == y_end) { y_it_ok = false; } } if(y_it_ok) { y_it_row = y_it.row() + pa_start_row; y_it_col = y_it.col() + pa_start_col; } else { y_it_row++; if(y_it_row >= pa_n_rows) { y_it_row = 0; y_it_col++; } } } else { if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end { if(x_val != eT(0)) { access::rw(out.values[cur_val]) = x_val; access::rw(out.row_indices[cur_val]) = x_it_row; ++access::rw(out.col_ptrs[x_it_col + 1]); ++cur_val; } if(x_it_ok) { ++x_it; if(x_it == x_end) { x_it_ok = false; } } if(x_it_ok) { x_it_row = x_it.row(); x_it_col = x_it.col(); } else { x_it_row++; if(x_it_row >= pa_n_rows) { x_it_row = 0; x_it_col++; } } } else { if(y_val != eT(0)) { access::rw(out.values[cur_val]) = y_val; access::rw(out.row_indices[cur_val]) = y_it_row; ++access::rw(out.col_ptrs[y_it_col + 1]); ++cur_val; } if(y_it_ok) { ++y_it; if(y_it == y_end) { y_it_ok = false; } } if(y_it_ok) { y_it_row = y_it.row() + pa_start_row; y_it_col = y_it.col() + pa_start_col; } else { y_it_row++; if(y_it_row >= pa_n_rows) { y_it_row = 0; y_it_col++; } } } } } const uword out_n_cols = out.n_cols; uword* col_ptrs = access::rwp(out.col_ptrs); // Fix column pointers to be cumulative. for(uword c = 1; c <= out_n_cols; ++c) { col_ptrs[c] += col_ptrs[c - 1]; } access::rw((*this).m).steal_mem(out); access::rw(n_nonzero) = pb.get_n_nonzero(); return *this; } template template inline const SpSubview& SpSubview::operator+=(const SpBase& x) { arma_extra_debug_sigprint(); // TODO: implement dedicated machinery return (*this).operator=( (*this) + x.get_ref() ); } template template inline const SpSubview& SpSubview::operator-=(const SpBase& x) { arma_extra_debug_sigprint(); // TODO: implement dedicated machinery return (*this).operator=( (*this) - x.get_ref() ); } template template inline const SpSubview& SpSubview::operator*=(const SpBase& x) { arma_extra_debug_sigprint(); return (*this).operator=( (*this) * x.get_ref() ); } template template inline const SpSubview& SpSubview::operator%=(const SpBase& x) { arma_extra_debug_sigprint(); // TODO: implement dedicated machinery return (*this).operator=( (*this) % x.get_ref() ); } //! If you are using this function, you are probably misguided. template template inline const SpSubview& SpSubview::operator/=(const SpBase& x) { arma_extra_debug_sigprint(); SpProxy p(x.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise division"); if(p.is_alias(m) == false) { for(uword lcol = 0; lcol < n_cols; ++lcol) for(uword lrow = 0; lrow < n_rows; ++lrow) { at(lrow,lcol) /= p.at(lrow,lcol); } } else { const SpMat tmp(p.Q); (*this).operator/=(tmp); } return *this; } template inline void SpSubview::fill(const eT val) { arma_extra_debug_sigprint(); if(val != eT(0)) { Mat tmp( (*this).n_rows, (*this).n_cols ); tmp.fill(val); (*this).operator=(tmp); } else { (*this).zeros(); } } template inline void SpSubview::zeros() { arma_extra_debug_sigprint(); (*this).operator*=(eT(0)); } template inline void SpSubview::ones() { arma_extra_debug_sigprint(); (*this).fill(eT(1)); } template inline void SpSubview::eye() { arma_extra_debug_sigprint(); SpMat tmp; tmp.eye( (*this).n_rows, (*this).n_cols ); (*this).operator=(tmp); } template arma_hot inline SpValProxy > SpSubview::operator[](const uword i) { const uword lrow = i % n_rows; const uword lcol = i / n_rows; return (*this).at(lrow, lcol); } template arma_hot inline eT SpSubview::operator[](const uword i) const { const uword lrow = i % n_rows; const uword lcol = i / n_rows; return (*this).at(lrow, lcol); } template arma_hot inline SpValProxy< SpSubview > SpSubview::operator()(const uword i) { arma_debug_check( (i >= n_elem), "SpSubview::operator(): index out of bounds"); const uword lrow = i % n_rows; const uword lcol = i / n_rows; return (*this).at(lrow, lcol); } template arma_hot inline eT SpSubview::operator()(const uword i) const { arma_debug_check( (i >= n_elem), "SpSubview::operator(): index out of bounds"); const uword lrow = i % n_rows; const uword lcol = i / n_rows; return (*this).at(lrow, lcol); } template arma_hot inline SpValProxy< SpSubview > SpSubview::operator()(const uword in_row, const uword in_col) { arma_debug_check( (in_row >= n_rows) || (in_col >= n_cols), "SpSubview::operator(): index out of bounds"); return (*this).at(in_row, in_col); } template arma_hot inline eT SpSubview::operator()(const uword in_row, const uword in_col) const { arma_debug_check( (in_row >= n_rows) || (in_col >= n_cols), "SpSubview::operator(): index out of bounds"); return (*this).at(in_row, in_col); } template arma_hot inline SpValProxy< SpSubview > SpSubview::at(const uword i) { const uword lrow = i % n_rows; const uword lcol = i / n_cols; return (*this).at(lrow, lcol); } template arma_hot inline eT SpSubview::at(const uword i) const { const uword lrow = i % n_rows; const uword lcol = i / n_cols; return (*this).at(lrow, lcol); } template arma_hot inline SpValProxy< SpSubview > SpSubview::at(const uword in_row, const uword in_col) { const uword colptr = m.col_ptrs[in_col + aux_col1]; const uword next_colptr = m.col_ptrs[in_col + aux_col1 + 1]; // Step through the row indices to see if our element exists. for(uword i = colptr; i < next_colptr; ++i) { // First check that we have not stepped past it. if((in_row + aux_row1) < m.row_indices[i]) { return SpValProxy >(in_row, in_col, *this); // Proxy for a zero value. } // Now check if we are at the correct place. if((in_row + aux_row1) == m.row_indices[i]) // If we are, return a reference to the value. { return SpValProxy >(in_row, in_col, *this, &access::rw(m.values[i])); } } // We did not find it, so it does not exist. return SpValProxy >(in_row, in_col, *this); } template arma_hot inline eT SpSubview::at(const uword in_row, const uword in_col) const { return m.at(aux_row1 + in_row, aux_col1 + in_col); } template inline bool SpSubview::check_overlap(const SpSubview& x) const { const subview& t = *this; if(&t.m != &x.m) { return false; } else { if( (t.n_elem == 0) || (x.n_elem == 0) ) { return false; } else { const uword t_row_start = t.aux_row1; const uword t_row_end_p1 = t_row_start + t.n_rows; const uword t_col_start = t.aux_col1; const uword t_col_end_p1 = t_col_start + t.n_cols; const uword x_row_start = x.aux_row1; const uword x_row_end_p1 = x_row_start + x.n_rows; const uword x_col_start = x.aux_col1; const uword x_col_end_p1 = x_col_start + x.n_cols; const bool outside_rows = ( (x_row_start >= t_row_end_p1) || (t_row_start >= x_row_end_p1) ); const bool outside_cols = ( (x_col_start >= t_col_end_p1) || (t_col_start >= x_col_end_p1) ); return ( (outside_rows == false) && (outside_cols == false) ); } } } template inline bool SpSubview::is_vec() const { return ( (n_rows == 1) || (n_cols == 1) ); } template inline SpSubview SpSubview::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds"); return submat(row_num, 0, row_num, n_cols - 1); } template inline const SpSubview SpSubview::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check(row_num >= n_rows, "SpSubview::row(): out of bounds"); return submat(row_num, 0, row_num, n_cols - 1); } template inline SpSubview SpSubview::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds"); return submat(0, col_num, n_rows - 1, col_num); } template inline const SpSubview SpSubview::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check(col_num >= n_cols, "SpSubview::col(): out of bounds"); return submat(0, col_num, n_rows - 1, col_num); } template inline SpSubview SpSubview::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpSubview::rows(): indices out of bounds or incorrectly used" ); return submat(in_row1, 0, in_row2, n_cols - 1); } template inline const SpSubview SpSubview::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "SpSubview::rows(): indices out of bounds or incorrectly used" ); return submat(in_row1, 0, in_row2, n_cols - 1); } template inline SpSubview SpSubview::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpSubview::cols(): indices out of bounds or incorrectly used" ); return submat(0, in_col1, n_rows - 1, in_col2); } template inline const SpSubview SpSubview::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "SpSubview::cols(): indices out of bounds or incorrectly used" ); return submat(0, in_col1, n_rows - 1, in_col2); } template inline SpSubview SpSubview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "SpSubview::submat(): indices out of bounds or incorrectly used" ); return access::rw(m).submat(in_row1 + aux_row1, in_col1 + aux_col1, in_row2 + aux_row1, in_col2 + aux_col1); } template inline const SpSubview SpSubview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "SpSubview::submat(): indices out of bounds or incorrectly used" ); return m.submat(in_row1 + aux_row1, in_col1 + aux_col1, in_row2 + aux_row1, in_col2 + aux_col1); } template inline SpSubview SpSubview::submat(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = row_span.whole; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_all ? n_rows : row_span.b; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_all ? n_cols : col_span.b; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows))) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))), "SpSubview::submat(): indices out of bounds or incorrectly used" ); return submat(in_row1, in_col1, in_row2, in_col2); } template inline const SpSubview SpSubview::submat(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = row_span.whole; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_all ? n_rows - 1 : row_span.b; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_all ? n_cols - 1 : col_span.b; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= n_rows))) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= n_cols))), "SpSubview::submat(): indices out of bounds or incorrectly used" ); return submat(in_row1, in_col1, in_row2, in_col2); } template inline SpSubview SpSubview::operator()(const uword row_num, const span& col_span) { arma_extra_debug_sigprint(); return submat(span(row_num, row_num), col_span); } template inline const SpSubview SpSubview::operator()(const uword row_num, const span& col_span) const { arma_extra_debug_sigprint(); return submat(span(row_num, row_num), col_span); } template inline SpSubview SpSubview::operator()(const span& row_span, const uword col_num) { arma_extra_debug_sigprint(); return submat(row_span, span(col_num, col_num)); } template inline const SpSubview SpSubview::operator()(const span& row_span, const uword col_num) const { arma_extra_debug_sigprint(); return submat(row_span, span(col_num, col_num)); } template inline SpSubview SpSubview::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return submat(row_span, col_span); } template inline const SpSubview SpSubview::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return submat(row_span, col_span); } template inline void SpSubview::swap_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check((in_row1 >= n_rows) || (in_row2 >= n_rows), "SpSubview::swap_rows(): invalid row index"); const uword lstart_col = aux_col1; const uword lend_col = aux_col1 + n_cols; for(uword c = lstart_col; c < lend_col; ++c) { eT val = m.at(in_row1 + aux_row1, c); access::rw(m).at(in_row2 + aux_row1, c) = m.at(in_row1 + aux_row1, c); access::rw(m).at(in_row1 + aux_row1, c) = val; } } template inline void SpSubview::swap_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check((in_col1 >= n_cols) || (in_col2 >= n_cols), "SpSubview::swap_cols(): invalid column index"); const uword lstart_row = aux_row1; const uword lend_row = aux_row1 + n_rows; for(uword r = lstart_row; r < lend_row; ++r) { eT val = m.at(r, in_col1 + aux_col1); access::rw(m).at(r, in_col1 + aux_col1) = m.at(r, in_col2 + aux_col1); access::rw(m).at(r, in_col2 + aux_col1) = val; } } template inline typename SpSubview::iterator SpSubview::begin() { return iterator(*this); } template inline typename SpSubview::const_iterator SpSubview::begin() const { return const_iterator(*this); } template inline typename SpSubview::iterator SpSubview::begin_col(const uword col_num) { return iterator(*this, 0, col_num); } template inline typename SpSubview::const_iterator SpSubview::begin_col(const uword col_num) const { return const_iterator(*this, 0, col_num); } template inline typename SpSubview::row_iterator SpSubview::begin_row(const uword row_num) { return row_iterator(*this, row_num, 0); } template inline typename SpSubview::const_row_iterator SpSubview::begin_row(const uword row_num) const { return const_row_iterator(*this, row_num, 0); } template inline typename SpSubview::iterator SpSubview::end() { return iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero); } template inline typename SpSubview::const_iterator SpSubview::end() const { return const_iterator(*this, 0, n_cols, n_nonzero, m.n_nonzero - n_nonzero); } template inline typename SpSubview::row_iterator SpSubview::end_row() { return row_iterator(*this, n_nonzero); } template inline typename SpSubview::const_row_iterator SpSubview::end_row() const { return const_row_iterator(*this, n_nonzero); } template inline typename SpSubview::row_iterator SpSubview::end_row(const uword row_num) { return row_iterator(*this, row_num + 1, 0); } template inline typename SpSubview::const_row_iterator SpSubview::end_row(const uword row_num) const { return const_row_iterator(*this, row_num + 1, 0); } template inline arma_hot arma_warn_unused eT& SpSubview::add_element(const uword in_row, const uword in_col, const eT in_val) { arma_extra_debug_sigprint(); // This may not actually add an element. const uword old_n_nonzero = m.n_nonzero; eT& retval = access::rw(m).add_element(in_row + aux_row1, in_col + aux_col1, in_val); // Update n_nonzero (if necessary). access::rw(n_nonzero) += (m.n_nonzero - old_n_nonzero); return retval; } template inline void SpSubview::delete_element(const uword in_row, const uword in_col) { arma_extra_debug_sigprint(); // This may not actually delete an element. const uword old_n_nonzero = m.n_nonzero; access::rw(m).delete_element(in_row + aux_row1, in_col + aux_col1); access::rw(n_nonzero) -= (old_n_nonzero - m.n_nonzero); } /** * Sparse subview col * template inline SpSubview_col::SpSubview_col(const Mat& in_m, const uword in_col) { arma_extra_debug_sigprint(); } template inline SpSubview_col::SpSubview_col(Mat& in_m, const uword in_col) { arma_extra_debug_sigprint(); } template inline SpSubview_col::SpSubview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows) { arma_extra_debug_sigprint(); } template inline SpSubview_col::SpSubview_col(Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows) { arma_extra_debug_sigprint(); } */ /** * Sparse subview row * template inline SpSubview_row::SpSubview_row(const Mat& in_m, const uword in_row) { arma_extra_debug_sigprint(); } template inline SpSubview_row::SpSubview_row(Mat& in_m, const uword in_row) { arma_extra_debug_sigprint(); } template inline SpSubview_row::SpSubview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols) { arma_extra_debug_sigprint(); } template inline SpSubview_row::SpSubview_row(Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols) { arma_extra_debug_sigprint(); } */ //! @} armadillo-6.500.5/include/armadillo_bits/operator_cube_div.hpp0000666000000000000000000001012412620272703023150 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup operator_cube_div //! @{ //! BaseCube / scalar template arma_inline const eOpCube operator/ ( const BaseCube& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! scalar / BaseCube template arma_inline const eOpCube operator/ ( const typename T1::elem_type k, const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! complex scalar / non-complex BaseCube (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_div_pre> operator/ ( const std::complex& k, const BaseCube& X ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_div_pre>('j', X.get_ref(), k); } //! non-complex BaseCube / complex scalar (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_div_post> operator/ ( const BaseCube& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_div_post>('j', X.get_ref(), k); } //! element-wise division of BaseCube objects with same element type template arma_inline const eGlueCube operator/ ( const BaseCube& X, const BaseCube& Y ) { arma_extra_debug_sigprint(); return eGlueCube(X.get_ref(), Y.get_ref()); } //! element-wise division of BaseCube objects with different element types template inline const mtGlueCube::result, T1, T2, glue_mixed_div> operator/ ( const BaseCube< typename force_different_type::T1_result, T1>& X, const BaseCube< typename force_different_type::T2_result, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template arma_inline Cube operator/ ( const subview_cube_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_cube_each1_aux::operator_div(X, Y.get_ref()); } template arma_inline Cube operator/ ( const Base& X, const subview_cube_each1& Y ) { arma_extra_debug_sigprint(); return subview_cube_each1_aux::operator_div(X.get_ref(), Y); } template arma_inline Cube operator/ ( const subview_cube_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_cube_each2_aux::operator_div(X, Y.get_ref()); } template arma_inline Cube operator/ ( const Base& X, const subview_cube_each2& Y ) { arma_extra_debug_sigprint(); return subview_cube_each2_aux::operator_div(X.get_ref(), Y); } //! @} armadillo-6.500.5/include/armadillo_bits/op_chol_meat.hpp0000666000000000000000000000136612620272703022116 0ustar rootroot// Copyright (C) 2008-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_chol //! @{ template inline void op_chol::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); const bool status = auxlib::chol(out, X.m, X.aux_uword_a); if(status == false) { out.reset(); arma_bad("chol(): decomposition failed"); } } //! @} armadillo-6.500.5/include/armadillo_bits/subview_cube_meat.hpp0000666000000000000000000015514012651566055023167 0ustar rootroot// Copyright (C) 2008-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_cube //! @{ template inline subview_cube::~subview_cube() { arma_extra_debug_sigprint(); } template arma_inline subview_cube::subview_cube ( const Cube& in_m, const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_n_rows, const uword in_n_cols, const uword in_n_slices ) : m (in_m) , aux_row1 (in_row1) , aux_col1 (in_col1) , aux_slice1 (in_slice1) , n_rows (in_n_rows) , n_cols (in_n_cols) , n_elem_slice(in_n_rows * in_n_cols) , n_slices (in_n_slices) , n_elem (n_elem_slice * in_n_slices) { arma_extra_debug_sigprint(); } template inline void subview_cube::operator= (const eT val) { arma_extra_debug_sigprint(); if(n_elem != 1) { arma_debug_assert_same_size(n_rows, n_cols, n_slices, 1, 1, 1, "copy into subcube"); } Cube& Q = const_cast< Cube& >(m); Q.at(aux_row1, aux_col1, aux_slice1) = val; } template inline void subview_cube::operator+= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_plus( slice_colptr(slice,col), val, local_n_rows ); } } } template inline void subview_cube::operator-= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_minus( slice_colptr(slice,col), val, local_n_rows ); } } } template inline void subview_cube::operator*= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_mul( slice_colptr(slice,col), val, local_n_rows ); } } } template inline void subview_cube::operator/= (const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_div( slice_colptr(slice,col), val, local_n_rows ); } } } template template inline void subview_cube::operator= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "copy into subcube"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template template inline void subview_cube::operator+= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "addition"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template template inline void subview_cube::operator-= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "subtraction"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template template inline void subview_cube::operator%= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "element-wise multiplication"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template template inline void subview_cube::operator/= (const BaseCube& in) { arma_extra_debug_sigprint(); const unwrap_cube tmp(in.get_ref()); const Cube& x = tmp.M; subview_cube& t = *this; arma_debug_assert_same_size(t, x, "element-wise division"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } //! x.subcube(...) = y.subcube(...) template inline void subview_cube::operator= (const subview_cube& x) { arma_extra_debug_sigprint(); if(check_overlap(x)) { const Cube tmp(x); (*this).operator=(tmp); return; } subview_cube& t = *this; arma_debug_assert_same_size(t, x, "copy into subcube"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template inline void subview_cube::operator+= (const subview_cube& x) { arma_extra_debug_sigprint(); if(check_overlap(x)) { const Cube tmp(x); (*this).operator+=(tmp); return; } subview_cube& t = *this; arma_debug_assert_same_size(t, x, "addition"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template inline void subview_cube::operator-= (const subview_cube& x) { arma_extra_debug_sigprint(); if(check_overlap(x)) { const Cube tmp(x); (*this).operator-=(tmp); return; } subview_cube& t = *this; arma_debug_assert_same_size(t, x, "subtraction"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template inline void subview_cube::operator%= (const subview_cube& x) { arma_extra_debug_sigprint(); if(check_overlap(x)) { const Cube tmp(x); (*this).operator%=(tmp); return; } subview_cube& t = *this; arma_debug_assert_same_size(t, x, "element-wise multiplication"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template inline void subview_cube::operator/= (const subview_cube& x) { arma_extra_debug_sigprint(); if(check_overlap(x)) { const Cube tmp(x); (*this).operator/=(tmp); return; } subview_cube& t = *this; arma_debug_assert_same_size(t, x, "element-wise division"); const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; for(uword slice = 0; slice < t_n_slices; ++slice) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); } } } template template inline void subview_cube::operator= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( ((x_n_rows == 1) || (x_n_cols == 1)) && (t_n_rows == 1) && (t_n_cols == 1) && (x.n_elem == t_n_slices) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; const eT* x_mem = x.memptr(); uword i,j; for(i=0, j=1; j < t_n_slices; i+=2, j+=2) { const eT tmp_i = x_mem[i]; const eT tmp_j = x_mem[j]; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) = tmp_i; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + j) = tmp_j; } if(i < t_n_slices) { Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) = x_mem[i]; } } else if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { // interpret the matrix as a cube with one slice for(uword col = 0; col < t_n_cols; ++col) { arrayops::copy( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::copy( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) = tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "copy into subcube") ); } } } template template inline void subview_cube::operator+= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( ((x_n_rows == 1) || (x_n_cols == 1)) && (t_n_rows == 1) && (t_n_cols == 1) && (x.n_elem == t_n_slices) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; const eT* x_mem = x.memptr(); uword i,j; for(i=0, j=1; j < t_n_slices; i+=2, j+=2) { const eT tmp_i = x_mem[i]; const eT tmp_j = x_mem[j]; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) += tmp_i; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + j) += tmp_j; } if(i < t_n_slices) { Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) += x_mem[i]; } } else if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_plus( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::inplace_plus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) += tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "addition") ); } } } template template inline void subview_cube::operator-= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( ((x_n_rows == 1) || (x_n_cols == 1)) && (t_n_rows == 1) && (t_n_cols == 1) && (x.n_elem == t_n_slices) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; const eT* x_mem = x.memptr(); uword i,j; for(i=0, j=1; j < t_n_slices; i+=2, j+=2) { const eT tmp_i = x_mem[i]; const eT tmp_j = x_mem[j]; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) -= tmp_i; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + j) -= tmp_j; } if(i < t_n_slices) { Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) -= x_mem[i]; } } else if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_minus( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::inplace_minus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) -= tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "subtraction") ); } } } template template inline void subview_cube::operator%= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( ((x_n_rows == 1) || (x_n_cols == 1)) && (t_n_rows == 1) && (t_n_cols == 1) && (x.n_elem == t_n_slices) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; const eT* x_mem = x.memptr(); uword i,j; for(i=0, j=1; j < t_n_slices; i+=2, j+=2) { const eT tmp_i = x_mem[i]; const eT tmp_j = x_mem[j]; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) *= tmp_i; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + j) *= tmp_j; } if(i < t_n_slices) { Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) *= x_mem[i]; } } else if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_mul( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::inplace_mul( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) *= tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "element-wise multiplication") ); } } } template template inline void subview_cube::operator/= (const Base& in) { arma_extra_debug_sigprint(); const unwrap tmp(in.get_ref()); const Mat& x = tmp.M; subview_cube& t = *this; const uword t_n_rows = t.n_rows; const uword t_n_cols = t.n_cols; const uword t_n_slices = t.n_slices; const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; if( ((x_n_rows == 1) || (x_n_cols == 1)) && (t_n_rows == 1) && (t_n_cols == 1) && (x.n_elem == t_n_slices) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; const eT* x_mem = x.memptr(); uword i,j; for(i=0, j=1; j < t_n_slices; i+=2, j+=2) { const eT tmp_i = x_mem[i]; const eT tmp_j = x_mem[j]; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) /= tmp_i; Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + j) /= tmp_j; } if(i < t_n_slices) { Q.at(t_aux_row1, t_aux_col1, t_aux_slice1 + i) /= x_mem[i]; } } else if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) { for(uword col = 0; col < t_n_cols; ++col) { arrayops::inplace_div( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); } } else if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) { for(uword i=0; i < t_n_slices; ++i) { arrayops::inplace_div( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); } } else if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) { Cube& Q = const_cast< Cube& >(t.m); const uword t_aux_row1 = t.aux_row1; const uword t_aux_col1 = t.aux_col1; const uword t_aux_slice1 = t.aux_slice1; for(uword slice=0; slice < t_n_slices; ++slice) { const uword mod_slice = t_aux_slice1 + slice; const eT* x_colptr = x.colptr(slice); uword i,j; for(i=0, j=1; j < t_n_cols; i+=2, j+=2) { const eT tmp_i = x_colptr[i]; const eT tmp_j = x_colptr[j]; Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= tmp_i; Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) /= tmp_j; } if(i < t_n_cols) { Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= x_colptr[i]; } } } else { if(arma_config::debug == true) { arma_stop( arma_incompat_size_string(t, x, "element-wise division") ); } } } //! apply a functor to each element template template inline void subview_cube::for_each(functor F) { arma_extra_debug_sigprint(); Cube& Q = const_cast< Cube& >(m); const uword start_col = aux_col1; const uword start_row = aux_row1; const uword start_slice = aux_slice1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; const uword end_slice_plus1 = start_slice + n_slices; for(uword uslice = start_slice; uslice < end_slice_plus1; ++uslice) for(uword ucol = start_col; ucol < end_col_plus1; ++ucol ) for(uword urow = start_row; urow < end_row_plus1; ++urow ) { F( Q.at(urow, ucol, uslice) ); } } template template inline void subview_cube::for_each(functor F) const { arma_extra_debug_sigprint(); const Cube& Q = m; const uword start_col = aux_col1; const uword start_row = aux_row1; const uword start_slice = aux_slice1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; const uword end_slice_plus1 = start_slice + n_slices; for(uword uslice = start_slice; uslice < end_slice_plus1; ++uslice) for(uword ucol = start_col; ucol < end_col_plus1; ++ucol ) for(uword urow = start_row; urow < end_row_plus1; ++urow ) { F( Q.at(urow, ucol, uslice) ); } } //! transform each element in the subview using a functor template template inline void subview_cube::transform(functor F) { arma_extra_debug_sigprint(); Cube& Q = const_cast< Cube& >(m); const uword start_col = aux_col1; const uword start_row = aux_row1; const uword start_slice = aux_slice1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; const uword end_slice_plus1 = start_slice + n_slices; for(uword uslice = start_slice; uslice < end_slice_plus1; ++uslice) for(uword ucol = start_col; ucol < end_col_plus1; ++ucol ) for(uword urow = start_row; urow < end_row_plus1; ++urow ) { Q.at(urow, ucol, uslice) = eT( F( Q.at(urow, ucol, uslice) ) ); } } //! imbue (fill) the subview with values provided by a functor template template inline void subview_cube::imbue(functor F) { arma_extra_debug_sigprint(); Cube& Q = const_cast< Cube& >(m); const uword start_col = aux_col1; const uword start_row = aux_row1; const uword start_slice = aux_slice1; const uword end_col_plus1 = start_col + n_cols; const uword end_row_plus1 = start_row + n_rows; const uword end_slice_plus1 = start_slice + n_slices; for(uword uslice = start_slice; uslice < end_slice_plus1; ++uslice) for(uword ucol = start_col; ucol < end_col_plus1; ++ucol ) for(uword urow = start_row; urow < end_row_plus1; ++urow ) { Q.at(urow, ucol, uslice) = eT( F() ); } } #if defined(ARMA_USE_CXX11) //! apply a lambda function to each slice, where each slice is interpreted as a matrix template inline void subview_cube::each_slice(const std::function< void(Mat&) >& F) { arma_extra_debug_sigprint(); Mat tmp1(n_rows, n_cols); Mat tmp2('j', tmp1.memptr(), n_rows, n_cols); for(uword slice_id=0; slice_id < n_slices; ++slice_id) { for(uword col_id=0; col_id < n_cols; ++col_id) { arrayops::copy( tmp1.colptr(col_id), slice_colptr(slice_id, col_id), n_rows ); } F(tmp2); for(uword col_id=0; col_id < n_cols; ++col_id) { arrayops::copy( slice_colptr(slice_id, col_id), tmp1.colptr(col_id), n_rows ); } } } template inline void subview_cube::each_slice(const std::function< void(const Mat&) >& F) const { arma_extra_debug_sigprint(); Mat tmp1(n_rows, n_cols); const Mat tmp2('j', tmp1.memptr(), n_rows, n_cols); for(uword slice_id=0; slice_id < n_slices; ++slice_id) { for(uword col_id=0; col_id < n_cols; ++col_id) { arrayops::copy( tmp1.colptr(col_id), slice_colptr(slice_id, col_id), n_rows ); } F(tmp2); } } #endif template inline void subview_cube::fill(const eT val) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::inplace_set( slice_colptr(slice,col), val, local_n_rows ); } } } template inline void subview_cube::zeros() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arrayops::fill_zeros( slice_colptr(slice,col), local_n_rows ); } } } template inline void subview_cube::ones() { arma_extra_debug_sigprint(); fill(eT(1)); } template inline void subview_cube::randu() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arma_rng::randu::fill( slice_colptr(slice,col), local_n_rows ); } } } template inline void subview_cube::randn() { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { arma_rng::randn::fill( slice_colptr(slice,col), local_n_rows ); } } } template inline arma_warn_unused bool subview_cube::is_finite() const { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { if(arrayops::is_finite(slice_colptr(slice,col), local_n_rows) == false) { return false; } } } return true; } template inline arma_warn_unused bool subview_cube::has_inf() const { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { if(arrayops::has_inf(slice_colptr(slice,col), local_n_rows)) { return true; } } } return false; } template inline arma_warn_unused bool subview_cube::has_nan() const { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; for(uword slice = 0; slice < local_n_slices; ++slice) { for(uword col = 0; col < local_n_cols; ++col) { if(arrayops::has_nan(slice_colptr(slice,col), local_n_rows)) { return true; } } } return false; } template inline arma_warn_unused eT subview_cube::min() const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "subview_cube::min(): object has no elements"); return Datum::nan; } const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; eT min_val = at(0,0,0); for(uword si=0; si < local_n_slices; ++si) for(uword ci=0; ci < local_n_cols; ++ci) { min_val = (std::min)( min_val, op_min::direct_min(slice_colptr(si,ci), local_n_rows) ); } return min_val; } template inline arma_warn_unused eT subview_cube::max() const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "subview_cube::max(): object has no elements"); return Datum::nan; } const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; eT max_val = at(0,0,0); for(uword si=0; si < local_n_slices; ++si) for(uword ci=0; ci < local_n_cols; ++ci) { max_val = (std::max)( max_val, op_max::direct_max(slice_colptr(si,ci), local_n_rows) ); } return max_val; } template inline eT subview_cube::at_alt(const uword i) const { return operator[](i); } template inline eT& subview_cube::operator[](const uword i) { const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Cube& >(m)).mem[index] ); } template inline eT subview_cube::operator[](const uword i) const { const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template inline eT& subview_cube::operator()(const uword i) { arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds" ); const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Cube& >(m)).mem[index] ); } template inline eT subview_cube::operator()(const uword i) const { arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds" ); const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; const uword in_col = j / n_rows; const uword in_row = j % n_rows; const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template arma_inline eT& subview_cube::operator()(const uword in_row, const uword in_col, const uword in_slice) { arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds" ); const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Cube& >(m)).mem[index] ); } template arma_inline eT subview_cube::operator()(const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds" ); const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template arma_inline eT& subview_cube::at(const uword in_row, const uword in_col, const uword in_slice) { const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return access::rw( (const_cast< Cube& >(m)).mem[index] ); } template arma_inline eT subview_cube::at(const uword in_row, const uword in_col, const uword in_slice) const { const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; return m.mem[index]; } template arma_inline eT* subview_cube::slice_colptr(const uword in_slice, const uword in_col) { return & access::rw((const_cast< Cube& >(m)).mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ]); } template arma_inline const eT* subview_cube::slice_colptr(const uword in_slice, const uword in_col) const { return & m.mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ]; } template inline bool subview_cube::check_overlap(const subview_cube& x) const { const subview_cube& t = *this; if(&t.m != &x.m) { return false; } else { if( (t.n_elem == 0) || (x.n_elem == 0) ) { return false; } else { const uword t_row_start = t.aux_row1; const uword t_row_end_p1 = t_row_start + t.n_rows; const uword t_col_start = t.aux_col1; const uword t_col_end_p1 = t_col_start + t.n_cols; const uword t_slice_start = t.aux_slice1; const uword t_slice_end_p1 = t_slice_start + t.n_slices; const uword x_row_start = x.aux_row1; const uword x_row_end_p1 = x_row_start + x.n_rows; const uword x_col_start = x.aux_col1; const uword x_col_end_p1 = x_col_start + x.n_cols; const uword x_slice_start = x.aux_slice1; const uword x_slice_end_p1 = x_slice_start + x.n_slices; const bool outside_rows = ( (x_row_start >= t_row_end_p1 ) || (t_row_start >= x_row_end_p1 ) ); const bool outside_cols = ( (x_col_start >= t_col_end_p1 ) || (t_col_start >= x_col_end_p1 ) ); const bool outside_slices = ( (x_slice_start >= t_slice_end_p1) || (t_slice_start >= x_slice_end_p1) ); return ( (outside_rows == false) && (outside_cols == false) && (outside_slices == false) ); } } } template inline bool subview_cube::check_overlap(const Mat& x) const { const subview_cube& t = *this; const uword t_aux_slice1 = t.aux_slice1; const uword t_aux_slice2_plus_1 = t_aux_slice1 + t.n_slices; for(uword slice = t_aux_slice1; slice < t_aux_slice2_plus_1; ++slice) { if(t.m.mat_ptrs[slice] != NULL) { const Mat& y = *(t.m.mat_ptrs[slice]); if( x.memptr() == y.memptr() ) { return true; } } } return false; } //! cube X = Y.subcube(...) template inline void subview_cube::extract(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Cube contructor or operator=() const uword n_rows = in.n_rows; const uword n_cols = in.n_cols; const uword n_slices = in.n_slices; arma_extra_debug_print(arma_str::format("out.n_rows = %d out.n_cols = %d out.n_slices = %d in.m.n_rows = %d in.m.n_cols = %d in.m.n_slices = %d") % out.n_rows % out.n_cols % out.n_slices % in.m.n_rows % in.m.n_cols % in.m.n_slices); for(uword slice = 0; slice < n_slices; ++slice) { for(uword col = 0; col < n_cols; ++col) { arrayops::copy( out.slice_colptr(slice,col), in.slice_colptr(slice,col), n_rows ); } } } //! cube X += Y.subcube(...) template inline void subview_cube::plus_inplace(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "addition"); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; const uword n_slices = out.n_slices; for(uword slice = 0; slice inline void subview_cube::minus_inplace(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "subtraction"); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; const uword n_slices = out.n_slices; for(uword slice = 0; slice inline void subview_cube::schur_inplace(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "element-wise multiplication"); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; const uword n_slices = out.n_slices; for(uword slice = 0; slice inline void subview_cube::div_inplace(Cube& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out, in, "element-wise division"); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; const uword n_slices = out.n_slices; for(uword slice = 0; slice inline void subview_cube::extract(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { out.set_size(in_n_rows, in_n_cols); for(uword col=0; col < in_n_cols; ++col) { arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if(in_n_cols == 1) { out.set_size(in_n_rows, in_n_slices); for(uword i=0; i < in_n_slices; ++i) { arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if(in_n_rows == 1) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; out.set_size(in_n_cols, in_n_slices); for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] = tmp_i; out_colptr[j] = tmp_j; } if(i < in_n_cols) { out_colptr[i] = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { out.set_size(in_n_slices); eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i inline void subview_cube::plus_inplace(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "addition", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { if( (arma_config::debug) && ((out_n_rows != in_n_rows) || (out_n_cols != in_n_cols)) ) { std::stringstream tmp; tmp << "in-place addition: " << out_n_rows << 'x' << out_n_cols << " output matrix is incompatible with " << in_n_rows << 'x' << in_n_cols << 'x' << in_n_slices << " cube interpreted as " << in_n_rows << 'x' << in_n_cols << " matrix"; arma_stop(tmp.str()); } for(uword col=0; col < in_n_cols; ++col) { arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] += tmp_i; out_colptr[j] += tmp_j; } if(i < in_n_cols) { out_colptr[i] += Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i inline void subview_cube::minus_inplace(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "subtraction", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { if( (arma_config::debug) && ((out_n_rows != in_n_rows) || (out_n_cols != in_n_cols)) ) { std::stringstream tmp; tmp << "in-place subtraction: " << out_n_rows << 'x' << out_n_cols << " output matrix is incompatible with " << in_n_rows << 'x' << in_n_cols << 'x' << in_n_slices << " cube interpreted as " << in_n_rows << 'x' << in_n_cols << " matrix"; arma_stop(tmp.str()); } for(uword col=0; col < in_n_cols; ++col) { arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] -= tmp_i; out_colptr[j] -= tmp_j; } if(i < in_n_cols) { out_colptr[i] -= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i inline void subview_cube::schur_inplace(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { if( (arma_config::debug) && ((out_n_rows != in_n_rows) || (out_n_cols != in_n_cols)) ) { std::stringstream tmp; tmp << "in-place element-wise multiplication: " << out_n_rows << 'x' << out_n_cols << " output matrix is incompatible with " << in_n_rows << 'x' << in_n_cols << 'x' << in_n_slices << " cube interpreted as " << in_n_rows << 'x' << in_n_cols << " matrix"; arma_stop(tmp.str()); } for(uword col=0; col < in_n_cols; ++col) { arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] *= tmp_i; out_colptr[j] *= tmp_j; } if(i < in_n_cols) { out_colptr[i] *= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i inline void subview_cube::div_inplace(Mat& out, const subview_cube& in) { arma_extra_debug_sigprint(); arma_debug_assert_cube_as_mat(out, in, "element-wise division", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { if( (arma_config::debug) && ((out_n_rows != in_n_rows) || (out_n_cols != in_n_cols)) ) { std::stringstream tmp; tmp << "in-place element-wise division: " << out_n_rows << 'x' << out_n_cols << " output matrix is incompatible with " << in_n_rows << 'x' << in_n_cols << 'x' << in_n_slices << " cube interpreted as " << in_n_rows << 'x' << in_n_cols << " matrix"; arma_stop(tmp.str()); } for(uword col=0; col < in_n_cols; ++col) { arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword slice=0; slice < in_n_slices; ++slice) { const uword mod_slice = in_aux_slice1 + slice; eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); out_colptr[i] /= tmp_i; out_colptr[j] /= tmp_j; } if(i < in_n_cols) { out_colptr[i] /= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); } } } } else { eT* out_mem = out.memptr(); const Cube& Q = in.m; const uword in_aux_row1 = in.aux_row1; const uword in_aux_col1 = in.aux_col1; const uword in_aux_slice1 = in.aux_slice1; for(uword i=0; i inline SpCol::SpCol() : SpMat(0, 1) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; } //! construct a column vector with the specified number of elements template inline SpCol::SpCol(const uword in_n_elem) : SpMat(in_n_elem, 1) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; } template inline SpCol::SpCol(const uword in_n_rows, const uword in_n_cols) : SpMat(in_n_rows, in_n_cols) { arma_extra_debug_sigprint(); arma_debug_check((in_n_cols != 1), "SpCol::SpCol(): must have only one column"); access::rw(SpMat::vec_state) = 1; } //! construct a column vector from specified text template inline SpCol::SpCol(const char* text) : SpMat(text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; arma_debug_check((SpMat::n_cols != 1), "SpCol::SpCol(): must have only one column"); } //! construct a column vector from specified text template inline const SpCol& SpCol::operator=(const char* text) { arma_extra_debug_sigprint(); SpMat::init(std::string(text)); access::rw(SpMat::vec_state) = 1; return *this; } //! construct a column vector from specified text template inline SpCol::SpCol(const std::string& text) : SpMat(text) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; arma_debug_check((SpMat::n_cols != 1), "SpCol::SpCol(): must have only one column"); } //! construct a column vector from specified text template inline const SpCol& SpCol::operator=(const std::string& text) { arma_extra_debug_sigprint(); SpMat::init(std::string(text)); return *this; } template inline const SpCol& SpCol::operator=(const eT val) { arma_extra_debug_sigprint(); SpMat::operator=(val); return *this; } template template inline SpCol::SpCol(const Base& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::operator=(X.get_ref()); } template template inline const SpCol& SpCol::operator=(const Base& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::operator=(X.get_ref()); return *this; } template template inline SpCol::SpCol(const SpBase& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::operator=(X.get_ref()); } template template inline const SpCol& SpCol::operator=(const SpBase& X) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::operator=(X.get_ref()); return *this; } template template inline SpCol::SpCol ( const SpBase::pod_type, T1>& A, const SpBase::pod_type, T2>& B ) { arma_extra_debug_sigprint(); access::rw(SpMat::vec_state) = 1; SpMat::init(A,B); } //! remove specified row template inline void SpCol::shed_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= SpMat::n_rows, "SpCol::shed_row(): out of bounds"); shed_rows(row_num, row_num); } //! remove specified rows template inline void SpCol::shed_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= SpMat::n_rows), "SpCol::shed_rows(): indices out of bounds or incorrectly used" ); const uword diff = (in_row2 - in_row1 + 1); // This is easy because everything is in one column. uword start = 0, end = 0; bool start_found = false, end_found = false; for(uword i = 0; i < SpMat::n_nonzero; ++i) { // Start position found? if (SpMat::row_indices[i] >= in_row1 && !start_found) { start = i; start_found = true; } // End position found? if (SpMat::row_indices[i] > in_row2) { end = i; end_found = true; break; } } if (!end_found) { end = SpMat::n_nonzero; } // Now we can make the copy. if (start != end) { const uword elem_diff = end - start; eT* new_values = memory::acquire_chunked (SpMat::n_nonzero - elem_diff); uword* new_row_indices = memory::acquire_chunked(SpMat::n_nonzero - elem_diff); // Copy before the section we are dropping (if it exists). if (start > 0) { arrayops::copy(new_values, SpMat::values, start); arrayops::copy(new_row_indices, SpMat::row_indices, start); } // Copy after the section we are dropping (if it exists). if (end != SpMat::n_nonzero) { arrayops::copy(new_values + start, SpMat::values + end, (SpMat::n_nonzero - end)); arrayops::copy(new_row_indices + start, SpMat::row_indices + end, (SpMat::n_nonzero - end)); arrayops::inplace_minus(new_row_indices + start, diff, (SpMat::n_nonzero - end)); } memory::release(SpMat::values); memory::release(SpMat::row_indices); access::rw(SpMat::values) = new_values; access::rw(SpMat::row_indices) = new_row_indices; access::rw(SpMat::n_nonzero) -= elem_diff; access::rw(SpMat::col_ptrs[1]) -= elem_diff; } access::rw(SpMat::n_rows) -= diff; access::rw(SpMat::n_elem) -= diff; } // //! insert N rows at the specified row position, // //! optionally setting the elements of the inserted rows to zero // template // inline // void // SpCol::insert_rows(const uword row_num, const uword N, const bool set_to_zero) // { // arma_extra_debug_sigprint(); // // arma_debug_check(set_to_zero == false, "SpCol::insert_rows(): cannot set nonzero values"); // // arma_debug_check((row_num > SpMat::n_rows), "SpCol::insert_rows(): out of bounds"); // // for(uword row = 0; row < SpMat::n_rows; ++row) // { // if (SpMat::row_indices[row] >= row_num) // { // access::rw(SpMat::row_indices[row]) += N; // } // } // // access::rw(SpMat::n_rows) += N; // access::rw(SpMat::n_elem) += N; // } template inline typename SpCol::row_iterator SpCol::begin_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= SpMat::n_rows), "SpCol::begin_row(): index out of bounds"); return row_iterator(*this, row_num, 0); } template inline typename SpCol::const_row_iterator SpCol::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= SpMat::n_rows), "SpCol::begin_row(): index out of bounds"); return const_row_iterator(*this, row_num, 0); } template inline typename SpCol::row_iterator SpCol::end_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= SpMat::n_rows), "SpCol::end_row(): index out of bounds"); return row_iterator(*this, row_num + 1, 0); } template inline typename SpCol::const_row_iterator SpCol::end_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= SpMat::n_rows), "SpCol::end_row(): index out of bounds"); return const_row_iterator(*this, row_num + 1, 0); } #ifdef ARMA_EXTRA_SPCOL_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_SPCOL_MEAT) #endif //! @} armadillo-6.500.5/include/armadillo_bits/glue_cor_bones.hpp0000666000000000000000000000174112620272703022447 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas // // ------------------------------------------------------------------- // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. //! \addtogroup glue_cor //! @{ class glue_cor { public: template inline static void direct_cor(Mat& out, const Mat& A, const Mat& B, const uword norm_type); template inline static void direct_cor(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type); template inline static void apply(Mat& out, const Glue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/arma_static_check.hpp0000666000000000000000000000232312620272703023103 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arma_static_check //! @{ template struct arma_type_check_cxx1998 { arma_inline static void apply() { static const char junk[ ERROR___INCORRECT_OR_UNSUPPORTED_TYPE ? -1 : +1 ]; } }; template<> struct arma_type_check_cxx1998 { arma_inline static void apply() { } }; #if defined(ARMA_USE_CXX11) #define arma_static_check(condition, message) static_assert( !(condition), #message ) #define arma_type_check(condition) static_assert( !(condition), "error: incorrect or unsupported type" ) #else #define arma_static_check(condition, message) static const char message[ (condition) ? -1 : +1 ] #define arma_type_check(condition) arma_type_check_cxx1998::apply() #endif //! @} armadillo-6.500.5/include/armadillo_bits/glue_times_bones.hpp0000666000000000000000000001071312620272703023004 0ustar rootroot// Copyright (C) 2008-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_times //! @{ //! \brief //! Template metaprogram depth_lhs //! calculates the number of Glue instances on the left hand side argument of Glue //! i.e. it recursively expands each Tx, until the type of Tx is not "Glue<..,.., glue_type>" (i.e the "glue_type" changes) template struct depth_lhs { static const uword num = 0; }; template struct depth_lhs< glue_type, Glue > { static const uword num = 1 + depth_lhs::num; }; template struct glue_times_redirect2_helper { template arma_hot inline static void apply(Mat& out, const Glue& X); }; template<> struct glue_times_redirect2_helper { template arma_hot inline static void apply(Mat& out, const Glue& X); }; template struct glue_times_redirect3_helper { template arma_hot inline static void apply(Mat& out, const Glue< Glue,T3,glue_times>& X); }; template<> struct glue_times_redirect3_helper { template arma_hot inline static void apply(Mat& out, const Glue< Glue,T3,glue_times>& X); }; template struct glue_times_redirect { template arma_hot inline static void apply(Mat& out, const Glue& X); }; template<> struct glue_times_redirect<2> { template arma_hot inline static void apply(Mat& out, const Glue& X); }; template<> struct glue_times_redirect<3> { template arma_hot inline static void apply(Mat& out, const Glue< Glue,T3,glue_times>& X); }; template<> struct glue_times_redirect<4> { template arma_hot inline static void apply(Mat& out, const Glue< Glue< Glue, T3, glue_times>, T4, glue_times>& X); }; //! Class which implements the immediate multiplication of two or more matrices class glue_times { public: template arma_hot inline static void apply(Mat& out, const Glue& X); template arma_hot inline static void apply_inplace(Mat& out, const T1& X); template arma_hot inline static void apply_inplace_plus(Mat& out, const Glue& X, const sword sign); // template arma_inline static uword mul_storage_cost(const TA& A, const TB& B); template arma_hot inline static void apply(Mat& out, const TA& A, const TB& B, const eT val); template arma_hot inline static void apply(Mat& out, const TA& A, const TB& B, const TC& C, const eT val); template arma_hot inline static void apply(Mat& out, const TA& A, const TB& B, const TC& C, const TD& D, const eT val); }; class glue_times_diag { public: template arma_hot inline static void apply(Mat& out, const Glue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/mtGlue_bones.hpp0000666000000000000000000000332412620272703022104 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup mtGlue //! @{ template class mtGlue : public Base > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = \ ( ((T1::is_row || T2::is_row) && is_glue_mixed_elem::value) || (T1::is_row && is_glue_mixed_times::value) || (T1::is_row && is_same_type::yes) || (T1::is_row && is_same_type::yes) ); static const bool is_col = \ ( ((T1::is_col || T2::is_col) && is_glue_mixed_elem::value) || (T2::is_col && is_glue_mixed_times::value) || (T1::is_col && is_same_type::yes) || (T1::is_col && is_same_type::yes) ); arma_inline mtGlue(const T1& in_A, const T2& in_B); arma_inline mtGlue(const T1& in_A, const T2& in_B, const uword in_aux_uword); arma_inline ~mtGlue(); arma_aligned const T1& A; //!< first operand arma_aligned const T2& B; //!< second operand arma_aligned uword aux_uword; //!< storage of auxiliary data, uword format }; //! @} armadillo-6.500.5/include/armadillo_bits/SizeCube_meat.hpp0000666000000000000000000000645212620272703022205 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup SizeCube //! @{ inline SizeCube::SizeCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) : n_rows (in_n_rows ) , n_cols (in_n_cols ) , n_slices(in_n_slices) { arma_extra_debug_sigprint(); } inline uword SizeCube::operator[](const uword dim) const { if(dim == 0) { return n_rows; } if(dim == 1) { return n_cols; } if(dim == 2) { return n_slices; } return ( (n_rows == 0) || (n_cols == 0) || (n_slices == 0) ) ? uword(0) : uword(1); } inline uword SizeCube::operator()(const uword dim) const { if(dim == 0) { return n_rows; } if(dim == 1) { return n_cols; } if(dim == 2) { return n_slices; } arma_debug_check(true, "size(): index out of bounds"); return ( (n_rows == 0) || (n_cols == 0) || (n_slices == 0) ) ? uword(0) : uword(1); } inline bool SizeCube::operator==(const SizeCube& s) const { if(n_rows != s.n_rows ) { return false; } if(n_cols != s.n_cols ) { return false; } if(n_slices != s.n_slices) { return false; } return true; } inline bool SizeCube::operator!=(const SizeCube& s) const { if(n_rows != s.n_rows ) { return true; } if(n_cols != s.n_cols ) { return true; } if(n_slices != s.n_slices) { return true; } return false; } inline SizeCube SizeCube::operator+(const SizeCube& s) const { return SizeCube( (n_rows + s.n_rows), (n_cols + s.n_cols), (n_slices + s.n_slices) ); } inline SizeCube SizeCube::operator-(const SizeCube& s) const { const uword out_n_rows = (n_rows > s.n_rows ) ? (n_rows - s.n_rows ) : uword(0); const uword out_n_cols = (n_cols > s.n_cols ) ? (n_cols - s.n_cols ) : uword(0); const uword out_n_slices = (n_slices > s.n_slices) ? (n_slices - s.n_slices) : uword(0); const uword k = ( (out_n_rows == uword(0)) || (out_n_cols == uword(0)) || (out_n_slices == uword(0)) ) ? uword(0) : uword(1); return SizeCube( (k*out_n_rows), (k*out_n_cols), (k*out_n_slices) ); } inline SizeCube SizeCube::operator+(const uword val) const { return SizeCube( (n_rows + val), (n_cols + val), (n_slices + val) ); } inline SizeCube SizeCube::operator-(const uword val) const { const uword out_n_rows = (n_rows > val) ? (n_rows - val) : uword(0); const uword out_n_cols = (n_cols > val) ? (n_cols - val) : uword(0); const uword out_n_slices = (n_slices > val) ? (n_slices - val) : uword(0); const uword k = ( (out_n_rows == uword(0)) || (out_n_cols == uword(0)) || (out_n_slices == uword(0)) ) ? uword(0) : uword(1); return SizeCube( (k*out_n_rows), (k*out_n_cols), (k*out_n_slices) ); } inline SizeCube SizeCube::operator*(const uword val) const { return SizeCube( (n_rows * val), (n_cols * val), (n_slices * val) ); } inline SizeCube SizeCube::operator/(const uword val) const { return SizeCube( (n_rows / val), (n_cols / val), (n_slices / val) ); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_trunc_log.hpp0000666000000000000000000000304612620272703022141 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_trunc_log //! @{ template inline static typename arma_real_only::result trunc_log(const eT x) { if(std::numeric_limits::is_iec559) { if(x == std::numeric_limits::infinity()) { return Math::log_max(); } else { return (x <= eT(0)) ? Math::log_min() : std::log(x); } } else { return std::log(x); } } template inline static typename arma_integral_only::result trunc_log(const eT x) { return eT( trunc_log( double(x) ) ); } template inline static std::complex trunc_log(const std::complex& x) { return std::complex( trunc_log( std::abs(x) ), std::arg(x) ); } template arma_inline const eOp trunc_log(const Base& A) { arma_extra_debug_sigprint(); return eOp(A.get_ref()); } template arma_inline const eOpCube trunc_log(const BaseCube& A) { arma_extra_debug_sigprint(); return eOpCube(A.get_ref()); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_rank.hpp0000666000000000000000000000270512620272703021101 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas // Written by Stanislav Funiak //! \addtogroup fn_rank //! @{ template inline arma_warn_unused uword rank ( const Base& X, typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; uword X_n_rows; uword X_n_cols; Col s; const bool status = auxlib::svd_dc(s, X, X_n_rows, X_n_cols); if(status == false) { arma_bad("rank(): svd failed"); return uword(0); } const uword s_n_elem = s.n_elem; const T* s_mem = s.memptr(); // set tolerance to default if it hasn't been specified if( (tol == T(0)) && (s_n_elem > 0) ) { tol = (std::max)(X_n_rows, X_n_cols) * s_mem[0] * std::numeric_limits::epsilon(); } uword count = 0; for(uword i=0; i < s_n_elem; ++i) { count += (s_mem[i] > tol) ? uword(1) : uword(0); } return count; } //! @} armadillo-6.500.5/include/armadillo_bits/op_all_meat.hpp0000666000000000000000000002406212620272703021737 0ustar rootroot// Copyright (C) 2013-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_all //! @{ template inline bool op_all::all_vec_helper(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); uword count = 0; if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i inline bool op_all::all_vec_helper ( const mtOp& X, const typename arma_op_rel_only::result junk1, const typename arma_not_cx::result junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy P(X.m); const uword n_elem = P.get_n_elem(); uword count = 0; if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { const eT tmp = Pea[i]; if(is_same_type::yes) { count += (val < tmp) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp < val) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (val > tmp) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp > val) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (val <= tmp) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp <= val) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (val >= tmp) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp >= val) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp == val) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp != val) ? uword(1) : uword(0); } } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT tmp = P.at(row,col); if(is_same_type::yes) { if(val < tmp) { ++count; } } else if(is_same_type::yes) { if(tmp < val) { ++count; } } else if(is_same_type::yes) { if(val > tmp) { ++count; } } else if(is_same_type::yes) { if(tmp > val) { ++count; } } else if(is_same_type::yes) { if(val <= tmp) { ++count; } } else if(is_same_type::yes) { if(tmp <= val) { ++count; } } else if(is_same_type::yes) { if(val >= tmp) { ++count; } } else if(is_same_type::yes) { if(tmp >= val) { ++count; } } else if(is_same_type::yes) { if(tmp == val) { ++count; } } else if(is_same_type::yes) { if(tmp != val) { ++count; } } } } return (n_elem == count); } template inline bool op_all::all_vec_helper ( const mtGlue& X, const typename arma_glue_rel_only::result junk1, const typename arma_not_cx::result junk2, const typename arma_not_cx::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); const uword n_elem = A.get_n_elem(); uword count = 0; const bool prefer_at_accessor = Proxy::prefer_at_accessor || Proxy::prefer_at_accessor; if(prefer_at_accessor == false) { ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); for(uword i=0; i::yes) { count += (tmp1 < tmp2) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp1 > tmp2) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp1 <= tmp2) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp1 >= tmp2) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp1 == tmp2) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp1 != tmp2) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp1 && tmp2) ? uword(1) : uword(0); } else if(is_same_type::yes) { count += (tmp1 || tmp2) ? uword(1) : uword(0); } } } else { const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT1 tmp1 = A.at(row,col); const eT2 tmp2 = B.at(row,col); if(is_same_type::yes) { if(tmp1 < tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 > tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 <= tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 >= tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 == tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 != tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 && tmp2) { ++count; } } else if(is_same_type::yes) { if(tmp1 || tmp2) { ++count; } } } } return (n_elem == count); } template inline bool op_all::all_vec(T1& X) { arma_extra_debug_sigprint(); return op_all::all_vec_helper(X); } template inline void op_all::apply_helper(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); typedef typename Proxy::elem_type eT; if(dim == 0) // traverse rows (ie. process each column) { out.zeros(1, n_cols); if(out.n_elem == 0) { return; } uword* out_mem = out.memptr(); if(is_Mat::stored_type>::value) { const unwrap::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); uword count = 0; for(uword row=0; row < n_rows; ++row) { count += (colmem[row] != eT(0)) ? uword(1) : uword(0); } out_mem[col] = (n_rows == count) ? uword(1) : uword(0); } } else { for(uword col=0; col < n_cols; ++col) { uword count = 0; for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { ++count; } } out_mem[col] = (n_rows == count) ? uword(1) : uword(0); } } } else { out.zeros(n_rows, 1); uword* out_mem = out.memptr(); // internal dual use of 'out': keep the counts for each row if(is_Mat::stored_type>::value) { const unwrap::stored_type> U(P.Q); for(uword col=0; col < n_cols; ++col) { const eT* colmem = U.M.colptr(col); for(uword row=0; row < n_rows; ++row) { out_mem[row] += (colmem[row] != eT(0)) ? uword(1) : uword(0); } } } else { for(uword col=0; col < n_cols; ++col) { for(uword row=0; row < n_rows; ++row) { if(P.at(row,col) != eT(0)) { ++out_mem[row]; } } } } // see what the counts tell us for(uword row=0; row < n_rows; ++row) { out_mem[row] = (n_cols == out_mem[row]) ? uword(1) : uword(0); } } } template inline void op_all::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); const uword dim = X.aux_uword_a; const Proxy P(X.m); if(P.is_alias(out) == false) { op_all::apply_helper(out, P, dim); } else { Mat out2; op_all::apply_helper(out2, P, dim); out.steal_mem(out2); } } //! @} armadillo-6.500.5/include/armadillo_bits/xvec_htrans_bones.hpp0000666000000000000000000000222212620272703023167 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup xvec_htrans //! @{ template class xvec_htrans : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = false; arma_aligned const eT* const mem; const uword n_rows; const uword n_cols; const uword n_elem; inline explicit xvec_htrans(const eT* const in_mem, const uword in_n_rows, const uword in_n_cols); inline void extract(Mat& out) const; inline eT operator[](const uword ii) const; inline eT at_alt (const uword ii) const; inline eT at (const uword in_row, const uword in_col) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/glue_hist_bones.hpp0000666000000000000000000000165412620272703022636 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_hist //! @{ class glue_hist { public: template inline static void apply_noalias(Mat& out, const Mat& X, const Mat& C, const uword dim); template inline static void apply(Mat& out, const mtGlue& expr); }; class glue_hist_default { public: template inline static void apply(Mat& out, const mtGlue& expr); }; //! @} armadillo-6.500.5/include/armadillo_bits/diskio_bones.hpp0000666000000000000000000002632012622013021022116 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ian Cullinan // Written by Ryan Curtin // Written by Szabolcs Horvat //! \addtogroup diskio //! @{ //! class for saving and loading matrices and fields class diskio { public: template inline static std::string gen_txt_header(const Mat& x); template inline static std::string gen_bin_header(const Mat& x); template inline static std::string gen_bin_header(const SpMat& x); template inline static std::string gen_txt_header(const Cube& x); template inline static std::string gen_bin_header(const Cube& x); inline static file_type guess_file_type(std::istream& f); inline arma_cold static std::string gen_tmp_name(const std::string& x); inline arma_cold static bool safe_rename(const std::string& old_name, const std::string& new_name); template inline static bool convert_naninf(eT& val, const std::string& token); template inline static bool convert_naninf(std::complex& val, const std::string& token); // // matrix saving template inline static bool save_raw_ascii (const Mat& x, const std::string& final_name); template inline static bool save_raw_binary (const Mat& x, const std::string& final_name); template inline static bool save_arma_ascii (const Mat& x, const std::string& final_name); template inline static bool save_csv_ascii (const Mat& x, const std::string& final_name); template inline static bool save_arma_binary(const Mat& x, const std::string& final_name); template inline static bool save_pgm_binary (const Mat& x, const std::string& final_name); template inline static bool save_pgm_binary (const Mat< std::complex >& x, const std::string& final_name); template inline static bool save_hdf5_binary(const Mat& x, const std::string& final_name); template inline static bool save_raw_ascii (const Mat& x, std::ostream& f); template inline static bool save_raw_binary (const Mat& x, std::ostream& f); template inline static bool save_arma_ascii (const Mat& x, std::ostream& f); template inline static bool save_csv_ascii (const Mat& x, std::ostream& f); template inline static bool save_arma_binary(const Mat& x, std::ostream& f); template inline static bool save_pgm_binary (const Mat& x, std::ostream& f); template inline static bool save_pgm_binary (const Mat< std::complex >& x, std::ostream& f); // // matrix loading template inline static bool load_raw_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_binary (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_csv_ascii (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_pgm_binary (Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_pgm_binary (Mat< std::complex >& x, const std::string& name, std::string& err_msg); template inline static bool load_hdf5_binary(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect(Mat& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_raw_binary (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_csv_ascii (Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(Mat& x, std::istream& f, std::string& err_msg); template inline static bool load_pgm_binary (Mat& x, std::istream& is, std::string& err_msg); template inline static bool load_pgm_binary (Mat< std::complex >& x, std::istream& is, std::string& err_msg); template inline static bool load_auto_detect(Mat& x, std::istream& f, std::string& err_msg); inline static void pnm_skip_comments(std::istream& f); // // sparse matrix saving template inline static bool save_coord_ascii(const SpMat& x, const std::string& final_name); template inline static bool save_arma_binary(const SpMat& x, const std::string& final_name); template inline static bool save_coord_ascii(const SpMat& x, std::ostream& f); template inline static bool save_coord_ascii(const SpMat< std::complex >& x, std::ostream& f); template inline static bool save_arma_binary(const SpMat& x, std::ostream& f); // // sparse matrix loading template inline static bool load_coord_ascii(SpMat& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(SpMat& x, const std::string& name, std::string& err_msg); template inline static bool load_coord_ascii(SpMat& x, std::istream& f, std::string& err_msg); template inline static bool load_coord_ascii(SpMat< std::complex >& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(SpMat& x, std::istream& f, std::string& err_msg); // // cube saving template inline static bool save_raw_ascii (const Cube& x, const std::string& name); template inline static bool save_raw_binary (const Cube& x, const std::string& name); template inline static bool save_arma_ascii (const Cube& x, const std::string& name); template inline static bool save_arma_binary(const Cube& x, const std::string& name); template inline static bool save_hdf5_binary(const Cube& x, const std::string& name); template inline static bool save_raw_ascii (const Cube& x, std::ostream& f); template inline static bool save_raw_binary (const Cube& x, std::ostream& f); template inline static bool save_arma_ascii (const Cube& x, std::ostream& f); template inline static bool save_arma_binary(const Cube& x, std::ostream& f); // // cube loading template inline static bool load_raw_ascii (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_binary (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_ascii (Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_hdf5_binary(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect(Cube& x, const std::string& name, std::string& err_msg); template inline static bool load_raw_ascii (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_raw_binary (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_ascii (Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_arma_binary(Cube& x, std::istream& f, std::string& err_msg); template inline static bool load_auto_detect(Cube& x, std::istream& f, std::string& err_msg); // // field saving and loading template inline static bool save_arma_binary(const field& x, const std::string& name); template inline static bool save_arma_binary(const field& x, std::ostream& f); template inline static bool load_arma_binary( field& x, const std::string& name, std::string& err_msg); template inline static bool load_arma_binary( field& x, std::istream& f, std::string& err_msg); template inline static bool load_auto_detect( field& x, const std::string& name, std::string& err_msg); template inline static bool load_auto_detect( field& x, std::istream& f, std::string& err_msg); inline static bool save_std_string(const field& x, const std::string& name); inline static bool save_std_string(const field& x, std::ostream& f); inline static bool load_std_string( field& x, const std::string& name, std::string& err_msg); inline static bool load_std_string( field& x, std::istream& f, std::string& err_msg); // // handling of PPM images by cubes template inline static bool save_ppm_binary(const Cube& x, const std::string& final_name); template inline static bool save_ppm_binary(const Cube& x, std::ostream& f); template inline static bool load_ppm_binary( Cube& x, const std::string& final_name, std::string& err_msg); template inline static bool load_ppm_binary( Cube& x, std::istream& f, std::string& err_msg); // // handling of PPM images by fields template inline static bool save_ppm_binary(const field& x, const std::string& final_name); template inline static bool save_ppm_binary(const field& x, std::ostream& f); template inline static bool load_ppm_binary( field& x, const std::string& final_name, std::string& err_msg); template inline static bool load_ppm_binary( field& x, std::istream& f, std::string& err_msg); }; //! @} armadillo-6.500.5/include/armadillo_bits/spop_mean_bones.hpp0000666000000000000000000000336012620272703022630 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_mean //! @{ //! Class for finding mean values of a sparse matrix class spop_mean { public: // Apply mean into an output sparse matrix (or vector). template inline static void apply(SpMat& out, const SpOp& in); template inline static void apply_noalias_fast(SpMat& out, const SpProxy& p, const uword dim); template inline static void apply_noalias_slow(SpMat& out, const SpProxy& p, const uword dim); // Take direct mean of a set of values. Length of array and number of values can be different. template inline static eT direct_mean(const eT* const X, const uword length, const uword N); template inline static eT direct_mean_robust(const eT* const X, const uword length, const uword N); template inline static typename T1::elem_type mean_all(const SpBase& X); // Take the mean using an iterator. template inline static eT iterator_mean(T1& it, const T1& end, const uword n_zero, const eT junk); template inline static eT iterator_mean_robust(T1& it, const T1& end, const uword n_zero, const eT junk); }; //! @} armadillo-6.500.5/include/armadillo_bits/xtrans_mat_bones.hpp0000666000000000000000000000226712620272703023034 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup xtrans_mat //! @{ template class xtrans_mat : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = false; arma_aligned const Mat& X; arma_aligned mutable Mat Y; arma_aligned const uword n_rows; arma_aligned const uword n_cols; arma_aligned const uword n_elem; inline explicit xtrans_mat(const Mat& in_X); inline void extract(Mat& out) const; inline eT operator[](const uword ii) const; inline eT at_alt (const uword ii) const; arma_inline eT at(const uword in_row, const uword in_col) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/op_diagvec_meat.hpp0000666000000000000000000000571512620272703022575 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_diagvec //! @{ template inline void op_diagvec::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword a = X.aux_uword_a; const uword b = X.aux_uword_b; const uword row_offset = (b > 0) ? a : 0; const uword col_offset = (b == 0) ? a : 0; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "diagvec(): requested diagonal is out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); if( (is_Mat::stored_type>::value) && (Proxy::fake_mat == false) ) { op_diagvec::apply_unwrap(out, P.Q, row_offset, col_offset, len); } else { if(P.is_alias(out) == false) { op_diagvec::apply_proxy(out, P, row_offset, col_offset, len); } else { Mat tmp; op_diagvec::apply_proxy(tmp, P, row_offset, col_offset, len); out.steal_mem(tmp); } } } template arma_hot inline void op_diagvec::apply_unwrap(Mat& out, const T1& X, const uword row_offset, const uword col_offset, const uword len) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp_A(X, out); const Mat& A = tmp_A.M; out.set_size(len, 1); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < len; i+=2, j+=2) { const eT tmp_i = A.at( i + row_offset, i + col_offset ); const eT tmp_j = A.at( j + row_offset, j + col_offset ); out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < len) { out_mem[i] = A.at( i + row_offset, i + col_offset ); } } template arma_hot inline void op_diagvec::apply_proxy(Mat& out, const Proxy& P, const uword row_offset, const uword col_offset, const uword len) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; out.set_size(len, 1); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < len; i+=2, j+=2) { const eT tmp_i = P.at( i + row_offset, i + col_offset ); const eT tmp_j = P.at( j + row_offset, j + col_offset ); out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < len) { out_mem[i] = P.at( i + row_offset, i + col_offset ); } } //! @} armadillo-6.500.5/include/armadillo_bits/mtOpCube_bones.hpp0000666000000000000000000000356412620272703022373 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup mtOpCube //! @{ template class mtOpCube : public BaseCube > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; typedef typename T1::elem_type in_eT; inline explicit mtOpCube(const T1& in_m); inline mtOpCube(const T1& in_m, const in_eT in_aux); inline mtOpCube(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline mtOpCube(const T1& in_m, const in_eT in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline mtOpCube(const char junk, const T1& in_m, const out_eT in_aux); inline ~mtOpCube(); arma_aligned const T1& m; //!< storage of reference to the operand (eg. a matrix) arma_aligned in_eT aux; //!< storage of auxiliary data, using the element type as used by T1 arma_aligned out_eT aux_out_eT; //!< storage of auxiliary data, using the element type as specified by the out_eT template parameter arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_c; //!< storage of auxiliary data, uword format }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_find.hpp0000666000000000000000000001025112620272703021061 0ustar rootroot// Copyright (C) 2010-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_find //! @{ template inline typename enable_if2 < is_arma_type::value, const mtOp >::result find(const T1& X) { arma_extra_debug_sigprint(); return mtOp(X); } template inline const mtOp find(const Base& X, const uword k, const char* direction = "first") { arma_extra_debug_sigprint(); const char sig = (direction != NULL) ? direction[0] : char(0); arma_debug_check ( ( (sig != 'f') && (sig != 'F') && (sig != 'l') && (sig != 'L') ), "find(): direction must be \"first\" or \"last\"" ); const uword type = ( (sig == 'f') || (sig == 'F') ) ? 0 : 1; return mtOp(X.get_ref(), k, type); } // template inline uvec find(const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.get_ref()); const Mat R( const_cast< eT* >(tmp.M.memptr()), tmp.M.n_elem, 1, false ); return find(R); } template inline uvec find(const BaseCube& X, const uword k, const char* direction = "first") { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.get_ref()); const Mat R( const_cast< eT* >(tmp.M.memptr()), tmp.M.n_elem, 1, false ); return find(R, k, direction); } template inline uvec find(const mtOpCube& X, const uword k = 0, const char* direction = "first") { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.m); const Mat R( const_cast< eT* >(tmp.M.memptr()), tmp.M.n_elem, 1, false ); return find( mtOp, op_rel_type>(R, X.aux), k, direction ); } template inline uvec find(const mtGlueCube& X, const uword k = 0, const char* direction = "first") { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; const unwrap_cube tmp1(X.A); const unwrap_cube tmp2(X.B); arma_debug_assert_same_size( tmp1.M, tmp2.M, "relational operator" ); const Mat R1( const_cast< eT1* >(tmp1.M.memptr()), tmp1.M.n_elem, 1, false ); const Mat R2( const_cast< eT2* >(tmp2.M.memptr()), tmp2.M.n_elem, 1, false ); return find( mtGlue, Mat, glue_rel_type>(R1, R2), k, direction ); } // template inline typename enable_if2 < is_arma_type::value, const mtOp >::result find_finite(const T1& X) { arma_extra_debug_sigprint(); return mtOp(X); } template inline typename enable_if2 < is_arma_type::value, const mtOp >::result find_nonfinite(const T1& X) { arma_extra_debug_sigprint(); return mtOp(X); } // template inline uvec find_finite(const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.get_ref()); const Mat R( const_cast< eT* >(tmp.M.memptr()), tmp.M.n_elem, 1, false ); return find_finite(R); } template inline uvec find_nonfinite(const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_cube tmp(X.get_ref()); const Mat R( const_cast< eT* >(tmp.M.memptr()), tmp.M.n_elem, 1, false ); return find_nonfinite(R); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_mean.hpp0000666000000000000000000000700512620272703021064 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_mean //! @{ template arma_inline const Op mean ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return Op(X, dim, 0); } template arma_inline const Op mean ( const T1& X, const uword dim, const typename enable_if::value == true>::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return Op(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type mean ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if::value == true>::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return op_mean::mean_all(X); } //! \brief //! Immediate 'find mean value' operation, //! invoked, for example, by: mean(mean(A)) template inline arma_warn_unused typename T1::elem_type mean(const Op& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("mean(): two consecutive mean() calls detected"); return op_mean::mean_all(in.m); } template arma_inline const Op< Op, op_mean> mean(const Op& in, const uword dim) { arma_extra_debug_sigprint(); return Op< Op, op_mean>(in, dim, 0); } template arma_inline arma_warn_unused const typename arma_scalar_only::result & mean(const T& x) { return x; } template inline arma_warn_unused const SpOp mean ( const T1& X, const uword dim = 0, const typename enable_if< is_arma_sparse_type::value == true >::result* junk1 = 0, const typename enable_if< resolves_to_sparse_vector::value == false >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return SpOp(X, dim, 0); } template inline arma_warn_unused const SpOp mean ( const T1& X, const uword dim, const typename enable_if< resolves_to_sparse_vector::value == true >::result* junk1 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); return SpOp(X, dim, 0); } template inline arma_warn_unused typename T1::elem_type mean ( const T1& X, const arma_empty_class junk1 = arma_empty_class(), const typename enable_if< resolves_to_sparse_vector::value == true >::result* junk2 = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); return spop_mean::mean_all(X); } template inline arma_warn_unused typename T1::elem_type mean(const SpOp& in) { arma_extra_debug_sigprint(); arma_extra_debug_print("mean(): two consecutive mean() calls detected"); return spop_mean::mean_all(in.m); } //! @} armadillo-6.500.5/include/armadillo_bits/strip.hpp0000666000000000000000000000333712624342232020625 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup strip //! @{ template struct strip_diagmat { typedef T1 stored_type; arma_hot inline strip_diagmat(const T1& X) : M(X) { arma_extra_debug_sigprint(); } static const bool do_diagmat = false; const T1& M; }; template struct strip_diagmat< Op > { typedef T1 stored_type; arma_hot inline strip_diagmat(const Op& X) : M(X.m) { arma_extra_debug_sigprint(); } static const bool do_diagmat = true; const T1& M; }; template struct strip_inv { typedef T1 stored_type; arma_hot inline strip_inv(const T1& X) : M(X) { arma_extra_debug_sigprint(); } const T1& M; static const bool do_inv = false; }; template struct strip_inv< Op > { typedef T1 stored_type; arma_hot inline strip_inv(const Op& X) : M(X.m) { arma_extra_debug_sigprint(); } const T1& M; static const bool do_inv = true; }; template struct strip_inv< Op > { typedef T1 stored_type; arma_hot inline strip_inv(const Op& X) : M(X.m) { arma_extra_debug_sigprint(); } const T1& M; static const bool do_inv = true; }; //! @} armadillo-6.500.5/include/armadillo_bits/eop_core_meat.hpp0000666000000000000000000005350712650723436022301 0ustar rootroot// Copyright (C) 2010-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eop_core //! @{ #undef arma_applier_1u #undef arma_applier_1a #undef arma_applier_2 #undef arma_applier_3 #undef operatorA #if defined(ARMA_SIMPLE_LOOPS) #define arma_applier_1u(operatorA) \ {\ for(uword i=0; i::process(P[i], k);\ }\ } #else #define arma_applier_1u(operatorA) \ {\ uword i,j;\ \ for(i=0, j=1; j::process(tmp_i, k);\ tmp_j = eop_core::process(tmp_j, k);\ \ out_mem[i] operatorA tmp_i;\ out_mem[j] operatorA tmp_j;\ }\ \ if(i < n_elem)\ {\ out_mem[i] operatorA eop_core::process(P[i], k);\ }\ } #endif #if defined(ARMA_SIMPLE_LOOPS) #define arma_applier_1a(operatorA) \ {\ for(uword i=0; i::process(P.at_alt(i), k);\ }\ } #else #define arma_applier_1a(operatorA) \ {\ uword i,j;\ \ for(i=0, j=1; j::process(tmp_i, k);\ tmp_j = eop_core::process(tmp_j, k);\ \ out_mem[i] operatorA tmp_i;\ out_mem[j] operatorA tmp_j;\ }\ \ if(i < n_elem)\ {\ out_mem[i] operatorA eop_core::process(P.at_alt(i), k);\ }\ } #endif #define arma_applier_2(operatorA) \ {\ if(n_rows != 1)\ {\ for(uword col=0; col::process(tmp_i, k);\ tmp_j = eop_core::process(tmp_j, k);\ \ *out_mem operatorA tmp_i; out_mem++;\ *out_mem operatorA tmp_j; out_mem++;\ }\ \ if(i < n_rows)\ {\ *out_mem operatorA eop_core::process(P.at(i,col), k); out_mem++;\ }\ }\ }\ else\ {\ for(uword count=0; count < n_cols; ++count)\ {\ out_mem[count] operatorA eop_core::process(P.at(0,count), k);\ }\ }\ } #define arma_applier_3(operatorA) \ {\ for(uword slice=0; slice::process(tmp_i, k);\ tmp_j = eop_core::process(tmp_j, k);\ \ *out_mem operatorA tmp_i; out_mem++; \ *out_mem operatorA tmp_j; out_mem++; \ }\ \ if(i < n_rows)\ {\ *out_mem operatorA eop_core::process(P.at(i,col,slice), k); out_mem++; \ }\ }\ }\ } // // matrices template template arma_hot inline void eop_core::apply(outT& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(=); } } else { const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const Proxy& P = x.P; arma_applier_2(=); } } template template arma_hot inline void eop_core::apply_inplace_plus(Mat& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition"); const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(+=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(+=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(+=); } } else { const Proxy& P = x.P; arma_applier_2(+=); } } template template arma_hot inline void eop_core::apply_inplace_minus(Mat& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction"); const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(-=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(-=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(-=); } } else { const Proxy& P = x.P; arma_applier_2(-=); } } template template arma_hot inline void eop_core::apply_inplace_schur(Mat& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise multiplication"); const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(*=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(*=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(*=); } } else { const Proxy& P = x.P; arma_applier_2(*=); } } template template arma_hot inline void eop_core::apply_inplace_div(Mat& out, const eOp& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise division"); const eT k = x.aux; eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { const uword n_elem = x.get_n_elem(); if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename Proxy::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(/=); } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(/=); } } else { typename Proxy::ea_type P = x.P.get_ea(); arma_applier_1u(/=); } } else { const Proxy& P = x.P; arma_applier_2(/=); } } // // cubes template template arma_hot inline void eop_core::apply(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(=); } } else { const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); const ProxyCube& P = x.P; arma_applier_3(=); } } template template arma_hot inline void eop_core::apply_inplace_plus(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition"); const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(+=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(+=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(+=); } } else { const ProxyCube& P = x.P; arma_applier_3(+=); } } template template arma_hot inline void eop_core::apply_inplace_minus(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(-=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(-=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(-=); } } else { const ProxyCube& P = x.P; arma_applier_3(-=); } } template template arma_hot inline void eop_core::apply_inplace_schur(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(*=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(*=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(*=); } } else { const ProxyCube& P = x.P; arma_applier_3(*=); } } template template arma_hot inline void eop_core::apply_inplace_div(Cube& out, const eOpCube& x) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_rows = x.get_n_rows(); const uword n_cols = x.get_n_cols(); const uword n_slices = x.get_n_slices(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); const eT k = x.aux; eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { const uword n_elem = out.n_elem; if(memory::is_aligned(out_mem)) { memory::mark_as_aligned(out_mem); if(x.P.is_aligned()) { typename ProxyCube::aligned_ea_type P = x.P.get_aligned_ea(); arma_applier_1a(/=); } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(/=); } } else { typename ProxyCube::ea_type P = x.P.get_ea(); arma_applier_1u(/=); } } else { const ProxyCube& P = x.P; arma_applier_3(/=); } } // // common template template arma_hot arma_inline eT eop_core::process(const eT, const eT) { arma_stop("eop_core::process(): unhandled eop_type"); return eT(0); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT k) { return val + k; } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT k) { return k - val; } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT k) { return val - k; } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT k) { return val * k; } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT k) { return k / val; } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT k) { return val / k; } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return val*val; } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::neg(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::sqrt(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::log(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::log2(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::log10(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return arma::trunc_log(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::exp(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::exp2(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::exp10(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return arma::trunc_exp(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::cos(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::sin(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::tan(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::acos(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::asin(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::atan(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::cosh(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::sinh(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::tanh(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::acosh(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::asinh(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::atanh(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::direct_eps(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::arma_abs(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::conj(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT k) { return eop_aux::pow(val, k); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::floor(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::ceil(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::round(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::trunc(val); } template<> template arma_hot arma_inline eT eop_core::process(const eT val, const eT ) { return eop_aux::sign(val); } #undef arma_applier_1u #undef arma_applier_1a #undef arma_applier_2 #undef arma_applier_3 //! @} armadillo-6.500.5/include/armadillo_bits/spop_diagmat_bones.hpp0000666000000000000000000000203212620272703023311 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spop_diagmat //! @{ class spop_diagmat { public: template inline static void apply(SpMat& out, const SpOp& in); template inline static void apply_noalias(SpMat& out, const SpProxy& p); }; class spop_diagmat2 { public: template inline static void apply(SpMat& out, const SpOp& in); template inline static void apply_noalias(SpMat& out, const SpMat& X, const uword row_offset, const uword col_offset); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_var_meat.hpp0000666000000000000000000001537412620272703021765 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_var //! @{ //! \brief //! For each row or for each column, find the variance. //! The result is stored in a dense matrix that has either one column or one row. //! The dimension, for which the variances are found, is set via the var() function. template inline void op_var::apply(Mat& out, const mtOp& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type in_eT; typedef typename T1::pod_type out_eT; const unwrap_check_mixed tmp(in.m, out); const Mat& X = tmp.M; const uword norm_type = in.aux_uword_a; const uword dim = in.aux_uword_b; arma_debug_check( (norm_type > 1), "var(): parameter 'norm_type' must be 0 or 1" ); arma_debug_check( (dim > 1), "var(): parameter 'dim' must be 0 or 1" ); const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { arma_extra_debug_print("op_var::apply(): dim = 0"); out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows > 0) { out_eT* out_mem = out.memptr(); for(uword col=0; col 0) ? 1 : 0); if(X_n_cols > 0) { podarray dat(X_n_cols); in_eT* dat_mem = dat.memptr(); out_eT* out_mem = out.memptr(); for(uword row=0; row inline typename T1::pod_type op_var::var_vec(const Base& X, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; arma_debug_check( (norm_type > 1), "var(): parameter 'norm_type' must be 0 or 1" ); const Proxy P(X.get_ref()); const podarray tmp(P); return op_var::direct_var(tmp.memptr(), tmp.n_elem, norm_type); } template inline typename get_pod_type::result op_var::var_vec(const subview_col& X, const uword norm_type) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "var(): parameter 'norm_type' must be 0 or 1" ); return op_var::direct_var(X.colptr(0), X.n_rows, norm_type); } template inline typename get_pod_type::result op_var::var_vec(const subview_row& X, const uword norm_type) { arma_extra_debug_sigprint(); arma_debug_check( (norm_type > 1), "var(): parameter 'norm_type' must be 0 or 1" ); const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X.n_cols; podarray tmp(X.n_elem); eT* tmp_mem = tmp.memptr(); for(uword i=0, col=start_col; col < end_col_p1; ++col, ++i) { tmp_mem[i] = A.at(start_row, col); } return op_var::direct_var(tmp.memptr(), tmp.n_elem, norm_type); } //! find the variance of an array template inline eT op_var::direct_var(const eT* const X, const uword n_elem, const uword norm_type) { arma_extra_debug_sigprint(); if(n_elem >= 2) { const eT acc1 = op_mean::direct_mean(X, n_elem); eT acc2 = eT(0); eT acc3 = eT(0); uword i,j; for(i=0, j=1; j inline eT op_var::direct_var_robust(const eT* const X, const uword n_elem, const uword norm_type) { arma_extra_debug_sigprint(); if(n_elem > 1) { eT r_mean = X[0]; eT r_var = eT(0); for(uword i=1; i inline T op_var::direct_var(const std::complex* const X, const uword n_elem, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(n_elem >= 2) { const eT acc1 = op_mean::direct_mean(X, n_elem); T acc2 = T(0); eT acc3 = eT(0); for(uword i=0; i inline T op_var::direct_var_robust(const std::complex* const X, const uword n_elem, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(n_elem > 1) { eT r_mean = X[0]; T r_var = T(0); for(uword i=1; i inline void op_repmat::apply_noalias(Mat& out, const obj& X, const uword copies_per_row, const uword copies_per_col) { arma_extra_debug_sigprint(); typedef typename obj::elem_type eT; const uword X_n_rows = obj::is_row ? uword(1) : X.n_rows; const uword X_n_cols = obj::is_col ? uword(1) : X.n_cols; out.set_size(X_n_rows * copies_per_row, X_n_cols * copies_per_col); const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; // if( (out_n_rows > 0) && (out_n_cols > 0) ) // { // for(uword col = 0; col < out_n_cols; col += X_n_cols) // for(uword row = 0; row < out_n_rows; row += X_n_rows) // { // out.submat(row, col, row+X_n_rows-1, col+X_n_cols-1) = X; // } // } if( (out_n_rows > 0) && (out_n_cols > 0) ) { if(copies_per_row != 1) { for(uword col_copy=0; col_copy < copies_per_col; ++col_copy) { const uword out_col_offset = X_n_cols * col_copy; for(uword col=0; col < X_n_cols; ++col) { eT* out_colptr = out.colptr(col + out_col_offset); const eT* X_colptr = X.colptr(col); for(uword row_copy=0; row_copy < copies_per_row; ++row_copy) { const uword out_row_offset = X_n_rows * row_copy; arrayops::copy( &out_colptr[out_row_offset], X_colptr, X_n_rows ); } } } } else { for(uword col_copy=0; col_copy < copies_per_col; ++col_copy) { const uword out_col_offset = X_n_cols * col_copy; for(uword col=0; col < X_n_cols; ++col) { eT* out_colptr = out.colptr(col + out_col_offset); const eT* X_colptr = X.colptr(col); arrayops::copy( out_colptr, X_colptr, X_n_rows ); } } } } } template inline void op_repmat::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword copies_per_row = in.aux_uword_a; const uword copies_per_col = in.aux_uword_b; const quasi_unwrap U(in.m); if(U.is_alias(out)) { Mat tmp; op_repmat::apply_noalias(tmp, U.M, copies_per_row, copies_per_col); out.steal_mem(tmp); } else { op_repmat::apply_noalias(out, U.M, copies_per_row, copies_per_col); } } //! @} armadillo-6.500.5/include/armadillo_bits/spop_min_meat.hpp0000666000000000000000000003723512620272703022323 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_min //! @{ template inline void spop_min::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "min(): parameter 'dim' must be 0 or 1" ); const SpProxy p(in.m); const uword p_n_rows = p.get_n_rows(); const uword p_n_cols = p.get_n_cols(); if( (p_n_rows == 0) || (p_n_cols == 0) || (p.get_n_nonzero() == 0) ) { if(dim == 0) { out.zeros((p_n_rows > 0) ? 1 : 0, p_n_cols); } if(dim == 1) { out.zeros(p_n_rows, (p_n_cols > 0) ? 1 : 0); } return; } spop_min::apply_proxy(out, p, dim); } template inline void spop_min::apply_proxy ( SpMat& out, const SpProxy& p, const uword dim, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); const uword p_n_cols = p.get_n_cols(); const uword p_n_rows = p.get_n_rows(); if(dim == 0) // find the minimum in each column { Row value(p_n_cols, fill::zeros); urowvec count(p_n_cols, fill::zeros); while(it != it_end) { const uword col = it.col(); value[col] = (count[col] == 0) ? (*it) : (std::min)(value[col], (*it)); count[col]++; ++it; } for(uword col=0; col value(p_n_rows, fill::zeros); ucolvec count(p_n_rows, fill::zeros); while(it != it_end) { const uword row = it.row(); value[row] = (count[row] == 0) ? (*it) : (std::min)(value[row], (*it)); count[row]++; ++it; } for(uword row=0; row inline typename T1::elem_type spop_min::vector_min ( const T1& x, const typename arma_not_cx::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; const SpProxy p(x); if(p.get_n_elem() == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } if(p.get_n_nonzero() == 0) { return eT(0); } if(SpProxy::must_use_iterator == false) { // direct access of values if(p.get_n_nonzero() == p.get_n_elem()) { return op_min::direct_min(p.get_values(), p.get_n_nonzero()); } else { return std::min(eT(0), op_min::direct_min(p.get_values(), p.get_n_nonzero())); } } else { // use iterator typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); eT result = (*it); ++it; while(it != it_end) { if((*it) < result) { result = (*it); } ++it; } if(p.get_n_nonzero() == p.get_n_elem()) { return result; } else { return std::min(eT(0), result); } } } template inline typename arma_not_cx::result spop_min::min(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); const uword n_nonzero = P.get_n_nonzero(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } eT min_val = priv::most_pos(); if(SpProxy::must_use_iterator) { // We have to iterate over the elements. typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { if ((*it) < min_val) { min_val = *it; } ++it; } } else { // We can do direct access of the values, row_indices, and col_ptrs. // We don't need the location of the min value, so we can just call out to // other functions... min_val = op_min::direct_min(P.get_values(), n_nonzero); } if(n_elem == n_nonzero) { return min_val; } else { return std::min(eT(0), min_val); } } template inline typename arma_not_cx::result spop_min::min_with_index(const SpProxy& P, uword& index_of_min_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword n_elem = P.get_n_elem(); const uword n_nonzero = P.get_n_nonzero(); const uword n_rows = P.get_n_rows(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } eT min_val = priv::most_pos(); if(SpProxy::must_use_iterator) { // We have to iterate over the elements. typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { if ((*it) < min_val) { min_val = *it; index_of_min_val = it.row() + it.col() * n_rows; } ++it; } } else { // We can do direct access. min_val = op_min::direct_min(P.get_values(), n_nonzero, index_of_min_val); // Convert to actual position in matrix. const uword row = P.get_row_indices()[index_of_min_val]; uword col = 0; while (P.get_col_ptrs()[++col] < index_of_min_val + 1) { } index_of_min_val = (col - 1) * n_rows + row; } if(n_elem != n_nonzero) { min_val = std::min(eT(0), min_val); // If the min_val is a nonzero element, we need its actual position in the matrix. if(min_val == eT(0)) { // Find first zero element. uword last_row = 0; uword last_col = 0; typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { // Have we moved more than one position from the last place? if ((it.col() == last_col) && (it.row() - last_row > 1)) { index_of_min_val = it.col() * n_rows + last_row + 1; break; } else if ((it.col() >= last_col + 1) && (last_row < n_rows - 1)) { index_of_min_val = last_col * n_rows + last_row + 1; break; } else if ((it.col() == last_col + 1) && (it.row() > 0)) { index_of_min_val = it.col() * n_rows; break; } else if (it.col() > last_col + 1) { index_of_min_val = (last_col + 1) * n_rows; break; } last_row = it.row(); last_col = it.col(); ++it; } } } return min_val; } template inline void spop_min::apply_proxy ( SpMat& out, const SpProxy& p, const uword dim, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); const uword p_n_cols = p.get_n_cols(); const uword p_n_rows = p.get_n_rows(); if(dim == 0) // find the minimum in each column { Row rawval(p_n_cols, fill::zeros); Row< T> absval(p_n_cols, fill::zeros); urowvec count(p_n_cols, fill::zeros); while(it != it_end) { const uword col = it.col(); const eT& v = (*it); const T a = std::abs(v); if(count[col] == 0) { absval[col] = a; rawval[col] = v; } else { if(a < absval[col]) { absval[col] = a; rawval[col] = v; } } count[col]++; ++it; } for(uword col=0; col < p_n_cols; ++col) { if(count[col] < p_n_rows) { if(T(0) < absval[col]) { rawval[col] = eT(0); } } } out = rawval; } else if(dim == 1) // find the minimum in each row { Col rawval(p_n_rows, fill::zeros); Col< T> absval(p_n_rows, fill::zeros); ucolvec count(p_n_rows, fill::zeros); while(it != it_end) { const uword row = it.row(); const eT& v = (*it); const T a = std::abs(v); if(count[row] == 0) { absval[row] = a; rawval[row] = v; } else { if(a < absval[row]) { absval[row] = a; rawval[row] = v; } } count[row]++; ++it; } for(uword row=0; row < p_n_rows; ++row) { if(count[row] < p_n_cols) { if(T(0) < absval[row]) { rawval[row] = eT(0); } } } out = rawval; } } template inline typename T1::elem_type spop_min::vector_min ( const T1& x, const typename arma_cx_only::result* junk ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const SpProxy p(x); if(p.get_n_elem() == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } if(p.get_n_nonzero() == 0) { return eT(0); } if(SpProxy::must_use_iterator == false) { // direct access of values if(p.get_n_nonzero() == p.get_n_elem()) { return op_min::direct_min(p.get_values(), p.get_n_nonzero()); } else { const eT val1 = eT(0); const eT val2 = op_min::direct_min(p.get_values(), p.get_n_nonzero()); return ( std::abs(val1) < std::abs(val2) ) ? val1 : val2; } } else { // use iterator typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); eT best_val_orig = *it; T best_val_abs = std::abs(best_val_orig); ++it; while(it != it_end) { eT val_orig = *it; T val_abs = std::abs(val_orig); if(val_abs < best_val_abs) { best_val_abs = val_abs; best_val_orig = val_orig; } ++it; } if(p.get_n_nonzero() == p.get_n_elem()) { return best_val_orig; } else { const eT val1 = eT(0); return ( std::abs(val1) < best_val_abs ) ? val1 : best_val_orig; } } } template inline typename arma_cx_only::result spop_min::min(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const SpProxy P(X.get_ref()); const uword n_elem = P.get_n_elem(); const uword n_nonzero = P.get_n_nonzero(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } T min_val = priv::most_pos(); eT ret_val; if(SpProxy::must_use_iterator) { // We have to iterate over the elements. typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { const T tmp_val = std::abs(*it); if (tmp_val < min_val) { min_val = tmp_val; ret_val = *it; } ++it; } } else { // We can do direct access of the values, row_indices, and col_ptrs. // We don't need the location of the min value, so we can just call out to // other functions... ret_val = op_min::direct_min(P.get_values(), n_nonzero); min_val = std::abs(ret_val); } if(n_elem == n_nonzero) { return ret_val; } else { if (T(0) < min_val) return eT(0); else return ret_val; } } template inline typename arma_cx_only::result spop_min::min_with_index(const SpProxy& P, uword& index_of_min_val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const uword n_elem = P.get_n_elem(); const uword n_nonzero = P.get_n_nonzero(); const uword n_rows = P.get_n_rows(); if(n_elem == 0) { arma_debug_check(true, "min(): object has no elements"); return Datum::nan; } T min_val = priv::most_pos(); if(SpProxy::must_use_iterator) { // We have to iterate over the elements. typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { const T tmp_val = std::abs(*it); if (tmp_val < min_val) { min_val = tmp_val; index_of_min_val = it.row() + it.col() * n_rows; } ++it; } } else { // We can do direct access. min_val = std::abs(op_min::direct_min(P.get_values(), n_nonzero, index_of_min_val)); // Convert to actual position in matrix. const uword row = P.get_row_indices()[index_of_min_val]; uword col = 0; while (P.get_col_ptrs()[++col] < index_of_min_val + 1) { } index_of_min_val = (col - 1) * n_rows + row; } if(n_elem != n_nonzero) { min_val = std::min(T(0), min_val); // If the min_val is a nonzero element, we need its actual position in the matrix. if(min_val == T(0)) { // Find first zero element. uword last_row = 0; uword last_col = 0; typedef typename SpProxy::const_iterator_type it_type; it_type it = P.begin(); it_type it_end = P.end(); while (it != it_end) { // Have we moved more than one position from the last place? if ((it.col() == last_col) && (it.row() - last_row > 1)) { index_of_min_val = it.col() * n_rows + last_row + 1; break; } else if ((it.col() >= last_col + 1) && (last_row < n_rows - 1)) { index_of_min_val = last_col * n_rows + last_row + 1; break; } else if ((it.col() == last_col + 1) && (it.row() > 0)) { index_of_min_val = it.col() * n_rows; break; } else if (it.col() > last_col + 1) { index_of_min_val = (last_col + 1) * n_rows; break; } last_row = it.row(); last_col = it.col(); ++it; } } } return P[index_of_min_val]; } //! @} armadillo-6.500.5/include/armadillo_bits/Cube_meat.hpp0000666000000000000000000030707112650111756021356 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Cube //! @{ template inline Cube::~Cube() { arma_extra_debug_sigprint_this(this); delete_mat(); if( (mem_state == 0) && (n_elem > Cube_prealloc::mem_n_elem) ) { memory::release( access::rw(mem) ); } if(arma_config::debug == true) { // try to expose buggy user code that accesses deleted objects access::rw(mem) = 0; access::rw(mat_ptrs) = 0; } arma_type_check(( is_supported_elem_type::value == false )); } template inline Cube::Cube() : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); } //! construct the cube to have user specified dimensions template inline Cube::Cube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem_slice(in_n_rows*in_n_cols) , n_slices(in_n_slices) , n_elem(in_n_rows*in_n_cols*in_n_slices) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); init_cold(); } template inline Cube::Cube(const SizeCube& s) : n_rows(s.n_rows) , n_cols(s.n_cols) , n_elem_slice(s.n_rows*s.n_cols) , n_slices(s.n_slices) , n_elem(s.n_rows*s.n_cols*s.n_slices) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); init_cold(); } //! construct the cube to have user specified dimensions and fill with specified pattern template template inline Cube::Cube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices, const fill::fill_class&) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem_slice(in_n_rows*in_n_cols) , n_slices(in_n_slices) , n_elem(in_n_rows*in_n_cols*in_n_slices) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); init_cold(); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); if(is_same_type::yes) { arma_debug_check(true, "Cube::Cube(): unsupported fill type"); } } template template inline Cube::Cube(const SizeCube& s, const fill::fill_class&) : n_rows(s.n_rows) , n_cols(s.n_cols) , n_elem_slice(s.n_rows*s.n_cols) , n_slices(s.n_slices) , n_elem(s.n_rows*s.n_cols*s.n_slices) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); init_cold(); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); if(is_same_type::yes) { arma_debug_check(true, "Cube::Cube(): unsupported fill type"); } } #if defined(ARMA_USE_CXX11) template inline Cube::Cube(Cube&& in_cube) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint(arma_str::format("this = %x in_cube = %x") % this % &in_cube); (*this).steal_mem(in_cube); } template inline const Cube& Cube::operator=(Cube&& in_cube) { arma_extra_debug_sigprint(arma_str::format("this = %x in_cube = %x") % this % &in_cube); (*this).steal_mem(in_cube); return *this; } #endif template inline void Cube::init_cold() { arma_extra_debug_sigprint( arma_str::format("n_rows = %d, n_cols = %d, n_slices = %d") % n_rows % n_cols % n_slices ); #if (defined(ARMA_USE_CXX11) || defined(ARMA_64BIT_WORD)) const char* error_message = "Cube::init(): requested size is too large"; #else const char* error_message = "Cube::init(): requested size is too large; suggest to compile in C++11 mode or enable ARMA_64BIT_WORD"; #endif arma_debug_check ( ( ( (n_rows > 0x0FFF) || (n_cols > 0x0FFF) || (n_slices > 0xFF) ) ? ( (double(n_rows) * double(n_cols) * double(n_slices)) > double(ARMA_MAX_UWORD) ) : false ), error_message ); if(n_elem <= Cube_prealloc::mem_n_elem) { arma_extra_debug_print("Cube::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Cube::init(): acquiring memory"); access::rw(mem) = memory::acquire(n_elem); } if(n_elem == 0) { access::rw(n_rows) = 0; access::rw(n_cols) = 0; access::rw(n_elem_slice) = 0; access::rw(n_slices) = 0; } else { create_mat(); } } template inline void Cube::init_warm(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) { arma_extra_debug_sigprint( arma_str::format("in_n_rows = %d, in_n_cols = %d, in_n_slices = %d") % in_n_rows % in_n_cols % in_n_slices ); if( (n_rows == in_n_rows) && (n_cols == in_n_cols) && (n_slices == in_n_slices) ) { return; } const uword t_mem_state = mem_state; bool err_state = false; char* err_msg = 0; arma_debug_set_error( err_state, err_msg, (t_mem_state == 3), "Cube::init(): size is fixed and hence cannot be changed" ); #if (defined(ARMA_USE_CXX11) || defined(ARMA_64BIT_WORD)) const char* error_message = "Cube::init(): requested size is too large"; #else const char* error_message = "Cube::init(): requested size is too large; suggest to compile in C++11 mode or enable ARMA_64BIT_WORD"; #endif arma_debug_set_error ( err_state, err_msg, ( ( (in_n_rows > 0x0FFF) || (in_n_cols > 0x0FFF) || (in_n_slices > 0xFF) ) ? ( (double(in_n_rows) * double(in_n_cols) * double(in_n_slices)) > double(ARMA_MAX_UWORD) ) : false ), error_message ); arma_debug_check(err_state, err_msg); const uword old_n_elem = n_elem; const uword new_n_elem = in_n_rows * in_n_cols * in_n_slices; if(old_n_elem == new_n_elem) { arma_extra_debug_print("Cube::init(): reusing memory"); delete_mat(); if(new_n_elem > 0) { access::rw(n_rows) = in_n_rows; access::rw(n_cols) = in_n_cols; access::rw(n_elem_slice) = in_n_rows*in_n_cols; access::rw(n_slices) = in_n_slices; create_mat(); } } else // condition: old_n_elem != new_n_elem { arma_debug_check( (t_mem_state == 2), "Cube::init(): requested size is not compatible with the size of auxiliary memory" ); delete_mat(); if(new_n_elem < old_n_elem) // reuse existing memory if possible { if( (t_mem_state == 0) && (new_n_elem <= Cube_prealloc::mem_n_elem) ) { if(old_n_elem > Cube_prealloc::mem_n_elem) { arma_extra_debug_print("Cube::init(): releasing memory"); memory::release( access::rw(mem) ); } arma_extra_debug_print("Cube::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Cube::init(): reusing memory"); } } else // condition: new_n_elem > old_n_elem { if( (t_mem_state == 0) && (old_n_elem > Cube_prealloc::mem_n_elem) ) { arma_extra_debug_print("Cube::init(): releasing memory"); memory::release( access::rw(mem) ); } if(new_n_elem <= Cube_prealloc::mem_n_elem) { arma_extra_debug_print("Cube::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Cube::init(): acquiring memory"); access::rw(mem) = memory::acquire(new_n_elem); } access::rw(mem_state) = 0; } if(new_n_elem > 0) { access::rw(n_rows) = in_n_rows; access::rw(n_cols) = in_n_cols; access::rw(n_elem_slice) = in_n_rows*in_n_cols; access::rw(n_slices) = in_n_slices; access::rw(n_elem) = new_n_elem; create_mat(); } } if(new_n_elem == 0) { access::rw(n_rows) = 0; access::rw(n_cols) = 0; access::rw(n_elem_slice) = 0; access::rw(n_slices) = 0; access::rw(n_elem) = 0; } } //! for constructing a complex cube out of two non-complex cubes template template inline void Cube::init ( const BaseCube::pod_type,T1>& X, const BaseCube::pod_type,T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type T; arma_type_check(( is_complex::value == false )); //!< compile-time abort if eT is not std::complex arma_type_check(( is_complex< T>::value == true )); //!< compile-time abort if T is std::complex arma_type_check(( is_same_type< std::complex, eT >::no )); //!< compile-time abort if types are not compatible const ProxyCube PX(X.get_ref()); const ProxyCube PY(Y.get_ref()); arma_debug_assert_same_size(PX, PY, "Cube()"); const uword local_n_rows = PX.get_n_rows(); const uword local_n_cols = PX.get_n_cols(); const uword local_n_slices = PX.get_n_slices(); init_warm(local_n_rows, local_n_cols, local_n_slices); eT* out_mem = (*this).memptr(); const bool prefer_at_accessor = ( ProxyCube::prefer_at_accessor || ProxyCube::prefer_at_accessor ); if(prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type1; typedef typename ProxyCube::ea_type ea_type2; const uword N = n_elem; ea_type1 A = PX.get_ea(); ea_type2 B = PY.get_ea(); for(uword i=0; i(A[i], B[i]); } } else { for(uword uslice = 0; uslice < local_n_slices; ++uslice) for(uword ucol = 0; ucol < local_n_cols; ++ucol ) for(uword urow = 0; urow < local_n_rows; ++urow ) { *out_mem = std::complex( PX.at(urow,ucol,uslice), PY.at(urow,ucol,uslice) ); out_mem++; } } } template inline void Cube::delete_mat() { arma_extra_debug_sigprint(); if(mat_ptrs != NULL) { for(uword uslice = 0; uslice < n_slices; ++uslice) { if(mat_ptrs[uslice] != NULL) { delete access::rw(mat_ptrs[uslice]); } } if( (mem_state <= 2) && (n_slices > Cube_prealloc::mat_ptrs_size) ) { delete [] mat_ptrs; } } } template inline void Cube::create_mat() { arma_extra_debug_sigprint(); if(mem_state <= 2) { if(n_slices <= Cube_prealloc::mat_ptrs_size) { access::rw(mat_ptrs) = const_cast< const Mat** >(mat_ptrs_local); } else { access::rw(mat_ptrs) = new(std::nothrow) const Mat*[n_slices]; arma_check_bad_alloc( (mat_ptrs == 0), "Cube::create_mat(): out of memory" ); } } for(uword uslice = 0; uslice < n_slices; ++uslice) { mat_ptrs[uslice] = NULL; } } //! Set the cube to be equal to the specified scalar. //! NOTE: the size of the cube will be 1x1x1 template arma_inline const Cube& Cube::operator=(const eT val) { arma_extra_debug_sigprint(); init_warm(1,1,1); access::rw(mem[0]) = val; return *this; } //! In-place addition of a scalar to all elements of the cube template arma_inline const Cube& Cube::operator+=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_plus( memptr(), val, n_elem ); return *this; } //! In-place subtraction of a scalar from all elements of the cube template arma_inline const Cube& Cube::operator-=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_minus( memptr(), val, n_elem ); return *this; } //! In-place multiplication of all elements of the cube with a scalar template arma_inline const Cube& Cube::operator*=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_mul( memptr(), val, n_elem ); return *this; } //! In-place division of all elements of the cube with a scalar template arma_inline const Cube& Cube::operator/=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_div( memptr(), val, n_elem ); return *this; } //! construct a cube from a given cube template inline Cube::Cube(const Cube& x) : n_rows(x.n_rows) , n_cols(x.n_cols) , n_elem_slice(x.n_elem_slice) , n_slices(x.n_slices) , n_elem(x.n_elem) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); arma_extra_debug_sigprint(arma_str::format("this = %x in_cube = %x") % this % &x); init_cold(); arrayops::copy( memptr(), x.mem, n_elem ); } //! construct a cube from a given cube template inline const Cube& Cube::operator=(const Cube& x) { arma_extra_debug_sigprint(arma_str::format("this = %x in_cube = %x") % this % &x); if(this != &x) { init_warm(x.n_rows, x.n_cols, x.n_slices); arrayops::copy( memptr(), x.mem, n_elem ); } return *this; } //! construct a cube from a given auxiliary array of eTs. //! if copy_aux_mem is true, new memory is allocated and the array is copied. //! if copy_aux_mem is false, the auxiliary array is used directly (without allocating memory and copying). template inline Cube::Cube(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices, const bool copy_aux_mem, const bool strict, const bool prealloc_mat) : n_rows ( aux_n_rows ) , n_cols ( aux_n_cols ) , n_elem_slice( aux_n_rows*aux_n_cols ) , n_slices ( aux_n_slices ) , n_elem ( aux_n_rows*aux_n_cols*aux_n_slices ) , mem_state ( copy_aux_mem ? 0 : (strict ? 2 : 1) ) , mem ( copy_aux_mem ? 0 : aux_mem ) , mat_ptrs ( 0 ) { arma_extra_debug_sigprint_this(this); if(prealloc_mat == true) { arma_debug_warn("Cube::Cube(): parameter 'prealloc_mat' ignored as it's no longer used"); } if(copy_aux_mem == true) { init_cold(); arrayops::copy( memptr(), aux_mem, n_elem ); } else { create_mat(); } } //! construct a cube from a given auxiliary read-only array of eTs. //! the array is copied. template inline Cube::Cube(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const uword aux_n_slices) : n_rows(aux_n_rows) , n_cols(aux_n_cols) , n_elem_slice(aux_n_rows*aux_n_cols) , n_slices(aux_n_slices) , n_elem(aux_n_rows*aux_n_cols*aux_n_slices) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); init_cold(); arrayops::copy( memptr(), aux_mem, n_elem ); } //! in-place cube addition template inline const Cube& Cube::operator+=(const Cube& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "addition"); arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); return *this; } //! in-place cube subtraction template inline const Cube& Cube::operator-=(const Cube& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "subtraction"); arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); return *this; } //! in-place element-wise cube multiplication template inline const Cube& Cube::operator%=(const Cube& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "element-wise multiplication"); arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); return *this; } //! in-place element-wise cube division template inline const Cube& Cube::operator/=(const Cube& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "element-wise division"); arrayops::inplace_div( memptr(), m.memptr(), n_elem ); return *this; } //! for constructing a complex cube out of two non-complex cubes template template inline Cube::Cube ( const BaseCube::pod_type,T1>& A, const BaseCube::pod_type,T2>& B ) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); init(A,B); } //! construct a cube from a subview_cube instance (e.g. construct a cube from a delayed subcube operation) template inline Cube::Cube(const subview_cube& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem_slice(X.n_elem_slice) , n_slices(X.n_slices) , n_elem(X.n_elem) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); init_cold(); subview_cube::extract(*this, X); } //! construct a cube from a subview_cube instance (e.g. construct a cube from a delayed subcube operation) template inline const Cube& Cube::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); const bool alias = (this == &(X.m)); if(alias == false) { init_warm(X.n_rows, X.n_cols, X.n_slices); subview_cube::extract(*this, X); } else { Cube tmp(X); steal_mem(tmp); } return *this; } //! in-place cube addition (using a subcube on the right-hand-side) template inline const Cube& Cube::operator+=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::plus_inplace(*this, X); return *this; } //! in-place cube subtraction (using a subcube on the right-hand-side) template inline const Cube& Cube::operator-=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::minus_inplace(*this, X); return *this; } //! in-place element-wise cube mutiplication (using a subcube on the right-hand-side) template inline const Cube& Cube::operator%=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::schur_inplace(*this, X); return *this; } //! in-place element-wise cube division (using a subcube on the right-hand-side) template inline const Cube& Cube::operator/=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::div_inplace(*this, X); return *this; } //! provide the reference to the matrix representing a single slice template arma_inline Mat& Cube::slice(const uword in_slice) { arma_extra_debug_sigprint(); arma_debug_check( (in_slice >= n_slices), "Cube::slice(): index out of bounds" ); if(mat_ptrs[in_slice] == NULL) { mat_ptrs[in_slice] = new Mat('j', slice_memptr(in_slice), n_rows, n_cols); } return const_cast< Mat& >( *(mat_ptrs[in_slice]) ); } //! provide the reference to the matrix representing a single slice template arma_inline const Mat& Cube::slice(const uword in_slice) const { arma_extra_debug_sigprint(); arma_debug_check( (in_slice >= n_slices), "Cube::slice(): index out of bounds" ); if(mat_ptrs[in_slice] == NULL) { mat_ptrs[in_slice] = new Mat('j', slice_memptr(in_slice), n_rows, n_cols); } return *(mat_ptrs[in_slice]); } //! creation of subview_cube (subcube comprised of specified slices) template arma_inline subview_cube Cube::slices(const uword in_slice1, const uword in_slice2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_slice1 > in_slice2) || (in_slice2 >= n_slices), "Cube::slices(): indices out of bounds or incorrectly used" ); const uword subcube_n_slices = in_slice2 - in_slice1 + 1; return subview_cube(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices); } //! creation of subview_cube (subcube comprised of specified slices) template arma_inline const subview_cube Cube::slices(const uword in_slice1, const uword in_slice2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_slice1 > in_slice2) || (in_slice2 >= n_slices), "Cube::rows(): indices out of bounds or incorrectly used" ); const uword subcube_n_slices = in_slice2 - in_slice1 + 1; return subview_cube(*this, 0, 0, in_slice1, n_rows, n_cols, subcube_n_slices); } //! creation of subview_cube (generic subcube) template arma_inline subview_cube Cube::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) || (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices), "Cube::subcube(): indices out of bounds or incorrectly used" ); const uword subcube_n_rows = in_row2 - in_row1 + 1; const uword subcube_n_cols = in_col2 - in_col1 + 1; const uword subcube_n_slices = in_slice2 - in_slice1 + 1; return subview_cube(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices); } //! creation of subview_cube (generic subcube) template arma_inline const subview_cube Cube::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_slice1 > in_slice2) || (in_row2 >= n_rows) || (in_col2 >= n_cols) || (in_slice2 >= n_slices), "Cube::subcube(): indices out of bounds or incorrectly used" ); const uword subcube_n_rows = in_row2 - in_row1 + 1; const uword subcube_n_cols = in_col2 - in_col1 + 1; const uword subcube_n_slices = in_slice2 - in_slice1 + 1; return subview_cube(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices); } //! creation of subview_cube (generic subcube) template inline subview_cube Cube::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword l_n_slices = n_slices; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; const uword s_n_slices = s.n_slices; arma_debug_check ( ( in_row1 >= l_n_rows) || ( in_col1 >= l_n_cols) || ( in_slice1 >= l_n_slices) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols) || ((in_slice1 + s_n_slices) > l_n_slices), "Cube::subcube(): indices or size out of bounds" ); return subview_cube(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n_cols, s_n_slices); } //! creation of subview_cube (generic subcube) template inline const subview_cube Cube::subcube(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword l_n_slices = n_slices; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; const uword s_n_slices = s.n_slices; arma_debug_check ( ( in_row1 >= l_n_rows) || ( in_col1 >= l_n_cols) || ( in_slice1 >= l_n_slices) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols) || ((in_slice1 + s_n_slices) > l_n_slices), "Cube::subcube(): indices or size out of bounds" ); return subview_cube(*this, in_row1, in_col1, in_slice1, s_n_rows, s_n_cols, s_n_slices); } //! creation of subview_cube (generic subcube) template inline subview_cube Cube::subcube(const span& row_span, const span& col_span, const span& slice_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const bool slice_all = slice_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword in_slice1 = slice_all ? 0 : slice_span.a; const uword in_slice2 = slice_span.b; const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) || ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) ) , "Cube::subcube(): indices out of bounds or incorrectly used" ); return subview_cube(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices); } //! creation of subview_cube (generic subcube) template inline const subview_cube Cube::subcube(const span& row_span, const span& col_span, const span& slice_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const bool slice_all = slice_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword local_n_slices = n_slices; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; const uword in_slice1 = slice_all ? 0 : slice_span.a; const uword in_slice2 = slice_span.b; const uword subcube_n_slices = slice_all ? local_n_slices : in_slice2 - in_slice1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) || ( slice_all ? false : ((in_slice1 > in_slice2) || (in_slice2 >= local_n_slices)) ) , "Cube::subcube(): indices out of bounds or incorrectly used" ); return subview_cube(*this, in_row1, in_col1, in_slice1, subcube_n_rows, subcube_n_cols, subcube_n_slices); } template inline subview_cube Cube::operator()(const span& row_span, const span& col_span, const span& slice_span) { arma_extra_debug_sigprint(); return (*this).subcube(row_span, col_span, slice_span); } template inline const subview_cube Cube::operator()(const span& row_span, const span& col_span, const span& slice_span) const { arma_extra_debug_sigprint(); return (*this).subcube(row_span, col_span, slice_span); } template inline subview_cube Cube::operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) { arma_extra_debug_sigprint(); return (*this).subcube(in_row1, in_col1, in_slice1, s); } template inline const subview_cube Cube::operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const { arma_extra_debug_sigprint(); return (*this).subcube(in_row1, in_col1, in_slice1, s); } template arma_inline subview_cube Cube::tube(const uword in_row1, const uword in_col1) { arma_extra_debug_sigprint(); arma_debug_check ( ((in_row1 >= n_rows) || (in_col1 >= n_cols)), "Cube::tube(): indices out of bounds" ); return subview_cube(*this, in_row1, in_col1, 0, 1, 1, n_slices); } template arma_inline const subview_cube Cube::tube(const uword in_row1, const uword in_col1) const { arma_extra_debug_sigprint(); arma_debug_check ( ((in_row1 >= n_rows) || (in_col1 >= n_cols)), "Cube::tube(): indices out of bounds" ); return subview_cube(*this, in_row1, in_col1, 0, 1, 1, n_slices); } template arma_inline subview_cube Cube::tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "Cube::tube(): indices out of bounds or incorrectly used" ); const uword subcube_n_rows = in_row2 - in_row1 + 1; const uword subcube_n_cols = in_col2 - in_col1 + 1; return subview_cube(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices); } template arma_inline const subview_cube Cube::tube(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "Cube::tube(): indices out of bounds or incorrectly used" ); const uword subcube_n_rows = in_row2 - in_row1 + 1; const uword subcube_n_cols = in_col2 - in_col1 + 1; return subview_cube(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices); } template arma_inline subview_cube Cube::tube(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "Cube::tube(): indices or size out of bounds" ); return subview_cube(*this, in_row1, in_col1, 0, s_n_rows, s_n_cols, n_slices); } template arma_inline const subview_cube Cube::tube(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "Cube::tube(): indices or size out of bounds" ); return subview_cube(*this, in_row1, in_col1, 0, s_n_rows, s_n_cols, n_slices); } template inline subview_cube Cube::tube(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Cube::tube(): indices out of bounds or incorrectly used" ); return subview_cube(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices); } template inline const subview_cube Cube::tube(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword subcube_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subcube_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Cube::tube(): indices out of bounds or incorrectly used" ); return subview_cube(*this, in_row1, in_col1, 0, subcube_n_rows, subcube_n_cols, n_slices); } template template arma_inline subview_elem1 Cube::elem(const Base& a) { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline const subview_elem1 Cube::elem(const Base& a) const { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline subview_elem1 Cube::operator()(const Base& a) { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline const subview_elem1 Cube::operator()(const Base& a) const { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template arma_inline subview_cube_each1 Cube::each_slice() { arma_extra_debug_sigprint(); return subview_cube_each1(*this); } template arma_inline const subview_cube_each1 Cube::each_slice() const { arma_extra_debug_sigprint(); return subview_cube_each1(*this); } template template inline subview_cube_each2 Cube::each_slice(const Base& indices) { arma_extra_debug_sigprint(); return subview_cube_each2(*this, indices); } template template inline const subview_cube_each2 Cube::each_slice(const Base& indices) const { arma_extra_debug_sigprint(); return subview_cube_each2(*this, indices); } #if defined(ARMA_USE_CXX11) //! apply a lambda function to each slice, where each slice is interpreted as a matrix template inline const Cube& Cube::each_slice(const std::function< void(Mat&) >& F) { arma_extra_debug_sigprint(); for(uword slice_id=0; slice_id < n_slices; ++slice_id) { Mat tmp('j', slice_memptr(slice_id), n_rows, n_cols); F(tmp); } return *this; } template inline const Cube& Cube::each_slice(const std::function< void(const Mat&) >& F) const { arma_extra_debug_sigprint(); for(uword slice_id=0; slice_id < n_slices; ++slice_id) { const Mat tmp('j', slice_memptr(slice_id), n_rows, n_cols); F(tmp); } return *this; } #endif //! remove specified slice template inline void Cube::shed_slice(const uword slice_num) { arma_extra_debug_sigprint(); arma_debug_check( slice_num >= n_slices, "Cube::shed_slice(): index out of bounds"); shed_slices(slice_num, slice_num); } //! remove specified slices template inline void Cube::shed_slices(const uword in_slice1, const uword in_slice2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_slice1 > in_slice2) || (in_slice2 >= n_slices), "Cube::shed_slices(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_slice1; const uword n_keep_back = n_slices - (in_slice2 + 1); Cube X(n_rows, n_cols, n_keep_front + n_keep_back); if(n_keep_front > 0) { X.slices( 0, (n_keep_front-1) ) = slices( 0, (in_slice1-1) ); } if(n_keep_back > 0) { X.slices( n_keep_front, (n_keep_front+n_keep_back-1) ) = slices( (in_slice2+1), (n_slices-1) ); } steal_mem(X); } //! insert N slices at the specified slice position, //! optionally setting the elements of the inserted slices to zero template inline void Cube::insert_slices(const uword slice_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_slices = n_slices; const uword A_n_slices = slice_num; const uword B_n_slices = t_n_slices - slice_num; // insertion at slice_num == n_slices is in effect an append operation arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): index out of bounds"); if(N > 0) { Cube out(n_rows, n_cols, t_n_slices + N); if(A_n_slices > 0) { out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1); } if(B_n_slices > 0) { out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices-1); } if(set_to_zero == true) { //out.slices(slice_num, slice_num + N - 1).zeros(); for(uword i=slice_num; i < (slice_num + N); ++i) { arrayops::fill_zeros(out.slice_memptr(i), out.n_elem_slice); } } steal_mem(out); } } //! insert the given object at the specified slice position; //! the given object must have the same number of rows and columns as the cube template template inline void Cube::insert_slices(const uword slice_num, const BaseCube& X) { arma_extra_debug_sigprint(); const unwrap_cube tmp(X.get_ref()); const Cube& C = tmp.M; const uword N = C.n_slices; const uword t_n_slices = n_slices; const uword A_n_slices = slice_num; const uword B_n_slices = t_n_slices - slice_num; // insertion at slice_num == n_slices is in effect an append operation arma_debug_check( (slice_num > t_n_slices), "Cube::insert_slices(): index out of bounds"); arma_debug_check ( ( (C.n_rows != n_rows) || (C.n_cols != n_cols) ), "Cube::insert_slices(): given object has incompatible dimensions" ); if(N > 0) { Cube out(n_rows, n_cols, t_n_slices + N); if(A_n_slices > 0) { out.slices(0, A_n_slices-1) = slices(0, A_n_slices-1); } if(B_n_slices > 0) { out.slices(slice_num + N, t_n_slices + N - 1) = slices(slice_num, t_n_slices - 1); } out.slices(slice_num, slice_num + N - 1) = C; steal_mem(out); } } //! create a cube from OpCube, i.e. run the previously delayed unary operations template template inline Cube::Cube(const GenCube& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem_slice(X.n_rows*X.n_cols) , n_slices(X.n_slices) , n_elem(X.n_rows*X.n_cols*X.n_slices) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); init_cold(); X.apply(*this); } template template inline const Cube& Cube::operator=(const GenCube& X) { arma_extra_debug_sigprint(); init_warm(X.n_rows, X.n_cols, X.n_slices); X.apply(*this); return *this; } template template inline const Cube& Cube::operator+=(const GenCube& X) { arma_extra_debug_sigprint(); X.apply_inplace_plus(*this); return *this; } template template inline const Cube& Cube::operator-=(const GenCube& X) { arma_extra_debug_sigprint(); X.apply_inplace_minus(*this); return *this; } template template inline const Cube& Cube::operator%=(const GenCube& X) { arma_extra_debug_sigprint(); X.apply_inplace_schur(*this); return *this; } template template inline const Cube& Cube::operator/=(const GenCube& X) { arma_extra_debug_sigprint(); X.apply_inplace_div(*this); return *this; } //! create a cube from OpCube, i.e. run the previously delayed unary operations template template inline Cube::Cube(const OpCube& X) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); op_type::apply(*this, X); } //! create a cube from OpCube, i.e. run the previously delayed unary operations template template inline const Cube& Cube::operator=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); op_type::apply(*this, X); return *this; } //! in-place cube addition, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator+=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Cube m(X); return (*this).operator+=(m); } //! in-place cube subtraction, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator-=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Cube m(X); return (*this).operator-=(m); } //! in-place cube element-wise multiplication, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator%=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Cube m(X); return (*this).operator%=(m); } //! in-place cube element-wise division, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator/=(const OpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Cube m(X); return (*this).operator/=(m); } //! create a cube from eOpCube, i.e. run the previously delayed unary operations template template inline Cube::Cube(const eOpCube& X) : n_rows(X.get_n_rows()) , n_cols(X.get_n_cols()) , n_elem_slice(X.get_n_elem_slice()) , n_slices(X.get_n_slices()) , n_elem(X.get_n_elem()) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); init_cold(); eop_type::apply(*this, X); } //! create a cube from eOpCube, i.e. run the previously delayed unary operations template template inline const Cube& Cube::operator=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const bool bad_alias = ( X.P.has_subview && X.P.is_alias(*this) ); if(bad_alias == false) { init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices()); eop_type::apply(*this, X); } else { Cube tmp(X); steal_mem(tmp); } return *this; } //! in-place cube addition, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator+=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_plus(*this, X); return *this; } //! in-place cube subtraction, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator-=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_minus(*this, X); return *this; } //! in-place cube element-wise multiplication, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator%=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_schur(*this, X); return *this; } //! in-place cube element-wise division, with the right-hand-side operand having delayed operations template template inline const Cube& Cube::operator/=(const eOpCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_div(*this, X); return *this; } //! EXPERIMENTAL template template inline Cube::Cube(const mtOpCube& X) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); op_type::apply(*this, X); } //! EXPERIMENTAL template template inline const Cube& Cube::operator=(const mtOpCube& X) { arma_extra_debug_sigprint(); op_type::apply(*this, X); return *this; } //! EXPERIMENTAL template template inline const Cube& Cube::operator+=(const mtOpCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator+=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator-=(const mtOpCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator-=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator%=(const mtOpCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator%=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator/=(const mtOpCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator/=(m); } //! create a cube from Glue, i.e. run the previously delayed binary operations template template inline Cube::Cube(const GlueCube& X) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); this->operator=(X); } //! create a cube from Glue, i.e. run the previously delayed binary operations template template inline const Cube& Cube::operator=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_type::apply(*this, X); return *this; } //! in-place cube addition, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator+=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Cube m(X); return (*this).operator+=(m); } //! in-place cube subtraction, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator-=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Cube m(X); return (*this).operator-=(m); } //! in-place cube element-wise multiplication, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator%=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Cube m(X); return (*this).operator%=(m); } //! in-place cube element-wise division, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator/=(const GlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Cube m(X); return (*this).operator/=(m); } //! create a cube from eGlue, i.e. run the previously delayed binary operations template template inline Cube::Cube(const eGlueCube& X) : n_rows(X.get_n_rows()) , n_cols(X.get_n_cols()) , n_elem_slice(X.get_n_elem_slice()) , n_slices(X.get_n_slices()) , n_elem(X.get_n_elem()) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); init_cold(); eglue_type::apply(*this, X); } //! create a cube from Glue, i.e. run the previously delayed binary operations template template inline const Cube& Cube::operator=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const bool bad_alias = ( (X.P1.has_subview && X.P1.is_alias(*this)) || (X.P2.has_subview && X.P2.is_alias(*this)) ); if(bad_alias == false) { init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices()); eglue_type::apply(*this, X); } else { Cube tmp(X); steal_mem(tmp); } return *this; } //! in-place cube addition, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator+=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_plus(*this, X); return *this; } //! in-place cube subtraction, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator-=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_minus(*this, X); return *this; } //! in-place cube element-wise multiplication, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator%=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_schur(*this, X); return *this; } //! in-place cube element-wise division, with the right-hand-side operands having delayed operations template template inline const Cube& Cube::operator/=(const eGlueCube& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_div(*this, X); return *this; } //! EXPERIMENTAL template template inline Cube::Cube(const mtGlueCube& X) : n_rows(0) , n_cols(0) , n_elem_slice(0) , n_slices(0) , n_elem(0) , mem_state(0) , mem() , mat_ptrs(0) { arma_extra_debug_sigprint_this(this); glue_type::apply(*this, X); } //! EXPERIMENTAL template template inline const Cube& Cube::operator=(const mtGlueCube& X) { arma_extra_debug_sigprint(); glue_type::apply(*this, X); return *this; } //! EXPERIMENTAL template template inline const Cube& Cube::operator+=(const mtGlueCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator+=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator-=(const mtGlueCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator-=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator%=(const mtGlueCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator%=(m); } //! EXPERIMENTAL template template inline const Cube& Cube::operator/=(const mtGlueCube& X) { arma_extra_debug_sigprint(); const Cube m(X); return (*this).operator/=(m); } //! linear element accessor (treats the cube as a vector); no bounds check; assumes memory is aligned template arma_inline arma_warn_unused const eT& Cube::at_alt(const uword i) const { const eT* mem_aligned = mem; memory::mark_as_aligned(mem_aligned); return mem_aligned[i]; } //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused eT& Cube::operator() (const uword i) { arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds"); return access::rw(mem[i]); } //! linear element accessor (treats the cube as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused const eT& Cube::operator() (const uword i) const { arma_debug_check( (i >= n_elem), "Cube::operator(): index out of bounds"); return mem[i]; } //! linear element accessor (treats the cube as a vector); no bounds check. template arma_inline arma_warn_unused eT& Cube::operator[] (const uword i) { return access::rw(mem[i]); } //! linear element accessor (treats the cube as a vector); no bounds check template arma_inline arma_warn_unused const eT& Cube::operator[] (const uword i) const { return mem[i]; } //! linear element accessor (treats the cube as a vector); no bounds check. template arma_inline arma_warn_unused eT& Cube::at(const uword i) { return access::rw(mem[i]); } //! linear element accessor (treats the cube as a vector); no bounds check template arma_inline arma_warn_unused const eT& Cube::at(const uword i) const { return mem[i]; } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused eT& Cube::operator() (const uword in_row, const uword in_col, const uword in_slice) { arma_debug_check ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) , "Cube::operator(): index out of bounds" ); return access::rw(mem[in_slice*n_elem_slice + in_col*n_rows + in_row]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused const eT& Cube::operator() (const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) , "Cube::operator(): index out of bounds" ); return mem[in_slice*n_elem_slice + in_col*n_rows + in_row]; } //! element accessor; no bounds check template arma_inline arma_warn_unused eT& Cube::at(const uword in_row, const uword in_col, const uword in_slice) { return access::rw( mem[in_slice*n_elem_slice + in_col*n_rows + in_row] ); } //! element accessor; no bounds check template arma_inline arma_warn_unused const eT& Cube::at(const uword in_row, const uword in_col, const uword in_slice) const { return mem[in_slice*n_elem_slice + in_col*n_rows + in_row]; } //! prefix ++ template arma_inline const Cube& Cube::operator++() { Cube_aux::prefix_pp(*this); return *this; } //! postfix ++ (must not return the object by reference) template arma_inline void Cube::operator++(int) { Cube_aux::postfix_pp(*this); } //! prefix -- template arma_inline const Cube& Cube::operator--() { Cube_aux::prefix_mm(*this); return *this; } //! postfix -- (must not return the object by reference) template arma_inline void Cube::operator--(int) { Cube_aux::postfix_mm(*this); } //! returns true if all of the elements are finite template arma_inline arma_warn_unused bool Cube::is_finite() const { return arrayops::is_finite( memptr(), n_elem ); } //! returns true if the cube has no elements template arma_inline arma_warn_unused bool Cube::is_empty() const { return (n_elem == 0); } template inline arma_warn_unused bool Cube::has_inf() const { arma_extra_debug_sigprint(); return arrayops::has_inf( memptr(), n_elem ); } template inline arma_warn_unused bool Cube::has_nan() const { arma_extra_debug_sigprint(); return arrayops::has_nan( memptr(), n_elem ); } //! returns true if the given index is currently in range template arma_inline arma_warn_unused bool Cube::in_range(const uword i) const { return (i < n_elem); } //! returns true if the given start and end indices are currently in range template arma_inline arma_warn_unused bool Cube::in_range(const span& x) const { arma_extra_debug_sigprint(); if(x.whole == true) { return true; } else { const uword a = x.a; const uword b = x.b; return ( (a <= b) && (b < n_elem) ); } } //! returns true if the given location is currently in range template arma_inline arma_warn_unused bool Cube::in_range(const uword in_row, const uword in_col, const uword in_slice) const { return ( (in_row < n_rows) && (in_col < n_cols) && (in_slice < n_slices) ); } template inline arma_warn_unused bool Cube::in_range(const span& row_span, const span& col_span, const span& slice_span) const { arma_extra_debug_sigprint(); const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; const uword in_slice1 = slice_span.a; const uword in_slice2 = slice_span.b; const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); const bool slices_ok = slice_span.whole ? true : ( (in_slice1 <= in_slice2) && (in_slice2 < n_slices) ); return ( (rows_ok == true) && (cols_ok == true) && (slices_ok == true) ); } template inline arma_warn_unused bool Cube::in_range(const uword in_row, const uword in_col, const uword in_slice, const SizeCube& s) const { const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword l_n_slices = n_slices; if( ( in_row >= l_n_rows) || ( in_col >= l_n_cols) || ( in_slice >= l_n_slices) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) || ((in_slice + s.n_slices) > l_n_slices) ) { return false; } else { return true; } } //! returns a pointer to array of eTs used by the cube template arma_inline arma_warn_unused eT* Cube::memptr() { return const_cast(mem); } //! returns a pointer to array of eTs used by the cube template arma_inline arma_warn_unused const eT* Cube::memptr() const { return mem; } //! returns a pointer to array of eTs used by the specified slice in the cube template arma_inline arma_warn_unused eT* Cube::slice_memptr(const uword uslice) { return const_cast( &mem[ uslice*n_elem_slice ] ); } //! returns a pointer to array of eTs used by the specified slice in the cube template arma_inline arma_warn_unused const eT* Cube::slice_memptr(const uword uslice) const { return &mem[ uslice*n_elem_slice ]; } //! returns a pointer to array of eTs used by the specified slice in the cube template arma_inline arma_warn_unused eT* Cube::slice_colptr(const uword uslice, const uword col) { return const_cast( &mem[ uslice*n_elem_slice + col*n_rows] ); } //! returns a pointer to array of eTs used by the specified slice in the cube template arma_inline arma_warn_unused const eT* Cube::slice_colptr(const uword uslice, const uword col) const { return &mem[ uslice*n_elem_slice + col*n_rows ]; } //! print contents of the cube (to the cout stream), //! optionally preceding with a user specified line of text. //! the precision and cell width are modified. //! on return, the stream's state are restored to their original values. template inline void Cube::impl_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { ARMA_DEFAULT_OSTREAM << extra_text << '\n'; } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true); } //! print contents of the cube to a user specified stream, //! optionally preceding with a user specified line of text. //! the precision and cell width are modified. //! on return, the stream's state are restored to their original values. template inline void Cube::impl_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { user_stream << extra_text << '\n'; } arma_ostream::print(user_stream, *this, true); } //! print contents of the cube (to the cout stream), //! optionally preceding with a user specified line of text. //! the stream's state are used as is and are not modified //! (i.e. the precision and cell width are not modified). template inline void Cube::impl_raw_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { ARMA_DEFAULT_OSTREAM << extra_text << '\n'; } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false); } //! print contents of the cube to a user specified stream, //! optionally preceding with a user specified line of text. //! the stream's state are used as is and are not modified. //! (i.e. the precision and cell width are not modified). template inline void Cube::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { user_stream << extra_text << '\n'; } arma_ostream::print(user_stream, *this, false); } //! change the cube to have user specified dimensions (data is not preserved) template inline void Cube::set_size(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) { arma_extra_debug_sigprint(); init_warm(in_n_rows, in_n_cols, in_n_slices); } //! change the cube to have user specified dimensions (data is preserved) template inline void Cube::reshape(const uword in_rows, const uword in_cols, const uword in_slices, const uword dim) { arma_extra_debug_sigprint(); *this = arma::reshape(*this, in_rows, in_cols, in_slices, dim); } //! change the cube to have user specified dimensions (data is preserved) template inline void Cube::resize(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); *this = arma::resize(*this, in_rows, in_cols, in_slices); } template inline void Cube::set_size(const SizeCube& s) { arma_extra_debug_sigprint(); init_warm(s.n_rows, s.n_cols, s.n_slices); } template inline void Cube::reshape(const SizeCube& s) { arma_extra_debug_sigprint(); *this = arma::reshape(*this, s.n_rows, s.n_cols, s.n_slices, 0); } template inline void Cube::resize(const SizeCube& s) { arma_extra_debug_sigprint(); *this = arma::resize(*this, s.n_rows, s.n_cols, s.n_slices); } //! change the cube (without preserving data) to have the same dimensions as the given cube template template inline void Cube::copy_size(const Cube& m) { arma_extra_debug_sigprint(); init_warm(m.n_rows, m.n_cols, m.n_slices); } //! apply a functor to each element template template inline const Cube& Cube::for_each(functor F) { arma_extra_debug_sigprint(); eT* data = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { F(data[ii]); F(data[jj]); } if(ii < N) { F(data[ii]); } return *this; } template template inline const Cube& Cube::for_each(functor F) const { arma_extra_debug_sigprint(); const eT* data = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { F(data[ii]); F(data[jj]); } if(ii < N) { F(data[ii]); } return *this; } //! transform each element in the cube using a functor template template inline const Cube& Cube::transform(functor F) { arma_extra_debug_sigprint(); eT* out_mem = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { eT tmp_ii = out_mem[ii]; eT tmp_jj = out_mem[jj]; tmp_ii = eT( F(tmp_ii) ); tmp_jj = eT( F(tmp_jj) ); out_mem[ii] = tmp_ii; out_mem[jj] = tmp_jj; } if(ii < N) { out_mem[ii] = eT( F(out_mem[ii]) ); } return *this; } //! imbue (fill) the cube with values provided by a functor template template inline const Cube& Cube::imbue(functor F) { arma_extra_debug_sigprint(); eT* out_mem = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { const eT tmp_ii = eT( F() ); const eT tmp_jj = eT( F() ); out_mem[ii] = tmp_ii; out_mem[jj] = tmp_jj; } if(ii < N) { out_mem[ii] = eT( F() ); } return *this; } //! fill the cube with the specified value template inline const Cube& Cube::fill(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_set( memptr(), val, n_elem ); return *this; } template inline const Cube& Cube::zeros() { arma_extra_debug_sigprint(); arrayops::fill_zeros(memptr(), n_elem); return *this; } template inline const Cube& Cube::zeros(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols, in_slices); return (*this).zeros(); } template inline const Cube& Cube::zeros(const SizeCube& s) { arma_extra_debug_sigprint(); return (*this).zeros(s.n_rows, s.n_cols, s.n_slices); } template inline const Cube& Cube::ones() { arma_extra_debug_sigprint(); return (*this).fill(eT(1)); } template inline const Cube& Cube::ones(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols, in_slices); return (*this).fill(eT(1)); } template inline const Cube& Cube::ones(const SizeCube& s) { arma_extra_debug_sigprint(); return (*this).ones(s.n_rows, s.n_cols, s.n_slices); } template inline const Cube& Cube::randu() { arma_extra_debug_sigprint(); arma_rng::randu::fill( memptr(), n_elem ); return *this; } template inline const Cube& Cube::randu(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols, in_slices); return (*this).randu(); } template inline const Cube& Cube::randu(const SizeCube& s) { arma_extra_debug_sigprint(); return (*this).randu(s.n_rows, s.n_cols, s.n_slices); } template inline const Cube& Cube::randn() { arma_extra_debug_sigprint(); arma_rng::randn::fill( memptr(), n_elem ); return *this; } template inline const Cube& Cube::randn(const uword in_rows, const uword in_cols, const uword in_slices) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols, in_slices); return (*this).randn(); } template inline const Cube& Cube::randn(const SizeCube& s) { arma_extra_debug_sigprint(); return (*this).randn(s.n_rows, s.n_cols, s.n_slices); } template inline void Cube::reset() { arma_extra_debug_sigprint(); init_warm(0,0,0); } template template inline void Cube::set_real(const BaseCube::pod_type,T1>& X) { arma_extra_debug_sigprint(); Cube_aux::set_real(*this, X); } template template inline void Cube::set_imag(const BaseCube::pod_type,T1>& X) { arma_extra_debug_sigprint(); Cube_aux::set_imag(*this, X); } template inline arma_warn_unused eT Cube::min() const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Cube::min(): object has no elements"); return Datum::nan; } return op_min::direct_min(memptr(), n_elem); } template inline arma_warn_unused eT Cube::max() const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Cube::max(): object has no elements"); return Datum::nan; } return op_max::direct_max(memptr(), n_elem); } template inline eT Cube::min(uword& index_of_min_val) const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Cube::min(): object has no elements"); return Datum::nan; } return op_min::direct_min(memptr(), n_elem, index_of_min_val); } template inline eT Cube::max(uword& index_of_max_val) const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Cube::max(): object has no elements"); return Datum::nan; } return op_max::direct_max(memptr(), n_elem, index_of_max_val); } template inline eT Cube::min(uword& row_of_min_val, uword& col_of_min_val, uword& slice_of_min_val) const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Cube::min(): object has no elements"); return Datum::nan; } uword i; eT val = op_min::direct_min(memptr(), n_elem, i); const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; row_of_min_val = j % n_rows; col_of_min_val = j / n_rows; slice_of_min_val = in_slice; return val; } template inline eT Cube::max(uword& row_of_max_val, uword& col_of_max_val, uword& slice_of_max_val) const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Cube::max(): object has no elements"); return Datum::nan; } uword i; eT val = op_max::direct_max(memptr(), n_elem, i); const uword in_slice = i / n_elem_slice; const uword offset = in_slice * n_elem_slice; const uword j = i - offset; row_of_max_val = j % n_rows; col_of_max_val = j / n_rows; slice_of_max_val = in_slice; return val; } //! save the cube to a file template inline bool Cube::save(const std::string name, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { case raw_ascii: save_okay = diskio::save_raw_ascii(*this, name); break; case arma_ascii: save_okay = diskio::save_arma_ascii(*this, name); break; case raw_binary: save_okay = diskio::save_raw_binary(*this, name); break; case arma_binary: save_okay = diskio::save_arma_binary(*this, name); break; case ppm_binary: save_okay = diskio::save_ppm_binary(*this, name); break; case hdf5_binary: save_okay = diskio::save_hdf5_binary(*this, name); break; default: if(print_status) { arma_debug_warn("Cube::save(): unsupported file type"); } save_okay = false; } if(print_status && (save_okay == false)) { arma_debug_warn("Cube::save(): couldn't write to ", name); } return save_okay; } //! save the cube to a stream template inline bool Cube::save(std::ostream& os, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { case raw_ascii: save_okay = diskio::save_raw_ascii(*this, os); break; case arma_ascii: save_okay = diskio::save_arma_ascii(*this, os); break; case raw_binary: save_okay = diskio::save_raw_binary(*this, os); break; case arma_binary: save_okay = diskio::save_arma_binary(*this, os); break; case ppm_binary: save_okay = diskio::save_ppm_binary(*this, os); break; default: if(print_status) { arma_debug_warn("Cube::save(): unsupported file type"); } save_okay = false; } if(print_status && (save_okay == false)) { arma_debug_warn("Cube::save(): couldn't write to given stream"); } return save_okay; } //! load a cube from a file template inline bool Cube::load(const std::string name, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { case auto_detect: load_okay = diskio::load_auto_detect(*this, name, err_msg); break; case raw_ascii: load_okay = diskio::load_raw_ascii(*this, name, err_msg); break; case arma_ascii: load_okay = diskio::load_arma_ascii(*this, name, err_msg); break; case raw_binary: load_okay = diskio::load_raw_binary(*this, name, err_msg); break; case arma_binary: load_okay = diskio::load_arma_binary(*this, name, err_msg); break; case ppm_binary: load_okay = diskio::load_ppm_binary(*this, name, err_msg); break; case hdf5_binary: load_okay = diskio::load_hdf5_binary(*this, name, err_msg); break; default: if(print_status) { arma_debug_warn("Cube::load(): unsupported file type"); } load_okay = false; } if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_debug_warn("Cube::load(): ", err_msg, name); } else { arma_debug_warn("Cube::load(): couldn't read ", name); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! load a cube from a stream template inline bool Cube::load(std::istream& is, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { case auto_detect: load_okay = diskio::load_auto_detect(*this, is, err_msg); break; case raw_ascii: load_okay = diskio::load_raw_ascii(*this, is, err_msg); break; case arma_ascii: load_okay = diskio::load_arma_ascii(*this, is, err_msg); break; case raw_binary: load_okay = diskio::load_raw_binary(*this, is, err_msg); break; case arma_binary: load_okay = diskio::load_arma_binary(*this, is, err_msg); break; case ppm_binary: load_okay = diskio::load_ppm_binary(*this, is, err_msg); break; default: if(print_status) { arma_debug_warn("Cube::load(): unsupported file type"); } load_okay = false; } if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_debug_warn("Cube::load(): ", err_msg, "the given stream"); } else { arma_debug_warn("Cube::load(): couldn't load from the given stream"); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! save the cube to a file, without printing any error messages template inline bool Cube::quiet_save(const std::string name, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(name, type, false); } //! save the cube to a stream, without printing any error messages template inline bool Cube::quiet_save(std::ostream& os, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(os, type, false); } //! load a cube from a file, without printing any error messages template inline bool Cube::quiet_load(const std::string name, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(name, type, false); } //! load a cube from a stream, without printing any error messages template inline bool Cube::quiet_load(std::istream& is, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(is, type, false); } template inline typename Cube::iterator Cube::begin() { arma_extra_debug_sigprint(); return memptr(); } template inline typename Cube::const_iterator Cube::begin() const { arma_extra_debug_sigprint(); return memptr(); } template inline typename Cube::const_iterator Cube::cbegin() const { arma_extra_debug_sigprint(); return memptr(); } template inline typename Cube::iterator Cube::end() { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Cube::const_iterator Cube::end() const { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Cube::const_iterator Cube::cend() const { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Cube::slice_iterator Cube::begin_slice(const uword slice_num) { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds"); return slice_memptr(slice_num); } template inline typename Cube::const_slice_iterator Cube::begin_slice(const uword slice_num) const { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "begin_slice(): index out of bounds"); return slice_memptr(slice_num); } template inline typename Cube::slice_iterator Cube::end_slice(const uword slice_num) { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds"); return slice_memptr(slice_num) + n_elem_slice; } template inline typename Cube::const_slice_iterator Cube::end_slice(const uword slice_num) const { arma_extra_debug_sigprint(); arma_debug_check( (slice_num >= n_slices), "end_slice(): index out of bounds"); return slice_memptr(slice_num) + n_elem_slice; } //! resets this cube to an empty matrix template inline void Cube::clear() { reset(); } //! returns true if the cube has no elements template inline bool Cube::empty() const { return (n_elem == 0); } //! returns the number of elements in this cube template inline uword Cube::size() const { return n_elem; } template inline void Cube::swap(Cube& B) { Cube& A = (*this); arma_extra_debug_sigprint(arma_str::format("A = %x B = %x") % &A % &B); if( (A.mem_state == 0) && (B.mem_state == 0) && (A.n_elem > Cube_prealloc::mem_n_elem) && (B.n_elem > Cube_prealloc::mem_n_elem) ) { A.delete_mat(); B.delete_mat(); std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); std::swap( access::rw(A.n_elem_slice), access::rw(B.n_elem_slice) ); std::swap( access::rw(A.n_slices), access::rw(B.n_slices) ); std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); std::swap( access::rw(A.mem), access::rw(B.mem) ); A.create_mat(); B.create_mat(); } else if( (A.mem_state == 0) && (B.mem_state == 0) && (A.n_elem <= Cube_prealloc::mem_n_elem) && (B.n_elem <= Cube_prealloc::mem_n_elem) ) { A.delete_mat(); B.delete_mat(); std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); std::swap( access::rw(A.n_elem_slice), access::rw(B.n_elem_slice) ); std::swap( access::rw(A.n_slices), access::rw(B.n_slices) ); std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); const uword N = (std::max)(A.n_elem, B.n_elem); eT* A_mem = A.memptr(); eT* B_mem = B.memptr(); for(uword i=0; i C = A; A.steal_mem(B); B.steal_mem(C); } else { Cube C = B; B.steal_mem(A); A.steal_mem(C); } } } //! try to steal the memory from a given cube; //! if memory can't be stolen, copy the given cube template inline void Cube::steal_mem(Cube& x) { arma_extra_debug_sigprint(); if(this == &x) { return; } if( (mem_state <= 1) && ( ((x.mem_state == 0) && (x.n_elem > Cube_prealloc::mem_n_elem)) || (x.mem_state == 1) ) ) { reset(); const uword x_n_slices = x.n_slices; access::rw(n_rows) = x.n_rows; access::rw(n_cols) = x.n_cols; access::rw(n_elem_slice) = x.n_elem_slice; access::rw(n_slices) = x_n_slices; access::rw(n_elem) = x.n_elem; access::rw(mem_state) = x.mem_state; access::rw(mem) = x.mem; if(x_n_slices > Cube_prealloc::mat_ptrs_size) { access::rw( mat_ptrs) = x.mat_ptrs; access::rw(x.mat_ptrs) = 0; } else { access::rw(mat_ptrs) = const_cast< const Mat** >(mat_ptrs_local); for(uword i=0; i < x_n_slices; ++i) { mat_ptrs[i] = x.mat_ptrs[i]; x.mat_ptrs[i] = 0; } } access::rw(x.n_rows) = 0; access::rw(x.n_cols) = 0; access::rw(x.n_elem_slice) = 0; access::rw(x.n_slices) = 0; access::rw(x.n_elem) = 0; access::rw(x.mem_state) = 0; access::rw(x.mem) = 0; } else { (*this).operator=(x); } } // // Cube::fixed template template arma_inline void Cube::fixed::mem_setup() { arma_extra_debug_sigprint(); if(fixed_n_elem > 0) { access::rw(Cube::n_rows) = fixed_n_rows; access::rw(Cube::n_cols) = fixed_n_cols; access::rw(Cube::n_elem_slice) = fixed_n_rows * fixed_n_cols; access::rw(Cube::n_slices) = fixed_n_slices; access::rw(Cube::n_elem) = fixed_n_elem; access::rw(Cube::mem_state) = 3; access::rw(Cube::mem) = (fixed_n_elem > Cube_prealloc::mem_n_elem) ? mem_local_extra : mem_local; access::rw(Cube::mat_ptrs) = const_cast< const Mat** >( \ (fixed_n_slices > Cube_prealloc::mat_ptrs_size) ? mat_ptrs_local_extra : mat_ptrs_local ); create_mat(); } else { access::rw(Cube::n_rows) = 0; access::rw(Cube::n_cols) = 0; access::rw(Cube::n_elem_slice) = 0; access::rw(Cube::n_slices) = 0; access::rw(Cube::n_elem) = 0; access::rw(Cube::mem_state) = 3; access::rw(Cube::mem) = 0; access::rw(Cube::mat_ptrs) = 0; } } template template inline Cube::fixed::fixed() { arma_extra_debug_sigprint_this(this); mem_setup(); } template template inline Cube::fixed::fixed(const fixed& X) { arma_extra_debug_sigprint_this(this); mem_setup(); eT* dest = (use_extra) ? mem_local_extra : mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } template template template inline Cube::fixed::fixed(const fill::fill_class&) { arma_extra_debug_sigprint_this(this); mem_setup(); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); if(is_same_type::yes) { arma_debug_check(true, "Cube::fixed::fixed(): unsupported fill type"); } } template template template inline Cube::fixed::fixed(const BaseCube& A) { arma_extra_debug_sigprint_this(this); mem_setup(); Cube::operator=(A.get_ref()); } template template template inline Cube::fixed::fixed(const BaseCube& A, const BaseCube& B) { arma_extra_debug_sigprint_this(this); mem_setup(); Cube::init(A,B); } template template inline const Cube& Cube::fixed::operator=(const fixed& X) { arma_extra_debug_sigprint(); eT* dest = (use_extra) ? mem_local_extra : mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); return *this; } template template arma_inline arma_warn_unused eT& Cube::fixed::operator[] (const uword i) { return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::operator[] (const uword i) const { return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused eT& Cube::fixed::at(const uword i) { return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::at(const uword i) const { return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused eT& Cube::fixed::operator() (const uword i) { arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::operator() (const uword i) const { arma_debug_check( (i >= fixed_n_elem), "Cube::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused eT& Cube::fixed::at(const uword in_row, const uword in_col, const uword in_slice) { const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::at(const uword in_row, const uword in_col, const uword in_slice) const { const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused eT& Cube::fixed::operator() (const uword in_row, const uword in_col, const uword in_slice) { arma_debug_check ( (in_row >= fixed_n_rows ) || (in_col >= fixed_n_cols ) || (in_slice >= fixed_n_slices) , "operator(): index out of bounds" ); const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; return (use_extra) ? mem_local_extra[i] : mem_local[i]; } template template arma_inline arma_warn_unused const eT& Cube::fixed::operator() (const uword in_row, const uword in_col, const uword in_slice) const { arma_debug_check ( (in_row >= fixed_n_rows ) || (in_col >= fixed_n_cols ) || (in_slice >= fixed_n_slices) , "Cube::operator(): index out of bounds" ); const uword i = in_slice*fixed_n_elem_slice + in_col*fixed_n_rows + in_row; return (use_extra) ? mem_local_extra[i] : mem_local[i]; } // // Cube_aux //! prefix ++ template arma_inline void Cube_aux::prefix_pp(Cube& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Cube_aux::prefix_pp(Cube< std::complex >& x) { x += T(1); } //! postfix ++ template arma_inline void Cube_aux::postfix_pp(Cube& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Cube_aux::postfix_pp(Cube< std::complex >& x) { x += T(1); } //! prefix -- template arma_inline void Cube_aux::prefix_mm(Cube& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Cube_aux::prefix_mm(Cube< std::complex >& x) { x -= T(1); } //! postfix -- template arma_inline void Cube_aux::postfix_mm(Cube& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Cube_aux::postfix_mm(Cube< std::complex >& x) { x -= T(1); } template inline void Cube_aux::set_real(Cube& out, const BaseCube& X) { arma_extra_debug_sigprint(); const unwrap_cube tmp(X.get_ref()); const Cube& A = tmp.M; arma_debug_assert_same_size( out, A, "Cube::set_real()" ); out = A; } template inline void Cube_aux::set_imag(Cube&, const BaseCube&) { arma_extra_debug_sigprint(); } template inline void Cube_aux::set_real(Cube< std::complex >& out, const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube P(X.get_ref()); const uword local_n_rows = P.get_n_rows(); const uword local_n_cols = P.get_n_cols(); const uword local_n_slices = P.get_n_slices(); arma_debug_assert_same_size ( out.n_rows, out.n_cols, out.n_slices, local_n_rows, local_n_cols, local_n_slices, "Cube::set_real()" ); eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; ea_type A = P.get_ea(); const uword N = out.n_elem; for(uword i=0; i( A[i], out_mem[i].imag() ); } } else { for(uword slice = 0; slice < local_n_slices; ++slice) for(uword col = 0; col < local_n_cols; ++col ) for(uword row = 0; row < local_n_rows; ++row ) { (*out_mem) = std::complex( P.at(row,col,slice), (*out_mem).imag() ); out_mem++; } } } template inline void Cube_aux::set_imag(Cube< std::complex >& out, const BaseCube& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const ProxyCube P(X.get_ref()); const uword local_n_rows = P.get_n_rows(); const uword local_n_cols = P.get_n_cols(); const uword local_n_slices = P.get_n_slices(); arma_debug_assert_same_size ( out.n_rows, out.n_cols, out.n_slices, local_n_rows, local_n_cols, local_n_slices, "Cube::set_imag()" ); eT* out_mem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typedef typename ProxyCube::ea_type ea_type; ea_type A = P.get_ea(); const uword N = out.n_elem; for(uword i=0; i( out_mem[i].real(), A[i] ); } } else { for(uword slice = 0; slice < local_n_slices; ++slice) for(uword col = 0; col < local_n_cols; ++col ) for(uword row = 0; row < local_n_rows; ++row ) { (*out_mem) = std::complex( (*out_mem).real(), P.at(row,col,slice) ); out_mem++; } } } #ifdef ARMA_EXTRA_CUBE_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_CUBE_MEAT) #endif //! @} armadillo-6.500.5/include/armadillo_bits/fn_join.hpp0000666000000000000000000001145512620272703021107 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_join //! @{ template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && is_same_type::value), const Glue >::result join_cols(const T1& A, const T2& B) { arma_extra_debug_sigprint(); return Glue(A, B); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && is_same_type::value), const Glue >::result join_vert(const T1& A, const T2& B) { arma_extra_debug_sigprint(); return Glue(A, B); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && is_same_type::value), const Glue >::result join_rows(const T1& A, const T2& B) { arma_extra_debug_sigprint(); return Glue(A, B); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && is_same_type::value), const Glue >::result join_horiz(const T1& A, const T2& B) { arma_extra_debug_sigprint(); return Glue(A, B); } // // for cubes template inline const GlueCube join_slices(const BaseCube& A, const BaseCube& B) { arma_extra_debug_sigprint(); return GlueCube(A.get_ref(), B.get_ref()); } template inline Cube join_slices(const Base& A, const Base& B) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap UA(A.get_ref()); const unwrap UB(B.get_ref()); arma_debug_assert_same_size(UA.M.n_rows, UA.M.n_cols, UB.M.n_rows, UB.M.n_cols, "join_slices(): incompatible dimensions"); Cube out(UA.M.n_rows, UA.M.n_cols, 2); arrayops::copy(out.slice_memptr(0), UA.M.memptr(), UA.M.n_elem); arrayops::copy(out.slice_memptr(1), UB.M.memptr(), UB.M.n_elem); return out; } template inline Cube join_slices(const Base& A, const BaseCube& B) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap U(A.get_ref()); const Cube M(const_cast(U.M.memptr()), U.M.n_rows, U.M.n_cols, 1, false); return join_slices(M,B); } template inline Cube join_slices(const BaseCube& A, const Base& B) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap U(B.get_ref()); const Cube M(const_cast(U.M.memptr()), U.M.n_rows, U.M.n_cols, 1, false); return join_slices(A,M); } // // for sparse matrices template inline const SpGlue join_cols(const SpBase& A, const SpBase& B) { arma_extra_debug_sigprint(); return SpGlue(A.get_ref(), B.get_ref()); } template inline const SpGlue join_vert(const SpBase& A, const SpBase& B) { arma_extra_debug_sigprint(); return SpGlue(A.get_ref(), B.get_ref()); } template inline const SpGlue join_rows(const SpBase& A, const SpBase& B) { arma_extra_debug_sigprint(); return SpGlue(A.get_ref(), B.get_ref()); } template inline const SpGlue join_horiz(const SpBase& A, const SpBase& B) { arma_extra_debug_sigprint(); return SpGlue(A.get_ref(), B.get_ref()); } //! @} armadillo-6.500.5/include/armadillo_bits/mtGlueCube_bones.hpp0000666000000000000000000000214112620272703022677 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup mtGlueCube //! @{ template class mtGlueCube : public BaseCube > { public: typedef out_eT elem_type; typedef typename get_pod_type::result pod_type; arma_inline mtGlueCube(const T1& in_A, const T2& in_B); arma_inline mtGlueCube(const T1& in_A, const T2& in_B, const uword in_aux_uword); arma_inline ~mtGlueCube(); arma_aligned const T1& A; //!< first operand arma_aligned const T2& B; //!< second operand arma_aligned uword aux_uword; //!< storage of auxiliary data, uword format }; //! @} armadillo-6.500.5/include/armadillo_bits/spglue_minus_meat.hpp0000666000000000000000000001054712620272703023206 0ustar rootroot// Copyright (C) 2012-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spglue_minus //! @{ template arma_hot inline void spglue_minus::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_minus::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_minus::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } } template arma_hot inline void spglue_minus::apply_noalias(SpMat& result, const SpProxy& pa, const SpProxy& pb) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(pa.get_n_rows(), pa.get_n_cols(), pb.get_n_rows(), pb.get_n_cols(), "subtraction"); if( (pa.get_n_nonzero() != 0) && (pb.get_n_nonzero() != 0) ) { result.zeros(pa.get_n_rows(), pa.get_n_cols()); // Resize memory to correct size. result.mem_resize(n_unique(pa, pb, op_n_unique_sub())); // Now iterate across both matrices. typename SpProxy::const_iterator_type x_it = pa.begin(); typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type x_end = pa.end(); typename SpProxy::const_iterator_type y_end = pb.end(); uword cur_val = 0; while((x_it != x_end) || (y_it != y_end)) { if(x_it == y_it) { const eT val = (*x_it) - (*y_it); if(val != eT(0)) { access::rw(result.values[cur_val]) = val; access::rw(result.row_indices[cur_val]) = x_it.row(); ++access::rw(result.col_ptrs[x_it.col() + 1]); ++cur_val; } ++x_it; ++y_it; } else { const uword x_it_row = x_it.row(); const uword x_it_col = x_it.col(); const uword y_it_row = y_it.row(); const uword y_it_col = y_it.col(); if((x_it_col < y_it_col) || ((x_it_col == y_it_col) && (x_it_row < y_it_row))) // if y is closer to the end { const eT val = (*x_it); if(val != eT(0)) { access::rw(result.values[cur_val]) = val; access::rw(result.row_indices[cur_val]) = x_it_row; ++access::rw(result.col_ptrs[x_it_col + 1]); ++cur_val; } ++x_it; } else { const eT val = (*y_it); if(val != eT(0)) { access::rw(result.values[cur_val]) = -(val); // take the negative access::rw(result.row_indices[cur_val]) = y_it_row; ++access::rw(result.col_ptrs[y_it_col + 1]); ++cur_val; } ++y_it; } } } // Fix column pointers to be cumulative. for(uword c = 1; c <= result.n_cols; ++c) { access::rw(result.col_ptrs[c]) += result.col_ptrs[c - 1]; } } else { if(pa.get_n_nonzero() == 0) { result = pb.Q; result *= eT(-1); return; } if(pb.get_n_nonzero() == 0) { result = pa.Q; return; } } } // // // spglue_minus2: scalar*(A - B) template arma_hot inline void spglue_minus2::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_minus::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_minus::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } out *= X.aux; } //! @} armadillo-6.500.5/include/armadillo_bits/SpSubview_bones.hpp0000666000000000000000000003520712620272703022603 0ustar rootroot// Copyright (C) 2011-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin // Written by Matthew Amidon //! \addtogroup SpSubview //! @{ template class SpSubview : public SpBase > { public: const SpMat& m; typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = false; const uword aux_row1; const uword aux_col1; const uword n_rows; const uword n_cols; const uword n_elem; const uword n_nonzero; // So that SpValProxy can call add_element() and delete_element(). friend class SpValProxy >; protected: arma_inline SpSubview(const SpMat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); arma_inline SpSubview( SpMat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); public: inline ~SpSubview(); inline const SpSubview& operator+= (const eT val); inline const SpSubview& operator-= (const eT val); inline const SpSubview& operator*= (const eT val); inline const SpSubview& operator/= (const eT val); inline const SpSubview& operator=(const SpSubview& x); template inline const SpSubview& operator= (const Base& x); template inline const SpSubview& operator+=(const Base& x); template inline const SpSubview& operator-=(const Base& x); template inline const SpSubview& operator*=(const Base& x); template inline const SpSubview& operator%=(const Base& x); template inline const SpSubview& operator/=(const Base& x); template inline const SpSubview& operator_equ_common(const SpBase& x); template inline const SpSubview& operator= (const SpBase& x); template inline const SpSubview& operator+=(const SpBase& x); template inline const SpSubview& operator-=(const SpBase& x); template inline const SpSubview& operator*=(const SpBase& x); template inline const SpSubview& operator%=(const SpBase& x); template inline const SpSubview& operator/=(const SpBase& x); /* inline static void extract(SpMat& out, const SpSubview& in); inline static void plus_inplace(Mat& out, const subview& in); inline static void minus_inplace(Mat& out, const subview& in); inline static void schur_inplace(Mat& out, const subview& in); inline static void div_inplace(Mat& out, const subview& in); */ inline void fill(const eT val); inline void zeros(); inline void ones(); inline void eye(); arma_hot inline SpValProxy > operator[](const uword i); arma_hot inline eT operator[](const uword i) const; arma_hot inline SpValProxy > operator()(const uword i); arma_hot inline eT operator()(const uword i) const; arma_hot inline SpValProxy > operator()(const uword in_row, const uword in_col); arma_hot inline eT operator()(const uword in_row, const uword in_col) const; arma_hot inline SpValProxy > at(const uword i); arma_hot inline eT at(const uword i) const; arma_hot inline SpValProxy > at(const uword in_row, const uword in_col); arma_hot inline eT at(const uword in_row, const uword in_col) const; inline bool check_overlap(const SpSubview& x) const; inline bool is_vec() const; inline SpSubview row(const uword row_num); inline const SpSubview row(const uword row_num) const; inline SpSubview col(const uword col_num); inline const SpSubview col(const uword col_num) const; inline SpSubview rows(const uword in_row1, const uword in_row2); inline const SpSubview rows(const uword in_row1, const uword in_row2) const; inline SpSubview cols(const uword in_col1, const uword in_col2); inline const SpSubview cols(const uword in_col1, const uword in_col2) const; inline SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); inline const SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; inline SpSubview submat(const span& row_span, const span& col_span); inline const SpSubview submat(const span& row_span, const span& col_span) const; inline SpSubview operator()(const uword row_num, const span& col_span); inline const SpSubview operator()(const uword row_num, const span& col_span) const; inline SpSubview operator()(const span& row_span, const uword col_num); inline const SpSubview operator()(const span& row_span, const uword col_num) const; inline SpSubview operator()(const span& row_span, const span& col_span); inline const SpSubview operator()(const span& row_span, const span& col_span) const; inline void swap_rows(const uword in_row1, const uword in_row2); inline void swap_cols(const uword in_col1, const uword in_col2); // Forward declarations. class iterator_base; class const_iterator; class iterator; class const_row_iterator; class row_iterator; // Similar to SpMat iterators but automatically iterates past and ignores values not in the subview. class iterator_base { public: inline iterator_base(const SpSubview& in_M); inline iterator_base(const SpSubview& in_M, const uword col, const uword pos, const uword skip_pos); inline eT operator*() const; // Don't hold location internally; call "dummy" methods to get that information. arma_inline uword row() const { return M.m.row_indices[internal_pos + skip_pos] - M.aux_row1; } arma_inline uword col() const { return internal_col; } arma_inline uword pos() const { return internal_pos; } arma_aligned const SpSubview& M; arma_aligned uword internal_col; arma_aligned uword internal_pos; arma_aligned uword skip_pos; // not used in row_iterator or const_row_iterator // So that we satisfy the STL iterator types. typedef std::bidirectional_iterator_tag iterator_category; typedef eT value_type; typedef uword difference_type; // not certain on this one typedef const eT* pointer; typedef const eT& reference; }; class const_iterator : public iterator_base { public: inline const_iterator(const SpSubview& in_M, uword initial_pos = 0); inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col); inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col, uword in_pos, uword skip_pos); inline const_iterator(const const_iterator& other); inline const_iterator& operator++(); inline const_iterator operator++(int); inline const_iterator& operator--(); inline const_iterator operator--(int); inline bool operator!=(const const_iterator& rhs) const; inline bool operator==(const const_iterator& rhs) const; inline bool operator!=(const typename SpMat::const_iterator& rhs) const; inline bool operator==(const typename SpMat::const_iterator& rhs) const; inline bool operator!=(const const_row_iterator& rhs) const; inline bool operator==(const const_row_iterator& rhs) const; inline bool operator!=(const typename SpMat::const_row_iterator& rhs) const; inline bool operator==(const typename SpMat::const_row_iterator& rhs) const; }; class iterator : public const_iterator { public: inline iterator(SpSubview& in_M, const uword initial_pos = 0) : const_iterator(in_M, initial_pos) { } inline iterator(SpSubview& in_M, const uword in_row, const uword in_col) : const_iterator(in_M, in_row, in_col) { } inline iterator(SpSubview& in_M, const uword in_row, const uword in_col, const uword in_pos, const uword in_skip_pos) : const_iterator(in_M, in_row, in_col, in_pos, in_skip_pos) { } inline iterator(const iterator& other) : const_iterator(other) { } inline SpValProxy > operator*(); // overloads needed for return type correctness inline iterator& operator++(); inline iterator operator++(int); inline iterator& operator--(); inline iterator operator--(int); // This has a different value_type than iterator_base. typedef SpValProxy > value_type; typedef const SpValProxy >* pointer; typedef const SpValProxy >& reference; }; class const_row_iterator : public iterator_base { public: inline const_row_iterator(const SpSubview& in_M, uword initial_pos = 0); inline const_row_iterator(const SpSubview& in_M, uword in_row, uword in_col); inline const_row_iterator(const const_row_iterator& other); inline const_row_iterator& operator++(); inline const_row_iterator operator++(int); inline const_row_iterator& operator--(); inline const_row_iterator operator--(int); uword internal_row; // Hold row internally because we use internal_pos differently. uword actual_pos; // Actual position in subview's parent matrix. arma_inline eT operator*() const { return iterator_base::M.m.values[actual_pos]; } arma_inline uword row() const { return internal_row; } inline bool operator!=(const const_iterator& rhs) const; inline bool operator==(const const_iterator& rhs) const; inline bool operator!=(const typename SpMat::const_iterator& rhs) const; inline bool operator==(const typename SpMat::const_iterator& rhs) const; inline bool operator!=(const const_row_iterator& rhs) const; inline bool operator==(const const_row_iterator& rhs) const; inline bool operator!=(const typename SpMat::const_row_iterator& rhs) const; inline bool operator==(const typename SpMat::const_row_iterator& rhs) const; }; class row_iterator : public const_row_iterator { public: inline row_iterator(SpSubview& in_M, uword initial_pos = 0) : const_row_iterator(in_M, initial_pos) { } inline row_iterator(SpSubview& in_M, uword in_row, uword in_col) : const_row_iterator(in_M, in_row, in_col) { } inline row_iterator(const row_iterator& other) : const_row_iterator(other) { } inline SpValProxy > operator*(); // overloads needed for return type correctness inline row_iterator& operator++(); inline row_iterator operator++(int); inline row_iterator& operator--(); inline row_iterator operator--(int); // This has a different value_type than iterator_base. typedef SpValProxy > value_type; typedef const SpValProxy >* pointer; typedef const SpValProxy >& reference; }; inline iterator begin(); inline const_iterator begin() const; inline iterator begin_col(const uword col_num); inline const_iterator begin_col(const uword col_num) const; inline row_iterator begin_row(const uword row_num = 0); inline const_row_iterator begin_row(const uword row_num = 0) const; inline iterator end(); inline const_iterator end() const; inline row_iterator end_row(); inline const_row_iterator end_row() const; inline row_iterator end_row(const uword row_num = 0); inline const_row_iterator end_row(const uword row_num = 0) const; private: friend class SpMat; SpSubview(); // For use by SpValProxy. We just update n_nonzero and pass the call on to the matrix. inline arma_hot arma_warn_unused eT& add_element(const uword in_row, const uword in_col, const eT in_val = 0.0); inline arma_hot void delete_element(const uword in_row, const uword in_col); }; /* template class SpSubview_col : public SpSubview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline void operator= (const SpSubview& x); inline void operator= (const SpSubview_col& x); template inline void operator= (const Base& x); inline SpSubview_col rows(const uword in_row1, const uword in_row2); inline const SpSubview_col rows(const uword in_row1, const uword in_row2) const; inline SpSubview_col subvec(const uword in_row1, const uword in_row2); inline const SpSubview_col subvec(const uword in_row1, const uword in_row2) const; protected: inline SpSubview_col(const Mat& in_m, const uword in_col); inline SpSubview_col( Mat& in_m, const uword in_col); inline SpSubview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); inline SpSubview_col( Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); private: friend class Mat; friend class Col; friend class SpSubview; SpSubview_col(); }; template class SpSubview_row : public SpSubview { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; inline void operator= (const SpSubview& x); inline void operator= (const SpSubview_row& x); template inline void operator= (const Base& x); inline SpSubview_row cols(const uword in_col1, const uword in_col2); inline const SpSubview_row cols(const uword in_col1, const uword in_col2) const; inline SpSubview_row subvec(const uword in_col1, const uword in_col2); inline const SpSubview_row subvec(const uword in_col1, const uword in_col2) const; protected: inline SpSubview_row(const Mat& in_m, const uword in_row); inline SpSubview_row( Mat& in_m, const uword in_row); inline SpSubview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); inline SpSubview_row( Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); private: friend class Mat; friend class Row; friend class SpSubview; SpSubview_row(); }; */ //! @} armadillo-6.500.5/include/armadillo_bits/cond_rel_bones.hpp0000666000000000000000000000165112620272703022435 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup cond_rel //! @{ // // for preventing pedantic compiler warnings template class cond_rel { public: template arma_inline static bool lt(const eT A, const eT B); template arma_inline static bool gt(const eT A, const eT B); template arma_inline static bool leq(const eT A, const eT B); template arma_inline static bool geq(const eT A, const eT B); template arma_inline static eT make_neg(const eT val); }; //! @} armadillo-6.500.5/include/armadillo_bits/unwrap_cube.hpp0000666000000000000000000000326712620272703022001 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup unwrap_cube //! @{ template class unwrap_cube { public: typedef typename T1::elem_type eT; inline unwrap_cube(const T1& A) : M(A) { arma_extra_debug_sigprint(); } const Cube M; }; template class unwrap_cube< Cube > { public: inline unwrap_cube(const Cube& A) : M(A) { arma_extra_debug_sigprint(); } const Cube& M; }; // // // template class unwrap_cube_check { public: typedef typename T1::elem_type eT; inline unwrap_cube_check(const T1& A, const Cube&) : M(A) { arma_extra_debug_sigprint(); arma_type_check(( is_arma_cube_type::value == false )); } const Cube M; }; template class unwrap_cube_check< Cube > { public: inline unwrap_cube_check(const Cube& A, const Cube& B) : M_local( (&A == &B) ? new Cube(A) : 0 ) , M ( (&A == &B) ? (*M_local) : A ) { arma_extra_debug_sigprint(); } inline ~unwrap_cube_check() { arma_extra_debug_sigprint(); if(M_local) { delete M_local; } } // the order below is important const Cube* M_local; const Cube& M; }; //! @} armadillo-6.500.5/include/armadillo_bits/field_bones.hpp0000666000000000000000000003637112633721645021752 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ian Cullinan //! \addtogroup field //! @{ struct field_prealloc_n_elem { static const uword val = 16; }; //! A lightweight 1D/2D/3D container for arbitrary objects //! (the objects must have a copy constructor) template class field { public: typedef oT object_type; const uword n_rows; //!< number of rows (read-only) const uword n_cols; //!< number of columns (read-only) const uword n_slices; //!< number of slices (read-only) const uword n_elem; //!< number of elements (read-only) private: arma_aligned oT** mem; //!< pointers to stored objects arma_aligned oT* mem_local[ field_prealloc_n_elem::val ]; //!< local storage, for small fields public: inline ~field(); inline field(); inline field(const field& x); inline const field& operator=(const field& x); inline field(const subview_field& x); inline const field& operator=(const subview_field& x); inline explicit field(const uword n_elem_in); inline explicit field(const uword n_rows_in, const uword n_cols_in); inline explicit field(const uword n_rows_in, const uword n_cols_in, const uword n_slices_in); inline explicit field(const SizeMat& s); inline explicit field(const SizeCube& s); inline void set_size(const uword n_obj_in); inline void set_size(const uword n_rows_in, const uword n_cols_in); inline void set_size(const uword n_rows_in, const uword n_cols_in, const uword n_slices_in); inline void set_size(const SizeMat& s); inline void set_size(const SizeCube& s); #if defined(ARMA_USE_CXX11) inline field(const std::initializer_list& list); inline const field& operator=(const std::initializer_list& list); inline field(const std::initializer_list< std::initializer_list >& list); inline const field& operator=(const std::initializer_list< std::initializer_list >& list); inline field(field&& X); inline const field& operator=(field&& X); #endif template inline void copy_size(const field& x); arma_inline oT& operator[](const uword i); arma_inline const oT& operator[](const uword i) const; arma_inline oT& at(const uword i); arma_inline const oT& at(const uword i) const; arma_inline oT& operator()(const uword i); arma_inline const oT& operator()(const uword i) const; arma_inline oT& at(const uword row, const uword col); arma_inline const oT& at(const uword row, const uword col) const; arma_inline oT& at(const uword row, const uword col, const uword slice); arma_inline const oT& at(const uword row, const uword col, const uword slice) const; arma_inline oT& operator()(const uword row, const uword col); arma_inline const oT& operator()(const uword row, const uword col) const; arma_inline oT& operator()(const uword row, const uword col, const uword slice); arma_inline const oT& operator()(const uword row, const uword col, const uword slice) const; inline field_injector operator<<(const oT& val); inline field_injector operator<<(const injector_end_of_row<>& x); inline subview_field row(const uword row_num); inline const subview_field row(const uword row_num) const; inline subview_field col(const uword col_num); inline const subview_field col(const uword col_num) const; inline subview_field slice(const uword slice_num); inline const subview_field slice(const uword slice_num) const; inline subview_field rows(const uword in_row1, const uword in_row2); inline const subview_field rows(const uword in_row1, const uword in_row2) const; inline subview_field cols(const uword in_col1, const uword in_col2); inline const subview_field cols(const uword in_col1, const uword in_col2) const; inline subview_field slices(const uword in_slice1, const uword in_slice2); inline const subview_field slices(const uword in_slice1, const uword in_slice2) const; inline subview_field subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); inline const subview_field subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; inline subview_field subfield(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2); inline const subview_field subfield(const uword in_row1, const uword in_col1, const uword in_slice1, const uword in_row2, const uword in_col2, const uword in_slice2) const; inline subview_field subfield(const uword in_row1, const uword in_col1, const SizeMat& s); inline const subview_field subfield(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline subview_field subfield(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s); inline const subview_field subfield(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const; inline subview_field subfield(const span& row_span, const span& col_span); inline const subview_field subfield(const span& row_span, const span& col_span) const; inline subview_field subfield(const span& row_span, const span& col_span, const span& slice_span); inline const subview_field subfield(const span& row_span, const span& col_span, const span& slice_span) const; inline subview_field operator()(const span& row_span, const span& col_span); inline const subview_field operator()(const span& row_span, const span& col_span) const; inline subview_field operator()(const span& row_span, const span& col_span, const span& slice_span); inline const subview_field operator()(const span& row_span, const span& col_span, const span& slice_span) const; inline subview_field operator()(const uword in_row1, const uword in_col1, const SizeMat& s); inline const subview_field operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const; inline subview_field operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s); inline const subview_field operator()(const uword in_row1, const uword in_col1, const uword in_slice1, const SizeCube& s) const; inline void print( const std::string extra_text = "") const; inline void print(std::ostream& user_stream, const std::string extra_text = "") const; #if defined(ARMA_USE_CXX11) inline const field& for_each(const std::function< void( oT&) >& F); inline const field& for_each(const std::function< void(const oT&) >& F) const; #else template inline const field& for_each(functor F); template inline const field& for_each(functor F) const; #endif inline const field& fill(const oT& x); inline void reset(); inline void reset_objects(); arma_inline bool is_empty() const; arma_inline arma_warn_unused bool in_range(const uword i) const; arma_inline arma_warn_unused bool in_range(const span& x) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const uword in_col) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const SizeMat& s) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice) const; arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span, const span& slice_span) const; arma_inline arma_warn_unused bool in_range(const uword in_row, const uword in_col, const uword in_slice, const SizeCube& s) const; inline bool save(const std::string name, const file_type type = arma_binary, const bool print_status = true) const; inline bool save( std::ostream& os, const file_type type = arma_binary, const bool print_status = true) const; inline bool load(const std::string name, const file_type type = auto_detect, const bool print_status = true); inline bool load( std::istream& is, const file_type type = auto_detect, const bool print_status = true); inline bool quiet_save(const std::string name, const file_type type = arma_binary) const; inline bool quiet_save( std::ostream& os, const file_type type = arma_binary) const; inline bool quiet_load(const std::string name, const file_type type = auto_detect); inline bool quiet_load( std::istream& is, const file_type type = auto_detect); // for container-like functionality typedef oT value_type; typedef uword size_type; class iterator { public: inline iterator(field& in_M, const bool at_end = false); inline oT& operator* (); inline iterator& operator++(); inline void operator++(int); inline iterator& operator--(); inline void operator--(int); inline bool operator!=(const iterator& X) const; inline bool operator==(const iterator& X) const; arma_aligned field& M; arma_aligned uword i; }; class const_iterator { public: const_iterator(const field& in_M, const bool at_end = false); const_iterator(const iterator& X); inline const oT& operator*() const; inline const_iterator& operator++(); inline void operator++(int); inline const_iterator& operator--(); inline void operator--(int); inline bool operator!=(const const_iterator& X) const; inline bool operator==(const const_iterator& X) const; arma_aligned const field& M; arma_aligned uword i; }; inline iterator begin(); inline const_iterator begin() const; inline const_iterator cbegin() const; inline iterator end(); inline const_iterator end() const; inline const_iterator cend() const; inline void clear(); inline bool empty() const; inline uword size() const; private: inline void init(const field& x); inline void init(const uword n_rows_in, const uword n_cols_in); inline void init(const uword n_rows_in, const uword n_cols_in, const uword n_slices_in); inline void delete_objects(); inline void create_objects(); friend class field_aux; friend class subview_field; public: #ifdef ARMA_EXTRA_FIELD_PROTO #include ARMA_INCFILE_WRAP(ARMA_EXTRA_FIELD_PROTO) #endif }; class field_aux { public: template inline static void reset_objects(field< oT >& x); template inline static void reset_objects(field< Mat >& x); template inline static void reset_objects(field< Col >& x); template inline static void reset_objects(field< Row >& x); template inline static void reset_objects(field< Cube >& x); inline static void reset_objects(field< std::string >& x); template inline static bool save(const field< oT >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< oT >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< oT >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< oT >& x, std::istream& is, const file_type type, std::string& err_msg); template inline static bool save(const field< Mat >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< Mat >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< Mat >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< Mat >& x, std::istream& is, const file_type type, std::string& err_msg); template inline static bool save(const field< Col >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< Col >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< Col >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< Col >& x, std::istream& is, const file_type type, std::string& err_msg); template inline static bool save(const field< Row >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< Row >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< Row >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< Row >& x, std::istream& is, const file_type type, std::string& err_msg); template inline static bool save(const field< Cube >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool save(const field< Cube >& x, std::ostream& os, const file_type type, std::string& err_msg); template inline static bool load( field< Cube >& x, const std::string& name, const file_type type, std::string& err_msg); template inline static bool load( field< Cube >& x, std::istream& is, const file_type type, std::string& err_msg); inline static bool save(const field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg); inline static bool save(const field< std::string >& x, std::ostream& os, const file_type type, std::string& err_msg); inline static bool load( field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg); inline static bool load( field< std::string >& x, std::istream& is, const file_type type, std::string& err_msg); }; //! @} armadillo-6.500.5/include/armadillo_bits/subview_cube_each_meat.hpp0000666000000000000000000005001412634445270024135 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_cube_each //! @{ // // // subview_cube_each_common template inline subview_cube_each_common::subview_cube_each_common(const Cube& in_p) : P(in_p) { arma_extra_debug_sigprint(); } template inline void subview_cube_each_common::check_size(const Mat& A) const { if(arma_config::debug == true) { if( (A.n_rows != P.n_rows) || (A.n_cols != P.n_cols) ) { arma_stop( incompat_size_string(A) ); } } } template arma_cold inline const std::string subview_cube_each_common::incompat_size_string(const Mat& A) const { std::stringstream tmp; tmp << "each_slice(): incompatible size; expected " << P.n_rows << 'x' << P.n_cols << ", got " << A.n_rows << 'x' << A.n_cols; return tmp.str(); } // // // subview_cube_each1 template inline subview_cube_each1::~subview_cube_each1() { arma_extra_debug_sigprint(); } template inline subview_cube_each1::subview_cube_each1(const Cube& in_p) : subview_cube_each_common::subview_cube_each_common(in_p) { arma_extra_debug_sigprint(); } template template inline void subview_cube_each1::operator= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const eT* A_mem = A.memptr(); for(uword i=0; i < p_n_slices; ++i) { arrayops::copy( p.slice_memptr(i), A_mem, p_n_elem_slice ); } } template template inline void subview_cube_each1::operator+= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const eT* A_mem = A.memptr(); for(uword i=0; i < p_n_slices; ++i) { arrayops::inplace_plus( p.slice_memptr(i), A_mem, p_n_elem_slice ); } } template template inline void subview_cube_each1::operator-= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const eT* A_mem = A.memptr(); for(uword i=0; i < p_n_slices; ++i) { arrayops::inplace_minus( p.slice_memptr(i), A_mem, p_n_elem_slice ); } } template template inline void subview_cube_each1::operator%= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const eT* A_mem = A.memptr(); for(uword i=0; i < p_n_slices; ++i) { arrayops::inplace_mul( p.slice_memptr(i), A_mem, p_n_elem_slice ); } } template template inline void subview_cube_each1::operator/= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const eT* A_mem = A.memptr(); for(uword i=0; i < p_n_slices; ++i) { arrayops::inplace_div( p.slice_memptr(i), A_mem, p_n_elem_slice ); } } // // // subview_cube_each2 template inline subview_cube_each2::~subview_cube_each2() { arma_extra_debug_sigprint(); } template inline subview_cube_each2::subview_cube_each2(const Cube& in_p, const Base& in_indices) : subview_cube_each_common::subview_cube_each_common(in_p) , base_indices(in_indices) { arma_extra_debug_sigprint(); } template inline void subview_cube_each2::check_indices(const Mat& indices) const { arma_debug_check( ((indices.is_vec() == false) && (indices.is_empty() == false)), "each_slice(): list of indices must be a vector" ); } template template inline void subview_cube_each2::operator= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const unwrap U( base_indices.get_ref() ); check_indices(U.M); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); arrayops::copy(p.slice_memptr(slice), A_mem, p_n_elem_slice); } } template template inline void subview_cube_each2::operator+= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const unwrap U( base_indices.get_ref() ); check_indices(U.M); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); arrayops::inplace_plus(p.slice_memptr(slice), A_mem, p_n_elem_slice); } } template template inline void subview_cube_each2::operator-= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const unwrap U( base_indices.get_ref() ); check_indices(U.M); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); arrayops::inplace_minus(p.slice_memptr(slice), A_mem, p_n_elem_slice); } } template template inline void subview_cube_each2::operator%= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const unwrap U( base_indices.get_ref() ); check_indices(U.M); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); arrayops::inplace_mul(p.slice_memptr(slice), A_mem, p_n_elem_slice); } } template template inline void subview_cube_each2::operator/= (const Base& in) { arma_extra_debug_sigprint(); Cube& p = access::rw(subview_cube_each_common::P); const unwrap tmp( in.get_ref() ); const Mat& A = tmp.M; subview_cube_each_common::check_size(A); const unwrap U( base_indices.get_ref() ); check_indices(U.M); const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); arrayops::inplace_div(p.slice_memptr(slice), A_mem, p_n_elem_slice); } } // // // subview_cube_each1_aux template inline Cube subview_cube_each1_aux::operator_plus ( const subview_cube_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); const Cube& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword p_n_slices = p.n_slices; Cube out(p_n_rows, p_n_cols, p_n_slices); const unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; X.check_size(A); for(uword i=0; i < p_n_slices; ++i) { Mat out_slice( out.slice_memptr(i), p_n_rows, p_n_cols, false, true); const Mat p_slice(const_cast(p.slice_memptr(i)), p_n_rows, p_n_cols, false, true); out_slice = p_slice + A; } return out; } template inline Cube subview_cube_each1_aux::operator_minus ( const subview_cube_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); const Cube& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword p_n_slices = p.n_slices; Cube out(p_n_rows, p_n_cols, p_n_slices); const unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; X.check_size(A); for(uword i=0; i < p_n_slices; ++i) { Mat out_slice( out.slice_memptr(i), p_n_rows, p_n_cols, false, true); const Mat p_slice(const_cast(p.slice_memptr(i)), p_n_rows, p_n_cols, false, true); out_slice = p_slice - A; } return out; } template inline Cube subview_cube_each1_aux::operator_minus ( const Base& X, const subview_cube_each1& Y ) { arma_extra_debug_sigprint(); const Cube& p = Y.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword p_n_slices = p.n_slices; Cube out(p_n_rows, p_n_cols, p_n_slices); const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; Y.check_size(A); for(uword i=0; i < p_n_slices; ++i) { Mat out_slice( out.slice_memptr(i), p_n_rows, p_n_cols, false, true); const Mat p_slice(const_cast(p.slice_memptr(i)), p_n_rows, p_n_cols, false, true); out_slice = A - p_slice; } return out; } template inline Cube subview_cube_each1_aux::operator_schur ( const subview_cube_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); const Cube& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword p_n_slices = p.n_slices; Cube out(p_n_rows, p_n_cols, p_n_slices); const unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; X.check_size(A); for(uword i=0; i < p_n_slices; ++i) { Mat out_slice( out.slice_memptr(i), p_n_rows, p_n_cols, false, true); const Mat p_slice(const_cast(p.slice_memptr(i)), p_n_rows, p_n_cols, false, true); out_slice = p_slice % A; } return out; } template inline Cube subview_cube_each1_aux::operator_div ( const subview_cube_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); const Cube& p = X.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword p_n_slices = p.n_slices; Cube out(p_n_rows, p_n_cols, p_n_slices); const unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; X.check_size(A); for(uword i=0; i < p_n_slices; ++i) { Mat out_slice( out.slice_memptr(i), p_n_rows, p_n_cols, false, true); const Mat p_slice(const_cast(p.slice_memptr(i)), p_n_rows, p_n_cols, false, true); out_slice = p_slice / A; } return out; } template inline Cube subview_cube_each1_aux::operator_div ( const Base& X, const subview_cube_each1& Y ) { arma_extra_debug_sigprint(); const Cube& p = Y.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword p_n_slices = p.n_slices; Cube out(p_n_rows, p_n_cols, p_n_slices); const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; Y.check_size(A); for(uword i=0; i < p_n_slices; ++i) { Mat out_slice( out.slice_memptr(i), p_n_rows, p_n_cols, false, true); const Mat p_slice(const_cast(p.slice_memptr(i)), p_n_rows, p_n_cols, false, true); out_slice = A / p_slice; } return out; } // // // subview_cube_each2_aux template inline Cube subview_cube_each2_aux::operator_plus ( const subview_cube_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); const Cube& p = X.P; const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; Cube out = p; const unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; const unwrap U(X.base_indices.get_ref()); X.check_size(A); X.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); arrayops::inplace_plus(out.slice_memptr(slice), A_mem, p_n_elem_slice); } return out; } template inline Cube subview_cube_each2_aux::operator_minus ( const subview_cube_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); const Cube& p = X.P; const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; Cube out = p; const unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; const unwrap U(X.base_indices.get_ref()); X.check_size(A); X.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); arrayops::inplace_minus(out.slice_memptr(slice), A_mem, p_n_elem_slice); } return out; } template inline Cube subview_cube_each2_aux::operator_minus ( const Base& X, const subview_cube_each2& Y ) { arma_extra_debug_sigprint(); const Cube& p = Y.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword p_n_slices = p.n_slices; Cube out = p; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; const unwrap U(Y.base_indices.get_ref()); Y.check_size(A); Y.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); Mat out_slice( out.slice_memptr(slice), p_n_rows, p_n_cols, false, true); const Mat p_slice(const_cast(p.slice_memptr(slice)), p_n_rows, p_n_cols, false, true); out_slice = A - p_slice; } return out; } template inline Cube subview_cube_each2_aux::operator_schur ( const subview_cube_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); const Cube& p = X.P; const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; Cube out = p; const unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; const unwrap U(X.base_indices.get_ref()); X.check_size(A); X.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); arrayops::inplace_mul(out.slice_memptr(slice), A_mem, p_n_elem_slice); } return out; } template inline Cube subview_cube_each2_aux::operator_div ( const subview_cube_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); const Cube& p = X.P; const uword p_n_slices = p.n_slices; const uword p_n_elem_slice = p.n_elem_slice; Cube out = p; const unwrap tmp(Y.get_ref()); const Mat& A = tmp.M; const unwrap U(X.base_indices.get_ref()); X.check_size(A); X.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; const eT* A_mem = A.memptr(); for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); arrayops::inplace_div(out.slice_memptr(slice), A_mem, p_n_elem_slice); } return out; } template inline Cube subview_cube_each2_aux::operator_div ( const Base& X, const subview_cube_each2& Y ) { arma_extra_debug_sigprint(); const Cube& p = Y.P; const uword p_n_rows = p.n_rows; const uword p_n_cols = p.n_cols; const uword p_n_slices = p.n_slices; Cube out = p; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; const unwrap U(Y.base_indices.get_ref()); Y.check_size(A); Y.check_indices(U.M); const uword* indices_mem = U.M.memptr(); const uword N = U.M.n_elem; for(uword i=0; i < N; ++i) { const uword slice = indices_mem[i]; arma_debug_check( (slice >= p_n_slices), "each_slice(): index out of bounds" ); Mat out_slice( out.slice_memptr(slice), p_n_rows, p_n_cols, false, true); const Mat p_slice(const_cast(p.slice_memptr(slice)), p_n_rows, p_n_cols, false, true); out_slice = A / p_slice; } return out; } //! @} armadillo-6.500.5/include/armadillo_bits/eOpCube_bones.hpp0000666000000000000000000000470212620272703022172 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eOpCube //! @{ template class eOpCube : public BaseCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool prefer_at_accessor = ProxyCube::prefer_at_accessor; static const bool has_subview = ProxyCube::has_subview; arma_aligned const ProxyCube P; arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_c; //!< storage of auxiliary data, uword format inline ~eOpCube(); inline explicit eOpCube(const BaseCube& in_m); inline eOpCube(const BaseCube& in_m, const elem_type in_aux); inline eOpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline eOpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline eOpCube(const BaseCube& in_m, const elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); arma_inline uword get_n_rows() const; arma_inline uword get_n_cols() const; arma_inline uword get_n_elem_slice() const; arma_inline uword get_n_slices() const; arma_inline uword get_n_elem() const; arma_inline elem_type operator[] (const uword i) const; arma_inline elem_type at (const uword row, const uword col, const uword slice) const; arma_inline elem_type at_alt (const uword i) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/arma_str.hpp0000666000000000000000000002430612650111756021277 0ustar rootroot// Copyright (C) 2008-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arma_str //! @{ namespace arma_str { #if ( defined(ARMA_USE_CXX11) || defined(ARMA_HAVE_SNPRINTF) ) #define arma_snprintf std::snprintf #else // better-than-nothing emulation of C99 snprintf(), // with correct return value and null-terminated output string. // note that _snprintf() provided by MS is not a good substitute for snprintf() inline int arma_snprintf(char* out, size_t size, const char* fmt, ...) { size_t i; for(i=0; i 0) out[size-1] = char(0); return int(i); } #endif class format { public: format(const char* in_fmt) : A(in_fmt) { } format(const std::string& in_fmt) : A(in_fmt) { } const std::string A; private: format(); }; template class basic_format { public: basic_format(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { } const T1& A; const T2& B; private: basic_format(); }; template inline basic_format< format, T2 > operator% (const format& X, const T2& arg) { return basic_format< format, T2 >(X, arg); } template inline basic_format< basic_format, T3 > operator% (const basic_format& X, const T3& arg) { return basic_format< basic_format, T3 >(X, arg); } template inline std::string str(const basic_format< format, T2>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.c_str(), X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< format, T2>, T3>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.c_str(), X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< basic_format< format, T2>, T3>, T4>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.A.c_str(), X.A.A.B, X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< basic_format< basic_format< format, T2>, T3>, T4>, T5>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.A.A.c_str(), X.A.A.A.B, X.A.A.B, X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< basic_format< basic_format< basic_format< format, T2>, T3>, T4>, T5>, T6>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.A.A.A.c_str(), X.A.A.A.A.B, X.A.A.A.B, X.A.A.B, X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template inline std::string str(const basic_format< basic_format< basic_format< basic_format< basic_format< basic_format< format, T2>, T3>, T4>, T5>, T6>, T7>& X) { char local_buffer[1024]; char* buffer = local_buffer; int buffer_size = 1024; int required_size = buffer_size; bool using_local_buffer = true; std::string out; do { if(using_local_buffer == false) { buffer = new char[buffer_size]; } required_size = arma_snprintf(buffer, size_t(buffer_size), X.A.A.A.A.A.A.A.c_str(), X.A.A.A.A.A.B, X.A.A.A.A.B, X.A.A.A.B, X.A.A.B, X.A.B, X.B); if(required_size < buffer_size) { if(required_size > 0) { out = buffer; } } else { buffer_size *= 2; } if(using_local_buffer) { using_local_buffer = false; } else { delete[] buffer; } } while( (required_size >= buffer_size) ); return out; } template struct format_metaprog { static const uword depth = 0; inline static const std::string& get_fmt(const T1& X) { return X.A; } }; //template<> template struct format_metaprog< basic_format > { static const uword depth = 1 + format_metaprog::depth; inline static const std::string& get_fmt(const T1& X) { return format_metaprog::get_fmt(X.A); } }; template inline std::string str(const basic_format& X) { return format_metaprog< basic_format >::get_fmt(X.A); } template inline std::ostream& operator<< (std::ostream& o, const basic_format& X) { o << str(X); return o; } template struct string_only { }; template<> struct string_only { typedef std::string result; }; template struct char_only { }; template<> struct char_only { typedef char result; }; template struct basic_format_only { }; template struct basic_format_only< basic_format > { typedef basic_format result; }; template inline static const T1& str_wrapper(const T1& x, const typename string_only::result* junk = 0) { arma_ignore(junk); return x; } template inline static const T1* str_wrapper(const T1* x, const typename char_only::result* junk = 0) { arma_ignore(junk); return x; } template inline static std::string str_wrapper(const T1& x, const typename basic_format_only::result* junk = 0) { arma_ignore(junk); return str(x); } } //! @} armadillo-6.500.5/include/armadillo_bits/eGlue_meat.hpp0000666000000000000000000000655112620272703021535 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eGlue //! @{ template arma_inline eGlue::~eGlue() { arma_extra_debug_sigprint(); } template arma_inline eGlue::eGlue(const T1& in_A, const T2& in_B) : P1(in_A) , P2(in_B) { arma_extra_debug_sigprint(); // arma_debug_assert_same_size( P1, P2, eglue_type::text() ); arma_debug_assert_same_size ( P1.get_n_rows(), P1.get_n_cols(), P2.get_n_rows(), P2.get_n_cols(), eglue_type::text() ); } template arma_inline uword eGlue::get_n_rows() const { return is_row ? 1 : P1.get_n_rows(); } template arma_inline uword eGlue::get_n_cols() const { return is_col ? 1 : P1.get_n_cols(); } template arma_inline uword eGlue::get_n_elem() const { return P1.get_n_elem(); } template arma_inline typename T1::elem_type eGlue::operator[] (const uword ii) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1[ii] + P2[ii]; } else if(is_same_type::yes) { return P1[ii] - P2[ii]; } else if(is_same_type::yes) { return P1[ii] / P2[ii]; } else if(is_same_type::yes) { return P1[ii] * P2[ii]; } else return eT(0); } template arma_inline typename T1::elem_type eGlue::at(const uword row, const uword col) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1.at(row,col) + P2.at(row,col); } else if(is_same_type::yes) { return P1.at(row,col) - P2.at(row,col); } else if(is_same_type::yes) { return P1.at(row,col) / P2.at(row,col); } else if(is_same_type::yes) { return P1.at(row,col) * P2.at(row,col); } else return eT(0); } template arma_inline typename T1::elem_type eGlue::at_alt(const uword ii) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1.at_alt(ii) + P2.at_alt(ii); } else if(is_same_type::yes) { return P1.at_alt(ii) - P2.at_alt(ii); } else if(is_same_type::yes) { return P1.at_alt(ii) / P2.at_alt(ii); } else if(is_same_type::yes) { return P1.at_alt(ii) * P2.at_alt(ii); } else return eT(0); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_schur.hpp0000666000000000000000000000405212620272703021267 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_schur //! @{ template inline bool schur ( Mat& S, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; Mat U; const bool status = auxlib::schur(U, S, X.get_ref(), false); if(status == false) { S.reset(); arma_debug_warn("schur(): decomposition failed"); } return status; } template inline Mat schur ( const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; Mat S; Mat U; const bool status = auxlib::schur(U, S, X.get_ref(), false); if(status == false) { S.reset(); arma_bad("schur(): decomposition failed"); } return S; } template inline bool schur ( Mat& U, Mat& S, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( void_ptr(&U) == void_ptr(&S), "schur(): 'U' is an alias of 'S'" ); const bool status = auxlib::schur(U, S, X.get_ref(), true); if(status == false) { U.reset(); S.reset(); arma_debug_warn("schur(): decomposition failed"); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/spglue_times_meat.hpp0000666000000000000000000002023412620272703023166 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spglue_times //! @{ template inline void spglue_times::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // unconditionally unwrapping, as the column iterator in SpSubview is slow const unwrap_spmat tmp1(X.A); const unwrap_spmat tmp2(X.B); const SpProxy::stored_type> pa(tmp1.M); const SpProxy::stored_type> pb(tmp2.M); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_times::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_times::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } } template arma_hot inline void spglue_times::apply_noalias(SpMat& c, const SpProxy& pa, const SpProxy& pb) { arma_extra_debug_sigprint(); const uword x_n_rows = pa.get_n_rows(); const uword x_n_cols = pa.get_n_cols(); const uword y_n_rows = pb.get_n_rows(); const uword y_n_cols = pb.get_n_cols(); arma_debug_assert_mul_size(x_n_rows, x_n_cols, y_n_rows, y_n_cols, "matrix multiplication"); // First we must determine the structure of the new matrix (column pointers). // This follows the algorithm described in 'Sparse Matrix Multiplication // Package (SMMP)' (R.E. Bank and C.C. Douglas, 2001). Their description of // "SYMBMM" does not include anything about memory allocation. In addition it // does not consider that there may be elements which space may be allocated // for but which evaluate to zero anyway. So we have to modify the algorithm // to work that way. For the "SYMBMM" implementation we will not determine // the row indices but instead just the column pointers. //SpMat c(x_n_rows, y_n_cols); // Initializes col_ptrs to 0. c.zeros(x_n_rows, y_n_cols); //if( (pa.get_n_elem() == 0) || (pb.get_n_elem() == 0) ) if( (pa.get_n_nonzero() == 0) || (pb.get_n_nonzero() == 0) ) { return; } // Auxiliary storage which denotes when items have been found. podarray index(x_n_rows); index.fill(x_n_rows); // Fill with invalid links. typename SpProxy::const_iterator_type y_it = pb.begin(); typename SpProxy::const_iterator_type y_end = pb.end(); // SYMBMM: calculate column pointers for resultant matrix to obtain a good // upper bound on the number of nonzero elements. uword cur_col_length = 0; uword last_ind = x_n_rows + 1; do { const uword y_it_row = y_it.row(); // Look through the column that this point (*y_it) could affect. typename SpProxy::const_iterator_type x_it = pa.begin_col(y_it_row); while(x_it.col() == y_it_row) { // A point at x(i, j) and y(j, k) implies a point at c(i, k). if(index[x_it.row()] == x_n_rows) { index[x_it.row()] = last_ind; last_ind = x_it.row(); ++cur_col_length; } ++x_it; } const uword old_col = y_it.col(); ++y_it; // See if column incremented. if(old_col != y_it.col()) { // Set column pointer (this is not a cumulative count; that is done later). access::rw(c.col_ptrs[old_col + 1]) = cur_col_length; cur_col_length = 0; // Return index markers to zero. Use last_ind for traversal. while(last_ind != x_n_rows + 1) { const uword tmp = index[last_ind]; index[last_ind] = x_n_rows; last_ind = tmp; } } } while(y_it != y_end); // Accumulate column pointers. for(uword i = 0; i < c.n_cols; ++i) { access::rw(c.col_ptrs[i + 1]) += c.col_ptrs[i]; } // Now that we know a decent bound on the number of nonzero elements, allocate // the memory and fill it. c.mem_resize(c.col_ptrs[c.n_cols]); // Now the implementation of the NUMBMM algorithm. uword cur_pos = 0; // Current position in c matrix. podarray sums(x_n_rows); // Partial sums. sums.zeros(); // setting the size of 'sorted_indices' to x_n_rows is a better-than-nothing guess; // the correct minimum size is determined later podarray sorted_indices(x_n_rows); // last_ind is already set to x_n_rows, and cur_col_length is already set to 0. // We will loop through all columns as necessary. uword cur_col = 0; while(cur_col < c.n_cols) { // Skip to next column with elements in it. while((cur_col < c.n_cols) && (c.col_ptrs[cur_col] == c.col_ptrs[cur_col + 1])) { // Update current column pointer to actual number of nonzero elements up // to this point. access::rw(c.col_ptrs[cur_col]) = cur_pos; ++cur_col; } if(cur_col == c.n_cols) { break; } // Update current column pointer. access::rw(c.col_ptrs[cur_col]) = cur_pos; // Check all elements in this column. typename SpProxy::const_iterator_type y_col_it = pb.begin_col(cur_col); while(y_col_it.col() == cur_col) { // Check all elements in the column of the other matrix corresponding to // the row of this column. typename SpProxy::const_iterator_type x_col_it = pa.begin_col(y_col_it.row()); const eT y_value = (*y_col_it); while(x_col_it.col() == y_col_it.row()) { // A point at x(i, j) and y(j, k) implies a point at c(i, k). // Add to partial sum. const eT x_value = (*x_col_it); sums[x_col_it.row()] += (x_value * y_value); // Add point if it hasn't already been marked. if(index[x_col_it.row()] == x_n_rows) { index[x_col_it.row()] = last_ind; last_ind = x_col_it.row(); } ++x_col_it; } ++y_col_it; } // Now sort the indices that were used in this column. //podarray sorted_indices(c.col_ptrs[cur_col + 1] - c.col_ptrs[cur_col]); sorted_indices.set_min_size(c.col_ptrs[cur_col + 1] - c.col_ptrs[cur_col]); // .set_min_size() can only enlarge the array to the specified size, // hence if we request a smaller size than already allocated, // no new memory allocation is done uword cur_index = 0; while(last_ind != x_n_rows + 1) { const uword tmp = last_ind; // Check that it wasn't a "fake" nonzero element. if(sums[tmp] != eT(0)) { // Assign to next open position. sorted_indices[cur_index] = tmp; ++cur_index; } last_ind = index[tmp]; index[tmp] = x_n_rows; } // Now sort the indices. if (cur_index != 0) { op_sort::direct_sort_ascending(sorted_indices.memptr(), cur_index); for(uword k = 0; k < cur_index; ++k) { const uword row = sorted_indices[k]; access::rw(c.row_indices[cur_pos]) = row; access::rw(c.values[cur_pos]) = sums[row]; sums[row] = eT(0); ++cur_pos; } } // Move to next column. ++cur_col; } // Update last column pointer and resize to actual memory size. access::rw(c.col_ptrs[c.n_cols]) = cur_pos; c.mem_resize(cur_pos); } // // // spglue_times2: scalar*(A * B) template inline void spglue_times2::apply(SpMat& out, const SpGlue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const SpProxy pa(X.A); const SpProxy pb(X.B); const bool is_alias = pa.is_alias(out) || pb.is_alias(out); if(is_alias == false) { spglue_times::apply_noalias(out, pa, pb); } else { SpMat tmp; spglue_times::apply_noalias(tmp, pa, pb); out.steal_mem(tmp); } out *= X.aux; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_cond.hpp0000666000000000000000000000237112626613771021102 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_cond //! @{ template arma_warn_unused inline typename enable_if2::value, typename T1::pod_type>::result cond(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::pod_type T; Col S; const bool status = auxlib::svd_dc(S, X); if(status == false) { arma_debug_warn("cond(): svd failed"); return T(0); } if(S.n_elem > 0) { return T( max(S) / min(S) ); } else { return T(0); } } template arma_warn_unused inline typename enable_if2::value, typename T1::pod_type>::result rcond(const Base& X) { arma_extra_debug_sigprint(); return auxlib::rcond(X.get_ref()); } //! @} armadillo-6.500.5/include/armadillo_bits/eGlueCube_meat.hpp0000666000000000000000000000733712620272703022337 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup eGlueCube //! @{ template arma_inline eGlueCube::~eGlueCube() { arma_extra_debug_sigprint(); } template arma_inline eGlueCube::eGlueCube(const T1& in_A, const T2& in_B) : P1(in_A) , P2(in_B) { arma_extra_debug_sigprint(); arma_debug_assert_same_size ( P1.get_n_rows(), P1.get_n_cols(), P1.get_n_slices(), P2.get_n_rows(), P2.get_n_cols(), P2.get_n_slices(), eglue_type::text() ); } template arma_inline uword eGlueCube::get_n_rows() const { return P1.get_n_rows(); } template arma_inline uword eGlueCube::get_n_cols() const { return P1.get_n_cols(); } template arma_inline uword eGlueCube::get_n_slices() const { return P1.get_n_slices(); } template arma_inline uword eGlueCube::get_n_elem_slice() const { return P1.get_n_elem_slice(); } template arma_inline uword eGlueCube::get_n_elem() const { return P1.get_n_elem(); } template arma_inline typename T1::elem_type eGlueCube::operator[] (const uword i) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1[i] + P2[i]; } else if(is_same_type::yes) { return P1[i] - P2[i]; } else if(is_same_type::yes) { return P1[i] / P2[i]; } else if(is_same_type::yes) { return P1[i] * P2[i]; } else return eT(0); } template arma_inline typename T1::elem_type eGlueCube::at(const uword row, const uword col, const uword slice) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1.at(row,col,slice) + P2.at(row,col,slice); } else if(is_same_type::yes) { return P1.at(row,col,slice) - P2.at(row,col,slice); } else if(is_same_type::yes) { return P1.at(row,col,slice) / P2.at(row,col,slice); } else if(is_same_type::yes) { return P1.at(row,col,slice) * P2.at(row,col,slice); } else return eT(0); } template arma_inline typename T1::elem_type eGlueCube::at_alt(const uword i) const { // the optimiser will keep only one return statement typedef typename T1::elem_type eT; if(is_same_type::yes) { return P1.at_alt(i) + P2.at_alt(i); } else if(is_same_type::yes) { return P1.at_alt(i) - P2.at_alt(i); } else if(is_same_type::yes) { return P1.at_alt(i) / P2.at_alt(i); } else if(is_same_type::yes) { return P1.at_alt(i) * P2.at_alt(i); } else return eT(0); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_eigs_gen.hpp0000666000000000000000000000610512620272703021724 0ustar rootroot// Copyright (C) 2013-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup fn_eigs_gen //! @{ //! eigenvalues of general sparse matrix X template inline Col< std::complex > eigs_gen ( const SpBase& X, const uword n_eigvals, const char* form = "lm", const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; Mat< std::complex > eigvec; Col< std::complex > eigval; const bool status = sp_auxlib::eigs_gen(eigval, eigvec, X, n_eigvals, form, tol); if(status == false) { eigval.reset(); arma_bad("eigs_gen(): decomposition failed"); } return eigval; } //! eigenvalues of general sparse matrix X template inline bool eigs_gen ( Col< std::complex >& eigval, const SpBase& X, const uword n_eigvals, const char* form = "lm", const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; Mat< std::complex > eigvec; const bool status = sp_auxlib::eigs_gen(eigval, eigvec, X, n_eigvals, form, tol); if(status == false) { eigval.reset(); arma_debug_warn("eigs_gen(): decomposition failed"); } return status; } //! eigenvalues and eigenvectors of general real sparse matrix X template inline bool eigs_gen ( Col< std::complex >& eigval, Mat< std::complex >& eigvec, const SpBase& X, const uword n_eigvals, const char* form = "lm", const typename T1::pod_type tol = 0.0, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( void_ptr(&eigval) == void_ptr(&eigvec), "eigs_gen(): parameter 'eigval' is an alias of parameter 'eigvec'" ); const bool status = sp_auxlib::eigs_gen(eigval, eigvec, X, n_eigvals, form, tol); if(status == false) { eigval.reset(); eigvec.reset(); arma_debug_warn("eigs_gen(): decomposition failed"); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_pinv.hpp0000666000000000000000000000312512620272703021117 0ustar rootroot// Copyright (C) 2009-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup fn_pinv //! @{ template inline const Op pinv ( const Base& X, const typename T1::elem_type tol = 0.0, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); const char sig = (method != NULL) ? method[0] : char(0); arma_debug_check( ((sig != 's') && (sig != 'd')), "pinv(): unknown method specified" ); return (sig == 'd') ? Op(X.get_ref(), tol, 1, 0) : Op(X.get_ref(), tol, 0, 0); } template inline bool pinv ( Mat& out, const Base& X, const typename T1::elem_type tol = 0.0, const char* method = "dc", const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); try { out = pinv(X, tol, method); } catch(std::runtime_error&) { return false; } return true; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_sprandu.hpp0000666000000000000000000000452512620272703021624 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_sprandu //! @{ //! Generate a sparse matrix with a randomly selected subset of the elements //! set to random values in the [0,1] interval (uniform distribution) template inline obj_type sprandu ( const uword n_rows, const uword n_cols, const double density, const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_SpCol::value == true) { arma_debug_check( (n_cols != 1), "sprandu(): incompatible size" ); } else if(is_SpRow::value == true) { arma_debug_check( (n_rows != 1), "sprandu(): incompatible size" ); } obj_type out; out.sprandu(n_rows, n_cols, density); return out; } template inline obj_type sprandu(const SizeMat& s, const double density, const typename arma_SpMat_SpCol_SpRow_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return sprandu(s.n_rows, s.n_cols, density); } inline sp_mat sprandu(const uword n_rows, const uword n_cols, const double density) { arma_extra_debug_sigprint(); sp_mat out; out.sprandu(n_rows, n_cols, density); return out; } inline sp_mat sprandu(const SizeMat& s, const double density) { arma_extra_debug_sigprint(); sp_mat out; out.sprandu(s.n_rows, s.n_cols, density); return out; } //! Generate a sparse matrix with the non-zero values in the same locations as in the given sparse matrix X, //! with the non-zero values set to random values in the [0,1] interval (uniform distribution) template inline SpMat sprandu(const SpBase& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; SpMat out( X.get_ref() ); arma_rng::randu::fill( access::rwp(out.values), out.n_nonzero ); return out; } //! @} armadillo-6.500.5/include/armadillo_bits/op_cov_meat.hpp0000666000000000000000000000432612620272703021757 0ustar rootroot// Copyright (C) 2009-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_cov //! @{ template inline void op_cov::direct_cov(Mat& out, const Mat& A, const uword norm_type) { arma_extra_debug_sigprint(); if(A.is_vec()) { if(A.n_rows == 1) { out = var(trans(A), norm_type); } else { out = var(A, norm_type); } } else { const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); const Row acc = sum(A); out = trans(A) * A; out -= (trans(acc) * acc)/eT(N); out /= norm_val; } } template inline void op_cov::direct_cov(Mat< std::complex >& out, const Mat< std::complex >& A, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(A.is_vec()) { if(A.n_rows == 1) { const Mat tmp_mat = var(trans(A), norm_type); out.set_size(1,1); out[0] = tmp_mat[0]; } else { const Mat tmp_mat = var(A, norm_type); out.set_size(1,1); out[0] = tmp_mat[0]; } } else { const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); const Row acc = sum(A); out = trans(A) * A; // out = strans(conj(A)) * A; out -= (trans(acc) * acc)/eT(N); // out -= (strans(conj(acc)) * acc)/eT(N); out /= norm_val; } } template inline void op_cov::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check tmp(in.m, out); const Mat& A = tmp.M; const uword norm_type = in.aux_uword_a; op_cov::direct_cov(out, A, norm_type); } //! @} armadillo-6.500.5/include/armadillo_bits/glue_kron_meat.hpp0000666000000000000000000000577712620272703022472 0ustar rootroot// Copyright (C) 2009-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup glue_kron //! @{ //! \brief //! both input matrices have the same element type template inline void glue_kron::direct_kron(Mat& out, const Mat& A, const Mat& B) { arma_extra_debug_sigprint(); const uword A_rows = A.n_rows; const uword A_cols = A.n_cols; const uword B_rows = B.n_rows; const uword B_cols = B.n_cols; out.set_size(A_rows*B_rows, A_cols*B_cols); for(uword j = 0; j < A_cols; j++) { for(uword i = 0; i < A_rows; i++) { out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A.at(i,j) * B; } } } //! \brief //! different types of input matrices //! A -> complex, B -> basic element type template inline void glue_kron::direct_kron(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat& B) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const uword A_rows = A.n_rows; const uword A_cols = A.n_cols; const uword B_rows = B.n_rows; const uword B_cols = B.n_cols; out.set_size(A_rows*B_rows, A_cols*B_cols); Mat tmp_B = conv_to< Mat >::from(B); for(uword j = 0; j < A_cols; j++) { for(uword i = 0; i < A_rows; i++) { out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A.at(i,j) * tmp_B; } } } //! \brief //! different types of input matrices //! A -> basic element type, B -> complex template inline void glue_kron::direct_kron(Mat< std::complex >& out, const Mat& A, const Mat< std::complex >& B) { arma_extra_debug_sigprint(); const uword A_rows = A.n_rows; const uword A_cols = A.n_cols; const uword B_rows = B.n_rows; const uword B_cols = B.n_cols; out.set_size(A_rows*B_rows, A_cols*B_cols); for(uword j = 0; j < A_cols; j++) { for(uword i = 0; i < A_rows; i++) { out.submat(i*B_rows, j*B_cols, (i+1)*B_rows-1, (j+1)*B_cols-1) = A.at(i,j) * B; } } } //! \brief //! apply Kronecker product for two objects with same element type template inline void glue_kron::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap A_tmp(X.A); const unwrap B_tmp(X.B); const Mat& A = A_tmp.M; const Mat& B = B_tmp.M; if( (&out != &A) && (&out != &B) ) { glue_kron::direct_kron(out, A, B); } else { Mat tmp; glue_kron::direct_kron(tmp, A, B); out.steal_mem(tmp); } } //! @} armadillo-6.500.5/include/armadillo_bits/operator_cube_times.hpp0000666000000000000000000000364412620272703023520 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup operator_cube_times //! @{ //! BaseCube * scalar template arma_inline const eOpCube operator* ( const BaseCube& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! scalar * BaseCube template arma_inline const eOpCube operator* ( const typename T1::elem_type k, const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! non-complex BaseCube * complex scalar (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_times> operator* ( const BaseCube& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_times>('j', X.get_ref(), k); } //! complex scalar * non-complex BaseCube (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_times> operator* ( const std::complex& k, const BaseCube& X ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_times>('j', X.get_ref(), k); } //! @} armadillo-6.500.5/include/armadillo_bits/include_hdf5.hpp0000666000000000000000000000172212620272703022012 0ustar rootroot// Copyright (C) 2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au #if defined(ARMA_USE_HDF5) #if !defined(ARMA_HDF5_INCLUDE_DIR) #include #else #define ARMA_STR1(x) x #define ARMA_STR2(x) ARMA_STR1(x) #define ARMA_HDF5_HEADER ARMA_STR2(ARMA_HDF5_INCLUDE_DIR)ARMA_STR2(hdf5.h) #include ARMA_INCFILE_WRAP(ARMA_HDF5_HEADER) #undef ARMA_STR1 #undef ARMA_STR2 #undef ARMA_HDF5_HEADER #endif #if defined(H5_USE_16_API_DEFAULT) || defined(H5_USE_16_API) #pragma message ("WARNING: disabling use of HDF5 due to its incompatible configuration") #undef ARMA_USE_HDF5 #endif #endif armadillo-6.500.5/include/armadillo_bits/mtSpOp_meat.hpp0000666000000000000000000000205012620272703021704 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup mtSpOp //! @{ template inline mtSpOp::mtSpOp(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline mtSpOp::mtSpOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline mtSpOp::~mtSpOp() { arma_extra_debug_sigprint(); } armadillo-6.500.5/include/armadillo_bits/arma_rng.hpp0000666000000000000000000001653512620272703021257 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arma_rng //! @{ #if defined(ARMA_RNG_ALT) #undef ARMA_USE_EXTERN_CXX11_RNG #endif #if !defined(ARMA_USE_CXX11) #undef ARMA_USE_EXTERN_CXX11_RNG #endif #if defined(ARMA_USE_EXTERN_CXX11_RNG) extern thread_local arma_rng_cxx11 arma_rng_cxx11_instance; // namespace { thread_local arma_rng_cxx11 arma_rng_cxx11_instance; } #endif class arma_rng { public: #if defined(ARMA_RNG_ALT) typedef arma_rng_alt::seed_type seed_type; #elif defined(ARMA_USE_EXTERN_CXX11_RNG) typedef arma_rng_cxx11::seed_type seed_type; #else typedef arma_rng_cxx98::seed_type seed_type; #endif #if defined(ARMA_RNG_ALT) static const int rng_method = 2; #elif defined(ARMA_USE_EXTERN_CXX11_RNG) static const int rng_method = 1; #else static const int rng_method = 0; #endif inline static void set_seed(const seed_type val); inline static void set_seed_random(); template struct randi; template struct randu; template struct randn; }; inline void arma_rng::set_seed(const arma_rng::seed_type val) { #if defined(ARMA_RNG_ALT) { arma_rng_alt::set_seed(val); } #elif defined(ARMA_USE_EXTERN_CXX11_RNG) { arma_rng_cxx11_instance.set_seed(val); } #else { arma_rng_cxx98::set_seed(val); } #endif } inline void arma_rng::set_seed_random() { seed_type seed1 = seed_type(0); seed_type seed2 = seed_type(0); seed_type seed3 = seed_type(0); seed_type seed4 = seed_type(0); seed_type seed5 = seed_type(0); bool have_seed = false; #if defined(ARMA_USE_CXX11) { try { std::random_device rd; if(rd.entropy() > double(0)) { seed1 = static_cast( rd() ); } if(seed1 != seed_type(0)) { have_seed = true; } } catch(...) {} } #endif if(have_seed == false) { try { union { seed_type a; unsigned char b[sizeof(seed_type)]; } tmp; tmp.a = seed_type(0); std::ifstream f("/dev/urandom", std::ifstream::binary); if(f.good()) { f.read((char*)(&(tmp.b[0])), sizeof(seed_type)); } if(f.good()) { seed2 = tmp.a; if(seed2 != seed_type(0)) { have_seed = true; } } } catch(...) {} } if(have_seed == false) { // get better-than-nothing seeds in case reading /dev/urandom failed #if defined(ARMA_HAVE_GETTIMEOFDAY) { struct timeval posix_time; gettimeofday(&posix_time, 0); seed3 = static_cast(posix_time.tv_usec); } #endif seed4 = static_cast( std::time(NULL) & 0xFFFF ); union { uword* a; unsigned char b[sizeof(uword*)]; } tmp; tmp.a = (uword*)malloc(sizeof(uword)); if(tmp.a != NULL) { for(size_t i=0; i struct arma_rng::randi { arma_inline operator eT () { #if defined(ARMA_RNG_ALT) { return eT( arma_rng_alt::randi_val() ); } #elif defined(ARMA_USE_EXTERN_CXX11_RNG) { return eT( arma_rng_cxx11_instance.randi_val() ); } #else { return eT( arma_rng_cxx98::randi_val() ); } #endif } inline static int max_val() { #if defined(ARMA_RNG_ALT) { return arma_rng_alt::randi_max_val(); } #elif defined(ARMA_USE_EXTERN_CXX11_RNG) { return arma_rng_cxx11::randi_max_val(); } #else { return arma_rng_cxx98::randi_max_val(); } #endif } inline static void fill(eT* mem, const uword N, const int a, const int b) { #if defined(ARMA_RNG_ALT) { return arma_rng_alt::randi_fill(mem, N, a, b); } #elif defined(ARMA_USE_EXTERN_CXX11_RNG) { return arma_rng_cxx11_instance.randi_fill(mem, N, a, b); } #else { return arma_rng_cxx98::randi_fill(mem, N, a, b); } #endif } }; template struct arma_rng::randu { arma_inline operator eT () { #if defined(ARMA_RNG_ALT) { return eT( arma_rng_alt::randu_val() ); } #elif defined(ARMA_USE_EXTERN_CXX11_RNG) { return eT( arma_rng_cxx11_instance.randu_val() ); } #else { return eT( arma_rng_cxx98::randu_val() ); } #endif } inline static void fill(eT* mem, const uword N) { uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT tmp_i = eT( arma_rng::randu() ); const eT tmp_j = eT( arma_rng::randu() ); mem[i] = tmp_i; mem[j] = tmp_j; } if(i < N) { mem[i] = eT( arma_rng::randu() ); } } }; template struct arma_rng::randu< std::complex > { arma_inline operator std::complex () { const T a = T( arma_rng::randu() ); const T b = T( arma_rng::randu() ); return std::complex(a, b); } inline static void fill(std::complex* mem, const uword N) { for(uword i=0; i < N; ++i) { const T a = T( arma_rng::randu() ); const T b = T( arma_rng::randu() ); mem[i] = std::complex(a, b); } } }; template struct arma_rng::randn { inline operator eT () const { #if defined(ARMA_RNG_ALT) { return eT( arma_rng_alt::randn_val() ); } #elif defined(ARMA_USE_EXTERN_CXX11_RNG) { return eT( arma_rng_cxx11_instance.randn_val() ); } #else { return eT( arma_rng_cxx98::randn_val() ); } #endif } arma_inline static void dual_val(eT& out1, eT& out2) { #if defined(ARMA_RNG_ALT) { arma_rng_alt::randn_dual_val(out1, out2); } #elif defined(ARMA_USE_EXTERN_CXX11_RNG) { arma_rng_cxx11_instance.randn_dual_val(out1, out2); } #else { arma_rng_cxx98::randn_dual_val(out1, out2); } #endif } inline static void fill(eT* mem, const uword N) { uword i, j; for(i=0, j=1; j < N; i+=2, j+=2) { arma_rng::randn::dual_val( mem[i], mem[j] ); } if(i < N) { mem[i] = eT( arma_rng::randn() ); } } }; template struct arma_rng::randn< std::complex > { inline operator std::complex () const { T a, b; arma_rng::randn::dual_val(a, b); return std::complex(a, b); } inline static void fill(std::complex* mem, const uword N) { for(uword i=0; i < N; ++i) { mem[i] = std::complex( arma_rng::randn< std::complex >() ); } } }; //! @} armadillo-6.500.5/include/armadillo_bits/glue_min_bones.hpp0000666000000000000000000000161612620272703022450 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_min //! @{ class glue_min { public: template inline static void apply(Mat< eT >& out, const Proxy& PA, const Proxy& PB); template inline static void apply(Mat< std::complex >& out, const Proxy& PA, const Proxy& PB); template inline static void apply(Mat& out, const Glue& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_cx_scalar_bones.hpp0000666000000000000000000000670412620272703023311 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_cx_scalar //! @{ class op_cx_scalar_times { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_times>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_times>& X ); }; class op_cx_scalar_plus { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_plus>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_plus>& X ); }; class op_cx_scalar_minus_pre { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_minus_pre>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_minus_pre>& X ); }; class op_cx_scalar_minus_post { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_minus_post>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_minus_post>& X ); }; class op_cx_scalar_div_pre { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_div_pre>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_div_pre>& X ); }; class op_cx_scalar_div_post { public: template inline static void apply ( Mat< typename std::complex >& out, const mtOp, T1, op_cx_scalar_div_post>& X ); template inline static void apply ( Cube< typename std::complex >& out, const mtOpCube, T1, op_cx_scalar_div_post>& X ); }; //! @} armadillo-6.500.5/include/armadillo_bits/Glue_bones.hpp0000666000000000000000000000414612620272703021546 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Glue //! @{ //! Class for storing data required for delayed binary operations, //! such as the operands (e.g. two matrices) and the binary operator (e.g. addition). //! The operands are stored as references (which can be optimised away), //! while the operator is "stored" through the template definition (glue_type). //! The operands can be 'Mat', 'Row', 'Col', 'Op', and 'Glue'. //! Note that as 'Glue' can be one of the operands, more than two matrices can be stored. //! //! For example, we could have: Glue //! //! Another example is: Glue< Op, Op, glue_times > template class Glue : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = \ (is_same_type::value && T1::is_row) || (is_same_type::value && T1::is_row) || (is_same_type::value && T1::is_row && T2::is_row); static const bool is_col = \ (is_same_type::value && T2::is_col) || (is_same_type::value && T1::is_col) || (is_same_type::value && T1::is_col && T2::is_col); arma_inline Glue(const T1& in_A, const T2& in_B); arma_inline Glue(const T1& in_A, const T2& in_B, const uword in_aux_uword); arma_inline ~Glue(); const T1& A; //!< first operand const T2& B; //!< second operand uword aux_uword; //!< storage of auxiliary data, uword format }; //! @} armadillo-6.500.5/include/armadillo_bits/wrapper_blas.hpp0000666000000000000000000001765312620272703022154 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au #ifdef ARMA_USE_BLAS //! \namespace blas namespace for BLAS functions namespace blas { template inline void gemv(const char* transA, const blas_int* m, const blas_int* n, const eT* alpha, const eT* A, const blas_int* ldA, const eT* x, const blas_int* incx, const eT* beta, eT* y, const blas_int* incy) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; arma_fortran(arma_sgemv)(transA, m, n, (const T*)alpha, (const T*)A, ldA, (const T*)x, incx, (const T*)beta, (T*)y, incy); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgemv)(transA, m, n, (const T*)alpha, (const T*)A, ldA, (const T*)x, incx, (const T*)beta, (T*)y, incy); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_cgemv)(transA, m, n, (const T*)alpha, (const T*)A, ldA, (const T*)x, incx, (const T*)beta, (T*)y, incy); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zgemv)(transA, m, n, (const T*)alpha, (const T*)A, ldA, (const T*)x, incx, (const T*)beta, (T*)y, incy); } } template inline void gemm(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const eT* alpha, const eT* A, const blas_int* ldA, const eT* B, const blas_int* ldB, const eT* beta, eT* C, const blas_int* ldC) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; arma_fortran(arma_sgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC); } else if(is_double::value) { typedef double T; arma_fortran(arma_dgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC); } else if(is_supported_complex_float::value) { typedef std::complex T; arma_fortran(arma_cgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC); } else if(is_supported_complex_double::value) { typedef std::complex T; arma_fortran(arma_zgemm)(transA, transB, m, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)B, ldB, (const T*)beta, (T*)C, ldC); } } template inline void syrk(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const eT* alpha, const eT* A, const blas_int* ldA, const eT* beta, eT* C, const blas_int* ldC) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float T; arma_fortran(arma_ssyrk)(uplo, transA, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)beta, (T*)C, ldC); } else if(is_double::value) { typedef double T; arma_fortran(arma_dsyrk)(uplo, transA, n, k, (const T*)alpha, (const T*)A, ldA, (const T*)beta, (T*)C, ldC); } } template inline void herk(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const T* alpha, const std::complex* A, const blas_int* ldA, const T* beta, std::complex* C, const blas_int* ldC) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { typedef float TT; typedef std::complex cx_TT; arma_fortran(arma_cherk)(uplo, transA, n, k, (const TT*)alpha, (const cx_TT*)A, ldA, (const TT*)beta, (cx_TT*)C, ldC); } else if(is_double::value) { typedef double TT; typedef std::complex cx_TT; arma_fortran(arma_zherk)(uplo, transA, n, k, (const TT*)alpha, (const cx_TT*)A, ldA, (const TT*)beta, (cx_TT*)C, ldC); } } template inline eT dot(const uword n_elem, const eT* x, const eT* y) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { #if defined(ARMA_BLAS_SDOT_BUG) { if(n_elem == 0) { return eT(0); } const char trans = 'T'; const blas_int m = blas_int(n_elem); const blas_int n = 1; //const blas_int lda = (n_elem > 0) ? blas_int(n_elem) : blas_int(1); const blas_int inc = 1; const eT alpha = eT(1); const eT beta = eT(0); eT result[2]; // paranoia: using two elements instead of one //blas::gemv(&trans, &m, &n, &alpha, x, &lda, y, &inc, &beta, &result[0], &inc); blas::gemv(&trans, &m, &n, &alpha, x, &m, y, &inc, &beta, &result[0], &inc); return result[0]; } #else { blas_int n = blas_int(n_elem); blas_int inc = 1; typedef float T; return eT( arma_fortran(arma_sdot)(&n, (const T*)x, &inc, (const T*)y, &inc) ); } #endif } else if(is_double::value) { blas_int n = blas_int(n_elem); blas_int inc = 1; typedef double T; return eT( arma_fortran(arma_ddot)(&n, (const T*)x, &inc, (const T*)y, &inc) ); } else if( (is_supported_complex_float::value) || (is_supported_complex_double::value) ) { if(n_elem == 0) { return eT(0); } // using gemv() workaround due to compatibility issues with cdotu() and zdotu() const char trans = 'T'; const blas_int m = blas_int(n_elem); const blas_int n = 1; //const blas_int lda = (n_elem > 0) ? blas_int(n_elem) : blas_int(1); const blas_int inc = 1; const eT alpha = eT(1); const eT beta = eT(0); eT result[2]; // paranoia: using two elements instead of one //blas::gemv(&trans, &m, &n, &alpha, x, &lda, y, &inc, &beta, &result[0], &inc); blas::gemv(&trans, &m, &n, &alpha, x, &m, y, &inc, &beta, &result[0], &inc); return result[0]; } else { return eT(0); } } template arma_inline eT asum(const uword n_elem, const eT* x) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { blas_int n = blas_int(n_elem); blas_int inc = 1; typedef float T; return arma_fortran(arma_sasum)(&n, (const T*)x, &inc); } else if(is_double::value) { blas_int n = blas_int(n_elem); blas_int inc = 1; typedef double T; return arma_fortran(arma_dasum)(&n, (const T*)x, &inc); } else { return eT(0); } } template arma_inline eT nrm2(const uword n_elem, const eT* x) { arma_type_check((is_supported_blas_type::value == false)); if(is_float::value) { blas_int n = blas_int(n_elem); blas_int inc = 1; typedef float T; return arma_fortran(arma_snrm2)(&n, (const T*)x, &inc); } else if(is_double::value) { blas_int n = blas_int(n_elem); blas_int inc = 1; typedef double T; return arma_fortran(arma_dnrm2)(&n, (const T*)x, &inc); } else { return eT(0); } } } #endif armadillo-6.500.5/include/armadillo_bits/spop_strans_meat.hpp0000666000000000000000000000537212620272703023047 0ustar rootroot// Copyright (C) 2012-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup spop_strans //! @{ template arma_hot inline void spop_strans::apply_spmat(SpMat& out, const SpMat& X) { arma_extra_debug_sigprint(); typedef typename umat::elem_type ueT; const uword N = X.n_nonzero; if(N == uword(0)) { out.zeros(X.n_cols, X.n_rows); return; } umat locs(2, N); typename SpMat::const_iterator it = X.begin(); for(uword count = 0; count < N; ++count) { ueT* locs_ptr = locs.colptr(count); locs_ptr[0] = it.col(); locs_ptr[1] = it.row(); ++it; } const Col vals(const_cast(X.values), N, false); SpMat tmp(locs, vals, X.n_cols, X.n_rows); out.steal_mem(tmp); } template arma_hot inline void spop_strans::apply_proxy(SpMat& out, const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename umat::elem_type ueT; const SpProxy p(X); const uword N = p.get_n_nonzero(); if(N == uword(0)) { out.zeros(p.get_n_cols(), p.get_n_rows()); return; } umat locs(2, N); Col vals(N); eT* vals_ptr = vals.memptr(); typename SpProxy::const_iterator_type it = p.begin(); for(uword count = 0; count < N; ++count) { ueT* locs_ptr = locs.colptr(count); locs_ptr[0] = it.col(); locs_ptr[1] = it.row(); vals_ptr[count] = (*it); ++it; } SpMat tmp(locs, vals, p.get_n_cols(), p.get_n_rows()); out.steal_mem(tmp); } template arma_hot inline void spop_strans::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); if(is_SpMat::value) { const unwrap_spmat tmp(in.m); spop_strans::apply_spmat(out, tmp.M); } else { spop_strans::apply_proxy(out, in.m); } } //! for transpose of non-complex matrices, redirected from spop_htrans::apply() template arma_hot inline void spop_strans::apply(SpMat& out, const SpOp& in) { arma_extra_debug_sigprint(); if(is_SpMat::value) { const unwrap_spmat tmp(in.m); spop_strans::apply_spmat(out, tmp.M); } else { spop_strans::apply_proxy(out, in.m); } } //! @} armadillo-6.500.5/include/armadillo_bits/op_strans_meat.hpp0000666000000000000000000004120212620272703022474 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup op_strans //! @{ //! for tiny square matrices (size <= 4x4) template arma_hot inline void op_strans::apply_mat_noalias_tinysq(Mat& out, const TA& A) { const eT* Am = A.memptr(); eT* outm = out.memptr(); switch(A.n_rows) { case 1: { outm[0] = Am[0]; } break; case 2: { outm[pos::n2] = Am[pos::n2]; outm[pos::n2] = Am[pos::n2]; outm[pos::n2] = Am[pos::n2]; outm[pos::n2] = Am[pos::n2]; } break; case 3: { outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; outm[pos::n3] = Am[pos::n3]; } break; case 4: { outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; outm[pos::n4] = Am[pos::n4]; } break; default: ; } } //! Immediate transpose of a dense matrix template arma_hot inline void op_strans::apply_mat_noalias(Mat& out, const TA& A) { arma_extra_debug_sigprint(); const uword A_n_cols = A.n_cols; const uword A_n_rows = A.n_rows; out.set_size(A_n_cols, A_n_rows); if( (TA::is_row) || (TA::is_col) || (A_n_cols == 1) || (A_n_rows == 1) ) { arrayops::copy( out.memptr(), A.memptr(), A.n_elem ); } else { if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) ) { op_strans::apply_mat_noalias_tinysq(out, A); } else { eT* outptr = out.memptr(); for(uword k=0; k < A_n_rows; ++k) { const eT* Aptr = &(A.at(k,0)); uword j; for(j=1; j < A_n_cols; j+=2) { const eT tmp_i = (*Aptr); Aptr += A_n_rows; const eT tmp_j = (*Aptr); Aptr += A_n_rows; (*outptr) = tmp_i; outptr++; (*outptr) = tmp_j; outptr++; } if((j-1) < A_n_cols) { (*outptr) = (*Aptr); outptr++;; } } } } } template arma_hot inline void op_strans::apply_mat_inplace(Mat& out) { arma_extra_debug_sigprint(); const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; if(n_rows == n_cols) { arma_extra_debug_print("op_strans::apply(): doing in-place transpose of a square matrix"); const uword N = n_rows; for(uword k=0; k < N; ++k) { eT* colptr = &(out.at(k,k)); eT* rowptr = colptr; colptr++; rowptr += N; uword j; for(j=(k+2); j < N; j+=2) { std::swap( (*rowptr), (*colptr) ); rowptr += N; colptr++; std::swap( (*rowptr), (*colptr) ); rowptr += N; colptr++; } if((j-1) < N) { std::swap( (*rowptr), (*colptr) ); } } } else { Mat tmp; op_strans::apply_mat_noalias(tmp, out); out.steal_mem(tmp); } } template arma_hot inline void op_strans::apply_mat(Mat& out, const TA& A) { arma_extra_debug_sigprint(); if(&out != &A) { op_strans::apply_mat_noalias(out, A); } else { op_strans::apply_mat_inplace(out); } } template arma_hot inline void op_strans::apply_proxy(Mat& out, const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); // allow detection of in-place transpose if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { const unwrap::stored_type> tmp(P.Q); op_strans::apply_mat(out, tmp.M); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool is_alias = P.is_alias(out); if( (resolves_to_vector::value == true) && (Proxy::prefer_at_accessor == false) ) { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* out_mem = out.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < n_elem) { out_mem[i] = Pea[i]; } } else // aliasing { Mat out2(n_cols, n_rows); eT* out_mem = out2.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < n_elem) { out_mem[i] = Pea[i]; } out.steal_mem(out2); } } else // general matrix transpose { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* outptr = out.memptr(); for(uword k=0; k < n_rows; ++k) { uword j; for(j=1; j < n_cols; j+=2) { const uword i = j-1; const eT tmp_i = P.at(k,i); const eT tmp_j = P.at(k,j); (*outptr) = tmp_i; outptr++; (*outptr) = tmp_j; outptr++; } const uword i = j-1; if(i < n_cols) { (*outptr) = P.at(k,i); outptr++; } } } else // aliasing { Mat out2(n_cols, n_rows); eT* out2ptr = out2.memptr(); for(uword k=0; k < n_rows; ++k) { uword j; for(j=1; j < n_cols; j+=2) { const uword i = j-1; const eT tmp_i = P.at(k,i); const eT tmp_j = P.at(k,j); (*out2ptr) = tmp_i; out2ptr++; (*out2ptr) = tmp_j; out2ptr++; } const uword i = j-1; if(i < n_cols) { (*out2ptr) = P.at(k,i); out2ptr++; } } out.steal_mem(out2); } } } } template arma_hot inline void op_strans::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); op_strans::apply_proxy(out, in.m); } // // op_strans2 //! for tiny square matrices (size <= 4x4) template arma_hot inline void op_strans2::apply_noalias_tinysq(Mat& out, const TA& A, const eT val) { const eT* Am = A.memptr(); eT* outm = out.memptr(); switch(A.n_rows) { case 1: { outm[0] = val * Am[0]; } break; case 2: { outm[pos::n2] = val * Am[pos::n2]; outm[pos::n2] = val * Am[pos::n2]; outm[pos::n2] = val * Am[pos::n2]; outm[pos::n2] = val * Am[pos::n2]; } break; case 3: { outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; outm[pos::n3] = val * Am[pos::n3]; } break; case 4: { outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; outm[pos::n4] = val * Am[pos::n4]; } break; default: ; } } template arma_hot inline void op_strans2::apply_noalias(Mat& out, const TA& A, const eT val) { arma_extra_debug_sigprint(); const uword A_n_cols = A.n_cols; const uword A_n_rows = A.n_rows; out.set_size(A_n_cols, A_n_rows); if( (TA::is_col) || (TA::is_row) || (A_n_cols == 1) || (A_n_rows == 1) ) { const uword N = A.n_elem; const eT* A_mem = A.memptr(); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT tmp_i = A_mem[i]; const eT tmp_j = A_mem[j]; out_mem[i] = val * tmp_i; out_mem[j] = val * tmp_j; } if(i < N) { out_mem[i] = val * A_mem[i]; } } else { if( (A_n_rows <= 4) && (A_n_rows == A_n_cols) ) { op_strans2::apply_noalias_tinysq(out, A, val); } else { eT* outptr = out.memptr(); for(uword k=0; k < A_n_rows; ++k) { const eT* Aptr = &(A.at(k,0)); uword j; for(j=1; j < A_n_cols; j+=2) { const eT tmp_i = (*Aptr); Aptr += A_n_rows; const eT tmp_j = (*Aptr); Aptr += A_n_rows; (*outptr) = val * tmp_i; outptr++; (*outptr) = val * tmp_j; outptr++; } if((j-1) < A_n_cols) { (*outptr) = val * (*Aptr); outptr++;; } } } } } template arma_hot inline void op_strans2::apply(Mat& out, const TA& A, const eT val) { arma_extra_debug_sigprint(); if(&out != &A) { op_strans2::apply_noalias(out, A, val); } else { const uword n_rows = out.n_rows; const uword n_cols = out.n_cols; if(n_rows == n_cols) { arma_extra_debug_print("op_strans2::apply(): doing in-place transpose of a square matrix"); const uword N = n_rows; // TODO: do multiplication while swapping for(uword k=0; k < N; ++k) { eT* colptr = out.colptr(k); uword i,j; for(i=(k+1), j=(k+2); j < N; i+=2, j+=2) { std::swap(out.at(k,i), colptr[i]); std::swap(out.at(k,j), colptr[j]); } if(i < N) { std::swap(out.at(k,i), colptr[i]); } } arrayops::inplace_mul( out.memptr(), val, out.n_elem ); } else { Mat tmp; op_strans2::apply_noalias(tmp, A, val); out.steal_mem(tmp); } } } template arma_hot inline void op_strans2::apply_proxy(Mat& out, const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X); // allow detection of in-place transpose if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { const unwrap::stored_type> tmp(P.Q); op_strans2::apply(out, tmp.M, val); } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool is_alias = P.is_alias(out); if( (resolves_to_vector::value == true) && (Proxy::prefer_at_accessor == false) ) { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* out_mem = out.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; out_mem[i] = val * tmp_i; out_mem[j] = val * tmp_j; } if(i < n_elem) { out_mem[i] = val * Pea[i]; } } else // aliasing { Mat out2(n_cols, n_rows); eT* out_mem = out2.memptr(); const uword n_elem = P.get_n_elem(); typename Proxy::ea_type Pea = P.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tmp_i = Pea[i]; const eT tmp_j = Pea[j]; out_mem[i] = val * tmp_i; out_mem[j] = val * tmp_j; } if(i < n_elem) { out_mem[i] = val * Pea[i]; } out.steal_mem(out2); } } else // general matrix transpose { if(is_alias == false) { out.set_size(n_cols, n_rows); eT* outptr = out.memptr(); for(uword k=0; k < n_rows; ++k) { uword j; for(j=1; j < n_cols; j+=2) { const uword i = j-1; const eT tmp_i = P.at(k,i); const eT tmp_j = P.at(k,j); (*outptr) = val * tmp_i; outptr++; (*outptr) = val * tmp_j; outptr++; } const uword i = j-1; if(i < n_cols) { (*outptr) = val * P.at(k,i); outptr++; } } } else // aliasing { Mat out2(n_cols, n_rows); eT* out2ptr = out2.memptr(); for(uword k=0; k < n_rows; ++k) { uword j; for(j=1; j < n_cols; j+=2) { const uword i = j-1; const eT tmp_i = P.at(k,i); const eT tmp_j = P.at(k,j); (*out2ptr) = val * tmp_i; out2ptr++; (*out2ptr) = val * tmp_j; out2ptr++; } const uword i = j-1; if(i < n_cols) { (*out2ptr) = val * P.at(k,i); out2ptr++; } } out.steal_mem(out2); } } } } //! @} armadillo-6.500.5/include/armadillo_bits/op_symmat_meat.hpp0000666000000000000000000001142012620344073022473 0ustar rootroot// Copyright (C) 2011-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_symmat //! @{ template inline void op_symmat::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat& A = tmp.M; arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square sized" ); const uword N = A.n_rows; const bool upper = (in.aux_uword_a == 0); if(&out != &A) { out.copy_size(A); if(upper) { // upper triangular: copy the diagonal and the elements above the diagonal for(uword i=0; i inline void op_symmat_cx::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(in.m); const Mat& A = tmp.M; arma_debug_check( (A.is_square() == false), "symmatu()/symmatl(): given matrix must be square sized" ); const uword N = A.n_rows; const bool upper = (in.aux_uword_a == 0); const bool do_conj = (in.aux_uword_b == 1); if(&out != &A) { out.copy_size(A); if(upper) { // upper triangular: copy the diagonal and the elements above the diagonal for(uword i=0; i inline const eOp eps(const Base& X, const typename arma_not_cx::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return eOp(X.get_ref()); } //! \brief //! eps version for complex matrices and vectors template inline Mat< typename T1::pod_type > eps(const Base< std::complex, T1>& X, const typename arma_cx_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::pod_type T; typedef typename T1::elem_type eT; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; Mat out(A.n_rows, A.n_cols); T* out_mem = out.memptr(); const eT* A_mem = A.memptr(); const uword n_elem = A.n_elem; for(uword i=0; i arma_inline arma_warn_unused typename arma_integral_only::result eps(const eT& x) { arma_ignore(x); return eT(0); } template arma_inline arma_warn_unused typename arma_real_only::result eps(const eT& x) { return eop_aux::direct_eps(x); } template arma_inline arma_warn_unused typename arma_real_only::result eps(const std::complex& x) { return eop_aux::direct_eps(x); } //! @} armadillo-6.500.5/include/armadillo_bits/op_diagmat_meat.hpp0000666000000000000000000001306012620272703022571 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_diagmat //! @{ template inline void op_diagmat::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy P(X.m); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const bool P_is_vec = (n_rows == 1) || (n_cols == 1); if(P.is_alias(out) == false) { if(P_is_vec) // generate a diagonal matrix out of a vector { const uword N = (n_rows == 1) ? n_cols : n_rows; out.zeros(N, N); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type P_ea = P.get_ea(); for(uword i=0; i < N; ++i) { out.at(i,i) = P_ea[i]; } } else { if(n_rows == 1) { for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(0,i); } } else { for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(i,0); } } } } else // generate a diagonal matrix out of a matrix { out.zeros(n_rows, n_cols); const uword N = (std::min)(n_rows, n_cols); for(uword i=0; i < N; ++i) { out.at(i,i) = P.at(i,i); } } } else // we have aliasing { if(P_is_vec) // generate a diagonal matrix out of a vector { const uword N = (n_rows == 1) ? n_cols : n_rows; podarray tmp(N); eT* tmp_mem = tmp.memptr(); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type P_ea = P.get_ea(); for(uword i=0; i < N; ++i) { tmp_mem[i] = P_ea[i]; } } else { if(n_rows == 1) { for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(0,i); } } else { for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(i,0); } } } out.zeros(N, N); for(uword i=0; i < N; ++i) { out.at(i,i) = tmp_mem[i]; } } else // generate a diagonal matrix out of a matrix { const uword N = (std::min)(n_rows, n_cols); if( (Proxy::has_subview == false) && (Proxy::fake_mat == false) ) { // NOTE: we have aliasing and it's not due to a subview, hence we're assuming that the output matrix already has the correct size for(uword i=0; i < n_cols; ++i) { if(i < N) { const eT val = P.at(i,i); arrayops::fill_zeros(out.colptr(i), n_rows); out.at(i,i) = val; } else { arrayops::fill_zeros(out.colptr(i), n_rows); } } } else { podarray tmp(N); eT* tmp_mem = tmp.memptr(); for(uword i=0; i < N; ++i) { tmp_mem[i] = P.at(i,i); } out.zeros(n_rows, n_cols); for(uword i=0; i < N; ++i) { out.at(i,i) = tmp_mem[i]; } } } } } template inline void op_diagmat2::apply(Mat& out, const Proxy& P, const uword row_offset, const uword col_offset) { arma_extra_debug_sigprint(); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_elem = P.get_n_elem(); if(n_elem == 0) { out.reset(); return; } const bool P_is_vec = (T1::is_row) || (T1::is_col) || (n_rows == 1) || (n_cols == 1); if(P_is_vec) { const uword n_pad = (std::max)(row_offset, col_offset); out.zeros(n_elem + n_pad, n_elem + n_pad); if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i < n_elem; ++i) { out.at(row_offset + i, col_offset + i) = Pea[i]; } } else { const unwrap::stored_type> U(P.Q); const Proxy::stored_type>::stored_type> PP(U.M); op_diagmat2::apply(out, PP, row_offset, col_offset); } } else // P represents a matrix { arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "diagmat(): requested diagonal out of bounds" ); out.zeros(n_rows, n_cols); const uword N = (std::min)(n_rows - row_offset, n_cols - col_offset); for(uword i=0; i inline void op_diagmat2::apply(Mat& out, const Op& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword row_offset = X.aux_uword_a; const uword col_offset = X.aux_uword_b; const Proxy P(X.m); if(P.is_alias(out)) { Mat tmp; op_diagmat2::apply(tmp, P, row_offset, col_offset); out.steal_mem(tmp); } else { op_diagmat2::apply(out, P, row_offset, col_offset); } } //! @} armadillo-6.500.5/include/armadillo_bits/glue_cov_meat.hpp0000666000000000000000000000670012620272703022273 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup glue_cov //! @{ template inline void glue_cov::direct_cov(Mat& out, const Mat& A, const Mat& B, const uword norm_type) { arma_extra_debug_sigprint(); if(A.is_vec() && B.is_vec()) { arma_debug_check( (A.n_elem != B.n_elem), "cov(): the number of elements in A and B must match" ); const eT* A_ptr = A.memptr(); const eT* B_ptr = B.memptr(); eT A_acc = eT(0); eT B_acc = eT(0); eT out_acc = eT(0); const uword N = A.n_elem; for(uword i=0; i 1) ? eT(N-1) : eT(1) ) : eT(N); out.set_size(1,1); out[0] = out_acc/norm_val; } else { arma_debug_assert_mul_size(A, B, true, false, "cov()"); const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out = trans(A) * B; out -= (trans(sum(A)) * sum(B))/eT(N); out /= norm_val; } } template inline void glue_cov::direct_cov(Mat< std::complex >& out, const Mat< std::complex >& A, const Mat< std::complex >& B, const uword norm_type) { arma_extra_debug_sigprint(); typedef typename std::complex eT; if(A.is_vec() && B.is_vec()) { arma_debug_check( (A.n_elem != B.n_elem), "cov(): the number of elements in A and B must match" ); const eT* A_ptr = A.memptr(); const eT* B_ptr = B.memptr(); eT A_acc = eT(0); eT B_acc = eT(0); eT out_acc = eT(0); const uword N = A.n_elem; for(uword i=0; i 1) ? eT(N-1) : eT(1) ) : eT(N); out.set_size(1,1); out[0] = out_acc/norm_val; } else { arma_debug_assert_mul_size(A, B, true, false, "cov()"); const uword N = A.n_rows; const eT norm_val = (norm_type == 0) ? ( (N > 1) ? eT(N-1) : eT(1) ) : eT(N); out = trans(A) * B; // out = strans(conj(A)) * B; out -= (trans(sum(A)) * sum(B))/eT(N); // out -= (strans(conj(sum(A))) * sum(B))/eT(N); out /= norm_val; } } template inline void glue_cov::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap_check A_tmp(X.A, out); const unwrap_check B_tmp(X.B, out); const Mat& A = A_tmp.M; const Mat& B = B_tmp.M; const uword norm_type = X.aux_uword; if(&A != &B) { glue_cov::direct_cov(out, A, B, norm_type); } else { op_cov::direct_cov(out, A, norm_type); } } //! @} armadillo-6.500.5/include/armadillo_bits/def_lapack.hpp0000666000000000000000000006501512627061342021541 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by James Sanders // Written by Eric Jon Sundstrom #ifdef ARMA_USE_LAPACK #if !defined(ARMA_BLAS_CAPITALS) #define arma_sgetrf sgetrf #define arma_dgetrf dgetrf #define arma_cgetrf cgetrf #define arma_zgetrf zgetrf #define arma_sgetri sgetri #define arma_dgetri dgetri #define arma_cgetri cgetri #define arma_zgetri zgetri #define arma_strtri strtri #define arma_dtrtri dtrtri #define arma_ctrtri ctrtri #define arma_ztrtri ztrtri #define arma_sgeev sgeev #define arma_dgeev dgeev #define arma_cgeev cgeev #define arma_zgeev zgeev #define arma_ssyev ssyev #define arma_dsyev dsyev #define arma_cheev cheev #define arma_zheev zheev #define arma_ssyevd ssyevd #define arma_dsyevd dsyevd #define arma_cheevd cheevd #define arma_zheevd zheevd #define arma_sggev sggev #define arma_dggev dggev #define arma_cggev cggev #define arma_zggev zggev #define arma_spotrf spotrf #define arma_dpotrf dpotrf #define arma_cpotrf cpotrf #define arma_zpotrf zpotrf #define arma_spotri spotri #define arma_dpotri dpotri #define arma_cpotri cpotri #define arma_zpotri zpotri #define arma_sgeqrf sgeqrf #define arma_dgeqrf dgeqrf #define arma_cgeqrf cgeqrf #define arma_zgeqrf zgeqrf #define arma_sorgqr sorgqr #define arma_dorgqr dorgqr #define arma_cungqr cungqr #define arma_zungqr zungqr #define arma_sgesvd sgesvd #define arma_dgesvd dgesvd #define arma_cgesvd cgesvd #define arma_zgesvd zgesvd #define arma_sgesdd sgesdd #define arma_dgesdd dgesdd #define arma_cgesdd cgesdd #define arma_zgesdd zgesdd #define arma_sgesv sgesv #define arma_dgesv dgesv #define arma_cgesv cgesv #define arma_zgesv zgesv #define arma_sgesvx sgesvx #define arma_dgesvx dgesvx #define arma_cgesvx cgesvx #define arma_zgesvx zgesvx #define arma_sgels sgels #define arma_dgels dgels #define arma_cgels cgels #define arma_zgels zgels #define arma_sgelsd sgelsd #define arma_dgelsd dgelsd #define arma_cgelsd cgelsd #define arma_zgelsd zgelsd #define arma_strtrs strtrs #define arma_dtrtrs dtrtrs #define arma_ctrtrs ctrtrs #define arma_ztrtrs ztrtrs #define arma_sgees sgees #define arma_dgees dgees #define arma_cgees cgees #define arma_zgees zgees #define arma_strsyl strsyl #define arma_dtrsyl dtrsyl #define arma_ctrsyl ctrsyl #define arma_ztrsyl ztrsyl #define arma_ssytrf ssytrf #define arma_dsytrf dsytrf #define arma_csytrf csytrf #define arma_zsytrf zsytrf #define arma_ssytri ssytri #define arma_dsytri dsytri #define arma_csytri csytri #define arma_zsytri zsytri #define arma_sgges sgges #define arma_dgges dgges #define arma_cgges cgges #define arma_zgges zgges #define arma_slange slange #define arma_dlange dlange #define arma_clange clange #define arma_zlange zlange #define arma_sgecon sgecon #define arma_dgecon dgecon #define arma_cgecon cgecon #define arma_zgecon zgecon #define arma_ilaenv ilaenv #else #define arma_sgetrf SGETRF #define arma_dgetrf DGETRF #define arma_cgetrf CGETRF #define arma_zgetrf ZGETRF #define arma_sgetri SGETRI #define arma_dgetri DGETRI #define arma_cgetri CGETRI #define arma_zgetri ZGETRI #define arma_strtri STRTRI #define arma_dtrtri DTRTRI #define arma_ctrtri CTRTRI #define arma_ztrtri ZTRTRI #define arma_sgeev SGEEV #define arma_dgeev DGEEV #define arma_cgeev CGEEV #define arma_zgeev ZGEEV #define arma_ssyev SSYEV #define arma_dsyev DSYEV #define arma_cheev CHEEV #define arma_zheev ZHEEV #define arma_ssyevd SSYEVD #define arma_dsyevd DSYEVD #define arma_cheevd CHEEVD #define arma_zheevd ZHEEVD #define arma_sggev SGGEV #define arma_dggev DGGEV #define arma_cggev CGGEV #define arma_zggev ZGGEV #define arma_spotrf SPOTRF #define arma_dpotrf DPOTRF #define arma_cpotrf CPOTRF #define arma_zpotrf ZPOTRF #define arma_spotri SPOTRI #define arma_dpotri DPOTRI #define arma_cpotri CPOTRI #define arma_zpotri ZPOTRI #define arma_sgeqrf SGEQRF #define arma_dgeqrf DGEQRF #define arma_cgeqrf CGEQRF #define arma_zgeqrf ZGEQRF #define arma_sorgqr SORGQR #define arma_dorgqr DORGQR #define arma_cungqr CUNGQR #define arma_zungqr ZUNGQR #define arma_sgesvd SGESVD #define arma_dgesvd DGESVD #define arma_cgesvd CGESVD #define arma_zgesvd ZGESVD #define arma_sgesdd SGESDD #define arma_dgesdd DGESDD #define arma_cgesdd CGESDD #define arma_zgesdd ZGESDD #define arma_sgesv SGESV #define arma_dgesv DGESV #define arma_cgesv CGESV #define arma_zgesv ZGESV #define arma_sgesvx SGESVX #define arma_dgesvx DGESVX #define arma_cgesvx CGESVX #define arma_zgesvx ZGESVX #define arma_sgels SGELS #define arma_dgels DGELS #define arma_cgels CGELS #define arma_zgels ZGELS #define arma_sgelsd SGELSD #define arma_dgelsd DGELSD #define arma_cgelsd CGELSD #define arma_zgelsd ZGELSD #define arma_strtrs STRTRS #define arma_dtrtrs DTRTRS #define arma_ctrtrs CTRTRS #define arma_ztrtrs ZTRTRS #define arma_sgees SGEES #define arma_dgees DGEES #define arma_cgees CGEES #define arma_zgees ZGEES #define arma_strsyl STRSYL #define arma_dtrsyl DTRSYL #define arma_ctrsyl CTRSYL #define arma_ztrsyl ZTRSYL #define arma_ssytrf SSYTRF #define arma_dsytrf DSYTRF #define arma_csytrf CSYTRF #define arma_zsytrf ZSYTRF #define arma_ssytri SSYTRI #define arma_dsytri DSYTRI #define arma_csytri CSYTRI #define arma_zsytri ZSYTRI #define arma_sgges SGGES #define arma_dgges DGGES #define arma_cgges CGGES #define arma_zgges ZGGES #define arma_slange SLANGE #define arma_dlange DLANGE #define arma_clange CLANGE #define arma_zlange ZLANGE #define arma_sgecon SGECON #define arma_dgecon DGECON #define arma_cgecon CGECON #define arma_zgecon ZGECON #define arma_ilaenv ILAENV #endif extern "C" { // LU factorisation void arma_fortran(arma_sgetrf)(blas_int* m, blas_int* n, float* a, blas_int* lda, blas_int* ipiv, blas_int* info); void arma_fortran(arma_dgetrf)(blas_int* m, blas_int* n, double* a, blas_int* lda, blas_int* ipiv, blas_int* info); void arma_fortran(arma_cgetrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, blas_int* info); void arma_fortran(arma_zgetrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, blas_int* info); // matrix inversion (using LU factorisation result) void arma_fortran(arma_sgetri)(blas_int* n, float* a, blas_int* lda, blas_int* ipiv, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgetri)(blas_int* n, double* a, blas_int* lda, blas_int* ipiv, double* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_cgetri)(blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zgetri)(blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info); // matrix inversion (triangular matrices) void arma_fortran(arma_strtri)(char* uplo, char* diag, blas_int* n, float* a, blas_int* lda, blas_int* info); void arma_fortran(arma_dtrtri)(char* uplo, char* diag, blas_int* n, double* a, blas_int* lda, blas_int* info); void arma_fortran(arma_ctrtri)(char* uplo, char* diag, blas_int* n, void* a, blas_int* lda, blas_int* info); void arma_fortran(arma_ztrtri)(char* uplo, char* diag, blas_int* n, void* a, blas_int* lda, blas_int* info); // eigen decomposition of general matrix (real) void arma_fortran(arma_sgeev)(char* jobvl, char* jobvr, blas_int* N, float* a, blas_int* lda, float* wr, float* wi, float* vl, blas_int* ldvl, float* vr, blas_int* ldvr, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgeev)(char* jobvl, char* jobvr, blas_int* N, double* a, blas_int* lda, double* wr, double* wi, double* vl, blas_int* ldvl, double* vr, blas_int* ldvr, double* work, blas_int* lwork, blas_int* info); // eigen decomposition of general matrix (complex) void arma_fortran(arma_cgeev)(char* jobvl, char* jobvr, blas_int* N, void* a, blas_int* lda, void* w, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, float* rwork, blas_int* info); void arma_fortran(arma_zgeev)(char* jobvl, char* jobvr, blas_int* N, void* a, blas_int* lda, void* w, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, double* rwork, blas_int* info); // eigen decomposition of symmetric real matrices void arma_fortran(arma_ssyev)(char* jobz, char* uplo, blas_int* n, float* a, blas_int* lda, float* w, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dsyev)(char* jobz, char* uplo, blas_int* n, double* a, blas_int* lda, double* w, double* work, blas_int* lwork, blas_int* info); // eigen decomposition of hermitian matrices (complex) void arma_fortran(arma_cheev)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, float* w, void* work, blas_int* lwork, float* rwork, blas_int* info); void arma_fortran(arma_zheev)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, double* w, void* work, blas_int* lwork, double* rwork, blas_int* info); // eigen decomposition of symmetric real matrices by divide and conquer void arma_fortran(arma_ssyevd)(char* jobz, char* uplo, blas_int* n, float* a, blas_int* lda, float* w, float* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info); void arma_fortran(arma_dsyevd)(char* jobz, char* uplo, blas_int* n, double* a, blas_int* lda, double* w, double* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info); // eigen decomposition of hermitian matrices (complex) by divide and conquer void arma_fortran(arma_cheevd)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, float* w, void* work, blas_int* lwork, float* rwork, blas_int* lrwork, blas_int* iwork, blas_int* liwork, blas_int* info); void arma_fortran(arma_zheevd)(char* jobz, char* uplo, blas_int* n, void* a, blas_int* lda, double* w, void* work, blas_int* lwork, double* rwork, blas_int* lrwork, blas_int* iwork, blas_int* liwork, blas_int* info); // eigen decomposition of general real matrix pair void arma_fortran(arma_sggev)(char* jobvl, char* jobvr, blas_int* n, float* a, blas_int* lda, float* b, blas_int* ldb, float* alphar, float* alphai, float* beta, float* vl, blas_int* ldvl, float* vr, blas_int* ldvr, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dggev)(char* jobvl, char* jobvr, blas_int* n, double* a, blas_int* lda, double* b, blas_int* ldb, double* alphar, double* alphai, double* beta, double* vl, blas_int* ldvl, double* vr, blas_int* ldvr, double* work, blas_int* lwork, blas_int* info); // eigen decomposition of general complex matrix pair void arma_fortran(arma_cggev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, void* alpha, void* beta, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, float* rwork, blas_int* info); void arma_fortran(arma_zggev)(char* jobvl, char* jobvr, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, void* alpha, void* beta, void* vl, blas_int* ldvl, void* vr, blas_int* ldvr, void* work, blas_int* lwork, double* rwork, blas_int* info); // Cholesky decomposition void arma_fortran(arma_spotrf)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* info); void arma_fortran(arma_dpotrf)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* info); void arma_fortran(arma_cpotrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info); void arma_fortran(arma_zpotrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info); // matrix inversion (using Cholesky decomposition result) void arma_fortran(arma_spotri)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* info); void arma_fortran(arma_dpotri)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* info); void arma_fortran(arma_cpotri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info); void arma_fortran(arma_zpotri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* info); // QR decomposition void arma_fortran(arma_sgeqrf)(blas_int* m, blas_int* n, float* a, blas_int* lda, float* tau, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgeqrf)(blas_int* m, blas_int* n, double* a, blas_int* lda, double* tau, double* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_cgeqrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zgeqrf)(blas_int* m, blas_int* n, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info); // Q matrix calculation from QR decomposition (real matrices) void arma_fortran(arma_sorgqr)(blas_int* m, blas_int* n, blas_int* k, float* a, blas_int* lda, float* tau, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dorgqr)(blas_int* m, blas_int* n, blas_int* k, double* a, blas_int* lda, double* tau, double* work, blas_int* lwork, blas_int* info); // Q matrix calculation from QR decomposition (complex matrices) void arma_fortran(arma_cungqr)(blas_int* m, blas_int* n, blas_int* k, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zungqr)(blas_int* m, blas_int* n, blas_int* k, void* a, blas_int* lda, void* tau, void* work, blas_int* lwork, blas_int* info); // SVD (real matrices) void arma_fortran(arma_sgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, float* a, blas_int* lda, float* s, float* u, blas_int* ldu, float* vt, blas_int* ldvt, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, double* a, blas_int* lda, double* s, double* u, blas_int* ldu, double* vt, blas_int* ldvt, double* work, blas_int* lwork, blas_int* info); // SVD (complex matrices) void arma_fortran(arma_cgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, void* a, blas_int* lda, float* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, float* rwork, blas_int* info); void arma_fortran(arma_zgesvd)(char* jobu, char* jobvt, blas_int* m, blas_int* n, void* a, blas_int* lda, double* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, double* rwork, blas_int* info); // SVD (real matrices) by divide and conquer void arma_fortran(arma_sgesdd)(char* jobz, blas_int* m, blas_int* n, float* a, blas_int* lda, float* s, float* u, blas_int* ldu, float* vt, blas_int* ldvt, float* work, blas_int* lwork, blas_int* iwork, blas_int* info); void arma_fortran(arma_dgesdd)(char* jobz, blas_int* m, blas_int* n, double* a, blas_int* lda, double* s, double* u, blas_int* ldu, double* vt, blas_int* ldvt, double* work, blas_int* lwork, blas_int* iwork, blas_int* info); // SVD (complex matrices) by divide and conquer void arma_fortran(arma_cgesdd)(char* jobz, blas_int* m, blas_int* n, void* a, blas_int* lda, float* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, float* rwork, blas_int* iwork, blas_int* info); void arma_fortran(arma_zgesdd)(char* jobz, blas_int* m, blas_int* n, void* a, blas_int* lda, double* s, void* u, blas_int* ldu, void* vt, blas_int* ldvt, void* work, blas_int* lwork, double* rwork, blas_int* iwork, blas_int* info); // solve system of linear equations (general square matrix) void arma_fortran(arma_sgesv)(blas_int* n, blas_int* nrhs, float* a, blas_int* lda, blas_int* ipiv, float* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_dgesv)(blas_int* n, blas_int* nrhs, double* a, blas_int* lda, blas_int* ipiv, double* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_cgesv)(blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_zgesv)(blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info); // solve system of linear equations (general square matrix, advanced form, real matrices) void arma_fortran(arma_sgesvx)(char* fact, char* trans, blas_int* n, blas_int* nrhs, float* a, blas_int* lda, float* af, blas_int* ldaf, blas_int* ipiv, char* equed, float* r, float* c, float* b, blas_int* ldb, float* x, blas_int* ldx, float* rcond, float* ferr, float* berr, float* work, blas_int* iwork, blas_int* info); void arma_fortran(arma_dgesvx)(char* fact, char* trans, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, double* af, blas_int* ldaf, blas_int* ipiv, char* equed, double* r, double* c, double* b, blas_int* ldb, double* x, blas_int* ldx, double* rcond, double* ferr, double* berr, double* work, blas_int* iwork, blas_int* info); // solve system of linear equations (general square matrix, advanced form, complex matrices) void arma_fortran(arma_cgesvx)(char* fact, char* trans, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* af, blas_int* ldaf, blas_int* ipiv, char* equed, float* r, float* c, void* b, blas_int* ldb, void* x, blas_int* ldx, float* rcond, float* ferr, float* berr, void* work, float* rwork, blas_int* info); void arma_fortran(arma_zgesvx)(char* fact, char* trans, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* af, blas_int* ldaf, blas_int* ipiv, char* equed, double* r, double* c, void* b, blas_int* ldb, void* x, blas_int* ldx, double* rcond, double* ferr, double* berr, void* work, double* rwork, blas_int* info); // solve over/under-determined system of linear equations void arma_fortran(arma_sgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, float* a, blas_int* lda, float* b, blas_int* ldb, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, double* b, blas_int* ldb, double* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_cgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zgels)(char* trans, blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, void* work, blas_int* lwork, blas_int* info); // approximately solve system of linear equations using svd (real) void arma_fortran(arma_sgelsd)(blas_int* m, blas_int* n, blas_int* nrhs, float* a, blas_int* lda, float* b, blas_int* ldb, float* S, float* rcond, blas_int* rank, float* work, blas_int* lwork, blas_int* iwork, blas_int* info); void arma_fortran(arma_dgelsd)(blas_int* m, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, double* b, blas_int* ldb, double* S, double* rcond, blas_int* rank, double* work, blas_int* lwork, blas_int* iwork, blas_int* info); // approximately solve system of linear equations using svd (complex) void arma_fortran(arma_cgelsd)(blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, float* S, float* rcond, blas_int* rank, void* work, blas_int* lwork, float* rwork, blas_int* iwork, blas_int* info); void arma_fortran(arma_zgelsd)(blas_int* m, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, void* b, blas_int* ldb, double* S, double* rcond, blas_int* rank, void* work, blas_int* lwork, double* rwork, blas_int* iwork, blas_int* info); // solve system of linear equations (triangular matrix) void arma_fortran(arma_strtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const float* a, blas_int* lda, float* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_dtrtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const double* a, blas_int* lda, double* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_ctrtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* info); void arma_fortran(arma_ztrtrs)(char* uplo, char* trans, char* diag, blas_int* n, blas_int* nrhs, const void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* info); // Schur decomposition (real matrices) void arma_fortran(arma_sgees)(char* jobvs, char* sort, void* select, blas_int* n, float* a, blas_int* lda, blas_int* sdim, float* wr, float* wi, float* vs, blas_int* ldvs, float* work, blas_int* lwork, blas_int* bwork, blas_int* info); void arma_fortran(arma_dgees)(char* jobvs, char* sort, void* select, blas_int* n, double* a, blas_int* lda, blas_int* sdim, double* wr, double* wi, double* vs, blas_int* ldvs, double* work, blas_int* lwork, blas_int* bwork, blas_int* info); // Schur decomposition (complex matrices) void arma_fortran(arma_cgees)(char* jobvs, char* sort, void* select, blas_int* n, void* a, blas_int* lda, blas_int* sdim, void* w, void* vs, blas_int* ldvs, void* work, blas_int* lwork, float* rwork, blas_int* bwork, blas_int* info); void arma_fortran(arma_zgees)(char* jobvs, char* sort, void* select, blas_int* n, void* a, blas_int* lda, blas_int* sdim, void* w, void* vs, blas_int* ldvs, void* work, blas_int* lwork, double* rwork, blas_int* bwork, blas_int* info); // solve a Sylvester equation ax + xb = c, with a and b assumed to be in Schur form void arma_fortran(arma_strsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const float* a, blas_int* lda, const float* b, blas_int* ldb, float* c, blas_int* ldc, float* scale, blas_int* info); void arma_fortran(arma_dtrsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const double* a, blas_int* lda, const double* b, blas_int* ldb, double* c, blas_int* ldc, double* scale, blas_int* info); void arma_fortran(arma_ctrsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const void* a, blas_int* lda, const void* b, blas_int* ldb, void* c, blas_int* ldc, float* scale, blas_int* info); void arma_fortran(arma_ztrsyl)(char* transa, char* transb, blas_int* isgn, blas_int* m, blas_int* n, const void* a, blas_int* lda, const void* b, blas_int* ldb, void* c, blas_int* ldc, double* scale, blas_int* info); void arma_fortran(arma_ssytrf)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* ipiv, float* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_dsytrf)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* ipiv, double* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_csytrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_zsytrf)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* lwork, blas_int* info); void arma_fortran(arma_ssytri)(char* uplo, blas_int* n, float* a, blas_int* lda, blas_int* ipiv, float* work, blas_int* info); void arma_fortran(arma_dsytri)(char* uplo, blas_int* n, double* a, blas_int* lda, blas_int* ipiv, double* work, blas_int* info); void arma_fortran(arma_csytri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* info); void arma_fortran(arma_zsytri)(char* uplo, blas_int* n, void* a, blas_int* lda, blas_int* ipiv, void* work, blas_int* info); // QZ decomposition (real matrices) void arma_fortran(arma_sgges)(char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, float* a, blas_int* lda, float* b, blas_int* ldb, blas_int* sdim, float* alphar, float* alphai, float* beta, float* vsl, blas_int* ldvsl, float* vsr, blas_int* ldvsr, float* work, blas_int* lwork, float* bwork, blas_int* info); void arma_fortran(arma_dgges)(char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, double* a, blas_int* lda, double* b, blas_int* ldb, blas_int* sdim, double* alphar, double* alphai, double* beta, double* vsl, blas_int* ldvsl, double* vsr, blas_int* ldvsr, double* work, blas_int* lwork, double* bwork, blas_int* info); // QZ decomposition (complex matrices) void arma_fortran(arma_cgges)(char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* sdim, void* alpha, void* beta, void* vsl, blas_int* ldvsl, void* vsr, blas_int* ldvsr, void* work, blas_int* lwork, float* rwork, float* bwork, blas_int* info); void arma_fortran(arma_zgges)(char* jobvsl, char* jobvsr, char* sort, void* selctg, blas_int* n, void* a, blas_int* lda, void* b, blas_int* ldb, blas_int* sdim, void* alpha, void* beta, void* vsl, blas_int* ldvsl, void* vsr, blas_int* ldvsr, void* work, blas_int* lwork, double* rwork, double* bwork, blas_int* info); // 1-norm float arma_fortran(arma_slange)(char* norm, blas_int* m, blas_int* n, float* a, blas_int* lda, float* work); double arma_fortran(arma_dlange)(char* norm, blas_int* m, blas_int* n, double* a, blas_int* lda, double* work); float arma_fortran(arma_clange)(char* norm, blas_int* m, blas_int* n, void* a, blas_int* lda, float* work); double arma_fortran(arma_zlange)(char* norm, blas_int* m, blas_int* n, void* a, blas_int* lda, double* work); // reciprocal of condition number (real) void arma_fortran(arma_sgecon)(char* norm, blas_int* n, float* a, blas_int* lda, float* anorm, float* rcond, float* work, blas_int* iwork, blas_int* info); void arma_fortran(arma_dgecon)(char* norm, blas_int* n, double* a, blas_int* lda, double* anorm, double* rcond, double* work, blas_int* iwork, blas_int* info); // reciprocal of condition number (complex) void arma_fortran(arma_cgecon)(char* norm, blas_int* n, void* a, blas_int* lda, float* anorm, float* rcond, void* work, float* rwork, blas_int* info); void arma_fortran(arma_zgecon)(char* norm, blas_int* n, void* a, blas_int* lda, double* anorm, double* rcond, void* work, double* rwork, blas_int* info); // obtain parameters according to the local configuration of lapack blas_int arma_fortran(arma_ilaenv)(blas_int* ispec, char* name, char* opts, blas_int* n1, blas_int* n2, blas_int* n3, blas_int* n4); } #endif armadillo-6.500.5/include/armadillo_bits/op_vectorise_meat.hpp0000666000000000000000000001327012620272703023171 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_vectorise //! @{ template inline void op_vectorise_col::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); op_vectorise_col::apply_proxy(out, P); } template inline void op_vectorise_col::apply_proxy(Mat& out, const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; if(P.is_alias(out) == false) { const uword N = P.get_n_elem(); out.set_size(N, 1); if(is_Mat::stored_type>::value == true) { const unwrap::stored_type> tmp(P.Q); arrayops::copy(out.memptr(), tmp.M.memptr(), N); } else { eT* outmem = out.memptr(); if(Proxy::prefer_at_accessor == false) { // TODO: add handling of aligned access ? typename Proxy::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT tmp_i = A[i]; const eT tmp_j = A[j]; outmem[i] = tmp_i; outmem[j] = tmp_j; } if(i < N) { outmem[i] = A[i]; } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); if(n_rows == 1) { for(uword i=0; i < n_cols; ++i) { outmem[i] = P.at(0,i); } } else { for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { *outmem = P.at(row,col); outmem++; } } } } } else // we have aliasing { arma_extra_debug_print("op_vectorise_col::apply(): aliasing detected"); if( (is_Mat::stored_type>::value == true) && (Proxy::fake_mat == false) ) { out.set_size(out.n_elem, 1); // set_size() doesn't destroy data as long as the number of elements in the matrix remains the same } else { Mat tmp; op_vectorise_col::apply_proxy(tmp, P); out.steal_mem(tmp); } } } template inline void op_vectorise_row::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); op_vectorise_row::apply_proxy(out, P); } template inline void op_vectorise_row::apply_proxy(Mat& out, const Proxy& P) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; if(P.is_alias(out) == false) { out.set_size( 1, P.get_n_elem() ); eT* outmem = out.memptr(); const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); for(uword row=0; row < n_rows; ++row) { uword i,j; for(i=0, j=1; j < n_cols; i+=2, j+=2) { const eT tmp_i = P.at(row,i); const eT tmp_j = P.at(row,j); *outmem = tmp_i; outmem++; *outmem = tmp_j; outmem++; } if(i < n_cols) { *outmem = P.at(row,i); outmem++; } } } else // we have aliasing { arma_extra_debug_print("op_vectorise_row::apply(): aliasing detected"); Mat tmp; op_vectorise_row::apply_proxy(tmp, P); out.steal_mem(tmp); } } template inline void op_vectorise_all::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); const Proxy P(in.m); const uword dim = in.aux_uword_a; if(dim == 0) { op_vectorise_col::apply_proxy(out, P); } else { op_vectorise_row::apply_proxy(out, P); } } // template inline void op_vectorise_cube_col::apply(Mat& out, const BaseCube& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; ProxyCube P(in.get_ref()); const uword N = P.get_n_elem(); out.set_size(N, 1); if(is_Cube::stored_type>::value == true) { const unwrap_cube::stored_type> tmp(P.Q); arrayops::copy(out.memptr(), tmp.M.memptr(), N); } else { eT* outmem = out.memptr(); if(ProxyCube::prefer_at_accessor == false) { typename ProxyCube::ea_type A = P.get_ea(); uword i,j; for(i=0, j=1; j < N; i+=2, j+=2) { const eT tmp_i = A[i]; const eT tmp_j = A[j]; outmem[i] = tmp_i; outmem[j] = tmp_j; } if(i < N) { outmem[i] = A[i]; } } else { const uword n_rows = P.get_n_rows(); const uword n_cols = P.get_n_cols(); const uword n_slices = P.get_n_slices(); for(uword slice=0; slice < n_slices; ++slice) for(uword col=0; col < n_cols; ++col ) for(uword row=0; row < n_rows; ++row ) { *outmem = P.at(row,col,slice); outmem++; } } } } //! @} armadillo-6.500.5/include/armadillo_bits/diagview_meat.hpp0000666000000000000000000005030412622544541022272 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup diagview //! @{ template inline diagview::~diagview() { arma_extra_debug_sigprint(); } template arma_inline diagview::diagview(const Mat& in_m, const uword in_row_offset, const uword in_col_offset, const uword in_len) : m(in_m) , row_offset(in_row_offset) , col_offset(in_col_offset) , n_rows(in_len) , n_elem(in_len) { arma_extra_debug_sigprint(); } //! set a diagonal of our matrix using a diagonal from a foreign matrix template inline void diagview::operator= (const diagview& x) { arma_extra_debug_sigprint(); diagview& d = *this; arma_debug_check( (d.n_elem != x.n_elem), "diagview: diagonals have incompatible lengths"); Mat& d_m = const_cast< Mat& >(d.m); const Mat& x_m = x.m; if(&d_m != &x_m) { const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const uword x_row_offset = x.row_offset; const uword x_col_offset = x.col_offset; uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_m.at(ii + x_row_offset, ii + x_col_offset); const eT tmp_j = x_m.at(jj + x_row_offset, jj + x_col_offset); d_m.at(ii + d_row_offset, ii + d_col_offset) = tmp_i; d_m.at(jj + d_row_offset, jj + d_col_offset) = tmp_j; } if(ii < d_n_elem) { d_m.at(ii + d_row_offset, ii + d_col_offset) = x_m.at(ii + x_row_offset, ii + x_col_offset); } } else { const Mat tmp = x; (*this).operator=(tmp); } } template inline void diagview::operator+=(const eT val) { arma_extra_debug_sigprint(); Mat& t_m = const_cast< Mat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword ii=0; ii < t_n_elem; ++ii) { t_m.at( ii + t_row_offset, ii + t_col_offset) += val; } } template inline void diagview::operator-=(const eT val) { arma_extra_debug_sigprint(); Mat& t_m = const_cast< Mat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword ii=0; ii < t_n_elem; ++ii) { t_m.at( ii + t_row_offset, ii + t_col_offset) -= val; } } template inline void diagview::operator*=(const eT val) { arma_extra_debug_sigprint(); Mat& t_m = const_cast< Mat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword ii=0; ii < t_n_elem; ++ii) { t_m.at( ii + t_row_offset, ii + t_col_offset) *= val; } } template inline void diagview::operator/=(const eT val) { arma_extra_debug_sigprint(); Mat& t_m = const_cast< Mat& >(m); const uword t_n_elem = n_elem; const uword t_row_offset = row_offset; const uword t_col_offset = col_offset; for(uword ii=0; ii < t_n_elem; ++ii) { t_m.at( ii + t_row_offset, ii + t_col_offset) /= val; } } //! set a diagonal of our matrix using data from a foreign object template template inline void diagview::operator= (const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); if(is_alias) { arma_extra_debug_print("aliasing detected"); } if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) || (is_alias) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) = tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) = tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) = x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) = tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) = tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) = Pea[ii]; } } } template template inline void diagview::operator+=(const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); if(is_alias) { arma_extra_debug_print("aliasing detected"); } if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) || (is_alias) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) += tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) += tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) += x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) += tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) += tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) += Pea[ii]; } } } template template inline void diagview::operator-=(const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); if(is_alias) { arma_extra_debug_print("aliasing detected"); } if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) || (is_alias) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) -= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) -= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) -= x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) -= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) -= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) -= Pea[ii]; } } } template template inline void diagview::operator%=(const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); if(is_alias) { arma_extra_debug_print("aliasing detected"); } if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) || (is_alias) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) *= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) *= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) *= x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) *= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) *= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) *= Pea[ii]; } } } template template inline void diagview::operator/=(const Base& o) { arma_extra_debug_sigprint(); diagview& d = *this; Mat& d_m = const_cast< Mat& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); if(is_alias) { arma_extra_debug_print("aliasing detected"); } if( (is_Mat::stored_type>::value) || (Proxy::prefer_at_accessor) || (is_alias) ) { const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) /= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) /= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) /= x_mem[ii]; } } else { typename Proxy::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) /= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) /= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) /= Pea[ii]; } } } //! extract a diagonal and store it as a column vector template inline void diagview::extract(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; // size setting and alias checking is done by either the Mat contructor or operator=() const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] = tmp_i; out_mem[j] = tmp_j; } if(i < in_n_elem) { out_mem[i] = in_m.at( i + in_row_offset, i + in_col_offset ); } } //! X += Y.diag() template inline void diagview::plus_inplace(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "addition"); const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] += tmp_i; out_mem[j] += tmp_j; } if(i < in_n_elem) { out_mem[i] += in_m.at( i + in_row_offset, i + in_col_offset ); } } //! X -= Y.diag() template inline void diagview::minus_inplace(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "subtraction"); const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] -= tmp_i; out_mem[j] -= tmp_j; } if(i < in_n_elem) { out_mem[i] -= in_m.at( i + in_row_offset, i + in_col_offset ); } } //! X %= Y.diag() template inline void diagview::schur_inplace(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "element-wise multiplication"); const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] *= tmp_i; out_mem[j] *= tmp_j; } if(i < in_n_elem) { out_mem[i] *= in_m.at( i + in_row_offset, i + in_col_offset ); } } //! X /= Y.diag() template inline void diagview::div_inplace(Mat& out, const diagview& in) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols, "element-wise division"); const Mat& in_m = in.m; const uword in_n_elem = in.n_elem; const uword in_row_offset = in.row_offset; const uword in_col_offset = in.col_offset; eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j < in_n_elem; i+=2, j+=2) { const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); out_mem[i] /= tmp_i; out_mem[j] /= tmp_j; } if(i < in_n_elem) { out_mem[i] /= in_m.at( i + in_row_offset, i + in_col_offset ); } } template arma_inline eT diagview::at_alt(const uword ii) const { return m.at(ii+row_offset, ii+col_offset); } template arma_inline eT& diagview::operator[](const uword ii) { return (const_cast< Mat& >(m)).at(ii+row_offset, ii+col_offset); } template arma_inline eT diagview::operator[](const uword ii) const { return m.at(ii+row_offset, ii+col_offset); } template arma_inline eT& diagview::at(const uword ii) { return (const_cast< Mat& >(m)).at(ii+row_offset, ii+col_offset); } template arma_inline eT diagview::at(const uword ii) const { return m.at(ii+row_offset, ii+col_offset); } template arma_inline eT& diagview::operator()(const uword ii) { arma_debug_check( (ii >= n_elem), "diagview::operator(): out of bounds" ); return (const_cast< Mat& >(m)).at(ii+row_offset, ii+col_offset); } template arma_inline eT diagview::operator()(const uword ii) const { arma_debug_check( (ii >= n_elem), "diagview::operator(): out of bounds" ); return m.at(ii+row_offset, ii+col_offset); } template arma_inline eT& diagview::at(const uword row, const uword) { return (const_cast< Mat& >(m)).at(row+row_offset, row+col_offset); } template arma_inline eT diagview::at(const uword row, const uword) const { return m.at(row+row_offset, row+col_offset); } template arma_inline eT& diagview::operator()(const uword row, const uword col) { arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" ); return (const_cast< Mat& >(m)).at(row+row_offset, row+col_offset); } template arma_inline eT diagview::operator()(const uword row, const uword col) const { arma_debug_check( ((row >= n_elem) || (col > 0)), "diagview::operator(): out of bounds" ); return m.at(row+row_offset, row+col_offset); } template arma_inline const Op,op_htrans> diagview::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> diagview::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> diagview::st() const { return Op,op_strans>(*this); } template inline void diagview::fill(const eT val) { arma_extra_debug_sigprint(); Mat& x = const_cast< Mat& >(m); const uword local_n_elem = n_elem; for(uword ii=0; ii < local_n_elem; ++ii) { x.at(ii+row_offset, ii+col_offset) = val; } } template inline void diagview::zeros() { arma_extra_debug_sigprint(); (*this).fill(eT(0)); } template inline void diagview::ones() { arma_extra_debug_sigprint(); (*this).fill(eT(1)); } template inline void diagview::randu() { arma_extra_debug_sigprint(); Mat& x = const_cast< Mat& >(m); const uword local_n_elem = n_elem; for(uword ii=0; ii < local_n_elem; ++ii) { x.at(ii+row_offset, ii+col_offset) = eT(arma_rng::randu()); } } template inline void diagview::randn() { arma_extra_debug_sigprint(); Mat& x = const_cast< Mat& >(m); const uword local_n_elem = n_elem; for(uword ii=0; ii < local_n_elem; ++ii) { x.at(ii+row_offset, ii+col_offset) = eT(arma_rng::randn()); } } //! @} armadillo-6.500.5/include/armadillo_bits/injector_bones.hpp0000666000000000000000000000424012620272703022462 0ustar rootroot// Copyright (C) 2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup injector //! @{ template class mat_injector_row { public: inline mat_injector_row(); inline void insert(const eT val) const; mutable uword n_cols; mutable podarray A; mutable podarray B; }; template class mat_injector { public: typedef typename T1::elem_type elem_type; inline void insert(const elem_type val) const; inline void end_of_row() const; inline ~mat_injector(); private: inline mat_injector(T1& in_X, const elem_type val); inline mat_injector(T1& in_X, const injector_end_of_row<>& x); T1& X; mutable uword n_rows; mutable podarray< mat_injector_row* >* AA; mutable podarray< mat_injector_row* >* BB; friend class Mat; friend class Row; friend class Col; }; // template class field_injector_row { public: inline field_injector_row(); inline ~field_injector_row(); inline void insert(const oT& val) const; mutable uword n_cols; mutable field* AA; mutable field* BB; }; template class field_injector { public: typedef typename T1::object_type object_type; inline void insert(const object_type& val) const; inline void end_of_row() const; inline ~field_injector(); private: inline field_injector(T1& in_X, const object_type& val); inline field_injector(T1& in_X, const injector_end_of_row<>& x); T1& X; mutable uword n_rows; mutable podarray< field_injector_row* >* AA; mutable podarray< field_injector_row* >* BB; friend class field; }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_lu.hpp0000666000000000000000000000354312620272703020567 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_lu //! @{ //! immediate lower upper decomposition, permutation info is embedded into L (similar to Matlab/Octave) template inline bool lu ( Mat& L, Mat& U, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( (&L == &U), "lu(): L and U are the same object"); const bool status = auxlib::lu(L, U, X); if(status == false) { L.reset(); U.reset(); arma_debug_warn("lu(): decomposition failed"); } return status; } //! immediate lower upper decomposition, also providing the permutation matrix template inline bool lu ( Mat& L, Mat& U, Mat& P, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); arma_debug_check( ( (&L == &U) || (&L == &P) || (&U == &P) ), "lu(): two or more output objects are the same object"); const bool status = auxlib::lu(L, U, P, X); if(status == false) { L.reset(); U.reset(); P.reset(); arma_debug_warn("lu(): decomposition failed"); } return status; } //! @} armadillo-6.500.5/include/armadillo_bits/fn_log_det.hpp0000666000000000000000000000403112620272703021555 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_log_det //! @{ //! log determinant of mat template inline bool log_det ( typename T1::elem_type& out_val, typename T1::pod_type& out_sign, const Base& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); return auxlib::log_det(out_val, out_sign, X); } template inline void log_det ( typename T1::elem_type& out_val, typename T1::pod_type& out_sign, const Op& X, const typename arma_blas_type_only::result* junk = 0 ) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename T1::pod_type T; const diagmat_proxy A(X.m); arma_debug_check( (A.n_rows != A.n_cols), "log_det(): given matrix must be square sized" ); const uword N = (std::min)(A.n_rows, A.n_cols); if(N == 0) { out_val = eT(0); out_sign = T(1); return; } eT x = A[0]; T sign = (is_complex::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1; eT val = (is_complex::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x); for(uword i=1; i::value == false) ? ( (access::tmp_real(x) < T(0)) ? -1 : +1 ) : +1; val += (is_complex::value == false) ? std::log( (access::tmp_real(x) < T(0)) ? x*T(-1) : x ) : std::log(x); } out_val = val; out_sign = sign; } //! @} armadillo-6.500.5/include/armadillo_bits/Gen_bones.hpp0000666000000000000000000000355212620272703021363 0ustar rootroot// Copyright (C) 2011-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Gen //! @{ //! support class for generator functions (eg. zeros, randu, randn, ...) template class Gen : public Base > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; static const bool prefer_at_accessor = (is_same_type::value) ? true : false; static const bool is_simple = (is_same_type::value) || (is_same_type::value); static const bool is_row = T1::is_row; static const bool is_col = T1::is_col; arma_aligned const uword n_rows; arma_aligned const uword n_cols; arma_inline Gen(const uword in_n_rows, const uword in_n_cols); arma_inline ~Gen(); arma_inline static elem_type generate(); arma_inline elem_type operator[] (const uword ii) const; arma_inline elem_type at (const uword row, const uword col) const; arma_inline elem_type at_alt (const uword ii) const; inline void apply (Mat& out) const; inline void apply_inplace_plus (Mat& out) const; inline void apply_inplace_minus(Mat& out) const; inline void apply_inplace_schur(Mat& out) const; inline void apply_inplace_div (Mat& out) const; inline void apply(subview& out) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/def_blas.hpp0000666000000000000000000001167412620272703021227 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au #ifdef ARMA_USE_BLAS #if !defined(ARMA_BLAS_CAPITALS) #define arma_sasum sasum #define arma_dasum dasum #define arma_snrm2 snrm2 #define arma_dnrm2 dnrm2 #define arma_sdot sdot #define arma_ddot ddot #define arma_sgemv sgemv #define arma_dgemv dgemv #define arma_cgemv cgemv #define arma_zgemv zgemv #define arma_sgemm sgemm #define arma_dgemm dgemm #define arma_cgemm cgemm #define arma_zgemm zgemm #define arma_ssyrk ssyrk #define arma_dsyrk dsyrk #define arma_cherk cherk #define arma_zherk zherk #else #define arma_sasum SASUM #define arma_dasum DASUM #define arma_snrm2 SNRM2 #define arma_dnrm2 DNRM2 #define arma_sdot SDOT #define arma_ddot DDOT #define arma_sgemv SGEMV #define arma_dgemv DGEMV #define arma_cgemv CGEMV #define arma_zgemv ZGEMV #define arma_sgemm SGEMM #define arma_dgemm DGEMM #define arma_cgemm CGEMM #define arma_zgemm ZGEMM #define arma_ssyrk SSYRK #define arma_dsyrk DSYRK #define arma_cherk CHERK #define arma_zherk ZHERK #endif extern "C" { float arma_fortran(arma_sasum)(blas_int* n, const float* x, blas_int* incx); double arma_fortran(arma_dasum)(blas_int* n, const double* x, blas_int* incx); float arma_fortran(arma_snrm2)(blas_int* n, const float* x, blas_int* incx); double arma_fortran(arma_dnrm2)(blas_int* n, const double* x, blas_int* incx); float arma_fortran(arma_sdot)(blas_int* n, const float* x, blas_int* incx, const float* y, blas_int* incy); double arma_fortran(arma_ddot)(blas_int* n, const double* x, blas_int* incx, const double* y, blas_int* incy); void arma_fortran(arma_sgemv)(const char* transA, const blas_int* m, const blas_int* n, const float* alpha, const float* A, const blas_int* ldA, const float* x, const blas_int* incx, const float* beta, float* y, const blas_int* incy); void arma_fortran(arma_dgemv)(const char* transA, const blas_int* m, const blas_int* n, const double* alpha, const double* A, const blas_int* ldA, const double* x, const blas_int* incx, const double* beta, double* y, const blas_int* incy); void arma_fortran(arma_cgemv)(const char* transA, const blas_int* m, const blas_int* n, const void* alpha, const void* A, const blas_int* ldA, const void* x, const blas_int* incx, const void* beta, void* y, const blas_int* incy); void arma_fortran(arma_zgemv)(const char* transA, const blas_int* m, const blas_int* n, const void* alpha, const void* A, const blas_int* ldA, const void* x, const blas_int* incx, const void* beta, void* y, const blas_int* incy); void arma_fortran(arma_sgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const float* alpha, const float* A, const blas_int* ldA, const float* B, const blas_int* ldB, const float* beta, float* C, const blas_int* ldC); void arma_fortran(arma_dgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const double* alpha, const double* A, const blas_int* ldA, const double* B, const blas_int* ldB, const double* beta, double* C, const blas_int* ldC); void arma_fortran(arma_cgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const void* alpha, const void* A, const blas_int* ldA, const void* B, const blas_int* ldB, const void* beta, void* C, const blas_int* ldC); void arma_fortran(arma_zgemm)(const char* transA, const char* transB, const blas_int* m, const blas_int* n, const blas_int* k, const void* alpha, const void* A, const blas_int* ldA, const void* B, const blas_int* ldB, const void* beta, void* C, const blas_int* ldC); void arma_fortran(arma_ssyrk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const float* alpha, const float* A, const blas_int* ldA, const float* beta, float* C, const blas_int* ldC); void arma_fortran(arma_dsyrk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const double* alpha, const double* A, const blas_int* ldA, const double* beta, double* C, const blas_int* ldC); void arma_fortran(arma_cherk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const float* alpha, const void* A, const blas_int* ldA, const float* beta, void* C, const blas_int* ldC); void arma_fortran(arma_zherk)(const char* uplo, const char* transA, const blas_int* n, const blas_int* k, const double* alpha, const void* A, const blas_int* ldA, const double* beta, void* C, const blas_int* ldC); } #endif armadillo-6.500.5/include/armadillo_bits/op_strans_bones.hpp0000666000000000000000000000514112620272703022656 0ustar rootroot// Copyright (C) 2008-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_strans //! @{ //! 'matrix transpose' operation (simple transpose, ie. without taking the conjugate of the elements) class op_strans { public: template struct pos { static const uword n2 = (do_flip == false) ? (row + col*2) : (col + row*2); static const uword n3 = (do_flip == false) ? (row + col*3) : (col + row*3); static const uword n4 = (do_flip == false) ? (row + col*4) : (col + row*4); }; template arma_hot inline static void apply_mat_noalias_tinysq(Mat& out, const TA& A); template arma_hot inline static void apply_mat_noalias(Mat& out, const TA& A); template arma_hot inline static void apply_mat_inplace(Mat& out); template arma_hot inline static void apply_mat(Mat& out, const TA& A); template arma_hot inline static void apply_proxy(Mat& out, const T1& X); template arma_hot inline static void apply(Mat& out, const Op& in); }; class op_strans2 { public: template struct pos { static const uword n2 = (do_flip == false) ? (row + col*2) : (col + row*2); static const uword n3 = (do_flip == false) ? (row + col*3) : (col + row*3); static const uword n4 = (do_flip == false) ? (row + col*4) : (col + row*4); }; template arma_hot inline static void apply_noalias_tinysq(Mat& out, const TA& A, const eT val); template arma_hot inline static void apply_noalias(Mat& out, const TA& A, const eT val); template arma_hot inline static void apply(Mat& out, const TA& A, const eT val); template arma_hot inline static void apply_proxy(Mat& out, const T1& X, const typename T1::elem_type val); // NOTE: there is no direct handling of Op, as op_strans2::apply_proxy() is currently only called by op_htrans2 for non-complex numbers }; //! @} armadillo-6.500.5/include/armadillo_bits/op_symmat_bones.hpp0000666000000000000000000000137212620272703022660 0ustar rootroot// Copyright (C) 2011-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_symmat //! @{ class op_symmat { public: template inline static void apply(Mat& out, const Op& in); }; class op_symmat_cx { public: template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_all_bones.hpp0000666000000000000000000000301412620272703022111 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_all //! @{ class op_all { public: template static inline bool all_vec_helper(const Base& X); template static inline bool all_vec_helper ( const mtOp& X, const typename arma_op_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0 ); template static inline bool all_vec_helper ( const mtGlue& X, const typename arma_glue_rel_only::result junk1 = 0, const typename arma_not_cx::result junk2 = 0, const typename arma_not_cx::result junk3 = 0 ); template static inline bool all_vec(T1& X); template static inline void apply_helper(Mat& out, const Proxy& P, const uword dim); template static inline void apply(Mat& out, const mtOp& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/operator_cube_plus.hpp0000666000000000000000000001060112620272703023351 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup operator_cube_plus //! @{ //! unary plus operation (does nothing, but is required for completeness) template arma_inline const BaseCube& operator+ ( const BaseCube& X ) { arma_extra_debug_sigprint(); return X; } //! BaseCube + scalar template arma_inline const eOpCube operator+ ( const BaseCube& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! scalar + BaseCube template arma_inline const eOpCube operator+ ( const typename T1::elem_type k, const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! non-complex BaseCube + complex scalar (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_plus> operator+ ( const BaseCube& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_plus>('j', X.get_ref(), k); } //! complex scalar + non-complex BaseCube (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_plus> operator+ ( const std::complex& k, const BaseCube& X ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_plus>('j', X.get_ref(), k); // NOTE: order is swapped } //! addition of BaseCube objects with same element type template arma_inline const eGlueCube operator+ ( const BaseCube& X, const BaseCube& Y ) { arma_extra_debug_sigprint(); return eGlueCube(X.get_ref(), Y.get_ref()); } //! addition of BaseCube objects with different element types template inline const mtGlueCube::result, T1, T2, glue_mixed_plus> operator+ ( const BaseCube< typename force_different_type::T1_result, T1>& X, const BaseCube< typename force_different_type::T2_result, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template arma_inline Cube operator+ ( const subview_cube_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_cube_each1_aux::operator_plus(X, Y.get_ref()); } template arma_inline Cube operator+ ( const Base& X, const subview_cube_each1& Y ) { arma_extra_debug_sigprint(); return subview_cube_each1_aux::operator_plus(Y, X.get_ref()); // NOTE: swapped order } template arma_inline Cube operator+ ( const subview_cube_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_cube_each2_aux::operator_plus(X, Y.get_ref()); } template arma_inline Cube operator+ ( const Base& X, const subview_cube_each2& Y ) { arma_extra_debug_sigprint(); return subview_cube_each2_aux::operator_plus(Y, X.get_ref()); // NOTE: swapped order } //! @} armadillo-6.500.5/include/armadillo_bits/spop_sum_bones.hpp0000666000000000000000000000113512620272703022512 0ustar rootroot// Copyright (C) 2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup spop_sum //! @{ class spop_sum { public: template arma_hot inline static void apply(SpMat& out, const SpOp& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/arma_rng_cxx98.hpp0000666000000000000000000000635412620272703022320 0ustar rootroot// Copyright (C) 2013-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arma_rng_cxx98 //! @{ class arma_rng_cxx98 { public: typedef unsigned int seed_type; inline static void set_seed(const seed_type val); arma_inline static int randi_val(); arma_inline static double randu_val(); inline static double randn_val(); template inline static void randn_dual_val(eT& out1, eT& out2); template inline static void randi_fill(eT* mem, const uword N, const int a, const int b); inline static int randi_max_val(); }; inline void arma_rng_cxx98::set_seed(const arma_rng_cxx98::seed_type val) { std::srand(val); } arma_inline int arma_rng_cxx98::randi_val() { #if (RAND_MAX == 32767) { u32 val1 = u32(std::rand()); u32 val2 = u32(std::rand()); val1 <<= 15; return (val1 | val2); } #else { return std::rand(); } #endif } arma_inline double arma_rng_cxx98::randu_val() { return double( double(randi_val()) * ( double(1) / double(randi_max_val()) ) ); } inline double arma_rng_cxx98::randn_val() { // polar form of the Box-Muller transformation: // http://en.wikipedia.org/wiki/Box-Muller_transformation // http://en.wikipedia.org/wiki/Marsaglia_polar_method double tmp1; double tmp2; double w; do { tmp1 = double(2) * double(randi_val()) * (double(1) / double(randi_max_val())) - double(1); tmp2 = double(2) * double(randi_val()) * (double(1) / double(randi_max_val())) - double(1); w = tmp1*tmp1 + tmp2*tmp2; } while ( w >= double(1) ); return double( tmp1 * std::sqrt( (double(-2) * std::log(w)) / w) ); } template inline void arma_rng_cxx98::randn_dual_val(eT& out1, eT& out2) { // make sure we are internally using at least floats typedef typename promote_type::result eTp; eTp tmp1; eTp tmp2; eTp w; do { tmp1 = eTp(2) * eTp(randi_val()) * (eTp(1) / eTp(randi_max_val())) - eTp(1); tmp2 = eTp(2) * eTp(randi_val()) * (eTp(1) / eTp(randi_max_val())) - eTp(1); w = tmp1*tmp1 + tmp2*tmp2; } while ( w >= eTp(1) ); const eTp k = std::sqrt( (eTp(-2) * std::log(w)) / w); out1 = eT(tmp1*k); out2 = eT(tmp2*k); } template inline void arma_rng_cxx98::randi_fill(eT* mem, const uword N, const int a, const int b) { if( (a == 0) && (b == RAND_MAX) ) { for(uword i=0; i eOp::eOp(const T1& in_m) : P(in_m) { arma_extra_debug_sigprint(); } template eOp::eOp(const T1& in_m, const typename T1::elem_type in_aux) : P(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template eOp::eOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : P(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template eOp::eOp(const T1& in_m, const typename T1::elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b) : P(in_m) , aux(in_aux) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template eOp::~eOp() { arma_extra_debug_sigprint(); } template arma_inline uword eOp::get_n_rows() const { return is_row ? 1 : P.get_n_rows(); } template arma_inline uword eOp::get_n_cols() const { return is_col ? 1 : P.get_n_cols(); } template arma_inline uword eOp::get_n_elem() const { return P.get_n_elem(); } template arma_inline typename T1::elem_type eOp::operator[] (const uword ii) const { return eop_core::process(P[ii], aux); } template arma_inline typename T1::elem_type eOp::at(const uword row, const uword col) const { if(is_row) { return eop_core::process(P.at(0, col), aux); } else if(is_col) { return eop_core::process(P.at(row, 0), aux); } else { return eop_core::process(P.at(row, col), aux); } } template arma_inline typename T1::elem_type eOp::at_alt(const uword ii) const { return eop_core::process(P.at_alt(ii), aux); } //! @} armadillo-6.500.5/include/armadillo_bits/upgrade_val.hpp0000666000000000000000000001121612620272703021751 0ustar rootroot// Copyright (C) 2009-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup upgrade_val //! @{ //! upgrade_val is used to ensure an operation such as multiplication is possible between two types. //! values are upgraded only where necessary. template struct upgrade_val { typedef typename promote_type::result T1_result; typedef typename promote_type::result T2_result; arma_inline static typename promote_type::result apply(const T1 x) { typedef typename promote_type::result out_type; return out_type(x); } arma_inline static typename promote_type::result apply(const T2 x) { typedef typename promote_type::result out_type; return out_type(x); } }; // template<> template struct upgrade_val { typedef T T1_result; typedef T T2_result; arma_inline static const T& apply(const T& x) { return x; } }; //! upgrade a type to allow multiplication with a complex type //! e.g. the int in "int * complex" is upgraded to a double // template<> template struct upgrade_val< std::complex, T2 > { typedef std::complex T1_result; typedef T T2_result; arma_inline static const std::complex& apply(const std::complex& x) { return x; } arma_inline static T apply(const T2 x) { return T(x); } }; // template<> template struct upgrade_val< T1, std::complex > { typedef T T1_result; typedef std::complex T2_result; arma_inline static T apply(const T1 x) { return T(x); } arma_inline static const std::complex& apply(const std::complex& x) { return x; } }; //! ensure we don't lose precision when multiplying a complex number with a higher precision real number template<> struct upgrade_val< std::complex, double > { typedef std::complex T1_result; typedef double T2_result; arma_inline static const std::complex apply(const std::complex& x) { return std::complex(x); } arma_inline static double apply(const double x) { return x; } }; template<> struct upgrade_val< double, std::complex > { typedef double T1_result; typedef std::complex T2_result; arma_inline static double apply(const double x) { return x; } arma_inline static const std::complex apply(const std::complex& x) { return std::complex(x); } }; //! ensure we don't lose precision when multiplying complex numbers with different underlying types template<> struct upgrade_val< std::complex, std::complex > { typedef std::complex T1_result; typedef std::complex T2_result; arma_inline static const std::complex apply(const std::complex& x) { return std::complex(x); } arma_inline static const std::complex& apply(const std::complex& x) { return x; } }; template<> struct upgrade_val< std::complex, std::complex > { typedef std::complex T1_result; typedef std::complex T2_result; arma_inline static const std::complex& apply(const std::complex& x) { return x; } arma_inline static const std::complex apply(const std::complex& x) { return std::complex(x); } }; //! work around limitations in the complex class (at least as present in gcc 4.1 & 4.3) template<> struct upgrade_val< std::complex, float > { typedef std::complex T1_result; typedef double T2_result; arma_inline static const std::complex& apply(const std::complex& x) { return x; } arma_inline static double apply(const float x) { return double(x); } }; template<> struct upgrade_val< float, std::complex > { typedef double T1_result; typedef std::complex T2_result; arma_inline static double apply(const float x) { return double(x); } arma_inline static const std::complex& apply(const std::complex& x) { return x; } }; //! @} armadillo-6.500.5/include/armadillo_bits/SpOp_meat.hpp0000666000000000000000000000220312620272703021343 0ustar rootroot// Copyright (C) 2008-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup SpOp //! @{ template inline SpOp::SpOp(const T1& in_m) : m(in_m) { arma_extra_debug_sigprint(); } template inline SpOp::SpOp(const T1& in_m, const typename T1::elem_type in_aux) : m(in_m) , aux(in_aux) { arma_extra_debug_sigprint(); } template inline SpOp::SpOp(const T1& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b) : m(in_m) , aux_uword_a(in_aux_uword_a) , aux_uword_b(in_aux_uword_b) { arma_extra_debug_sigprint(); } template inline SpOp::~SpOp() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/Mat_meat.hpp0000666000000000000000000053441312650111756021223 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin //! \addtogroup Mat //! @{ template inline Mat::~Mat() { arma_extra_debug_sigprint_this(this); if( (mem_state == 0) && (n_elem > arma_config::mat_prealloc) ) { memory::release( access::rw(mem) ); } if(arma_config::debug == true) { // try to expose buggy user code that accesses deleted objects access::rw(mem) = 0; } arma_type_check(( is_supported_elem_type::value == false )); } template inline Mat::Mat() : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); } //! construct the matrix to have user specified dimensions template inline Mat::Mat(const uword in_n_rows, const uword in_n_cols) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows*in_n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); } template inline Mat::Mat(const SizeMat& s) : n_rows(s.n_rows) , n_cols(s.n_cols) , n_elem(s.n_rows*s.n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); } //! construct the matrix to have user specified dimensions and fill with specified pattern template template inline Mat::Mat(const uword in_n_rows, const uword in_n_cols, const fill::fill_class& f) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows*in_n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); (*this).fill(f); } template template inline Mat::Mat(const SizeMat& s, const fill::fill_class& f) : n_rows(s.n_rows) , n_cols(s.n_cols) , n_elem(s.n_rows*s.n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); (*this).fill(f); } //! constructor used by Row and Col classes template inline Mat::Mat(const arma_vec_indicator&, const uhword in_vec_state) : n_rows( (in_vec_state == 2) ? 1 : 0 ) , n_cols( (in_vec_state == 1) ? 1 : 0 ) , n_elem(0) , vec_state(in_vec_state) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); } //! constructor used by Row and Col classes template inline Mat::Mat(const arma_vec_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state) : n_rows(in_n_rows) , n_cols(in_n_cols) , n_elem(in_n_rows*in_n_cols) , vec_state(in_vec_state) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); } template inline Mat::Mat(const arma_fixed_indicator&, const uword in_n_rows, const uword in_n_cols, const uhword in_vec_state, const eT* in_mem) : n_rows (in_n_rows) , n_cols (in_n_cols) , n_elem (in_n_rows*in_n_cols) , vec_state (in_vec_state) , mem_state (3) , mem (in_mem) { arma_extra_debug_sigprint_this(this); } template inline void Mat::init_cold() { arma_extra_debug_sigprint( arma_str::format("n_rows = %d, n_cols = %d") % n_rows % n_cols ); // ensure that n_elem can hold the result of (n_rows * n_cols) #if (defined(ARMA_USE_CXX11) || defined(ARMA_64BIT_WORD)) const char* error_message = "Mat::init(): requested size is too large"; #else const char* error_message = "Mat::init(): requested size is too large; suggest to compile in C++11 mode or enable ARMA_64BIT_WORD"; #endif arma_debug_check ( ( ( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) ) ? ( (double(n_rows) * double(n_cols)) > double(ARMA_MAX_UWORD) ) : false ), error_message ); if(n_elem <= arma_config::mat_prealloc) { arma_extra_debug_print("Mat::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Mat::init(): acquiring memory"); access::rw(mem) = memory::acquire(n_elem); } } template inline void Mat::init_warm(uword in_n_rows, uword in_n_cols) { arma_extra_debug_sigprint( arma_str::format("in_n_rows = %d, in_n_cols = %d") % in_n_rows % in_n_cols ); if( (n_rows == in_n_rows) && (n_cols == in_n_cols) ) { return; } bool err_state = false; char* err_msg = 0; const uhword t_vec_state = vec_state; const uhword t_mem_state = mem_state; arma_debug_set_error( err_state, err_msg, (t_mem_state == 3), "Mat::init(): size is fixed and hence cannot be changed" ); if(t_vec_state > 0) { if( (in_n_rows == 0) && (in_n_cols == 0) ) { if(t_vec_state == 1) { in_n_cols = 1; } if(t_vec_state == 2) { in_n_rows = 1; } } else { if(t_vec_state == 1) { arma_debug_set_error( err_state, err_msg, (in_n_cols != 1), "Mat::init(): requested size is not compatible with column vector layout" ); } if(t_vec_state == 2) { arma_debug_set_error( err_state, err_msg, (in_n_rows != 1), "Mat::init(): requested size is not compatible with row vector layout" ); } } } // ensure that n_elem can hold the result of (n_rows * n_cols) #if (defined(ARMA_USE_CXX11) || defined(ARMA_64BIT_WORD)) const char* error_message = "Mat::init(): requested size is too large"; #else const char* error_message = "Mat::init(): requested size is too large; suggest to compile in C++11 mode or enable ARMA_64BIT_WORD"; #endif arma_debug_set_error ( err_state, err_msg, ( ( (in_n_rows > ARMA_MAX_UHWORD) || (in_n_cols > ARMA_MAX_UHWORD) ) ? ( (double(in_n_rows) * double(in_n_cols)) > double(ARMA_MAX_UWORD) ) : false ), error_message ); arma_debug_check(err_state, err_msg); const uword old_n_elem = n_elem; const uword new_n_elem = in_n_rows * in_n_cols; if(old_n_elem == new_n_elem) { arma_extra_debug_print("Mat::init(): reusing memory"); access::rw(n_rows) = in_n_rows; access::rw(n_cols) = in_n_cols; } else // condition: old_n_elem != new_n_elem { arma_debug_check( (t_mem_state == 2), "Mat::init(): mismatch between size of auxiliary memory and requested size" ); if(new_n_elem < old_n_elem) // reuse existing memory if possible { if( (t_mem_state == 0) && (new_n_elem <= arma_config::mat_prealloc) ) { if(old_n_elem > arma_config::mat_prealloc) { arma_extra_debug_print("Mat::init(): releasing memory"); memory::release( access::rw(mem) ); } arma_extra_debug_print("Mat::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Mat::init(): reusing memory"); } } else // condition: new_n_elem > old_n_elem { if( (t_mem_state == 0) && (old_n_elem > arma_config::mat_prealloc) ) { arma_extra_debug_print("Mat::init(): releasing memory"); memory::release( access::rw(mem) ); } if(new_n_elem <= arma_config::mat_prealloc) { arma_extra_debug_print("Mat::init(): using local memory"); access::rw(mem) = mem_local; } else { arma_extra_debug_print("Mat::init(): acquiring memory"); access::rw(mem) = memory::acquire(new_n_elem); } access::rw(mem_state) = 0; } access::rw(n_rows) = in_n_rows; access::rw(n_cols) = in_n_cols; access::rw(n_elem) = new_n_elem; } } //! create the matrix from a textual description template inline Mat::Mat(const char* text) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init( std::string(text) ); } //! create the matrix from a textual description template inline const Mat& Mat::operator=(const char* text) { arma_extra_debug_sigprint(); init( std::string(text) ); return *this; } //! create the matrix from a textual description template inline Mat::Mat(const std::string& text) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init(text); } //! create the matrix from a textual description template inline const Mat& Mat::operator=(const std::string& text) { arma_extra_debug_sigprint(); init(text); return *this; } //! internal function to create the matrix from a textual description template inline void Mat::init(const std::string& text_orig) { arma_extra_debug_sigprint(); const bool replace_commas = (is_cx::yes) ? false : ( text_orig.find(',') != std::string::npos ); std::string text_mod; if(replace_commas) { text_mod = text_orig; std::replace(text_mod.begin(), text_mod.end(), ',', ' '); } const std::string& text = (replace_commas) ? text_mod : text_orig; // // work out the size uword t_n_rows = 0; uword t_n_cols = 0; bool t_n_cols_found = false; std::string token; std::string::size_type line_start = 0; std::string::size_type line_end = 0; std::stringstream line_stream; while( line_start < text.length() ) { line_end = text.find(';', line_start); if(line_end == std::string::npos) { line_end = text.length()-1; } std::string::size_type line_len = line_end - line_start + 1; line_stream.clear(); line_stream.str( text.substr(line_start,line_len) ); uword line_n_cols = 0; while(line_stream >> token) { ++line_n_cols; } if(line_n_cols > 0) { if(t_n_cols_found == false) { t_n_cols = line_n_cols; t_n_cols_found = true; } else { arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent number of columns in given string"); } ++t_n_rows; } line_start = line_end+1; } Mat& x = *this; x.set_size(t_n_rows, t_n_cols); line_start = 0; line_end = 0; uword urow = 0; while( line_start < text.length() ) { line_end = text.find(';', line_start); if(line_end == std::string::npos) { line_end = text.length()-1; } std::string::size_type line_len = line_end - line_start + 1; line_stream.clear(); line_stream.str( text.substr(line_start,line_len) ); // uword ucol = 0; // while(line_stream >> token) // { // x.at(urow,ucol) = strtod(token.c_str(), 0); // ++ucol; // } uword ucol = 0; eT val; while(line_stream >> val) { x(urow,ucol) = val; ++ucol; } ++urow; line_start = line_end+1; } } //! create the matrix from std::vector template inline Mat::Mat(const std::vector& x) : n_rows(uword(x.size())) , n_cols(1) , n_elem(uword(x.size())) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); if(n_elem > 0) { arrayops::copy( memptr(), &(x[0]), n_elem ); } } //! create the matrix from std::vector template inline const Mat& Mat::operator=(const std::vector& x) { arma_extra_debug_sigprint(); init_warm(uword(x.size()), 1); if(x.size() > 0) { arrayops::copy( memptr(), &(x[0]), uword(x.size()) ); } return *this; } #if defined(ARMA_USE_CXX11) template inline Mat::Mat(const std::initializer_list& list) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init(list); } template inline const Mat& Mat::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); init(list); return *this; } template inline Mat::Mat(const std::initializer_list< std::initializer_list >& list) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init(list); } template inline const Mat& Mat::operator=(const std::initializer_list< std::initializer_list >& list) { arma_extra_debug_sigprint(); init(list); return *this; } template inline Mat::Mat(Mat&& X) : n_rows (X.n_rows) , n_cols (X.n_cols) , n_elem (X.n_elem) , vec_state(0 ) , mem_state(0 ) , mem ( ) { arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); if( ((X.mem_state == 0) && (X.n_elem > arma_config::mat_prealloc)) || (X.mem_state == 1) || (X.mem_state == 2) ) { access::rw(mem_state) = X.mem_state; access::rw(mem) = X.mem; access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem_state) = 0; access::rw(X.mem) = 0; } else { init_cold(); arrayops::copy( memptr(), X.mem, X.n_elem ); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) ) { access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } } } template inline const Mat& Mat::operator=(Mat&& X) { arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); (*this).steal_mem(X); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) && (this != &X) ) { access::rw(X.n_rows) = 0; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } return *this; } #endif //! Set the matrix to be equal to the specified scalar. //! NOTE: the size of the matrix will be 1x1 template arma_inline const Mat& Mat::operator=(const eT val) { arma_extra_debug_sigprint(); init_warm(1,1); access::rw(mem[0]) = val; return *this; } //! In-place addition of a scalar to all elements of the matrix template arma_inline const Mat& Mat::operator+=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_plus( memptr(), val, n_elem ); return *this; } //! In-place subtraction of a scalar from all elements of the matrix template arma_inline const Mat& Mat::operator-=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_minus( memptr(), val, n_elem ); return *this; } //! In-place multiplication of all elements of the matrix with a scalar template arma_inline const Mat& Mat::operator*=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_mul( memptr(), val, n_elem ); return *this; } //! In-place division of all elements of the matrix with a scalar template arma_inline const Mat& Mat::operator/=(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_div( memptr(), val, n_elem ); return *this; } //! construct a matrix from a given matrix template inline Mat::Mat(const Mat& in_mat) : n_rows(in_mat.n_rows) , n_cols(in_mat.n_cols) , n_elem(in_mat.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint(arma_str::format("this = %x in_mat = %x") % this % &in_mat); init_cold(); arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem ); } //! construct a matrix from a given matrix template inline const Mat& Mat::operator=(const Mat& in_mat) { arma_extra_debug_sigprint(arma_str::format("this = %x in_mat = %x") % this % &in_mat); if(this != &in_mat) { init_warm(in_mat.n_rows, in_mat.n_cols); arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem ); } return *this; } #if defined(ARMA_USE_CXX11) template inline void Mat::init(const std::initializer_list& list) { arma_extra_debug_sigprint(); const uword N = uword(list.size()); set_size(1, N); arrayops::copy( memptr(), list.begin(), N ); } template inline void Mat::init(const std::initializer_list< std::initializer_list >& list) { arma_extra_debug_sigprint(); uword x_n_rows = uword(list.size()); uword x_n_cols = 0; bool x_n_cols_found = false; auto it = list.begin(); auto it_end = list.end(); for(; it != it_end; ++it) { if(x_n_cols_found == false) { x_n_cols = uword((*it).size()); x_n_cols_found = true; } else { arma_check( (uword((*it).size()) != x_n_cols), "Mat::init(): inconsistent number of columns in initialiser list" ); } } Mat& t = (*this); if(t.mem_state == 3) { arma_debug_check( ((x_n_rows != t.n_rows) || (x_n_cols != t.n_cols)), "Mat::init(): size mismatch between fixed size matrix and initialiser list" ); } else { t.set_size(x_n_rows, x_n_cols); } uword row_num = 0; auto row_it = list.begin(); auto row_it_end = list.end(); for(; row_it != row_it_end; ++row_it) { uword col_num = 0; auto col_it = (*row_it).begin(); auto col_it_end = (*row_it).end(); for(; col_it != col_it_end; ++col_it) { t.at(row_num, col_num) = (*col_it); ++col_num; } ++row_num; } } #endif //! for constructing a complex matrix out of two non-complex matrices template template inline void Mat::init ( const Base::pod_type, T1>& X, const Base::pod_type, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type T; arma_type_check(( is_complex::value == false )); //!< compile-time abort if eT is not std::complex arma_type_check(( is_complex< T>::value == true )); //!< compile-time abort if T is std::complex arma_type_check(( is_same_type< std::complex, eT >::no )); //!< compile-time abort if types are not compatible const Proxy PX(X.get_ref()); const Proxy PY(Y.get_ref()); arma_debug_assert_same_size(PX, PY, "Mat()"); const uword local_n_rows = PX.get_n_rows(); const uword local_n_cols = PX.get_n_cols(); init_warm(local_n_rows, local_n_cols); eT* out_mem = (*this).memptr(); const bool prefer_at_accessor = ( Proxy::prefer_at_accessor || Proxy::prefer_at_accessor ); if(prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const uword N = n_elem; ea_type1 A = PX.get_ea(); ea_type2 B = PY.get_ea(); for(uword ii=0; ii < N; ++ii) { out_mem[ii] = std::complex(A[ii], B[ii]); } } else { for(uword ucol=0; ucol < local_n_cols; ++ucol) for(uword urow=0; urow < local_n_rows; ++urow) { *out_mem = std::complex(PX.at(urow,ucol), PY.at(urow,ucol)); out_mem++; } } } //! swap the contents of this matrix, denoted as matrix A, with given matrix B template inline void Mat::swap(Mat& B) { Mat& A = (*this); arma_extra_debug_sigprint(arma_str::format("A = %x B = %x") % &A % &B); bool layout_ok = false; if(A.vec_state == B.vec_state) { layout_ok = true; } else { const uhword A_vec_state = A.vec_state; const uhword B_vec_state = B.vec_state; const bool A_absorbs_B = (A_vec_state == 0) || ( (A_vec_state == 1) && (B.n_cols == 1) ) || ( (A_vec_state == 2) && (B.n_rows == 1) ); const bool B_absorbs_A = (B_vec_state == 0) || ( (B_vec_state == 1) && (A.n_cols == 1) ) || ( (B_vec_state == 2) && (A.n_rows == 1) ); layout_ok = A_absorbs_B && B_absorbs_A; } const uhword A_mem_state = A.mem_state; const uhword B_mem_state = B.mem_state; if( (A_mem_state == 0) && (B_mem_state == 0) && layout_ok ) { const uword A_n_elem = A.n_elem; const uword B_n_elem = B.n_elem; const bool A_use_local_mem = (A_n_elem <= arma_config::mat_prealloc); const bool B_use_local_mem = (B_n_elem <= arma_config::mat_prealloc); if( (A_use_local_mem == false) && (B_use_local_mem == false) ) { std::swap( access::rw(A.mem), access::rw(B.mem) ); } else if( (A_use_local_mem == true) && (B_use_local_mem == true) ) { eT* A_mem_local = &(A.mem_local[0]); eT* B_mem_local = &(B.mem_local[0]); access::rw(A.mem) = A_mem_local; access::rw(B.mem) = B_mem_local; const uword N = (std::max)(A_n_elem, B_n_elem); for(uword ii=0; ii < N; ++ii) { std::swap( A_mem_local[ii], B_mem_local[ii] ); } } else if( (A_use_local_mem == true) && (B_use_local_mem == false) ) { eT* A_mem_local = &(A.mem_local[0]); eT* B_mem_local = &(B.mem_local[0]); arrayops::copy(B_mem_local, A_mem_local, A_n_elem); access::rw(A.mem) = B.mem; access::rw(B.mem) = B_mem_local; } else if( (A_use_local_mem == false) && (B_use_local_mem == true) ) { eT* A_mem_local = &(A.mem_local[0]); eT* B_mem_local = &(B.mem_local[0]); arrayops::copy(A_mem_local, B_mem_local, B_n_elem); access::rw(B.mem) = A.mem; access::rw(A.mem) = A_mem_local; } std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); std::swap( access::rw(A.n_elem), access::rw(B.n_elem) ); } else if( (A_mem_state <= 2) && (B_mem_state <= 2) && (A.n_elem == B.n_elem) && layout_ok ) { std::swap( access::rw(A.n_rows), access::rw(B.n_rows) ); std::swap( access::rw(A.n_cols), access::rw(B.n_cols) ); const uword N = A.n_elem; eT* A_mem = A.memptr(); eT* B_mem = B.memptr(); for(uword ii=0; ii < N; ++ii) { std::swap(A_mem[ii], B_mem[ii]); } } else if( (A.n_rows == B.n_rows) && (A.n_cols == B.n_cols) ) { const uword N = A.n_elem; eT* A_mem = A.memptr(); eT* B_mem = B.memptr(); for(uword ii=0; ii < N; ++ii) { std::swap(A_mem[ii], B_mem[ii]); } } else { // generic swap to handle remaining cases if(A.n_elem <= B.n_elem) { Mat C = A; A.steal_mem(B); B.steal_mem(C); } else { Mat C = B; B.steal_mem(A); A.steal_mem(C); } } } //! try to steal the memory from a given matrix; //! if memory can't be stolen, copy the given matrix template inline void Mat::steal_mem(Mat& x) { arma_extra_debug_sigprint(); if(this == &x) { return; } const uword x_n_rows = x.n_rows; const uword x_n_cols = x.n_cols; const uword x_n_elem = x.n_elem; const uhword x_vec_state = x.vec_state; const uhword x_mem_state = x.mem_state; const uhword t_vec_state = vec_state; const uhword t_mem_state = mem_state; bool layout_ok = false; if(t_vec_state == x_vec_state) { layout_ok = true; } else { if( (t_vec_state == 1) && (x_n_cols == 1) ) { layout_ok = true; } if( (t_vec_state == 2) && (x_n_rows == 1) ) { layout_ok = true; } } if( (t_mem_state <= 1) && ( ((x_mem_state == 0) && (x_n_elem > arma_config::mat_prealloc)) || (x_mem_state == 1) ) && layout_ok ) { reset(); access::rw(n_rows) = x_n_rows; access::rw(n_cols) = x_n_cols; access::rw(n_elem) = x_n_elem; access::rw(mem_state) = x_mem_state; access::rw(mem) = x.mem; access::rw(x.n_rows) = 0; access::rw(x.n_cols) = 0; access::rw(x.n_elem) = 0; access::rw(x.mem_state) = 0; access::rw(x.mem) = 0; } else { (*this).operator=(x); } } template inline void Mat::steal_mem_col(Mat& x, const uword max_n_rows) { arma_extra_debug_sigprint(); const uword x_n_elem = x.n_elem; const uhword x_mem_state = x.mem_state; const uhword t_vec_state = vec_state; const uhword t_mem_state = mem_state; const uword alt_n_rows = (std::min)(x.n_rows, max_n_rows); if((x_n_elem == 0) || (alt_n_rows == 0)) { (*this).set_size(0,1); return; } if( (this != &x) && (t_vec_state <= 1) && (t_mem_state <= 1) && (x_mem_state <= 1) ) { if( (x_mem_state == 0) && ((x_n_elem <= arma_config::mat_prealloc) || (alt_n_rows <= arma_config::mat_prealloc)) ) { (*this).set_size(alt_n_rows, uword(1)); arrayops::copy( (*this).memptr(), x.memptr(), alt_n_rows ); } else { reset(); access::rw(n_rows) = alt_n_rows; access::rw(n_cols) = 1; access::rw(n_elem) = alt_n_rows; access::rw(mem_state) = x_mem_state; access::rw(mem) = x.mem; access::rw(x.n_rows) = 0; access::rw(x.n_cols) = 0; access::rw(x.n_elem) = 0; access::rw(x.mem_state) = 0; access::rw(x.mem) = 0; } } else { Mat tmp(alt_n_rows, 1); arrayops::copy( tmp.memptr(), x.memptr(), alt_n_rows ); steal_mem(tmp); } } //! construct a matrix from a given auxiliary array of eTs. //! if copy_aux_mem is true, new memory is allocated and the array is copied. //! if copy_aux_mem is false, the auxiliary array is used directly (without allocating memory and copying). //! the default is to copy the array. template inline Mat::Mat(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const bool copy_aux_mem, const bool strict) : n_rows ( aux_n_rows ) , n_cols ( aux_n_cols ) , n_elem ( aux_n_rows*aux_n_cols ) , vec_state( 0 ) , mem_state( copy_aux_mem ? 0 : ( strict ? 2 : 1 ) ) , mem ( copy_aux_mem ? 0 : aux_mem ) { arma_extra_debug_sigprint_this(this); if(copy_aux_mem == true) { init_cold(); arrayops::copy( memptr(), aux_mem, n_elem ); } } //! construct a matrix from a given auxiliary read-only array of eTs. //! the array is copied. template inline Mat::Mat(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols) : n_rows(aux_n_rows) , n_cols(aux_n_cols) , n_elem(aux_n_rows*aux_n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); arrayops::copy( memptr(), aux_mem, n_elem ); } //! DANGEROUS! Construct a temporary matrix, using auxiliary memory. //! This constructor is NOT intended for usage by user code. //! Its sole purpose is to be used by the Cube class. template inline Mat::Mat(const char junk, const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols) : n_rows (aux_n_rows ) , n_cols (aux_n_cols ) , n_elem (aux_n_rows*aux_n_cols) , vec_state(0 ) , mem_state(3 ) , mem (aux_mem ) { arma_extra_debug_sigprint_this(this); arma_ignore(junk); } //! in-place matrix addition template inline const Mat& Mat::operator+=(const Mat& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "addition"); arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); return *this; } //! in-place matrix subtraction template inline const Mat& Mat::operator-=(const Mat& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "subtraction"); arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); return *this; } //! in-place matrix multiplication template inline const Mat& Mat::operator*=(const Mat& m) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, m); return *this; } //! in-place element-wise matrix multiplication template inline const Mat& Mat::operator%=(const Mat& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "element-wise multiplication"); arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); return *this; } //! in-place element-wise matrix division template inline const Mat& Mat::operator/=(const Mat& m) { arma_extra_debug_sigprint(); arma_debug_assert_same_size(*this, m, "element-wise division"); arrayops::inplace_div( memptr(), m.memptr(), n_elem ); return *this; } template template inline Mat::Mat(const BaseCube& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); (*this).operator=(X); } template template inline const Mat& Mat::operator=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { out.set_size(in_n_rows, in_n_cols); for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::copy( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if(in_n_cols == 1) { out.set_size(in_n_rows, in_n_slices); for(uword i=0; i < in_n_slices; ++i) { arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if(in_n_rows == 1) { out.set_size(in_n_cols, in_n_slices); for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] = tmp_i; out_colptr[j] = tmp_j; } if(i < in_n_cols) { out_colptr[i] = in.at(0, i, slice); } } } } else { out.set_size(in_n_slices); eT* out_mem = out.memptr(); for(uword i=0; i template inline const Mat& Mat::operator+=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "addition", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::inplace_plus( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] += tmp_i; out_colptr[j] += tmp_j; } if(i < in_n_cols) { out_colptr[i] += in.at(0, i, slice); } } } } else { eT* out_mem = out.memptr(); for(uword i=0; i template inline const Mat& Mat::operator-=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "subtraction", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::inplace_minus( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] -= tmp_i; out_colptr[j] -= tmp_j; } if(i < in_n_cols) { out_colptr[i] -= in.at(0, i, slice); } } } } else { eT* out_mem = out.memptr(); for(uword i=0; i template inline const Mat& Mat::operator*=(const BaseCube& X) { arma_extra_debug_sigprint(); const Mat B(X); (*this).operator*=(B); return *this; } template template inline const Mat& Mat::operator%=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::inplace_mul( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] *= tmp_i; out_colptr[j] *= tmp_j; } if(i < in_n_cols) { out_colptr[i] *= in.at(0, i, slice); } } } } else { eT* out_mem = out.memptr(); for(uword i=0; i template inline const Mat& Mat::operator/=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat& out = *this; const unwrap_cube tmp(X.get_ref()); const Cube& in = tmp.M; arma_debug_assert_cube_as_mat(out, in, "element-wise division", true); const uword in_n_rows = in.n_rows; const uword in_n_cols = in.n_cols; const uword in_n_slices = in.n_slices; const uword out_n_rows = out.n_rows; const uword out_n_cols = out.n_cols; const uword out_vec_state = out.vec_state; if(in_n_slices == 1) { for(uword ucol=0; ucol < in_n_cols; ++ucol) { arrayops::inplace_div( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows ); } } else { if(out_vec_state == 0) { if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) { for(uword i=0; i < in_n_slices; ++i) { arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); } } else if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) { for(uword slice=0; slice < in_n_slices; ++slice) { eT* out_colptr = out.colptr(slice); uword i,j; for(i=0, j=1; j < in_n_cols; i+=2, j+=2) { const eT tmp_i = in.at(0, i, slice); const eT tmp_j = in.at(0, j, slice); out_colptr[i] /= tmp_i; out_colptr[j] /= tmp_j; } if(i < in_n_cols) { out_colptr[i] /= in.at(0, i, slice); } } } } else { eT* out_mem = out.memptr(); for(uword i=0; i template inline Mat::Mat ( const Base::pod_type,T1>& A, const Base::pod_type,T2>& B ) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init(A,B); } //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation) template inline Mat::Mat(const subview& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); subview::extract(*this, X); } //! construct a matrix from subview (e.g. construct a matrix from a delayed submatrix operation) template inline const Mat& Mat::operator=(const subview& X) { arma_extra_debug_sigprint(); const bool alias = (this == &(X.m)); if(alias == false) { init_warm(X.n_rows, X.n_cols); subview::extract(*this, X); } else { Mat tmp(X); steal_mem(tmp); } return *this; } //! in-place matrix addition (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator+=(const subview& X) { arma_extra_debug_sigprint(); subview::plus_inplace(*this, X); return *this; } //! in-place matrix subtraction (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator-=(const subview& X) { arma_extra_debug_sigprint(); subview::minus_inplace(*this, X); return *this; } //! in-place matrix mutiplication (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator*=(const subview& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, X); return *this; } //! in-place element-wise matrix mutiplication (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator%=(const subview& X) { arma_extra_debug_sigprint(); subview::schur_inplace(*this, X); return *this; } //! in-place element-wise matrix division (using a submatrix on the right-hand-side) template inline const Mat& Mat::operator/=(const subview& X) { arma_extra_debug_sigprint(); subview::div_inplace(*this, X); return *this; } template inline Mat::Mat(const subview_row_strans& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); X.extract(*this); } template inline Mat::Mat(const subview_row_htrans& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); X.extract(*this); } template inline Mat::Mat(const xvec_htrans& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); X.extract(*this); } template template inline Mat::Mat(const xtrans_mat& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); X.extract(*this); } //! construct a matrix from a subview_cube instance template inline Mat::Mat(const subview_cube& x) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); this->operator=(x); } //! construct a matrix from a subview_cube instance template inline const Mat& Mat::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::extract(*this, X); return *this; } //! in-place matrix addition (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator+=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::plus_inplace(*this, X); return *this; } //! in-place matrix subtraction (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator-=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::minus_inplace(*this, X); return *this; } //! in-place matrix mutiplication (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator*=(const subview_cube& X) { arma_extra_debug_sigprint(); const Mat tmp(X); glue_times::apply_inplace(*this, tmp); return *this; } //! in-place element-wise matrix mutiplication (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator%=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::schur_inplace(*this, X); return *this; } //! in-place element-wise matrix division (using a single-slice subcube on the right-hand-side) template inline const Mat& Mat::operator/=(const subview_cube& X) { arma_extra_debug_sigprint(); subview_cube::div_inplace(*this, X); return *this; } //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation) template inline Mat::Mat(const diagview& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); diagview::extract(*this, X); } //! construct a matrix from diagview (e.g. construct a matrix from a delayed diag operation) template inline const Mat& Mat::operator=(const diagview& X) { arma_extra_debug_sigprint(); const bool alias = (this == &(X.m)); if(alias == false) { init_warm(X.n_rows, X.n_cols); diagview::extract(*this, X); } else { Mat tmp(X); steal_mem(tmp); } return *this; } //! in-place matrix addition (using a diagview on the right-hand-side) template inline const Mat& Mat::operator+=(const diagview& X) { arma_extra_debug_sigprint(); diagview::plus_inplace(*this, X); return *this; } //! in-place matrix subtraction (using a diagview on the right-hand-side) template inline const Mat& Mat::operator-=(const diagview& X) { arma_extra_debug_sigprint(); diagview::minus_inplace(*this, X); return *this; } //! in-place matrix mutiplication (using a diagview on the right-hand-side) template inline const Mat& Mat::operator*=(const diagview& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, X); return *this; } //! in-place element-wise matrix mutiplication (using a diagview on the right-hand-side) template inline const Mat& Mat::operator%=(const diagview& X) { arma_extra_debug_sigprint(); diagview::schur_inplace(*this, X); return *this; } //! in-place element-wise matrix division (using a diagview on the right-hand-side) template inline const Mat& Mat::operator/=(const diagview& X) { arma_extra_debug_sigprint(); diagview::div_inplace(*this, X); return *this; } template inline Mat::Mat(const spdiagview& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(X.n_elem) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); init_cold(); spdiagview::extract(*this, X); } template inline const Mat& Mat::operator=(const spdiagview& X) { arma_extra_debug_sigprint(); init_warm(X.n_rows, X.n_cols); spdiagview::extract(*this, X); return *this; } template inline const Mat& Mat::operator+=(const spdiagview& X) { arma_extra_debug_sigprint(); const Mat tmp(X); (*this).operator+=(tmp); return *this; } template inline const Mat& Mat::operator-=(const spdiagview& X) { arma_extra_debug_sigprint(); const Mat tmp(X); (*this).operator-=(tmp); return *this; } template inline const Mat& Mat::operator*=(const spdiagview& X) { arma_extra_debug_sigprint(); const Mat tmp(X); (*this).operator*=(tmp); return *this; } template inline const Mat& Mat::operator%=(const spdiagview& X) { arma_extra_debug_sigprint(); const Mat tmp(X); (*this).operator%=(tmp); return *this; } template inline const Mat& Mat::operator/=(const spdiagview& X) { arma_extra_debug_sigprint(); const Mat tmp(X); (*this).operator/=(tmp); return *this; } template template inline Mat::Mat(const subview_elem1& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); this->operator=(X); } template template inline const Mat& Mat::operator=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::extract(*this, X); return *this; } template template inline const Mat& Mat::operator+=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::plus_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator-=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::minus_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator*=(const subview_elem1& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator%=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::schur_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator/=(const subview_elem1& X) { arma_extra_debug_sigprint(); subview_elem1::div_inplace(*this, X); return *this; } template template inline Mat::Mat(const subview_elem2& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); this->operator=(X); } template template inline const Mat& Mat::operator=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::extract(*this, X); return *this; } template template inline const Mat& Mat::operator+=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::plus_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator-=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::minus_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator*=(const subview_elem2& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator%=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::schur_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator/=(const subview_elem2& X) { arma_extra_debug_sigprint(); subview_elem2::div_inplace(*this, X); return *this; } template template inline Mat::Mat(const SpBase& m) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); const SpProxy p(m.get_ref()); access::rw(n_rows) = p.get_n_rows(); access::rw(n_cols) = p.get_n_cols(); access::rw(n_elem) = p.get_n_elem(); init_cold(); zeros(); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { at(it.row(), it.col()) = (*it); ++it; } } template template inline const Mat& Mat::operator=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); init_warm(p.get_n_rows(), p.get_n_cols()); zeros(); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { at(it.row(), it.col()) = (*it); ++it; } return *this; } template template inline const Mat& Mat::operator+=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "addition"); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { at(it.row(), it.col()) += (*it); ++it; } return *this; } template template inline const Mat& Mat::operator-=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "subtraction"); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); while(it != it_end) { at(it.row(), it.col()) -= (*it); ++it; } return *this; } template template inline const Mat& Mat::operator*=(const SpBase& m) { arma_extra_debug_sigprint(); Mat z = (*this) * m.get_ref(); steal_mem(z); return *this; } template template inline const Mat& Mat::operator%=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise multiplication"); typename SpProxy::const_iterator_type it = p.begin(); typename SpProxy::const_iterator_type it_end = p.end(); // We have to zero everything that isn't being used. arrayops::inplace_set(memptr(), eT(0), (it.col() * n_rows) + it.row()); while(it != it_end) { const uword cur_loc = (it.col() * n_rows) + it.row(); access::rw(mem[cur_loc]) *= (*it); ++it; const uword next_loc = (it == it_end) ? (p.get_n_cols() * n_rows) : (it.col() * n_rows) + it.row(); arrayops::inplace_set(memptr() + cur_loc + 1, eT(0), (next_loc - cur_loc - 1)); } return *this; } template template inline const Mat& Mat::operator/=(const SpBase& m) { arma_extra_debug_sigprint(); const SpProxy p(m.get_ref()); arma_debug_assert_same_size(n_rows, n_cols, p.get_n_rows(), p.get_n_cols(), "element-wise division"); // If you use this method, you are probably stupid or misguided, but for completeness it is implemented. // Unfortunately the best way to do this is loop over every element. for(uword c = 0; c < n_cols; ++c) for(uword r = 0; r < n_rows; ++r) { at(r, c) /= p.at(r, c); } return *this; } template inline mat_injector< Mat > Mat::operator<<(const eT val) { return mat_injector< Mat >(*this, val); } template inline mat_injector< Mat > Mat::operator<<(const injector_end_of_row<>& x) { return mat_injector< Mat >(*this, x); } //! creation of subview (row vector) template arma_inline subview_row Mat::row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "Mat::row(): index out of bounds" ); return subview_row(*this, row_num); } //! creation of subview (row vector) template arma_inline const subview_row Mat::row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "Mat::row(): index out of bounds" ); return subview_row(*this, row_num); } template inline subview_row Mat::operator()(const uword row_num, const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::operator(): indices out of bounds or incorrectly used" ); return subview_row(*this, row_num, in_col1, submat_n_cols); } template inline const subview_row Mat::operator()(const uword row_num, const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( (row_num >= n_rows) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::operator(): indices out of bounds or incorrectly used" ); return subview_row(*this, row_num, in_col1, submat_n_cols); } //! creation of subview (column vector) template arma_inline subview_col Mat::col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::col(): index out of bounds"); return subview_col(*this, col_num); } //! creation of subview (column vector) template arma_inline const subview_col Mat::col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::col(): index out of bounds"); return subview_col(*this, col_num); } template inline subview_col Mat::operator()(const span& row_span, const uword col_num) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "Mat::operator(): indices out of bounds or incorrectly used" ); return subview_col(*this, col_num, in_row1, submat_n_rows); } template inline const subview_col Mat::operator()(const span& row_span, const uword col_num) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( (col_num >= n_cols) || ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "Mat::operator(): indices out of bounds or incorrectly used" ); return subview_col(*this, col_num, in_row1, submat_n_rows); } //! create a Col object which uses memory from an existing matrix object. //! this approach is currently not alias safe //! and does not take into account that the parent matrix object could be deleted. //! if deleted memory is accessed by the created Col object, //! it will cause memory corruption and/or a crash template inline Col Mat::unsafe_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): index out of bounds"); return Col(colptr(col_num), n_rows, false, true); } //! create a Col object which uses memory from an existing matrix object. //! this approach is currently not alias safe //! and does not take into account that the parent matrix object could be deleted. //! if deleted memory is accessed by the created Col object, //! it will cause memory corruption and/or a crash template inline const Col Mat::unsafe_col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): index out of bounds"); typedef const Col out_type; return out_type(const_cast(colptr(col_num)), n_rows, false, true); } //! creation of subview (submatrix comprised of specified row vectors) template arma_inline subview Mat::rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "Mat::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview(*this, in_row1, 0, subview_n_rows, n_cols ); } //! creation of subview (submatrix comprised of specified row vectors) template arma_inline const subview Mat::rows(const uword in_row1, const uword in_row2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "Mat::rows(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; return subview(*this, in_row1, 0, subview_n_rows, n_cols ); } //! creation of subview (submatrix comprised of specified column vectors) template arma_inline subview Mat::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "Mat::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview(*this, 0, in_col1, n_rows, subview_n_cols); } //! creation of subview (submatrix comprised of specified column vectors) template arma_inline const subview Mat::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "Mat::cols(): indices out of bounds or incorrectly used" ); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview(*this, 0, in_col1, n_rows, subview_n_cols); } //! creation of subview (submatrix comprised of specified row vectors) template inline subview Mat::rows(const span& row_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "Mat::rows(): indices out of bounds or incorrectly used" ); return subview(*this, in_row1, 0, submat_n_rows, n_cols); } //! creation of subview (submatrix comprised of specified row vectors) template inline const subview Mat::rows(const span& row_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const uword local_n_rows = n_rows; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) , "Mat::rows(): indices out of bounds or incorrectly used" ); return subview(*this, in_row1, 0, submat_n_rows, n_cols); } //! creation of subview (submatrix comprised of specified column vectors) template arma_inline subview Mat::cols(const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::cols(): indices out of bounds or incorrectly used" ); return subview(*this, 0, in_col1, n_rows, submat_n_cols); } //! creation of subview (submatrix comprised of specified column vectors) template arma_inline const subview Mat::cols(const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::cols(): indices out of bounds or incorrectly used" ); return subview(*this, 0, in_col1, n_rows, submat_n_cols); } //! creation of subview (submatrix) template arma_inline subview Mat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "Mat::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; return subview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); } //! creation of subview (generic submatrix) template arma_inline const subview Mat::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), "Mat::submat(): indices out of bounds or incorrectly used" ); const uword subview_n_rows = in_row2 - in_row1 + 1; const uword subview_n_cols = in_col2 - in_col1 + 1; return subview(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); } //! creation of subview (submatrix) template arma_inline subview Mat::submat(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "Mat::submat(): indices or size out of bounds" ); return subview(*this, in_row1, in_col1, s_n_rows, s_n_cols); } //! creation of subview (submatrix) template arma_inline const subview Mat::submat(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; arma_debug_check ( ((in_row1 >= l_n_rows) || (in_col1 >= l_n_cols) || ((in_row1 + s_n_rows) > l_n_rows) || ((in_col1 + s_n_cols) > l_n_cols)), "Mat::submat(): indices or size out of bounds" ); return subview(*this, in_row1, in_col1, s_n_rows, s_n_cols); } //! creation of subview (submatrix) template inline subview Mat::submat(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::submat(): indices out of bounds or incorrectly used" ); return subview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); } //! creation of subview (generic submatrix) template inline const subview Mat::submat(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const bool row_all = row_span.whole; const bool col_all = col_span.whole; const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; const uword in_row1 = row_all ? 0 : row_span.a; const uword in_row2 = row_span.b; const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check ( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) || ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) , "Mat::submat(): indices out of bounds or incorrectly used" ); return subview(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); } template inline subview Mat::operator()(const span& row_span, const span& col_span) { arma_extra_debug_sigprint(); return (*this).submat(row_span, col_span); } template inline const subview Mat::operator()(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); return (*this).submat(row_span, col_span); } template inline subview Mat::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).submat(in_row1, in_col1, s); } template inline const subview Mat::operator()(const uword in_row1, const uword in_col1, const SizeMat& s) const { arma_extra_debug_sigprint(); return (*this).submat(in_row1, in_col1, s); } template inline subview Mat::head_rows(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > n_rows), "Mat::head_rows(): size out of bounds"); return subview(*this, 0, 0, N, n_cols); } template inline const subview Mat::head_rows(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > n_rows), "Mat::head_rows(): size out of bounds"); return subview(*this, 0, 0, N, n_cols); } template inline subview Mat::tail_rows(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > n_rows), "Mat::tail_rows(): size out of bounds"); const uword start_row = n_rows - N; return subview(*this, start_row, 0, N, n_cols); } template inline const subview Mat::tail_rows(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > n_rows), "Mat::tail_rows(): size out of bounds"); const uword start_row = n_rows - N; return subview(*this, start_row, 0, N, n_cols); } template inline subview Mat::head_cols(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > n_cols), "Mat::head_cols(): size out of bounds"); return subview(*this, 0, 0, n_rows, N); } template inline const subview Mat::head_cols(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > n_cols), "Mat::head_cols(): size out of bounds"); return subview(*this, 0, 0, n_rows, N); } template inline subview Mat::tail_cols(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > n_cols), "Mat::tail_cols(): size out of bounds"); const uword start_col = n_cols - N; return subview(*this, 0, start_col, n_rows, N); } template inline const subview Mat::tail_cols(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > n_cols), "Mat::tail_cols(): size out of bounds"); const uword start_col = n_cols - N; return subview(*this, 0, start_col, n_rows, N); } template template arma_inline subview_elem1 Mat::elem(const Base& a) { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline const subview_elem1 Mat::elem(const Base& a) const { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline subview_elem1 Mat::operator()(const Base& a) { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline const subview_elem1 Mat::operator()(const Base& a) const { arma_extra_debug_sigprint(); return subview_elem1(*this, a); } template template arma_inline subview_elem2 Mat::elem(const Base& ri, const Base& ci) { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline const subview_elem2 Mat::elem(const Base& ri, const Base& ci) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline subview_elem2 Mat::submat(const Base& ri, const Base& ci) { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline const subview_elem2 Mat::submat(const Base& ri, const Base& ci) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline subview_elem2 Mat::operator()(const Base& ri, const Base& ci) { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline const subview_elem2 Mat::operator()(const Base& ri, const Base& ci) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ci, false, false); } template template arma_inline subview_elem2 Mat::rows(const Base& ri) { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ri, false, true); } template template arma_inline const subview_elem2 Mat::rows(const Base& ri) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ri, ri, false, true); } template template arma_inline subview_elem2 Mat::cols(const Base& ci) { arma_extra_debug_sigprint(); return subview_elem2(*this, ci, ci, true, false); } template template arma_inline const subview_elem2 Mat::cols(const Base& ci) const { arma_extra_debug_sigprint(); return subview_elem2(*this, ci, ci, true, false); } template arma_inline subview_each1< Mat, 0 > Mat::each_col() { arma_extra_debug_sigprint(); return subview_each1< Mat, 0>(*this); } template arma_inline subview_each1< Mat, 1 > Mat::each_row() { arma_extra_debug_sigprint(); return subview_each1< Mat, 1>(*this); } template arma_inline const subview_each1< Mat, 0 > Mat::each_col() const { arma_extra_debug_sigprint(); return subview_each1< Mat, 0>(*this); } template arma_inline const subview_each1< Mat, 1 > Mat::each_row() const { arma_extra_debug_sigprint(); return subview_each1< Mat, 1>(*this); } template template inline subview_each2< Mat, 0, T1 > Mat::each_col(const Base& indices) { arma_extra_debug_sigprint(); return subview_each2< Mat, 0, T1 >(*this, indices); } template template inline subview_each2< Mat, 1, T1 > Mat::each_row(const Base& indices) { arma_extra_debug_sigprint(); return subview_each2< Mat, 1, T1 >(*this, indices); } template template inline const subview_each2< Mat, 0, T1 > Mat::each_col(const Base& indices) const { arma_extra_debug_sigprint(); return subview_each2< Mat, 0, T1 >(*this, indices); } template template inline const subview_each2< Mat, 1, T1 > Mat::each_row(const Base& indices) const { arma_extra_debug_sigprint(); return subview_each2< Mat, 1, T1 >(*this, indices); } #if defined(ARMA_USE_CXX11) //! apply a lambda function to each column, where each column is interpreted as a column vector template inline const Mat& Mat::each_col(const std::function< void(Col&) >& F) { arma_extra_debug_sigprint(); for(uword ii=0; ii < n_cols; ++ii) { Col tmp(colptr(ii), n_rows, false, true); F(tmp); } return *this; } template inline const Mat& Mat::each_col(const std::function< void(const Col&) >& F) const { arma_extra_debug_sigprint(); for(uword ii=0; ii < n_cols; ++ii) { const Col tmp(colptr(ii), n_rows, false, true); F(tmp); } return *this; } //! apply a lambda function to each row, where each row is interpreted as a row vector template inline const Mat& Mat::each_row(const std::function< void(Row&) >& F) { arma_extra_debug_sigprint(); podarray array1(n_cols); podarray array2(n_cols); Row tmp1( array1.memptr(), n_cols, false, true ); Row tmp2( array2.memptr(), n_cols, false, true ); eT* tmp1_mem = tmp1.memptr(); eT* tmp2_mem = tmp2.memptr(); uword ii, jj; for(ii=0, jj=1; jj < n_rows; ii+=2, jj+=2) { for(uword col_id = 0; col_id < n_cols; ++col_id) { const eT* col_mem = colptr(col_id); tmp1_mem[col_id] = col_mem[ii]; tmp2_mem[col_id] = col_mem[jj]; } F(tmp1); F(tmp2); for(uword col_id = 0; col_id < n_cols; ++col_id) { eT* col_mem = colptr(col_id); col_mem[ii] = tmp1_mem[col_id]; col_mem[jj] = tmp2_mem[col_id]; } } if(ii < n_rows) { tmp1 = (*this).row(ii); F(tmp1); (*this).row(ii) = tmp1; } return *this; } template inline const Mat& Mat::each_row(const std::function< void(const Row&) >& F) const { arma_extra_debug_sigprint(); podarray array1(n_cols); podarray array2(n_cols); Row tmp1( array1.memptr(), n_cols, false, true ); Row tmp2( array2.memptr(), n_cols, false, true ); eT* tmp1_mem = tmp1.memptr(); eT* tmp2_mem = tmp2.memptr(); uword ii, jj; for(ii=0, jj=1; jj < n_rows; ii+=2, jj+=2) { for(uword col_id = 0; col_id < n_cols; ++col_id) { const eT* col_mem = colptr(col_id); tmp1_mem[col_id] = col_mem[ii]; tmp2_mem[col_id] = col_mem[jj]; } F(tmp1); F(tmp2); } if(ii < n_rows) { tmp1 = (*this).row(ii); F(tmp1); } return *this; } #endif //! creation of diagview (diagonal) template arma_inline diagview Mat::diag(const sword in_id) { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? uword(-in_id) : 0; const uword col_offset = (in_id > 0) ? uword( in_id) : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "Mat::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); return diagview(*this, row_offset, col_offset, len); } //! creation of diagview (diagonal) template arma_inline const diagview Mat::diag(const sword in_id) const { arma_extra_debug_sigprint(); const uword row_offset = (in_id < 0) ? -in_id : 0; const uword col_offset = (in_id > 0) ? in_id : 0; arma_debug_check ( ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), "Mat::diag(): requested diagonal out of bounds" ); const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); return diagview(*this, row_offset, col_offset, len); } template inline void Mat::swap_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; arma_debug_check ( (in_row1 >= local_n_rows) || (in_row2 >= local_n_rows), "Mat::swap_rows(): index out of bounds" ); if(n_elem > 0) { for(uword ucol=0; ucol < local_n_cols; ++ucol) { const uword offset = ucol * local_n_rows; const uword pos1 = in_row1 + offset; const uword pos2 = in_row2 + offset; std::swap( access::rw(mem[pos1]), access::rw(mem[pos2]) ); } } } template inline void Mat::swap_cols(const uword in_colA, const uword in_colB) { arma_extra_debug_sigprint(); const uword local_n_rows = n_rows; const uword local_n_cols = n_cols; arma_debug_check ( (in_colA >= local_n_cols) || (in_colB >= local_n_cols), "Mat::swap_cols(): index out of bounds" ); if(n_elem > 0) { eT* ptrA = colptr(in_colA); eT* ptrB = colptr(in_colB); eT tmp_i; eT tmp_j; uword iq,jq; for(iq=0, jq=1; jq < local_n_rows; iq+=2, jq+=2) { tmp_i = ptrA[iq]; tmp_j = ptrA[jq]; ptrA[iq] = ptrB[iq]; ptrA[jq] = ptrB[jq]; ptrB[iq] = tmp_i; ptrB[jq] = tmp_j; } if(iq < local_n_rows) { std::swap( ptrA[iq], ptrB[iq] ); } } } //! remove specified row template inline void Mat::shed_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( row_num >= n_rows, "Mat::shed_row(): index out of bounds"); shed_rows(row_num, row_num); } //! remove specified column template inline void Mat::shed_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= n_cols, "Mat::shed_col(): index out of bounds"); shed_cols(col_num, col_num); } //! remove specified rows template inline void Mat::shed_rows(const uword in_row1, const uword in_row2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_row1 > in_row2) || (in_row2 >= n_rows), "Mat::shed_rows(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_row1; const uword n_keep_back = n_rows - (in_row2 + 1); Mat X(n_keep_front + n_keep_back, n_cols); if(n_keep_front > 0) { X.rows( 0, (n_keep_front-1) ) = rows( 0, (in_row1-1) ); } if(n_keep_back > 0) { X.rows( n_keep_front, (n_keep_front+n_keep_back-1) ) = rows( (in_row2+1), (n_rows-1) ); } steal_mem(X); } //! remove specified columns template inline void Mat::shed_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= n_cols), "Mat::shed_cols(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_col1; const uword n_keep_back = n_cols - (in_col2 + 1); Mat X(n_rows, n_keep_front + n_keep_back); if(n_keep_front > 0) { X.cols( 0, (n_keep_front-1) ) = cols( 0, (in_col1-1) ); } if(n_keep_back > 0) { X.cols( n_keep_front, (n_keep_front+n_keep_back-1) ) = cols( (in_col2+1), (n_cols-1) ); } steal_mem(X); } //! insert N rows at the specified row position, //! optionally setting the elements of the inserted rows to zero template inline void Mat::insert_rows(const uword row_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_rows = n_rows; const uword t_n_cols = n_cols; const uword A_n_rows = row_num; const uword B_n_rows = t_n_rows - row_num; // insertion at row_num == n_rows is in effect an append operation arma_debug_check( (row_num > t_n_rows), "Mat::insert_rows(): index out of bounds"); if(N > 0) { Mat out(t_n_rows + N, t_n_cols); if(A_n_rows > 0) { out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); } if(B_n_rows > 0) { out.rows(row_num + N, t_n_rows + N - 1) = rows(row_num, t_n_rows-1); } if(set_to_zero == true) { out.rows(row_num, row_num + N - 1).zeros(); } steal_mem(out); } } //! insert N columns at the specified column position, //! optionally setting the elements of the inserted columns to zero template inline void Mat::insert_cols(const uword col_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_rows = n_rows; const uword t_n_cols = n_cols; const uword A_n_cols = col_num; const uword B_n_cols = t_n_cols - col_num; // insertion at col_num == n_cols is in effect an append operation arma_debug_check( (col_num > t_n_cols), "Mat::insert_cols(): index out of bounds"); if(N > 0) { Mat out(t_n_rows, t_n_cols + N); if(A_n_cols > 0) { out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); } if(B_n_cols > 0) { out.cols(col_num + N, t_n_cols + N - 1) = cols(col_num, t_n_cols-1); } if(set_to_zero == true) { out.cols(col_num, col_num + N - 1).zeros(); } steal_mem(out); } } //! insert the given object at the specified row position; //! the given object must have the same number of columns as the matrix template template inline void Mat::insert_rows(const uword row_num, const Base& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); const Mat& C = tmp.M; const uword C_n_rows = C.n_rows; const uword C_n_cols = C.n_cols; const uword t_n_rows = n_rows; const uword t_n_cols = n_cols; const uword A_n_rows = row_num; const uword B_n_rows = t_n_rows - row_num; bool err_state = false; char* err_msg = 0; // insertion at row_num == n_rows is in effect an append operation arma_debug_set_error ( err_state, err_msg, (row_num > t_n_rows), "Mat::insert_rows(): index out of bounds" ); arma_debug_set_error ( err_state, err_msg, ( (C_n_cols != t_n_cols) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ), "Mat::insert_rows(): given object has an incompatible number of columns" ); arma_debug_check(err_state, err_msg); if(C_n_rows > 0) { Mat out( t_n_rows + C_n_rows, (std::max)(t_n_cols, C_n_cols) ); if(t_n_cols > 0) { if(A_n_rows > 0) { out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); } if( (t_n_cols > 0) && (B_n_rows > 0) ) { out.rows(row_num + C_n_rows, t_n_rows + C_n_rows - 1) = rows(row_num, t_n_rows - 1); } } if(C_n_cols > 0) { out.rows(row_num, row_num + C_n_rows - 1) = C; } steal_mem(out); } } //! insert the given object at the specified column position; //! the given object must have the same number of rows as the matrix template template inline void Mat::insert_cols(const uword col_num, const Base& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); const Mat& C = tmp.M; const uword C_n_rows = C.n_rows; const uword C_n_cols = C.n_cols; const uword t_n_rows = n_rows; const uword t_n_cols = n_cols; const uword A_n_cols = col_num; const uword B_n_cols = t_n_cols - col_num; bool err_state = false; char* err_msg = 0; // insertion at col_num == n_cols is in effect an append operation arma_debug_set_error ( err_state, err_msg, (col_num > t_n_cols), "Mat::insert_cols(): index out of bounds" ); arma_debug_set_error ( err_state, err_msg, ( (C_n_rows != t_n_rows) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ), "Mat::insert_cols(): given object has an incompatible number of rows" ); arma_debug_check(err_state, err_msg); if(C_n_cols > 0) { Mat out( (std::max)(t_n_rows, C_n_rows), t_n_cols + C_n_cols ); if(t_n_rows > 0) { if(A_n_cols > 0) { out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); } if(B_n_cols > 0) { out.cols(col_num + C_n_cols, t_n_cols + C_n_cols - 1) = cols(col_num, t_n_cols - 1); } } if(C_n_rows > 0) { out.cols(col_num, col_num + C_n_cols - 1) = C; } steal_mem(out); } } template template inline Mat::Mat(const Gen& X) : n_rows(X.n_rows) , n_cols(X.n_cols) , n_elem(n_rows*n_cols) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); init_cold(); X.apply(*this); } template template inline const Mat& Mat::operator=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); init_warm(X.n_rows, X.n_cols); X.apply(*this); return *this; } template template inline const Mat& Mat::operator+=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); X.apply_inplace_plus(*this); return *this; } template template inline const Mat& Mat::operator-=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); X.apply_inplace_minus(*this); return *this; } template template inline const Mat& Mat::operator*=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat tmp(X); return (*this).operator*=(tmp); } template template inline const Mat& Mat::operator%=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); X.apply_inplace_schur(*this); return *this; } template template inline const Mat& Mat::operator/=(const Gen& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); X.apply_inplace_div(*this); return *this; } //! create a matrix from Op, i.e. run the previously delayed unary operations template template inline Mat::Mat(const Op& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); op_type::apply(*this, X); } //! create a matrix from Op, i.e. run the previously delayed unary operations template template inline const Mat& Mat::operator=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); op_type::apply(*this, X); return *this; } //! in-place matrix addition, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator+=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat m(X); return (*this).operator+=(m); } //! in-place matrix subtraction, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator-=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat m(X); return (*this).operator-=(m); } //! in-place matrix multiplication, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator*=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); glue_times::apply_inplace(*this, X); return *this; } //! in-place matrix element-wise multiplication, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator%=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat m(X); return (*this).operator%=(m); } //! in-place matrix element-wise division, with the right-hand-side operand having delayed operations template template inline const Mat& Mat::operator/=(const Op& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const Mat m(X); return (*this).operator/=(m); } //! create a matrix from eOp, i.e. run the previously delayed unary operations template template inline Mat::Mat(const eOp& X) : n_rows(X.get_n_rows()) , n_cols(X.get_n_cols()) , n_elem(X.get_n_elem()) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); init_cold(); eop_type::apply(*this, X); } //! create a matrix from eOp, i.e. run the previously delayed unary operations template template inline const Mat& Mat::operator=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const bool bad_alias = (eOp::proxy_type::has_subview && X.P.is_alias(*this)); if(bad_alias == false) { init_warm(X.get_n_rows(), X.get_n_cols()); eop_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Mat tmp(X); steal_mem(tmp); } return *this; } template template inline const Mat& Mat::operator+=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_plus(*this, X); return *this; } template template inline const Mat& Mat::operator-=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_minus(*this, X); return *this; } template template inline const Mat& Mat::operator*=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); glue_times::apply_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator%=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_schur(*this, X); return *this; } template template inline const Mat& Mat::operator/=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); eop_type::apply_inplace_div(*this, X); return *this; } //! EXPERIMENTAL template template inline Mat::Mat(const mtOp& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); op_type::apply(*this, X); } //! EXPERIMENTAL template template inline const Mat& Mat::operator=(const mtOp& X) { arma_extra_debug_sigprint(); op_type::apply(*this, X); return *this; } //! EXPERIMENTAL template template inline const Mat& Mat::operator+=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator+=(m); } //! EXPERIMENTAL template template inline const Mat& Mat::operator-=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator-=(m); } //! EXPERIMENTAL template template inline const Mat& Mat::operator*=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator*=(m); } //! EXPERIMENTAL template template inline const Mat& Mat::operator%=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator%=(m); } //! EXPERIMENTAL template template inline const Mat& Mat::operator/=(const mtOp& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator/=(m); } //! create a matrix from Glue, i.e. run the previously delayed binary operations template template inline Mat::Mat(const Glue& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_type::apply(*this, X); } //! create a matrix from Glue, i.e. run the previously delayed binary operations template template inline const Mat& Mat::operator=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_type::apply(*this, X); return *this; } //! in-place matrix addition, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator+=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Mat m(X); return (*this).operator+=(m); } //! in-place matrix subtraction, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator-=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Mat m(X); return (*this).operator-=(m); } //! in-place matrix multiplications, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator*=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_times::apply_inplace(*this, X); return *this; } //! in-place matrix element-wise multiplication, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator%=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Mat m(X); return (*this).operator%=(m); } //! in-place matrix element-wise division, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator/=(const Glue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const Mat m(X); return (*this).operator/=(m); } template template inline const Mat& Mat::operator+=(const Glue& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace_plus(*this, X, sword(+1)); return *this; } template template inline const Mat& Mat::operator-=(const Glue& X) { arma_extra_debug_sigprint(); glue_times::apply_inplace_plus(*this, X, sword(-1)); return *this; } //! create a matrix from eGlue, i.e. run the previously delayed binary operations template template inline Mat::Mat(const eGlue& X) : n_rows(X.get_n_rows()) , n_cols(X.get_n_cols()) , n_elem(X.get_n_elem()) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); init_cold(); eglue_type::apply(*this, X); } //! create a matrix from eGlue, i.e. run the previously delayed binary operations template template inline const Mat& Mat::operator=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const bool bad_alias = ( (eGlue::proxy1_type::has_subview && X.P1.is_alias(*this)) || (eGlue::proxy2_type::has_subview && X.P2.is_alias(*this)) ); if(bad_alias == false) { init_warm(X.get_n_rows(), X.get_n_cols()); eglue_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Mat tmp(X); steal_mem(tmp); } return *this; } //! in-place matrix addition, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator+=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_plus(*this, X); return *this; } //! in-place matrix subtraction, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator-=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_minus(*this, X); return *this; } template template inline const Mat& Mat::operator*=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); glue_times::apply_inplace(*this, X); return *this; } template template inline const Mat& Mat::operator%=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_schur(*this, X); return *this; } template template inline const Mat& Mat::operator/=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); eglue_type::apply_inplace_div(*this, X); return *this; } //! EXPERIMENTAL: create a matrix from mtGlue, i.e. run the previously delayed binary operations template template inline Mat::Mat(const mtGlue& X) : n_rows(0) , n_cols(0) , n_elem(0) , vec_state(0) , mem_state(0) , mem() { arma_extra_debug_sigprint_this(this); glue_type::apply(*this, X); } //! EXPERIMENTAL: create a matrix from Glue, i.e. run the previously delayed binary operations template template inline const Mat& Mat::operator=(const mtGlue& X) { arma_extra_debug_sigprint(); glue_type::apply(*this, X); return *this; } //! EXPERIMENTAL: in-place matrix addition, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator+=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator+=(m); } //! EXPERIMENTAL: in-place matrix subtraction, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator-=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator-=(m); } //! EXPERIMENTAL: in-place matrix multiplications, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator*=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); glue_times::apply_inplace(*this, m); return *this; } //! EXPERIMENTAL: in-place matrix element-wise multiplication, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator%=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator%=(m); } //! EXPERIMENTAL: in-place matrix element-wise division, with the right-hand-side operands having delayed operations template template inline const Mat& Mat::operator/=(const mtGlue& X) { arma_extra_debug_sigprint(); const Mat m(X); return (*this).operator/=(m); } //! linear element accessor (treats the matrix as a vector); no bounds check; assumes memory is aligned template arma_inline arma_warn_unused const eT& Mat::at_alt(const uword ii) const { const eT* mem_aligned = mem; memory::mark_as_aligned(mem_aligned); return mem_aligned[ii]; } //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused eT& Mat::operator() (const uword ii) { arma_debug_check( (ii >= n_elem), "Mat::operator(): index out of bounds"); return access::rw(mem[ii]); } //! linear element accessor (treats the matrix as a vector); bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused const eT& Mat::operator() (const uword ii) const { arma_debug_check( (ii >= n_elem), "Mat::operator(): index out of bounds"); return mem[ii]; } //! linear element accessor (treats the matrix as a vector); no bounds check. template arma_inline arma_warn_unused eT& Mat::operator[] (const uword ii) { return access::rw(mem[ii]); } //! linear element accessor (treats the matrix as a vector); no bounds check template arma_inline arma_warn_unused const eT& Mat::operator[] (const uword ii) const { return mem[ii]; } //! linear element accessor (treats the matrix as a vector); no bounds check. template arma_inline arma_warn_unused eT& Mat::at(const uword ii) { return access::rw(mem[ii]); } //! linear element accessor (treats the matrix as a vector); no bounds check template arma_inline arma_warn_unused const eT& Mat::at(const uword ii) const { return mem[ii]; } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused eT& Mat::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): index out of bounds"); return access::rw(mem[in_row + in_col*n_rows]); } //! element accessor; bounds checking not done when ARMA_NO_DEBUG is defined template arma_inline arma_warn_unused const eT& Mat::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): index out of bounds"); return mem[in_row + in_col*n_rows]; } //! element accessor; no bounds check template arma_inline arma_warn_unused eT& Mat::at(const uword in_row, const uword in_col) { return access::rw( mem[in_row + in_col*n_rows] ); } //! element accessor; no bounds check template arma_inline arma_warn_unused const eT& Mat::at(const uword in_row, const uword in_col) const { return mem[in_row + in_col*n_rows]; } //! prefix ++ template arma_inline const Mat& Mat::operator++() { Mat_aux::prefix_pp(*this); return *this; } //! postfix ++ (must not return the object by reference) template arma_inline void Mat::operator++(int) { Mat_aux::postfix_pp(*this); } //! prefix -- template arma_inline const Mat& Mat::operator--() { Mat_aux::prefix_mm(*this); return *this; } //! postfix -- (must not return the object by reference) template arma_inline void Mat::operator--(int) { Mat_aux::postfix_mm(*this); } //! returns true if the matrix has no elements template arma_inline arma_warn_unused bool Mat::is_empty() const { return (n_elem == 0); } //! returns true if the object can be interpreted as a column or row vector template arma_inline arma_warn_unused bool Mat::is_vec() const { return ( (n_rows == 1) || (n_cols == 1) ); } //! returns true if the object can be interpreted as a row vector template arma_inline arma_warn_unused bool Mat::is_rowvec() const { return (n_rows == 1); } //! returns true if the object can be interpreted as a column vector template arma_inline arma_warn_unused bool Mat::is_colvec() const { return (n_cols == 1); } //! returns true if the object has the same number of non-zero rows and columnns template arma_inline arma_warn_unused bool Mat::is_square() const { return (n_rows == n_cols); } //! returns true if all of the elements are finite template inline arma_warn_unused bool Mat::is_finite() const { return arrayops::is_finite( memptr(), n_elem ); } template inline arma_warn_unused bool Mat::has_inf() const { arma_extra_debug_sigprint(); return arrayops::has_inf(memptr(), n_elem); } template inline arma_warn_unused bool Mat::has_nan() const { arma_extra_debug_sigprint(); return arrayops::has_nan(memptr(), n_elem); } template inline arma_warn_unused bool Mat::is_sorted(const char* direction) const { arma_extra_debug_sigprint(); return (*this).is_sorted(direction, (((vec_state == 2) || (n_rows == 1)) ? uword(1) : uword(0))); } template inline arma_warn_unused bool Mat::is_sorted(const char* direction, const uword dim) const { arma_extra_debug_sigprint(); const char sig = (direction != NULL) ? direction[0] : char(0); arma_debug_check( ((sig != 'a') && (sig != 'd')), "Mat::is_sorted(): unknown sort direction" ); arma_debug_check( (dim > 1), "Mat::is_sorted(): parameter 'dim' must be 0 or 1" ); if(n_elem <= 1) { return true; } const uword local_n_cols = n_cols; const uword local_n_rows = n_rows; if(sig == 'a') { // deliberately using the opposite direction comparator, // as we need to handle the case of two elements being equal arma_descend_sort_helper comparator; if(dim == 0) { if(local_n_rows <= 1u) { return true; } const uword local_n_rows_m1 = local_n_rows - 1; for(uword c=0; c < local_n_cols; ++c) { const eT* coldata = colptr(c); for(uword r=0; r < local_n_rows_m1; ++r) { const eT val1 = (*coldata); coldata++; const eT val2 = (*coldata); if(comparator(val1,val2)) { return false; } } } } else // dim == 1 { if(local_n_cols <= 1u) { return true; } const uword local_n_cols_m1 = local_n_cols - 1; if(local_n_rows == 1) { const eT* rowdata = memptr(); for(uword c=0; c < local_n_cols_m1; ++c) { const eT val1 = (*rowdata); rowdata++; const eT val2 = (*rowdata); if(comparator(val1,val2)) { return false; } } } else { for(uword r=0; r < local_n_rows; ++r) for(uword c=0; c < local_n_cols_m1; ++c) { const eT val1 = at(r,c ); const eT val2 = at(r,c+1); if(comparator(val1,val2)) { return false; } } } } } else if(sig == 'd') { // deliberately using the opposite direction comparator, // as we need to handle the case of two elements being equal arma_ascend_sort_helper comparator; if(dim == 0) { if(local_n_rows <= 1u) { return true; } const uword local_n_rows_m1 = local_n_rows - 1; for(uword c=0; c < local_n_cols; ++c) { const eT* coldata = colptr(c); for(uword r=0; r < local_n_rows_m1; ++r) { const eT val1 = (*coldata); coldata++; const eT val2 = (*coldata); if(comparator(val1,val2)) { return false; } } } } else // dim == 1 { if(local_n_cols <= 1u) { return true; } const uword local_n_cols_m1 = local_n_cols - 1; if(local_n_rows == 1) { const eT* rowdata = memptr(); for(uword c=0; c < local_n_cols_m1; ++c) { const eT val1 = (*rowdata); rowdata++; const eT val2 = (*rowdata); if(comparator(val1,val2)) { return false; } } } else { for(uword r=0; r < local_n_rows; ++r) for(uword c=0; c < local_n_cols_m1; ++c) { const eT val1 = at(r,c ); const eT val2 = at(r,c+1); if(comparator(val1,val2)) { return false; } } } } } return true; } //! returns true if the given index is currently in range template arma_inline arma_warn_unused bool Mat::in_range(const uword ii) const { return (ii < n_elem); } //! returns true if the given start and end indices are currently in range template arma_inline arma_warn_unused bool Mat::in_range(const span& x) const { arma_extra_debug_sigprint(); if(x.whole == true) { return true; } else { const uword a = x.a; const uword b = x.b; return ( (a <= b) && (b < n_elem) ); } } //! returns true if the given location is currently in range template arma_inline arma_warn_unused bool Mat::in_range(const uword in_row, const uword in_col) const { return ( (in_row < n_rows) && (in_col < n_cols) ); } template arma_inline arma_warn_unused bool Mat::in_range(const span& row_span, const uword in_col) const { arma_extra_debug_sigprint(); if(row_span.whole == true) { return (in_col < n_cols); } else { const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) ); } } template arma_inline arma_warn_unused bool Mat::in_range(const uword in_row, const span& col_span) const { arma_extra_debug_sigprint(); if(col_span.whole == true) { return (in_row < n_rows); } else { const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); } } template arma_inline arma_warn_unused bool Mat::in_range(const span& row_span, const span& col_span) const { arma_extra_debug_sigprint(); const uword in_row1 = row_span.a; const uword in_row2 = row_span.b; const uword in_col1 = col_span.a; const uword in_col2 = col_span.b; const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); return ( (rows_ok == true) && (cols_ok == true) ); } template arma_inline arma_warn_unused bool Mat::in_range(const uword in_row, const uword in_col, const SizeMat& s) const { const uword l_n_rows = n_rows; const uword l_n_cols = n_cols; if( (in_row >= l_n_rows) || (in_col >= l_n_cols) || ((in_row + s.n_rows) > l_n_rows) || ((in_col + s.n_cols) > l_n_cols) ) { return false; } else { return true; } } //! returns a pointer to array of eTs for a specified column; no bounds check template arma_inline arma_warn_unused eT* Mat::colptr(const uword in_col) { return & access::rw(mem[in_col*n_rows]); } //! returns a pointer to array of eTs for a specified column; no bounds check template arma_inline arma_warn_unused const eT* Mat::colptr(const uword in_col) const { return & mem[in_col*n_rows]; } //! returns a pointer to array of eTs used by the matrix template arma_inline arma_warn_unused eT* Mat::memptr() { return const_cast(mem); } //! returns a pointer to array of eTs used by the matrix template arma_inline arma_warn_unused const eT* Mat::memptr() const { return mem; } //! print contents of the matrix (to the cout stream), //! optionally preceding with a user specified line of text. //! the precision and cell width are modified. //! on return, the stream's state are restored to their original values. template inline void Mat::impl_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, true); } //! print contents of the matrix to a user specified stream, //! optionally preceding with a user specified line of text. //! the precision and cell width are modified. //! on return, the stream's state are restored to their original values. template inline void Mat::impl_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this, true); } //! print contents of the matrix (to the cout stream), //! optionally preceding with a user specified line of text. //! the stream's state are used as is and are not modified //! (i.e. the precision and cell width are not modified). template inline void Mat::impl_raw_print(const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = ARMA_DEFAULT_OSTREAM.width(); ARMA_DEFAULT_OSTREAM << extra_text << '\n'; ARMA_DEFAULT_OSTREAM.width(orig_width); } arma_ostream::print(ARMA_DEFAULT_OSTREAM, *this, false); } //! print contents of the matrix to a user specified stream, //! optionally preceding with a user specified line of text. //! the stream's state are used as is and are not modified. //! (i.e. the precision and cell width are not modified). template inline void Mat::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const { arma_extra_debug_sigprint(); if(extra_text.length() != 0) { const std::streamsize orig_width = user_stream.width(); user_stream << extra_text << '\n'; user_stream.width(orig_width); } arma_ostream::print(user_stream, *this, false); } //! change the matrix to have user specified dimensions (data is not preserved) template inline void Mat::set_size(const uword in_elem) { arma_extra_debug_sigprint(); switch(vec_state) { case 0: case 1: init_warm(in_elem, 1); break; case 2: init_warm(1, in_elem); break; default: ; } } //! change the matrix to have user specified dimensions (data is not preserved) template inline void Mat::set_size(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); init_warm(in_rows, in_cols); } template inline void Mat::set_size(const SizeMat& s) { arma_extra_debug_sigprint(); init_warm(s.n_rows, s.n_cols); } //! change the matrix to have user specified dimensions (data is preserved) template inline void Mat::resize(const uword in_elem) { arma_extra_debug_sigprint(); switch(vec_state) { case 0: case 1: (*this).resize(in_elem, 1); break; case 2: (*this).resize(1, in_elem); break; default: ; } } //! change the matrix to have user specified dimensions (data is preserved) template inline void Mat::resize(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); *this = arma::resize(*this, in_rows, in_cols); } template inline void Mat::resize(const SizeMat& s) { arma_extra_debug_sigprint(); *this = arma::resize(*this, s.n_rows, s.n_cols); } //! change the matrix to have user specified dimensions (data is preserved) template inline void Mat::reshape(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); *this = arma::reshape(*this, in_rows, in_cols); } template inline void Mat::reshape(const SizeMat& s) { arma_extra_debug_sigprint(); *this = arma::reshape(*this, s.n_rows, s.n_cols); } //!< NOTE: don't use this in new code; kept only for compatibility with old code template arma_deprecated inline void Mat::reshape(const uword in_rows, const uword in_cols, const uword dim) { arma_extra_debug_sigprint(); *this = arma::reshape(*this, in_rows, in_cols, dim); } //! change the matrix (without preserving data) to have the same dimensions as the given expression template template inline void Mat::copy_size(const Base& X) { arma_extra_debug_sigprint(); const Proxy P(X.get_ref()); const uword X_n_rows = P.get_n_rows(); const uword X_n_cols = P.get_n_cols(); init_warm(X_n_rows, X_n_cols); } //! apply a functor to each element template template inline const Mat& Mat::for_each(functor F) { arma_extra_debug_sigprint(); eT* data = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { F(data[ii]); F(data[jj]); } if(ii < N) { F(data[ii]); } return *this; } template template inline const Mat& Mat::for_each(functor F) const { arma_extra_debug_sigprint(); const eT* data = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { F(data[ii]); F(data[jj]); } if(ii < N) { F(data[ii]); } return *this; } //! transform each element in the matrix using a functor template template inline const Mat& Mat::transform(functor F) { arma_extra_debug_sigprint(); eT* out_mem = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { eT tmp_ii = out_mem[ii]; eT tmp_jj = out_mem[jj]; tmp_ii = eT( F(tmp_ii) ); tmp_jj = eT( F(tmp_jj) ); out_mem[ii] = tmp_ii; out_mem[jj] = tmp_jj; } if(ii < N) { out_mem[ii] = eT( F(out_mem[ii]) ); } return *this; } //! imbue (fill) the matrix with values provided by a functor template template inline const Mat& Mat::imbue(functor F) { arma_extra_debug_sigprint(); eT* out_mem = memptr(); const uword N = n_elem; uword ii, jj; for(ii=0, jj=1; jj < N; ii+=2, jj+=2) { const eT tmp_ii = eT( F() ); const eT tmp_jj = eT( F() ); out_mem[ii] = tmp_ii; out_mem[jj] = tmp_jj; } if(ii < N) { out_mem[ii] = eT( F() ); } return *this; } //! fill the matrix with the specified value template arma_hot inline const Mat& Mat::fill(const eT val) { arma_extra_debug_sigprint(); arrayops::inplace_set( memptr(), val, n_elem ); return *this; } //! fill the matrix with the specified value template template arma_hot inline const Mat& Mat::fill(const fill::fill_class&) { arma_extra_debug_sigprint(); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).eye(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); return *this; } template inline const Mat& Mat::zeros() { arma_extra_debug_sigprint(); arrayops::fill_zeros(memptr(), n_elem); return *this; } template inline const Mat& Mat::zeros(const uword in_elem) { arma_extra_debug_sigprint(); set_size(in_elem); return (*this).zeros(); } template inline const Mat& Mat::zeros(const uword in_n_rows, const uword in_n_cols) { arma_extra_debug_sigprint(); set_size(in_n_rows, in_n_cols); return (*this).zeros(); } template inline const Mat& Mat::zeros(const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).zeros(s.n_rows, s.n_cols); } template inline const Mat& Mat::ones() { arma_extra_debug_sigprint(); return fill(eT(1)); } template inline const Mat& Mat::ones(const uword in_elem) { arma_extra_debug_sigprint(); set_size(in_elem); return fill(eT(1)); } template inline const Mat& Mat::ones(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols); return fill(eT(1)); } template inline const Mat& Mat::ones(const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).ones(s.n_rows, s.n_cols); } template inline const Mat& Mat::randu() { arma_extra_debug_sigprint(); arma_rng::randu::fill( memptr(), n_elem ); return *this; } template inline const Mat& Mat::randu(const uword in_elem) { arma_extra_debug_sigprint(); set_size(in_elem); return (*this).randu(); } template inline const Mat& Mat::randu(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols); return (*this).randu(); } template inline const Mat& Mat::randu(const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).randu(s.n_rows, s.n_cols); } template inline const Mat& Mat::randn() { arma_extra_debug_sigprint(); arma_rng::randn::fill( memptr(), n_elem ); return *this; } template inline const Mat& Mat::randn(const uword in_elem) { arma_extra_debug_sigprint(); set_size(in_elem); return (*this).randn(); } template inline const Mat& Mat::randn(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols); return (*this).randn(); } template inline const Mat& Mat::randn(const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).randn(s.n_rows, s.n_cols); } template inline const Mat& Mat::eye() { arma_extra_debug_sigprint(); (*this).zeros(); const uword N = (std::min)(n_rows, n_cols); for(uword ii=0; ii inline const Mat& Mat::eye(const uword in_rows, const uword in_cols) { arma_extra_debug_sigprint(); set_size(in_rows, in_cols); return (*this).eye(); } template inline const Mat& Mat::eye(const SizeMat& s) { arma_extra_debug_sigprint(); return (*this).eye(s.n_rows, s.n_cols); } template inline void Mat::reset() { arma_extra_debug_sigprint(); switch(vec_state) { default: init_warm(0, 0); break; case 1: init_warm(0, 1); break; case 2: init_warm(1, 0); break; } } template template inline void Mat::set_real(const Base::pod_type,T1>& X) { arma_extra_debug_sigprint(); Mat_aux::set_real(*this, X); } template template inline void Mat::set_imag(const Base::pod_type,T1>& X) { arma_extra_debug_sigprint(); Mat_aux::set_imag(*this, X); } template inline arma_warn_unused eT Mat::min() const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Mat::min(): object has no elements"); return Datum::nan; } return op_min::direct_min(memptr(), n_elem); } template inline arma_warn_unused eT Mat::max() const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Mat::max(): object has no elements"); return Datum::nan; } return op_max::direct_max(memptr(), n_elem); } template inline eT Mat::min(uword& index_of_min_val) const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Mat::min(): object has no elements"); return Datum::nan; } return op_min::direct_min(memptr(), n_elem, index_of_min_val); } template inline eT Mat::max(uword& index_of_max_val) const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Mat::max(): object has no elements"); return Datum::nan; } return op_max::direct_max(memptr(), n_elem, index_of_max_val); } template inline eT Mat::min(uword& row_of_min_val, uword& col_of_min_val) const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Mat::min(): object has no elements"); return Datum::nan; } uword iq; eT val = op_min::direct_min(memptr(), n_elem, iq); row_of_min_val = iq % n_rows; col_of_min_val = iq / n_rows; return val; } template inline eT Mat::max(uword& row_of_max_val, uword& col_of_max_val) const { arma_extra_debug_sigprint(); if(n_elem == 0) { arma_debug_check(true, "Mat::max(): object has no elements"); return Datum::nan; } uword iq; eT val = op_max::direct_max(memptr(), n_elem, iq); row_of_max_val = iq % n_rows; col_of_max_val = iq / n_rows; return val; } //! save the matrix to a file template inline bool Mat::save(const std::string name, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { case raw_ascii: save_okay = diskio::save_raw_ascii(*this, name); break; case arma_ascii: save_okay = diskio::save_arma_ascii(*this, name); break; case csv_ascii: save_okay = diskio::save_csv_ascii(*this, name); break; case raw_binary: save_okay = diskio::save_raw_binary(*this, name); break; case arma_binary: save_okay = diskio::save_arma_binary(*this, name); break; case pgm_binary: save_okay = diskio::save_pgm_binary(*this, name); break; case hdf5_binary: save_okay = diskio::save_hdf5_binary(*this, name); break; default: if(print_status) { arma_debug_warn("Mat::save(): unsupported file type"); } save_okay = false; } if(print_status && (save_okay == false)) { arma_debug_warn("Mat::save(): couldn't write to ", name); } return save_okay; } //! save the matrix to a stream template inline bool Mat::save(std::ostream& os, const file_type type, const bool print_status) const { arma_extra_debug_sigprint(); bool save_okay; switch(type) { case raw_ascii: save_okay = diskio::save_raw_ascii(*this, os); break; case arma_ascii: save_okay = diskio::save_arma_ascii(*this, os); break; case csv_ascii: save_okay = diskio::save_csv_ascii(*this, os); break; case raw_binary: save_okay = diskio::save_raw_binary(*this, os); break; case arma_binary: save_okay = diskio::save_arma_binary(*this, os); break; case pgm_binary: save_okay = diskio::save_pgm_binary(*this, os); break; default: if(print_status) { arma_debug_warn("Mat::save(): unsupported file type"); } save_okay = false; } if(print_status && (save_okay == false)) { arma_debug_warn("Mat::save(): couldn't write to the given stream"); } return save_okay; } //! load a matrix from a file template inline bool Mat::load(const std::string name, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { case auto_detect: load_okay = diskio::load_auto_detect(*this, name, err_msg); break; case raw_ascii: load_okay = diskio::load_raw_ascii(*this, name, err_msg); break; case arma_ascii: load_okay = diskio::load_arma_ascii(*this, name, err_msg); break; case csv_ascii: load_okay = diskio::load_csv_ascii(*this, name, err_msg); break; case raw_binary: load_okay = diskio::load_raw_binary(*this, name, err_msg); break; case arma_binary: load_okay = diskio::load_arma_binary(*this, name, err_msg); break; case pgm_binary: load_okay = diskio::load_pgm_binary(*this, name, err_msg); break; case hdf5_binary: load_okay = diskio::load_hdf5_binary(*this, name, err_msg); break; default: if(print_status) { arma_debug_warn("Mat::load(): unsupported file type"); } load_okay = false; } if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_debug_warn("Mat::load(): ", err_msg, name); } else { arma_debug_warn("Mat::load(): couldn't read ", name); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! load a matrix from a stream template inline bool Mat::load(std::istream& is, const file_type type, const bool print_status) { arma_extra_debug_sigprint(); bool load_okay; std::string err_msg; switch(type) { case auto_detect: load_okay = diskio::load_auto_detect(*this, is, err_msg); break; case raw_ascii: load_okay = diskio::load_raw_ascii(*this, is, err_msg); break; case arma_ascii: load_okay = diskio::load_arma_ascii(*this, is, err_msg); break; case csv_ascii: load_okay = diskio::load_csv_ascii(*this, is, err_msg); break; case raw_binary: load_okay = diskio::load_raw_binary(*this, is, err_msg); break; case arma_binary: load_okay = diskio::load_arma_binary(*this, is, err_msg); break; case pgm_binary: load_okay = diskio::load_pgm_binary(*this, is, err_msg); break; default: if(print_status) { arma_debug_warn("Mat::load(): unsupported file type"); } load_okay = false; } if( (print_status == true) && (load_okay == false) ) { if(err_msg.length() > 0) { arma_debug_warn("Mat::load(): ", err_msg, "the given stream"); } else { arma_debug_warn("Mat::load(): couldn't load from the given stream"); } } if(load_okay == false) { (*this).reset(); } return load_okay; } //! save the matrix to a file, without printing any error messages template inline bool Mat::quiet_save(const std::string name, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(name, type, false); } //! save the matrix to a stream, without printing any error messages template inline bool Mat::quiet_save(std::ostream& os, const file_type type) const { arma_extra_debug_sigprint(); return (*this).save(os, type, false); } //! load a matrix from a file, without printing any error messages template inline bool Mat::quiet_load(const std::string name, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(name, type, false); } //! load a matrix from a stream, without printing any error messages template inline bool Mat::quiet_load(std::istream& is, const file_type type) { arma_extra_debug_sigprint(); return (*this).load(is, type, false); } template inline Mat::row_iterator::row_iterator(Mat& in_M, const uword in_row) : M (in_M ) , row(in_row) , col(0 ) { arma_extra_debug_sigprint(); } template inline eT& Mat::row_iterator::operator*() { return M.at(row,col); } template inline typename Mat::row_iterator& Mat::row_iterator::operator++() { ++col; if(col >= M.n_cols) { col = 0; ++row; } return *this; } template inline void Mat::row_iterator::operator++(int) { operator++(); } template inline typename Mat::row_iterator& Mat::row_iterator::operator--() { if(col > 0) { --col; } else { if(row > 0) { col = M.n_cols - 1; --row; } } return *this; } template inline void Mat::row_iterator::operator--(int) { operator--(); } template inline bool Mat::row_iterator::operator!=(const typename Mat::row_iterator& X) const { return ( (row != X.row) || (col != X.col) ) ? true : false; } template inline bool Mat::row_iterator::operator==(const typename Mat::row_iterator& X) const { return ( (row == X.row) && (col == X.col) ) ? true : false; } template inline Mat::const_row_iterator::const_row_iterator(const Mat& in_M, const uword in_row) : M (in_M ) , row(in_row) , col(0 ) { arma_extra_debug_sigprint(); } template inline Mat::const_row_iterator::const_row_iterator(const typename Mat::row_iterator& X) : M (X.M) , row(X.row) , col(X.col) { arma_extra_debug_sigprint(); } template inline eT Mat::const_row_iterator::operator*() const { return M.at(row,col); } template inline typename Mat::const_row_iterator& Mat::const_row_iterator::operator++() { ++col; if(col >= M.n_cols) { col = 0; ++row; } return *this; } template inline void Mat::const_row_iterator::operator++(int) { operator++(); } template inline typename Mat::const_row_iterator& Mat::const_row_iterator::operator--() { if(col > 0) { --col; } else { if(row > 0) { col = M.n_cols - 1; --row; } } return *this; } template inline void Mat::const_row_iterator::operator--(int) { operator--(); } template inline bool Mat::const_row_iterator::operator!=(const typename Mat::const_row_iterator& X) const { return ( (row != X.row) || (col != X.col) ) ? true : false; } template inline bool Mat::const_row_iterator::operator==(const typename Mat::const_row_iterator& X) const { return ( (row == X.row) && (col == X.col) ) ? true : false; } template inline Mat::row_col_iterator::row_col_iterator() : M (NULL) , current_pos (NULL) , internal_col(0 ) , internal_row(0 ) { arma_extra_debug_sigprint(); // Technically this iterator is invalid (it does not point to a real element) } template inline Mat::row_col_iterator::row_col_iterator(const row_col_iterator& in_it) : M (in_it.M ) , current_pos (in_it.current_pos ) , internal_col(in_it.internal_col) , internal_row(in_it.internal_row) { arma_extra_debug_sigprint(); } template inline Mat::row_col_iterator::row_col_iterator(Mat& in_M, const uword in_row, const uword in_col) : M (&in_M ) , current_pos (&in_M.at(in_row,in_col)) , internal_col(in_col ) , internal_row(in_row ) { arma_extra_debug_sigprint(); } template inline eT& Mat::row_col_iterator::operator*() { return *current_pos; } template inline typename Mat::row_col_iterator& Mat::row_col_iterator::operator++() { current_pos++; internal_row++; // Check to see if we moved a column. if(internal_row == M->n_rows) { internal_col++; internal_row = 0; } return *this; } template inline typename Mat::row_col_iterator Mat::row_col_iterator::operator++(int) { typename Mat::row_col_iterator temp(*this); ++(*this); return temp; } template inline typename Mat::row_col_iterator& Mat::row_col_iterator::operator--() { if(internal_row > 0) { current_pos--; internal_row--; } else if(internal_col > 0) { current_pos--; internal_col--; internal_row = M->n_rows - 1; } return *this; } template inline typename Mat::row_col_iterator Mat::row_col_iterator::operator--(int) { typename Mat::row_col_iterator temp(*this); --(*this); return temp; } template inline uword Mat::row_col_iterator::row() const { return internal_row; } template inline uword Mat::row_col_iterator::col() const { return internal_col; } template inline bool Mat::row_col_iterator::operator==(const row_col_iterator& rhs) const { return (current_pos == rhs.current_pos); } template inline bool Mat::row_col_iterator::operator!=(const row_col_iterator& rhs) const { return (current_pos != rhs.current_pos); } template inline bool Mat::row_col_iterator::operator==(const const_row_col_iterator& rhs) const { return (current_pos == rhs.current_pos); } template inline bool Mat::row_col_iterator::operator!=(const const_row_col_iterator& rhs) const { return (current_pos != rhs.current_pos); } template inline Mat::const_row_col_iterator::const_row_col_iterator() : M (NULL) , current_pos (NULL) , internal_col(0 ) , internal_row(0 ) { arma_extra_debug_sigprint(); // Technically this iterator is invalid (it does not point to a real element) } template inline Mat::const_row_col_iterator::const_row_col_iterator(const row_col_iterator& in_it) : M (in_it.M ) , current_pos (in_it.current_pos) , internal_col(in_it.col() ) , internal_row(in_it.row() ) { arma_extra_debug_sigprint(); } template inline Mat::const_row_col_iterator::const_row_col_iterator(const const_row_col_iterator& in_it) : M (in_it.M ) , current_pos (in_it.current_pos) , internal_col(in_it.col() ) , internal_row(in_it.row() ) { arma_extra_debug_sigprint(); } template inline Mat::const_row_col_iterator::const_row_col_iterator(const Mat& in_M, const uword in_row, const uword in_col) : M (&in_M ) , current_pos (&in_M.at(in_row,in_col)) , internal_col(in_col ) , internal_row(in_row ) { arma_extra_debug_sigprint(); } template inline const eT& Mat::const_row_col_iterator::operator*() const { return *current_pos; } template inline typename Mat::const_row_col_iterator& Mat::const_row_col_iterator::operator++() { current_pos++; internal_row++; // Check to see if we moved a column. if(internal_row == M->n_rows) { internal_col++; internal_row = 0; } return *this; } template inline typename Mat::const_row_col_iterator Mat::const_row_col_iterator::operator++(int) { typename Mat::const_row_col_iterator temp(*this); ++(*this); return temp; } template inline typename Mat::const_row_col_iterator& Mat::const_row_col_iterator::operator--() { if(internal_row > 0) { current_pos--; internal_row--; } else if(internal_col > 0) { current_pos--; internal_col--; internal_row = M->n_rows - 1; } return *this; } template inline typename Mat::const_row_col_iterator Mat::const_row_col_iterator::operator--(int) { typename Mat::const_row_col_iterator temp(*this); --(*this); return temp; } template inline uword Mat::const_row_col_iterator::row() const { return internal_row; } template inline uword Mat::const_row_col_iterator::col() const { return internal_col; } template inline bool Mat::const_row_col_iterator::operator==(const const_row_col_iterator& rhs) const { return (current_pos == rhs.current_pos); } template inline bool Mat::const_row_col_iterator::operator!=(const const_row_col_iterator& rhs) const { return (current_pos != rhs.current_pos); } template inline bool Mat::const_row_col_iterator::operator==(const row_col_iterator& rhs) const { return (current_pos == rhs.current_pos); } template inline bool Mat::const_row_col_iterator::operator!=(const row_col_iterator& rhs) const { return (current_pos != rhs.current_pos); } template inline typename Mat::iterator Mat::begin() { arma_extra_debug_sigprint(); return memptr(); } template inline typename Mat::const_iterator Mat::begin() const { arma_extra_debug_sigprint(); return memptr(); } template inline typename Mat::const_iterator Mat::cbegin() const { arma_extra_debug_sigprint(); return memptr(); } template inline typename Mat::iterator Mat::end() { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Mat::const_iterator Mat::end() const { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Mat::const_iterator Mat::cend() const { arma_extra_debug_sigprint(); return memptr() + n_elem; } template inline typename Mat::col_iterator Mat::begin_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "Mat::begin_col(): index out of bounds"); return colptr(col_num); } template inline typename Mat::const_col_iterator Mat::begin_col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "Mat::begin_col(): index out of bounds"); return colptr(col_num); } template inline typename Mat::col_iterator Mat::end_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "Mat::end_col(): index out of bounds"); return colptr(col_num) + n_rows; } template inline typename Mat::const_col_iterator Mat::end_col(const uword col_num) const { arma_extra_debug_sigprint(); arma_debug_check( (col_num >= n_cols), "Mat::end_col(): index out of bounds"); return colptr(col_num) + n_rows; } template inline typename Mat::row_iterator Mat::begin_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" ); return typename Mat::row_iterator(*this, row_num); } template inline typename Mat::const_row_iterator Mat::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" ); return typename Mat::const_row_iterator(*this, row_num); } template inline typename Mat::row_iterator Mat::end_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" ); return typename Mat::row_iterator(*this, row_num + 1); } template inline typename Mat::const_row_iterator Mat::end_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" ); return typename Mat::const_row_iterator(*this, row_num + 1); } template inline typename Mat::row_col_iterator Mat::begin_row_col() { return row_col_iterator(*this); } template inline typename Mat::const_row_col_iterator Mat::begin_row_col() const { return const_row_col_iterator(*this); } template inline typename Mat::row_col_iterator Mat::end_row_col() { return row_col_iterator(*this, 0, n_cols); } template inline typename Mat::const_row_col_iterator Mat::end_row_col() const { return const_row_col_iterator(*this, 0, n_cols); } //! resets this matrix to an empty matrix template inline void Mat::clear() { reset(); } //! returns true if the matrix has no elements template inline bool Mat::empty() const { return (n_elem == 0); } //! returns the number of elements in this matrix template inline uword Mat::size() const { return n_elem; } template template arma_inline Mat::fixed::fixed() : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); } template template arma_inline Mat::fixed::fixed(const fixed& X) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } template template template inline Mat::fixed::fixed(const fill::fill_class&) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).eye(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); } template template template inline Mat::fixed::fixed(const Base& A) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); Mat::operator=(A.get_ref()); } template template template inline Mat::fixed::fixed(const Base& A, const Base& B) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); Mat::init(A,B); } template template inline Mat::fixed::fixed(const eT* aux_mem) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : mem_local; arrayops::copy( dest, aux_mem, fixed_n_elem ); } template template inline Mat::fixed::fixed(const char* text) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); Mat::operator=(text); } template template inline Mat::fixed::fixed(const std::string& text) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); Mat::operator=(text); } #if defined(ARMA_USE_CXX11) template template inline Mat::fixed::fixed(const std::initializer_list& list) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); (*this).operator=(list); } template template inline const Mat& Mat::fixed::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); const uword N = uword(list.size()); arma_debug_check( (N > fixed_n_elem), "Mat::fixed: initialiser list is too long" ); eT* this_mem = (*this).memptr(); arrayops::copy( this_mem, list.begin(), N ); for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); } return *this; } template template inline Mat::fixed::fixed(const std::initializer_list< std::initializer_list >& list) : Mat( arma_fixed_indicator(), fixed_n_rows, fixed_n_cols, 0, ((use_extra) ? mem_local_extra : mem_local) ) { arma_extra_debug_sigprint_this(this); Mat::init(list); } template template inline const Mat& Mat::fixed::operator=(const std::initializer_list< std::initializer_list >& list) { arma_extra_debug_sigprint(); Mat::init(list); return *this; } #endif template template arma_inline const Mat& Mat::fixed::operator=(const fixed& X) { arma_extra_debug_sigprint(); if(this != &X) { eT* dest = (use_extra) ? mem_local_extra : mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } return *this; } #if defined(ARMA_GOOD_COMPILER) template template template inline const Mat& Mat::fixed::operator=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const bool bad_alias = (eOp::proxy_type::has_subview && X.P.is_alias(*this)); if(bad_alias == false) { arma_debug_assert_same_size(fixed_n_rows, fixed_n_cols, X.get_n_rows(), X.get_n_cols(), "Mat::fixed::operator="); eop_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Mat tmp(X); (*this) = tmp; } return *this; } template template template inline const Mat& Mat::fixed::operator=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const bool bad_alias = ( (eGlue::proxy1_type::has_subview && X.P1.is_alias(*this)) || (eGlue::proxy2_type::has_subview && X.P2.is_alias(*this)) ); if(bad_alias == false) { arma_debug_assert_same_size(fixed_n_rows, fixed_n_cols, X.get_n_rows(), X.get_n_cols(), "Mat::fixed::operator="); eglue_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Mat tmp(X); (*this) = tmp; } return *this; } #endif template template arma_inline const Op< typename Mat::template fixed::Mat_fixed_type, op_htrans > Mat::fixed::t() const { return Op< typename Mat::template fixed::Mat_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Mat::template fixed::Mat_fixed_type, op_htrans > Mat::fixed::ht() const { return Op< typename Mat::template fixed::Mat_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Mat::template fixed::Mat_fixed_type, op_strans > Mat::fixed::st() const { return Op< typename Mat::template fixed::Mat_fixed_type, op_strans >(*this); } template template arma_inline arma_warn_unused const eT& Mat::fixed::at_alt(const uword ii) const { #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; #else const eT* mem_aligned = (use_extra) ? mem_local_extra : mem_local; memory::mark_as_aligned(mem_aligned); return mem_aligned[ii]; #endif } template template arma_inline arma_warn_unused eT& Mat::fixed::operator[] (const uword ii) { return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::operator[] (const uword ii) const { return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused eT& Mat::fixed::at(const uword ii) { return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::at(const uword ii) const { return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused eT& Mat::fixed::operator() (const uword ii) { arma_debug_check( (ii >= fixed_n_elem), "Mat::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::operator() (const uword ii) const { arma_debug_check( (ii >= fixed_n_elem), "Mat::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; } template template arma_inline arma_warn_unused eT& Mat::fixed::at(const uword in_row, const uword in_col) { const uword iq = in_row + in_col*fixed_n_rows; return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::at(const uword in_row, const uword in_col) const { const uword iq = in_row + in_col*fixed_n_rows; return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; } template template arma_inline arma_warn_unused eT& Mat::fixed::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::operator(): index out of bounds"); const uword iq = in_row + in_col*fixed_n_rows; return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; } template template arma_inline arma_warn_unused const eT& Mat::fixed::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::operator(): index out of bounds"); const uword iq = in_row + in_col*fixed_n_rows; return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; } template template arma_inline arma_warn_unused eT* Mat::fixed::colptr(const uword in_col) { eT* mem_actual = (use_extra) ? mem_local_extra : mem_local; return & access::rw(mem_actual[in_col*fixed_n_rows]); } template template arma_inline arma_warn_unused const eT* Mat::fixed::colptr(const uword in_col) const { const eT* mem_actual = (use_extra) ? mem_local_extra : mem_local; return & mem_actual[in_col*fixed_n_rows]; } template template arma_inline arma_warn_unused eT* Mat::fixed::memptr() { return (use_extra) ? mem_local_extra : mem_local; } template template arma_inline arma_warn_unused const eT* Mat::fixed::memptr() const { return (use_extra) ? mem_local_extra : mem_local; } template template arma_inline arma_warn_unused bool Mat::fixed::is_vec() const { return ( (fixed_n_rows == 1) || (fixed_n_cols == 1) ); } template template arma_hot inline const Mat& Mat::fixed::fill(const eT val) { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(mem_local[0]); arrayops::inplace_set_fixed( mem_use, val ); return *this; } template template arma_hot inline const Mat& Mat::fixed::zeros() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(0) ); return *this; } template template arma_hot inline const Mat& Mat::fixed::ones() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(1) ); return *this; } //! prefix ++ template arma_inline void Mat_aux::prefix_pp(Mat& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Mat_aux::prefix_pp(Mat< std::complex >& x) { x += T(1); } //! postfix ++ template arma_inline void Mat_aux::postfix_pp(Mat& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Mat_aux::postfix_pp(Mat< std::complex >& x) { x += T(1); } //! prefix -- template arma_inline void Mat_aux::prefix_mm(Mat& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Mat_aux::prefix_mm(Mat< std::complex >& x) { x -= T(1); } //! postfix -- template arma_inline void Mat_aux::postfix_mm(Mat& x) { eT* memptr = x.memptr(); const uword n_elem = x.n_elem; uword i,j; for(i=0, j=1; j arma_inline void Mat_aux::postfix_mm(Mat< std::complex >& x) { x -= T(1); } template inline void Mat_aux::set_real(Mat& out, const Base& X) { arma_extra_debug_sigprint(); const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; arma_debug_assert_same_size( out, A, "Mat::set_real()" ); out = A; } template inline void Mat_aux::set_imag(Mat&, const Base&) { arma_extra_debug_sigprint(); } template inline void Mat_aux::set_real(Mat< std::complex >& out, const Base& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy P(X.get_ref()); const uword local_n_rows = P.get_n_rows(); const uword local_n_cols = P.get_n_cols(); arma_debug_assert_same_size( out.n_rows, out.n_cols, local_n_rows, local_n_cols, "Mat::set_real()" ); eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); const uword N = out.n_elem; for(uword i=0; i( A[i], out_mem[i].imag() ); } } else { for(uword col=0; col < local_n_cols; ++col) for(uword row=0; row < local_n_rows; ++row) { (*out_mem) = std::complex( P.at(row,col), (*out_mem).imag() ); out_mem++; } } } template inline void Mat_aux::set_imag(Mat< std::complex >& out, const Base& X) { arma_extra_debug_sigprint(); typedef typename std::complex eT; const Proxy P(X.get_ref()); const uword local_n_rows = P.get_n_rows(); const uword local_n_cols = P.get_n_cols(); arma_debug_assert_same_size( out.n_rows, out.n_cols, local_n_rows, local_n_cols, "Mat::set_imag()" ); eT* out_mem = out.memptr(); if(Proxy::prefer_at_accessor == false) { typedef typename Proxy::ea_type ea_type; ea_type A = P.get_ea(); const uword N = out.n_elem; for(uword i=0; i( out_mem[i].real(), A[i] ); } } else { for(uword col=0; col < local_n_cols; ++col) for(uword row=0; row < local_n_rows; ++row) { (*out_mem) = std::complex( (*out_mem).real(), P.at(row,col) ); out_mem++; } } } #ifdef ARMA_EXTRA_MAT_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_MEAT) #endif //! @} armadillo-6.500.5/include/armadillo_bits/arrayops_bones.hpp0000666000000000000000000001170212650172354022512 0ustar rootroot// Copyright (C) 2011-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arrayops //! @{ class arrayops { public: template arma_hot arma_inline static void copy(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void copy_small(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void copy_forwards(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void copy_backwards(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void fill_zeros(eT* dest, const uword n_elem); // // array = convert(array) template arma_hot arma_inline static void convert_cx_scalar(out_eT& out, const in_eT& in, const typename arma_not_cx::result* junk1 = 0, const typename arma_not_cx< in_eT>::result* junk2 = 0); template arma_hot arma_inline static void convert_cx_scalar(out_eT& out, const std::complex& in, const typename arma_not_cx::result* junk = 0); template arma_hot arma_inline static void convert_cx_scalar(std::complex& out, const std::complex< in_T>& in); template arma_hot inline static void convert(out_eT* dest, const in_eT* src, const uword n_elem); template arma_hot inline static void convert_cx(out_eT* dest, const in_eT* src, const uword n_elem); // // array op= array template arma_hot inline static void inplace_plus(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_minus(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_mul(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_div(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_plus_base(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_minus_base(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_mul_base(eT* dest, const eT* src, const uword n_elem); template arma_hot inline static void inplace_div_base(eT* dest, const eT* src, const uword n_elem); // // array op= scalar template arma_hot inline static void inplace_set(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_set_base(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_set_small(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_set_fixed(eT* dest, const eT val); template arma_hot inline static void inplace_plus(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_minus(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_mul(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_div(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_plus_base(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_minus_base(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_mul_base(eT* dest, const eT val, const uword n_elem); template arma_hot inline static void inplace_div_base(eT* dest, const eT val, const uword n_elem); // // scalar = op(array) template arma_hot inline static eT accumulate(const eT* src, const uword n_elem); template arma_hot inline static eT product(const eT* src, const uword n_elem); template arma_hot inline static bool is_finite(const eT* src, const uword n_elem); template arma_hot inline static bool has_inf(const eT* src, const uword n_elem); template arma_hot inline static bool has_nan(const eT* src, const uword n_elem); }; //! @} armadillo-6.500.5/include/armadillo_bits/SpMat_iterators_meat.hpp0000666000000000000000000004442612620272703023617 0ustar rootroot// Copyright (C) 2011-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin // Written by Matthew Amidon //! \addtogroup SpMat //! @{ /////////////////////////////////////////////////////////////////////////////// // SpMat::iterator_base implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpMat::iterator_base::iterator_base() : M(NULL) , internal_col(0) , internal_pos(0) { // Technically this iterator is invalid (it may not point to a real element) } template inline SpMat::iterator_base::iterator_base(const SpMat& in_M) : M(&in_M) , internal_col(0) , internal_pos(0) { // Technically this iterator is invalid (it may not point to a real element) } template inline SpMat::iterator_base::iterator_base(const SpMat& in_M, const uword in_col, const uword in_pos) : M(&in_M) , internal_col(in_col) , internal_pos(in_pos) { // Nothing to do. } template inline arma_hot eT SpMat::iterator_base::operator*() const { return M->values[internal_pos]; } /////////////////////////////////////////////////////////////////////////////// // SpMat::const_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline SpMat::const_iterator::const_iterator() : iterator_base() { } template inline SpMat::const_iterator::const_iterator(const SpMat& in_M, uword initial_pos) : iterator_base(in_M, 0, initial_pos) { // Corner case for empty matrices. if(in_M.n_nonzero == 0) { iterator_base::internal_col = in_M.n_cols; return; } // Determine which column we should be in. while(iterator_base::M->col_ptrs[iterator_base::internal_col + 1] <= iterator_base::internal_pos) { iterator_base::internal_col++; } } template inline SpMat::const_iterator::const_iterator(const SpMat& in_M, uword in_row, uword in_col) : iterator_base(in_M, in_col, 0) { // So we have a position we want to be right after. Skip to the column. iterator_base::internal_pos = iterator_base::M->col_ptrs[iterator_base::internal_col]; // Now we have to make sure that is the right column. while(iterator_base::M->col_ptrs[iterator_base::internal_col + 1] <= iterator_base::internal_pos) { iterator_base::internal_col++; } // Now we have to get to the right row. while((iterator_base::M->row_indices[iterator_base::internal_pos] < in_row) && (iterator_base::internal_col == in_col)) { ++(*this); // Increment iterator. } } template inline SpMat::const_iterator::const_iterator(const SpMat& in_M, const uword /* in_row */, const uword in_col, const uword in_pos) : iterator_base(in_M, in_col, in_pos) { // Nothing to do. } template inline SpMat::const_iterator::const_iterator(const typename SpMat::const_iterator& other) : iterator_base(*other.M, other.internal_col, other.internal_pos) { // Nothing to do. } template inline arma_hot typename SpMat::const_iterator& SpMat::const_iterator::operator++() { ++iterator_base::internal_pos; if (iterator_base::internal_pos == iterator_base::M->n_nonzero) { iterator_base::internal_col = iterator_base::M->n_cols; return *this; } // Check to see if we moved a column. while (iterator_base::M->col_ptrs[iterator_base::internal_col + 1] <= iterator_base::internal_pos) { ++iterator_base::internal_col; } return *this; } template inline arma_hot typename SpMat::const_iterator SpMat::const_iterator::operator++(int) { typename SpMat::const_iterator tmp(*this); ++(*this); return tmp; } template inline arma_hot typename SpMat::const_iterator& SpMat::const_iterator::operator--() { //iterator_base::M.print("M"); // printf("decrement from %d, %d, %d\n", iterator_base::internal_pos, iterator_base::internal_col, iterator_base::row()); --iterator_base::internal_pos; // printf("now pos %d\n", iterator_base::internal_pos); // First, see if we moved back a column. while (iterator_base::internal_pos < iterator_base::M->col_ptrs[iterator_base::internal_col]) { // printf("colptr %d (col %d)\n", iterator_base::M.col_ptrs[iterator_base::internal_col], iterator_base::internal_col); --iterator_base::internal_col; } return *this; } template inline arma_hot typename SpMat::const_iterator SpMat::const_iterator::operator--(int) { typename SpMat::const_iterator tmp(*this); --(*this); return tmp; } template inline arma_hot bool SpMat::const_iterator::operator==(const const_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator!=(const const_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator==(const typename SpSubview::const_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator!=(const typename SpSubview::const_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator==(const const_row_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator!=(const const_row_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator==(const typename SpSubview::const_row_iterator& rhs) const { return (rhs.row() == (*this).row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_iterator::operator!=(const typename SpSubview::const_row_iterator& rhs) const { return (rhs.row() != (*this).row()) || (rhs.col() != iterator_base::internal_col); } /////////////////////////////////////////////////////////////////////////////// // SpMat::iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline arma_hot SpValProxy > SpMat::iterator::operator*() { return SpValProxy >( iterator_base::M->row_indices[iterator_base::internal_pos], iterator_base::internal_col, access::rw(*iterator_base::M), &access::rw(iterator_base::M->values[iterator_base::internal_pos])); } template inline arma_hot typename SpMat::iterator& SpMat::iterator::operator++() { const_iterator::operator++(); return *this; } template inline arma_hot typename SpMat::iterator SpMat::iterator::operator++(int) { typename SpMat::iterator tmp(*this); const_iterator::operator++(); return tmp; } template inline arma_hot typename SpMat::iterator& SpMat::iterator::operator--() { const_iterator::operator--(); return *this; } template inline arma_hot typename SpMat::iterator SpMat::iterator::operator--(int) { typename SpMat::iterator tmp(*this); const_iterator::operator--(); return tmp; } /////////////////////////////////////////////////////////////////////////////// // SpMat::const_row_iterator implementation // /////////////////////////////////////////////////////////////////////////////// /** * Initialize the const_row_iterator. */ template inline SpMat::const_row_iterator::const_row_iterator() : iterator_base() , internal_row(0) , actual_pos(0) { } template inline SpMat::const_row_iterator::const_row_iterator(const SpMat& in_M, uword initial_pos) : iterator_base(in_M, 0, initial_pos) , internal_row(0) , actual_pos(0) { // Corner case for empty matrix. if(in_M.n_nonzero == 0) { iterator_base::internal_col = 0; internal_row = in_M.n_rows; return; } // We don't count zeros in our position count, so we have to find the nonzero // value corresponding to the given initial position. We assume initial_pos // is valid. // This is irritating because we don't know where the elements are in each // row. What we will do is loop across all columns looking for elements in // row 0 (and add to our sum), then in row 1, and so forth, until we get to // the desired position. uword cur_pos = std::numeric_limits::max(); // Invalid value. uword cur_row = 0; uword cur_col = 0; while(true) // This loop is terminated from the inside. { // Is there anything in the column we are looking at? for (uword ind = 0; ((iterator_base::M->col_ptrs[cur_col] + ind < iterator_base::M->col_ptrs[cur_col + 1]) && (iterator_base::M->row_indices[iterator_base::M->col_ptrs[cur_col] + ind] <= cur_row)); ind++) { // There is something in this column. Is it in the row we are looking at? const uword row_index = iterator_base::M->row_indices[iterator_base::M->col_ptrs[cur_col] + ind]; if (row_index == cur_row) { // Yes, it is what we are looking for. Increment our current position. if (++cur_pos == iterator_base::internal_pos) // TODO: HACK: if cur_pos is std::numeric_limits::max(), ++cur_pos relies on a wraparound/overflow, which is not portable { actual_pos = iterator_base::M->col_ptrs[cur_col] + ind; internal_row = cur_row; iterator_base::internal_col = cur_col; return; } // We are done with this column. Break to the column incrementing code (directly below). break; } else if(row_index > cur_row) { break; // Can't be in this column. } } cur_col++; // Done with the column. Move on. if (cur_col == iterator_base::M->n_cols) { // We are out of columns. Loop back to the beginning and look on the // next row. cur_col = 0; cur_row++; } } } template inline SpMat::const_row_iterator::const_row_iterator(const SpMat& in_M, uword in_row, uword in_col) : iterator_base(in_M, in_col, 0) , internal_row(0) , actual_pos(0) { // This is slow. It needs to be rewritten. // So we have a destination we want to be just after, but don't know what position that is. Make another iterator to find out... const_row_iterator it(in_M, 0); while((it.row() < in_row) || ((it.row() == in_row) && (it.col() < in_col))) { it++; } // Now that it is at the right place, take its position. iterator_base::internal_col = it.internal_col; iterator_base::internal_pos = it.internal_pos; internal_row = it.internal_row; actual_pos = it.actual_pos; } /** * Initialize the const_row_iterator from another const_row_iterator. */ template inline SpMat::const_row_iterator::const_row_iterator(const typename SpMat::const_row_iterator& other) : iterator_base(*other.M, other.internal_col, other.internal_pos) , internal_row(other.internal_row) , actual_pos(other.actual_pos) { // Nothing to do. } /** * Increment the row_iterator. */ template inline arma_hot typename SpMat::const_row_iterator& SpMat::const_row_iterator::operator++() { // We just need to find the next nonzero element. iterator_base::internal_pos++; if(iterator_base::internal_pos == iterator_base::M->n_nonzero) { internal_row = iterator_base::M->n_rows; iterator_base::internal_col = 0; actual_pos = iterator_base::M->n_nonzero; return *this; } // Otherwise, we need to search. uword cur_col = iterator_base::internal_col; uword cur_row = internal_row; while (true) // This loop is terminated from the inside. { // Increment the current column and see if we are now on a new row. if (++cur_col == iterator_base::M->n_cols) { cur_col = 0; cur_row++; } // Is there anything in this new column? for (uword ind = 0; ((iterator_base::M->col_ptrs[cur_col] + ind < iterator_base::M->col_ptrs[cur_col + 1]) && (iterator_base::M->row_indices[iterator_base::M->col_ptrs[cur_col] + ind] <= cur_row)); ind++) { if (iterator_base::M->row_indices[iterator_base::M->col_ptrs[cur_col] + ind] == cur_row) { // We have successfully incremented. internal_row = cur_row; iterator_base::internal_col = cur_col; actual_pos = iterator_base::M->col_ptrs[cur_col] + ind; return *this; // Now we are done. } } } } /** * Increment the row_iterator (but do not return anything. */ template inline arma_hot typename SpMat::const_row_iterator SpMat::const_row_iterator::operator++(int) { typename SpMat::const_row_iterator tmp(*this); ++(*this); return tmp; } /** * Decrement the row_iterator. */ template inline arma_hot typename SpMat::const_row_iterator& SpMat::const_row_iterator::operator--() { iterator_base::internal_pos--; // We have to search backwards. uword cur_col = iterator_base::internal_col; uword cur_row = internal_row; while (true) // This loop is terminated from the inside. { // Decrement the current column and see if we are now on a new row. This is a uword so a negativity check won't work. if (--cur_col > iterator_base::M->n_cols /* this means it underflew */) { cur_col = iterator_base::M->n_cols - 1; cur_row--; } // Is there anything in this new column? for (uword ind = 0; ((iterator_base::M->col_ptrs[cur_col] + ind < iterator_base::M->col_ptrs[cur_col + 1]) && (iterator_base::M->row_indices[iterator_base::M->col_ptrs[cur_col] + ind] <= cur_row)); ind++) { if (iterator_base::M->row_indices[iterator_base::M->col_ptrs[cur_col] + ind] == cur_row) { // We have successfully decremented. iterator_base::internal_col = cur_col; internal_row = cur_row; actual_pos = iterator_base::M->col_ptrs[cur_col] + ind; return *this; // Now we are done. } } } } /** * Decrement the row_iterator. */ template inline arma_hot typename SpMat::const_row_iterator SpMat::const_row_iterator::operator--(int) { typename SpMat::const_row_iterator tmp(*this); --(*this); return tmp; } template inline arma_hot bool SpMat::const_row_iterator::operator==(const const_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator!=(const const_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator==(const typename SpSubview::const_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator!=(const typename SpSubview::const_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator==(const const_row_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator!=(const const_row_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator==(const typename SpSubview::const_row_iterator& rhs) const { return (rhs.row() == row()) && (rhs.col() == iterator_base::internal_col); } template inline arma_hot bool SpMat::const_row_iterator::operator!=(const typename SpSubview::const_row_iterator& rhs) const { return (rhs.row() != row()) || (rhs.col() != iterator_base::internal_col); } /////////////////////////////////////////////////////////////////////////////// // SpMat::row_iterator implementation // /////////////////////////////////////////////////////////////////////////////// template inline arma_hot SpValProxy > SpMat::row_iterator::operator*() { return SpValProxy >( const_row_iterator::internal_row, iterator_base::internal_col, access::rw(*iterator_base::M), &access::rw(iterator_base::M->values[const_row_iterator::actual_pos])); } template inline arma_hot typename SpMat::row_iterator& SpMat::row_iterator::operator++() { const_row_iterator::operator++(); return *this; } template inline arma_hot typename SpMat::row_iterator SpMat::row_iterator::operator++(int) { typename SpMat::row_iterator tmp(*this); const_row_iterator::operator++(); return tmp; } template inline arma_hot typename SpMat::row_iterator& SpMat::row_iterator::operator--() { const_row_iterator::operator--(); return *this; } template inline arma_hot typename SpMat::row_iterator SpMat::row_iterator::operator--(int) { typename SpMat::row_iterator tmp(*this); const_row_iterator::operator--(); return tmp; } //! @} armadillo-6.500.5/include/armadillo_bits/promote_type.hpp0000666000000000000000000003420412620272703022210 0ustar rootroot// Copyright (C) 2009-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup promote_type //! @{ template struct is_promotable { static const bool value = false; typedef T1 result; }; struct is_promotable_ok { static const bool value = true; }; template struct is_promotable : public is_promotable_ok { typedef T result; }; template struct is_promotable, T> : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable, std::complex > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable, float> : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable, double> : public is_promotable_ok { typedef std::complex result; }; #if defined(ARMA_USE_U64S64) template struct is_promotable, u64> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, s64> : public is_promotable_ok { typedef std::complex result; }; #endif #if defined(ARMA_ALLOW_LONG) template struct is_promotable, ulng_t> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, slng_t> : public is_promotable_ok { typedef std::complex result; }; #endif template struct is_promotable, s32> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, u32> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, s16> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, u16> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, s8> : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable, u8> : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; #endif #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef u32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef u32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; // s32 ? template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; // s32 ? template<> struct is_promotable : public is_promotable_ok { typedef u16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s8 result; }; // s16 ? // // mirrored versions template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable, std::complex > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; #if defined(ARMA_USE_U64S64) template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; #endif #if defined(ARMA_ALLOW_LONG) template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; #endif template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template struct is_promotable > : public is_promotable_ok { typedef std::complex result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; template<> struct is_promotable : public is_promotable_ok { typedef double result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; template<> struct is_promotable : public is_promotable_ok { typedef float result; }; #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef u64 result; }; #endif #if defined(ARMA_USE_U64S64) template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s64 result; }; #endif template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef u32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s32 result; }; // float ? template<> struct is_promotable : public is_promotable_ok { typedef u32 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; // s32 ? template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s16 result; }; // s32 ? template<> struct is_promotable : public is_promotable_ok { typedef u16 result; }; template<> struct is_promotable : public is_promotable_ok { typedef s8 result; }; // s16 ? template struct promote_type { inline static void check() { arma_type_check(( is_promotable::value == false )); } typedef typename is_promotable::result result; }; template struct eT_promoter { typedef typename promote_type::result eT; }; //! @} armadillo-6.500.5/include/armadillo_bits/op_find_meat.hpp0000666000000000000000000003565512620272703022121 0ustar rootroot// Copyright (C) 2010-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_find //! @{ template inline uword op_find::helper ( Mat& indices, const Base& X ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy A(X.get_ref()); const uword n_elem = A.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type PA = A.get_ea(); for(uword i=0; i inline uword op_find::helper ( Mat& indices, const mtOp& X, const typename arma_op_rel_only::result junk1, const typename arma_not_cx::result junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename T1::elem_type eT; const eT val = X.aux; const Proxy A(X.m); const uword n_elem = A.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; if(Proxy::prefer_at_accessor == false) { typename Proxy::ea_type PA = A.get_ea(); uword i,j; for(i=0, j=1; j < n_elem; i+=2, j+=2) { const eT tpi = PA[i]; const eT tpj = PA[j]; bool not_zero_i; bool not_zero_j; if(is_same_type::yes) { not_zero_i = (val < tpi); } else if(is_same_type::yes) { not_zero_i = (tpi < val); } else if(is_same_type::yes) { not_zero_i = (val > tpi); } else if(is_same_type::yes) { not_zero_i = (tpi > val); } else if(is_same_type::yes) { not_zero_i = (val <= tpi); } else if(is_same_type::yes) { not_zero_i = (tpi <= val); } else if(is_same_type::yes) { not_zero_i = (val >= tpi); } else if(is_same_type::yes) { not_zero_i = (tpi >= val); } else if(is_same_type::yes) { not_zero_i = (tpi == val); } else if(is_same_type::yes) { not_zero_i = (tpi != val); } else not_zero_i = false; if(is_same_type::yes) { not_zero_j = (val < tpj); } else if(is_same_type::yes) { not_zero_j = (tpj < val); } else if(is_same_type::yes) { not_zero_j = (val > tpj); } else if(is_same_type::yes) { not_zero_j = (tpj > val); } else if(is_same_type::yes) { not_zero_j = (val <= tpj); } else if(is_same_type::yes) { not_zero_j = (tpj <= val); } else if(is_same_type::yes) { not_zero_j = (val >= tpj); } else if(is_same_type::yes) { not_zero_j = (tpj >= val); } else if(is_same_type::yes) { not_zero_j = (tpj == val); } else if(is_same_type::yes) { not_zero_j = (tpj != val); } else not_zero_j = false; if(not_zero_i == true) { indices_mem[n_nz] = i; ++n_nz; } if(not_zero_j == true) { indices_mem[n_nz] = j; ++n_nz; } } if(i < n_elem) { bool not_zero; const eT tmp = PA[i]; if(is_same_type::yes) { not_zero = (val < tmp); } else if(is_same_type::yes) { not_zero = (tmp < val); } else if(is_same_type::yes) { not_zero = (val > tmp); } else if(is_same_type::yes) { not_zero = (tmp > val); } else if(is_same_type::yes) { not_zero = (val <= tmp); } else if(is_same_type::yes) { not_zero = (tmp <= val); } else if(is_same_type::yes) { not_zero = (val >= tmp); } else if(is_same_type::yes) { not_zero = (tmp >= val); } else if(is_same_type::yes) { not_zero = (tmp == val); } else if(is_same_type::yes) { not_zero = (tmp != val); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } } } else { const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); uword i = 0; for(uword col=0; col < n_cols; ++col) for(uword row=0; row < n_rows; ++row) { const eT tmp = A.at(row,col); bool not_zero; if(is_same_type::yes) { not_zero = (val < tmp); } else if(is_same_type::yes) { not_zero = (tmp < val); } else if(is_same_type::yes) { not_zero = (val > tmp); } else if(is_same_type::yes) { not_zero = (tmp > val); } else if(is_same_type::yes) { not_zero = (val <= tmp); } else if(is_same_type::yes) { not_zero = (tmp <= val); } else if(is_same_type::yes) { not_zero = (val >= tmp); } else if(is_same_type::yes) { not_zero = (tmp >= val); } else if(is_same_type::yes) { not_zero = (tmp == val); } else if(is_same_type::yes) { not_zero = (tmp != val); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } ++i; } } return n_nz; } template inline uword op_find::helper ( Mat& indices, const mtOp& X, const typename arma_op_rel_only::result junk1, const typename arma_cx_only::result junk2 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); typedef typename T1::elem_type eT; typedef typename Proxy::ea_type ea_type; const eT val = X.aux; const Proxy A(X.m); ea_type PA = A.get_ea(); const uword n_elem = A.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; if(Proxy::prefer_at_accessor == false) { for(uword i=0; i::yes) { not_zero = (tmp == val); } else if(is_same_type::yes) { not_zero = (tmp != val); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } } } else { const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); uword i = 0; for(uword col=0; col::yes) { not_zero = (tmp == val); } else if(is_same_type::yes) { not_zero = (tmp != val); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } i++; } } return n_nz; } template inline uword op_find::helper ( Mat& indices, const mtGlue& X, const typename arma_glue_rel_only::result junk1, const typename arma_not_cx::result junk2, const typename arma_not_cx::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); const uword n_elem = B.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; for(uword i=0; i::yes) { not_zero = (tmp1 < tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 > tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 <= tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 >= tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 == tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 != tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 && tmp2); } else if(is_same_type::yes) { not_zero = (tmp1 || tmp2); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } } return n_nz; } template inline uword op_find::helper ( Mat& indices, const mtGlue& X, const typename arma_glue_rel_only::result junk1, const typename arma_cx_only::result junk2, const typename arma_cx_only::result junk3 ) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); arma_ignore(junk3); typedef typename Proxy::ea_type ea_type1; typedef typename Proxy::ea_type ea_type2; const Proxy A(X.A); const Proxy B(X.B); arma_debug_assert_same_size(A, B, "relational operator"); ea_type1 PA = A.get_ea(); ea_type2 PB = B.get_ea(); const uword n_elem = B.get_n_elem(); indices.set_size(n_elem, 1); uword* indices_mem = indices.memptr(); uword n_nz = 0; if(Proxy::prefer_at_accessor == false) { for(uword i=0; i::yes) { not_zero = (PA[i] == PB[i]); } else if(is_same_type::yes) { not_zero = (PA[i] != PB[i]); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } } } else { const uword n_rows = A.get_n_rows(); const uword n_cols = A.get_n_cols(); uword i = 0; for(uword col=0; col::yes) { not_zero = (A.at(row,col) == B.at(row,col)); } else if(is_same_type::yes) { not_zero = (A.at(row,col) != B.at(row,col)); } else not_zero = false; if(not_zero == true) { indices_mem[n_nz] = i; ++n_nz; } i++; } } return n_nz; } template inline void op_find::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); const uword k = X.aux_uword_a; const uword type = X.aux_uword_b; Mat indices; const uword n_nz = op_find::helper(indices, X.m); if(n_nz > 0) { if(type == 0) // "first" { out = (k > 0 && k <= n_nz) ? indices.rows(0, k-1 ) : indices.rows(0, n_nz-1); } else // "last" { out = (k > 0 && k <= n_nz) ? indices.rows(n_nz-k, n_nz-1) : indices.rows(0, n_nz-1); } } else { out.set_size(0,1); // empty column vector } } // template inline void op_find_simple::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); Mat indices; const uword n_nz = op_find::helper(indices, X.m); out.steal_mem_col(indices, n_nz); } // template inline void op_find_finite::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); const Proxy P(X.m); const uword n_elem = P.get_n_elem(); Mat indices(n_elem,1); uword* indices_mem = indices.memptr(); uword count = 0; if(Proxy::prefer_at_accessor == false) { const typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i inline void op_find_nonfinite::apply(Mat& out, const mtOp& X) { arma_extra_debug_sigprint(); const Proxy P(X.m); const uword n_elem = P.get_n_elem(); Mat indices(n_elem,1); uword* indices_mem = indices.memptr(); uword count = 0; if(Proxy::prefer_at_accessor == false) { const typename Proxy::ea_type Pea = P.get_ea(); for(uword i=0; i inline void op_mean::apply(Mat& out, const Op& in) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const uword dim = in.aux_uword_a; arma_debug_check( (dim > 1), "mean(): parameter 'dim' must be 0 or 1" ); const Proxy P(in.m); if(P.is_alias(out) == false) { op_mean::apply_noalias(out, P, dim); } else { Mat tmp; op_mean::apply_noalias(tmp, P, dim); out.steal_mem(tmp); } } template inline void op_mean::apply_noalias(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); if(is_Mat::stored_type>::value) { op_mean::apply_noalias_unwrap(out, P, dim); } else { op_mean::apply_noalias_proxy(out, P, dim); } } template inline void op_mean::apply_noalias_unwrap(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; typedef typename Proxy::stored_type P_stored_type; const unwrap tmp(P.Q); const typename unwrap::stored_type& X = tmp.M; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; if(dim == 0) { out.set_size((X_n_rows > 0) ? 1 : 0, X_n_cols); if(X_n_rows == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col < X_n_cols; ++col) { out_mem[col] = op_mean::direct_mean( X.colptr(col), X_n_rows ); } } else if(dim == 1) { out.zeros(X_n_rows, (X_n_cols > 0) ? 1 : 0); if(X_n_cols == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col < X_n_cols; ++col) { const eT* col_mem = X.colptr(col); for(uword row=0; row < X_n_rows; ++row) { out_mem[row] += col_mem[row]; } } out /= T(X_n_cols); for(uword row=0; row < X_n_rows; ++row) { if(arma_isfinite(out_mem[row]) == false) { out_mem[row] = op_mean::direct_mean_robust( X, row ); } } } } template arma_hot inline void op_mean::apply_noalias_proxy(Mat& out, const Proxy& P, const uword dim) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; const uword P_n_rows = P.get_n_rows(); const uword P_n_cols = P.get_n_cols(); if(dim == 0) { out.set_size((P_n_rows > 0) ? 1 : 0, P_n_cols); if(P_n_rows == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col < P_n_cols; ++col) { eT val1 = eT(0); eT val2 = eT(0); uword i,j; for(i=0, j=1; j < P_n_rows; i+=2, j+=2) { val1 += P.at(i,col); val2 += P.at(j,col); } if(i < P_n_rows) { val1 += P.at(i,col); } out_mem[col] = (val1 + val2) / T(P_n_rows); } } else if(dim == 1) { out.zeros(P_n_rows, (P_n_cols > 0) ? 1 : 0); if(P_n_cols == 0) { return; } eT* out_mem = out.memptr(); for(uword col=0; col < P_n_cols; ++col) for(uword row=0; row < P_n_rows; ++row) { out_mem[row] += P.at(row,col); } out /= T(P_n_cols); } if(out.is_finite() == false) { // TODO: replace with dedicated handling to avoid unwrapping op_mean::apply_noalias_unwrap(out, P, dim); } } template inline eT op_mean::direct_mean(const eT* const X, const uword n_elem) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const eT result = arrayops::accumulate(X, n_elem) / T(n_elem); return arma_isfinite(result) ? result : op_mean::direct_mean_robust(X, n_elem); } template inline eT op_mean::direct_mean_robust(const eT* const X, const uword n_elem) { arma_extra_debug_sigprint(); // use an adapted form of the mean finding algorithm from the running_stat class typedef typename get_pod_type::result T; uword i,j; eT r_mean = eT(0); for(i=0, j=1; j inline eT op_mean::direct_mean(const Mat& X, const uword row) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_cols = X.n_cols; eT val = eT(0); uword i,j; for(i=0, j=1; j < X_n_cols; i+=2, j+=2) { val += X.at(row,i); val += X.at(row,j); } if(i < X_n_cols) { val += X.at(row,i); } const eT result = val / T(X_n_cols); return arma_isfinite(result) ? result : op_mean::direct_mean_robust(X, row); } template inline eT op_mean::direct_mean_robust(const Mat& X, const uword row) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_cols = X.n_cols; eT r_mean = eT(0); for(uword col=0; col < X_n_cols; ++col) { r_mean = r_mean + (X.at(row,col) - r_mean)/T(col+1); } return r_mean; } template inline eT op_mean::mean_all(const subview& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword X_n_elem = X.n_elem; if(X_n_elem == 0) { arma_debug_check(true, "mean(): object has no elements"); return Datum::nan; } eT val = eT(0); if(X_n_rows == 1) { const Mat& A = X.m; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_col_p1 = start_col + X_n_cols; uword i,j; for(i=start_col, j=start_col+1; j < end_col_p1; i+=2, j+=2) { val += A.at(start_row, i); val += A.at(start_row, j); } if(i < end_col_p1) { val += A.at(start_row, i); } } else { for(uword col=0; col < X_n_cols; ++col) { val += arrayops::accumulate(X.colptr(col), X_n_rows); } } const eT result = val / T(X_n_elem); return arma_isfinite(result) ? result : op_mean::mean_all_robust(X); } template inline eT op_mean::mean_all_robust(const subview& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_rows = X.n_rows; const uword X_n_cols = X.n_cols; const uword start_row = X.aux_row1; const uword start_col = X.aux_col1; const uword end_row_p1 = start_row + X_n_rows; const uword end_col_p1 = start_col + X_n_cols; const Mat& A = X.m; eT r_mean = eT(0); if(X_n_rows == 1) { uword i=0; for(uword col = start_col; col < end_col_p1; ++col, ++i) { r_mean = r_mean + (A.at(start_row,col) - r_mean)/T(i+1); } } else { uword i=0; for(uword col = start_col; col < end_col_p1; ++col) for(uword row = start_row; row < end_row_p1; ++row, ++i) { r_mean = r_mean + (A.at(row,col) - r_mean)/T(i+1); } } return r_mean; } template inline eT op_mean::mean_all(const diagview& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_elem = X.n_elem; if(X_n_elem == 0) { arma_debug_check(true, "mean(): object has no elements"); return Datum::nan; } eT val = eT(0); for(uword i=0; i inline eT op_mean::mean_all_robust(const diagview& X) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; const uword X_n_elem = X.n_elem; eT r_mean = eT(0); for(uword i=0; i inline typename T1::elem_type op_mean::mean_all(const Base& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const unwrap tmp(X.get_ref()); const Mat& A = tmp.M; const uword A_n_elem = A.n_elem; if(A_n_elem == 0) { arma_debug_check(true, "mean(): object has no elements"); return Datum::nan; } return op_mean::direct_mean(A.memptr(), A_n_elem); } template arma_inline eT op_mean::robust_mean(const eT A, const eT B) { return A + (B - A)/eT(2); } template arma_inline std::complex op_mean::robust_mean(const std::complex& A, const std::complex& B) { return A + (B - A)/T(2); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_trimat.hpp0000666000000000000000000000151012620272703021437 0ustar rootroot// Copyright (C) 2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_trimat //! @{ template arma_inline const Op trimatu(const Base& X) { arma_extra_debug_sigprint(); return Op(X.get_ref(), 0, 0); } template arma_inline const Op trimatl(const Base& X) { arma_extra_debug_sigprint(); return Op(X.get_ref(), 1, 0); } //! @} armadillo-6.500.5/include/armadillo_bits/restrictors.hpp0000666000000000000000000002254712620272703022054 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup restrictors //! @{ // structures for template based restrictions of input/output arguments // (part of the SFINAE approach) // http://en.wikipedia.org/wiki/SFINAE template struct arma_scalar_only { }; template<> struct arma_scalar_only { typedef u8 result; }; template<> struct arma_scalar_only { typedef s8 result; }; template<> struct arma_scalar_only { typedef u16 result; }; template<> struct arma_scalar_only { typedef s16 result; }; template<> struct arma_scalar_only { typedef u32 result; }; template<> struct arma_scalar_only { typedef s32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_scalar_only { typedef u64 result; }; template<> struct arma_scalar_only { typedef s64 result; }; #endif template<> struct arma_scalar_only { typedef float result; }; template<> struct arma_scalar_only { typedef double result; }; #if defined(ARMA_ALLOW_LONG) template<> struct arma_scalar_only { typedef ulng_t result; }; template<> struct arma_scalar_only { typedef slng_t result; }; #endif template struct arma_scalar_only< std::complex > { typedef std::complex result; }; template struct arma_integral_only { }; template<> struct arma_integral_only { typedef u8 result; }; template<> struct arma_integral_only { typedef s8 result; }; template<> struct arma_integral_only { typedef u16 result; }; template<> struct arma_integral_only { typedef s16 result; }; template<> struct arma_integral_only { typedef u32 result; }; template<> struct arma_integral_only { typedef s32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_integral_only { typedef u64 result; }; template<> struct arma_integral_only { typedef s64 result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct arma_integral_only { typedef ulng_t result; }; template<> struct arma_integral_only { typedef slng_t result; }; #endif template struct arma_unsigned_integral_only { }; template<> struct arma_unsigned_integral_only { typedef u8 result; }; template<> struct arma_unsigned_integral_only { typedef u16 result; }; template<> struct arma_unsigned_integral_only { typedef u32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_unsigned_integral_only { typedef u64 result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct arma_unsigned_integral_only { typedef ulng_t result; }; #endif template struct arma_signed_integral_only { }; template<> struct arma_signed_integral_only { typedef s8 result; }; template<> struct arma_signed_integral_only { typedef s16 result; }; template<> struct arma_signed_integral_only { typedef s32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_signed_integral_only { typedef s64 result; }; #endif #if defined(ARMA_ALLOW_LONG) template<> struct arma_signed_integral_only { typedef slng_t result; }; #endif template struct arma_signed_only { }; template<> struct arma_signed_only { typedef s8 result; }; template<> struct arma_signed_only { typedef s16 result; }; template<> struct arma_signed_only { typedef s32 result; }; #if defined(ARMA_USE_U64S64) template<> struct arma_signed_only { typedef s64 result; }; #endif template<> struct arma_signed_only { typedef float result; }; template<> struct arma_signed_only { typedef double result; }; #if defined(ARMA_ALLOW_LONG) template<> struct arma_signed_only { typedef slng_t result; }; #endif template struct arma_signed_only< std::complex > { typedef std::complex result; }; template struct arma_real_only { }; template<> struct arma_real_only { typedef float result; }; template<> struct arma_real_only { typedef double result; }; template struct arma_real_or_cx_only { }; template<> struct arma_real_or_cx_only< float > { typedef float result; }; template<> struct arma_real_or_cx_only< double > { typedef double result; }; template<> struct arma_real_or_cx_only< std::complex > { typedef std::complex result; }; template<> struct arma_real_or_cx_only< std::complex > { typedef std::complex result; }; template struct arma_cx_only { }; template<> struct arma_cx_only< std::complex > { typedef std::complex result; }; template<> struct arma_cx_only< std::complex > { typedef std::complex result; }; template struct arma_not_cx { typedef T result; }; template struct arma_not_cx< std::complex > { }; template struct arma_blas_type_only { }; template<> struct arma_blas_type_only< float > { typedef float result; }; template<> struct arma_blas_type_only< double > { typedef double result; }; template<> struct arma_blas_type_only< std::complex > { typedef std::complex result; }; template<> struct arma_blas_type_only< std::complex > { typedef std::complex result; }; template struct arma_not_blas_type { typedef T result; }; template<> struct arma_not_blas_type< float > { }; template<> struct arma_not_blas_type< double > { }; template<> struct arma_not_blas_type< std::complex > { }; template<> struct arma_not_blas_type< std::complex > { }; template struct arma_op_rel_only { }; template<> struct arma_op_rel_only< op_rel_lt_pre > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_lt_post > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_gt_pre > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_gt_post > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_lteq_pre > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_lteq_post > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_gteq_pre > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_gteq_post > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_eq > { typedef int result; }; template<> struct arma_op_rel_only< op_rel_noteq > { typedef int result; }; template struct arma_not_op_rel { typedef int result; }; template<> struct arma_not_op_rel< op_rel_lt_pre > { }; template<> struct arma_not_op_rel< op_rel_lt_post > { }; template<> struct arma_not_op_rel< op_rel_gt_pre > { }; template<> struct arma_not_op_rel< op_rel_gt_post > { }; template<> struct arma_not_op_rel< op_rel_lteq_pre > { }; template<> struct arma_not_op_rel< op_rel_lteq_post > { }; template<> struct arma_not_op_rel< op_rel_gteq_pre > { }; template<> struct arma_not_op_rel< op_rel_gteq_post > { }; template<> struct arma_not_op_rel< op_rel_eq > { }; template<> struct arma_not_op_rel< op_rel_noteq > { }; template struct arma_glue_rel_only { }; template<> struct arma_glue_rel_only< glue_rel_lt > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_gt > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_lteq > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_gteq > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_eq > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_noteq > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_and > { typedef int result; }; template<> struct arma_glue_rel_only< glue_rel_or > { typedef int result; }; template struct arma_Mat_Col_Row_only { }; template struct arma_Mat_Col_Row_only< Mat > { typedef Mat result; }; template struct arma_Mat_Col_Row_only< Col > { typedef Col result; }; template struct arma_Mat_Col_Row_only< Row > { typedef Row result; }; template struct arma_Cube_only { }; template struct arma_Cube_only< Cube > { typedef Cube result; }; template struct arma_SpMat_SpCol_SpRow_only { }; template struct arma_SpMat_SpCol_SpRow_only< SpMat > { typedef SpMat result; }; template struct arma_SpMat_SpCol_SpRow_only< SpCol > { typedef SpCol result; }; template struct arma_SpMat_SpCol_SpRow_only< SpRow > { typedef SpRow result; }; template struct enable_if { }; template<> struct enable_if { typedef int result; }; template struct enable_if2 { }; template< typename result_type > struct enable_if2 { typedef result_type result; }; //! @} armadillo-6.500.5/include/armadillo_bits/Gen_meat.hpp0000666000000000000000000001665512620272703021213 0ustar rootroot// Copyright (C) 2011-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Gen //! @{ template arma_inline Gen::Gen(const uword in_n_rows, const uword in_n_cols) : n_rows(in_n_rows) , n_cols(in_n_cols) { arma_extra_debug_sigprint(); } template arma_inline Gen::~Gen() { arma_extra_debug_sigprint(); } template arma_inline typename T1::elem_type Gen::generate() { typedef typename T1::elem_type eT; if(is_same_type::yes) { return eT(1); } else if(is_same_type::yes) { return eT(0); } else if(is_same_type::yes) { return eT(arma_rng::randu()); } else if(is_same_type::yes) { return eT(arma_rng::randn()); } else { return eT(); } } template arma_inline typename T1::elem_type Gen::operator[](const uword ii) const { typedef typename T1::elem_type eT; if(is_same_type::yes) { return ((ii % n_rows) == (ii / n_rows)) ? eT(1) : eT(0); } else { return Gen::generate(); } } template arma_inline typename T1::elem_type Gen::at(const uword row, const uword col) const { typedef typename T1::elem_type eT; if(is_same_type::yes) { return (row == col) ? eT(1) : eT(0); } else { return Gen::generate(); } } template arma_inline typename T1::elem_type Gen::at_alt(const uword ii) const { return operator[](ii); } template inline void Gen::apply(Mat& out) const { arma_extra_debug_sigprint(); // NOTE: we're assuming that the matrix has already been set to the correct size; // this is done by either the Mat contructor or operator=() if(is_same_type::yes) { out.eye(); } else if(is_same_type::yes) { out.ones(); } else if(is_same_type::yes) { out.zeros(); } else if(is_same_type::yes) { out.randu(); } else if(is_same_type::yes) { out.randn(); } } template inline void Gen::apply_inplace_plus(Mat& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addition"); typedef typename T1::elem_type eT; if(is_same_type::yes) { const uword N = (std::min)(n_rows, n_cols); for(uword iq=0; iq < N; ++iq) { out.at(iq,iq) += eT(1); } } else { eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword iq,jq; for(iq=0, jq=1; jq < n_elem; iq+=2, jq+=2) { const eT tmp_i = Gen::generate(); const eT tmp_j = Gen::generate(); out_mem[iq] += tmp_i; out_mem[jq] += tmp_j; } if(iq < n_elem) { out_mem[iq] += Gen::generate(); } } } template inline void Gen::apply_inplace_minus(Mat& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subtraction"); typedef typename T1::elem_type eT; if(is_same_type::yes) { const uword N = (std::min)(n_rows, n_cols); for(uword iq=0; iq < N; ++iq) { out.at(iq,iq) -= eT(1); } } else { eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword iq,jq; for(iq=0, jq=1; jq < n_elem; iq+=2, jq+=2) { const eT tmp_i = Gen::generate(); const eT tmp_j = Gen::generate(); out_mem[iq] -= tmp_i; out_mem[jq] -= tmp_j; } if(iq < n_elem) { out_mem[iq] -= Gen::generate(); } } } template inline void Gen::apply_inplace_schur(Mat& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise multiplication"); typedef typename T1::elem_type eT; if(is_same_type::yes) { const uword N = (std::min)(n_rows, n_cols); for(uword iq=0; iq < N; ++iq) { for(uword row=0; row < iq; ++row) { out.at(row,iq) = eT(0); } for(uword row=iq+1; row < n_rows; ++row) { out.at(row,iq) = eT(0); } } } else { eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword iq,jq; for(iq=0, jq=1; jq < n_elem; iq+=2, jq+=2) { const eT tmp_i = Gen::generate(); const eT tmp_j = Gen::generate(); out_mem[iq] *= tmp_i; out_mem[jq] *= tmp_j; } if(iq < n_elem) { out_mem[iq] *= Gen::generate(); } } } template inline void Gen::apply_inplace_div(Mat& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "element-wise division"); typedef typename T1::elem_type eT; if(is_same_type::yes) { const uword N = (std::min)(n_rows, n_cols); for(uword iq=0; iq < N; ++iq) { const eT zero = eT(0); for(uword row=0; row < iq; ++row) { out.at(row,iq) /= zero; } for(uword row=iq+1; row < n_rows; ++row) { out.at(row,iq) /= zero; } } } else { eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword iq,jq; for(iq=0, jq=1; jq < n_elem; iq+=2, jq+=2) { const eT tmp_i = Gen::generate(); const eT tmp_j = Gen::generate(); out_mem[iq] /= tmp_i; out_mem[jq] /= tmp_j; } if(iq < n_elem) { out_mem[iq] /= Gen::generate(); } } } template inline void Gen::apply(subview& out) const { arma_extra_debug_sigprint(); // NOTE: we're assuming that the submatrix has the same dimensions as the Gen object // this is checked by subview::operator=() if(is_same_type::yes) { out.eye(); } else if(is_same_type::yes) { out.ones(); } else if(is_same_type::yes) { out.zeros(); } else if(is_same_type::yes) { out.randu(); } else if(is_same_type::yes) { out.randn(); } } //! @} armadillo-6.500.5/include/armadillo_bits/GenCube_meat.hpp0000666000000000000000000001206712620272703022003 0ustar rootroot// Copyright (C) 2011-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup GenCube //! @{ template arma_inline GenCube::GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices) : n_rows (in_n_rows ) , n_cols (in_n_cols ) , n_slices(in_n_slices) { arma_extra_debug_sigprint(); } template arma_inline GenCube::~GenCube() { arma_extra_debug_sigprint(); } template arma_inline eT GenCube::generate() { if(is_same_type::yes) { return eT(1); } else if(is_same_type::yes) { return eT(0); } else if(is_same_type::yes) { return eT(arma_rng::randu()); } else if(is_same_type::yes) { return eT(arma_rng::randn()); } else { return eT(); } } template arma_inline eT GenCube::operator[](const uword) const { return GenCube::generate(); } template arma_inline eT GenCube::at(const uword, const uword, const uword) const { return GenCube::generate(); } template arma_inline eT GenCube::at_alt(const uword) const { return GenCube::generate(); } template inline void GenCube::apply(Cube& out) const { arma_extra_debug_sigprint(); // NOTE: we're assuming that the cube has already been set to the correct size; // this is done by either the Cube contructor or operator=() if(is_same_type::yes) { out.ones(); } else if(is_same_type::yes) { out.zeros(); } else if(is_same_type::yes) { out.randu(); } else if(is_same_type::yes) { out.randn(); } } template inline void GenCube::apply_inplace_plus(Cube& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "addition"); eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword i,j; for(i=0, j=1; j::generate(); const eT tmp_j = GenCube::generate(); out_mem[i] += tmp_i; out_mem[j] += tmp_j; } if(i < n_elem) { out_mem[i] += GenCube::generate(); } } template inline void GenCube::apply_inplace_minus(Cube& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "subtraction"); eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword i,j; for(i=0, j=1; j::generate(); const eT tmp_j = GenCube::generate(); out_mem[i] -= tmp_i; out_mem[j] -= tmp_j; } if(i < n_elem) { out_mem[i] -= GenCube::generate(); } } template inline void GenCube::apply_inplace_schur(Cube& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise multiplication"); eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword i,j; for(i=0, j=1; j::generate(); const eT tmp_j = GenCube::generate(); out_mem[i] *= tmp_i; out_mem[j] *= tmp_j; } if(i < n_elem) { out_mem[i] *= GenCube::generate(); } } template inline void GenCube::apply_inplace_div(Cube& out) const { arma_extra_debug_sigprint(); arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows, n_cols, n_slices, "element-wise division"); eT* out_mem = out.memptr(); const uword n_elem = out.n_elem; uword i,j; for(i=0, j=1; j::generate(); const eT tmp_j = GenCube::generate(); out_mem[i] /= tmp_i; out_mem[j] /= tmp_j; } if(i < n_elem) { out_mem[i] /= GenCube::generate(); } } //! @} armadillo-6.500.5/include/armadillo_bits/subview_elem1_meat.hpp0000666000000000000000000005136512622544541023252 0ustar rootroot// Copyright (C) 2010-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_elem1 //! @{ template inline subview_elem1::~subview_elem1() { arma_extra_debug_sigprint(); } template arma_inline subview_elem1::subview_elem1(const Mat& in_m, const Base& in_a) : m(in_m) , a(in_a) { arma_extra_debug_sigprint(); } template arma_inline subview_elem1::subview_elem1(const Cube& in_q, const Base& in_a) : fake_m( const_cast< eT* >(in_q.memptr()), in_q.n_elem, 1, false ) , m( fake_m ) , a( in_a ) { arma_extra_debug_sigprint(); } template template inline void subview_elem1::inplace_op(const eT val) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const unwrap_check_mixed tmp(a.get_ref(), m_local); const umat& aa = tmp.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = val; m_mem[jj] = val; } if(is_same_type::yes) { m_mem[ii] += val; m_mem[jj] += val; } if(is_same_type::yes) { m_mem[ii] -= val; m_mem[jj] -= val; } if(is_same_type::yes) { m_mem[ii] *= val; m_mem[jj] *= val; } if(is_same_type::yes) { m_mem[ii] /= val; m_mem[jj] /= val; } } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = val; } if(is_same_type::yes) { m_mem[ii] += val; } if(is_same_type::yes) { m_mem[ii] -= val; } if(is_same_type::yes) { m_mem[ii] *= val; } if(is_same_type::yes) { m_mem[ii] /= val; } } } template template inline void subview_elem1::inplace_op(const subview_elem1& x) { arma_extra_debug_sigprint(); subview_elem1& s = *this; if(&(s.m) == &(x.m)) { arma_extra_debug_print("subview_elem1::inplace_op(): aliasing detected"); const Mat tmp(x); if(is_same_type::yes) { s.operator= (tmp); } if(is_same_type::yes) { s.operator+=(tmp); } if(is_same_type::yes) { s.operator-=(tmp); } if(is_same_type::yes) { s.operator%=(tmp); } if(is_same_type::yes) { s.operator/=(tmp); } } else { Mat& s_m_local = const_cast< Mat& >(s.m); const Mat& x_m_local = x.m; const unwrap_check_mixed s_tmp(s.a.get_ref(), s_m_local); const unwrap_check_mixed x_tmp(x.a.get_ref(), s_m_local); const umat& s_aa = s_tmp.M; const umat& x_aa = x_tmp.M; arma_debug_check ( ( ((s_aa.is_vec() == false) && (s_aa.is_empty() == false)) || ((x_aa.is_vec() == false) && (x_aa.is_empty() == false)) ), "Mat::elem(): given object is not a vector" ); const uword* s_aa_mem = s_aa.memptr(); const uword* x_aa_mem = x_aa.memptr(); const uword s_aa_n_elem = s_aa.n_elem; arma_debug_check( (s_aa_n_elem != x_aa.n_elem), "Mat::elem(): size mismatch" ); eT* s_m_mem = s_m_local.memptr(); const uword s_m_n_elem = s_m_local.n_elem; const eT* x_m_mem = x_m_local.memptr(); const uword x_m_n_elem = x_m_local.n_elem; uword iq,jq; for(iq=0, jq=1; jq < s_aa_n_elem; iq+=2, jq+=2) { const uword s_ii = s_aa_mem[iq]; const uword s_jj = s_aa_mem[jq]; const uword x_ii = x_aa_mem[iq]; const uword x_jj = x_aa_mem[jq]; arma_debug_check ( (s_ii >= s_m_n_elem) || (s_jj >= s_m_n_elem) || (x_ii >= x_m_n_elem) || (x_jj >= x_m_n_elem), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { s_m_mem[s_ii] = x_m_mem[x_ii]; s_m_mem[s_jj] = x_m_mem[x_jj]; } if(is_same_type::yes) { s_m_mem[s_ii] += x_m_mem[x_ii]; s_m_mem[s_jj] += x_m_mem[x_jj]; } if(is_same_type::yes) { s_m_mem[s_ii] -= x_m_mem[x_ii]; s_m_mem[s_jj] -= x_m_mem[x_jj]; } if(is_same_type::yes) { s_m_mem[s_ii] *= x_m_mem[x_ii]; s_m_mem[s_jj] *= x_m_mem[x_jj]; } if(is_same_type::yes) { s_m_mem[s_ii] /= x_m_mem[x_ii]; s_m_mem[s_jj] /= x_m_mem[x_jj]; } } if(iq < s_aa_n_elem) { const uword s_ii = s_aa_mem[iq]; const uword x_ii = x_aa_mem[iq]; arma_debug_check ( ( (s_ii >= s_m_n_elem) || (x_ii >= x_m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { s_m_mem[s_ii] = x_m_mem[x_ii]; } if(is_same_type::yes) { s_m_mem[s_ii] += x_m_mem[x_ii]; } if(is_same_type::yes) { s_m_mem[s_ii] -= x_m_mem[x_ii]; } if(is_same_type::yes) { s_m_mem[s_ii] *= x_m_mem[x_ii]; } if(is_same_type::yes) { s_m_mem[s_ii] /= x_m_mem[x_ii]; } } } } template template inline void subview_elem1::inplace_op(const Base& x) { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const unwrap_check_mixed aa_tmp(a.get_ref(), m_local); const umat& aa = aa_tmp.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; const Proxy P(x.get_ref()); arma_debug_check( (aa_n_elem != P.get_n_elem()), "Mat::elem(): size mismatch" ); const bool is_alias = P.is_alias(m); if( (is_alias == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type X = P.get_ea(); uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = X[iq]; m_mem[jj] = X[jq]; } if(is_same_type::yes) { m_mem[ii] += X[iq]; m_mem[jj] += X[jq]; } if(is_same_type::yes) { m_mem[ii] -= X[iq]; m_mem[jj] -= X[jq]; } if(is_same_type::yes) { m_mem[ii] *= X[iq]; m_mem[jj] *= X[jq]; } if(is_same_type::yes) { m_mem[ii] /= X[iq]; m_mem[jj] /= X[jq]; } } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = X[iq]; } if(is_same_type::yes) { m_mem[ii] += X[iq]; } if(is_same_type::yes) { m_mem[ii] -= X[iq]; } if(is_same_type::yes) { m_mem[ii] *= X[iq]; } if(is_same_type::yes) { m_mem[ii] /= X[iq]; } } } else { arma_extra_debug_print("subview_elem1::inplace_op(): aliasing or prefer_at_accessor detected"); const unwrap_check::stored_type> tmp(P.Q, is_alias); const Mat& M = tmp.M; const eT* X = M.memptr(); uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = X[iq]; m_mem[jj] = X[jq]; } if(is_same_type::yes) { m_mem[ii] += X[iq]; m_mem[jj] += X[jq]; } if(is_same_type::yes) { m_mem[ii] -= X[iq]; m_mem[jj] -= X[jq]; } if(is_same_type::yes) { m_mem[ii] *= X[iq]; m_mem[jj] *= X[jq]; } if(is_same_type::yes) { m_mem[ii] /= X[iq]; m_mem[jj] /= X[jq]; } } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { m_mem[ii] = X[iq]; } if(is_same_type::yes) { m_mem[ii] += X[iq]; } if(is_same_type::yes) { m_mem[ii] -= X[iq]; } if(is_same_type::yes) { m_mem[ii] *= X[iq]; } if(is_same_type::yes) { m_mem[ii] /= X[iq]; } } } } // // template arma_inline const Op,op_htrans> subview_elem1::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> subview_elem1::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> subview_elem1::st() const { return Op,op_strans>(*this); } template inline void subview_elem1::fill(const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem1::zeros() { arma_extra_debug_sigprint(); inplace_op(eT(0)); } template inline void subview_elem1::ones() { arma_extra_debug_sigprint(); inplace_op(eT(1)); } template inline void subview_elem1::randu() { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const unwrap_check_mixed tmp(a.get_ref(), m_local); const umat& aa = tmp.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); const eT val1 = eT(arma_rng::randu()); const eT val2 = eT(arma_rng::randu()); m_mem[ii] = val1; m_mem[jj] = val2; } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); m_mem[ii] = eT(arma_rng::randu()); } } template inline void subview_elem1::randn() { arma_extra_debug_sigprint(); Mat& m_local = const_cast< Mat& >(m); eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const unwrap_check_mixed tmp(a.get_ref(), m_local); const umat& aa = tmp.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; uword iq,jq; for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) { const uword ii = aa_mem[iq]; const uword jj = aa_mem[jq]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); arma_rng::randn::dual_val( m_mem[ii], m_mem[jj] ); } if(iq < aa_n_elem) { const uword ii = aa_mem[iq]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); m_mem[ii] = eT(arma_rng::randn()); } } template inline void subview_elem1::operator+= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem1::operator-= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem1::operator*= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } template inline void subview_elem1::operator/= (const eT val) { arma_extra_debug_sigprint(); inplace_op(val); } // // template template inline void subview_elem1::operator_equ(const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator= (const subview_elem1& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } //! work around compiler bugs template inline void subview_elem1::operator= (const subview_elem1& x) { arma_extra_debug_sigprint(); (*this).operator_equ(x); } template template inline void subview_elem1::operator+= (const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator-= (const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator%= (const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator/= (const subview_elem1& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator+= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator-= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator%= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } template template inline void subview_elem1::operator/= (const Base& x) { arma_extra_debug_sigprint(); inplace_op(x); } // // template inline void subview_elem1::extract(Mat& actual_out, const subview_elem1& in) { arma_extra_debug_sigprint(); const unwrap_check_mixed tmp1(in.a.get_ref(), actual_out); const umat& aa = tmp1.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; const Mat& m_local = in.m; const eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const bool alias = (&actual_out == &m_local); if(alias) { arma_extra_debug_print("subview_elem1::extract(): aliasing detected"); } Mat* tmp_out = alias ? new Mat() : 0; Mat& out = alias ? *tmp_out : actual_out; out.set_size(aa_n_elem, 1); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); out_mem[i] = m_mem[ii]; out_mem[j] = m_mem[jj]; } if(i < aa_n_elem) { const uword ii = aa_mem[i]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); out_mem[i] = m_mem[ii]; } if(alias == true) { actual_out.steal_mem(out); delete tmp_out; } } template template inline void subview_elem1::mat_inplace_op(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); const unwrap tmp1(in.a.get_ref()); const umat& aa = tmp1.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; const unwrap_check< Mat > tmp2(in.m, out); const Mat& m_local = tmp2.M; const eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; arma_debug_check( (out.n_elem != aa_n_elem), "Mat::elem(): size mismatch" ); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { out_mem[i] += m_mem[ii]; out_mem[j] += m_mem[jj]; } if(is_same_type::yes) { out_mem[i] -= m_mem[ii]; out_mem[j] -= m_mem[jj]; } if(is_same_type::yes) { out_mem[i] *= m_mem[ii]; out_mem[j] *= m_mem[jj]; } if(is_same_type::yes) { out_mem[i] /= m_mem[ii]; out_mem[j] /= m_mem[jj]; } } if(i < aa_n_elem) { const uword ii = aa_mem[i]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); if(is_same_type::yes) { out_mem[i] += m_mem[ii]; } if(is_same_type::yes) { out_mem[i] -= m_mem[ii]; } if(is_same_type::yes) { out_mem[i] *= m_mem[ii]; } if(is_same_type::yes) { out_mem[i] /= m_mem[ii]; } } } template inline void subview_elem1::plus_inplace(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); mat_inplace_op(out, in); } template inline void subview_elem1::minus_inplace(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); mat_inplace_op(out, in); } template inline void subview_elem1::schur_inplace(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); mat_inplace_op(out, in); } template inline void subview_elem1::div_inplace(Mat& out, const subview_elem1& in) { arma_extra_debug_sigprint(); mat_inplace_op(out, in); } //! @} armadillo-6.500.5/include/armadillo_bits/op_var_bones.hpp0000666000000000000000000000314212620272703022133 0ustar rootroot// Copyright (C) 2009-2012 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_var //! @{ //! Class for finding variance values of a matrix class op_var { public: template inline static void apply(Mat& out, const mtOp& in); // template inline static typename get_pod_type::result var_vec(const subview_col& X, const uword norm_type = 0); template inline static typename get_pod_type::result var_vec(const subview_row& X, const uword norm_type = 0); template inline static typename T1::pod_type var_vec(const Base& X, const uword norm_type = 0); // template inline static eT direct_var(const eT* const X, const uword N, const uword norm_type = 0); template inline static eT direct_var_robust(const eT* const X, const uword N, const uword norm_type = 0); // template inline static T direct_var(const std::complex* const X, const uword N, const uword norm_type = 0); template inline static T direct_var_robust(const std::complex* const X, const uword N, const uword norm_type = 0); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_repmat_bones.hpp0000666000000000000000000000143612620272703022637 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Dimitrios Bouzas //! \addtogroup op_repmat //! @{ class op_repmat { public: template inline static void apply_noalias(Mat& out, const obj& X, const uword copies_per_row, const uword copies_per_col); template inline static void apply(Mat& out, const Op& in); }; //! @} armadillo-6.500.5/include/armadillo_bits/glue_cross_meat.hpp0000666000000000000000000000404312620272703022633 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_cross //! @{ template inline void glue_cross::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const Proxy PA(X.A); const Proxy PB(X.B); arma_debug_check( ((PA.get_n_elem() != 3) || (PB.get_n_elem() != 3)), "cross(): input vectors must have 3 elements" ); const uword PA_n_rows = Proxy::is_row ? 1 : PA.get_n_rows(); const uword PA_n_cols = Proxy::is_col ? 1 : PA.get_n_cols(); out.set_size(PA_n_rows, PA_n_cols); eT* out_mem = out.memptr(); if( (Proxy::prefer_at_accessor == false) && (Proxy::prefer_at_accessor == false) ) { typename Proxy::ea_type A = PA.get_ea(); typename Proxy::ea_type B = PB.get_ea(); const eT ax = A[0]; const eT ay = A[1]; const eT az = A[2]; const eT bx = B[0]; const eT by = B[1]; const eT bz = B[2]; out_mem[0] = ay*bz - az*by; out_mem[1] = az*bx - ax*bz; out_mem[2] = ax*by - ay*bx; } else { const bool PA_is_col = Proxy::is_col ? true : (PA_n_cols == 1); const bool PB_is_col = Proxy::is_col ? true : (PB.get_n_cols() == 1); const eT ax = PA.at(0,0); const eT ay = PA_is_col ? PA.at(1,0) : PA.at(0,1); const eT az = PA_is_col ? PA.at(2,0) : PA.at(0,2); const eT bx = PB.at(0,0); const eT by = PB_is_col ? PB.at(1,0) : PB.at(0,1); const eT bz = PB_is_col ? PB.at(2,0) : PB.at(0,2); out_mem[0] = ay*bz - az*by; out_mem[1] = az*bx - ax*bz; out_mem[2] = ax*by - ay*bx; } } //! @} armadillo-6.500.5/include/armadillo_bits/op_max_bones.hpp0000666000000000000000000000463212620272703022135 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_max //! @{ class op_max { public: template inline static void apply(Mat& out, const Op& in); template inline static void apply_noalias(Mat& out, const Mat& X, const uword dim, const typename arma_not_cx::result* junk = 0); template inline static void apply_noalias(Mat& out, const Mat& X, const uword dim, const typename arma_cx_only::result* junk = 0); // // for non-complex numbers template inline static eT direct_max(const eT* const X, const uword N); template inline static eT direct_max(const eT* const X, const uword N, uword& index_of_max_val); template inline static eT direct_max(const Mat& X, const uword row); template inline static eT max(const subview& X); template inline static typename arma_not_cx::result max(const Base& X); template inline static typename arma_not_cx::result max_with_index(const Proxy& P, uword& index_of_max_val); // // for complex numbers template inline static std::complex direct_max(const std::complex* const X, const uword n_elem); template inline static std::complex direct_max(const std::complex* const X, const uword n_elem, uword& index_of_max_val); template inline static std::complex direct_max(const Mat< std::complex >& X, const uword row); template inline static std::complex max(const subview< std::complex >& X); template inline static typename arma_cx_only::result max(const Base& X); template inline static typename arma_cx_only::result max_with_index(const Proxy& P, uword& index_of_max_val); }; //! @} armadillo-6.500.5/include/armadillo_bits/mul_herk.hpp0000666000000000000000000003175112650172354021300 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup herk //! @{ class herk_helper { public: template inline static void inplace_conj_copy_upper_tri_to_lower_tri(Mat& C) { // under the assumption that C is a square matrix const uword N = C.n_rows; for(uword k=0; k < N; ++k) { eT* colmem = C.colptr(k); for(uword i=(k+1); i < N; ++i) { colmem[i] = std::conj( C.at(k,i) ); } } } template static arma_hot inline eT dot_conj_row(const uword n_elem, const eT* const A, const Mat& B, const uword row) { arma_extra_debug_sigprint(); typedef typename get_pod_type::result T; T val_real = T(0); T val_imag = T(0); for(uword i=0; i& X = A[i]; const std::complex& Y = B.at(row,i); const T a = X.real(); const T b = X.imag(); const T c = Y.real(); const T d = Y.imag(); val_real += (a*c) + (b*d); val_imag += (b*c) - (a*d); } return std::complex(val_real, val_imag); } }; template class herk_vec { public: template arma_hot inline static void apply ( Mat< std::complex >& C, const TA& A, const T alpha = T(1), const T beta = T(0) ) { arma_extra_debug_sigprint(); typedef std::complex eT; const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; // for beta != 0, C is assumed to be hermitian // do_trans_A == false -> C = alpha * A * A^H + beta*C // do_trans_A == true -> C = alpha * A^H * A + beta*C const eT* A_mem = A.memptr(); if(do_trans_A == false) { if(A_n_rows == 1) { const eT acc = op_cdot::direct_cdot(A_n_cols, A_mem, A_mem); if( (use_alpha == false) && (use_beta == false) ) { C[0] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C[0] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C[0] = acc + beta*C[0]; } else if( (use_alpha == true ) && (use_beta == true ) ) { C[0] = alpha*acc + beta*C[0]; } } else for(uword row_A=0; row_A < A_n_rows; ++row_A) { const eT& A_rowdata = A_mem[row_A]; for(uword k=row_A; k < A_n_rows; ++k) { const eT acc = A_rowdata * std::conj( A_mem[k] ); if( (use_alpha == false) && (use_beta == false) ) { C.at(row_A, k) = acc; if(row_A != k) { C.at(k, row_A) = std::conj(acc); } } else if( (use_alpha == true) && (use_beta == false) ) { const eT val = alpha*acc; C.at(row_A, k) = val; if(row_A != k) { C.at(k, row_A) = std::conj(val); } } else if( (use_alpha == false) && (use_beta == true) ) { C.at(row_A, k) = acc + beta*C.at(row_A, k); if(row_A != k) { C.at(k, row_A) = std::conj(acc) + beta*C.at(k, row_A); } } else if( (use_alpha == true) && (use_beta == true) ) { const eT val = alpha*acc; C.at(row_A, k) = val + beta*C.at(row_A, k); if(row_A != k) { C.at(k, row_A) = std::conj(val) + beta*C.at(k, row_A); } } } } } else if(do_trans_A == true) { if(A_n_cols == 1) { const eT acc = op_cdot::direct_cdot(A_n_rows, A_mem, A_mem); if( (use_alpha == false) && (use_beta == false) ) { C[0] = acc; } else if( (use_alpha == true ) && (use_beta == false) ) { C[0] = alpha*acc; } else if( (use_alpha == false) && (use_beta == true ) ) { C[0] = acc + beta*C[0]; } else if( (use_alpha == true ) && (use_beta == true ) ) { C[0] = alpha*acc + beta*C[0]; } } else for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const eT A_coldata = std::conj( A_mem[col_A] ); for(uword k=col_A; k < A_n_cols ; ++k) { const eT acc = A_coldata * A_mem[k]; if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A, k) = acc; if(col_A != k) { C.at(k, col_A) = std::conj(acc); } } else if( (use_alpha == true ) && (use_beta == false) ) { const eT val = alpha*acc; C.at(col_A, k) = val; if(col_A != k) { C.at(k, col_A) = std::conj(val); } } else if( (use_alpha == false) && (use_beta == true ) ) { C.at(col_A, k) = acc + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = std::conj(acc) + beta*C.at(k, col_A); } } else if( (use_alpha == true ) && (use_beta == true ) ) { const eT val = alpha*acc; C.at(col_A, k) = val + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = std::conj(val) + beta*C.at(k, col_A); } } } } } } }; template class herk_emul { public: template arma_hot inline static void apply ( Mat< std::complex >& C, const TA& A, const T alpha = T(1), const T beta = T(0) ) { arma_extra_debug_sigprint(); typedef std::complex eT; // do_trans_A == false -> C = alpha * A * A^H + beta*C // do_trans_A == true -> C = alpha * A^H * A + beta*C if(do_trans_A == false) { Mat AA; op_htrans::apply_mat_noalias(AA, A); herk_emul::apply(C, AA, alpha, beta); } else if(do_trans_A == true) { const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; for(uword col_A=0; col_A < A_n_cols; ++col_A) { // col_A is interpreted as row_A when storing the results in matrix C const eT* A_coldata = A.colptr(col_A); for(uword k=col_A; k < A_n_cols ; ++k) { const eT acc = op_cdot::direct_cdot(A_n_rows, A_coldata, A.colptr(k)); if( (use_alpha == false) && (use_beta == false) ) { C.at(col_A, k) = acc; if(col_A != k) { C.at(k, col_A) = std::conj(acc); } } else if( (use_alpha == true) && (use_beta == false) ) { const eT val = alpha*acc; C.at(col_A, k) = val; if(col_A != k) { C.at(k, col_A) = std::conj(val); } } else if( (use_alpha == false) && (use_beta == true) ) { C.at(col_A, k) = acc + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = std::conj(acc) + beta*C.at(k, col_A); } } else if( (use_alpha == true) && (use_beta == true) ) { const eT val = alpha*acc; C.at(col_A, k) = val + beta*C.at(col_A, k); if(col_A != k) { C.at(k, col_A) = std::conj(val) + beta*C.at(k, col_A); } } } } } } }; template class herk { public: template inline static void apply_blas_type( Mat >& C, const TA& A, const T alpha = T(1), const T beta = T(0) ) { arma_extra_debug_sigprint(); const uword threshold = 16; if(A.is_vec()) { // work around poor handling of vectors by herk() in ATLAS 3.8.4 and standard BLAS herk_vec::apply(C,A,alpha,beta); return; } if( (A.n_elem <= threshold) ) { herk_emul::apply(C,A,alpha,beta); } else { #if defined(ARMA_USE_ATLAS) { if(use_beta == true) { typedef typename std::complex eT; // use a temporary matrix, as we can't assume that matrix C is already symmetric Mat D(C.n_rows, C.n_cols); herk::apply_blas_type(D,A,alpha); // NOTE: assuming beta=1; this is okay for now, as currently glue_times only uses beta=1 arrayops::inplace_plus(C.memptr(), D.memptr(), C.n_elem); return; } atlas::cblas_herk ( atlas::CblasColMajor, atlas::CblasUpper, (do_trans_A) ? CblasConjTrans : atlas::CblasNoTrans, C.n_cols, (do_trans_A) ? A.n_rows : A.n_cols, (use_alpha) ? alpha : T(1), A.mem, (do_trans_A) ? A.n_rows : C.n_cols, (use_beta) ? beta : T(0), C.memptr(), C.n_cols ); herk_helper::inplace_conj_copy_upper_tri_to_lower_tri(C); } #elif defined(ARMA_USE_BLAS) { if(use_beta == true) { typedef typename std::complex eT; // use a temporary matrix, as we can't assume that matrix C is already symmetric Mat D(C.n_rows, C.n_cols); herk::apply_blas_type(D,A,alpha); // NOTE: assuming beta=1; this is okay for now, as currently glue_times only uses beta=1 arrayops::inplace_plus(C.memptr(), D.memptr(), C.n_elem); return; } arma_extra_debug_print("blas::herk()"); const char uplo = 'U'; const char trans_A = (do_trans_A) ? 'C' : 'N'; const blas_int n = blas_int(C.n_cols); const blas_int k = (do_trans_A) ? blas_int(A.n_rows) : blas_int(A.n_cols); const T local_alpha = (use_alpha) ? alpha : T(1); const T local_beta = (use_beta) ? beta : T(0); const blas_int lda = (do_trans_A) ? k : n; arma_extra_debug_print( arma_str::format("blas::herk(): trans_A = %c") % trans_A ); blas::herk ( &uplo, &trans_A, &n, &k, &local_alpha, A.mem, &lda, &local_beta, C.memptr(), &n // &ldc ); herk_helper::inplace_conj_copy_upper_tri_to_lower_tri(C); } #else { herk_emul::apply(C,A,alpha,beta); } #endif } } template inline static void apply( Mat& C, const TA& A, const eT alpha = eT(1), const eT beta = eT(0), const typename arma_not_cx::result* junk = 0 ) { arma_ignore(C); arma_ignore(A); arma_ignore(alpha); arma_ignore(beta); arma_ignore(junk); // herk() cannot be used by non-complex matrices return; } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const float alpha = float(1), const float beta = float(0) ) { herk::apply_blas_type(C,A,alpha,beta); } template arma_inline static void apply ( Mat< std::complex >& C, const TA& A, const double alpha = double(1), const double beta = double(0) ) { herk::apply_blas_type(C,A,alpha,beta); } }; //! @} armadillo-6.500.5/include/armadillo_bits/operator_relational.hpp0000666000000000000000000001616712620272703023537 0ustar rootroot// Copyright (C) 2009-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup operator_relational //! @{ // < : lt // > : gt // <= : lteq // >= : gteq // == : eq // != : noteq // && : and // || : or template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator< (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator> (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator<= (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator>= (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value), const mtGlue >::result operator== (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value), const mtGlue >::result operator!= (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator&& (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } template inline typename enable_if2 < (is_arma_type::value && is_arma_type::value && (is_cx::no) && (is_cx::no)), const mtGlue >::result operator|| (const T1& X, const T2& Y) { arma_extra_debug_sigprint(); return mtGlue( X, Y ); } // // // template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator< (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator< (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator> (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator> (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator<= (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator<= (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator>= (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < (is_arma_type::value && (is_cx::no)), const mtOp >::result operator>= (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < is_arma_type::value, const mtOp >::result operator== (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < is_arma_type::value, const mtOp >::result operator== (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < is_arma_type::value, const mtOp >::result operator!= (const typename T1::elem_type val, const T1& X) { arma_extra_debug_sigprint(); return mtOp(X, val); } template inline typename enable_if2 < is_arma_type::value, const mtOp >::result operator!= (const T1& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOp(X, val); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_inplace_trans.hpp0000666000000000000000000000404412620272703022766 0ustar rootroot// Copyright (C) 2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_inplace_trans //! @{ template inline typename enable_if2 < is_cx::no, void >::result inplace_htrans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); inplace_strans(X, method); } template inline typename enable_if2 < is_cx::yes, void >::result inplace_htrans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); const char sig = (method != NULL) ? method[0] : char(0); arma_debug_check( ((sig != 's') && (sig != 'l')), "inplace_htrans(): unknown method specified" ); const bool low_memory = (sig == 'l'); if( (low_memory == false) || (X.n_rows == X.n_cols) ) { op_htrans::apply_mat_inplace(X); } else { inplace_strans(X, method); X = conj(X); } } template inline typename enable_if2 < is_cx::no, void >::result inplace_trans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); const char sig = (method != NULL) ? method[0] : char(0); arma_debug_check( ((sig != 's') && (sig != 'l')), "inplace_trans(): unknown method specified" ); inplace_strans(X, method); } template inline typename enable_if2 < is_cx::yes, void >::result inplace_trans ( Mat& X, const char* method = "std" ) { arma_extra_debug_sigprint(); const char sig = (method != NULL) ? method[0] : char(0); arma_debug_check( ((sig != 's') && (sig != 'l')), "inplace_trans(): unknown method specified" ); inplace_htrans(X, method); } //! @} armadillo-6.500.5/include/armadillo_bits/operator_cube_minus.hpp0000666000000000000000000001106512620272703023526 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup operator_cube_minus //! @{ //! unary - template arma_inline const eOpCube operator- ( const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref()); } //! cancellation of two consecutive negations: -(-T1) template arma_inline const typename ProxyCube::stored_type& operator- ( const eOpCube& X ) { arma_extra_debug_sigprint(); return X.P.Q; } //! BaseCube - scalar template arma_inline const eOpCube operator- ( const BaseCube& X, const typename T1::elem_type k ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! scalar - BaseCube template arma_inline const eOpCube operator- ( const typename T1::elem_type k, const BaseCube& X ) { arma_extra_debug_sigprint(); return eOpCube(X.get_ref(), k); } //! complex scalar - non-complex BaseCube (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_minus_pre> operator- ( const std::complex& k, const BaseCube& X ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_minus_pre>('j', X.get_ref(), k); } //! non-complex BaseCube - complex scalar (experimental) template arma_inline const mtOpCube, T1, op_cx_scalar_minus_post> operator- ( const BaseCube& X, const std::complex& k ) { arma_extra_debug_sigprint(); return mtOpCube, T1, op_cx_scalar_minus_post>('j', X.get_ref(), k); } //! subtraction of BaseCube objects with same element type template arma_inline const eGlueCube operator- ( const BaseCube& X, const BaseCube& Y ) { arma_extra_debug_sigprint(); return eGlueCube(X.get_ref(), Y.get_ref()); } //! subtraction of BaseCube objects with different element types template inline const mtGlueCube::result, T1, T2, glue_mixed_minus> operator- ( const BaseCube< typename force_different_type::T1_result, T1>& X, const BaseCube< typename force_different_type::T2_result, T2>& Y ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT1; typedef typename T2::elem_type eT2; typedef typename promote_type::result out_eT; promote_type::check(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template arma_inline Cube operator- ( const subview_cube_each1& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_cube_each1_aux::operator_minus(X, Y.get_ref()); } template arma_inline Cube operator- ( const Base& X, const subview_cube_each1& Y ) { arma_extra_debug_sigprint(); return subview_cube_each1_aux::operator_minus(X.get_ref(), Y); } template arma_inline Cube operator- ( const subview_cube_each2& X, const Base& Y ) { arma_extra_debug_sigprint(); return subview_cube_each2_aux::operator_minus(X, Y.get_ref()); } template arma_inline Cube operator- ( const Base& X, const subview_cube_each2& Y ) { arma_extra_debug_sigprint(); return subview_cube_each2_aux::operator_minus(X.get_ref(), Y); } //! @} armadillo-6.500.5/include/armadillo_bits/include_superlu.hpp0000666000000000000000000002020612627351654022673 0ustar rootroot// This Source Code Form is a compilation of: // (1) source code written by Ryan Curtin and Conrad Sanderson, and // (2) extracts from SuperLU 4.3 source code. // This compilation is Copyright (C) 2015 National ICT Australia (NICTA) // and is subject to the terms of the Mozilla Public License, v. 2.0. // // The source code that is distinct and separate from SuperLU 4.3 source code // is Copyright (C) 2015 National ICT Australia (NICTA) // and is subject to the terms of the Mozilla Public License, v. 2.0. // // If a copy of the MPL was not distributed with this file, // You can obtain one at http://mozilla.org/MPL/2.0/. // // The original SuperLU 4.3 source code is licensed under a 3-clause BSD license, // as follows: // // Copyright (c) 2003, The Regents of the University of California, through // Lawrence Berkeley National Laboratory (subject to receipt of any required // approvals from U.S. Dept. of Energy) // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // (1) Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // (2) Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S. Dept. of // Energy nor the names of its contributors may be used to endorse or promote // products derived from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #if defined(ARMA_USE_SUPERLU) #if defined(ARMA_USE_SUPERLU_HEADERS) || defined(ARMA_SUPERLU_INCLUDE_DIR) // Since we need to suport float, double, cx_float and cx_double, // as well as preserve the sanity of the user, // we cannot simply include all the SuperLU headers due to their messy state // (duplicate definitions, pollution of global namespace, bizarro defines). // As such we are forced to include only a subset of the headers // and manually specify a few SuperLU structures and function prototypes. // // CAVEAT: // This code requires SuperLU version 4.3, // and assumes that newer 4.x versions will have no API changes. namespace arma { namespace superlu { // slu_*defs.h has int typedef'fed to int_t. I'll just write it as int for // simplicity, where I can, but supermatrix.h needs int_t. typedef int int_t; // Include supermatrix.h. This gives us SuperMatrix. // Put it in the slu namespace. // For versions of SuperLU I am familiar with, supermatrix.h does not include any other files. // Therefore, putting it in the superlu namespace is reasonably safe. // This same reasoning is true for superlu_enum_consts.h. #if defined(ARMA_SUPERLU_INCLUDE_DIR) #define ARMA_SLU_STR(x) x #define ARMA_SLU_STR2(x) ARMA_SLU_STR(x) #define ARMA_SLU_SUPERMATRIX_H ARMA_SLU_STR2(ARMA_SUPERLU_INCLUDE_DIR)ARMA_SLU_STR2(supermatrix.h) #define ARMA_SLU_SUPERLU_ENUM_CONSTS_H ARMA_SLU_STR2(ARMA_SUPERLU_INCLUDE_DIR)ARMA_SLU_STR2(superlu_enum_consts.h) #else #define ARMA_SLU_SUPERMATRIX_H supermatrix.h #define ARMA_SLU_SUPERLU_ENUM_CONSTS_H superlu_enum_consts.h #endif #include ARMA_INCFILE_WRAP(ARMA_SLU_SUPERMATRIX_H) #include ARMA_INCFILE_WRAP(ARMA_SLU_SUPERLU_ENUM_CONSTS_H) #undef ARMA_SLU_SUPERMATRIX_H #undef ARMA_SLU_SUPERLU_ENUM_CONSTS_H typedef struct { int* panel_histo; double* utime; float* ops; int TinyPivots; int RefineSteps; int expansions; } SuperLUStat_t; typedef struct { fact_t Fact; yes_no_t Equil; colperm_t ColPerm; trans_t Trans; IterRefine_t IterRefine; double DiagPivotThresh; yes_no_t SymmetricMode; yes_no_t PivotGrowth; yes_no_t ConditionNumber; rowperm_t RowPerm; int ILU_DropRule; double ILU_DropTol; double ILU_FillFactor; norm_t ILU_Norm; double ILU_FillTol; milu_t ILU_MILU; double ILU_MILU_Dim; yes_no_t ParSymbFact; yes_no_t ReplaceTinyPivot; yes_no_t SolveInitialized; yes_no_t RefineInitialized; yes_no_t PrintStat; int nnzL, nnzU; int num_lookaheads; yes_no_t lookahead_etree; yes_no_t SymPattern; } superlu_options_t; typedef struct { float for_lu; float total_needed; } mem_usage_t; } } #else // Not using any SuperLU headers, so define all required enums and structs. // // CAVEAT: // This code requires SuperLU version 4.3, // and assumes that newer 4.x versions will have no API changes. namespace arma { namespace superlu { typedef int int_t; typedef enum { SLU_NC, SLU_NCP, SLU_NR, SLU_SC, SLU_SCP, SLU_SR, SLU_DN, SLU_NR_loc } Stype_t; typedef enum { SLU_S, SLU_D, SLU_C, SLU_Z } Dtype_t; typedef enum { SLU_GE, SLU_TRLU, SLU_TRUU, SLU_TRL, SLU_TRU, SLU_SYL, SLU_SYU, SLU_HEL, SLU_HEU } Mtype_t; typedef struct { Stype_t Stype; Dtype_t Dtype; Mtype_t Mtype; int_t nrow; int_t ncol; void* Store; } SuperMatrix; typedef struct { int* panel_histo; double* utime; float* ops; int TinyPivots; int RefineSteps; int expansions; } SuperLUStat_t; typedef enum {NO, YES} yes_no_t; typedef enum {DOFACT, SamePattern, SamePattern_SameRowPerm, FACTORED} fact_t; typedef enum {NOROWPERM, LargeDiag, MY_PERMR} rowperm_t; typedef enum {NATURAL, MMD_ATA, MMD_AT_PLUS_A, COLAMD, METIS_AT_PLUS_A, PARMETIS, ZOLTAN, MY_PERMC} colperm_t; typedef enum {NOTRANS, TRANS, CONJ} trans_t; typedef enum {NOREFINE, SLU_SINGLE=1, SLU_DOUBLE, SLU_EXTRA} IterRefine_t; typedef enum {ONE_NORM, TWO_NORM, INF_NORM} norm_t; typedef enum {SILU, SMILU_1, SMILU_2, SMILU_3} milu_t; typedef struct { fact_t Fact; yes_no_t Equil; colperm_t ColPerm; trans_t Trans; IterRefine_t IterRefine; double DiagPivotThresh; yes_no_t SymmetricMode; yes_no_t PivotGrowth; yes_no_t ConditionNumber; rowperm_t RowPerm; int ILU_DropRule; double ILU_DropTol; double ILU_FillFactor; norm_t ILU_Norm; double ILU_FillTol; milu_t ILU_MILU; double ILU_MILU_Dim; yes_no_t ParSymbFact; yes_no_t ReplaceTinyPivot; yes_no_t SolveInitialized; yes_no_t RefineInitialized; yes_no_t PrintStat; int nnzL, nnzU; int num_lookaheads; yes_no_t lookahead_etree; yes_no_t SymPattern; } superlu_options_t; typedef struct { float for_lu; float total_needed; } mem_usage_t; typedef struct { int_t nnz; void* nzval; int_t* rowind; int_t* colptr; } NCformat; typedef struct { int_t lda; void* nzval; } DNformat; } } #endif #endif armadillo-6.500.5/include/armadillo_bits/fn_kmeans.hpp0000666000000000000000000000302712647162534021433 0ustar rootroot// Copyright (C) 2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_kmeans //! @{ #if defined(ARMA_BAD_COMPILER) template inline bool kmeans(Mat& means, const Base&, const uword, const gmm_seed_mode&, const uword, const bool) { arma_extra_debug_sigprint(); arma_stop("kmeans(): unsupported/inadequate compiler"); means.reset(); return false; } #else template inline typename enable_if2::value, bool>::result kmeans ( Mat& means, const Base& data, const uword k, const gmm_seed_mode& seed_mode, const uword n_iter, const bool print_mode ) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; gmm_priv::gmm_diag model; const bool status = model.kmeans_wrapper(means, data.get_ref(), k, seed_mode, n_iter, print_mode); if(status == true) { means = model.means; } else { means.reset(); } return status; } #endif //! @} armadillo-6.500.5/include/armadillo_bits/wrapper_superlu.hpp0000666000000000000000000000757312627351654022744 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au // Written by Ryan Curtin #if defined(ARMA_USE_SUPERLU) //! \namespace superlu namespace for SuperLU functions namespace superlu { template inline void gssv(superlu_options_t* options, SuperMatrix* A, int* perm_c, int* perm_r, SuperMatrix* L, SuperMatrix* U, SuperMatrix* B, SuperLUStat_t* stat, int* info) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { arma_wrapper(sgssv)(options, A, perm_c, perm_r, L, U, B, stat, info); } else if(is_double::value) { arma_wrapper(dgssv)(options, A, perm_c, perm_r, L, U, B, stat, info); } else if(is_supported_complex_float::value) { arma_wrapper(cgssv)(options, A, perm_c, perm_r, L, U, B, stat, info); } else if(is_supported_complex_double::value) { arma_wrapper(zgssv)(options, A, perm_c, perm_r, L, U, B, stat, info); } } template inline void gssvx( superlu_options_t* opts, SuperMatrix* A, int* perm_c, int* perm_r, int* etree, char* equed, typename get_pod_type::result* R, typename get_pod_type::result* C, SuperMatrix* L, SuperMatrix* U, void* work, int lwork, SuperMatrix* B, SuperMatrix* X, typename get_pod_type::result* rpg, typename get_pod_type::result* rcond, typename get_pod_type::result* ferr, typename get_pod_type::result* berr, mem_usage_t* mu, SuperLUStat_t* stat, int* info ) { arma_type_check(( is_supported_blas_type::value == false )); if(is_float::value) { typedef float T; arma_wrapper(sgssvx)(opts, A, perm_c, perm_r, etree, equed, (T*)R, (T*)C, L, U, work, lwork, B, X, (T*)rpg, (T*)rcond, (T*)ferr, (T*)berr, mu, stat, info); } else if(is_double::value) { typedef double T; arma_wrapper(dgssvx)(opts, A, perm_c, perm_r, etree, equed, (T*)R, (T*)C, L, U, work, lwork, B, X, (T*)rpg, (T*)rcond, (T*)ferr, (T*)berr, mu, stat, info); } else if(is_supported_complex_float::value) { typedef float T; arma_wrapper(cgssvx)(opts, A, perm_c, perm_r, etree, equed, (T*)R, (T*)C, L, U, work, lwork, B, X, (T*)rpg, (T*)rcond, (T*)ferr, (T*)berr, mu, stat, info); } else if(is_supported_complex_double::value) { typedef double T; arma_wrapper(zgssvx)(opts, A, perm_c, perm_r, etree, equed, (T*)R, (T*)C, L, U, work, lwork, B, X, (T*)rpg, (T*)rcond, (T*)ferr, (T*)berr, mu, stat, info); } } inline void init_stat(SuperLUStat_t* stat) { arma_wrapper(StatInit)(stat); } inline void free_stat(SuperLUStat_t* stat) { arma_wrapper(StatFree)(stat); } inline void set_default_opts(superlu_options_t* opts) { arma_wrapper(set_default_options)(opts); } inline void destroy_supernode_mat(SuperMatrix* a) { arma_wrapper(Destroy_SuperNode_Matrix)(a); } inline void destroy_compcol_mat(SuperMatrix* a) { arma_wrapper(Destroy_CompCol_Matrix)(a); } inline void destroy_dense_mat(SuperMatrix* a) { arma_wrapper(Destroy_SuperMatrix_Store)(a); } inline void* malloc(size_t N) { return arma_wrapper(superlu_malloc)(N); } inline void free(void* mem) { arma_wrapper(superlu_free)(mem); } } // namespace superlu #endif armadillo-6.500.5/include/armadillo_bits/GenCube_bones.hpp0000666000000000000000000000335512620272703022163 0ustar rootroot// Copyright (C) 2011-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup GenCube //! @{ //! support class for generator functions (eg. zeros, randu, randn, ...) template class GenCube : public BaseCube > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool prefer_at_accessor = false; static const bool is_simple = (is_same_type::value) || (is_same_type::value); arma_aligned const uword n_rows; arma_aligned const uword n_cols; arma_aligned const uword n_slices; arma_inline GenCube(const uword in_n_rows, const uword in_n_cols, const uword in_n_slices); arma_inline ~GenCube(); arma_inline static eT generate(); arma_inline eT operator[] (const uword i) const; arma_inline eT at (const uword row, const uword col, const uword slice) const; arma_inline eT at_alt (const uword i) const; inline void apply (Cube& out) const; inline void apply_inplace_plus (Cube& out) const; inline void apply_inplace_minus(Cube& out) const; inline void apply_inplace_schur(Cube& out) const; inline void apply_inplace_div (Cube& out) const; }; //! @} armadillo-6.500.5/include/armadillo_bits/subview_each_bones.hpp0000666000000000000000000001270412625475676023340 0ustar rootroot// Copyright (C) 2012-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_each //! @{ template class subview_each_common { public: typedef typename parent::elem_type eT; const parent& P; inline void check_size(const Mat& A) const; protected: arma_inline subview_each_common(const parent& in_P); arma_inline const Mat& get_mat_ref_helper(const Mat & X) const; arma_inline const Mat& get_mat_ref_helper(const subview& X) const; arma_inline const Mat& get_mat_ref() const; arma_cold inline const std::string incompat_size_string(const Mat& A) const; private: subview_each_common(); }; template class subview_each1 : public subview_each_common { protected: arma_inline subview_each1(const parent& in_P); public: typedef typename parent::elem_type eT; inline ~subview_each1(); // deliberately returning void template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); private: friend class Mat; friend class subview; }; template class subview_each2 : public subview_each_common { protected: inline subview_each2(const parent& in_P, const Base& in_indices); public: const Base& base_indices; typedef typename parent::elem_type eT; inline void check_indices(const Mat& indices) const; inline ~subview_each2(); // deliberately returning void template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); private: friend class Mat; friend class subview; }; class subview_each1_aux { public: template static inline Mat operator_plus(const subview_each1& X, const Base& Y); template static inline Mat operator_minus(const subview_each1& X, const Base& Y); template static inline Mat operator_minus(const Base& X, const subview_each1& Y); template static inline Mat operator_schur(const subview_each1& X, const Base& Y); template static inline Mat operator_div(const subview_each1& X,const Base& Y); template static inline Mat operator_div(const Base& X, const subview_each1& Y); }; class subview_each2_aux { public: template static inline Mat operator_plus(const subview_each2& X, const Base& Y); template static inline Mat operator_minus(const subview_each2& X, const Base& Y); template static inline Mat operator_minus(const Base& X, const subview_each2& Y); template static inline Mat operator_schur(const subview_each2& X, const Base& Y); template static inline Mat operator_div(const subview_each2& X, const Base& Y); template static inline Mat operator_div(const Base& X, const subview_each2& Y); }; //! @} armadillo-6.500.5/include/armadillo_bits/op_find_unique_bones.hpp0000666000000000000000000000270512620272703023655 0ustar rootroot// Copyright (C) 2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_find_unique //! @{ class op_find_unique { public: template static inline bool apply_helper(Mat& out, const Proxy& P, const bool ascending_indices); template static inline void apply(Mat& out, const mtOp& in); }; template struct arma_find_unique_packet { eT val; uword index; }; template struct arma_find_unique_comparator { arma_inline bool operator() (const arma_find_unique_packet& A, const arma_find_unique_packet& B) const { return (A.val < B.val); } }; template struct arma_find_unique_comparator< std::complex > { arma_inline bool operator() (const arma_find_unique_packet< std::complex >& A, const arma_find_unique_packet< std::complex >& B) const { const T A_real = A.val.real(); const T B_real = B.val.real(); return ( (A_real < B_real) ? true : ((A_real == B_real) ? (A.val.imag() < B.val.imag()) : false) ); } }; //! @} armadillo-6.500.5/include/armadillo_bits/op_prod_bones.hpp0000666000000000000000000000157612620272703022320 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_prod //! @{ class op_prod { public: template inline static void apply_noalias(Mat& out, const Mat& X, const uword dim); template inline static void apply(Mat& out, const Op& in); template inline static eT prod(const subview& S); template inline static typename T1::elem_type prod(const Base& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_ones.hpp0000666000000000000000000000635312620272703021115 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_ones //! @{ arma_inline const Gen ones(const uword n_elem) { arma_extra_debug_sigprint(); return Gen(n_elem, 1); } template arma_inline const Gen ones(const uword n_elem, const arma_empty_class junk1 = arma_empty_class(), const typename arma_Mat_Col_Row_only::result* junk2 = 0) { arma_extra_debug_sigprint(); arma_ignore(junk1); arma_ignore(junk2); if(is_Row::value) { return Gen(1, n_elem); } else { return Gen(n_elem, 1); } } arma_inline const Gen ones(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return Gen(n_rows, n_cols); } arma_inline const Gen ones(const SizeMat& s) { arma_extra_debug_sigprint(); return Gen(s.n_rows, s.n_cols); } template inline const Gen ones(const uword n_rows, const uword n_cols, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); if(is_Col::value) { arma_debug_check( (n_cols != 1), "ones(): incompatible size" ); } else if(is_Row::value) { arma_debug_check( (n_rows != 1), "ones(): incompatible size" ); } return Gen(n_rows, n_cols); } template inline const Gen ones(const SizeMat& s, const typename arma_Mat_Col_Row_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return ones(s.n_rows, s.n_cols); } arma_inline const GenCube ones(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return GenCube(n_rows, n_cols, n_slices); } arma_inline const GenCube ones(const SizeCube& s) { arma_extra_debug_sigprint(); return GenCube(s.n_rows, s.n_cols, s.n_slices); } template arma_inline const GenCube ones(const uword n_rows, const uword n_cols, const uword n_slices, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(n_rows, n_cols, n_slices); } template arma_inline const GenCube ones(const SizeCube& s, const typename arma_Cube_only::result* junk = 0) { arma_extra_debug_sigprint(); arma_ignore(junk); return GenCube(s.n_rows, s.n_cols, s.n_slices); } //! @} armadillo-6.500.5/include/armadillo_bits/Row_meat.hpp0000666000000000000000000007757612650111756021265 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup Row //! @{ //! construct an empty row vector template inline Row::Row() : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); } template inline Row::Row(const Row& X) : Mat(arma_vec_indicator(), 1, X.n_elem, 2) { arma_extra_debug_sigprint(); arrayops::copy((*this).memptr(), X.memptr(), X.n_elem); } //! construct a row vector with the specified number of n_elem template inline Row::Row(const uword in_n_elem) : Mat(arma_vec_indicator(), 1, in_n_elem, 2) { arma_extra_debug_sigprint(); } template inline Row::Row(const uword in_n_rows, const uword in_n_cols) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); Mat::init_warm(in_n_rows, in_n_cols); } template inline Row::Row(const SizeMat& s) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); Mat::init_warm(s.n_rows, s.n_cols); } template template inline Row::Row(const uword in_n_elem, const fill::fill_class& f) : Mat(arma_vec_indicator(), 1, in_n_elem, 2) { arma_extra_debug_sigprint(); (*this).fill(f); } template template inline Row::Row(const uword in_n_rows, const uword in_n_cols, const fill::fill_class& f) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); Mat::init_warm(in_n_rows, in_n_cols); (*this).fill(f); } template template inline Row::Row(const SizeMat& s, const fill::fill_class& f) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); Mat::init_warm(s.n_rows, s.n_cols); (*this).fill(f); } template inline Row::Row(const char* text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); } template inline const Row& Row::operator=(const char* text) { arma_extra_debug_sigprint(); Mat::operator=(text); return *this; } template inline Row::Row(const std::string& text) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(text); } template inline const Row& Row::operator=(const std::string& text) { arma_extra_debug_sigprint(); Mat::operator=(text); return *this; } //! create a row vector from std::vector template inline Row::Row(const std::vector& x) : Mat(arma_vec_indicator(), 1, uword(x.size()), 2) { arma_extra_debug_sigprint_this(this); if(x.size() > 0) { arrayops::copy( Mat::memptr(), &(x[0]), uword(x.size()) ); } } //! create a row vector from std::vector template inline const Row& Row::operator=(const std::vector& x) { arma_extra_debug_sigprint(); Mat::init_warm(1, uword(x.size())); if(x.size() > 0) { arrayops::copy( Mat::memptr(), &(x[0]), uword(x.size()) ); } return *this; } #if defined(ARMA_USE_CXX11) template inline Row::Row(const std::initializer_list& list) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(list); } template inline const Row& Row::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); Mat::operator=(list); return *this; } template inline Row::Row(Row&& X) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); access::rw(Mat::n_rows) = 1; access::rw(Mat::n_cols) = X.n_cols; access::rw(Mat::n_elem) = X.n_elem; if( ((X.mem_state == 0) && (X.n_elem > arma_config::mat_prealloc)) || (X.mem_state == 1) || (X.mem_state == 2) ) { access::rw(Mat::mem_state) = X.mem_state; access::rw(Mat::mem) = X.mem; access::rw(X.n_rows) = 1; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem_state) = 0; access::rw(X.mem) = 0; } else { (*this).init_cold(); arrayops::copy( (*this).memptr(), X.mem, X.n_elem ); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) ) { access::rw(X.n_rows) = 1; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } } } template inline const Row& Row::operator=(Row&& X) { arma_extra_debug_sigprint(arma_str::format("this = %x X = %x") % this % &X); (*this).steal_mem(X); if( (X.mem_state == 0) && (X.n_elem <= arma_config::mat_prealloc) && (this != &X) ) { access::rw(X.n_rows) = 1; access::rw(X.n_cols) = 0; access::rw(X.n_elem) = 0; access::rw(X.mem) = 0; } return *this; } #endif template inline Row::Row(const SpRow& X) : Mat(arma_vec_indicator(), 1, X.n_elem, 1) { arma_extra_debug_sigprint_this(this); arrayops::inplace_set(Mat::memptr(), eT(0), X.n_elem); for(typename SpRow::const_iterator it = X.begin(); it != X.end(); ++it) { at(it.col()) = (*it); } } template inline const Row& Row::operator=(const eT val) { arma_extra_debug_sigprint(); Mat::operator=(val); return *this; } template inline const Row& Row::operator=(const Row& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template template inline Row::Row(const Base& X) : Mat(arma_vec_indicator(), 2) { arma_extra_debug_sigprint(); Mat::operator=(X.get_ref()); } template template inline const Row& Row::operator=(const Base& X) { arma_extra_debug_sigprint(); Mat::operator=(X.get_ref()); return *this; } //! construct a row vector from a given auxiliary array template inline Row::Row(eT* aux_mem, const uword aux_length, const bool copy_aux_mem, const bool strict) : Mat(aux_mem, 1, aux_length, copy_aux_mem, strict) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; } //! construct a row vector from a given auxiliary array template inline Row::Row(const eT* aux_mem, const uword aux_length) : Mat(aux_mem, 1, aux_length) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; } template template inline Row::Row ( const Base::pod_type, T1>& A, const Base::pod_type, T2>& B ) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::init(A,B); } template template inline Row::Row(const BaseCube& X) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(X); } template template inline const Row& Row::operator=(const BaseCube& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template inline Row::Row(const subview_cube& X) { arma_extra_debug_sigprint(); access::rw(Mat::vec_state) = 2; Mat::operator=(X); } template inline const Row& Row::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); Mat::operator=(X); return *this; } template inline mat_injector< Row > Row::operator<<(const eT val) { return mat_injector< Row >(*this, val); } template arma_inline const Op,op_htrans> Row::t() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_htrans> Row::ht() const { return Op,op_htrans>(*this); } template arma_inline const Op,op_strans> Row::st() const { return Op,op_strans>(*this); } template arma_inline subview_row Row::col(const uword in_col1) { arma_extra_debug_sigprint(); arma_debug_check( (in_col1 >= Mat::n_cols), "Row::col(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, 1); } template arma_inline const subview_row Row::col(const uword in_col1) const { arma_extra_debug_sigprint(); arma_debug_check( (in_col1 >= Mat::n_cols), "Row::col(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, 1); } template arma_inline subview_row Row::cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline const subview_row Row::cols(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::cols(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline subview_row Row::subvec(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline const subview_row Row::subvec(const uword in_col1, const uword in_col2) const { arma_extra_debug_sigprint(); arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols) ), "Row::subvec(): indices out of bounds or incorrectly used"); const uword subview_n_cols = in_col2 - in_col1 + 1; return subview_row(*this, 0, in_col1, subview_n_cols); } template arma_inline subview_row Row::cols(const span& col_span) { arma_extra_debug_sigprint(); return subvec(col_span); } template arma_inline const subview_row Row::cols(const span& col_span) const { arma_extra_debug_sigprint(); return subvec(col_span); } template arma_inline subview_row Row::subvec(const span& col_span) { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = Mat::n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "Row::subvec(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, subvec_n_cols); } template arma_inline const subview_row Row::subvec(const span& col_span) const { arma_extra_debug_sigprint(); const bool col_all = col_span.whole; const uword local_n_cols = Mat::n_cols; const uword in_col1 = col_all ? 0 : col_span.a; const uword in_col2 = col_span.b; const uword subvec_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; arma_debug_check( ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ), "Row::subvec(): indices out of bounds or incorrectly used"); return subview_row(*this, 0, in_col1, subvec_n_cols); } template arma_inline subview_row Row::operator()(const span& col_span) { arma_extra_debug_sigprint(); return subvec(col_span); } template arma_inline const subview_row Row::operator()(const span& col_span) const { arma_extra_debug_sigprint(); return subvec(col_span); } template arma_inline subview_row Row::head(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > Mat::n_cols), "Row::head(): size out of bounds"); return subview_row(*this, 0, 0, N); } template arma_inline const subview_row Row::head(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > Mat::n_cols), "Row::head(): size out of bounds"); return subview_row(*this, 0, 0, N); } template arma_inline subview_row Row::tail(const uword N) { arma_extra_debug_sigprint(); arma_debug_check( (N > Mat::n_cols), "Row::tail(): size out of bounds"); const uword start_col = Mat::n_cols - N; return subview_row(*this, 0, start_col, N); } template arma_inline const subview_row Row::tail(const uword N) const { arma_extra_debug_sigprint(); arma_debug_check( (N > Mat::n_cols), "Row::tail(): size out of bounds"); const uword start_col = Mat::n_cols - N; return subview_row(*this, 0, start_col, N); } template arma_inline subview_row Row::head_cols(const uword N) { arma_extra_debug_sigprint(); return (*this).head(N); } template arma_inline const subview_row Row::head_cols(const uword N) const { arma_extra_debug_sigprint(); return (*this).head(N); } template arma_inline subview_row Row::tail_cols(const uword N) { arma_extra_debug_sigprint(); return (*this).tail(N); } template arma_inline const subview_row Row::tail_cols(const uword N) const { arma_extra_debug_sigprint(); return (*this).tail(N); } //! remove specified columns template inline void Row::shed_col(const uword col_num) { arma_extra_debug_sigprint(); arma_debug_check( col_num >= Mat::n_cols, "Row::shed_col(): index out of bounds"); shed_cols(col_num, col_num); } //! remove specified columns template inline void Row::shed_cols(const uword in_col1, const uword in_col2) { arma_extra_debug_sigprint(); arma_debug_check ( (in_col1 > in_col2) || (in_col2 >= Mat::n_cols), "Row::shed_cols(): indices out of bounds or incorrectly used" ); const uword n_keep_front = in_col1; const uword n_keep_back = Mat::n_cols - (in_col2 + 1); Row X(n_keep_front + n_keep_back); eT* X_mem = X.memptr(); const eT* t_mem = (*this).memptr(); if(n_keep_front > 0) { arrayops::copy( X_mem, t_mem, n_keep_front ); } if(n_keep_back > 0) { arrayops::copy( &(X_mem[n_keep_front]), &(t_mem[in_col2+1]), n_keep_back); } Mat::steal_mem(X); } //! insert N cols at the specified col position, //! optionally setting the elements of the inserted cols to zero template inline void Row::insert_cols(const uword col_num, const uword N, const bool set_to_zero) { arma_extra_debug_sigprint(); const uword t_n_cols = Mat::n_cols; const uword A_n_cols = col_num; const uword B_n_cols = t_n_cols - col_num; // insertion at col_num == n_cols is in effect an append operation arma_debug_check( (col_num > t_n_cols), "Row::insert_cols(): index out of bounds"); if(N > 0) { Row out(t_n_cols + N); eT* out_mem = out.memptr(); const eT* t_mem = (*this).memptr(); if(A_n_cols > 0) { arrayops::copy( out_mem, t_mem, A_n_cols ); } if(B_n_cols > 0) { arrayops::copy( &(out_mem[col_num + N]), &(t_mem[col_num]), B_n_cols ); } if(set_to_zero == true) { arrayops::inplace_set( &(out_mem[col_num]), eT(0), N ); } Mat::steal_mem(out); } } //! insert the given object at the specified col position; //! the given object must have one row template template inline void Row::insert_cols(const uword col_num, const Base& X) { arma_extra_debug_sigprint(); Mat::insert_cols(col_num, X); } template arma_inline arma_warn_unused eT& Row::at(const uword i) { return access::rw(Mat::mem[i]); } template arma_inline arma_warn_unused const eT& Row::at(const uword i) const { return Mat::mem[i]; } template arma_inline arma_warn_unused eT& Row::at(const uword, const uword in_col) { return access::rw( Mat::mem[in_col] ); } template arma_inline arma_warn_unused const eT& Row::at(const uword, const uword in_col) const { return Mat::mem[in_col]; } template inline typename Row::row_iterator Row::begin_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "Row::begin_row(): index out of bounds"); return Mat::memptr(); } template inline typename Row::const_row_iterator Row::begin_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "Row::begin_row(): index out of bounds"); return Mat::memptr(); } template inline typename Row::row_iterator Row::end_row(const uword row_num) { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "Row::end_row(): index out of bounds"); return Mat::memptr() + Mat::n_cols; } template inline typename Row::const_row_iterator Row::end_row(const uword row_num) const { arma_extra_debug_sigprint(); arma_debug_check( (row_num >= Mat::n_rows), "Row::end_row(): index out of bounds"); return Mat::memptr() + Mat::n_cols; } template template inline Row::fixed::fixed() : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); } template template arma_inline Row::fixed::fixed(const fixed& X) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } template template arma_inline Row::fixed::fixed(const subview_cube& X) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::operator=(X); } template template template inline Row::fixed::fixed(const fill::fill_class&) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); if(is_same_type::yes) (*this).zeros(); if(is_same_type::yes) (*this).ones(); if(is_same_type::yes) (*this).eye(); if(is_same_type::yes) (*this).randu(); if(is_same_type::yes) (*this).randn(); } template template template arma_inline Row::fixed::fixed(const Base& A) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::operator=(A.get_ref()); } template template template arma_inline Row::fixed::fixed(const Base& A, const Base& B) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::init(A,B); } template template inline Row::fixed::fixed(const eT* aux_mem) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; arrayops::copy( dest, aux_mem, fixed_n_elem ); } template template inline Row::fixed::fixed(const char* text) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::operator=(text); } template template inline Row::fixed::fixed(const std::string& text) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); Row::operator=(text); } template template template const Row& Row::fixed::operator=(const Base& A) { arma_extra_debug_sigprint(); Row::operator=(A.get_ref()); return *this; } template template const Row& Row::fixed::operator=(const eT val) { arma_extra_debug_sigprint(); Row::operator=(val); return *this; } template template const Row& Row::fixed::operator=(const char* text) { arma_extra_debug_sigprint(); Row::operator=(text); return *this; } template template const Row& Row::fixed::operator=(const std::string& text) { arma_extra_debug_sigprint(); Row::operator=(text); return *this; } template template const Row& Row::fixed::operator=(const subview_cube& X) { arma_extra_debug_sigprint(); Row::operator=(X); return *this; } #if defined(ARMA_USE_CXX11) template template inline Row::fixed::fixed(const std::initializer_list& list) : Row( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat::mem_local) ) { arma_extra_debug_sigprint_this(this); (*this).operator=(list); } template template inline const Row& Row::fixed::operator=(const std::initializer_list& list) { arma_extra_debug_sigprint(); const uword N = uword(list.size()); arma_debug_check( (N > fixed_n_elem), "Row::fixed: initialiser list is too long" ); eT* this_mem = (*this).memptr(); arrayops::copy( this_mem, list.begin(), N ); for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); } return *this; } #endif template template arma_inline const Row& Row::fixed::operator=(const fixed& X) { arma_extra_debug_sigprint(); if(this != &X) { eT* dest = (use_extra) ? mem_local_extra : Mat::mem_local; const eT* src = (use_extra) ? X.mem_local_extra : X.mem_local; arrayops::copy( dest, src, fixed_n_elem ); } return *this; } #if defined(ARMA_GOOD_COMPILER) template template template inline const Row& Row::fixed::operator=(const eOp& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); const bool bad_alias = (eOp::proxy_type::has_subview && X.P.is_alias(*this)); if(bad_alias == false) { arma_debug_assert_same_size(uword(1), fixed_n_elem, X.get_n_rows(), X.get_n_cols(), "Row::fixed::operator="); eop_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Row tmp(X); (*this) = tmp; } return *this; } template template template inline const Row& Row::fixed::operator=(const eGlue& X) { arma_extra_debug_sigprint(); arma_type_check(( is_same_type< eT, typename T1::elem_type >::no )); arma_type_check(( is_same_type< eT, typename T2::elem_type >::no )); const bool bad_alias = ( (eGlue::proxy1_type::has_subview && X.P1.is_alias(*this)) || (eGlue::proxy2_type::has_subview && X.P2.is_alias(*this)) ); if(bad_alias == false) { arma_debug_assert_same_size(uword(1), fixed_n_elem, X.get_n_rows(), X.get_n_cols(), "Row::fixed::operator="); eglue_type::apply(*this, X); } else { arma_extra_debug_print("bad_alias = true"); Row tmp(X); (*this) = tmp; } return *this; } #endif template template arma_inline const Op< typename Row::template fixed::Row_fixed_type, op_htrans > Row::fixed::t() const { return Op< typename Row::template fixed::Row_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Row::template fixed::Row_fixed_type, op_htrans > Row::fixed::ht() const { return Op< typename Row::template fixed::Row_fixed_type, op_htrans >(*this); } template template arma_inline const Op< typename Row::template fixed::Row_fixed_type, op_strans > Row::fixed::st() const { return Op< typename Row::template fixed::Row_fixed_type, op_strans >(*this); } template template arma_inline arma_warn_unused const eT& Row::fixed::at_alt(const uword ii) const { #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE) return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; #else const eT* mem_aligned = (use_extra) ? mem_local_extra : Mat::mem_local; memory::mark_as_aligned(mem_aligned); return mem_aligned[ii]; #endif } template template arma_inline arma_warn_unused eT& Row::fixed::operator[] (const uword ii) { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Row::fixed::operator[] (const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Row::fixed::at(const uword ii) { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Row::fixed::at(const uword ii) const { return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Row::fixed::operator() (const uword ii) { arma_debug_check( (ii >= fixed_n_elem), "Row::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused const eT& Row::fixed::operator() (const uword ii) const { arma_debug_check( (ii >= fixed_n_elem), "Row::operator(): index out of bounds"); return (use_extra) ? mem_local_extra[ii] : Mat::mem_local[ii]; } template template arma_inline arma_warn_unused eT& Row::fixed::at(const uword, const uword in_col) { return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; } template template arma_inline arma_warn_unused const eT& Row::fixed::at(const uword, const uword in_col) const { return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; } template template arma_inline arma_warn_unused eT& Row::fixed::operator() (const uword in_row, const uword in_col) { arma_debug_check( ((in_row > 0) || (in_col >= fixed_n_elem)), "Row::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; } template template arma_inline arma_warn_unused const eT& Row::fixed::operator() (const uword in_row, const uword in_col) const { arma_debug_check( ((in_row > 0) || (in_col >= fixed_n_elem)), "Row::operator(): index out of bounds" ); return (use_extra) ? mem_local_extra[in_col] : Mat::mem_local[in_col]; } template template arma_inline arma_warn_unused eT* Row::fixed::memptr() { return (use_extra) ? mem_local_extra : Mat::mem_local; } template template arma_inline arma_warn_unused const eT* Row::fixed::memptr() const { return (use_extra) ? mem_local_extra : Mat::mem_local; } template template arma_hot inline const Row& Row::fixed::fill(const eT val) { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, val ); return *this; } template template arma_hot inline const Row& Row::fixed::zeros() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(0) ); return *this; } template template arma_hot inline const Row& Row::fixed::ones() { arma_extra_debug_sigprint(); eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat::mem_local[0]); arrayops::inplace_set_fixed( mem_use, eT(1) ); return *this; } template inline Row::Row(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem) : Mat(arma_fixed_indicator(), 1, in_n_elem, 2, in_mem) { arma_extra_debug_sigprint_this(this); } #ifdef ARMA_EXTRA_ROW_MEAT #include ARMA_INCFILE_WRAP(ARMA_EXTRA_ROW_MEAT) #endif //! @} armadillo-6.500.5/include/armadillo_bits/fn_cross.hpp0000666000000000000000000000137612620272703021302 0ustar rootroot// Copyright (C) 2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_cross //! @{ //! cross product (only valid for 3 dimensional vectors) template inline const Glue cross(const Base& X, const Base& Y) { arma_extra_debug_sigprint(); return Glue(X.get_ref(), Y.get_ref()); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_solve.hpp0000666000000000000000000001557312626356526021321 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_solve //! @{ // // solve_gen template inline typename enable_if2< is_supported_blas_type::value, const Glue >::result solve ( const Base& A, const Base& B, const solve_opts::opts& opts = solve_opts::none ) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref(), opts.flags); } template inline typename enable_if2< is_supported_blas_type::value, const Glue >::result solve ( const Base& A, const Base& B, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref(), solve_opts::flag_none); } template inline typename enable_if2< is_supported_blas_type::value, const Glue >::result solve ( const Base& A, const Base& B, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return Glue(A.get_ref(), B.get_ref(), solve_opts::flag_none); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result solve ( Mat& out, const Base& A, const Base& B, const solve_opts::opts& opts = solve_opts::none ) { arma_extra_debug_sigprint(); return glue_solve_gen::apply(out, A.get_ref(), B.get_ref(), opts.flags); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result solve ( Mat& out, const Base& A, const Base& B, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return glue_solve_gen::apply(out, A.get_ref(), B.get_ref(), solve_opts::flag_none); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result solve ( Mat& out, const Base& A, const Base& B, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); return glue_solve_gen::apply(out, A.get_ref(), B.get_ref(), solve_opts::flag_none); } // // solve_tri template inline typename enable_if2< is_supported_blas_type::value, const Glue >::result solve ( const Op& A, const Base& B, const solve_opts::opts& opts = solve_opts::none ) { arma_extra_debug_sigprint(); uword flags = opts.flags; if(A.aux_uword_a == 0) { flags |= solve_opts::flag_triu; } if(A.aux_uword_a == 1) { flags |= solve_opts::flag_tril; } return Glue(A.m, B.get_ref(), flags); } template inline typename enable_if2< is_supported_blas_type::value, const Glue >::result solve ( const Op& A, const Base& B, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); uword flags = solve_opts::flag_none; if(A.aux_uword_a == 0) { flags |= solve_opts::flag_triu; } if(A.aux_uword_a == 1) { flags |= solve_opts::flag_tril; } return Glue(A.m, B.get_ref(), flags); } template inline typename enable_if2< is_supported_blas_type::value, const Glue >::result solve ( const Op& A, const Base& B, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); uword flags = solve_opts::flag_none; if(A.aux_uword_a == 0) { flags |= solve_opts::flag_triu; } if(A.aux_uword_a == 1) { flags |= solve_opts::flag_tril; } return Glue(A.m, B.get_ref(), flags); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result solve ( Mat& out, const Op& A, const Base& B, const solve_opts::opts& opts = solve_opts::none ) { arma_extra_debug_sigprint(); uword flags = opts.flags; if(A.aux_uword_a == 0) { flags |= solve_opts::flag_triu; } if(A.aux_uword_a == 1) { flags |= solve_opts::flag_tril; } return glue_solve_tri::apply(out, A.m, B.get_ref(), flags); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result solve ( Mat& out, const Op& A, const Base& B, const bool // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); uword flags = solve_opts::flag_none; if(A.aux_uword_a == 0) { flags |= solve_opts::flag_triu; } if(A.aux_uword_a == 1) { flags |= solve_opts::flag_tril; } return glue_solve_tri::apply(out, A.m, B.get_ref(), flags); } template inline typename enable_if2< is_supported_blas_type::value, bool >::result solve ( Mat& out, const Op& A, const Base& B, const char* // argument kept only for compatibility with old user code ) { arma_extra_debug_sigprint(); uword flags = solve_opts::flag_none; if(A.aux_uword_a == 0) { flags |= solve_opts::flag_triu; } if(A.aux_uword_a == 1) { flags |= solve_opts::flag_tril; } return glue_solve_tri::apply(out, A.m, B.get_ref(), flags); } //! @} armadillo-6.500.5/include/armadillo_bits/op_dotext_meat.hpp0000666000000000000000000000654612620272703022505 0ustar rootroot// Copyright (C) 2008-2010 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup op_dotext //! @{ template inline eT op_dotext::direct_rowvec_mat_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); const uword cost_AB = B.n_cols; const uword cost_BC = B.n_rows; if(cost_AB <= cost_BC) { podarray tmp(B.n_cols); for(uword col=0; col tmp(B.n_rows); for(uword row=0; row inline eT op_dotext::direct_rowvec_transmat_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); const uword cost_AB = B.n_rows; const uword cost_BC = B.n_cols; if(cost_AB <= cost_BC) { podarray tmp(B.n_rows); for(uword row=0; row tmp(B.n_cols); for(uword col=0; col inline eT op_dotext::direct_rowvec_diagmat_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); eT val = eT(0); for(uword i=0; i inline eT op_dotext::direct_rowvec_invdiagmat_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); eT val = eT(0); for(uword i=0; i inline eT op_dotext::direct_rowvec_invdiagvec_colvec ( const eT* A_mem, const Mat& B, const eT* C_mem ) { arma_extra_debug_sigprint(); const eT* B_mem = B.mem; eT val = eT(0); for(uword i=0; i inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_times>& X); }; class glue_mixed_plus { public: template inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_plus>& X); template inline static void apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_plus>& X); }; class glue_mixed_minus { public: template inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_minus>& X); template inline static void apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_minus>& X); }; class glue_mixed_div { public: template inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_div>& X); template inline static void apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_div>& X); }; class glue_mixed_schur { public: template inline static void apply(Mat::eT>& out, const mtGlue::eT, T1, T2, glue_mixed_schur>& X); template inline static void apply(Cube::eT>& out, const mtGlueCube::eT, T1, T2, glue_mixed_schur>& X); }; //! @} armadillo-6.500.5/include/armadillo_bits/arma_config.hpp0000666000000000000000000000616612620272703021735 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup arma_config //! @{ struct arma_config { #if defined(ARMA_MAT_PREALLOC) static const uword mat_prealloc = (sword(ARMA_MAT_PREALLOC) > 0) ? uword(ARMA_MAT_PREALLOC) : 1; #else static const uword mat_prealloc = 16; #endif #if defined(ARMA_SPMAT_CHUNKSIZE) static const uword spmat_chunksize = (sword(ARMA_SPMAT_CHUNKSIZE) > 0) ? uword(ARMA_SPMAT_CHUNKSIZE) : 256; #else static const uword spmat_chunksize = 256; #endif #if defined(ARMA_USE_ATLAS) static const bool atlas = true; #else static const bool atlas = false; #endif #if defined(ARMA_USE_LAPACK) static const bool lapack = true; #else static const bool lapack = false; #endif #if defined(ARMA_USE_BLAS) static const bool blas = true; #else static const bool blas = false; #endif #if defined(ARMA_USE_ARPACK) static const bool arpack = true; #else static const bool arpack = false; #endif #if defined(ARMA_USE_SUPERLU) static const bool superlu = true; #else static const bool superlu = false; #endif #if defined(ARMA_USE_HDF5) static const bool hdf5 = true; #else static const bool hdf5 = false; #endif #if defined(ARMA_NO_DEBUG) static const bool debug = false; #else static const bool debug = true; #endif #if defined(ARMA_EXTRA_DEBUG) static const bool extra_debug = true; #else static const bool extra_debug = false; #endif #if defined(ARMA_GOOD_COMPILER) static const bool good_comp = true; #else static const bool good_comp = false; #endif #if ( \ defined(ARMA_EXTRA_MAT_PROTO) || defined(ARMA_EXTRA_MAT_MEAT) \ || defined(ARMA_EXTRA_COL_PROTO) || defined(ARMA_EXTRA_COL_MEAT) \ || defined(ARMA_EXTRA_ROW_PROTO) || defined(ARMA_EXTRA_ROW_MEAT) \ || defined(ARMA_EXTRA_CUBE_PROTO) || defined(ARMA_EXTRA_CUBE_MEAT) \ || defined(ARMA_EXTRA_FIELD_PROTO) || defined(ARMA_EXTRA_FIELD_MEAT) \ || defined(ARMA_EXTRA_SPMAT_PROTO) || defined(ARMA_EXTRA_SPMAT_MEAT) \ || defined(ARMA_EXTRA_SPCOL_PROTO) || defined(ARMA_EXTRA_SPCOL_MEAT) \ || defined(ARMA_EXTRA_SPROW_PROTO) || defined(ARMA_EXTRA_SPROW_MEAT) \ ) static const bool extra_code = true; #else static const bool extra_code = false; #endif #if defined(ARMA_USE_CXX11) static const bool use_cxx11 = true; #else static const bool use_cxx11 = false; #endif #if defined(ARMA_USE_WRAPPER) static const bool use_wrapper = true; #else static const bool use_wrapper = false; #endif #if defined(_OPENMP) static const bool openmp = true; #else static const bool openmp = false; #endif }; //! @} armadillo-6.500.5/include/armadillo_bits/mtGlue_meat.hpp0000666000000000000000000000210412620272703021717 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup mtGlue //! @{ template inline mtGlue::mtGlue(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { arma_extra_debug_sigprint(); } template inline mtGlue::mtGlue(const T1& in_A, const T2& in_B, const uword in_aux_uword) : A(in_A) , B(in_B) , aux_uword(in_aux_uword) { arma_extra_debug_sigprint(); } template inline mtGlue::~mtGlue() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/glue_times_meat.hpp0000666000000000000000000007413412650111756022636 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup glue_times //! @{ template template arma_hot inline void glue_times_redirect2_helper::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const partial_unwrap tmp1(X.A); const partial_unwrap tmp2(X.B); const typename partial_unwrap::stored_type& A = tmp1.M; const typename partial_unwrap::stored_type& B = tmp2.M; const bool use_alpha = partial_unwrap::do_times || partial_unwrap::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val()) : eT(0); const bool alias = tmp1.is_alias(out) || tmp2.is_alias(out); if(alias == false) { glue_times::apply < eT, partial_unwrap::do_trans, partial_unwrap::do_trans, (partial_unwrap::do_times || partial_unwrap::do_times) > (out, A, B, alpha); } else { Mat tmp; glue_times::apply < eT, partial_unwrap::do_trans, partial_unwrap::do_trans, (partial_unwrap::do_times || partial_unwrap::do_times) > (tmp, A, B, alpha); out.steal_mem(tmp); } } template arma_hot inline void glue_times_redirect2_helper::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; if(strip_inv::do_inv == true) { // replace inv(A)*B with solve(A,B) arma_extra_debug_print("glue_times_redirect<2>::apply(): detected inv(A)*B"); const strip_inv A_strip(X.A); Mat A = A_strip.M; arma_debug_check( (A.is_square() == false), "inv(): given matrix must be square sized" ); const unwrap_check B_tmp(X.B, out); const Mat& B = B_tmp.M; arma_debug_assert_mul_size(A, B, "matrix multiplication"); const bool status = auxlib::solve_square_fast(out, A, B); if(status == false) { out.reset(); arma_bad("matrix multiplication: inverse of singular matrix; suggest to use solve() instead"); } return; } glue_times_redirect2_helper::apply(out, X); } template template arma_hot inline void glue_times_redirect3_helper::apply(Mat& out, const Glue< Glue, T3, glue_times>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // we have exactly 3 objects // hence we can safely expand X as X.A.A, X.A.B and X.B const partial_unwrap tmp1(X.A.A); const partial_unwrap tmp2(X.A.B); const partial_unwrap tmp3(X.B ); const typename partial_unwrap::stored_type& A = tmp1.M; const typename partial_unwrap::stored_type& B = tmp2.M; const typename partial_unwrap::stored_type& C = tmp3.M; const bool use_alpha = partial_unwrap::do_times || partial_unwrap::do_times || partial_unwrap::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val() * tmp3.get_val()) : eT(0); const bool alias = tmp1.is_alias(out) || tmp2.is_alias(out) || tmp3.is_alias(out); if(alias == false) { glue_times::apply < eT, partial_unwrap::do_trans, partial_unwrap::do_trans, partial_unwrap::do_trans, (partial_unwrap::do_times || partial_unwrap::do_times || partial_unwrap::do_times) > (out, A, B, C, alpha); } else { Mat tmp; glue_times::apply < eT, partial_unwrap::do_trans, partial_unwrap::do_trans, partial_unwrap::do_trans, (partial_unwrap::do_times || partial_unwrap::do_times || partial_unwrap::do_times) > (tmp, A, B, C, alpha); out.steal_mem(tmp); } } template arma_hot inline void glue_times_redirect3_helper::apply(Mat& out, const Glue< Glue, T3, glue_times>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; if(strip_inv::do_inv == true) { // replace inv(A)*B*C with solve(A,B*C); arma_extra_debug_print("glue_times_redirect<3>::apply(): detected inv(A)*B*C"); const strip_inv A_strip(X.A.A); Mat A = A_strip.M; arma_debug_check( (A.is_square() == false), "inv(): given matrix must be square sized" ); const partial_unwrap tmp2(X.A.B); const partial_unwrap tmp3(X.B ); const typename partial_unwrap::stored_type& B = tmp2.M; const typename partial_unwrap::stored_type& C = tmp3.M; const bool use_alpha = partial_unwrap::do_times || partial_unwrap::do_times; const eT alpha = use_alpha ? (tmp2.get_val() * tmp3.get_val()) : eT(0); Mat BC; glue_times::apply < eT, partial_unwrap::do_trans, partial_unwrap::do_trans, (partial_unwrap::do_times || partial_unwrap::do_times) > (BC, B, C, alpha); arma_debug_assert_mul_size(A, BC, "matrix multiplication"); const bool status = auxlib::solve_square_fast(out, A, BC); if(status == false) { out.reset(); arma_bad("matrix multiplication: inverse of singular matrix; suggest to use solve() instead"); } return; } if(strip_inv::do_inv == true) { // replace A*inv(B)*C with A*solve(B,C) arma_extra_debug_print("glue_times_redirect<3>::apply(): detected A*inv(B)*C"); const strip_inv B_strip(X.A.B); Mat B = B_strip.M; arma_debug_check( (B.is_square() == false), "inv(): given matrix must be square sized" ); const unwrap C_tmp(X.B); const Mat& C = C_tmp.M; arma_debug_assert_mul_size(B, C, "matrix multiplication"); Mat solve_result; const bool status = auxlib::solve_square_fast(solve_result, B, C); if(status == false) { out.reset(); arma_bad("matrix multiplication: inverse of singular matrix; suggest to use solve() instead"); return; } const partial_unwrap_check tmp1(X.A.A, out); const typename partial_unwrap_check::stored_type& A = tmp1.M; const bool use_alpha = partial_unwrap_check::do_times; const eT alpha = use_alpha ? tmp1.get_val() : eT(0); glue_times::apply < eT, partial_unwrap_check::do_trans, false, partial_unwrap_check::do_times > (out, A, solve_result, alpha); return; } glue_times_redirect3_helper::apply(out, X); } template template arma_hot inline void glue_times_redirect::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const partial_unwrap tmp1(X.A); const partial_unwrap tmp2(X.B); const typename partial_unwrap::stored_type& A = tmp1.M; const typename partial_unwrap::stored_type& B = tmp2.M; const bool use_alpha = partial_unwrap::do_times || partial_unwrap::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val()) : eT(0); const bool alias = tmp1.is_alias(out) || tmp2.is_alias(out); if(alias == false) { glue_times::apply < eT, partial_unwrap::do_trans, partial_unwrap::do_trans, (partial_unwrap::do_times || partial_unwrap::do_times) > (out, A, B, alpha); } else { Mat tmp; glue_times::apply < eT, partial_unwrap::do_trans, partial_unwrap::do_trans, (partial_unwrap::do_times || partial_unwrap::do_times) > (tmp, A, B, alpha); out.steal_mem(tmp); } } template arma_hot inline void glue_times_redirect<2>::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; glue_times_redirect2_helper< is_supported_blas_type::value >::apply(out, X); } template arma_hot inline void glue_times_redirect<3>::apply(Mat& out, const Glue< Glue, T3, glue_times>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; glue_times_redirect3_helper< is_supported_blas_type::value >::apply(out, X); } template arma_hot inline void glue_times_redirect<4>::apply(Mat& out, const Glue< Glue< Glue, T3, glue_times>, T4, glue_times>& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; // there is exactly 4 objects // hence we can safely expand X as X.A.A.A, X.A.A.B, X.A.B and X.B const partial_unwrap tmp1(X.A.A.A); const partial_unwrap tmp2(X.A.A.B); const partial_unwrap tmp3(X.A.B ); const partial_unwrap tmp4(X.B ); const typename partial_unwrap::stored_type& A = tmp1.M; const typename partial_unwrap::stored_type& B = tmp2.M; const typename partial_unwrap::stored_type& C = tmp3.M; const typename partial_unwrap::stored_type& D = tmp4.M; const bool use_alpha = partial_unwrap::do_times || partial_unwrap::do_times || partial_unwrap::do_times || partial_unwrap::do_times; const eT alpha = use_alpha ? (tmp1.get_val() * tmp2.get_val() * tmp3.get_val() * tmp4.get_val()) : eT(0); const bool alias = tmp1.is_alias(out) || tmp2.is_alias(out) || tmp3.is_alias(out) || tmp4.is_alias(out); if(alias == false) { glue_times::apply < eT, partial_unwrap::do_trans, partial_unwrap::do_trans, partial_unwrap::do_trans, partial_unwrap::do_trans, (partial_unwrap::do_times || partial_unwrap::do_times || partial_unwrap::do_times || partial_unwrap::do_times) > (out, A, B, C, D, alpha); } else { Mat tmp; glue_times::apply < eT, partial_unwrap::do_trans, partial_unwrap::do_trans, partial_unwrap::do_trans, partial_unwrap::do_trans, (partial_unwrap::do_times || partial_unwrap::do_times || partial_unwrap::do_times || partial_unwrap::do_times) > (tmp, A, B, C, D, alpha); out.steal_mem(tmp); } } template arma_hot inline void glue_times::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); const sword N_mat = 1 + depth_lhs< glue_times, Glue >::num; arma_extra_debug_print(arma_str::format("N_mat = %d") % N_mat); glue_times_redirect::apply(out, X); } template arma_hot inline void glue_times::apply_inplace(Mat& out, const T1& X) { arma_extra_debug_sigprint(); out = out * X; } template arma_hot inline void glue_times::apply_inplace_plus(Mat& out, const Glue& X, const sword sign) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename get_pod_type::result T; if( (is_outer_product::value) || (has_op_inv::value) || (has_op_inv::value) ) { // partial workaround for corner cases const Mat tmp(X); if(sign > sword(0)) { out += tmp; } else { out -= tmp; } return; } const partial_unwrap_check tmp1(X.A, out); const partial_unwrap_check tmp2(X.B, out); typedef typename partial_unwrap_check::stored_type TA; typedef typename partial_unwrap_check::stored_type TB; const TA& A = tmp1.M; const TB& B = tmp2.M; const bool do_trans_A = partial_unwrap_check::do_trans; const bool do_trans_B = partial_unwrap_check::do_trans; const bool use_alpha = partial_unwrap_check::do_times || partial_unwrap_check::do_times || (sign < sword(0)); const eT alpha = use_alpha ? ( tmp1.get_val() * tmp2.get_val() * ( (sign > sword(0)) ? eT(1) : eT(-1) ) ) : eT(0); arma_debug_assert_mul_size(A, B, do_trans_A, do_trans_B, "matrix multiplication"); const uword result_n_rows = (do_trans_A == false) ? (TA::is_row ? 1 : A.n_rows) : (TA::is_col ? 1 : A.n_cols); const uword result_n_cols = (do_trans_B == false) ? (TB::is_col ? 1 : B.n_cols) : (TB::is_row ? 1 : B.n_rows); arma_debug_assert_same_size(out.n_rows, out.n_cols, result_n_rows, result_n_cols, ( (sign > sword(0)) ? "addition" : "subtraction" ) ); if(out.n_elem == 0) { return; } if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == false) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == true) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == false) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::yes) ) { herk::apply(out, A, T(0), T(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == true) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == false) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::yes) ) { herk::apply(out, A, T(0), T(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == true) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == false) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } else if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == true) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha, eT(1)); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha, eT(1)); } else { gemm::apply(out, A, B, alpha, eT(1)); } } } template arma_inline uword glue_times::mul_storage_cost(const TA& A, const TB& B) { const uword final_A_n_rows = (do_trans_A == false) ? ( TA::is_row ? 1 : A.n_rows ) : ( TA::is_col ? 1 : A.n_cols ); const uword final_B_n_cols = (do_trans_B == false) ? ( TB::is_col ? 1 : B.n_cols ) : ( TB::is_row ? 1 : B.n_rows ); return final_A_n_rows * final_B_n_cols; } template < typename eT, const bool do_trans_A, const bool do_trans_B, const bool use_alpha, typename TA, typename TB > arma_hot inline void glue_times::apply ( Mat& out, const TA& A, const TB& B, const eT alpha ) { arma_extra_debug_sigprint(); //arma_debug_assert_mul_size(A, B, do_trans_A, do_trans_B, "matrix multiplication"); arma_debug_assert_trans_mul_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matrix multiplication"); const uword final_n_rows = (do_trans_A == false) ? (TA::is_row ? 1 : A.n_rows) : (TA::is_col ? 1 : A.n_cols); const uword final_n_cols = (do_trans_B == false) ? (TB::is_col ? 1 : B.n_cols) : (TB::is_row ? 1 : B.n_rows); out.set_size(final_n_rows, final_n_cols); if( (A.n_elem == 0) || (B.n_elem == 0) ) { out.zeros(); return; } if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == false) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr()); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr()); } else { gemm::apply(out, A, B ); } } else if( (do_trans_A == false) && (do_trans_B == false) && (use_alpha == true) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha); } else { gemm::apply(out, A, B, alpha); } } else if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == false) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr()); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr()); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A ); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::yes) ) { herk::apply(out, A ); } else { gemm::apply(out, A, B ); } } else if( (do_trans_A == true) && (do_trans_B == false) && (use_alpha == true) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha); } else if( (B.n_cols == 1) || (TB::is_col) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha); } else { gemm::apply(out, A, B, alpha); } } else if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == false) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr()); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr()); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A ); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::yes) ) { herk::apply(out, A ); } else { gemm::apply(out, A, B ); } } else if( (do_trans_A == false) && (do_trans_B == true) && (use_alpha == true) ) { if( ((A.n_rows == 1) || (TA::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha); } else if( (void_ptr(&A) == void_ptr(&B)) && (is_cx::no) ) { syrk::apply(out, A, alpha); } else { gemm::apply(out, A, B, alpha); } } else if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == false) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr()); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr()); } else { gemm::apply(out, A, B ); } } else if( (do_trans_A == true) && (do_trans_B == true) && (use_alpha == true) ) { if( ((A.n_cols == 1) || (TA::is_col)) && (is_cx::no) ) { gemv::apply(out.memptr(), B, A.memptr(), alpha); } else if( ((B.n_rows == 1) || (TB::is_row)) && (is_cx::no) ) { gemv::apply(out.memptr(), A, B.memptr(), alpha); } else { gemm::apply(out, A, B, alpha); } } } template < typename eT, const bool do_trans_A, const bool do_trans_B, const bool do_trans_C, const bool use_alpha, typename TA, typename TB, typename TC > arma_hot inline void glue_times::apply ( Mat& out, const TA& A, const TB& B, const TC& C, const eT alpha ) { arma_extra_debug_sigprint(); Mat tmp; const uword storage_cost_AB = glue_times::mul_storage_cost(A, B); const uword storage_cost_BC = glue_times::mul_storage_cost(B, C); if(storage_cost_AB <= storage_cost_BC) { // out = (A*B)*C glue_times::apply(tmp, A, B, alpha); glue_times::apply(out, tmp, C, eT(0)); } else { // out = A*(B*C) glue_times::apply(tmp, B, C, alpha); glue_times::apply(out, A, tmp, eT(0)); } } template < typename eT, const bool do_trans_A, const bool do_trans_B, const bool do_trans_C, const bool do_trans_D, const bool use_alpha, typename TA, typename TB, typename TC, typename TD > arma_hot inline void glue_times::apply ( Mat& out, const TA& A, const TB& B, const TC& C, const TD& D, const eT alpha ) { arma_extra_debug_sigprint(); Mat tmp; const uword storage_cost_AC = glue_times::mul_storage_cost(A, C); const uword storage_cost_BD = glue_times::mul_storage_cost(B, D); if(storage_cost_AC <= storage_cost_BD) { // out = (A*B*C)*D glue_times::apply(tmp, A, B, C, alpha); glue_times::apply(out, tmp, D, eT(0)); } else { // out = A*(B*C*D) glue_times::apply(tmp, B, C, D, alpha); glue_times::apply(out, A, tmp, eT(0)); } } // // glue_times_diag template arma_hot inline void glue_times_diag::apply(Mat& out, const Glue& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; const strip_diagmat S1(X.A); const strip_diagmat S2(X.B); typedef typename strip_diagmat::stored_type T1_stripped; typedef typename strip_diagmat::stored_type T2_stripped; if( (strip_diagmat::do_diagmat == true) && (strip_diagmat::do_diagmat == false) ) { arma_extra_debug_print("glue_times_diag::apply(): diagmat(A) * B"); const diagmat_proxy_check A(S1.M, out); const unwrap_check tmp(X.B, out); const Mat& B = tmp.M; const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword A_length = (std::min)(A_n_rows, A_n_cols); const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; arma_debug_assert_mul_size(A_n_rows, A_n_cols, B_n_rows, B_n_cols, "matrix multiplication"); out.zeros(A_n_rows, B_n_cols); for(uword col=0; col < B_n_cols; ++col) { eT* out_coldata = out.colptr(col); const eT* B_coldata = B.colptr(col); for(uword i=0; i < A_length; ++i) { out_coldata[i] = A[i] * B_coldata[i]; } } } else if( (strip_diagmat::do_diagmat == false) && (strip_diagmat::do_diagmat == true) ) { arma_extra_debug_print("glue_times_diag::apply(): A * diagmat(B)"); const unwrap_check tmp(X.A, out); const Mat& A = tmp.M; const diagmat_proxy_check B(S2.M, out); const uword A_n_rows = A.n_rows; const uword A_n_cols = A.n_cols; const uword B_n_rows = B.n_rows; const uword B_n_cols = B.n_cols; const uword B_length = (std::min)(B_n_rows, B_n_cols); arma_debug_assert_mul_size(A_n_rows, A_n_cols, B_n_rows, B_n_cols, "matrix multiplication"); out.zeros(A_n_rows, B_n_cols); for(uword col=0; col < B_length; ++col) { const eT val = B[col]; eT* out_coldata = out.colptr(col); const eT* A_coldata = A.colptr(col); for(uword i=0; i < A_n_rows; ++i) { out_coldata[i] = A_coldata[i] * val; } } } else if( (strip_diagmat::do_diagmat == true) && (strip_diagmat::do_diagmat == true) ) { arma_extra_debug_print("glue_times_diag::apply(): diagmat(A) * diagmat(B)"); const diagmat_proxy_check A(S1.M, out); const diagmat_proxy_check B(S2.M, out); arma_debug_assert_mul_size(A.n_rows, A.n_cols, B.n_rows, B.n_cols, "matrix multiplication"); out.zeros(A.n_rows, B.n_cols); const uword A_length = (std::min)(A.n_rows, A.n_cols); const uword B_length = (std::min)(B.n_rows, B.n_cols); const uword N = (std::min)(A_length, B_length); for(uword i=0; i < N; ++i) { out.at(i,i) = A[i] * B[i]; } } } //! @} armadillo-6.500.5/include/armadillo_bits/OpCube_bones.hpp0000666000000000000000000000424112620272703022023 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup OpCube //! @{ //! Analog of the Op class, intended for cubes template class OpCube : public BaseCube > { public: typedef typename T1::elem_type elem_type; typedef typename get_pod_type::result pod_type; inline explicit OpCube(const BaseCube& in_m); inline OpCube(const BaseCube& in_m, const elem_type in_aux); inline OpCube(const BaseCube& in_m, const elem_type in_aux, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b); inline OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c); inline OpCube(const BaseCube& in_m, const uword in_aux_uword_a, const uword in_aux_uword_b, const uword in_aux_uword_c, const uword in_aux_uword_d, const char junk); inline ~OpCube(); arma_aligned const T1& m; //!< storage of reference to the operand (e.g. a cube) arma_aligned elem_type aux; //!< storage of auxiliary data, user defined format arma_aligned uword aux_uword_a; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_b; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_c; //!< storage of auxiliary data, uword format arma_aligned uword aux_uword_d; //!< storage of auxiliary data, uword format }; //! @} armadillo-6.500.5/include/armadillo_bits/operator_cube_relational.hpp0000666000000000000000000001600212620272703024521 0ustar rootroot// Copyright (C) 2009-2014 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup operator_cube_relational //! @{ // < : lt // > : gt // <= : lteq // >= : gteq // == : eq // != : noteq // && : and // || : or template inline const mtGlueCube operator< (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator> (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator<= (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator>= (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator== (const BaseCube& X, const BaseCube& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator!= (const BaseCube& X, const BaseCube& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator&& (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } template inline const mtGlueCube operator|| (const BaseCube::result,T1>& X, const BaseCube::result,T2>& Y) { arma_extra_debug_sigprint(); return mtGlueCube( X.get_ref(), Y.get_ref() ); } // // // template inline const mtOpCube operator< (const typename arma_not_cx::result val, const BaseCube::result,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator< (const BaseCube::result,T1>& X, const typename arma_not_cx::result val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator> (const typename arma_not_cx::result val, const BaseCube::result,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator> (const BaseCube::result,T1>& X, const typename arma_not_cx::result val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator<= (const typename arma_not_cx::result val, const BaseCube::result,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator<= (const BaseCube::result,T1>& X, const typename arma_not_cx::result val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator>= (const typename arma_not_cx::result val, const BaseCube::result,T1>& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator>= (const BaseCube::result,T1>& X, const typename arma_not_cx::result val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator== (const typename T1::elem_type val, const BaseCube& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator== (const BaseCube& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator!= (const typename T1::elem_type val, const BaseCube& X) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } template inline const mtOpCube operator!= (const BaseCube& X, const typename T1::elem_type val) { arma_extra_debug_sigprint(); return mtOpCube(X.get_ref(), val); } //! @} armadillo-6.500.5/include/armadillo_bits/mtGlueCube_meat.hpp0000666000000000000000000000214012620272703022516 0ustar rootroot// Copyright (C) 2008-2011 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup mtGlueCube //! @{ template inline mtGlueCube::mtGlueCube(const T1& in_A, const T2& in_B) : A(in_A) , B(in_B) { arma_extra_debug_sigprint(); } template inline mtGlueCube::mtGlueCube(const T1& in_A, const T2& in_B, const uword in_aux_uword) : A(in_A) , B(in_B) , aux_uword(in_aux_uword) { arma_extra_debug_sigprint(); } template inline mtGlueCube::~mtGlueCube() { arma_extra_debug_sigprint(); } //! @} armadillo-6.500.5/include/armadillo_bits/fn_sort_index.hpp0000666000000000000000000000464312620272703022327 0ustar rootroot// Copyright (C) 2009-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_sort_index //! @{ //! kept for compatibility with old code template inline const mtOp sort_index ( const Base& X, const uword sort_type = 0 ) { arma_extra_debug_sigprint(); arma_debug_check( (sort_type > 1), "sort_index(): parameter 'sort_type' must be 0 or 1" ); return mtOp(X.get_ref(), sort_type, uword(0)); } //! kept for compatibility with old code template inline const mtOp stable_sort_index ( const Base& X, const uword sort_type = 0 ) { arma_extra_debug_sigprint(); arma_debug_check( (sort_type > 1), "stable_sort_index(): parameter 'sort_type' must be 0 or 1" ); return mtOp(X.get_ref(), sort_type, uword(0)); } template inline typename enable_if2 < ( (is_arma_type::value == true) && (is_same_type::value == true) ), const mtOp >::result sort_index ( const T1& X, const T2* sort_direction ) { arma_extra_debug_sigprint(); const char sig = (sort_direction != NULL) ? sort_direction[0] : char(0); arma_debug_check( ((sig != 'a') && (sig != 'd')), "sort_index(): unknown sort direction" ); return mtOp(X, ((sig == 'a') ? uword(0) : uword(1)), uword(0)); } template inline typename enable_if2 < ( (is_arma_type::value == true) && (is_same_type::value == true) ), const mtOp >::result stable_sort_index ( const T1& X, const T2* sort_direction ) { arma_extra_debug_sigprint(); const char sig = (sort_direction != NULL) ? sort_direction[0] : char(0); arma_debug_check( ((sig != 'a') && (sig != 'd')), "stable_sort_index(): unknown sort direction" ); return mtOp(X, ((sig == 'a') ? uword(0) : uword(1)), uword(0)); } //! @} armadillo-6.500.5/include/armadillo_bits/wall_clock_bones.hpp0000666000000000000000000000177112623320713022763 0ustar rootroot// Copyright (C) 2008-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup wall_clock //! @{ //! Class for measuring time intervals class wall_clock { public: inline wall_clock(); inline ~wall_clock(); inline void tic(); //!< start the timer inline double toc(); //!< return the number of seconds since the last call to tic() private: bool valid; #if defined(ARMA_USE_CXX11) && !defined(ARMA_DONT_USE_CXX11_CHRONO) std::chrono::steady_clock::time_point chrono_time1; #elif defined(ARMA_HAVE_GETTIMEOFDAY) struct timeval posix_time1; struct timeval posix_time2; #else std::clock_t time1; #endif }; //! @} armadillo-6.500.5/include/armadillo_bits/fn_size.hpp0000666000000000000000000000575412620272703021127 0ustar rootroot// Copyright (C) 2013-2015 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup fn_size //! @{ inline const SizeMat size(const uword n_rows, const uword n_cols) { arma_extra_debug_sigprint(); return SizeMat(n_rows, n_cols); } template inline typename enable_if2< is_arma_type::value, const SizeMat >::result size(const T1& X) { arma_extra_debug_sigprint(); const Proxy P(X); return SizeMat( P.get_n_rows(), P.get_n_cols() ); } template inline typename enable_if2< is_arma_type::value, uword >::result size(const T1& X, const uword dim) { arma_extra_debug_sigprint(); const Proxy P(X); return SizeMat( P.get_n_rows(), P.get_n_cols() )( dim ); } inline const SizeCube size(const uword n_rows, const uword n_cols, const uword n_slices) { arma_extra_debug_sigprint(); return SizeCube(n_rows, n_cols, n_slices); } template inline typename enable_if2< is_arma_cube_type::value, const SizeCube >::result size(const T1& X) { arma_extra_debug_sigprint(); const ProxyCube P(X); return SizeCube( P.get_n_rows(), P.get_n_cols(), P.get_n_slices() ); } template inline typename enable_if2< is_arma_cube_type::value, uword >::result size(const T1& X, const uword dim) { arma_extra_debug_sigprint(); const ProxyCube P(X); return SizeCube( P.get_n_rows(), P.get_n_cols(), P.get_n_slices() )( dim ); } template inline typename enable_if2< is_arma_sparse_type::value, const SizeMat >::result size(const T1& X) { arma_extra_debug_sigprint(); const SpProxy P(X); return SizeMat( P.get_n_rows(), P.get_n_cols() ); } template inline typename enable_if2< is_arma_sparse_type::value, uword >::result size(const T1& X, const uword dim) { arma_extra_debug_sigprint(); const SpProxy P(X); return SizeMat( P.get_n_rows(), P.get_n_cols() )( dim ); } template inline const SizeCube size(const field& X) { arma_extra_debug_sigprint(); return SizeCube( X.n_rows, X.n_cols, X.n_slices ); } template inline uword size(const field& X, const uword dim) { arma_extra_debug_sigprint(); return SizeCube( X.n_rows, X.n_cols, X.n_slices )( dim ); } template inline const SizeCube size(const subview_field& X) { arma_extra_debug_sigprint(); return SizeCube( X.n_rows, X.n_cols, X.n_slices ); } template inline uword size(const subview_field& X, const uword dim) { arma_extra_debug_sigprint(); return SizeCube( X.n_rows, X.n_cols, X.n_slices )( dim ); } //! @} armadillo-6.500.5/include/armadillo_bits/subview_elem1_bones.hpp0000666000000000000000000000660512620272703023423 0ustar rootroot// Copyright (C) 2010-2013 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au //! \addtogroup subview_elem1 //! @{ template class subview_elem1 : public Base > { public: typedef eT elem_type; typedef typename get_pod_type::result pod_type; static const bool is_row = false; static const bool is_col = true; arma_aligned const Mat fake_m; arma_aligned const Mat& m; arma_aligned const Base& a; protected: arma_inline subview_elem1(const Mat& in_m, const Base& in_a); arma_inline subview_elem1(const Cube& in_q, const Base& in_a); public: inline ~subview_elem1(); template inline void inplace_op(const eT val); template inline void inplace_op(const subview_elem1& x ); template inline void inplace_op(const Base& x ); arma_inline const Op,op_htrans> t() const; arma_inline const Op,op_htrans> ht() const; arma_inline const Op,op_strans> st() const; inline void fill(const eT val); inline void zeros(); inline void ones(); inline void randu(); inline void randn(); inline void operator+= (const eT val); inline void operator-= (const eT val); inline void operator*= (const eT val); inline void operator/= (const eT val); // deliberately returning void template inline void operator_equ(const subview_elem1& x); template inline void operator= (const subview_elem1& x); inline void operator= (const subview_elem1& x); template inline void operator+= (const subview_elem1& x); template inline void operator-= (const subview_elem1& x); template inline void operator%= (const subview_elem1& x); template inline void operator/= (const subview_elem1& x); template inline void operator= (const Base& x); template inline void operator+= (const Base& x); template inline void operator-= (const Base& x); template inline void operator%= (const Base& x); template inline void operator/= (const Base& x); inline static void extract(Mat& out, const subview_elem1& in); template inline static void mat_inplace_op(Mat& out, const subview_elem1& in); inline static void plus_inplace(Mat& out, const subview_elem1& in); inline static void minus_inplace(Mat& out, const subview_elem1& in); inline static void schur_inplace(Mat& out, const subview_elem1& in); inline static void div_inplace(Mat& out, const subview_elem1& in); private: friend class Mat; friend class Cube; subview_elem1(); }; //! @} armadillo-6.500.5/include/armadillo0000666000000000000000000005421212656116504015661 0ustar rootroot// Copyright (C) 2008-2016 National ICT Australia (NICTA) // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // ------------------------------------------------------------------- // // Written by Conrad Sanderson - http://conradsanderson.id.au #ifndef ARMA_INCLUDES #define ARMA_INCLUDES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if ( defined(__unix__) || defined(__unix) || defined(_POSIX_C_SOURCE) || (defined(__APPLE__) && defined(__MACH__)) ) && !defined(_WIN32) #include #endif #if (defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L)) #include #endif #if (__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X__) #undef ARMA_USE_CXX11 #define ARMA_USE_CXX11 #endif #include "armadillo_bits/config.hpp" #include "armadillo_bits/compiler_setup.hpp" #if defined(ARMA_USE_CXX11) #include #include #include #include #if !defined(ARMA_DONT_USE_CXX11_CHRONO) #include #endif #endif #if defined(ARMA_USE_TBB_ALLOC) #include #endif #if defined(ARMA_USE_MKL_ALLOC) #include #endif #if !defined(ARMA_USE_CXX11) #if defined(ARMA_HAVE_TR1) #include #include #endif #endif #include "armadillo_bits/include_atlas.hpp" #include "armadillo_bits/include_hdf5.hpp" #include "armadillo_bits/include_superlu.hpp" #if defined(_OPENMP) #include #endif //! \namespace arma namespace for Armadillo classes and functions namespace arma { // preliminaries #include "armadillo_bits/arma_forward.hpp" #include "armadillo_bits/arma_static_check.hpp" #include "armadillo_bits/typedef_elem.hpp" #include "armadillo_bits/typedef_elem_check.hpp" #include "armadillo_bits/typedef_mat.hpp" #include "armadillo_bits/arma_str.hpp" #include "armadillo_bits/arma_version.hpp" #include "armadillo_bits/arma_config.hpp" #include "armadillo_bits/traits.hpp" #include "armadillo_bits/promote_type.hpp" #include "armadillo_bits/upgrade_val.hpp" #include "armadillo_bits/restrictors.hpp" #include "armadillo_bits/access.hpp" #include "armadillo_bits/span.hpp" #include "armadillo_bits/distr_param.hpp" #include "armadillo_bits/constants.hpp" #include "armadillo_bits/constants_compat.hpp" #ifdef ARMA_RNG_ALT #include ARMA_INCFILE_WRAP(ARMA_RNG_ALT) #else #include "armadillo_bits/arma_rng_cxx98.hpp" #endif #include "armadillo_bits/arma_rng_cxx11.hpp" #include "armadillo_bits/arma_rng.hpp" // // class prototypes #include "armadillo_bits/Base_bones.hpp" #include "armadillo_bits/BaseCube_bones.hpp" #include "armadillo_bits/SpBase_bones.hpp" #include "armadillo_bits/def_blas.hpp" #include "armadillo_bits/def_lapack.hpp" #include "armadillo_bits/def_atlas.hpp" #include "armadillo_bits/def_arpack.hpp" #include "armadillo_bits/def_superlu.hpp" #include "armadillo_bits/def_hdf5.hpp" #include "armadillo_bits/wrapper_blas.hpp" #include "armadillo_bits/wrapper_lapack.hpp" #include "armadillo_bits/wrapper_atlas.hpp" #include "armadillo_bits/wrapper_arpack.hpp" #include "armadillo_bits/wrapper_superlu.hpp" #include "armadillo_bits/cond_rel_bones.hpp" #include "armadillo_bits/arrayops_bones.hpp" #include "armadillo_bits/podarray_bones.hpp" #include "armadillo_bits/auxlib_bones.hpp" #include "armadillo_bits/sp_auxlib_bones.hpp" #include "armadillo_bits/injector_bones.hpp" #include "armadillo_bits/Mat_bones.hpp" #include "armadillo_bits/Col_bones.hpp" #include "armadillo_bits/Row_bones.hpp" #include "armadillo_bits/Cube_bones.hpp" #include "armadillo_bits/xvec_htrans_bones.hpp" #include "armadillo_bits/xtrans_mat_bones.hpp" #include "armadillo_bits/SizeMat_bones.hpp" #include "armadillo_bits/SizeCube_bones.hpp" #include "armadillo_bits/SpValProxy_bones.hpp" #include "armadillo_bits/SpMat_bones.hpp" #include "armadillo_bits/SpCol_bones.hpp" #include "armadillo_bits/SpRow_bones.hpp" #include "armadillo_bits/SpSubview_bones.hpp" #include "armadillo_bits/spdiagview_bones.hpp" #include "armadillo_bits/typedef_mat_fixed.hpp" #include "armadillo_bits/field_bones.hpp" #include "armadillo_bits/subview_bones.hpp" #include "armadillo_bits/subview_elem1_bones.hpp" #include "armadillo_bits/subview_elem2_bones.hpp" #include "armadillo_bits/subview_field_bones.hpp" #include "armadillo_bits/subview_cube_bones.hpp" #include "armadillo_bits/diagview_bones.hpp" #include "armadillo_bits/subview_each_bones.hpp" #include "armadillo_bits/subview_cube_each_bones.hpp" #include "armadillo_bits/diskio_bones.hpp" #include "armadillo_bits/wall_clock_bones.hpp" #include "armadillo_bits/running_stat_bones.hpp" #include "armadillo_bits/running_stat_vec_bones.hpp" #include "armadillo_bits/Op_bones.hpp" #include "armadillo_bits/OpCube_bones.hpp" #include "armadillo_bits/SpOp_bones.hpp" #include "armadillo_bits/eOp_bones.hpp" #include "armadillo_bits/eOpCube_bones.hpp" #include "armadillo_bits/mtOp_bones.hpp" #include "armadillo_bits/mtOpCube_bones.hpp" #include "armadillo_bits/mtSpOp_bones.hpp" #include "armadillo_bits/Glue_bones.hpp" #include "armadillo_bits/eGlue_bones.hpp" #include "armadillo_bits/mtGlue_bones.hpp" #include "armadillo_bits/SpGlue_bones.hpp" #include "armadillo_bits/GlueCube_bones.hpp" #include "armadillo_bits/eGlueCube_bones.hpp" #include "armadillo_bits/mtGlueCube_bones.hpp" #include "armadillo_bits/eop_core_bones.hpp" #include "armadillo_bits/eglue_core_bones.hpp" #include "armadillo_bits/Gen_bones.hpp" #include "armadillo_bits/GenCube_bones.hpp" #include "armadillo_bits/op_diagmat_bones.hpp" #include "armadillo_bits/op_diagvec_bones.hpp" #include "armadillo_bits/op_dot_bones.hpp" #include "armadillo_bits/op_inv_bones.hpp" #include "armadillo_bits/op_htrans_bones.hpp" #include "armadillo_bits/op_max_bones.hpp" #include "armadillo_bits/op_min_bones.hpp" #include "armadillo_bits/op_mean_bones.hpp" #include "armadillo_bits/op_median_bones.hpp" #include "armadillo_bits/op_sort_bones.hpp" #include "armadillo_bits/op_sort_index_bones.hpp" #include "armadillo_bits/op_sum_bones.hpp" #include "armadillo_bits/op_stddev_bones.hpp" #include "armadillo_bits/op_strans_bones.hpp" #include "armadillo_bits/op_var_bones.hpp" #include "armadillo_bits/op_repmat_bones.hpp" #include "armadillo_bits/op_reshape_bones.hpp" #include "armadillo_bits/op_vectorise_bones.hpp" #include "armadillo_bits/op_resize_bones.hpp" #include "armadillo_bits/op_cov_bones.hpp" #include "armadillo_bits/op_cor_bones.hpp" #include "armadillo_bits/op_shuffle_bones.hpp" #include "armadillo_bits/op_prod_bones.hpp" #include "armadillo_bits/op_pinv_bones.hpp" #include "armadillo_bits/op_dotext_bones.hpp" #include "armadillo_bits/op_flip_bones.hpp" #include "armadillo_bits/op_princomp_bones.hpp" #include "armadillo_bits/op_misc_bones.hpp" #include "armadillo_bits/op_relational_bones.hpp" #include "armadillo_bits/op_find_bones.hpp" #include "armadillo_bits/op_find_unique_bones.hpp" #include "armadillo_bits/op_chol_bones.hpp" #include "armadillo_bits/op_cx_scalar_bones.hpp" #include "armadillo_bits/op_trimat_bones.hpp" #include "armadillo_bits/op_cumsum_bones.hpp" #include "armadillo_bits/op_cumprod_bones.hpp" #include "armadillo_bits/op_symmat_bones.hpp" #include "armadillo_bits/op_hist_bones.hpp" #include "armadillo_bits/op_unique_bones.hpp" #include "armadillo_bits/op_toeplitz_bones.hpp" #include "armadillo_bits/op_fft_bones.hpp" #include "armadillo_bits/op_any_bones.hpp" #include "armadillo_bits/op_all_bones.hpp" #include "armadillo_bits/op_normalise_bones.hpp" #include "armadillo_bits/op_clamp_bones.hpp" #include "armadillo_bits/op_expmat_bones.hpp" #include "armadillo_bits/op_nonzeros_bones.hpp" #include "armadillo_bits/op_diff_bones.hpp" #include "armadillo_bits/op_norm_bones.hpp" #include "armadillo_bits/glue_times_bones.hpp" #include "armadillo_bits/glue_mixed_bones.hpp" #include "armadillo_bits/glue_cov_bones.hpp" #include "armadillo_bits/glue_cor_bones.hpp" #include "armadillo_bits/glue_kron_bones.hpp" #include "armadillo_bits/glue_cross_bones.hpp" #include "armadillo_bits/glue_join_bones.hpp" #include "armadillo_bits/glue_relational_bones.hpp" #include "armadillo_bits/glue_solve_bones.hpp" #include "armadillo_bits/glue_conv_bones.hpp" #include "armadillo_bits/glue_toeplitz_bones.hpp" #include "armadillo_bits/glue_hist_bones.hpp" #include "armadillo_bits/glue_histc_bones.hpp" #include "armadillo_bits/glue_max_bones.hpp" #include "armadillo_bits/glue_min_bones.hpp" #if !defined(ARMA_BAD_COMPILER) #include "armadillo_bits/gmm_misc_bones.hpp" #include "armadillo_bits/gmm_diag_bones.hpp" #endif #include "armadillo_bits/spop_max_bones.hpp" #include "armadillo_bits/spop_min_bones.hpp" #include "armadillo_bits/spop_sum_bones.hpp" #include "armadillo_bits/spop_strans_bones.hpp" #include "armadillo_bits/spop_htrans_bones.hpp" #include "armadillo_bits/spop_misc_bones.hpp" #include "armadillo_bits/spop_diagmat_bones.hpp" #include "armadillo_bits/spop_mean_bones.hpp" #include "armadillo_bits/spop_var_bones.hpp" #include "armadillo_bits/spglue_plus_bones.hpp" #include "armadillo_bits/spglue_minus_bones.hpp" #include "armadillo_bits/spglue_times_bones.hpp" #include "armadillo_bits/spglue_join_bones.hpp" // // low-level debugging and memory handling functions #include "armadillo_bits/debug.hpp" #include "armadillo_bits/memory.hpp" // // wrappers for various cmath functions #include "armadillo_bits/arma_cmath.hpp" // // classes that underlay metaprogramming #include "armadillo_bits/unwrap.hpp" #include "armadillo_bits/unwrap_cube.hpp" #include "armadillo_bits/unwrap_spmat.hpp" #include "armadillo_bits/Proxy.hpp" #include "armadillo_bits/ProxyCube.hpp" #include "armadillo_bits/SpProxy.hpp" #include "armadillo_bits/diagmat_proxy.hpp" #include "armadillo_bits/strip.hpp" #include "armadillo_bits/Op_meat.hpp" #include "armadillo_bits/OpCube_meat.hpp" #include "armadillo_bits/SpOp_meat.hpp" #include "armadillo_bits/mtOp_meat.hpp" #include "armadillo_bits/mtOpCube_meat.hpp" #include "armadillo_bits/mtSpOp_meat.hpp" #include "armadillo_bits/Glue_meat.hpp" #include "armadillo_bits/GlueCube_meat.hpp" #include "armadillo_bits/SpGlue_meat.hpp" #include "armadillo_bits/eop_aux.hpp" #include "armadillo_bits/eOp_meat.hpp" #include "armadillo_bits/eOpCube_meat.hpp" #include "armadillo_bits/eGlue_meat.hpp" #include "armadillo_bits/eGlueCube_meat.hpp" #include "armadillo_bits/mtGlue_meat.hpp" #include "armadillo_bits/mtGlueCube_meat.hpp" #include "armadillo_bits/Base_meat.hpp" #include "armadillo_bits/BaseCube_meat.hpp" #include "armadillo_bits/SpBase_meat.hpp" #include "armadillo_bits/Gen_meat.hpp" #include "armadillo_bits/GenCube_meat.hpp" // // ostream #include "armadillo_bits/arma_ostream_bones.hpp" #include "armadillo_bits/arma_ostream_meat.hpp" // // n_unique, which is used by some sparse operators #include "armadillo_bits/fn_n_unique.hpp" // // operators #include "armadillo_bits/operator_plus.hpp" #include "armadillo_bits/operator_minus.hpp" #include "armadillo_bits/operator_times.hpp" #include "armadillo_bits/operator_schur.hpp" #include "armadillo_bits/operator_div.hpp" #include "armadillo_bits/operator_relational.hpp" #include "armadillo_bits/operator_cube_plus.hpp" #include "armadillo_bits/operator_cube_minus.hpp" #include "armadillo_bits/operator_cube_times.hpp" #include "armadillo_bits/operator_cube_schur.hpp" #include "armadillo_bits/operator_cube_div.hpp" #include "armadillo_bits/operator_cube_relational.hpp" #include "armadillo_bits/operator_ostream.hpp" // // user accessible functions // the order of the fn_*.hpp include files matters, // as some files require functionality given in preceding files #include "armadillo_bits/fn_conv_to.hpp" #include "armadillo_bits/fn_min.hpp" #include "armadillo_bits/fn_max.hpp" #include "armadillo_bits/fn_accu.hpp" #include "armadillo_bits/fn_sum.hpp" #include "armadillo_bits/fn_diagmat.hpp" #include "armadillo_bits/fn_diagvec.hpp" #include "armadillo_bits/fn_inv.hpp" #include "armadillo_bits/fn_trace.hpp" #include "armadillo_bits/fn_trans.hpp" #include "armadillo_bits/fn_det.hpp" #include "armadillo_bits/fn_log_det.hpp" #include "armadillo_bits/fn_eig_gen.hpp" #include "armadillo_bits/fn_eig_sym.hpp" #include "armadillo_bits/fn_eig_pair.hpp" #include "armadillo_bits/fn_lu.hpp" #include "armadillo_bits/fn_zeros.hpp" #include "armadillo_bits/fn_ones.hpp" #include "armadillo_bits/fn_eye.hpp" #include "armadillo_bits/fn_misc.hpp" #include "armadillo_bits/fn_find.hpp" #include "armadillo_bits/fn_find_unique.hpp" #include "armadillo_bits/fn_elem.hpp" #include "armadillo_bits/fn_norm.hpp" #include "armadillo_bits/fn_dot.hpp" #include "armadillo_bits/fn_randu.hpp" #include "armadillo_bits/fn_randn.hpp" #include "armadillo_bits/fn_trig.hpp" #include "armadillo_bits/fn_mean.hpp" #include "armadillo_bits/fn_median.hpp" #include "armadillo_bits/fn_stddev.hpp" #include "armadillo_bits/fn_var.hpp" #include "armadillo_bits/fn_sort.hpp" #include "armadillo_bits/fn_sort_index.hpp" #include "armadillo_bits/fn_strans.hpp" #include "armadillo_bits/fn_chol.hpp" #include "armadillo_bits/fn_qr.hpp" #include "armadillo_bits/fn_svd.hpp" #include "armadillo_bits/fn_solve.hpp" #include "armadillo_bits/fn_repmat.hpp" #include "armadillo_bits/fn_reshape.hpp" #include "armadillo_bits/fn_vectorise.hpp" #include "armadillo_bits/fn_resize.hpp" #include "armadillo_bits/fn_cov.hpp" #include "armadillo_bits/fn_cor.hpp" #include "armadillo_bits/fn_shuffle.hpp" #include "armadillo_bits/fn_prod.hpp" #include "armadillo_bits/fn_eps.hpp" #include "armadillo_bits/fn_pinv.hpp" #include "armadillo_bits/fn_rank.hpp" #include "armadillo_bits/fn_kron.hpp" #include "armadillo_bits/fn_flip.hpp" #include "armadillo_bits/fn_as_scalar.hpp" #include "armadillo_bits/fn_princomp.hpp" #include "armadillo_bits/fn_cross.hpp" #include "armadillo_bits/fn_join.hpp" #include "armadillo_bits/fn_conv.hpp" #include "armadillo_bits/fn_trunc_exp.hpp" #include "armadillo_bits/fn_trunc_log.hpp" #include "armadillo_bits/fn_toeplitz.hpp" #include "armadillo_bits/fn_trimat.hpp" #include "armadillo_bits/fn_cumsum.hpp" #include "armadillo_bits/fn_cumprod.hpp" #include "armadillo_bits/fn_symmat.hpp" #include "armadillo_bits/fn_syl_lyap.hpp" #include "armadillo_bits/fn_hist.hpp" #include "armadillo_bits/fn_histc.hpp" #include "armadillo_bits/fn_unique.hpp" #include "armadillo_bits/fn_fft.hpp" #include "armadillo_bits/fn_fft2.hpp" #include "armadillo_bits/fn_any.hpp" #include "armadillo_bits/fn_all.hpp" #include "armadillo_bits/fn_size.hpp" #include "armadillo_bits/fn_numel.hpp" #include "armadillo_bits/fn_inplace_strans.hpp" #include "armadillo_bits/fn_inplace_trans.hpp" #include "armadillo_bits/fn_randi.hpp" #include "armadillo_bits/fn_randg.hpp" #include "armadillo_bits/fn_cond.hpp" #include "armadillo_bits/fn_normalise.hpp" #include "armadillo_bits/fn_clamp.hpp" #include "armadillo_bits/fn_expmat.hpp" #include "armadillo_bits/fn_nonzeros.hpp" #include "armadillo_bits/fn_interp1.hpp" #include "armadillo_bits/fn_qz.hpp" #include "armadillo_bits/fn_diff.hpp" #include "armadillo_bits/fn_schur.hpp" #include "armadillo_bits/fn_kmeans.hpp" #include "armadillo_bits/fn_speye.hpp" #include "armadillo_bits/fn_spones.hpp" #include "armadillo_bits/fn_sprandn.hpp" #include "armadillo_bits/fn_sprandu.hpp" #include "armadillo_bits/fn_eigs_sym.hpp" #include "armadillo_bits/fn_eigs_gen.hpp" #include "armadillo_bits/fn_spsolve.hpp" #include "armadillo_bits/fn_svds.hpp" // // misc stuff #include "armadillo_bits/hdf5_misc.hpp" #include "armadillo_bits/fft_engine.hpp" // // classes implementing various forms of dense matrix multiplication #include "armadillo_bits/mul_gemv.hpp" #include "armadillo_bits/mul_gemm.hpp" #include "armadillo_bits/mul_gemm_mixed.hpp" #include "armadillo_bits/mul_syrk.hpp" #include "armadillo_bits/mul_herk.hpp" // // class meat #include "armadillo_bits/eop_core_meat.hpp" #include "armadillo_bits/eglue_core_meat.hpp" #include "armadillo_bits/cond_rel_meat.hpp" #include "armadillo_bits/arrayops_meat.hpp" #include "armadillo_bits/podarray_meat.hpp" #include "armadillo_bits/auxlib_meat.hpp" #include "armadillo_bits/sp_auxlib_meat.hpp" #include "armadillo_bits/injector_meat.hpp" #include "armadillo_bits/Mat_meat.hpp" #include "armadillo_bits/Col_meat.hpp" #include "armadillo_bits/Row_meat.hpp" #include "armadillo_bits/Cube_meat.hpp" #include "armadillo_bits/xvec_htrans_meat.hpp" #include "armadillo_bits/xtrans_mat_meat.hpp" #include "armadillo_bits/SizeMat_meat.hpp" #include "armadillo_bits/SizeCube_meat.hpp" #include "armadillo_bits/field_meat.hpp" #include "armadillo_bits/subview_meat.hpp" #include "armadillo_bits/subview_elem1_meat.hpp" #include "armadillo_bits/subview_elem2_meat.hpp" #include "armadillo_bits/subview_field_meat.hpp" #include "armadillo_bits/subview_cube_meat.hpp" #include "armadillo_bits/diagview_meat.hpp" #include "armadillo_bits/subview_each_meat.hpp" #include "armadillo_bits/subview_cube_each_meat.hpp" #include "armadillo_bits/SpValProxy_meat.hpp" #include "armadillo_bits/SpMat_meat.hpp" #include "armadillo_bits/SpMat_iterators_meat.hpp" #include "armadillo_bits/SpCol_meat.hpp" #include "armadillo_bits/SpRow_meat.hpp" #include "armadillo_bits/SpSubview_meat.hpp" #include "armadillo_bits/SpSubview_iterators_meat.hpp" #include "armadillo_bits/spdiagview_meat.hpp" #include "armadillo_bits/diskio_meat.hpp" #include "armadillo_bits/wall_clock_meat.hpp" #include "armadillo_bits/running_stat_meat.hpp" #include "armadillo_bits/running_stat_vec_meat.hpp" #include "armadillo_bits/op_diagmat_meat.hpp" #include "armadillo_bits/op_diagvec_meat.hpp" #include "armadillo_bits/op_dot_meat.hpp" #include "armadillo_bits/op_inv_meat.hpp" #include "armadillo_bits/op_htrans_meat.hpp" #include "armadillo_bits/op_max_meat.hpp" #include "armadillo_bits/op_min_meat.hpp" #include "armadillo_bits/op_mean_meat.hpp" #include "armadillo_bits/op_median_meat.hpp" #include "armadillo_bits/op_sort_meat.hpp" #include "armadillo_bits/op_sort_index_meat.hpp" #include "armadillo_bits/op_sum_meat.hpp" #include "armadillo_bits/op_stddev_meat.hpp" #include "armadillo_bits/op_strans_meat.hpp" #include "armadillo_bits/op_var_meat.hpp" #include "armadillo_bits/op_repmat_meat.hpp" #include "armadillo_bits/op_reshape_meat.hpp" #include "armadillo_bits/op_vectorise_meat.hpp" #include "armadillo_bits/op_resize_meat.hpp" #include "armadillo_bits/op_cov_meat.hpp" #include "armadillo_bits/op_cor_meat.hpp" #include "armadillo_bits/op_shuffle_meat.hpp" #include "armadillo_bits/op_prod_meat.hpp" #include "armadillo_bits/op_pinv_meat.hpp" #include "armadillo_bits/op_dotext_meat.hpp" #include "armadillo_bits/op_flip_meat.hpp" #include "armadillo_bits/op_princomp_meat.hpp" #include "armadillo_bits/op_misc_meat.hpp" #include "armadillo_bits/op_relational_meat.hpp" #include "armadillo_bits/op_find_meat.hpp" #include "armadillo_bits/op_find_unique_meat.hpp" #include "armadillo_bits/op_chol_meat.hpp" #include "armadillo_bits/op_cx_scalar_meat.hpp" #include "armadillo_bits/op_trimat_meat.hpp" #include "armadillo_bits/op_cumsum_meat.hpp" #include "armadillo_bits/op_cumprod_meat.hpp" #include "armadillo_bits/op_symmat_meat.hpp" #include "armadillo_bits/op_hist_meat.hpp" #include "armadillo_bits/op_unique_meat.hpp" #include "armadillo_bits/op_toeplitz_meat.hpp" #include "armadillo_bits/op_fft_meat.hpp" #include "armadillo_bits/op_any_meat.hpp" #include "armadillo_bits/op_all_meat.hpp" #include "armadillo_bits/op_normalise_meat.hpp" #include "armadillo_bits/op_clamp_meat.hpp" #include "armadillo_bits/op_expmat_meat.hpp" #include "armadillo_bits/op_nonzeros_meat.hpp" #include "armadillo_bits/op_diff_meat.hpp" #include "armadillo_bits/op_norm_meat.hpp" #include "armadillo_bits/glue_times_meat.hpp" #include "armadillo_bits/glue_mixed_meat.hpp" #include "armadillo_bits/glue_cov_meat.hpp" #include "armadillo_bits/glue_cor_meat.hpp" #include "armadillo_bits/glue_kron_meat.hpp" #include "armadillo_bits/glue_cross_meat.hpp" #include "armadillo_bits/glue_join_meat.hpp" #include "armadillo_bits/glue_relational_meat.hpp" #include "armadillo_bits/glue_solve_meat.hpp" #include "armadillo_bits/glue_conv_meat.hpp" #include "armadillo_bits/glue_toeplitz_meat.hpp" #include "armadillo_bits/glue_hist_meat.hpp" #include "armadillo_bits/glue_histc_meat.hpp" #include "armadillo_bits/glue_max_meat.hpp" #include "armadillo_bits/glue_min_meat.hpp" #if !defined(ARMA_BAD_COMPILER) #include "armadillo_bits/gmm_misc_meat.hpp" #include "armadillo_bits/gmm_diag_meat.hpp" #endif #include "armadillo_bits/spop_max_meat.hpp" #include "armadillo_bits/spop_min_meat.hpp" #include "armadillo_bits/spop_sum_meat.hpp" #include "armadillo_bits/spop_strans_meat.hpp" #include "armadillo_bits/spop_htrans_meat.hpp" #include "armadillo_bits/spop_misc_meat.hpp" #include "armadillo_bits/spop_diagmat_meat.hpp" #include "armadillo_bits/spop_mean_meat.hpp" #include "armadillo_bits/spop_var_meat.hpp" #include "armadillo_bits/spglue_plus_meat.hpp" #include "armadillo_bits/spglue_minus_meat.hpp" #include "armadillo_bits/spglue_times_meat.hpp" #include "armadillo_bits/spglue_join_meat.hpp" } #include "armadillo_bits/compiler_setup_post.hpp" #endif armadillo-6.500.5/configure0000777000000000000000000000065412620272703014252 0ustar rootroot#!/bin/sh ABORT=no check_cmake() { (cmake --version) /dev/null 2>&1 || { echo "error: cmake (version 2.8 or later) must be present to configure and install Armadillo" echo "" echo "cmake might be available as a package for your system," echo "or can be downloaded from http://cmake.org" ABORT=yes } } check_cmake test "$ABORT" = yes && exit -1 rm -f CMakeCache.txt cmake $@ . armadillo-6.500.5/LICENSE.txt0000666000000000000000000004131312620272703014163 0ustar rootrootMozilla Public License Version 2.0 ================================== 1. Definitions -------------- 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software. 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution. 1.3. "Contribution" means Covered Software of a particular Contributor. 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof. 1.5. "Incompatible With Secondary Licenses" means (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License. 1.6. "Executable Form" means any form of the work other than Source Code Form. 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. 1.8. "License" means this document. 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License. 1.10. "Modifications" means any of the following: (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or (b) any new file in Source Code Form that contains any Covered Software. 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version. 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses. 1.13. "Source Code Form" means the form of the work preferred for making modifications. 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 2. License Grants and Conditions -------------------------------- 2.1. Grants Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version. 2.2. Effective Date The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. 2.3. Limitations on Grant Scope The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor: (a) for any code that a Contributor has removed from Covered Software; or (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or (c) under Patent Claims infringed by Covered Software in the absence of its Contributions. This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4). 2.4. Subsequent Licenses No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3). 2.5. Representation Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License. 2.6. Fair Use This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. 2.7. Conditions Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. 3. Responsibilities ------------------- 3.1. Distribution of Source Form All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form. 3.2. Distribution of Executable Form If You distribute Covered Software in Executable Form then: (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License. 3.3. Distribution of a Larger Work You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s). 3.4. Notices You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies. 3.5. Application of Additional Terms You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction. 4. Inability to Comply Due to Statute or Regulation --------------------------------------------------- If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. 5. Termination -------------- 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice. 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate. 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination. ************************************************************************ * * * 6. Disclaimer of Warranty * * ------------------------- * * * * Covered Software is provided under this License on an "as is" * * basis, without warranty of any kind, either expressed, implied, or * * statutory, including, without limitation, warranties that the * * Covered Software is free of defects, merchantable, fit for a * * particular purpose or non-infringing. The entire risk as to the * * quality and performance of the Covered Software is with You. * * Should any Covered Software prove defective in any respect, You * * (not any Contributor) assume the cost of any necessary servicing, * * repair, or correction. This disclaimer of warranty constitutes an * * essential part of this License. No use of any Covered Software is * * authorized under this License except under this disclaimer. * * * ************************************************************************ ************************************************************************ * * * 7. Limitation of Liability * * -------------------------- * * * * Under no circumstances and under no legal theory, whether tort * * (including negligence), contract, or otherwise, shall any * * Contributor, or anyone who distributes Covered Software as * * permitted above, be liable to You for any direct, indirect, * * special, incidental, or consequential damages of any character * * including, without limitation, damages for lost profits, loss of * * goodwill, work stoppage, computer failure or malfunction, or any * * and all other commercial damages or losses, even if such party * * shall have been informed of the possibility of such damages. This * * limitation of liability shall not apply to liability for death or * * personal injury resulting from such party's negligence to the * * extent applicable law prohibits such limitation. Some * * jurisdictions do not allow the exclusion or limitation of * * incidental or consequential damages, so this exclusion and * * limitation may not apply to You. * * * ************************************************************************ 8. Litigation ------------- Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. 9. Miscellaneous ---------------- This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. 10. Versions of the License --------------------------- 10.1. New Versions Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number. 10.2. Effect of New Versions You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward. 10.3. Modified Versions If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License). 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached. Exhibit A - Source Code Form License Notice ------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. You may add additional accurate notices of copyright ownership. Exhibit B - "Incompatible With Secondary Licenses" Notice --------------------------------------------------------- This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. armadillo-6.500.5/armadillo_icon.png0000666000000000000000000000066012656116504016027 0ustar rootrootPNG  IHDRasRGB pHYs  UIDAT8˥1hQBAD%q R",B^4ZB,"Sc z:jj<WPC|opk*) &%-.' p x3< hGZ~cL+p<1.8ؖ עqAJ;|9Jԟ1ӏ>U[,R4 [IENDB`