diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index de46d4c8278f952d375fc303683b9be6a6b44373..8cd1f8748012bb25bc1979c708ef9344d93edea5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -24,6 +24,7 @@ stages:
     WITH_MPI: "no"
     # configurations
     WITH_TESTS: "no"
+    WITH_MATRIX_TESTS: "no"
     WITH_COVERAGE: "no"
     WITH_DOC: "no"
     WITH_BENCHMARKS: "no"
@@ -56,6 +57,7 @@ stages:
                 -DWITH_CUDA=${WITH_CUDA}
                 -DWITH_CUDA_ARCH=${WITH_CUDA_ARCH}
                 -DWITH_TESTS=${WITH_TESTS}
+                -DWITH_MATRIX_TESTS=${WITH_MATRIX_TESTS}
                 -DWITH_DOC=${WITH_DOC}
                 -DWITH_COVERAGE=${WITH_COVERAGE}
                 -DWITH_BENCHMARKS=${WITH_BENCHMARKS}
@@ -65,7 +67,7 @@ stages:
                 -DWITH_CI_FLAGS=yes
         # "install" implies the "all" target
         - ninja ${NINJAFLAGS} install
-        - if [[ ${WITH_TESTS} == "yes" ]]; then
+        - if [[ ${WITH_TESTS} == "yes" ]] || [[ ${WITH_MATRIX_TESTS} == "yes" ]]; then
                 ninja test;
           fi
         - popd
@@ -125,6 +127,31 @@ cuda_tests_Release:
         WITH_TESTS: "yes"
 
 
+cuda_matrix_tests_Debug:
+    <<: *build_template
+    tags:
+        - openmp
+        - gpu
+    variables:
+        <<: *default_cmake_flags
+        WITH_OPENMP: "yes"
+        WITH_CUDA: "yes"
+        BUILD_TYPE: Debug
+        WITH_MATRIX_TESTS: "yes"
+
+cuda_matrix_tests_Release:
+    <<: *build_template
+    tags:
+        - openmp
+        - gpu
+    variables:
+        <<: *default_cmake_flags
+        WITH_OPENMP: "yes"
+        WITH_CUDA: "yes"
+        BUILD_TYPE: Release
+        WITH_MATRIX_TESTS: "yes"
+
+
 cuda_examples_Debug:
     <<: *build_template
     tags:
@@ -214,6 +241,35 @@ cuda_mpi_tests_Release:
         WITH_TESTS: "yes"
 
 
+cuda_mpi_matrix_tests_Debug:
+    <<: *build_template
+    tags:
+        - openmp
+        - gpu
+        - mpi
+    variables:
+        <<: *default_cmake_flags
+        WITH_OPENMP: "yes"
+        WITH_CUDA: "yes"
+        WITH_MPI: "yes"
+        BUILD_TYPE: Debug
+        WITH_MATRIX_TESTS: "yes"
+
+cuda_mpi_matrix_tests_Release:
+    <<: *build_template
+    tags:
+        - openmp
+        - gpu
+        - mpi
+    variables:
+        <<: *default_cmake_flags
+        WITH_OPENMP: "yes"
+        WITH_CUDA: "yes"
+        WITH_MPI: "yes"
+        BUILD_TYPE: Release
+        WITH_MATRIX_TESTS: "yes"
+
+
 cuda_mpi_examples_Debug:
     <<: *build_template
     tags:
@@ -293,6 +349,20 @@ default_tests_Release:
         BUILD_TYPE: Release
         WITH_TESTS: "yes"
 
+default_matrix_tests_Debug:
+    <<: *build_template
+    variables:
+        <<: *default_cmake_flags
+        BUILD_TYPE: Debug
+        WITH_MATRIX_TESTS: "yes"
+
+default_matrix_tests_Release:
+    <<: *build_template
+    variables:
+        <<: *default_cmake_flags
+        BUILD_TYPE: Release
+        WITH_MATRIX_TESTS: "yes"
+
 default_examples_Debug:
     <<: *build_template
     variables:
@@ -350,6 +420,30 @@ mpi_tests_Release:
         BUILD_TYPE: Release
         WITH_TESTS: "yes"
 
+mpi_matrix_tests_Debug:
+    <<: *build_template
+    tags:
+        - openmp
+        - mpi
+    variables:
+        <<: *default_cmake_flags
+        WITH_OPENMP: "yes"
+        WITH_MPI: "yes"
+        BUILD_TYPE: Debug
+        WITH_MATRIX_TESTS: "yes"
+
+mpi_matrix_tests_Release:
+    <<: *build_template
+    tags:
+        - openmp
+        - mpi
+    variables:
+        <<: *default_cmake_flags
+        WITH_OPENMP: "yes"
+        WITH_MPI: "yes"
+        BUILD_TYPE: Release
+        WITH_MATRIX_TESTS: "yes"
+
 mpi_examples_Debug:
     <<: *build_template
     tags:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3fd9e9a7db622db0a6e6d0b4d8936e75e269a592..e74510f942beb67e37384caeaf5ecd488ee1a24e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,7 @@ option(WITH_OPENMP "Build with OpenMP support" ON)
 option(WITH_MPI "Build with MPI support" ON)
 option(WITH_GMP "Build with GMP support" OFF)
 option(WITH_TESTS "Build tests" ON)
+option(WITH_MATRIX_TESTS "Build tests for matrices" ON)
 option(WITH_PROFILING "Enable code profiling compiler flags" OFF )
 option(WITH_COVERAGE "Enable code coverage reports from unit tests" OFF)
 option(WITH_EXAMPLES "Compile the 'src/Examples' directory" ON)
@@ -142,7 +143,7 @@ if( DEFINED ENV{CI_JOB_NAME} OR ${CMAKE_GENERATOR} STREQUAL "Ninja" )
 endif()
 
 # gtest has to be built before we add the MPI flags
-if( ${WITH_TESTS} )
+if( ${WITH_TESTS} OR ${WITH_MATRIX_TESTS} )
    enable_testing()
 
    # build gtest libs
@@ -358,6 +359,7 @@ message( "   WITH_OPENMP = ${WITH_OPENMP}" )
 message( "   WITH_MPI = ${WITH_MPI}" )
 message( "   WITH_GMP = ${WITH_GMP}" )
 message( "   WITH_TESTS = ${WITH_TESTS}" )
+message( "   WITH_MATRIX_TESTS = ${WITH_MATRIX_TESTS}" )
 message( "   WITH_PROFILING = ${WITH_PROFILING}" )
 message( "   WITH_COVERAGE = ${WITH_COVERAGE}" )
 message( "   WITH_EXAMPLES = ${WITH_EXAMPLES}" )
diff --git a/build b/build
index ee74fa87bfb98b0db0bd87976afcfe8ad9f741a8..5c9b86918a6afc249eedfab4be8ea406fd540c68 100755
--- a/build
+++ b/build
@@ -22,6 +22,7 @@ WITH_CUDA_ARCH="auto"
 WITH_OPENMP="yes"
 WITH_GMP="no"
 WITH_TESTS="yes"
+WITH_MATRIX_TESTS="yes"
 RUN_TESTS="yes"   # whether to run tests if they were compiled (coverage script sets it to no)
 TESTS_JOBS="4"
 WITH_PROFILING="no"
@@ -54,6 +55,7 @@ do
         --with-openmp=*                  ) WITH_OPENMP="${option#*=}" ;;
         --with-gmp=*                     ) WITH_GMP="${option#*=}" ;;
         --with-tests=*                   ) WITH_TESTS="${option#*=}" ;;
+        --with-matrix-tests=*            ) WITH_MATRIX_TESTS="${option#*=}" ;;
         --run-tests=*                    ) RUN_TESTS="${option#*=}" ;;
         --tests-jobs=*                   ) TESTS_JOBS="${option#*=}" ;;
         --with-profiling=*               ) WITH_PROFILING="${option#*=}" ;;
@@ -137,6 +139,7 @@ cmake_command=(
          -DWITH_MPI=${WITH_MPI}
          -DWITH_GMP=${WITH_GMP}
          -DWITH_TESTS=${WITH_TESTS}
+         -DWITH_MATRIX_TESTS=${WITH_MATRIX_TESTS}
          -DWITH_PROFILING=${WITH_PROFILING}
          -DWITH_COVERAGE=${WITH_COVERAGE}
          -DWITH_DOC=${WITH_DOC}
@@ -213,6 +216,8 @@ if [[ ${WITH_DOC} == "yes" ]]; then
    "$ROOT_DIR/Documentation/build" --prefix="$PREFIX"
 fi
 
-if [[ ${WITH_TESTS} == "yes" ]] && [[ ${RUN_TESTS} == "yes" ]]; then
-   CTEST_PARALLEL_LEVEL=${TESTS_JOBS} CTEST_OUTPUT_ON_FAILURE=1 $make test
+if [[ ${WITH_TESTS} == "yes" ]] || [[ ${WITH_MATRIX_TESTS} == "yes" ]]; then
+   if [[ ${RUN_TESTS} == "yes" ]]; then
+      CTEST_PARALLEL_LEVEL=${TESTS_JOBS} CTEST_OUTPUT_ON_FAILURE=1 $make test
+   fi
 fi
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d394ac2ec631d32de0cf486af411aa27d7cda181..f0ac2d20050cb75102936c63b5d47c5dcd01f1ea 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -24,6 +24,9 @@ endif()
 if( ${WITH_TESTS} )
    ADD_SUBDIRECTORY( UnitTests )
 endif()
+if( ${WITH_MATRIX_TESTS} )
+   ADD_SUBDIRECTORY( UnitTests/Matrices )
+endif()
 
 if( ${WITH_PYTHON} )
    ADD_SUBDIRECTORY( Python )
diff --git a/src/UnitTests/CMakeLists.txt b/src/UnitTests/CMakeLists.txt
index 6bfae47e1604e174272b19c1a0e5cfbe109c7dcc..15a6bf9f0d058f28366b76fa50436cd0579c541e 100644
--- a/src/UnitTests/CMakeLists.txt
+++ b/src/UnitTests/CMakeLists.txt
@@ -1,7 +1,7 @@
 ADD_SUBDIRECTORY( Communicators )
 ADD_SUBDIRECTORY( Containers )
 ADD_SUBDIRECTORY( Functions )
-ADD_SUBDIRECTORY( Matrices )
+# Matrices are included from src/CMakeLists.txt
 ADD_SUBDIRECTORY( Meshes )
 ADD_SUBDIRECTORY( Pointers )