From b2740c765a28b618da35ce672845a0b389ec4980 Mon Sep 17 00:00:00 2001 From: Christoph Goering Date: Wed, 20 Dec 2017 14:25:23 +0100 Subject: [PATCH] added two unit tests and its output for compute_mmult_pattern(..) --- ...ynamic_sparsity_pattern_compute_mmult_1.cc | 98 ++++++++++++++++ ...ic_sparsity_pattern_compute_mmult_1.output | 2 + ...ynamic_sparsity_pattern_compute_mmult_2.cc | 111 ++++++++++++++++++ ...ic_sparsity_pattern_compute_mmult_2.output | 2 + 4 files changed, 213 insertions(+) create mode 100644 tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.cc create mode 100644 tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.output create mode 100644 tests/sparsity/dynamic_sparsity_pattern_compute_mmult_2.cc create mode 100644 tests/sparsity/dynamic_sparsity_pattern_compute_mmult_2.output diff --git a/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.cc b/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.cc new file mode 100644 index 0000000000..c04d0cd914 --- /dev/null +++ b/tests/sparsity/dynamic_sparsity_pattern_compute_mmult_1.cc @@ -0,0 +1,98 @@ + +// --------------------------------------------------------------------- +// +// Copyright (C) 2004 - 2016 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + +// check DynamicSparsityPattern::compute_mmult_pattern(). Test if multiplication +// with each combination of SparsityPatternTypes is possible. + +#include "../tests.h" +#include +#include + + +void test () +{ + // create different (dynamic) sparsity pattern and add entries at + // destinct locations. Check if mmultiplication creates entries at the right + // rows and columns. + const unsigned int M = 100; + const unsigned int N = 50; + const unsigned int O = 75; + + const unsigned int m_entries = 4; + const unsigned int n_entries = 5; + const unsigned int o_entries = 6; + + bool test_failed = false; + + DynamicSparsityPattern dyn_left (M,N), + dyn_right (N,O); + + DynamicSparsityPattern out; + + SparsityPattern left, + right; + + // add manually entries to pattern + for (unsigned int i=0; i +#include +#include +#include + + +void test () +{ + // create two different FullMatrix objects and add entries randomly to it. + // Multiply them via FullMatrix::mmult(..), go through each row and column, + // and check if DynamicSparsityPattern::compute_mmult_pattern(..) predicts + // the entries (i,j) where values supposed to be because of the multiplication. + + const unsigned int M = 100; + const unsigned int N = 50; + const unsigned int O = 75; + + const unsigned int m_entries = 4; + const unsigned int n_entries = 5; + const unsigned int o_entries = 6; + + bool test_failed = false; + + DynamicSparsityPattern dyn_left (M,N), + dyn_right (N,O); + DynamicSparsityPattern dyn_out; + + FullMatrix mat_left(M,N), + mat_right(N,O), + mat_out(M,O); + + // add randomly entries to the left matrices/pattern starting at the 2nd row + for (unsigned int m=1; m 0) + { + dyn_left.add (m,n); + mat_left[m][n] = 1; + } + // add randomly entries to the right matrices/pattern starting at the 2nd column + for (unsigned int n=0; n 0) + { + dyn_right.add (n,o); + mat_right[n][o] = 1; + } + // first row of left and first column of right in such a way that no entry + // is created in final matrix + for (unsigned int n=0; n 0) + { + dyn_right.add (n,0); + mat_right[n][0] = 1; + } + else + { + dyn_left.add (0,n); + mat_left[0][n] = 1; + } + + + // do matrix-matrix-multiplication + mat_left.mmult(mat_out,mat_right); + dyn_out.compute_mmult_pattern(dyn_left,dyn_right); + + // go through whole matrix and check if pattern are equal + for (unsigned int i=0; i