From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/boost/libs/yap/example/autodiff_library/Tape.h | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/boost/libs/yap/example/autodiff_library/Tape.h (limited to 'src/boost/libs/yap/example/autodiff_library/Tape.h') diff --git a/src/boost/libs/yap/example/autodiff_library/Tape.h b/src/boost/libs/yap/example/autodiff_library/Tape.h new file mode 100644 index 000000000..9ca62c4df --- /dev/null +++ b/src/boost/libs/yap/example/autodiff_library/Tape.h @@ -0,0 +1,97 @@ +/* + * Tape.h + * + * Created on: 15 Apr 2013 + * Author: s0965328 + */ + +#ifndef TAPE_H_ +#define TAPE_H_ + +#include +#include +#include +#include +#include + + +namespace AutoDiff { + +using namespace std; +#define TT (Tape::valueTape) +#define II (Tape::indexTape) + +template class Tape { +public: + Tape () : index(0){}; + T& at(const unsigned int index); + const T& get(const unsigned int index); + void set(T& v); + unsigned int size(); + void clear(); + bool empty(); + string toString(); + virtual ~Tape(); + + vector vals; + unsigned int index; + + static Tape* valueTape; + static Tape* indexTape; +}; + + +template Tape::~Tape() +{ + index = 0; + vals.clear(); +} + +template T& Tape::at(const unsigned int i) +{ + assert(this->vals.size()>i); + return vals[i]; +} +template const T& Tape::get(const unsigned int i) +{ + assert(this->vals.size()>i); + return vals[i]; +} +template void Tape::set(T& v) +{ + vals.push_back(v); + index++; +} + +template unsigned int Tape::size() +{ + return this->vals.size(); +} + +template bool Tape::empty() +{ + return vals.empty(); +} + +template void Tape::clear() +{ + this->vals.clear(); + this->index = 0; + assert(this->vals.size()==0); + assert(this->vals.empty()); +} + +template string Tape::toString() +{ + assert(vals.size()>=index); + ostringstream oss; + oss<<"Tape size["<