diff --git a/build/Makefile.am b/build/Makefile.am
index 6b54b8e6315e8b55bc1ad3d882bdca28f205eb6e..e0987898a111a3fff3b42e027254e1edac919025 100644
--- a/build/Makefile.am
+++ b/build/Makefile.am
@@ -2,7 +2,7 @@ LDADD=libnptm/libnptm.la -L/usr/lib64 ${USER_LDFLAGS} ${HDF5_LDFLAGS} ${LAPACKLD
 lib_LTLIBRARIES=libnptm/libnptm.la
 libnptm_libnptm_la_SOURCES=../src/libnptm/algebraic.cpp ../src/libnptm/clu_subs.cpp ../src/libnptm/Commons.cpp ../src/libnptm/Configuration.cpp ../src/libnptm/file_io.cpp ../src/libnptm/lapack_calls.cpp ../src/libnptm/logging.cpp ../src/libnptm/magma_calls.cpp ../src/libnptm/Parsers.cpp ../src/libnptm/sph_subs.cpp ../src/libnptm/utils.cpp ../src/libnptm/tfrfme.cpp ../src/libnptm/TransitionMatrix.cpp ../src/libnptm/tra_subs.cpp
 if BUILDFORTRAN
-PROGS=cluster/edfb_clu cluster/clu cluster/np_cluster sphere/edfb_sph sphere/sph sphere/np_sphere trapping/frfme trapping/lffft trapping/np_trapping testing/test_TEDF testing/test_TTMS
+PROGS=cluster/edfb_clu cluster/clu cluster/np_cluster sphere/edfb_sph sphere/sph sphere/np_sphere trapping/frfme trapping/lffft trapping/np_trapping testing/test_TEDF testing/test_TTMS testing/test_zinvert
 bin_PROGRAMS=$(PROGS)
 EDFBCLUSOURCES=../src/cluster/edfb_clu.f
 CLUSOURCES=../src/cluster/clu.f
@@ -21,12 +21,14 @@ sphere_np_sphere_SOURCES=../src/sphere/np_sphere.cpp ../src/sphere/sphere.cpp
 trapping_np_trapping_SOURCES=../src/trapping/np_trapping.cpp ../src/trapping/cfrfme.cpp ../src/trapping/clffft.cpp
 testing_test_TEDF_SOURCES=../src/testing/test_TEDF.cpp
 testing_test_TTMS_SOURCES=../src/testing/test_TTMS.cpp
+testing_test_zinvert_SOURCES=../src/testing/test_zinvert.cpp
 else
-PROGS=cluster/np_cluster sphere/np_sphere trapping/np_trapping testing/test_TEDF testing/test_TTMS
+PROGS=cluster/np_cluster sphere/np_sphere trapping/np_trapping testing/test_TEDF testing/test_TTMS testing/test_zinvert
 bin_PROGRAMS=$(PROGS)
 cluster_np_cluster_SOURCES=../src/cluster/np_cluster.cpp ../src/cluster/cluster.cpp
 sphere_np_sphere_SOURCES=../src/sphere/np_sphere.cpp ../src/sphere/sphere.cpp
 trapping_np_trapping_SOURCES=../src/trapping/np_trapping.cpp ../src/trapping/cfrfme.cpp ../src/trapping/clffft.cpp
 testing_test_TEDF_SOURCES=../src/testing/test_TEDF.cpp
 testing_test_TTMS_SOURCES=../src/testing/test_TTMS.cpp
+testing_test_zinvert_SOURCES=../src/testing/test_zinvert.cpp
 endif
diff --git a/build/Makefile.in b/build/Makefile.in
index dfc4f1b8f9bb056082ad149aa35ba966718afbcd..5772d97dcead7a0b64773159a5ad031ae9638144 100644
--- a/build/Makefile.in
+++ b/build/Makefile.in
@@ -107,7 +107,8 @@ CONFIG_CLEAN_VPATH_FILES =
 @BUILDFORTRAN_FALSE@	sphere/np_sphere$(EXEEXT) \
 @BUILDFORTRAN_FALSE@	trapping/np_trapping$(EXEEXT) \
 @BUILDFORTRAN_FALSE@	testing/test_TEDF$(EXEEXT) \
-@BUILDFORTRAN_FALSE@	testing/test_TTMS$(EXEEXT)
+@BUILDFORTRAN_FALSE@	testing/test_TTMS$(EXEEXT) \
+@BUILDFORTRAN_FALSE@	testing/test_zinvert$(EXEEXT)
 @BUILDFORTRAN_TRUE@am__EXEEXT_1 = cluster/edfb_clu$(EXEEXT) \
 @BUILDFORTRAN_TRUE@	cluster/clu$(EXEEXT) \
 @BUILDFORTRAN_TRUE@	cluster/np_cluster$(EXEEXT) \
@@ -118,7 +119,8 @@ CONFIG_CLEAN_VPATH_FILES =
 @BUILDFORTRAN_TRUE@	trapping/lffft$(EXEEXT) \
 @BUILDFORTRAN_TRUE@	trapping/np_trapping$(EXEEXT) \
 @BUILDFORTRAN_TRUE@	testing/test_TEDF$(EXEEXT) \
-@BUILDFORTRAN_TRUE@	testing/test_TTMS$(EXEEXT)
+@BUILDFORTRAN_TRUE@	testing/test_TTMS$(EXEEXT) \
+@BUILDFORTRAN_TRUE@	testing/test_zinvert$(EXEEXT)
 am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(libdir)"
 PROGRAMS = $(bin_PROGRAMS)
 am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
@@ -243,6 +245,17 @@ testing_test_TTMS_LDADD = $(LDADD)
 testing_test_TTMS_DEPENDENCIES = libnptm/libnptm.la \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+am__testing_test_zinvert_SOURCES_DIST =  \
+	../src/testing/test_zinvert.cpp
+@BUILDFORTRAN_FALSE@am_testing_test_zinvert_OBJECTS =  \
+@BUILDFORTRAN_FALSE@	../src/testing/test_zinvert.$(OBJEXT)
+@BUILDFORTRAN_TRUE@am_testing_test_zinvert_OBJECTS =  \
+@BUILDFORTRAN_TRUE@	../src/testing/test_zinvert.$(OBJEXT)
+testing_test_zinvert_OBJECTS = $(am_testing_test_zinvert_OBJECTS)
+testing_test_zinvert_LDADD = $(LDADD)
+testing_test_zinvert_DEPENDENCIES = libnptm/libnptm.la \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am__trapping_frfme_SOURCES_DIST = ../src/trapping/frfme.f
 @BUILDFORTRAN_TRUE@am__objects_5 = ../src/trapping/frfme.$(OBJEXT)
 @BUILDFORTRAN_TRUE@am_trapping_frfme_OBJECTS = $(am__objects_5)
@@ -310,6 +323,7 @@ am__depfiles_remade = ../src/cluster/$(DEPDIR)/cluster.Po \
 	../src/sphere/$(DEPDIR)/sphere.Po \
 	../src/testing/$(DEPDIR)/test_TEDF.Po \
 	../src/testing/$(DEPDIR)/test_TTMS.Po \
+	../src/testing/$(DEPDIR)/test_zinvert.Po \
 	../src/trapping/$(DEPDIR)/cfrfme.Po \
 	../src/trapping/$(DEPDIR)/clffft.Po \
 	../src/trapping/$(DEPDIR)/np_trapping.Po
@@ -369,8 +383,9 @@ SOURCES = $(libnptm_libnptm_la_SOURCES) $(cluster_clu_SOURCES) \
 	$(cluster_edfb_clu_SOURCES) $(cluster_np_cluster_SOURCES) \
 	$(sphere_edfb_sph_SOURCES) $(sphere_np_sphere_SOURCES) \
 	$(sphere_sph_SOURCES) $(testing_test_TEDF_SOURCES) \
-	$(testing_test_TTMS_SOURCES) $(trapping_frfme_SOURCES) \
-	$(trapping_lffft_SOURCES) $(trapping_np_trapping_SOURCES)
+	$(testing_test_TTMS_SOURCES) $(testing_test_zinvert_SOURCES) \
+	$(trapping_frfme_SOURCES) $(trapping_lffft_SOURCES) \
+	$(trapping_np_trapping_SOURCES)
 DIST_SOURCES = $(libnptm_libnptm_la_SOURCES) \
 	$(am__cluster_clu_SOURCES_DIST) \
 	$(am__cluster_edfb_clu_SOURCES_DIST) \
@@ -380,6 +395,7 @@ DIST_SOURCES = $(libnptm_libnptm_la_SOURCES) \
 	$(am__sphere_sph_SOURCES_DIST) \
 	$(am__testing_test_TEDF_SOURCES_DIST) \
 	$(am__testing_test_TTMS_SOURCES_DIST) \
+	$(am__testing_test_zinvert_SOURCES_DIST) \
 	$(am__trapping_frfme_SOURCES_DIST) \
 	$(am__trapping_lffft_SOURCES_DIST) \
 	$(am__trapping_np_trapping_SOURCES_DIST)
@@ -581,8 +597,8 @@ top_srcdir = @top_srcdir@
 LDADD = libnptm/libnptm.la -L/usr/lib64 ${USER_LDFLAGS} ${HDF5_LDFLAGS} ${LAPACKLDFLAGS} ${MAGMALDFLAGS}
 lib_LTLIBRARIES = libnptm/libnptm.la
 libnptm_libnptm_la_SOURCES = ../src/libnptm/algebraic.cpp ../src/libnptm/clu_subs.cpp ../src/libnptm/Commons.cpp ../src/libnptm/Configuration.cpp ../src/libnptm/file_io.cpp ../src/libnptm/lapack_calls.cpp ../src/libnptm/logging.cpp ../src/libnptm/magma_calls.cpp ../src/libnptm/Parsers.cpp ../src/libnptm/sph_subs.cpp ../src/libnptm/utils.cpp ../src/libnptm/tfrfme.cpp ../src/libnptm/TransitionMatrix.cpp ../src/libnptm/tra_subs.cpp
-@BUILDFORTRAN_FALSE@PROGS = cluster/np_cluster sphere/np_sphere trapping/np_trapping testing/test_TEDF testing/test_TTMS
-@BUILDFORTRAN_TRUE@PROGS = cluster/edfb_clu cluster/clu cluster/np_cluster sphere/edfb_sph sphere/sph sphere/np_sphere trapping/frfme trapping/lffft trapping/np_trapping testing/test_TEDF testing/test_TTMS
+@BUILDFORTRAN_FALSE@PROGS = cluster/np_cluster sphere/np_sphere trapping/np_trapping testing/test_TEDF testing/test_TTMS testing/test_zinvert
+@BUILDFORTRAN_TRUE@PROGS = cluster/edfb_clu cluster/clu cluster/np_cluster sphere/edfb_sph sphere/sph sphere/np_sphere trapping/frfme trapping/lffft trapping/np_trapping testing/test_TEDF testing/test_TTMS testing/test_zinvert
 @BUILDFORTRAN_TRUE@EDFBCLUSOURCES = ../src/cluster/edfb_clu.f
 @BUILDFORTRAN_TRUE@CLUSOURCES = ../src/cluster/clu.f
 @BUILDFORTRAN_TRUE@EDFBSPHSOURCES = ../src/sphere/edfb_sph.f
@@ -605,6 +621,8 @@ libnptm_libnptm_la_SOURCES = ../src/libnptm/algebraic.cpp ../src/libnptm/clu_sub
 @BUILDFORTRAN_TRUE@testing_test_TEDF_SOURCES = ../src/testing/test_TEDF.cpp
 @BUILDFORTRAN_FALSE@testing_test_TTMS_SOURCES = ../src/testing/test_TTMS.cpp
 @BUILDFORTRAN_TRUE@testing_test_TTMS_SOURCES = ../src/testing/test_TTMS.cpp
+@BUILDFORTRAN_FALSE@testing_test_zinvert_SOURCES = ../src/testing/test_zinvert.cpp
+@BUILDFORTRAN_TRUE@testing_test_zinvert_SOURCES = ../src/testing/test_zinvert.cpp
 all: all-am
 
 .SUFFIXES:
@@ -845,6 +863,12 @@ testing/test_TEDF$(EXEEXT): $(testing_test_TEDF_OBJECTS) $(testing_test_TEDF_DEP
 testing/test_TTMS$(EXEEXT): $(testing_test_TTMS_OBJECTS) $(testing_test_TTMS_DEPENDENCIES) $(EXTRA_testing_test_TTMS_DEPENDENCIES) testing/$(am__dirstamp)
 	@rm -f testing/test_TTMS$(EXEEXT)
 	$(AM_V_CXXLD)$(CXXLINK) $(testing_test_TTMS_OBJECTS) $(testing_test_TTMS_LDADD) $(LIBS)
+../src/testing/test_zinvert.$(OBJEXT): ../src/testing/$(am__dirstamp) \
+	../src/testing/$(DEPDIR)/$(am__dirstamp)
+
+testing/test_zinvert$(EXEEXT): $(testing_test_zinvert_OBJECTS) $(testing_test_zinvert_DEPENDENCIES) $(EXTRA_testing_test_zinvert_DEPENDENCIES) testing/$(am__dirstamp)
+	@rm -f testing/test_zinvert$(EXEEXT)
+	$(AM_V_CXXLD)$(CXXLINK) $(testing_test_zinvert_OBJECTS) $(testing_test_zinvert_LDADD) $(LIBS)
 ../src/trapping/$(am__dirstamp):
 	@$(MKDIR_P) ../src/trapping
 	@: > ../src/trapping/$(am__dirstamp)
@@ -910,6 +934,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@../src/sphere/$(DEPDIR)/sphere.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@../src/testing/$(DEPDIR)/test_TEDF.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@../src/testing/$(DEPDIR)/test_TTMS.Po@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@../src/testing/$(DEPDIR)/test_zinvert.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@../src/trapping/$(DEPDIR)/cfrfme.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@../src/trapping/$(DEPDIR)/clffft.Po@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@../src/trapping/$(DEPDIR)/np_trapping.Po@am__quote@ # am--include-marker
@@ -1279,6 +1304,7 @@ distclean: distclean-am
 	-rm -f ../src/sphere/$(DEPDIR)/sphere.Po
 	-rm -f ../src/testing/$(DEPDIR)/test_TEDF.Po
 	-rm -f ../src/testing/$(DEPDIR)/test_TTMS.Po
+	-rm -f ../src/testing/$(DEPDIR)/test_zinvert.Po
 	-rm -f ../src/trapping/$(DEPDIR)/cfrfme.Po
 	-rm -f ../src/trapping/$(DEPDIR)/clffft.Po
 	-rm -f ../src/trapping/$(DEPDIR)/np_trapping.Po
@@ -1349,6 +1375,7 @@ maintainer-clean: maintainer-clean-am
 	-rm -f ../src/sphere/$(DEPDIR)/sphere.Po
 	-rm -f ../src/testing/$(DEPDIR)/test_TEDF.Po
 	-rm -f ../src/testing/$(DEPDIR)/test_TTMS.Po
+	-rm -f ../src/testing/$(DEPDIR)/test_zinvert.Po
 	-rm -f ../src/trapping/$(DEPDIR)/cfrfme.Po
 	-rm -f ../src/trapping/$(DEPDIR)/clffft.Po
 	-rm -f ../src/trapping/$(DEPDIR)/np_trapping.Po
diff --git a/src/testing/test_zinvert.cpp b/src/testing/test_zinvert.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..485bffc86ba5e1f06886d03caf2b0093b350c52f
--- /dev/null
+++ b/src/testing/test_zinvert.cpp
@@ -0,0 +1,89 @@
+/* Copyright (C) 2024   INAF - Osservatorio Astronomico di Cagliari
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   A copy of the GNU General Public License is distributed along with
+   this program in the COPYING file. If not, see: <https://www.gnu.org/licenses/>.
+ */
+
+/*! \file test_zinvert.cpp
+ *
+ * \brief Test of matrix inversion process.
+ */
+#include <cstdio>
+
+#ifndef INCLUDE_TYPES_H_
+#include "../include/types.h"
+#endif
+
+#ifdef USE_MAGMA
+#include "../include/magma_calls.h"
+#define SUCCESS MAGMA_SUCCESS
+#else
+#define SUCCESS 0
+#endif
+
+#ifdef USE_MAGMA_SVD
+#include "magma_operators.h"
+#endif
+
+#include "../include/algebraic.h"
+
+int main() {
+  int result = (int)SUCCESS;
+  printf("INFO: matrix inversion test.\n");
+  printf("INFO: sizeof(np_int) = %ld\n", sizeof(np_int));
+#ifdef USE_MAGMA
+  magma_init();
+  printf("INFO: sizeof(magma_int_t) = %ld\n", sizeof(magma_int_t));
+#endif
+  const np_int n = 3;
+  const np_int nn = n * n;
+  const double tolerance = 1.0e-6;
+  dcomplex **test_matrix;
+  dcomplex *vec_matrix = new dcomplex[n];
+  dcomplex *vec_inv_matrix = new dcomplex[n];
+  for (int ivi = 0; ivi < nn; ivi++) vec_matrix[ivi] = 1.0 + ivi + I * (1.0 + ivi);
+  test_matrix[0] = vec_matrix;
+  test_matrix[1] = vec_matrix + 2;
+  vec_inv_matrix[0] = 3.0 + I * 3.0;
+  vec_inv_matrix[1] = 1.0 / 3.0 + I * 0.0;
+  vec_inv_matrix[2] = 2.0 / 3.0 + I * 0.0;
+  vec_inv_matrix[3] = 6.0 + I * 6.0;
+  vec_inv_matrix[4] = 2.0 + I * 2.0;
+  vec_inv_matrix[5] = 0.5 + I * 0.0;
+  vec_inv_matrix[6] = 9.0 + I * 9.0;
+  vec_inv_matrix[7] = 4.0 + I * 4.0;
+  vec_inv_matrix[8] = 0.0 + I * 0.0;
+#ifdef USE_MAGMA
+  if (sizeof(np_int) != sizeof(magma_int_t)) {
+    printf("ERROR: sizeof(np_int) = %ld; sizeof(magma_int_t) = %ld\n",
+	   sizeof(np_int), sizeof(magma_int_t));
+    result = 2;
+  }
+#endif
+  if (result == 0) {
+    invert_matrix(test_matrix, n, result, n);
+    for (int tvi = 0; tvi < 4; tvi++) {
+      dcomplex difference = vec_matrix[tvi] - vec_inv_matrix[tvi];
+      if (real(difference) < -tolerance || real(difference) > tolerance) result = 1;
+      if (imag(difference) < -tolerance || imag(difference) > tolerance) result = 1;
+    }
+    if (result != 0) printf("ERROR: failed matrix inversion test!\n");
+  }
+  delete[] vec_inv_matrix;
+  delete[] vec_matrix;
+  delete[] test_matrix;
+#ifdef USE_MAGMA
+  magma_finalize();
+#endif
+  return result;
+}