Loading...
Searching...
No Matches
utilities.C
Go to the documentation of this file.
1/*
2 * This file is part of the SPLINTER library.
3 * Copyright (C) 2012 Bjarne Grimstad (bjarne.grimstad@gmail.com).
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8*/
9
10#include "utilities.h"
11
12namespace SPLINTER
13{
14
15std::vector<double> denseVectorToVector(const DenseVector& denseVec)
16{
17 std::vector<double> vec(denseVec.size());
18
19 for (size_t i = 0; i < (size_t) denseVec.size(); ++i)
20 {
21 vec.at(i) = denseVec(i);
22 }
23
24 return vec;
25}
26
27DenseVector vectorToDenseVector(const std::vector<double>& vec)
28{
29 DenseVector denseVec(vec.size());
30
31 for (size_t i = 0; i < vec.size(); ++i)
32 {
33 denseVec(i) = vec.at(i);
34 }
35
36 return denseVec;
37}
38
39std::vector<std::vector<double>> denseMatrixToVectorVector(
40 const DenseMatrix& mat)
41{
42 std::vector<std::vector<double>> vec(mat.rows());
43
44 for (size_t i = 0; i < (size_t) mat.rows(); ++i)
45 {
46 for (size_t j = 0; j < (size_t) mat.cols(); ++j)
47 {
48 vec.at(i).push_back(mat(i, j));
49 }
50 }
51
52 return vec;
53}
54
55DenseMatrix vectorVectorToDenseMatrix(const std::vector<std::vector<double>>&
56 vec)
57{
58 size_t numRows = vec.size();
59 size_t numCols = numRows > 0 ? vec.at(0).size() : 0;
60 DenseMatrix mat(numRows, numCols);
61
62 for (size_t i = 0; i < numRows; ++i)
63 {
64 for (size_t j = 0; j < numCols; ++j)
65 {
66 mat(i, j) = vec.at(i).at(j);
67 }
68 }
69
70 return mat;
71}
72
73std::vector<double> linspace(double start, double stop, unsigned int num)
74{
75 std::vector<double> ret;
76 double dx = 0;
77
78 if (num > 1)
79 {
80 dx = (stop - start) / (num - 1);
81 }
82
83 for (unsigned int i = 0; i < num; ++i)
84 {
85 ret.push_back(start + i * dx);
86 }
87
88 return ret;
89}
90
91} // namespace SPLINTER
DenseMatrix vectorVectorToDenseMatrix(const std::vector< std::vector< double > > &vec)
Definition utilities.C:55
DenseVector vectorToDenseVector(const std::vector< double > &vec)
Definition utilities.C:27
std::vector< std::vector< double > > denseMatrixToVectorVector(const DenseMatrix &mat)
Definition utilities.C:39
std::vector< double > linspace(double start, double stop, unsigned int num)
Definition utilities.C:73
std::vector< double > denseVectorToVector(const DenseVector &denseVec)
Definition utilities.C:15
label i
Definition pEqn.H:46