From ebe1e871687b4eac356b22b9c7da655a4fb97a4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com>
Date: Sat, 30 Jan 2021 12:20:58 +0100
Subject: [PATCH] Legace matrix types moved to
 Benchmarks/SpMV/RereferenceFormats/Legacy.

---
 src/Benchmarks/BLAS/spmv.h                    | 10 +-
 .../SpMV/ReferenceFormats}/Legacy/AdEllpack.h | 14 ++-
 .../ReferenceFormats}/Legacy/AdEllpack_impl.h | 14 ++-
 .../SpMV/ReferenceFormats/Legacy/BiEllpack.h  | 12 ++-
 .../ReferenceFormats/Legacy/BiEllpack_impl.h  | 12 ++-
 .../SpMV/ReferenceFormats}/Legacy/CSR.h       | 14 ++-
 .../SpMV/ReferenceFormats}/Legacy/CSR_impl.h  | 16 ++--
 .../ReferenceFormats/Legacy/ChunkedEllpack.h  | 12 ++-
 .../Legacy/ChunkedEllpack_impl.h              | 12 ++-
 .../SpMV/ReferenceFormats/Legacy/Ellpack.h    | 12 ++-
 .../ReferenceFormats/Legacy/Ellpack_impl.h    | 12 ++-
 .../ReferenceFormats}/Legacy/Multidiagonal.h  | 16 ++--
 .../Legacy/MultidiagonalMatrixSetter.h        | 16 ++--
 .../Legacy/MultidiagonalMatrixSetter_impl.h   | 12 ++-
 .../Legacy/MultidiagonalRow.h                 | 14 ++-
 .../Legacy/MultidiagonalRow_impl.h            | 12 ++-
 .../Legacy/Multidiagonal_impl.h               | 14 ++-
 .../ReferenceFormats/Legacy/SlicedEllpack.h   | 12 ++-
 .../Legacy/SlicedEllpack_impl.h               | 12 ++-
 .../SpMV/ReferenceFormats/Legacy/Sparse.h     | 18 ++--
 .../SpMV/ReferenceFormats/Legacy/SparseRow.h  | 12 ++-
 .../ReferenceFormats/Legacy/SparseRow_impl.h  | 12 ++-
 .../ReferenceFormats/Legacy/Sparse_impl.h     | 20 ++--
 .../SpMV/ReferenceFormats/cusparseCSRMatrix.h |  2 +-
 src/Benchmarks/SpMV/spmv-legacy.h             | 39 ++++----
 src/TNL/Matrices/Matrix.h                     |  2 +-
 src/TNL/Matrices/MatrixInfo.h                 | 32 +++----
 src/TNL/Solvers/Linear/Preconditioners/ILU0.h |  4 +-
 .../Matrices/BinarySparseMatrixCopyTest.h     |  2 +-
 src/UnitTests/Matrices/DenseMatrixCopyTest.h  |  2 +-
 .../Matrices/Legacy/Legacy_SparseMatrixTest.h | 10 +-
 .../Legacy/Legacy_SparseMatrixTest.hpp        |  7 +-
 .../Legacy_SparseMatrixTest_BiEllpack.h       | 33 +++----
 .../Legacy/Legacy_SparseMatrixTest_CSR.h      | 94 +++++++++----------
 .../Legacy_SparseMatrixTest_ChunkedEllpack.h  | 33 +++----
 .../Legacy/Legacy_SparseMatrixTest_Ellpack.h  | 34 +++----
 .../Legacy_SparseMatrixTest_SlicedEllpack.h   |  4 +-
 src/UnitTests/Matrices/SparseMatrixCopyTest.h |  2 +-
 38 files changed, 351 insertions(+), 259 deletions(-)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/AdEllpack.h (96%)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/AdEllpack_impl.h (99%)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/CSR.h (97%)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/CSR_impl.h (99%)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/Multidiagonal.h (94%)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/MultidiagonalMatrixSetter.h (87%)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/MultidiagonalMatrixSetter_impl.h (94%)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/MultidiagonalRow.h (81%)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/MultidiagonalRow_impl.h (91%)
 rename src/{TNL/Matrices => Benchmarks/SpMV/ReferenceFormats}/Legacy/Multidiagonal_impl.h (98%)

diff --git a/src/Benchmarks/BLAS/spmv.h b/src/Benchmarks/BLAS/spmv.h
index 85cb4b7314..587794f356 100644
--- a/src/Benchmarks/BLAS/spmv.h
+++ b/src/Benchmarks/BLAS/spmv.h
@@ -15,7 +15,7 @@
 #include "../Benchmarks.h"
 
 #include <TNL/Pointers/DevicePointer.h>
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack.h>
@@ -25,11 +25,11 @@ namespace Benchmarks {
 
 // silly alias to match the number of template parameters with other formats
 template< typename Real, typename Device, typename Index >
-using SlicedEllpack = Matrices::Legacy::SlicedEllpack< Real, Device, Index >;
+using SlicedEllpack = SpMV::ReferenceFormats::Legacy::SlicedEllpack< Real, Device, Index >;
 
 // Legacy formats
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Scalar = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRScalar >;
+using SparseMatrixLegacy_CSR_Scalar = SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, SpMV::ReferenceFormats::Legacy::CSRScalar >;
 
 
 template< typename Matrix >
@@ -180,9 +180,9 @@ benchmarkSpmvSynthetic( Benchmark & benchmark,
    // TODO: benchmark all formats from tnl-benchmark-spmv (different parameters of the base formats)
    // NOTE: CSR is disabled because it is very slow on GPU
    //benchmarkSpMV< Real, SparseMatrixLegacy_CSR_Scalar >( benchmark, size, elementsPerRow );
-   benchmarkSpMV< Real, Matrices::Legacy::Ellpack >( benchmark, size, elementsPerRow );
+   benchmarkSpMV< Real, Benchmarks::SpMV::ReferenceFormats::Legacy::Ellpack >( benchmark, size, elementsPerRow );
    benchmarkSpMV< Real, SlicedEllpack >( benchmark, size, elementsPerRow );
-   benchmarkSpMV< Real, Matrices::Legacy::ChunkedEllpack >( benchmark, size, elementsPerRow );
+   benchmarkSpMV< Real, Benchmarks::SpMV::ReferenceFormats::Legacy::ChunkedEllpack >( benchmark, size, elementsPerRow );
 }
 
 } // namespace Benchmarks
diff --git a/src/TNL/Matrices/Legacy/AdEllpack.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack.h
similarity index 96%
rename from src/TNL/Matrices/Legacy/AdEllpack.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack.h
index 4c6a023666..7ef968cdda 100644
--- a/src/TNL/Matrices/Legacy/AdEllpack.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack.h
@@ -22,8 +22,10 @@
 #include <TNL/Containers/Vector.h>
 
 namespace TNL {
-namespace Matrices {
-namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+                namespace Legacy {
 
 template< typename Device >
 class AdEllpackDeviceDependentCode;
@@ -296,8 +298,10 @@ protected:
 
 };
 
-} //namespace Legacy
-} // namespace Matrices
+                } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
-#include <TNL/Matrices/Legacy/AdEllpack_impl.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack_impl.h>
diff --git a/src/TNL/Matrices/Legacy/AdEllpack_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack_impl.h
similarity index 99%
rename from src/TNL/Matrices/Legacy/AdEllpack_impl.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack_impl.h
index 3d3af0db10..42d3e3a6e0 100644
--- a/src/TNL/Matrices/Legacy/AdEllpack_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack_impl.h
@@ -8,7 +8,7 @@
 
 /* See Copyright Notice in tnl/Copyright */
 
-#include <TNL/Matrices/Legacy/AdEllpack.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack.h>
 #include <TNL/Containers/Vector.h>
 #include <TNL/Math.h>
 #include <TNL/TypeInfo.h>
@@ -16,8 +16,10 @@
 #pragma once
 
 namespace TNL {
-namespace Matrices {
-namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+                namespace Legacy {
 
 /*
  * Auxiliary list implementation
@@ -1587,6 +1589,8 @@ public:
 };
 
 
-} //namespace Legacy
-} // namespace Matrices
+                } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack.h
index 5f6e2728d4..cdb2c97e4e 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack.h
@@ -22,8 +22,10 @@
 #include <TNL/Containers/Vector.h>
 
 namespace TNL {
-   namespace Matrices {
-      namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+      			namespace Legacy {
 
 
 template< typename Device >
@@ -219,8 +221,10 @@ private:
 	Containers::Vector< Index, Device, Index > groupPointers;
 
 };
-      } //namespace Legacy
-   } //namespace Matrices
+      			} //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack_impl.h>
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack_impl.h
index 5c0ee8b2c8..d33ee47cc7 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack_impl.h
@@ -17,8 +17,10 @@
 #include <cstdio>
 
 namespace TNL {
-   namespace Matrices {
-      namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+      			namespace Legacy {
 
 
 template< typename Real,
@@ -1510,7 +1512,9 @@ public:
     }
 
 };
-      } //namespace Legacy
-   } //namespace Matrices
+      			} //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
diff --git a/src/TNL/Matrices/Legacy/CSR.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h
similarity index 97%
rename from src/TNL/Matrices/Legacy/CSR.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h
index c7a7af3216..487ed18bf5 100644
--- a/src/TNL/Matrices/Legacy/CSR.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h
@@ -17,8 +17,10 @@
 #include <TNL/Exceptions/CudaBadAlloc.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 enum class Type {
    /* LONG = 0!!! Non zero value rewrites index[1] */
@@ -332,8 +334,10 @@ protected:
    friend class CusparseCSR< RealType >;
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
-#include <TNL/Matrices/Legacy/CSR_impl.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR_impl.h>
diff --git a/src/TNL/Matrices/Legacy/CSR_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/CSR_impl.h
similarity index 99%
rename from src/TNL/Matrices/Legacy/CSR_impl.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/CSR_impl.h
index e23a20f0c2..4aa61a09f0 100644
--- a/src/TNL/Matrices/Legacy/CSR_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/CSR_impl.h
@@ -10,7 +10,7 @@
 
 #pragma once
 
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 #include <TNL/Containers/VectorView.h>
 #include <TNL/Math.h>
 #include <TNL/Algorithms/AtomicOperations.h>
@@ -26,8 +26,10 @@
 constexpr size_t MAX_X_DIM = 2147483647;
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 #ifdef HAVE_CUSPARSE
 template< typename Real, typename Index >
@@ -1764,7 +1766,7 @@ void SpMVCSRAdaptivePrepare( const Real *inVector,
 
       SpMVCSRAdaptive< Real, Index, warpSize,
             matrix.WARPS,
-            matrix.SHARED_PER_WARP, 
+            matrix.SHARED_PER_WARP,
             matrix.MAX_ELEMENTS_PER_WARP_ADAPT >
          <<<blocks, threads>>>(
                inVector,
@@ -1972,6 +1974,8 @@ class CSRDeviceDependentCode< Devices::Cuda >
       }
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack.h
index 3cd9a58ae5..0c310319ed 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack.h
@@ -26,8 +26,10 @@
 #include <TNL/Containers/Vector.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Device >
 class ChunkedEllpackDeviceDependentCode;
@@ -353,8 +355,10 @@ protected:
 #endif
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack_impl.h>
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack_impl.h
index 7cc04ad8b2..df66227770 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack_impl.h
@@ -16,8 +16,10 @@
 #include <TNL/Exceptions/NotImplementedError.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Real,
           typename Index,
@@ -1509,6 +1511,8 @@ class ChunkedEllpackDeviceDependentCode< Devices::Cuda >
 
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h
index ad812b6115..5aee8c7895 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h
@@ -14,8 +14,10 @@
 #include <TNL/Containers/Vector.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Device >
 class EllpackDeviceDependentCode;
@@ -210,8 +212,10 @@ protected:
    friend class EllpackDeviceDependentCode< DeviceType >;
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack_impl.h>
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack_impl.h
index f2e37c39ca..6f7845862a 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack_impl.h
@@ -16,8 +16,10 @@
 #include <TNL/Exceptions/NotImplementedError.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Real,
           typename Device,
@@ -975,6 +977,8 @@ class EllpackDeviceDependentCode< Devices::Cuda >
       }
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/TNL/Matrices/Legacy/Multidiagonal.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Multidiagonal.h
similarity index 94%
rename from src/TNL/Matrices/Legacy/Multidiagonal.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/Multidiagonal.h
index 129a9f59a5..8153854cca 100644
--- a/src/TNL/Matrices/Legacy/Multidiagonal.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Multidiagonal.h
@@ -12,11 +12,13 @@
 
 #include <TNL/Matrices/Matrix.h>
 #include <TNL/Containers/Vector.h>
-#include <TNL/Matrices/Legacy/MultidiagonalRow.h>
+#include <TNL/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalRow.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Device >
 class MultidiagonalDeviceDependentCode;
@@ -223,8 +225,10 @@ protected:
 };
 
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
-#include <TNL/Matrices/Legacy/Multidiagonal_impl.h>
+#include <TNL/Benchmarks/SpMV/ReferenceFormats/Legacy/Multidiagonal_impl.h>
diff --git a/src/TNL/Matrices/Legacy/MultidiagonalMatrixSetter.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalMatrixSetter.h
similarity index 87%
rename from src/TNL/Matrices/Legacy/MultidiagonalMatrixSetter.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalMatrixSetter.h
index b2cbc1d844..bbd13c2d32 100644
--- a/src/TNL/Matrices/Legacy/MultidiagonalMatrixSetter.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalMatrixSetter.h
@@ -11,11 +11,13 @@
 #pragma once
 
 #include <TNL/Meshes/Grid.h>
-#include <TNL/Matrices/Legacy/Multidiagonal.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/Multidiagonal.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename MeshType >
 class MultidiagonalMatrixSetter
@@ -83,8 +85,10 @@ class MultidiagonalMatrixSetter< Meshes::Grid< 3, MeshReal, Device, MeshIndex >
                                bool crossStencil = false );
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
-#include <TNL/Matrices/Legacy/MultidiagonalMatrixSetter_impl.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalMatrixSetter_impl.h>
diff --git a/src/TNL/Matrices/Legacy/MultidiagonalMatrixSetter_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalMatrixSetter_impl.h
similarity index 94%
rename from src/TNL/Matrices/Legacy/MultidiagonalMatrixSetter_impl.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalMatrixSetter_impl.h
index 69adba4a7d..cde61d7153 100644
--- a/src/TNL/Matrices/Legacy/MultidiagonalMatrixSetter_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalMatrixSetter_impl.h
@@ -11,8 +11,10 @@
 #pragma once
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename MeshReal,
           typename Device,
@@ -98,6 +100,8 @@ setupMatrix( const MeshType& mesh,
    return true;
 }
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/TNL/Matrices/Legacy/MultidiagonalRow.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalRow.h
similarity index 81%
rename from src/TNL/Matrices/Legacy/MultidiagonalRow.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalRow.h
index 5b37dfc560..2b078bde93 100644
--- a/src/TNL/Matrices/Legacy/MultidiagonalRow.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalRow.h
@@ -11,8 +11,10 @@
 #pragma once
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Real, typename Index >
 class MultidiagonalRow
@@ -52,9 +54,11 @@ class MultidiagonalRow
       Index row, columns, maxRowLength, step;
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
-#include <TNL/Matrices/Legacy/MultidiagonalRow_impl.h>
+#include <TNL/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalRow_impl.h>
 
diff --git a/src/TNL/Matrices/Legacy/MultidiagonalRow_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalRow_impl.h
similarity index 91%
rename from src/TNL/Matrices/Legacy/MultidiagonalRow_impl.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalRow_impl.h
index 58ecc6207b..7942032c79 100644
--- a/src/TNL/Matrices/Legacy/MultidiagonalRow_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/MultidiagonalRow_impl.h
@@ -11,8 +11,10 @@
 #pragma once
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Real, typename Index >
 __cuda_callable__
@@ -92,6 +94,8 @@ setElement( const Index& elementIndex,
    this->values[ aux * this->step ] = value;
 }
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/TNL/Matrices/Legacy/Multidiagonal_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Multidiagonal_impl.h
similarity index 98%
rename from src/TNL/Matrices/Legacy/Multidiagonal_impl.h
rename to src/Benchmarks/SpMV/ReferenceFormats/Legacy/Multidiagonal_impl.h
index d3a7599054..f976f1981d 100644
--- a/src/TNL/Matrices/Legacy/Multidiagonal_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Multidiagonal_impl.h
@@ -10,14 +10,16 @@
 
 #pragma once
 
-#include <TNL/Matrices/Legacy/Multidiagonal.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/Multidiagonal.h>
 #include <TNL/Containers/Vector.h>
 #include <TNL/Math.h>
 #include <TNL/Exceptions/NotImplementedError.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Device >
 class MultidiagonalDeviceDependentCode;
@@ -813,6 +815,8 @@ class MultidiagonalDeviceDependentCode< Devices::Cuda >
       }
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h
index 0254c5e4b9..e41949129b 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h
@@ -25,8 +25,10 @@
 #include <TNL/Containers/Vector.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Device >
 class SlicedEllpackDeviceDependentCode;
@@ -238,8 +240,10 @@ public:
 #endif
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack_impl.h>
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack_impl.h
index 3a28a4a6e3..c7127cf1fd 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack_impl.h
@@ -16,8 +16,10 @@
 #include <TNL/Exceptions/NotImplementedError.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Real,
           typename Device,
@@ -1061,6 +1063,8 @@ class SlicedEllpackDeviceDependentCode< Devices::Cuda >
       }
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Sparse.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Sparse.h
index 5f75efe184..2e50843c2e 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Sparse.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Sparse.h
@@ -14,22 +14,24 @@
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Real,
           typename Device,
           typename Index >
-class Sparse : public Matrix< Real, Device, Index >
+class Sparse : public TNL::Matrices::Matrix< Real, Device, Index >
 {
    public:
 
    typedef Real RealType;
    typedef Device DeviceType;
    typedef Index IndexType;
-   typedef typename Matrix< RealType, DeviceType, IndexType >::ValuesVectorType ValuesVector;
+   typedef typename TNL::Matrices::Matrix< RealType, DeviceType, IndexType >::ValuesVectorType ValuesVector;
    typedef Containers::Vector< IndexType, DeviceType, IndexType > ColumnIndexesVector;
-   typedef Matrix< Real, Device, Index > BaseType;
+   typedef TNL::Matrices::Matrix< Real, Device, Index > BaseType;
    typedef SparseRow< RealType, IndexType > MatrixRow;
    typedef SparseRow< const RealType, const IndexType > ConstMatrixRow;
 
@@ -62,8 +64,10 @@ class Sparse : public Matrix< Real, Device, Index >
    Index maxRowLength;
 };
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/Sparse_impl.h>
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow.h
index 0b5ff29d99..c0f578b089 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow.h
@@ -17,8 +17,10 @@
 #include <TNL/Cuda/CudaCallable.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Real, typename Index >
 class SparseRow
@@ -96,8 +98,10 @@ std::ostream& operator<<( std::ostream& str, const SparseRow< Real, Index >& row
    return str;
 }
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
 
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow_impl.h>
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow_impl.h
index f538bbb862..fa486fa91f 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/SparseRow_impl.h
@@ -18,8 +18,10 @@
 #include <vector>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Real, typename Index >
 __cuda_callable__
@@ -166,6 +168,8 @@ print( std::ostream& str ) const
    }
 }
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Sparse_impl.h b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Sparse_impl.h
index bb8b344981..d87c80eee5 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Sparse_impl.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/Legacy/Sparse_impl.h
@@ -14,8 +14,10 @@
 #include <TNL/Exceptions/NotImplementedError.h>
 
 namespace TNL {
-namespace Matrices {
-   namespace Legacy {
+    namespace Benchmarks {
+        namespace SpMV {
+            namespace ReferenceFormats {
+               namespace Legacy {
 
 template< typename Real,
           typename Device,
@@ -33,7 +35,7 @@ template< typename Real,
              typename Index2 >
 void Sparse< Real, Device, Index >::setLike( const Sparse< Real2, Device2, Index2 >& matrix )
 {
-   Matrix< Real, Device, Index >::setLike( matrix );
+   TNL::Matrices::Matrix< Real, Device, Index >::setLike( matrix );
    this->allocateMatrixElements( matrix.getAllocatedElementsCount() );
 }
 
@@ -75,7 +77,7 @@ template< typename Real,
           typename Index >
 void Sparse< Real, Device, Index >::reset()
 {
-   Matrix< Real, Device, Index >::reset();
+   TNL::Matrices::Matrix< Real, Device, Index >::reset();
    this->columnIndexes.reset();
 }
 
@@ -84,7 +86,7 @@ template< typename Real,
           typename Index >
 void Sparse< Real, Device, Index >::save( File& file ) const
 {
-   Matrix< Real, Device, Index >::save( file );
+   TNL::Matrices::Matrix< Real, Device, Index >::save( file );
    file << this->values << this->columnIndexes;
 }
 
@@ -93,7 +95,7 @@ template< typename Real,
           typename Index >
 void Sparse< Real, Device, Index >::load( File& file )
 {
-   Matrix< Real, Device, Index >::load( file );
+   TNL::Matrices::Matrix< Real, Device, Index >::load( file );
    file >> this->values >> this->columnIndexes;
 }
 
@@ -123,6 +125,8 @@ void Sparse< Real, Device, Index >::printStructure( std::ostream& str ) const
    throw Exceptions::NotImplementedError("Sparse::printStructure is not implemented yet.");
 }
 
-} //namespace Legacy
-} // namespace Matrices
+               } //namespace Legacy
+            } //namespace ReferenceFormats
+        } //namespace SpMV
+    } //namespace Benchmarks
 } // namespace TNL
diff --git a/src/Benchmarks/SpMV/ReferenceFormats/cusparseCSRMatrix.h b/src/Benchmarks/SpMV/ReferenceFormats/cusparseCSRMatrix.h
index ea5b9ddbfa..b331ac7ad1 100644
--- a/src/Benchmarks/SpMV/ReferenceFormats/cusparseCSRMatrix.h
+++ b/src/Benchmarks/SpMV/ReferenceFormats/cusparseCSRMatrix.h
@@ -22,7 +22,7 @@ class CusparseCSRBase
    public:
       typedef Real RealType;
       typedef Devices::Cuda DeviceType;
-      typedef Matrices::Legacy::CSR< RealType, Devices::Cuda, int > MatrixType;
+      typedef Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< RealType, Devices::Cuda, int > MatrixType;
 
       CusparseCSRBase()
       : matrix( 0 )
diff --git a/src/Benchmarks/SpMV/spmv-legacy.h b/src/Benchmarks/SpMV/spmv-legacy.h
index fed37410cf..f7fbf92404 100644
--- a/src/Benchmarks/SpMV/spmv-legacy.h
+++ b/src/Benchmarks/SpMV/spmv-legacy.h
@@ -18,11 +18,11 @@
 #include "SpmvBenchmarkResult.h"
 
 #include <TNL/Pointers/DevicePointer.h>
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack.h>
-#include <TNL/Matrices/Legacy/AdEllpack.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack.h>
 
 #include <TNL/Matrices/MatrixReader.h>
@@ -45,7 +45,7 @@ namespace TNL {
 
 // Alias to match the number of template parameters with other formats
 template< typename Real, typename Device, typename Index >
-using SlicedEllpackAlias = Matrices::Legacy::SlicedEllpack< Real, Device, Index >;
+using SlicedEllpackAlias = Benchmarks::SpMV::ReferenceFormats::Legacy::SlicedEllpack< Real, Device, Index >;
 
 // Segments based sparse matrix aliases
 template< typename Real, typename Device, typename Index >
@@ -86,37 +86,37 @@ using SparseMatrix_BiEllpack = Matrices::SparseMatrix< Real, Device, Index, Matr
 
 // Legacy formats
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Scalar = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRScalar >;
+using SparseMatrixLegacy_CSR_Scalar = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRScalar >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Vector = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRVector >;
+using SparseMatrixLegacy_CSR_Vector = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRVector >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Light = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRLight >;
+using SparseMatrixLegacy_CSR_Light = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Light2 = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRLight2 >;
+using SparseMatrixLegacy_CSR_Light2 = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight2 >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Light3 = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRLight3 >;
+using SparseMatrixLegacy_CSR_Light3 = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight3 >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Light4 = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRLight4 >;
+using SparseMatrixLegacy_CSR_Light4 = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight4 >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Light5 = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRLight5 >;
+using SparseMatrixLegacy_CSR_Light5 = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight5 >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Light6 = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRLight6 >;
+using SparseMatrixLegacy_CSR_Light6 = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight6 >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_Adaptive = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRAdaptive >;
+using SparseMatrixLegacy_CSR_Adaptive = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRAdaptive >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_MultiVector = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRMultiVector >;
+using SparseMatrixLegacy_CSR_MultiVector = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRMultiVector >;
 
 template< typename Real, typename Device, typename Index >
-using SparseMatrixLegacy_CSR_LightWithoutAtomic = Matrices::Legacy::CSR< Real, Device, Index, Matrices::Legacy::CSRLightWithoutAtomic >;
+using SparseMatrixLegacy_CSR_LightWithoutAtomic = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLightWithoutAtomic >;
 
 // Get the name (with extension) of input matrix file
 std::string getMatrixFileName( const String& InputFileName )
@@ -239,8 +239,8 @@ benchmarkSpmvSynthetic( Benchmark& benchmark,
                         const String& inputFileName,
                         bool verboseMR )
 {
-   using CSRHostMatrix = Matrices::Legacy::CSR< Real, Devices::Host, int >;
-   using CSRCudaMatrix = Matrices::Legacy::CSR< Real, Devices::Cuda, int >;
+   using CSRHostMatrix = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Devices::Host, int >;
+   using CSRCudaMatrix = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Devices::Cuda, int >;
    using HostVector = Containers::Vector< Real, Devices::Host, int >;
    using CudaVector = Containers::Vector< Real, Devices::Cuda, int >;
 
@@ -318,6 +318,7 @@ benchmarkSpmvSynthetic( Benchmark& benchmark,
    benchmark.time< Devices::Cuda >( resetCusparseVectors, "GPU", spmvCusparse, cusparseBenchmarkResults );
 #endif
 
+   using namespace Benchmarks::SpMV::ReferenceFormats;
    benchmarkSpMV< Real, SparseMatrixLegacy_CSR_Scalar             >( benchmark, hostOutVector, inputFileName, verboseMR );
    benchmarkSpMV< Real, SparseMatrixLegacy_CSR_Vector             >( benchmark, hostOutVector, inputFileName, verboseMR );
    benchmarkSpMV< Real, SparseMatrixLegacy_CSR_Light              >( benchmark, hostOutVector, inputFileName, verboseMR );
@@ -333,13 +334,13 @@ benchmarkSpmvSynthetic( Benchmark& benchmark,
    benchmarkSpMV< Real, SparseMatrix_CSR_Vector                   >( benchmark, hostOutVector, inputFileName, verboseMR );
    benchmarkSpMV< Real, SparseMatrix_CSR_Hybrid                   >( benchmark, hostOutVector, inputFileName, verboseMR );
    benchmarkSpMV< Real, SparseMatrix_CSR_Adaptive                 >( benchmark, hostOutVector, inputFileName, verboseMR );
-   benchmarkSpMV< Real, Matrices::Legacy::Ellpack                 >( benchmark, hostOutVector, inputFileName, verboseMR );
+   benchmarkSpMV< Real, Legacy::Ellpack                           >( benchmark, hostOutVector, inputFileName, verboseMR );
    benchmarkSpMV< Real, SparseMatrix_Ellpack                      >( benchmark, hostOutVector, inputFileName, verboseMR );
    benchmarkSpMV< Real, SlicedEllpackAlias                        >( benchmark, hostOutVector, inputFileName, verboseMR );
    benchmarkSpMV< Real, SparseMatrix_SlicedEllpack                >( benchmark, hostOutVector, inputFileName, verboseMR );
-   benchmarkSpMV< Real, Matrices::Legacy::ChunkedEllpack          >( benchmark, hostOutVector, inputFileName, verboseMR );
+   benchmarkSpMV< Real, Legacy::ChunkedEllpack                    >( benchmark, hostOutVector, inputFileName, verboseMR );
    benchmarkSpMV< Real, SparseMatrix_ChunkedEllpack               >( benchmark, hostOutVector, inputFileName, verboseMR );
-   benchmarkSpMV< Real, Matrices::Legacy::BiEllpack               >( benchmark, hostOutVector, inputFileName, verboseMR );
+   benchmarkSpMV< Real, Legacy::BiEllpack                         >( benchmark, hostOutVector, inputFileName, verboseMR );
    benchmarkSpMV< Real, SparseMatrix_BiEllpack                    >( benchmark, hostOutVector, inputFileName, verboseMR );
    /* AdEllpack is broken
    benchmarkSpMV< Real, Matrices::AdEllpack              >( benchmark, hostOutVector, inputFileName, verboseMR );
diff --git a/src/TNL/Matrices/Matrix.h b/src/TNL/Matrices/Matrix.h
index 7ddbd115d5..702e79162d 100644
--- a/src/TNL/Matrices/Matrix.h
+++ b/src/TNL/Matrices/Matrix.h
@@ -20,7 +20,7 @@
 
 namespace TNL {
 /**
- * \brief Namespace for matrices of different types.
+ * \brief Namespace for different matrix types.
  */
 namespace Matrices {
 
diff --git a/src/TNL/Matrices/MatrixInfo.h b/src/TNL/Matrices/MatrixInfo.h
index 2715d2f6e1..7d28956163 100644
--- a/src/TNL/Matrices/MatrixInfo.h
+++ b/src/TNL/Matrices/MatrixInfo.h
@@ -18,7 +18,7 @@
 #include <TNL/Algorithms/Segments/CSRView.h>
 #include <TNL/Algorithms/Segments/EllpackView.h>
 #include <TNL/Algorithms/Segments/SlicedEllpackView.h>
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack.h>
@@ -82,7 +82,7 @@ struct MatrixInfo< SparseMatrix< Real, Device, Index, MatrixType, Segments, Real
 /////
 // Legacy matrices
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::BiEllpack< Real, Device, Index > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::BiEllpack< Real, Device, Index > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -90,7 +90,7 @@ struct MatrixInfo< Legacy::BiEllpack< Real, Device, Index > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRScalar > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRScalar > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -98,7 +98,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRScalar > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRVector> >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRVector> >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -106,7 +106,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRVector> >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -114,7 +114,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight2 > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight2 > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -122,7 +122,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight2 > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight3 > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight3 > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -130,7 +130,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight3 > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight4 > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight4 > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -138,7 +138,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight4 > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight5 > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight5 > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -146,7 +146,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight5 > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight6 > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLight6 > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -154,7 +154,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLight6 > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRAdaptive > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRAdaptive > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -162,7 +162,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRAdaptive > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRMultiVector > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRMultiVector > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -170,7 +170,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRMultiVector > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLightWithoutAtomic > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< Real, Device, Index, Benchmarks::SpMV::ReferenceFormats::Legacy::CSRLightWithoutAtomic > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -178,7 +178,7 @@ struct MatrixInfo< Legacy::CSR< Real, Device, Index, Legacy::CSRLightWithoutAtom
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::ChunkedEllpack< Real, Device, Index > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::ChunkedEllpack< Real, Device, Index > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -186,7 +186,7 @@ struct MatrixInfo< Legacy::ChunkedEllpack< Real, Device, Index > >
 };
 
 template< typename Real, typename Device, typename Index >
-struct MatrixInfo< Legacy::Ellpack< Real, Device, Index > >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::Ellpack< Real, Device, Index > >
 {
    static String getDensity() { return String( "sparse" ); };
 
@@ -194,7 +194,7 @@ struct MatrixInfo< Legacy::Ellpack< Real, Device, Index > >
 };
 
 template< typename Real, typename Device, typename Index, int SliceSize >
-struct MatrixInfo< Legacy::SlicedEllpack< Real, Device, Index, SliceSize> >
+struct MatrixInfo< Benchmarks::SpMV::ReferenceFormats::Legacy::SlicedEllpack< Real, Device, Index, SliceSize> >
 {
    static String getDensity() { return String( "sparse" ); };
 
diff --git a/src/TNL/Solvers/Linear/Preconditioners/ILU0.h b/src/TNL/Solvers/Linear/Preconditioners/ILU0.h
index 8791b95e25..f72f398257 100644
--- a/src/TNL/Solvers/Linear/Preconditioners/ILU0.h
+++ b/src/TNL/Solvers/Linear/Preconditioners/ILU0.h
@@ -20,7 +20,7 @@
 #include <TNL/Exceptions/NotImplementedError.h>
 
 #if defined(HAVE_CUDA) && defined(HAVE_CUSPARSE)
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 #include <cusparse.h>
 #endif
 
@@ -136,7 +136,7 @@ public:
 protected:
 
 #if defined(HAVE_CUDA) && defined(HAVE_CUSPARSE)
-   using CSR = Matrices::Legacy::CSR< RealType, DeviceType, IndexType >;
+   using CSR = Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< RealType, DeviceType, IndexType >;
    Pointers::UniquePointer< CSR > A, L, U;
    Containers::Vector< RealType, DeviceType, IndexType > y;
 
diff --git a/src/UnitTests/Matrices/BinarySparseMatrixCopyTest.h b/src/UnitTests/Matrices/BinarySparseMatrixCopyTest.h
index 722ed5c6d2..0f2b00595b 100644
--- a/src/UnitTests/Matrices/BinarySparseMatrixCopyTest.h
+++ b/src/UnitTests/Matrices/BinarySparseMatrixCopyTest.h
@@ -8,7 +8,7 @@
 
 /* See Copyright Notice in tnl/Copyright */
 
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h>
 
diff --git a/src/UnitTests/Matrices/DenseMatrixCopyTest.h b/src/UnitTests/Matrices/DenseMatrixCopyTest.h
index 9e5794d0d9..fb1277ea2c 100644
--- a/src/UnitTests/Matrices/DenseMatrixCopyTest.h
+++ b/src/UnitTests/Matrices/DenseMatrixCopyTest.h
@@ -8,7 +8,7 @@
 
 /* See Copyright Notice in tnl/Copyright */
 
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h>
 
diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest.h b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest.h
index db79594387..b303876dd4 100644
--- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest.h
+++ b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest.h
@@ -8,7 +8,7 @@
 
 /* See Copyright Notice in tnl/Copyright */
 
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 
 #include "Legacy_SparseMatrixTest.hpp"
 #include <iostream>
@@ -16,11 +16,11 @@
 #ifdef HAVE_GTEST 
 #include <gtest/gtest.h>
 
-using CSR_host_float = TNL::Matrices::Legacy::CSR< float, TNL::Devices::Host, int >;
-using CSR_host_int = TNL::Matrices::Legacy::CSR< int, TNL::Devices::Host, int >;
+using CSR_host_float = TNL::Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< float, TNL::Devices::Host, int >;
+using CSR_host_int = TNL::Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< int, TNL::Devices::Host, int >;
 
-using CSR_cuda_float = TNL::Matrices::Legacy::CSR< float, TNL::Devices::Cuda, int >;
-using CSR_cuda_int = TNL::Matrices::Legacy::CSR< int, TNL::Devices::Cuda, int >;
+using CSR_cuda_float = TNL::Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< float, TNL::Devices::Cuda, int >;
+using CSR_cuda_int = TNL::Benchmarks::SpMV::ReferenceFormats::Legacy::CSR< int, TNL::Devices::Cuda, int >;
 
 TEST( SparseMatrixTest, CSR_perforSORIterationTest_Host )
 {
diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest.hpp b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest.hpp
index 1023186c49..fe856cde3e 100644
--- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest.hpp
+++ b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest.hpp
@@ -16,7 +16,7 @@
 
 // Temporary, until test_OperatorEquals doesn't work for all formats.
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/ChunkedEllpack.h>
-#include <TNL/Matrices/Legacy/AdEllpack.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/AdEllpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/BiEllpack.h>
 
 #ifdef HAVE_GTEST
@@ -1657,12 +1657,13 @@ void test_OperatorEquals()
    using DeviceType = typename Matrix::DeviceType;
    using IndexType = typename Matrix::IndexType;
 
+   using namespace TNL::Benchmarks::SpMV::ReferenceFormats;
    if( std::is_same< DeviceType, TNL::Devices::Cuda >::value )
        return;
    else
    {
-       using AdELL_host = TNL::Matrices::Legacy::AdEllpack< RealType, TNL::Devices::Host, IndexType >;
-       using AdELL_cuda = TNL::Matrices::Legacy::AdEllpack< RealType, TNL::Devices::Cuda, IndexType >;
+       using AdELL_host = Legacy::AdEllpack< RealType, TNL::Devices::Host, IndexType >;
+       using AdELL_cuda = Legacy::AdEllpack< RealType, TNL::Devices::Cuda, IndexType >;
 
        /*
         * Sets up the following 8x8 sparse matrix:
diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_BiEllpack.h b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_BiEllpack.h
index e443a61783..e2ee5c15e8 100644
--- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_BiEllpack.h
+++ b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_BiEllpack.h
@@ -24,26 +24,27 @@ protected:
    using BiEllpackMatrixType = Matrix;
 };
 
+using namespace TNL::Benchmarks::SpMV::ReferenceFormats;
 // types for which MatrixTest is instantiated
 using BiEllpackMatrixTypes = ::testing::Types
 <
-    TNL::Matrices::Legacy::BiEllpack< int,    TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::BiEllpack< long,   TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::BiEllpack< float,  TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::BiEllpack< double, TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::BiEllpack< int,    TNL::Devices::Host, long >,
-    TNL::Matrices::Legacy::BiEllpack< long,   TNL::Devices::Host, long >,
-    TNL::Matrices::Legacy::BiEllpack< float,  TNL::Devices::Host, long >,
-    TNL::Matrices::Legacy::BiEllpack< double, TNL::Devices::Host, long >
+    Legacy::BiEllpack< int,    TNL::Devices::Host, int >,
+    Legacy::BiEllpack< long,   TNL::Devices::Host, int >,
+    Legacy::BiEllpack< float,  TNL::Devices::Host, int >,
+    Legacy::BiEllpack< double, TNL::Devices::Host, int >,
+    Legacy::BiEllpack< int,    TNL::Devices::Host, long >,
+    Legacy::BiEllpack< long,   TNL::Devices::Host, long >,
+    Legacy::BiEllpack< float,  TNL::Devices::Host, long >,
+    Legacy::BiEllpack< double, TNL::Devices::Host, long >
 #ifdef HAVE_CUDA
-   ,TNL::Matrices::Legacy::BiEllpack< int,    TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::BiEllpack< long,   TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::BiEllpack< float,  TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::BiEllpack< double, TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::BiEllpack< int,    TNL::Devices::Cuda, long >,
-    TNL::Matrices::Legacy::BiEllpack< long,   TNL::Devices::Cuda, long >,
-    TNL::Matrices::Legacy::BiEllpack< float,  TNL::Devices::Cuda, long >,
-    TNL::Matrices::Legacy::BiEllpack< double, TNL::Devices::Cuda, long >
+   ,Legacy::BiEllpack< int,    TNL::Devices::Cuda, int >,
+    Legacy::BiEllpack< long,   TNL::Devices::Cuda, int >,
+    Legacy::BiEllpack< float,  TNL::Devices::Cuda, int >,
+    Legacy::BiEllpack< double, TNL::Devices::Cuda, int >,
+    Legacy::BiEllpack< int,    TNL::Devices::Cuda, long >,
+    Legacy::BiEllpack< long,   TNL::Devices::Cuda, long >,
+    Legacy::BiEllpack< float,  TNL::Devices::Cuda, long >,
+    Legacy::BiEllpack< double, TNL::Devices::Cuda, long >
 #endif
 >;
 
diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_CSR.h b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_CSR.h
index c43185c141..33aaab2607 100644
--- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_CSR.h
+++ b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_CSR.h
@@ -8,7 +8,7 @@
 
 /* See Copyright Notice in tnl/Copyright */
 
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 
 #include "Legacy_SparseMatrixTest.hpp"
 #include <iostream>
@@ -24,58 +24,54 @@ protected:
    using CSRMatrixType = Matrix;
 };
 
+using namespace TNL::Benchmarks::SpMV::ReferenceFormats;
+
 // types for which MatrixTest is instantiated
 using CSRMatrixTypes = ::testing::Types
 <
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Host, int,  TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Host, int,  TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Host, int,  TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Host, long, TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Host, long, TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Host, long, TNL::Matrices::Legacy::CSRScalar >
+   Legacy::CSR< int,    TNL::Devices::Host, int,  Legacy::CSRScalar >,
+   Legacy::CSR< float,  TNL::Devices::Host, int,  Legacy::CSRScalar >,
+   Legacy::CSR< double, TNL::Devices::Host, int,  Legacy::CSRScalar >,
+   Legacy::CSR< int,    TNL::Devices::Host, long, Legacy::CSRScalar >,
+   Legacy::CSR< float,  TNL::Devices::Host, long, Legacy::CSRScalar >,
+   Legacy::CSR< double, TNL::Devices::Host, long, Legacy::CSRScalar >
 #ifdef HAVE_CUDA
-  ,TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRScalar >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRVector >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRVector >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRVector >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRVector >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRVector >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRVector >,
-   /*TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRHybrid >, // Not implemented
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRHybrid >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRHybrid >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRHybrid >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRHybrid >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRHybrid >,*/
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRLight >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRLight >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRLight >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRLight >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRLight >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRLight >,
-   /*TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRAdaptive >, // Does not work, needs to be fixed.
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRAdaptive >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRAdaptive >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRAdaptive >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRAdaptive >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRAdaptive >,*/
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRMultiVector >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRMultiVector >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRMultiVector >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRMultiVector >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRMultiVector >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRMultiVector >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRLightWithoutAtomic >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRLightWithoutAtomic >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, int,  TNL::Matrices::Legacy::CSRLightWithoutAtomic >,
-   TNL::Matrices::Legacy::CSR< int,    TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRLightWithoutAtomic >,
-   TNL::Matrices::Legacy::CSR< float,  TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRLightWithoutAtomic >,
-   TNL::Matrices::Legacy::CSR< double, TNL::Devices::Cuda, long, TNL::Matrices::Legacy::CSRLightWithoutAtomic >
+  ,Legacy::CSR< int,    TNL::Devices::Cuda, int,  Legacy::CSRScalar >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, int,  Legacy::CSRScalar >,
+   Legacy::CSR< double, TNL::Devices::Cuda, int,  Legacy::CSRScalar >,
+   Legacy::CSR< int,    TNL::Devices::Cuda, long, Legacy::CSRScalar >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, long, Legacy::CSRScalar >,
+   Legacy::CSR< double, TNL::Devices::Cuda, long, Legacy::CSRScalar >,
+   Legacy::CSR< int,    TNL::Devices::Cuda, int,  Legacy::CSRVector >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, int,  Legacy::CSRVector >,
+   Legacy::CSR< double, TNL::Devices::Cuda, int,  Legacy::CSRVector >,
+   Legacy::CSR< int,    TNL::Devices::Cuda, long, Legacy::CSRVector >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, long, Legacy::CSRVector >,
+   Legacy::CSR< double, TNL::Devices::Cuda, long, Legacy::CSRVector >,
+   Legacy::CSR< int,    TNL::Devices::Cuda, int,  Legacy::CSRLight >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, int,  Legacy::CSRLight >,
+   Legacy::CSR< double, TNL::Devices::Cuda, int,  Legacy::CSRLight >,
+   Legacy::CSR< int,    TNL::Devices::Cuda, long, Legacy::CSRLight >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, long, Legacy::CSRLight >,
+   Legacy::CSR< double, TNL::Devices::Cuda, long, Legacy::CSRLight >,
+ /*Legacy::CSR< int,    TNL::Devices::Cuda, int,  Legacy::CSRAdaptive >, // Does not work, needs to be fixed.
+   Legacy::CSR< float,  TNL::Devices::Cuda, int,  Legacy::CSRAdaptive >,
+   Legacy::CSR< double, TNL::Devices::Cuda, int,  Legacy::CSRAdaptive >,
+   Legacy::CSR< int,    TNL::Devices::Cuda, long, Legacy::CSRAdaptive >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, long, Legacy::CSRAdaptive >,
+   Legacy::CSR< double, TNL::Devices::Cuda, long, Legacy::CSRAdaptive >,*/
+   Legacy::CSR< int,    TNL::Devices::Cuda, int,  Legacy::CSRMultiVector >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, int,  Legacy::CSRMultiVector >,
+   Legacy::CSR< double, TNL::Devices::Cuda, int,  Legacy::CSRMultiVector >,
+   Legacy::CSR< int,    TNL::Devices::Cuda, long, Legacy::CSRMultiVector >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, long, Legacy::CSRMultiVector >,
+   Legacy::CSR< double, TNL::Devices::Cuda, long, Legacy::CSRMultiVector >,
+   Legacy::CSR< int,    TNL::Devices::Cuda, int,  Legacy::CSRLightWithoutAtomic >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, int,  Legacy::CSRLightWithoutAtomic >,
+   Legacy::CSR< double, TNL::Devices::Cuda, int,  Legacy::CSRLightWithoutAtomic >,
+   Legacy::CSR< int,    TNL::Devices::Cuda, long, Legacy::CSRLightWithoutAtomic >,
+   Legacy::CSR< float,  TNL::Devices::Cuda, long, Legacy::CSRLightWithoutAtomic >,
+   Legacy::CSR< double, TNL::Devices::Cuda, long, Legacy::CSRLightWithoutAtomic >
 #endif
 >;
 
diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_ChunkedEllpack.h b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_ChunkedEllpack.h
index 84d0151887..1391e8be5a 100644
--- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_ChunkedEllpack.h
+++ b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_ChunkedEllpack.h
@@ -24,27 +24,28 @@ protected:
    using ChunkedEllpackMatrixType = Matrix;
 };
 
+using namespace TNL::Benchmarks::SpMV::ReferenceFormats;
 
 // types for which MatrixTest is instantiated
 using ChEllpackMatrixTypes = ::testing::Types
 <
-    TNL::Matrices::Legacy::ChunkedEllpack< int,    TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::ChunkedEllpack< long,   TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::ChunkedEllpack< float,  TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::ChunkedEllpack< double, TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::ChunkedEllpack< int,    TNL::Devices::Host, long >,
-    TNL::Matrices::Legacy::ChunkedEllpack< long,   TNL::Devices::Host, long >,
-    TNL::Matrices::Legacy::ChunkedEllpack< float,  TNL::Devices::Host, long >,
-    TNL::Matrices::Legacy::ChunkedEllpack< double, TNL::Devices::Host, long >
+    Legacy::ChunkedEllpack< int,    TNL::Devices::Host, int >,
+    Legacy::ChunkedEllpack< long,   TNL::Devices::Host, int >,
+    Legacy::ChunkedEllpack< float,  TNL::Devices::Host, int >,
+    Legacy::ChunkedEllpack< double, TNL::Devices::Host, int >,
+    Legacy::ChunkedEllpack< int,    TNL::Devices::Host, long >,
+    Legacy::ChunkedEllpack< long,   TNL::Devices::Host, long >,
+    Legacy::ChunkedEllpack< float,  TNL::Devices::Host, long >,
+    Legacy::ChunkedEllpack< double, TNL::Devices::Host, long >
 #ifdef HAVE_CUDA
-   ,TNL::Matrices::Legacy::ChunkedEllpack< int,    TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::ChunkedEllpack< long,   TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::ChunkedEllpack< float,  TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::ChunkedEllpack< double, TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::ChunkedEllpack< int,    TNL::Devices::Cuda, long >,
-    TNL::Matrices::Legacy::ChunkedEllpack< long,   TNL::Devices::Cuda, long >,
-    TNL::Matrices::Legacy::ChunkedEllpack< float,  TNL::Devices::Cuda, long >,
-    TNL::Matrices::Legacy::ChunkedEllpack< double, TNL::Devices::Cuda, long >
+   ,Legacy::ChunkedEllpack< int,    TNL::Devices::Cuda, int >,
+    Legacy::ChunkedEllpack< long,   TNL::Devices::Cuda, int >,
+    Legacy::ChunkedEllpack< float,  TNL::Devices::Cuda, int >,
+    Legacy::ChunkedEllpack< double, TNL::Devices::Cuda, int >,
+    Legacy::ChunkedEllpack< int,    TNL::Devices::Cuda, long >,
+    Legacy::ChunkedEllpack< long,   TNL::Devices::Cuda, long >,
+    Legacy::ChunkedEllpack< float,  TNL::Devices::Cuda, long >,
+    Legacy::ChunkedEllpack< double, TNL::Devices::Cuda, long >
 #endif
 >;
 
diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_Ellpack.h b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_Ellpack.h
index 307e5728a9..71a15d867d 100644
--- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_Ellpack.h
+++ b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_Ellpack.h
@@ -24,26 +24,28 @@ protected:
    using EllpackMatrixType = Matrix;
 };
 
+using namespace TNL::Benchmarks::SpMV::ReferenceFormats;
+
 // types for which MatrixTest is instantiated
 using EllpackMatrixTypes = ::testing::Types
 <
-    TNL::Matrices::Legacy::Ellpack< int,    TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::Ellpack< long,   TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::Ellpack< float,  TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::Ellpack< double, TNL::Devices::Host, int >,
-    TNL::Matrices::Legacy::Ellpack< int,    TNL::Devices::Host, long >,
-    TNL::Matrices::Legacy::Ellpack< long,   TNL::Devices::Host, long >,
-    TNL::Matrices::Legacy::Ellpack< float,  TNL::Devices::Host, long >,
-    TNL::Matrices::Legacy::Ellpack< double, TNL::Devices::Host, long >
+    Legacy::Ellpack< int,    TNL::Devices::Host, int >,
+    Legacy::Ellpack< long,   TNL::Devices::Host, int >,
+    Legacy::Ellpack< float,  TNL::Devices::Host, int >,
+    Legacy::Ellpack< double, TNL::Devices::Host, int >,
+    Legacy::Ellpack< int,    TNL::Devices::Host, long >,
+    Legacy::Ellpack< long,   TNL::Devices::Host, long >,
+    Legacy::Ellpack< float,  TNL::Devices::Host, long >,
+    Legacy::Ellpack< double, TNL::Devices::Host, long >
 #ifdef HAVE_CUDA
-   ,TNL::Matrices::Legacy::Ellpack< int,    TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::Ellpack< long,   TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::Ellpack< float,  TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::Ellpack< double, TNL::Devices::Cuda, int >,
-    TNL::Matrices::Legacy::Ellpack< int,    TNL::Devices::Cuda, long >,
-    TNL::Matrices::Legacy::Ellpack< long,   TNL::Devices::Cuda, long >,
-    TNL::Matrices::Legacy::Ellpack< float,  TNL::Devices::Cuda, long >,
-    TNL::Matrices::Legacy::Ellpack< double, TNL::Devices::Cuda, long >
+   ,Legacy::Ellpack< int,    TNL::Devices::Cuda, int >,
+    Legacy::Ellpack< long,   TNL::Devices::Cuda, int >,
+    Legacy::Ellpack< float,  TNL::Devices::Cuda, int >,
+    Legacy::Ellpack< double, TNL::Devices::Cuda, int >,
+    Legacy::Ellpack< int,    TNL::Devices::Cuda, long >,
+    Legacy::Ellpack< long,   TNL::Devices::Cuda, long >,
+    Legacy::Ellpack< float,  TNL::Devices::Cuda, long >,
+    Legacy::Ellpack< double, TNL::Devices::Cuda, long >
 #endif
 >;
 
diff --git a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_SlicedEllpack.h b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_SlicedEllpack.h
index b975c9c602..02c2c52969 100644
--- a/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_SlicedEllpack.h
+++ b/src/UnitTests/Matrices/Legacy/Legacy_SparseMatrixTest_SlicedEllpack.h
@@ -25,8 +25,10 @@ protected:
    using SlicedEllpackMatrixType = Matrix;
 };
 
+using namespace TNL::Benchmarks::SpMV::ReferenceFormats;
+
 template< typename Real, typename Device, typename Index >
-using SlicedEllpackType = TNL::Matrices::Legacy::SlicedEllpack< Real, Device, Index, 32 >;
+using SlicedEllpackType = Legacy::SlicedEllpack< Real, Device, Index, 32 >;
 
 
 // types for which MatrixTest is instantiated
diff --git a/src/UnitTests/Matrices/SparseMatrixCopyTest.h b/src/UnitTests/Matrices/SparseMatrixCopyTest.h
index 4ec2b7435d..098a3e0a41 100644
--- a/src/UnitTests/Matrices/SparseMatrixCopyTest.h
+++ b/src/UnitTests/Matrices/SparseMatrixCopyTest.h
@@ -8,7 +8,7 @@
 
 /* See Copyright Notice in tnl/Copyright */
 
-#include <TNL/Matrices/Legacy/CSR.h>
+#include <Benchmarks/SpMV/ReferenceFormats/Legacy/CSR.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/Ellpack.h>
 #include <Benchmarks/SpMV/ReferenceFormats/Legacy/SlicedEllpack.h>
 
-- 
GitLab