mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
big project cleaning
This commit is contained in:
parent
052f6cb389
commit
28b3306110
41
.gitignore
vendored
41
.gitignore
vendored
@ -1,9 +1,5 @@
|
|||||||
# binaries
|
# builds
|
||||||
*.o
|
build/*
|
||||||
*.a
|
|
||||||
*.so
|
|
||||||
*.dylib
|
|
||||||
examples/exMathCompiler
|
|
||||||
sandbox/*
|
sandbox/*
|
||||||
|
|
||||||
# Apple stuffs
|
# Apple stuffs
|
||||||
@ -13,32 +9,14 @@ sandbox/*
|
|||||||
# VIM
|
# VIM
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
# debug
|
|
||||||
*.dSYM
|
|
||||||
|
|
||||||
# autotools
|
# autotools
|
||||||
*.la
|
|
||||||
*.lo
|
|
||||||
*.Plo
|
|
||||||
autom4te.cache/*
|
autom4te.cache/*
|
||||||
|
*.in
|
||||||
|
*.in~
|
||||||
config.h*
|
config.h*
|
||||||
Makefile.in
|
|
||||||
Makefile
|
|
||||||
configure
|
configure
|
||||||
libtool
|
|
||||||
.buildutils/m4/*
|
|
||||||
.buildutils/*
|
.buildutils/*
|
||||||
latan/.libs/*
|
|
||||||
latan/.deps/*
|
|
||||||
examples/.deps/*
|
|
||||||
examples/.libs/*
|
|
||||||
utils/.deps/*
|
|
||||||
utils/.libs/*
|
|
||||||
aclocal.m4
|
aclocal.m4
|
||||||
config.log
|
|
||||||
config.status
|
|
||||||
stamp-h1
|
|
||||||
myconfig.sh
|
|
||||||
|
|
||||||
# bison/flex generated sources
|
# bison/flex generated sources
|
||||||
latan/*Lexer.cpp
|
latan/*Lexer.cpp
|
||||||
@ -48,14 +26,3 @@ latan/*Parser.hpp
|
|||||||
# Eigen headers
|
# Eigen headers
|
||||||
latan/Eigen/*
|
latan/Eigen/*
|
||||||
latan/eigen_files.mk
|
latan/eigen_files.mk
|
||||||
|
|
||||||
# Examples
|
|
||||||
examples/exCompiledDoubleFunction
|
|
||||||
examples/exMat
|
|
||||||
examples/exMathInterpreter
|
|
||||||
examples/exPlot
|
|
||||||
examples/exRand
|
|
||||||
examples/exRand.seed
|
|
||||||
|
|
||||||
# Utils
|
|
||||||
utils/latan_sample_read
|
|
||||||
|
2
build.sh
2
build.sh
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
PREFIX=`cat Makefile | grep '^prefix =' | awk '{print $3}'`
|
PREFIX=`cat Makefile | grep '^prefix =' | awk '{print $3}'`
|
||||||
case $1 in
|
case $1 in
|
||||||
'')
|
'')
|
||||||
|
@ -9,19 +9,21 @@ using namespace Latan;
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
AsciiFile F;
|
AsciiFile F;
|
||||||
DMat A,B;
|
DMat A(2, 3), B(3, 2);
|
||||||
const string fileName = "exMat.dat";
|
const string fileName = "exMat.dat";
|
||||||
|
|
||||||
|
A << 1, 2, 3,
|
||||||
|
4, 5, 6;
|
||||||
|
|
||||||
|
B << 1.0, 2.5,
|
||||||
|
4.5, 8.9,
|
||||||
|
1.2, 3.5;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
cout << "-- reading " << fileName << "..." << endl;
|
|
||||||
F.open(fileName, File::Mode::read);
|
|
||||||
A = F.read<DMat>("A");
|
|
||||||
B = F.read<DMat>("B");
|
|
||||||
cout << "A=\n" << A << '\n' << endl;
|
cout << "A=\n" << A << '\n' << endl;
|
||||||
cout << "B=\n" << B << '\n' << endl;
|
cout << "B=\n" << B << '\n' << endl;
|
||||||
cout << "A*B=\n" << A*B << '\n' << endl;
|
cout << "A*B=\n" << A*B << '\n' << endl;
|
||||||
cout << "cos(A)=\n" << A.unaryExpr(StdMath::cos) << '\n' << endl;
|
cout << "cos(A)=\n" << A.unaryExpr(StdMath::cos) << '\n' << endl;
|
||||||
F.close();
|
|
||||||
|
|
||||||
// write
|
// write
|
||||||
cout << "-- saving A*B..." << endl;
|
cout << "-- saving A*B..." << endl;
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
#L latan_begin mat A
|
|
||||||
2
|
|
||||||
2.3 5
|
|
||||||
4.5 -1.15281
|
|
||||||
#L latan_end mat
|
|
||||||
|
|
||||||
#L latan_begin mat B
|
|
||||||
3
|
|
||||||
1.1
|
|
||||||
1.2
|
|
||||||
1.3
|
|
||||||
2
|
|
||||||
2.2
|
|
||||||
2.3
|
|
||||||
#L latan_end mat
|
|
||||||
#L latan_begin mat AB
|
|
||||||
3
|
|
||||||
12.53 13.76 14.49
|
|
||||||
2.64438 2.86382 3.19854
|
|
||||||
#L latan_end mat
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* IoAsciiLexer.lpp, part of LatAnalyze 3
|
* AsciiLexer.lpp, part of LatAnalyze 3
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 - 2014 Antonin Portelli
|
* Copyright (C) 2013 - 2014 Antonin Portelli
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* IoAsciiParser.ypp, part of LatAnalyze 3
|
* AsciiParser.ypp, part of LatAnalyze 3
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 - 2014 Antonin Portelli
|
* Copyright (C) 2013 - 2014 Antonin Portelli
|
||||||
*
|
*
|
||||||
|
244
latan/Io.cpp
244
latan/Io.cpp
@ -1,244 +0,0 @@
|
|||||||
/*
|
|
||||||
* Io.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/Io.hpp>
|
|
||||||
#include <latan/includes.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace Latan;
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* File implementation *
|
|
||||||
******************************************************************************/
|
|
||||||
// constructors ////////////////////////////////////////////////////////////////
|
|
||||||
File::File(void)
|
|
||||||
: name_("")
|
|
||||||
, mode_(Mode::null)
|
|
||||||
, data_()
|
|
||||||
{}
|
|
||||||
|
|
||||||
File::File(const string &name, const unsigned int mode)
|
|
||||||
: name_(name)
|
|
||||||
, mode_(mode)
|
|
||||||
, data_()
|
|
||||||
{}
|
|
||||||
|
|
||||||
// destructor //////////////////////////////////////////////////////////////////
|
|
||||||
File::~File(void)
|
|
||||||
{
|
|
||||||
deleteData();
|
|
||||||
}
|
|
||||||
|
|
||||||
// access //////////////////////////////////////////////////////////////////////
|
|
||||||
const string & File::getName(void) const
|
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int File::getMode(void) const
|
|
||||||
{
|
|
||||||
return mode_;
|
|
||||||
}
|
|
||||||
|
|
||||||
// internal functions //////////////////////////////////////////////////////////
|
|
||||||
void File::deleteData(void)
|
|
||||||
{
|
|
||||||
for (auto &i : data_)
|
|
||||||
{
|
|
||||||
i.second.reset();
|
|
||||||
}
|
|
||||||
data_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void File::checkWritability(void)
|
|
||||||
{
|
|
||||||
if (!((mode_ & Mode::write)||(mode_ & Mode::append))||!isOpen())
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Io, "file '" + name_ + "' is not writable");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* AsciiFile implementation *
|
|
||||||
******************************************************************************/
|
|
||||||
// AsciiParserState constructor ////////////////////////////////////////////////
|
|
||||||
AsciiFile::AsciiParserState::AsciiParserState(istream *stream, string *name,
|
|
||||||
IoDataTable *data)
|
|
||||||
: ParserState<IoDataTable>(stream, name, data)
|
|
||||||
{
|
|
||||||
initScanner();
|
|
||||||
}
|
|
||||||
|
|
||||||
// AsciiParserState destructor /////////////////////////////////////////////////
|
|
||||||
AsciiFile::AsciiParserState::~AsciiParserState(void)
|
|
||||||
{
|
|
||||||
destroyScanner();
|
|
||||||
}
|
|
||||||
|
|
||||||
// constructor /////////////////////////////////////////////////////////////////
|
|
||||||
AsciiFile::AsciiFile(void)
|
|
||||||
: File(), fileStream_()
|
|
||||||
, isParsed_(false)
|
|
||||||
, state_(nullptr)
|
|
||||||
{}
|
|
||||||
|
|
||||||
AsciiFile::AsciiFile(const string &name, const unsigned int mode)
|
|
||||||
{
|
|
||||||
open(name, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// destructor //////////////////////////////////////////////////////////////////
|
|
||||||
AsciiFile::~AsciiFile(void)
|
|
||||||
{
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// access //////////////////////////////////////////////////////////////////////
|
|
||||||
void AsciiFile::save(const DMat &m, const std::string &name)
|
|
||||||
{
|
|
||||||
checkWritability();
|
|
||||||
isParsed_ = false;
|
|
||||||
fileStream_ << "#L latan_begin mat " << name << endl;
|
|
||||||
fileStream_ << m.cols() << endl;
|
|
||||||
fileStream_ << scientific << m << endl;
|
|
||||||
fileStream_ << "#L latan_end mat " << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AsciiFile::save(const DMatSample &s, const std::string &name)
|
|
||||||
{
|
|
||||||
checkWritability();
|
|
||||||
isParsed_ = false;
|
|
||||||
fileStream_ << "#L latan_begin rs_sample " << name << endl;
|
|
||||||
fileStream_ << s.size() << endl;
|
|
||||||
save(s[central], name + "_C");
|
|
||||||
for (int i = 0; i < static_cast<int>(s.size()); ++i)
|
|
||||||
{
|
|
||||||
save(s[i], name + "_S_" + strFrom(i));
|
|
||||||
}
|
|
||||||
fileStream_ << "#L latan_end rs_sample " << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AsciiFile::save(const RandGen::State &state, const std::string &name)
|
|
||||||
{
|
|
||||||
checkWritability();
|
|
||||||
isParsed_ = false;
|
|
||||||
fileStream_ << "#L latan_begin rg_state " << name << endl;
|
|
||||||
fileStream_ << state << endl;
|
|
||||||
fileStream_ << "#L latan_end rg_state " << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// tests ///////////////////////////////////////////////////////////////////////
|
|
||||||
bool AsciiFile::isOpen() const
|
|
||||||
{
|
|
||||||
return fileStream_.is_open();
|
|
||||||
}
|
|
||||||
|
|
||||||
// IO //////////////////////////////////////////////////////////////////////////
|
|
||||||
void AsciiFile::close(void)
|
|
||||||
{
|
|
||||||
state_.reset();
|
|
||||||
if (isOpen())
|
|
||||||
{
|
|
||||||
fileStream_.close();
|
|
||||||
}
|
|
||||||
name_ = "";
|
|
||||||
mode_ = Mode::null;
|
|
||||||
isParsed_ = false;
|
|
||||||
deleteData();
|
|
||||||
}
|
|
||||||
|
|
||||||
void AsciiFile::open(const string &name, const unsigned int mode)
|
|
||||||
{
|
|
||||||
if (isOpen())
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Io, "file already opened with name '" + name_ + "'");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ios_base::openmode stdMode = static_cast<ios_base::openmode>(0);
|
|
||||||
|
|
||||||
if (mode & Mode::write)
|
|
||||||
{
|
|
||||||
stdMode |= ios::out|ios::trunc;
|
|
||||||
}
|
|
||||||
if (mode & Mode::read)
|
|
||||||
{
|
|
||||||
stdMode |= ios::in;
|
|
||||||
}
|
|
||||||
if (mode & Mode::append)
|
|
||||||
{
|
|
||||||
stdMode |= ios::out|ios::app;
|
|
||||||
}
|
|
||||||
name_ = name;
|
|
||||||
mode_ = mode;
|
|
||||||
isParsed_ = false;
|
|
||||||
fileStream_.open(name_.c_str(), stdMode);
|
|
||||||
if (mode_ & Mode::read)
|
|
||||||
{
|
|
||||||
state_.reset(new AsciiParserState(&fileStream_, &name_, &data_));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
state_.reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string AsciiFile::load(const string &name)
|
|
||||||
{
|
|
||||||
if ((mode_ & Mode::read)&&(isOpen()))
|
|
||||||
{
|
|
||||||
if (!isParsed_)
|
|
||||||
{
|
|
||||||
state_->isFirst = true;
|
|
||||||
parse();
|
|
||||||
}
|
|
||||||
if (name.empty())
|
|
||||||
{
|
|
||||||
return state_->first;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (isOpen())
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Io, "file '" + name_ + "' is not opened in read mode");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Io, "file not opened");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parser //////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//// Bison/Flex parser declaration
|
|
||||||
int _ioAscii_parse(AsciiFile::AsciiParserState *state);
|
|
||||||
|
|
||||||
void AsciiFile::parse()
|
|
||||||
{
|
|
||||||
fileStream_.seekg(0);
|
|
||||||
_ioAscii_parse(state_.get());
|
|
||||||
isParsed_ = true;
|
|
||||||
}
|
|
177
latan/Io.hpp
177
latan/Io.hpp
@ -1,177 +0,0 @@
|
|||||||
/*
|
|
||||||
* Io.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_Io_hpp_
|
|
||||||
#define Latan_Io_hpp_
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <memory>
|
|
||||||
#include <queue>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <latan/Global.hpp>
|
|
||||||
#include <latan/IoObject.hpp>
|
|
||||||
#include <latan/Mat.hpp>
|
|
||||||
#include <latan/ParserState.hpp>
|
|
||||||
#include <latan/RandGen.hpp>
|
|
||||||
#include <latan/Sample.hpp>
|
|
||||||
|
|
||||||
BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* Abstract datafile class *
|
|
||||||
******************************************************************************/
|
|
||||||
typedef std::unordered_map<std::string, std::unique_ptr<IoObject>> IoDataTable;
|
|
||||||
|
|
||||||
class File
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
class Mode
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
null = 0,
|
|
||||||
write = 1 << 0,
|
|
||||||
read = 1 << 1,
|
|
||||||
append = 1 << 2
|
|
||||||
};
|
|
||||||
};
|
|
||||||
public:
|
|
||||||
// constructors
|
|
||||||
File(void);
|
|
||||||
File(const std::string &name, const unsigned int mode);
|
|
||||||
// destructor
|
|
||||||
virtual ~File(void);
|
|
||||||
// access
|
|
||||||
const std::string & getName(void) const;
|
|
||||||
unsigned int getMode(void) const;
|
|
||||||
template <typename IoT>
|
|
||||||
const IoT & read(const std::string &name = "");
|
|
||||||
virtual void save(const DMat &m, const std::string &name) = 0;
|
|
||||||
virtual void save(const DMatSample &state, const std::string &name) = 0;
|
|
||||||
virtual void save(const RandGen::State &state, const std::string &name) = 0;
|
|
||||||
// tests
|
|
||||||
virtual bool isOpen(void) const = 0;
|
|
||||||
// IO
|
|
||||||
virtual void close(void) = 0;
|
|
||||||
virtual void open(const std::string &name, const unsigned int mode) = 0;
|
|
||||||
protected:
|
|
||||||
// access
|
|
||||||
void setName(const std::string &name);
|
|
||||||
void setMode(const unsigned int mode);
|
|
||||||
// data access
|
|
||||||
void deleteData(void);
|
|
||||||
// error checking
|
|
||||||
void checkWritability(void);
|
|
||||||
private:
|
|
||||||
// data access
|
|
||||||
template <typename IoT>
|
|
||||||
const IoT& getData(const std::string &name = "") const;
|
|
||||||
// IO
|
|
||||||
virtual std::string load(const std::string &name = "") = 0;
|
|
||||||
protected:
|
|
||||||
std::string name_;
|
|
||||||
unsigned int mode_;
|
|
||||||
IoDataTable data_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Template implementations
|
|
||||||
template <typename IoT>
|
|
||||||
const IoT& File::read(const std::string &name)
|
|
||||||
{
|
|
||||||
std::string dataName;
|
|
||||||
|
|
||||||
dataName = load(name);
|
|
||||||
|
|
||||||
return getData<IoT>(dataName);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename IoT>
|
|
||||||
const IoT& File::getData(const std::string &name) const
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return dynamic_cast<const IoT &>(*(data_.at(name)));
|
|
||||||
}
|
|
||||||
catch(std::out_of_range)
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Definition, "no data with name '" + name + "' in file "
|
|
||||||
+ name_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* ASCII datafile class *
|
|
||||||
******************************************************************************/
|
|
||||||
class AsciiFile: public File
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
class AsciiParserState: public ParserState<IoDataTable>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// constructor
|
|
||||||
explicit AsciiParserState(std::istream *stream, std::string *name,
|
|
||||||
IoDataTable *data);
|
|
||||||
// destructor
|
|
||||||
virtual ~AsciiParserState(void);
|
|
||||||
// first element reference
|
|
||||||
bool isFirst;
|
|
||||||
std::string first;
|
|
||||||
// parsing buffers
|
|
||||||
RandGen::State stateBuf;
|
|
||||||
DMatSample dMatSampleBuf;
|
|
||||||
std::queue<DMat> dMatQueue;
|
|
||||||
std::queue<double> doubleQueue;
|
|
||||||
std::queue<int> intQueue;
|
|
||||||
private:
|
|
||||||
// allocation/deallocation functions defined in IoAsciiLexer.lpp
|
|
||||||
virtual void initScanner(void);
|
|
||||||
virtual void destroyScanner(void);
|
|
||||||
};
|
|
||||||
public:
|
|
||||||
// constructors
|
|
||||||
AsciiFile(void);
|
|
||||||
AsciiFile(const std::string &name, const unsigned int mode);
|
|
||||||
// destructor
|
|
||||||
virtual ~AsciiFile(void);
|
|
||||||
// access
|
|
||||||
virtual void save(const DMat &m, const std::string &name);
|
|
||||||
virtual void save(const DMatSample &s, const std::string &name);
|
|
||||||
virtual void save(const RandGen::State &state, const std::string &name);
|
|
||||||
// tests
|
|
||||||
virtual bool isOpen(void) const;
|
|
||||||
// IO
|
|
||||||
virtual void close(void);
|
|
||||||
virtual void open(const std::string &name, const unsigned int mode);
|
|
||||||
private:
|
|
||||||
// IO
|
|
||||||
virtual std::string load(const std::string &name = "");
|
|
||||||
// parser
|
|
||||||
void parse(void);
|
|
||||||
private:
|
|
||||||
std::fstream fileStream_;
|
|
||||||
bool isParsed_;
|
|
||||||
std::unique_ptr<AsciiParserState> state_;
|
|
||||||
};
|
|
||||||
|
|
||||||
END_NAMESPACE
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* IoAsciiLexer.lpp, 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
%option reentrant
|
|
||||||
%option prefix="_ioAscii_"
|
|
||||||
%option bison-bridge
|
|
||||||
%option bison-locations
|
|
||||||
%option noyywrap
|
|
||||||
%option yylineno
|
|
||||||
|
|
||||||
%{
|
|
||||||
#include <iostream>
|
|
||||||
#include <latan/IO.hpp>
|
|
||||||
#include <latan/IOASCIIParser.hpp>
|
|
||||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace Latan;
|
|
||||||
|
|
||||||
#define YY_EXTRA_TYPE AsciiFile::AsciiParserState*
|
|
||||||
#define YY_USER_ACTION \
|
|
||||||
yylloc->first_line = yylloc->last_line = yylineno;\
|
|
||||||
yylloc->first_column = yylloc->last_column + 1;\
|
|
||||||
yylloc->last_column = yylloc->first_column + yyleng - 1;
|
|
||||||
|
|
||||||
#define YY_INPUT(buf, result, max_size) \
|
|
||||||
{ \
|
|
||||||
(*yyextra->stream).read(buf,max_size);\
|
|
||||||
result = (*yyextra->stream).gcount();\
|
|
||||||
}
|
|
||||||
|
|
||||||
#define YY_DEBUG 0
|
|
||||||
#if (YY_DEBUG == 1)
|
|
||||||
#define RETTOK(tok) cout << #tok << "(" << yytext << ")" << endl; return tok
|
|
||||||
#else
|
|
||||||
#define RETTOK(tok) return tok
|
|
||||||
#endif
|
|
||||||
%}
|
|
||||||
|
|
||||||
DIGIT [0-9]
|
|
||||||
ALPHA [a-zA-Z_\-]
|
|
||||||
SIGN \+|-
|
|
||||||
EXP e|E
|
|
||||||
INT {SIGN}?{DIGIT}+
|
|
||||||
FLOAT {SIGN}?(({DIGIT}+\.{DIGIT}*)|({DIGIT}*\.{DIGIT}+))({EXP}{SIGN}?{INT}+)?
|
|
||||||
LMARK #L
|
|
||||||
BLANK [ \t]
|
|
||||||
|
|
||||||
%x MARK TYPE
|
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
{LMARK} {BEGIN(MARK);}
|
|
||||||
{INT} {yylval->val_int = strTo<int>(yytext); RETTOK(INT);}
|
|
||||||
{FLOAT} {yylval->val_double = strTo<double>(yytext); RETTOK(FLOAT);}
|
|
||||||
({ALPHA}|{DIGIT})+ {strcpy(yylval->val_str,yytext); RETTOK(ID);}
|
|
||||||
<MARK>latan_begin {BEGIN(TYPE); RETTOK(OPEN);}
|
|
||||||
<MARK>latan_end {BEGIN(TYPE); RETTOK(CLOSE);}
|
|
||||||
<TYPE>mat {BEGIN(INITIAL); RETTOK(MAT);}
|
|
||||||
<TYPE>rs_sample {BEGIN(INITIAL); RETTOK(SAMPLE);}
|
|
||||||
<TYPE>rg_state {BEGIN(INITIAL); RETTOK(RG_STATE);}
|
|
||||||
<*>\n {yylloc->last_column = 0;}
|
|
||||||
<*>[ \t]
|
|
||||||
<*>. {yylval->val_char = yytext[0]; RETTOK(ERR);}
|
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
void AsciiFile::AsciiParserState::initScanner()
|
|
||||||
{
|
|
||||||
yylex_init(&scanner);
|
|
||||||
yyset_extra(this, scanner);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AsciiFile::AsciiParserState::destroyScanner()
|
|
||||||
{
|
|
||||||
yylex_destroy(scanner);
|
|
||||||
}
|
|
@ -1,188 +0,0 @@
|
|||||||
/*
|
|
||||||
* IoAsciiParser.ypp, 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 <iostream>
|
|
||||||
#include <memory>
|
|
||||||
#include <sstream>
|
|
||||||
#include <utility>
|
|
||||||
#include <cstring>
|
|
||||||
#include <latan/Global.hpp>
|
|
||||||
#include <latan/IO.hpp>
|
|
||||||
#include <latan/Mat.hpp>
|
|
||||||
#include <latan/RandGen.hpp>
|
|
||||||
#include <latan/Sample.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace Latan;
|
|
||||||
|
|
||||||
#define TEST_FIRST(name) \
|
|
||||||
if (state->isFirst)\
|
|
||||||
{\
|
|
||||||
state->first = (name);\
|
|
||||||
state->isFirst = false;\
|
|
||||||
}
|
|
||||||
%}
|
|
||||||
|
|
||||||
%pure-parser
|
|
||||||
%name-prefix="_ioAscii_"
|
|
||||||
%locations
|
|
||||||
%defines
|
|
||||||
%error-verbose
|
|
||||||
%parse-param { Latan::AsciiFile::AsciiParserState* state }
|
|
||||||
%initial-action {yylloc.last_column = 0;}
|
|
||||||
%lex-param { void* scanner }
|
|
||||||
|
|
||||||
%union
|
|
||||||
{
|
|
||||||
int val_int;
|
|
||||||
double val_double;
|
|
||||||
char val_char;
|
|
||||||
char val_str[256];
|
|
||||||
}
|
|
||||||
|
|
||||||
%token <val_char> ERR
|
|
||||||
%token <val_double> FLOAT
|
|
||||||
%token <val_int> INT
|
|
||||||
%token <val_str> ID
|
|
||||||
%token OPEN CLOSE MAT SAMPLE RG_STATE
|
|
||||||
|
|
||||||
%type <val_str> mat sample rg_state
|
|
||||||
|
|
||||||
%{
|
|
||||||
int _ioAscii_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
|
|
||||||
|
|
||||||
void _ioAscii_error(YYLTYPE* locp, AsciiFile::AsciiParserState* state,
|
|
||||||
const char* err)
|
|
||||||
{
|
|
||||||
stringstream buf;
|
|
||||||
|
|
||||||
buf << *state->streamName << ":" << locp->first_line << ":"\
|
|
||||||
<< locp->first_column << ": " << err;
|
|
||||||
LATAN_ERROR(Parsing, buf.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
#define scanner state->scanner
|
|
||||||
%}
|
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
datas:
|
|
||||||
/* empty string */
|
|
||||||
| datas data
|
|
||||||
;
|
|
||||||
|
|
||||||
data:
|
|
||||||
mat
|
|
||||||
{
|
|
||||||
TEST_FIRST($1);
|
|
||||||
(*state->data)[$1].reset(new DMat(state->dMatQueue.front()));
|
|
||||||
state->dMatQueue.pop();
|
|
||||||
}
|
|
||||||
| sample
|
|
||||||
{
|
|
||||||
TEST_FIRST($1);
|
|
||||||
(*state->data)[$1].reset(new DMatSample(state->dMatSampleBuf));
|
|
||||||
}
|
|
||||||
| rg_state
|
|
||||||
{
|
|
||||||
TEST_FIRST($1);
|
|
||||||
(*state->data)[$1].reset(new RandGen::State(state->stateBuf));
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
mat:
|
|
||||||
OPEN MAT ID INT floats CLOSE MAT
|
|
||||||
{
|
|
||||||
const unsigned int nRow = state->doubleQueue.size()/$INT, nCol = $INT;
|
|
||||||
int i, j, r = 0;
|
|
||||||
|
|
||||||
if (state->doubleQueue.size() != nRow*nCol)
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Size, "matrix '" + *state->streamName + ":" + $ID +
|
|
||||||
"' has a wrong size");
|
|
||||||
}
|
|
||||||
|
|
||||||
state->dMatQueue.push(DMat(nRow, nCol));
|
|
||||||
while (!state->doubleQueue.empty())
|
|
||||||
{
|
|
||||||
j = r % nCol;
|
|
||||||
i = (r - j)/nCol;
|
|
||||||
state->dMatQueue.back()(i, j) = state->doubleQueue.front();
|
|
||||||
state->doubleQueue.pop();
|
|
||||||
r++;
|
|
||||||
}
|
|
||||||
strcpy($$, $ID);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
sample:
|
|
||||||
OPEN SAMPLE ID INT mats CLOSE SAMPLE
|
|
||||||
{
|
|
||||||
const unsigned int nSample = $INT + 1;
|
|
||||||
|
|
||||||
if (state->dMatQueue.size() != nSample)
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Size, "sample '" + *state->streamName + ":" + $ID +
|
|
||||||
"' has a wrong size");
|
|
||||||
}
|
|
||||||
state->dMatSampleBuf.resize(nSample);
|
|
||||||
state->dMatSampleBuf[central] = state->dMatQueue.front();
|
|
||||||
state->dMatQueue.pop();
|
|
||||||
for (int i = 0; i < $INT; ++i)
|
|
||||||
{
|
|
||||||
state->dMatSampleBuf[i] = state->dMatQueue.front();
|
|
||||||
state->dMatQueue.pop();
|
|
||||||
}
|
|
||||||
strcpy($$, $ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
rg_state:
|
|
||||||
OPEN RG_STATE ID ints CLOSE RG_STATE
|
|
||||||
{
|
|
||||||
if (state->intQueue.size() != RLXG_STATE_SIZE)
|
|
||||||
{
|
|
||||||
LATAN_ERROR(Size, "random generator state '" + *state->streamName
|
|
||||||
+ ":" + $ID + "' has a wrong size");
|
|
||||||
}
|
|
||||||
for (unsigned int i = 0; i < RLXG_STATE_SIZE; ++i)
|
|
||||||
{
|
|
||||||
state->stateBuf[i] = state->intQueue.front();
|
|
||||||
state->intQueue.pop();
|
|
||||||
}
|
|
||||||
strcpy($$, $ID);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
mats:
|
|
||||||
mats mat
|
|
||||||
| mat
|
|
||||||
;
|
|
||||||
|
|
||||||
floats:
|
|
||||||
floats FLOAT {state->doubleQueue.push($FLOAT);}
|
|
||||||
| floats INT {state->doubleQueue.push(static_cast<double>($INT));}
|
|
||||||
| FLOAT {state->doubleQueue.push($FLOAT);}
|
|
||||||
| INT {state->doubleQueue.push(static_cast<double>($INT));}
|
|
||||||
;
|
|
||||||
|
|
||||||
ints:
|
|
||||||
ints INT {state->intQueue.push($INT);}
|
|
||||||
| INT {state->intQueue.push($INT);}
|
|
||||||
;
|
|
@ -46,6 +46,7 @@ liblatan_la_SOURCES = \
|
|||||||
Model.cpp \
|
Model.cpp \
|
||||||
Plot.cpp \
|
Plot.cpp \
|
||||||
RandGen.cpp \
|
RandGen.cpp \
|
||||||
|
XYSampleData.cpp \
|
||||||
XYStatData.cpp \
|
XYStatData.cpp \
|
||||||
../config.h
|
../config.h
|
||||||
liblatan_ladir = $(pkgincludedir)
|
liblatan_ladir = $(pkgincludedir)
|
||||||
@ -68,7 +69,8 @@ liblatan_la_HEADERS = \
|
|||||||
ParserState.hpp \
|
ParserState.hpp \
|
||||||
Plot.hpp \
|
Plot.hpp \
|
||||||
RandGen.hpp \
|
RandGen.hpp \
|
||||||
StatArray.hpp
|
StatArray.hpp \
|
||||||
|
XYSampleData.hpp \
|
||||||
XYStatData.hpp
|
XYStatData.hpp
|
||||||
if HAVE_MINUIT
|
if HAVE_MINUIT
|
||||||
liblatan_la_SOURCES += MinuitMinimizer.cpp
|
liblatan_la_SOURCES += MinuitMinimizer.cpp
|
||||||
|
@ -24,7 +24,7 @@ using namespace std;
|
|||||||
using namespace Latan;
|
using namespace Latan;
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* DMat class *
|
* DMat implementation *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
// constructors ////////////////////////////////////////////////////////////////
|
// constructors ////////////////////////////////////////////////////////////////
|
||||||
DMat::DMat(const Index nRow, const Index nCol)
|
DMat::DMat(const Index nRow, const Index nCol)
|
||||||
|
@ -29,6 +29,10 @@ for (Latan::Index i = 0; i < mat.rows(); ++i)
|
|||||||
|
|
||||||
BEGIN_NAMESPACE
|
BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* double matrix type *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
class DMat: public DMatBase, public IoObject
|
class DMat: public DMatBase, public IoObject
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
116
latan/Sample.cpp
116
latan/Sample.cpp
@ -1,116 +0,0 @@
|
|||||||
/*
|
|
||||||
* Sample.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/Sample.hpp>
|
|
||||||
#include <latan/includes.hpp>
|
|
||||||
|
|
||||||
using namespace Latan;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* 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();
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
203
latan/Sample.hpp
203
latan/Sample.hpp
@ -1,203 +0,0 @@
|
|||||||
/*
|
|
||||||
* Sample.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_Sample_hpp_
|
|
||||||
#define Latan_Sample_hpp_
|
|
||||||
|
|
||||||
#include <latan/Global.hpp>
|
|
||||||
#include <latan/IoObject.hpp>
|
|
||||||
#include <latan/Mat.hpp>
|
|
||||||
#include <latan/StatArray.hpp>
|
|
||||||
|
|
||||||
BEGIN_NAMESPACE
|
|
||||||
|
|
||||||
#define SAMPLE_OFFSET 1u
|
|
||||||
|
|
||||||
const int central = -static_cast<int>(SAMPLE_OFFSET);
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* Sample class *
|
|
||||||
******************************************************************************/
|
|
||||||
template <typename T>
|
|
||||||
class Sample: public StatArray<T, SAMPLE_OFFSET>
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
typedef StatArray<T, SAMPLE_OFFSET> Base;
|
|
||||||
public:
|
|
||||||
// constructors
|
|
||||||
Sample(void) = default;
|
|
||||||
using Base::Base;
|
|
||||||
// destructor
|
|
||||||
virtual ~Sample(void) = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* DMatSample 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
|
|
||||||
DMatSample(void) = default;
|
|
||||||
DMatSample(const Index nSample, const Index nRow, const Index nCol);
|
|
||||||
DMatSample(ConstBlock &sampleBlock);
|
|
||||||
DMatSample(ConstBlock &&sampleBlock);
|
|
||||||
using Sample<DMat>::Sample;
|
|
||||||
// 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_Sample_hpp_
|
|
@ -34,6 +34,6 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "../config.h"
|
#include <config.h>
|
||||||
|
|
||||||
#endif // Latan_includes_hpp_
|
#endif // Latan_includes_hpp_
|
||||||
|
Loading…
Reference in New Issue
Block a user