mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
sample type (and specialisations) dispatched in different files
This commit is contained in:
parent
a659c699bb
commit
789ea6abe9
@ -23,8 +23,8 @@
|
||||
#include <latan/Global.hpp>
|
||||
#include <latan/File.hpp>
|
||||
#include <latan/Mat.hpp>
|
||||
#include <latan/MatSample.hpp>
|
||||
#include <latan/RandGen.hpp>
|
||||
#include <latan/Sample.hpp>
|
||||
#include <fstream>
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
@ -27,7 +27,7 @@
|
||||
%{
|
||||
#include <iostream>
|
||||
#include <latan/AsciiFile.hpp>
|
||||
#include <latan/IOASCIIParser.hpp>
|
||||
#include <latan/AsciiParser.hpp>
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
|
@ -21,8 +21,8 @@
|
||||
#include <latan/Global.hpp>
|
||||
#include <latan/AsciiFile.hpp>
|
||||
#include <latan/Mat.hpp>
|
||||
#include <latan/MatSample.hpp>
|
||||
#include <latan/RandGen.hpp>
|
||||
#include <latan/Sample.hpp>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
@ -134,9 +134,9 @@ mat:
|
||||
sample:
|
||||
OPEN SAMPLE ID INT mats CLOSE SAMPLE
|
||||
{
|
||||
const unsigned int nSample = $INT + 1;
|
||||
const unsigned int nSample = $INT;
|
||||
|
||||
if (state->dMatQueue.size() != nSample)
|
||||
if (state->dMatQueue.size() != nSample + DMatSample::offset)
|
||||
{
|
||||
LATAN_ERROR(Size, "sample '" + *state->streamName + ":" + $ID +
|
||||
"' has a wrong size");
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <latan/Global.hpp>
|
||||
#include <latan/File.hpp>
|
||||
#include <latan/Sample.hpp>
|
||||
#include <latan/StatArray.hpp>
|
||||
#include <latan/RandGen.hpp>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
@ -41,11 +41,11 @@ liblatan_la_SOURCES = \
|
||||
MathInterpreter.cpp \
|
||||
MathParser.ypp \
|
||||
MathLexer.lpp \
|
||||
MatSample.cpp \
|
||||
Minimizer.cpp \
|
||||
Model.cpp \
|
||||
Plot.cpp \
|
||||
RandGen.cpp \
|
||||
Sample.cpp \
|
||||
XYStatData.cpp \
|
||||
../config.h
|
||||
liblatan_ladir = $(pkgincludedir)
|
||||
@ -62,13 +62,13 @@ liblatan_la_HEADERS = \
|
||||
Mat.hpp \
|
||||
Math.hpp \
|
||||
MathInterpreter.hpp \
|
||||
MatSample.hpp \
|
||||
Minimizer.hpp \
|
||||
Model.hpp \
|
||||
ParserState.hpp \
|
||||
Plot.hpp \
|
||||
RandGen.hpp \
|
||||
Sample.hpp \
|
||||
StatArray.hpp \
|
||||
StatArray.hpp
|
||||
XYStatData.hpp
|
||||
if HAVE_MINUIT
|
||||
liblatan_la_SOURCES += MinuitMinimizer.cpp
|
||||
|
117
latan/MatSample.cpp
Normal file
117
latan/MatSample.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* MatSample.cpp, part of LatAnalyze 3
|
||||
*
|
||||
* Copyright (C) 2013 - 2014 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 <latan/MatSample.hpp>
|
||||
#include <latan/includes.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace Latan;
|
||||
|
||||
/******************************************************************************
|
||||
* DMatSample implementation *
|
||||
******************************************************************************/
|
||||
// constructors ////////////////////////////////////////////////////////////////
|
||||
DMatSample::DMatSample(const Index nSample, const Index nRow,
|
||||
const Index nCol)
|
||||
: Sample<DMat>(nSample)
|
||||
{
|
||||
resizeMat(nRow, nCol);
|
||||
}
|
||||
|
||||
DMatSample::DMatSample(ConstBlock &sampleBlock)
|
||||
: DMatSample(sampleBlock.getSample().size(), sampleBlock.getNRow(),
|
||||
sampleBlock.getNCol())
|
||||
{
|
||||
const DMatSample &sample = sampleBlock.getSample();
|
||||
|
||||
this->resize(sample.size());
|
||||
FOR_STAT_ARRAY(*this, s)
|
||||
{
|
||||
(*this)[s] = sample[s].block(sampleBlock.getStartRow(),
|
||||
sampleBlock.getStartCol(),
|
||||
sampleBlock.getNRow(),
|
||||
sampleBlock.getNCol());
|
||||
}
|
||||
}
|
||||
|
||||
DMatSample::DMatSample(ConstBlock &&sampleBlock)
|
||||
: DMatSample(sampleBlock)
|
||||
{}
|
||||
|
||||
// assignement operator ////////////////////////////////////////////////////////
|
||||
DMatSample & DMatSample::operator=(Block &sampleBlock)
|
||||
{
|
||||
DMatSample tmp(sampleBlock);
|
||||
|
||||
this->swap(tmp);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
DMatSample & DMatSample::operator=(Block &&sampleBlock)
|
||||
{
|
||||
*this = sampleBlock;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
DMatSample & DMatSample::operator=(ConstBlock &sampleBlock)
|
||||
{
|
||||
DMatSample tmp(sampleBlock);
|
||||
|
||||
this->swap(tmp);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
DMatSample & DMatSample::operator=(ConstBlock &&sampleBlock)
|
||||
{
|
||||
*this = sampleBlock;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// block access ////////////////////////////////////////////////////////////////
|
||||
DMatSample::ConstBlock DMatSample::block(const Index i, const Index j,
|
||||
const Index nRow,
|
||||
const Index nCol) const
|
||||
{
|
||||
return ConstBlock(*this, i, j, nRow, nCol);
|
||||
}
|
||||
|
||||
DMatSample::Block DMatSample::block(const Index i, const Index j,
|
||||
const Index nRow, const Index nCol)
|
||||
{
|
||||
return Block(*this, i, j, nRow, nCol);
|
||||
}
|
||||
|
||||
// resize all matrices /////////////////////////////////////////////////////////
|
||||
void DMatSample::resizeMat(const Index nRow, const Index nCol)
|
||||
{
|
||||
FOR_STAT_ARRAY(*this, s)
|
||||
{
|
||||
(*this)[s].resize(nRow, nCol);
|
||||
}
|
||||
}
|
||||
|
||||
// IO type /////////////////////////////////////////////////////////////////////
|
||||
IoObject::IoType DMatSample::getType(void) const
|
||||
{
|
||||
return IoType::dMatSample;
|
||||
}
|
181
latan/MatSample.hpp
Normal file
181
latan/MatSample.hpp
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* MatSample.hpp, part of LatAnalyze 3
|
||||
*
|
||||
* Copyright (C) 2013 - 2014 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_MatSample_hpp_
|
||||
#define Latan_MatSample_hpp_
|
||||
|
||||
#include <latan/Global.hpp>
|
||||
#include <latan/Mat.hpp>
|
||||
#include <latan/StatArray.hpp>
|
||||
|
||||
BEGIN_NAMESPACE
|
||||
|
||||
/******************************************************************************
|
||||
* DMat sample class *
|
||||
******************************************************************************/
|
||||
class DMatSample: public Sample<DMat>, public IoObject
|
||||
{
|
||||
public:
|
||||
// block type template
|
||||
template <class S>
|
||||
class BlockTemplate
|
||||
{
|
||||
private:
|
||||
typedef typename std::remove_const<S>::type NonConstType;
|
||||
public:
|
||||
// constructors
|
||||
BlockTemplate(S &sample, const Index i, const Index j, const Index nRow,
|
||||
const Index nCol);
|
||||
BlockTemplate(BlockTemplate<NonConstType> &b);
|
||||
BlockTemplate(BlockTemplate<NonConstType> &&b);
|
||||
// destructor
|
||||
~BlockTemplate(void) = default;
|
||||
// access
|
||||
S & getSample(void);
|
||||
const S & getSample(void) const;
|
||||
Index getStartRow(void) const;
|
||||
Index getStartCol(void) const;
|
||||
Index getNRow(void) const;
|
||||
Index getNCol(void) const;
|
||||
// assignement operators
|
||||
BlockTemplate<S> & operator=(const S &sample);
|
||||
BlockTemplate<S> & operator=(const S &&sample);
|
||||
private:
|
||||
S &sample_;
|
||||
const Index i_, j_, nRow_, nCol_;
|
||||
};
|
||||
// block types
|
||||
typedef BlockTemplate<DMatSample> Block;
|
||||
typedef const BlockTemplate<const DMatSample> ConstBlock;
|
||||
public:
|
||||
// constructors
|
||||
using Sample<DMat>::Sample;
|
||||
DMatSample(void) = default;
|
||||
DMatSample(const Index nSample, const Index nRow, const Index nCol);
|
||||
DMatSample(ConstBlock &sampleBlock);
|
||||
DMatSample(ConstBlock &&sampleBlock);
|
||||
// destructor
|
||||
virtual ~DMatSample(void) = default;
|
||||
// assignement operator
|
||||
DMatSample & operator=(Block &sampleBlock);
|
||||
DMatSample & operator=(Block &&sampleBlock);
|
||||
DMatSample & operator=(ConstBlock &sampleBlock);
|
||||
DMatSample & operator=(ConstBlock &&sampleBlock);
|
||||
// block access
|
||||
ConstBlock block(const Index i, const Index j, const Index nRow,
|
||||
const Index nCol) const;
|
||||
Block block(const Index i, const Index j, const Index nRow,
|
||||
const Index nCol);
|
||||
// resize all matrices
|
||||
void resizeMat(const Index nRow, const Index nCol);
|
||||
// IO type
|
||||
virtual IoType getType(void) const;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Block template implementation *
|
||||
******************************************************************************/
|
||||
// constructors ////////////////////////////////////////////////////////////////
|
||||
template <class S>
|
||||
DMatSample::BlockTemplate<S>::BlockTemplate(S &sample, const Index i,
|
||||
const Index j, const Index nRow,
|
||||
const Index nCol)
|
||||
: sample_(sample)
|
||||
, i_(i)
|
||||
, j_(j)
|
||||
, nRow_(nRow)
|
||||
, nCol_(nCol)
|
||||
{}
|
||||
|
||||
template <class S>
|
||||
DMatSample::BlockTemplate<S>::BlockTemplate(BlockTemplate<NonConstType> &b)
|
||||
: sample_(b.getSample())
|
||||
, i_(b.getStartRow())
|
||||
, j_(b.getStartCol())
|
||||
, nRow_(b.getNRow())
|
||||
, nCol_(b.getNCol())
|
||||
{}
|
||||
|
||||
template <class S>
|
||||
DMatSample::BlockTemplate<S>::BlockTemplate(BlockTemplate<NonConstType> &&b)
|
||||
: BlockTemplate(b)
|
||||
{}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
template <class S>
|
||||
S & DMatSample::BlockTemplate<S>::getSample(void)
|
||||
{
|
||||
return sample_;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
const S & DMatSample::BlockTemplate<S>::getSample(void) const
|
||||
{
|
||||
return sample_;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
Index DMatSample::BlockTemplate<S>::getStartRow(void) const
|
||||
{
|
||||
return i_;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
Index DMatSample::BlockTemplate<S>::getStartCol(void) const
|
||||
{
|
||||
return j_;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
Index DMatSample::BlockTemplate<S>::getNRow(void) const
|
||||
{
|
||||
return nRow_;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
Index DMatSample::BlockTemplate<S>::getNCol(void) const
|
||||
{
|
||||
return nCol_;
|
||||
}
|
||||
|
||||
// assignement operators ///////////////////////////////////////////////////////
|
||||
template <class S>
|
||||
DMatSample::BlockTemplate<S> &
|
||||
DMatSample::BlockTemplate<S>::operator=(const S &sample)
|
||||
{
|
||||
FOR_STAT_ARRAY(sample_, s)
|
||||
{
|
||||
sample_[s].block(i_, j_, nRow_, nCol_) = sample[s];
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class S>
|
||||
DMatSample::BlockTemplate<S> &
|
||||
DMatSample::BlockTemplate<S>::operator=(const S &&sample)
|
||||
{
|
||||
*this = sample;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
|
||||
#endif // Latan_MatSample_hpp_
|
@ -81,6 +81,16 @@ namespace ReducOp
|
||||
inline DMat tensProd(const DMat &v1, const DMat &v2);
|
||||
}
|
||||
|
||||
// Sample types
|
||||
#define SAMPLE_OFFSET 1
|
||||
|
||||
const int central = -SAMPLE_OFFSET;
|
||||
|
||||
template <typename T>
|
||||
using Sample = StatArray<T, SAMPLE_OFFSET>;
|
||||
|
||||
typedef Sample<double> DSample;
|
||||
|
||||
/******************************************************************************
|
||||
* StatArray class template implementation *
|
||||
******************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user