From 28b330611094cd9a18904e279c601cd718962dca Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 12 Mar 2014 19:54:27 +0000 Subject: [PATCH] big project cleaning --- .gitignore | 41 +------ build.sh | 2 + examples/exMat.cpp | 22 ++-- examples/exMat.dat | 20 ---- latan/AsciiLexer.lpp | 2 +- latan/AsciiParser.ypp | 2 +- latan/Io.cpp | 244 ---------------------------------------- latan/Io.hpp | 177 ----------------------------- latan/IoAsciiLexer.lpp | 95 ---------------- latan/IoAsciiParser.ypp | 188 ------------------------------- latan/Makefile.am | 4 +- latan/Mat.cpp | 2 +- latan/Mat.hpp | 4 + latan/Sample.cpp | 116 ------------------- latan/Sample.hpp | 203 --------------------------------- latan/includes.hpp | 2 +- 16 files changed, 29 insertions(+), 1095 deletions(-) delete mode 100644 examples/exMat.dat delete mode 100644 latan/Io.cpp delete mode 100644 latan/Io.hpp delete mode 100644 latan/IoAsciiLexer.lpp delete mode 100644 latan/IoAsciiParser.ypp delete mode 100644 latan/Sample.cpp delete mode 100644 latan/Sample.hpp diff --git a/.gitignore b/.gitignore index 46899ee..14e12bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,5 @@ -# binaries -*.o -*.a -*.so -*.dylib -examples/exMathCompiler +# builds +build/* sandbox/* # Apple stuffs @@ -13,32 +9,14 @@ sandbox/* # VIM *.swp -# debug -*.dSYM - # autotools -*.la -*.lo -*.Plo autom4te.cache/* +*.in +*.in~ config.h* -Makefile.in -Makefile configure -libtool -.buildutils/m4/* .buildutils/* -latan/.libs/* -latan/.deps/* -examples/.deps/* -examples/.libs/* -utils/.deps/* -utils/.libs/* aclocal.m4 -config.log -config.status -stamp-h1 -myconfig.sh # bison/flex generated sources latan/*Lexer.cpp @@ -48,14 +26,3 @@ latan/*Parser.hpp # Eigen headers latan/Eigen/* latan/eigen_files.mk - -# Examples -examples/exCompiledDoubleFunction -examples/exMat -examples/exMathInterpreter -examples/exPlot -examples/exRand -examples/exRand.seed - -# Utils -utils/latan_sample_read diff --git a/build.sh b/build.sh index 59c3dcf..1a9ed5e 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + PREFIX=`cat Makefile | grep '^prefix =' | awk '{print $3}'` case $1 in '') diff --git a/examples/exMat.cpp b/examples/exMat.cpp index 45d95e2..c64cbbd 100644 --- a/examples/exMat.cpp +++ b/examples/exMat.cpp @@ -9,19 +9,21 @@ using namespace Latan; int main(void) { AsciiFile F; - DMat A,B; + DMat A(2, 3), B(3, 2); 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 - cout << "-- reading " << fileName << "..." << endl; - F.open(fileName, File::Mode::read); - A = F.read("A"); - B = F.read("B"); - cout << "A=\n" << A << '\n' << endl; - cout << "B=\n" << B << '\n' << endl; - cout << "A*B=\n" << A*B << '\n' << endl; - cout << "cos(A)=\n" << A.unaryExpr(StdMath::cos) << '\n' << endl; - F.close(); + cout << "A=\n" << A << '\n' << endl; + cout << "B=\n" << B << '\n' << endl; + cout << "A*B=\n" << A*B << '\n' << endl; + cout << "cos(A)=\n" << A.unaryExpr(StdMath::cos) << '\n' << endl; // write cout << "-- saving A*B..." << endl; diff --git a/examples/exMat.dat b/examples/exMat.dat deleted file mode 100644 index 6a42143..0000000 --- a/examples/exMat.dat +++ /dev/null @@ -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 diff --git a/latan/AsciiLexer.lpp b/latan/AsciiLexer.lpp index adae707..810d026 100644 --- a/latan/AsciiLexer.lpp +++ b/latan/AsciiLexer.lpp @@ -1,5 +1,5 @@ /* - * IoAsciiLexer.lpp, part of LatAnalyze 3 + * AsciiLexer.lpp, part of LatAnalyze 3 * * Copyright (C) 2013 - 2014 Antonin Portelli * diff --git a/latan/AsciiParser.ypp b/latan/AsciiParser.ypp index a53dd96..f4389fb 100644 --- a/latan/AsciiParser.ypp +++ b/latan/AsciiParser.ypp @@ -1,5 +1,5 @@ /* - * IoAsciiParser.ypp, part of LatAnalyze 3 + * AsciiParser.ypp, part of LatAnalyze 3 * * Copyright (C) 2013 - 2014 Antonin Portelli * diff --git a/latan/Io.cpp b/latan/Io.cpp deleted file mode 100644 index 6ff5909..0000000 --- a/latan/Io.cpp +++ /dev/null @@ -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 . - */ - -#include -#include - -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(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(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(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; -} diff --git a/latan/Io.hpp b/latan/Io.hpp deleted file mode 100644 index 06742bf..0000000 --- a/latan/Io.hpp +++ /dev/null @@ -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 . - */ - -#ifndef Latan_Io_hpp_ -#define Latan_Io_hpp_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -BEGIN_NAMESPACE - -/****************************************************************************** - * Abstract datafile class * - ******************************************************************************/ -typedef std::unordered_map> 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 - 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 - 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 -const IoT& File::read(const std::string &name) -{ - std::string dataName; - - dataName = load(name); - - return getData(dataName); -} - -template -const IoT& File::getData(const std::string &name) const -{ - try - { - return dynamic_cast(*(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 - { - 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 dMatQueue; - std::queue doubleQueue; - std::queue 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 state_; -}; - -END_NAMESPACE - -#endif diff --git a/latan/IoAsciiLexer.lpp b/latan/IoAsciiLexer.lpp deleted file mode 100644 index ef54ddb..0000000 --- a/latan/IoAsciiLexer.lpp +++ /dev/null @@ -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 . - */ - -%option reentrant -%option prefix="_ioAscii_" -%option bison-bridge -%option bison-locations -%option noyywrap -%option yylineno - -%{ - #include - #include - #include - #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(yytext); RETTOK(INT);} -{FLOAT} {yylval->val_double = strTo(yytext); RETTOK(FLOAT);} -({ALPHA}|{DIGIT})+ {strcpy(yylval->val_str,yytext); RETTOK(ID);} -latan_begin {BEGIN(TYPE); RETTOK(OPEN);} -latan_end {BEGIN(TYPE); RETTOK(CLOSE);} -mat {BEGIN(INITIAL); RETTOK(MAT);} -rs_sample {BEGIN(INITIAL); RETTOK(SAMPLE);} -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); -} diff --git a/latan/IoAsciiParser.ypp b/latan/IoAsciiParser.ypp deleted file mode 100644 index 0574bb5..0000000 --- a/latan/IoAsciiParser.ypp +++ /dev/null @@ -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 . - */ - -%{ - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - - 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 ERR -%token FLOAT -%token INT -%token ID -%token OPEN CLOSE MAT SAMPLE RG_STATE - -%type 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($INT));} - | FLOAT {state->doubleQueue.push($FLOAT);} - | INT {state->doubleQueue.push(static_cast($INT));} - ; - -ints: - ints INT {state->intQueue.push($INT);} - | INT {state->intQueue.push($INT);} - ; diff --git a/latan/Makefile.am b/latan/Makefile.am index ce5574e..6abd3a8 100644 --- a/latan/Makefile.am +++ b/latan/Makefile.am @@ -46,6 +46,7 @@ liblatan_la_SOURCES = \ Model.cpp \ Plot.cpp \ RandGen.cpp \ + XYSampleData.cpp \ XYStatData.cpp \ ../config.h liblatan_ladir = $(pkgincludedir) @@ -68,7 +69,8 @@ liblatan_la_HEADERS = \ ParserState.hpp \ Plot.hpp \ RandGen.hpp \ - StatArray.hpp + StatArray.hpp \ + XYSampleData.hpp \ XYStatData.hpp if HAVE_MINUIT liblatan_la_SOURCES += MinuitMinimizer.cpp diff --git a/latan/Mat.cpp b/latan/Mat.cpp index 61bdbf4..5baf25b 100644 --- a/latan/Mat.cpp +++ b/latan/Mat.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace Latan; /****************************************************************************** - * DMat class * + * DMat implementation * ******************************************************************************/ // constructors //////////////////////////////////////////////////////////////// DMat::DMat(const Index nRow, const Index nCol) diff --git a/latan/Mat.hpp b/latan/Mat.hpp index d9dafa4..608b2a8 100644 --- a/latan/Mat.hpp +++ b/latan/Mat.hpp @@ -29,6 +29,10 @@ for (Latan::Index i = 0; i < mat.rows(); ++i) BEGIN_NAMESPACE +/****************************************************************************** + * double matrix type * + ******************************************************************************/ + class DMat: public DMatBase, public IoObject { private: diff --git a/latan/Sample.cpp b/latan/Sample.cpp deleted file mode 100644 index 0f80484..0000000 --- a/latan/Sample.cpp +++ /dev/null @@ -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 . - */ - -#include -#include - -using namespace Latan; -using namespace std; - -/****************************************************************************** - * DMatSample implementation * - ******************************************************************************/ -// constructors //////////////////////////////////////////////////////////////// -DMatSample::DMatSample(const Index nSample, const Index nRow, - const Index nCol) -: Sample(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; -} diff --git a/latan/Sample.hpp b/latan/Sample.hpp deleted file mode 100644 index 0546e88..0000000 --- a/latan/Sample.hpp +++ /dev/null @@ -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 . - */ - -#ifndef Latan_Sample_hpp_ -#define Latan_Sample_hpp_ - -#include -#include -#include -#include - -BEGIN_NAMESPACE - -#define SAMPLE_OFFSET 1u - -const int central = -static_cast(SAMPLE_OFFSET); - -/****************************************************************************** - * Sample class * - ******************************************************************************/ -template -class Sample: public StatArray -{ -private: - typedef StatArray Base; -public: - // constructors - Sample(void) = default; - using Base::Base; - // destructor - virtual ~Sample(void) = default; -}; - -/****************************************************************************** - * DMatSample class * - ******************************************************************************/ - -class DMatSample: public Sample, public IoObject -{ -public: - // block type template - template - class BlockTemplate - { - private: - typedef typename std::remove_const::type NonConstType; - public: - // constructors - BlockTemplate(S &sample, const Index i, const Index j, const Index nRow, - const Index nCol); - BlockTemplate(BlockTemplate &b); - BlockTemplate(BlockTemplate &&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 & operator=(const S &sample); - BlockTemplate & operator=(const S &&sample); - private: - S &sample_; - const Index i_, j_, nRow_, nCol_; - }; - // block types - typedef BlockTemplate Block; - typedef const BlockTemplate ConstBlock; -public: - // constructors - DMatSample(void) = default; - DMatSample(const Index nSample, const Index nRow, const Index nCol); - DMatSample(ConstBlock &sampleBlock); - DMatSample(ConstBlock &&sampleBlock); - using Sample::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 -DMatSample::BlockTemplate::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 -DMatSample::BlockTemplate::BlockTemplate(BlockTemplate &b) -: sample_(b.getSample()) -, i_(b.getStartRow()) -, j_(b.getStartCol()) -, nRow_(b.getNRow()) -, nCol_(b.getNCol()) -{} - -template -DMatSample::BlockTemplate::BlockTemplate(BlockTemplate &&b) -: BlockTemplate(b) -{} - -// access ////////////////////////////////////////////////////////////////////// -template -S & DMatSample::BlockTemplate::getSample(void) -{ - return sample_; -} - -template -const S & DMatSample::BlockTemplate::getSample(void) const -{ - return sample_; -} - -template -Index DMatSample::BlockTemplate::getStartRow(void) const -{ - return i_; -} - -template -Index DMatSample::BlockTemplate::getStartCol(void) const -{ - return j_; -} - -template -Index DMatSample::BlockTemplate::getNRow(void) const -{ - return nRow_; -} - -template -Index DMatSample::BlockTemplate::getNCol(void) const -{ - return nCol_; -} - -// assignement operators /////////////////////////////////////////////////////// -template -DMatSample::BlockTemplate & -DMatSample::BlockTemplate::operator=(const S &sample) -{ - FOR_STAT_ARRAY(sample_, s) - { - sample_[s].block(i_, j_, nRow_, nCol_) = sample[s]; - } - - return *this; -} - -template -DMatSample::BlockTemplate & -DMatSample::BlockTemplate::operator=(const S &&sample) -{ - *this = sample; - - return *this; -} - -END_NAMESPACE - -#endif // Latan_Sample_hpp_ diff --git a/latan/includes.hpp b/latan/includes.hpp index 0bf651e..7fa588e 100644 --- a/latan/includes.hpp +++ b/latan/includes.hpp @@ -34,6 +34,6 @@ #include #include #include -#include "../config.h" +#include #endif // Latan_includes_hpp_