1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-06-20 00:06:55 +01:00

first commit for the new fit interface

This commit is contained in:
2016-03-08 19:37:51 +00:00
parent 352caf30b6
commit 917031747f
6 changed files with 243 additions and 44 deletions

74
lib/FitInterface.cpp Normal file
View File

@ -0,0 +1,74 @@
/*
* FitInterface.cpp, part of LatAnalyze 3
*
* Copyright (C) 2013 - 2016 Antonin Portelli
*
* LatAnalyze 3 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.
*
* LatAnalyze 3 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.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatAnalyze/FitInterface.hpp>
#include <LatAnalyze/includes.hpp>
using namespace std;
using namespace Latan;
/******************************************************************************
* FitInterface implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
FitInterface::FitInterface(void)
{}
// add dimensions //////////////////////////////////////////////////////////////
void FitInterface::addXDim(const string name, const Index nData)
{
xDimName_.push_back(name);
xSize_.push_back(nData);
xIndex_[name] = xDimName_.size();
updateYSize();
}
void FitInterface::addYDim(const string name)
{
yDimName_.push_back(name);
yIndex_[name] = yDimName_.size();
}
unsigned int FitInterface::getNXDim(void)
{
return xDimName_.size();
}
unsigned int FitInterface::getNYDim(void)
{
return yDimName_.size();
}
void FitInterface::updateYSize(void)
{
ySize_ = 1;
for (Index size: xSize_)
{
ySize_ *= size;
}
isFitPoint_.resize(ySize_);
isFitPoint_.fill(1);
}
// enable fit points ///////////////////////////////////////////////////////////
void FitInterface::fitPoint(const bool isFitPoint, const Index j)
{
DEBUG_VAR(j);
isFitPoint_(j) = isFitPoint ? 1 : 0;
}

100
lib/FitInterface.hpp Normal file
View File

@ -0,0 +1,100 @@
/*
* FitInterface.hpp, part of LatAnalyze 3
*
* Copyright (C) 2013 - 2016 Antonin Portelli
*
* LatAnalyze 3 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.
*
* LatAnalyze 3 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.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Latan_FitInterface_hpp_
#define Latan_FitInterface_hpp_
#include <LatAnalyze/Global.hpp>
BEGIN_LATAN_NAMESPACE
/******************************************************************************
* FitInterface *
******************************************************************************/
class FitInterface
{
public:
// constructor
FitInterface(void);
// destructor
virtual ~FitInterface(void) = default;
// add dimensions
void addXDim(const std::string name, const Index nData);
void addYDim(const std::string name);
unsigned int getNXDim(void);
unsigned int getNYDim(void);
// Y dimension index helper
template <typename... Ts>
Index yIndex(const Ts... is);
// enable fit points
void fitPoint(const bool isFitPoint, const Index j);
private:
void updateYSize(void);
private:
std::vector<std::string> xDimName_, yDimName_;
std::map<std::string, Index> xIndex_, yIndex_;
std::vector<Index> xSize_;
Index ySize_;
public:
IVec isFitPoint_;
};
/******************************************************************************
* FitInterface template implementation *
******************************************************************************/
// Y dimension index helper ////////////////////////////////////////////////////
template <typename... Ts>
Index FitInterface::yIndex(const Ts... is)
{
static_assert(static_or<std::is_convertible<Index, Ts>::value...>::value,
"fitPoint arguments are not compatible with Index");
constexpr size_t n = sizeof...(is);
if (n != getNXDim())
{
LATAN_ERROR(Size, "number of arguments and number of X dimensions "
"mismatch");
}
constexpr std::array<Index, sizeof...(is)> i = {is...};
Index j;
for (unsigned int d = 0; d < n; ++d)
{
if (i[d] >= xSize_[d])
{
LATAN_ERROR(Range, "index in X dimension " + strFrom(d)
+ " out of range");
}
}
j = xSize_[1]*i[0];
for (unsigned int d = 1; d < n-1; ++d)
{
j = xSize_[d+1]*(i[d] + j);
}
j += i[n-1];
return j;
}
END_LATAN_NAMESPACE
#endif // Latan_FitInterface_hpp_

View File

@ -23,6 +23,7 @@ libLatAnalyze_la_SOURCES = \
Derivative.cpp \
Exceptions.cpp \
File.cpp \
FitInterface.cpp \
Function.cpp \
Global.cpp \
GslHybridRootFinder.cpp\
@ -55,6 +56,7 @@ libLatAnalyze_la_HEADERS = \
Exceptions.hpp \
Function.hpp \
File.hpp \
FitInterface.hpp \
Global.hpp \
GslHybridRootFinder.hpp\
GslQagsIntegrator.hpp \