SkelCL
SkelCL is a high level multi GPU skeleton library developed at the university of Münster, Germany.
 All Classes Namespaces Files Functions Variables Typedefs Groups
MatrixTests.cpp
1 /*****************************************************************************
2  * Copyright (c) 2011-2012 The SkelCL Team as listed in CREDITS.txt *
3  * http://skelcl.uni-muenster.de *
4  * *
5  * This file is part of SkelCL. *
6  * SkelCL is available under multiple licenses. *
7  * The different licenses are subject to terms and condition as provided *
8  * in the files specifying the license. See "LICENSE.txt" for details *
9  * *
10  *****************************************************************************
11  * *
12  * SkelCL is free software: you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation, either version 3 of the License, or *
15  * (at your option) any later version. See "LICENSE-gpl.txt" for details. *
16  * *
17  * SkelCL is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  *****************************************************************************
23  * *
24  * For non-commercial academic use see the license specified in the file *
25  * "LICENSE-academic.txt". *
26  * *
27  *****************************************************************************
28  * *
29  * If you are interested in other licensing models, including a commercial- *
30  * license, please contact the author at michel.steuwer@uni-muenster.de *
31  * *
32  *****************************************************************************/
33 
37 
38 #include <pvsutil/Logger.h>
39 
40 #include <SkelCL/Distributions.h>
41 #include <SkelCL/SkelCL.h>
42 #include <SkelCL/Matrix.h>
43 
44 #include "Test.h"
47 
48 class MatrixTest : public ::testing::Test {
49 protected:
50  MatrixTest() {
51  pvsutil::defaultLogger.setLoggingLevel(pvsutil::Logger::Severity::Debug);
53  }
54 
55  ~MatrixTest() {
57  }
58 };
59 
60 TEST_F(MatrixTest, CreateEmptyMatrix) {
62 
63  EXPECT_TRUE(mi.empty());
64  EXPECT_EQ( skelcl::MatrixSize(0,0) , mi.size());
65 }
66 
67 TEST_F(MatrixTest, CreateMatrix) {
68  skelcl::Matrix<double> mi( {10,10} );
69 
70  EXPECT_FALSE(mi.empty());
71  EXPECT_EQ(100, mi.size().elemCount());
72  EXPECT_EQ(0, *mi.begin());
73  for (size_t i = 0; i < 10; ++i) {
74  for (size_t j = 0; j < 10; ++j) {
75  EXPECT_EQ(0.0, mi({i,j}));
76  }
77  }
78 }
79 
80 TEST_F(MatrixTest, CreateMatrixFrom2DVector) {
81  std::vector<std::vector<int> > vec(10);
82  for (unsigned int i = 0; i < 10; ++i) {
83  vec[i].resize(10);
84  for (unsigned int j = 0; j < 10; ++j) {
85  vec[i][j] = i*j;
86  }
87  }
88 
90 
91  EXPECT_FALSE(mi.empty());
92  EXPECT_EQ(100, mi.size().elemCount());
93  for (size_t i = 0; i < 10; ++i) {
94  for (size_t j = 0; j < 10; ++j) {
95  EXPECT_EQ(i*j, mi[i][j]);
96  }
97  }
98 
99 }
100 
102 
The Matrix class is a two dimensional container which makes its data accessible on the host as well a...
Definition: Matrix.h:190
SKELCL_DLL void init(detail::DeviceProperties properties=allDevices())
Initializes the SkelCL library. This function (or another init function) has to be called prior to ev...
Definition: SkelCL.cpp:51
size_type elemCount() const
Returns the total number of elements. I.e. rowCount() * columnCount().
Definition: MatrixSize.cpp:51
SKELCL_DLL detail::DeviceProperties nDevices(size_t n)
Creates a detail::DeviceProperties object representing n devices. This object should be used as param...
Definition: SkelCL.cpp:66
This class defines a two dimensional size for a Matrix.
Definition: Matrix.h:67
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.
Definition: SkelCL.cpp:81
static Matrix< T > from2DVector(const std::vector< std::vector< T >> &matrix, const detail::Distribution< Matrix< T >> &distribution=detail::Distribution< Matrix< T >>())
static function creating a matrix from 2 dim std::vector as parameter