Verified Commit ce1ef470 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

dynare++ / tensor library (TL): move away from CWEB

By the way apply Dynare C++ coding style and extensions (.cc/.hh).
parent 84255f9e
......@@ -137,9 +137,6 @@ mex/build/matlab/run_m2html.m
/dynare++/src/dynglob_ll.cc
/dynare++/src/dynglob_tab.cc
/dynare++/src/dynglob_tab.hh
/dynare++/tl/cc/*.cpp
/dynare++/tl/cc/*.h
/dynare++/tl/cc/main.tex
/dynare++/tl/testing/tests
/dynare++/tl/testing/tests.exe
!/dynare++/extern/R/Makefile
......
......@@ -23,7 +23,7 @@
#include "mex.h"
#include "decision_rule.hh"
#include "fs_tensor.h"
#include "fs_tensor.hh"
#include "SylvException.h"
extern "C" {
......
// Copyright 2005, Ondra Kamenik
#include "product.hh"
#include "symmetry.h"
#include "symmetry.hh"
prodpit::prodpit()
: prodq(NULL), level(0), npoints(0), jseq(NULL),
......
......@@ -16,7 +16,7 @@
#ifndef PRODUCT_H
#define PRODUCT_H
#include "int_sequence.h"
#include "int_sequence.hh"
#include "vector_function.hh"
#include "quadrature.hh"
......
......@@ -32,8 +32,8 @@
#include <cstdlib>
#include "vector_function.hh"
#include "int_sequence.h"
#include "sthread.h"
#include "int_sequence.hh"
#include "sthread.hh"
/* This pure virtual class represents a concept of one-dimensional
(non-nested) quadrature. So, one dimensional quadrature must return
......
......@@ -25,7 +25,7 @@
#ifndef QUASI_MCARLO_H
#define QUASI_MCARLO_H
#include "int_sequence.h"
#include "int_sequence.hh"
#include "quadrature.hh"
#include "Vector.h"
......
// Copyright 2005, Ondra Kamenik
#include "smolyak.hh"
#include "symmetry.h"
#include "symmetry.hh"
smolpit::smolpit()
: smolq(NULL), isummand(0), jseq(NULL), sig(NULL), p(NULL)
......
......@@ -17,8 +17,8 @@
#ifndef SMOLYAK_H
#define SMOLYAK_H
#include "int_sequence.h"
#include "tl_static.h"
#include "int_sequence.hh"
#include "tl_static.hh"
#include "vector_function.hh"
#include "quadrature.hh"
......
......@@ -10,8 +10,8 @@
#ifndef DYNAMIC_MODEL_H
#define DYNAMIC_MODEL_H
#include "t_container.h"
#include "sparse_tensor.h"
#include "t_container.hh"
#include "sparse_tensor.hh"
#include "Vector.h"
......
// Copyright 2005, Ondra Kamenik
#include "faa_di_bruno.hh"
#include "fine_container.h"
#include "fine_container.hh"
#include <cmath>
......
......@@ -12,10 +12,10 @@
#define FAA_DI_BRUNO_H
#include "journal.hh"
#include "stack_container.h"
#include "t_container.h"
#include "sparse_tensor.h"
#include "gs_tensor.h"
#include "stack_container.hh"
#include "t_container.hh"
#include "sparse_tensor.hh"
#include "gs_tensor.hh"
/* Nothing special here. See |@<|FaaDiBruno::calculate| folded sparse
code@>| for reason of having |magic_mult|. */
......
......@@ -5,7 +5,7 @@
#ifndef JOURNAL_H
#define JOURNAL_H
#include "int_sequence.h"
#include "int_sequence.hh"
#include <sys/time.h>
#include <cstdio>
......
......@@ -25,13 +25,13 @@
#ifndef KORDER_H
#define KORDER_H
#include "int_sequence.h"
#include "fs_tensor.h"
#include "gs_tensor.h"
#include "t_container.h"
#include "stack_container.h"
#include "normal_moments.h"
#include "t_polynomial.h"
#include "int_sequence.hh"
#include "fs_tensor.hh"
#include "gs_tensor.hh"
#include "t_container.hh"
#include "stack_container.hh"
#include "normal_moments.hh"
#include "t_polynomial.hh"
#include "faa_di_bruno.hh"
#include "journal.hh"
......
......@@ -33,7 +33,7 @@
#ifndef NORMAL_CONJUGATE_H
#define NORMAL_CONJUGATE_H
#include "twod_matrix.h"
#include "twod_matrix.hh"
/* The class is described by the four parameters: $\mu$, $\kappa$, $\nu$ and
$\Lambda$. */
......
......@@ -8,7 +8,7 @@
#include "utils/cc/exception.h"
#include "parser/cc/parser_exception.h"
#include "parser/cc/atom_substitutions.h"
#include "../tl/cc/tl_exception.h"
#include "../tl/cc/tl_exception.hh"
#include "../kord/kord_exception.hh"
#ifndef DYNVERSION
......
......@@ -4,8 +4,8 @@
#ifndef DYNARE3_H
#define DYNARE3_H
#include "../tl/cc/t_container.h"
#include "../tl/cc/sparse_tensor.h"
#include "../tl/cc/t_container.hh"
#include "../tl/cc/sparse_tensor.hh"
#include "../kord/decision_rule.hh"
#include "../kord/dynamic_model.hh"
......
......@@ -7,7 +7,7 @@
#include "parser/cc/atom_assignings.h"
#include "dynare_atoms.h"
#include "twod_matrix.h"
#include "twod_matrix.hh"
#include "Vector.h"
#include "GeneralMatrix.h"
......
......@@ -5,7 +5,7 @@
#ifndef OGU_NLSOLVE_H
#define OGU_NLSOLVE_H
#include "twod_matrix.h"
#include "twod_matrix.hh"
#include "journal.hh"
namespace ogu
......
CWEBSRC = \
normal_moments.cweb \
int_sequence.cweb \
tensor.cweb \
ps_tensor.cweb \
pyramid_prod2.cweb \
equivalence.cweb \
fine_container.cweb \
kron_prod.cweb \
ps_tensor.hweb \
t_polynomial.cweb \
symmetry.cweb \
stack_container.cweb \
sthread.hweb \
twod_matrix.hweb \
twod_matrix.cweb \
symmetry.hweb \
sparse_tensor.cweb \
fine_container.hweb \
sthread.cweb \
int_sequence.hweb \
tl_exception.hweb \
pyramid_prod2.hweb \
t_container.hweb \
permutation.hweb \
tensor.hweb \
gs_tensor.cweb \
rfs_tensor.hweb \
pyramid_prod.hweb \
t_polynomial.hweb \
pyramid_prod.cweb \
fs_tensor.cweb \
sparse_tensor.hweb \
permutation.cweb \
equivalence.hweb \
gs_tensor.hweb \
normal_moments.hweb \
tl_static.hweb \
kron_prod.hweb \
fs_tensor.hweb \
stack_container.hweb \
rfs_tensor.cweb \
t_container.cweb \
tl_static.cweb
GENERATED_FILES = \
normal_moments.cpp \
int_sequence.cpp \
tensor.cpp \
ps_tensor.cpp \
pyramid_prod2.cpp \
equivalence.cpp \
fine_container.cpp \
kron_prod.cpp \
ps_tensor.h \
t_polynomial.cpp \
symmetry.cpp \
stack_container.cpp \
sthread.h \
twod_matrix.h \
twod_matrix.cpp \
symmetry.h \
sparse_tensor.cpp \
fine_container.h \
sthread.cpp \
int_sequence.h \
tl_exception.h \
pyramid_prod2.h \
t_container.h \
permutation.h \
tensor.h \
gs_tensor.cpp \
rfs_tensor.h \
pyramid_prod.h \
t_polynomial.h \
pyramid_prod.cpp \
fs_tensor.cpp \
sparse_tensor.h \
permutation.cpp \
equivalence.h \
gs_tensor.h \
normal_moments.h \
tl_static.h \
kron_prod.h \
fs_tensor.h \
stack_container.h \
rfs_tensor.cpp \
t_container.cpp \
tl_static.cpp
noinst_LIBRARIES = libtl.a
libtl_a_SOURCES = $(CWEBSRC) $(GENERATED_FILES)
libtl_a_SOURCES = \
equivalence.cc \
equivalence.hh \
fine_container.cc \
fine_container.hh \
fs_tensor.cc \
fs_tensor.hh \
gs_tensor.cc \
gs_tensor.hh \
int_sequence.cc \
int_sequence.hh \
kron_prod.cc \
kron_prod.hh \
normal_moments.cc \
normal_moments.hh \
permutation.cc \
permutation.hh \
ps_tensor.cc \
ps_tensor.hh \
pyramid_prod.cc \
pyramid_prod.hh \
pyramid_prod2.cc \
pyramid_prod2.hh \
rfs_tensor.cc \
rfs_tensor.hh \
sparse_tensor.cc \
sparse_tensor.hh \
stack_container.cc \
stack_container.hh \
sthread.cc \
sthread.hh \
symmetry.cc \
symmetry.hh \
t_container.cc \
t_container.hh \
t_polynomial.cc \
t_polynomial.hh \
tensor.cc \
tensor.hh \
tl_exception.hh \
tl_static.cc \
tl_static.hh \
twod_matrix.cc \
twod_matrix.hh
libtl_a_CPPFLAGS = -I../../sylv/cc $(CPPFLAGS_MATIO)
libtl_a_CXXFLAGS = $(AM_CXXFLAGS) $(PTHREAD_CFLAGS)
BUILT_SOURCES = $(GENERATED_FILES)
EXTRA_DIST = main.web dummy.ch
%.cpp: %.cweb dummy.ch
$(CTANGLE) -bhp $< dummy.ch $@
%.h: %.hweb dummy.ch
$(CTANGLE) -bhp $< dummy.ch $@
if HAVE_CWEAVE
if HAVE_PDFTEX
if HAVE_EPLAIN
pdf-local: tl.pdf
tl.pdf: main.web $(CWEBSRC)
$(CWEAVE) -bhp main.web
$(PDFTEX) main
mv main.pdf tl.pdf
endif
endif
endif
CLEANFILES = tl.pdf main.idx main.log main.scn main.tex main.toc
// Copyright 2004, Ondra Kamenik
#include "equivalence.hh"
#include "permutation.hh"
#include "tl_exception.hh"
#include <cstring>
int
OrdSequence::operator[](int i) const
{
TL_RAISE_IF((i < 0 || i >= length()),
"Index out of range in OrdSequence::operator[]");
return data[i];
}
/* Here we implement the ordering. It can be changed, or various
orderings can be used for different problem sizes. We order them
according to the average, and then according to the first item. */
bool
OrdSequence::operator<(const OrdSequence &s) const
{
double ta = average();
double sa = s.average();
return (ta < sa || ((ta == sa) && (operator[](0) > s[0])));
}
bool
OrdSequence::operator==(const OrdSequence &s) const
{
if (length() != s.length())
return false;
int i = 0;
while (i < length() && operator[](i) == s[i])
i++;
return (i == length());
}
/* The first |add| adds a given integer to the class, the second
iterates through a given sequence and adds everything found in the
given class. */
void
OrdSequence::add(int i)
{
vector<int>::iterator vit = data.begin();
while (vit != data.end() && *vit < i)
++vit;
if (vit != data.end() && *vit == i)
return;
data.insert(vit, i);
}
void
OrdSequence::add(const OrdSequence &s)
{
vector<int>::const_iterator vit = s.data.begin();
while (vit != s.data.end())
{
add(*vit);
++vit;
}
}
/* Answers |true| if a given number is in the class. */
bool
OrdSequence::has(int i) const
{
vector<int>::const_iterator vit = data.begin();
while (vit != data.end())
{
if (*vit == i)
return true;
++vit;
}
return false;
}
/* Return an average of the class. */
double
OrdSequence::average() const
{
double res = 0;
for (unsigned int i = 0; i < data.size(); i++)
res += data[i];
TL_RAISE_IF(data.size() == 0,
"Attempt to take average of empty class in OrdSequence::average");
return res/data.size();
}
/* Debug print. */
void
OrdSequence::print(const char *prefix) const
{
printf("%s", prefix);
for (unsigned int i = 0; i < data.size(); i++)
printf("%d ", data[i]);
printf("\n");
}
Equivalence::Equivalence(int num)
: n(num)
{
for (int i = 0; i < num; i++)
{
OrdSequence s;
s.add(i);
classes.push_back(s);
}
}
Equivalence::Equivalence(int num, const char *dummy)
: n(num)
{
OrdSequence s;
for (int i = 0; i < num; i++)
s.add(i);
classes.push_back(s);
}
/* Copy constructors. The second also glues a given couple. */
Equivalence::Equivalence(const Equivalence &e)
: n(e.n),
classes(e.classes)
{
}
Equivalence::Equivalence(const Equivalence &e, int i1, int i2)
: n(e.n),
classes(e.classes)
{
seqit s1 = find(i1);
seqit s2 = find(i2);
if (s1 != s2)
{
OrdSequence ns(*s1);
ns.add(*s2);
classes.erase(s1);
classes.erase(s2);
insert(ns);
}
}
const Equivalence &
Equivalence::operator=(const Equivalence &e)
{
classes.clear();
n = e.n;
classes = e.classes;
return *this;
}
bool
Equivalence::operator==(const Equivalence &e) const
{
if (!std::operator==(classes, e.classes))
return false;
if (n != e.n)
return false;
return true;
}
/* Return an iterator pointing to a class having a given integer. */
Equivalence::const_seqit
Equivalence::findHaving(int i) const
{
const_seqit si = classes.begin();
while (si != classes.end())
{
if ((*si).has(i))
return si;
++si;
}
TL_RAISE_IF(si == classes.end(),
"Couldn't find equivalence class in Equivalence::findHaving");
return si;
}
Equivalence::seqit
Equivalence::findHaving(int i)
{
seqit si = classes.begin();
while (si != classes.end())
{
if ((*si).has(i))
return si;
++si;
}
TL_RAISE_IF(si == classes.end(),
"Couldn't find equivalence class in Equivalence::findHaving");
return si;
}
/* Find $j$-th class for a given $j$. */
Equivalence::const_seqit
Equivalence::find(int j) const
{
const_seqit si = classes.begin();
int i = 0;
while (si != classes.end() && i < j)
{
++si;
i++;
}
TL_RAISE_IF(si == classes.end(),
"Couldn't find equivalence class in Equivalence::find");
return si;
}
Equivalence::seqit
Equivalence::find(int j)
{
seqit si = classes.begin();
int i = 0;
while (si != classes.end() && i < j)
{
++si;
i++;
}
TL_RAISE_IF(si == classes.end(),
"Couldn't find equivalence class in Equivalence::find");
return si;
}
/* Insert a new class yielding the ordering. */