Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions base/build/jsgpp/GridFactory.i
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,24 @@ struct RegularGridConfiguration {
};

struct AdaptivityConfiguration {
/// number of refinements
size_t numRefinements_;
/// refinement threshold for surpluses
double threshold_;
/// refinement type: false: classic, true: maxLevel
bool maxLevelType_;
/// max. number of points to be refined
size_t noPoints_;
/// max. percent of points to be refined
double percent_;
/// other refinement strategy, that is more expensive, but yields better results
bool errorBasedRefinement = false;
/// number of refinements
size_t numRefinements_;
/// refinement threshold
double refinementThreshold_;
/// coarsening threshold
double coarseningThreshold_;
/// refinement type: false: classic, true: maxLevel
bool maxLevelType_;
/// max. number of points to be refined
size_t numRefinementPoints_;
/// max. number of points to be coarsened
size_t numCoarseningPoints_;
/// max. percent of points to be refined
double percent_;
/// other refinement strategy, that is more expensive, but yields better results
bool errorBasedRefinement = false;
/// prevent coarsening of initial grid points, needed for some decompositions
bool coarsenInitialPoints_;
};

enum class GridType {
Expand Down
12 changes: 9 additions & 3 deletions base/build/matsgpp/GridFactory.i
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ struct RegularGridConfiguration {
struct AdaptivityConfiguration {
/// number of refinements
size_t numRefinements_;
/// refinement threshold for surpluses
double threshold_;
/// refinement threshold
double refinementThreshold_;
/// coarsening threshold
double coarseningThreshold_;
/// refinement type: false: classic, true: maxLevel
bool maxLevelType_;
/// max. number of points to be refined
size_t noPoints_;
size_t numRefinementPoints_;
/// max. number of points to be coarsened
size_t numCoarseningPoints_;
/// max. percent of points to be refined
double percent_;
/// prevent coarsening of initial grid points, needed for some decompositions
bool coarsenInitialPoints_;
};

enum class GridType {
Expand Down
12 changes: 9 additions & 3 deletions base/build/pysgpp/GridFactory.i
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,22 @@ struct RegularGridConfiguration {
struct AdaptivityConfiguration {
/// number of refinements
size_t numRefinements_;
/// refinement threshold for surpluses
double threshold_;
/// refinement threshold
double refinementThreshold_;
/// coarsening threshold
double coarseningThreshold_;
/// refinement type: false: classic, true: maxLevel
bool maxLevelType_;
/// max. number of points to be refined
size_t noPoints_;
size_t numRefinementPoints_;
/// max. number of points to be coarsened
size_t numCoarseningPoints_;
/// max. percent of points to be refined
double percent_;
/// other refinement strategy, that is more expensive, but yields better results
bool errorBasedRefinement = false;
/// prevent coarsening of initial grid points, needed for some decompositions
bool coarsenInitialPoints_;
};

enum class GridType {
Expand Down
54 changes: 34 additions & 20 deletions base/src/sgpp/base/datatypes/DataVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>

namespace sgpp {
namespace base {
Expand All @@ -30,11 +30,14 @@ DataVector::DataVector(size_t size) : DataVector(size, 0.0) {}

DataVector::DataVector(size_t size, double value) { this->assign(size, value); }

DataVector::DataVector(double* input, size_t size) : std::vector<double>(input, input + size) {}
DataVector::DataVector(double* input, size_t size)
: std::vector<double>(input, input + size) {}

DataVector::DataVector(std::vector<double> input) : std::vector<double>(input) {}
DataVector::DataVector(std::vector<double> input)
: std::vector<double>(input) {}

DataVector::DataVector(std::initializer_list<double> input) : std::vector<double>(input) {}
DataVector::DataVector(std::initializer_list<double> input)
: std::vector<double>(input) {}

DataVector::DataVector(std::vector<int> input) {
// copy data
Expand All @@ -48,7 +51,8 @@ DataVector DataVector::fromFile(const std::string& fileName) {
std::ifstream f(fileName, std::ifstream::in);
f.exceptions(std::ifstream::failbit | std::ifstream::badbit);
std::string content;
content.assign(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>());
content.assign(std::istreambuf_iterator<char>(f),
std::istreambuf_iterator<char>());
return DataVector::fromString(content);
}

Expand Down Expand Up @@ -78,7 +82,9 @@ DataVector DataVector::fromString(const std::string& serializedVector) {
// size_t next;
// double value = std::atof(&(serializedVector[i]));
size_t endNumber = i;
while (serializedVector[endNumber] != ',' && serializedVector[endNumber] != ']') ++endNumber;
while (serializedVector[endNumber] != ',' &&
serializedVector[endNumber] != ']')
++endNumber;
std::stringstream stream;
for (size_t j = i; j < endNumber; ++j) {
stream << serializedVector[j];
Expand All @@ -89,7 +95,8 @@ DataVector DataVector::fromString(const std::string& serializedVector) {
v.append(value);
state = PARSER_STATE::COMMAEND;
// i += next;
// while (serializedVector[i] != ',' && serializedVector[i] != ']') ++i;
// while (serializedVector[i] != ',' && serializedVector[i] != ']')
// ++i;
i = endNumber;

} else if (state == PARSER_STATE::COMMAEND) {
Expand All @@ -101,7 +108,8 @@ DataVector DataVector::fromString(const std::string& serializedVector) {
++i;
}
} else if (state == PARSER_STATE::END) {
// only reached if a non-whitespace character was encountered after closing brace
// only reached if a non-whitespace character was encountered after
// closing brace
throw data_exception("error: could not parse DataVector file");
}
}
Expand All @@ -123,10 +131,10 @@ void DataVector::remove(std::vector<size_t>& indexesToRemove) {
DataVector oldVector(*this);
std::vector<bool> willBeRemoved(this->size(), false);

// Count the indexes to remove for the case when there are duplicates in indexesToRemove
// Count the indexes to remove for the case when there are duplicates in
// indexesToRemove
size_t numIndexesToRemove = 0;
for (size_t i = 0; i < oldVector.size(); ++i) {
size_t idx = indexesToRemove[i];
for (size_t idx : indexesToRemove) {
if (!willBeRemoved[idx]) {
willBeRemoved[idx] = true;
++numIndexesToRemove;
Expand All @@ -152,7 +160,8 @@ size_t DataVector::append(double value) {

void DataVector::insert(size_t index, double value) {
if (index > this->size()) {
throw sgpp::base::data_exception("DataVector::insert : index out of bounds");
throw sgpp::base::data_exception(
"DataVector::insert : index out of bounds");
}

this->insert(this->begin() + index, value);
Expand All @@ -170,12 +179,14 @@ void DataVector::copyFrom(const DataVector& vec) {
if (*this == vec) {
return;
}
std::copy(vec.begin(), vec.begin() + std::min(this->size(), vec.size()), this->begin());
std::copy(vec.begin(), vec.begin() + std::min(this->size(), vec.size()),
this->begin());
}

void DataVector::add(const DataVector& vec) {
if (this->size() != vec.size()) {
throw sgpp::base::data_exception("DataVector::add : Dimensions do not match");
throw sgpp::base::data_exception(
"DataVector::add : Dimensions do not match");
}

for (size_t i = 0; i < this->size(); ++i) {
Expand All @@ -200,7 +211,8 @@ void DataVector::accumulate(const DataVector& vec) {

void DataVector::sub(const DataVector& vec) {
if (this->size() != vec.size()) {
throw sgpp::base::data_exception("DataVector::sub : Dimensions do not match");
throw sgpp::base::data_exception(
"DataVector::sub : Dimensions do not match");
}

for (size_t i = 0; i < this->size(); ++i) {
Expand All @@ -210,7 +222,8 @@ void DataVector::sub(const DataVector& vec) {

void DataVector::componentwise_mult(const DataVector& vec) {
if (this->size() != vec.size()) {
throw sgpp::base::data_exception("DataVector::componentwise_mult : Dimensions do not match");
throw sgpp::base::data_exception(
"DataVector::componentwise_mult : Dimensions do not match");
}

for (size_t i = 0; i < this->size(); ++i) {
Expand All @@ -220,7 +233,8 @@ void DataVector::componentwise_mult(const DataVector& vec) {

void DataVector::componentwise_div(const DataVector& vec) {
if (this->size() != vec.size()) {
throw sgpp::base::data_exception("DataVector::componentwise_div : Dimensions do not match");
throw sgpp::base::data_exception(
"DataVector::componentwise_div : Dimensions do not match");
}

for (size_t i = 0; i < this->size(); ++i) {
Expand Down
47 changes: 47 additions & 0 deletions base/src/sgpp/base/grid/AdaptivityThresholdTypeParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (C) 2008-today The SG++ project
// This file is part of the SG++ project. For conditions of distribution and
// use, please see the copyright notice provided with SG++ or at
// sgpp.sparsegrids.org

#include <sgpp/base/grid/AdaptivityThresholdTypeParser.hpp>

#include <sgpp/base/exception/data_exception.hpp>
#include <algorithm>
#include <string>

namespace sgpp {
namespace base {

using sgpp::base::data_exception;

AdaptivityThresholdType AdaptivityThresholdTypeParser::parse(
const std::string& input) {
auto inputLower = input;
std::transform(inputLower.begin(), inputLower.end(), inputLower.begin(),
::tolower);
if (inputLower == "relative") {
return AdaptivityThresholdType::Relative;
} else if (inputLower == "absolute") {
return AdaptivityThresholdType::Absolute;
} else {
std::string errorMsg = "Failed to convert string \"" + input +
"\" to any known "
"AdaptivityThresholdType";
throw data_exception(errorMsg.c_str());
}
}

const std::string& AdaptivityThresholdTypeParser::toString(
AdaptivityThresholdType type) {
return refinementFunctorTypeMap.at(type);
}

const AdaptivityThresholdTypeParser::AdaptivityThresholdTypeMap_t
AdaptivityThresholdTypeParser::refinementFunctorTypeMap = []() {
return AdaptivityThresholdTypeMap_t{
std::make_pair(AdaptivityThresholdType::Relative, "relative"),
std::make_pair(AdaptivityThresholdType::Absolute, "absolute"),
};
}();
} // namespace base
} // namespace sgpp
46 changes: 46 additions & 0 deletions base/src/sgpp/base/grid/AdaptivityThresholdTypeParser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2008-today The SG++ project
// This file is part of the SG++ project. For conditions of distribution and
// use, please see the copyright notice provided with SG++ or at
// sgpp.sparsegrids.org

#pragma once

#include <sgpp/base/grid/Grid.hpp>

#include <map>
#include <string>

namespace sgpp {
namespace base {
using sgpp::base::AdaptivityThresholdType;

class AdaptivityThresholdTypeParser {
public:
/**
* Convert strings to values #sgpp::base::AdaptivityThresholdType. Throws if there is no valid
* representation
* @param input case insensitive string representation of a
* #sgpp::base::AdaptivityThresholdType.
* @return the corresponding #sgpp::base::AdaptivityThresholdType.
*/
static AdaptivityThresholdType parse(const std::string& input);

/**
* generate string representations for values of #sgpp::base::AdaptivityThresholdType.
* @param type enum value.
* @return string representation of a #sgpp::base::AdaptivityThresholdType.
*/
static const std::string& toString(AdaptivityThresholdType type);

private:
typedef std::map<AdaptivityThresholdType, std::string> AdaptivityThresholdTypeMap_t;

/**
* Map containing all values of #sgpp::base::AdaptivityThresholdType and the corresponding
* string representation.
*/
static const AdaptivityThresholdTypeMap_t refinementFunctorTypeMap;
};

} /* namespace base */
} /* namespace sgpp */
16 changes: 16 additions & 0 deletions base/src/sgpp/base/grid/CoarseningConfiguration.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2008-today The SG++ project
// This file is part of the SG++ project. For conditions of distribution and
// use, please see the copyright notice provided with SG++ or at
// sgpp.sparsegrids.org

#pragma once

namespace sgpp {
namespace base {
/**
* Enumeration that defines different types of coarsening indicators / functors
*/
enum class CoarseningFunctorType { Surplus, SurplusVolume, Classification };

} // namespace base
} // namespace sgpp
51 changes: 51 additions & 0 deletions base/src/sgpp/base/grid/CoarseningFunctorTypeParser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2008-today The SG++ project
// This file is part of the SG++ project. For conditions of distribution and
// use, please see the copyright notice provided with SG++ or at
// sgpp.sparsegrids.org

#include <sgpp/base/grid/CoarseningFunctorTypeParser.hpp>

#include <sgpp/base/exception/data_exception.hpp>
#include <algorithm>
#include <string>

namespace sgpp {
namespace base {

using sgpp::base::data_exception;

CoarseningFunctorType CoarseningFunctorTypeParser::parse(
const std::string& input) {
auto inputLower = input;
std::transform(inputLower.begin(), inputLower.end(), inputLower.begin(),
::tolower);
if (inputLower == "surplus") {
return CoarseningFunctorType::Surplus;
} else if (inputLower == "surplusvolume") {
return CoarseningFunctorType::SurplusVolume;
} else if (inputLower == "classification") {
return CoarseningFunctorType::Classification;
} else {
std::string errorMsg = "Failed to convert string \"" + input +
"\" to any known "
"CoarseningFunctorType";
throw data_exception(errorMsg.c_str());
}
}

const std::string& CoarseningFunctorTypeParser::toString(
CoarseningFunctorType type) {
return coarseningFunctorTypeMap.at(type);
}

const CoarseningFunctorTypeParser::CoarseningFunctorTypeMap_t
CoarseningFunctorTypeParser::coarseningFunctorTypeMap = []() {
return CoarseningFunctorTypeMap_t{
std::make_pair(CoarseningFunctorType::Surplus, "Surplus"),
std::make_pair(CoarseningFunctorType::SurplusVolume, "SurplusVolume"),
std::make_pair(CoarseningFunctorType::Classification,
"Classification")};
}();

} /* namespace base */
} /* namespace sgpp */
Loading