本文整理汇总了C++中Tape类的典型用法代码示例。如果您正苦于以下问题:C++ Tape类的具体用法?C++ Tape怎么用?C++ Tape使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Tape
Tape* TapeManager::findTape( const QString & id )
{
/* 2002-01-26 LEW */
// printf("Contents of _tapeIDs: %d entries\n", _tapes.count());
// for ( QStringList::Iterator it = _tapeIDs.begin(); it != _tapeIDs.end(); ++it ) {
// printf("%s\n", (*it).latin1());
// }
// printf("\n");
// QDictIterator<Tape> it( _tapes );
// printf("Contents of _tapes: %d entries\n", _tapes.count());
// for( ; it.current(); ++it )
// printf("index ?: %s (%d)\n", it.current()->getName().latin1(),
// it.current()->getCTime());
// printf("\n");
/* 2002-01-26 LEW */
Tape* tape = _tapes[ id ];
if ( !tape ) {
tape = new Tape( id.ascii() );
_tapes.insert( tape->getID(), tape );
}
return tape;
}
示例2: measure
double measure(Tape& tape) {
uint64_t result(0);
timer t;
t.start();
std::accumulate(tape.begin(), tape.end(), result);
return t.stop();
}
示例3: Tape
Tape* TapeManager::findTape( const char* id )
{
Tape* tape = _tapes[ id ];
if ( !tape ) {
tape = new Tape( id );
_tapes.insert( tape->getID(), tape );
}
return tape;
}
示例4: run
void run() {
Tape tape;
for (int pc = 0; pc < code.length(); pc++) {
switch (code[pc]) {
case '+':
tape.inc();
break;
case '-':
tape.dec();
break;
case '>':
tape.advance();
break;
case '<':
tape.devance();
break;
case '[':
if (tape.get() == 0) pc = bracket_map[pc];
break;
case ']':
if (tape.get() != 0) pc = bracket_map[pc];
break;
case '.':
printf("%c", tape.get());
fflush(stdout);
break;
}
}
}
示例5: emplace_back
namespace graph {
thread_local bool _backprop_enabled = true;
thread_local Tape tape;
void emplace_back(std::function<void()>&& f) {
tape.backprop.emplace_back(f);
}
void backward() {
tape.backward();
}
void clear() {
tape.backprop.clear();
}
bool backprop_enabled() {
return _backprop_enabled;
}
void _set_backprop_enabled(bool value) {
_backprop_enabled = value;
}
size_t size() {
return tape.backprop.size();
}
/* Tape */
void Tape::backward () {
for (auto it = backprop.rbegin(); it != backprop.rend(); ++it)
(*it)();
backprop.clear();
}
/* NoBackprop */
NoBackprop::NoBackprop() : NoBackprop(true) {
}
NoBackprop::NoBackprop(bool condition) : old_value(_backprop_enabled), enabled(condition) {
if(enabled)
_backprop_enabled = false;
}
NoBackprop::~NoBackprop() {
if (enabled)
_backprop_enabled = old_value;
}
}
示例6: main
int main()
{
const int success(0);
Tape tape;
tape.Initialize("AABB");
try{
tape.Update('B','L');
}
catch(Crash &error)
{
cout << error.what() << ".\n";
}
catch (bad_alloc& error)
{
cout << "allocation error!\n";
}
catch(...)
{
cout << "Something went wrong!\n";
}
tape.View();
return success;
}
示例7: Run
void Run(Tape &tape, bool print_each_step = false)
{
if (print_each_step)
tape.PrintLine();
m_state = 0;
while (!m_state_final[m_state])
{
Rule23::iterator i = m_rules.find(m_state);
if (i == m_rules.end())
{
std::cerr << 'S' << m_state << " undefined.\n";
break;
}
char symbol_read = tape.Read();
Rule13 &rule13 = i->second;
Rule13::iterator j = rule13.find(symbol_read);
if (j == rule13.end())
{
std::cerr << "No rule for S" << m_state << " and '" << symbol_read << "'.\n";
break;
}
Rule03 &rule03 = j->second;
m_state = std::get<0>(rule03);
char symbol_write = std::get<1>(rule03);
tape.Write(symbol_write);
char direction = std::get<2>(rule03);
if (direction == 'L')
tape.MoveLeft();
else if (direction == 'R')
tape.MoveRight();
if (print_each_step)
tape.PrintLine();
}
}
示例8: gradient
/**
* @brief Get a reference to the actual gradient value of this instance.
* @return Reference to the gradient value.
*/
inline Real& gradient() {
return globalTape.gradient(gradientData);
}
示例9: calcGradient
inline void calcGradient(Data& data, const Real& jacobi) const {
globalTape.pushJacobi(data, jacobi, primalValue, gradientData);
}
示例10:
/**
* @brief Call the tape to destroy the gradient data.
*/
inline ~ActiveReal() {
globalTape.destroyGradientData(primalValue, gradientData);
}
示例11: ActiveReal
/**
* @brief Copy Constructor. The logic is handled by the tape.
*
* The tape is required to set the primal value of v to the primal value
* of this type.
*
* @param[in] v The value to copy.
*/
inline ActiveReal(const ActiveReal<Real, Tape>& v) {
globalTape.initGradientData(this->primalValue, gradientData);
globalTape.store(primalValue, gradientData, v);
}
示例12: getGradient
/**
* @brief Get the value of the gradient of this instance.
* @return The gradient value.
*/
inline Real getGradient() const {
return globalTape.getGradient(gradientData);
}
示例13: setGradient
/**
* @brief Set the value of the gradient of this instance.
* @param gradient The new gradient value.
*/
inline void setGradient(const Real& gradient) {
globalTape.setGradient(gradientData, gradient);
}
示例14: print_tape
inline void print_tape() {
if (tape_changed) {
for (int i=0; i<tape.size(); i++)
cout << tape[i];
cout << endl;
}
}
示例15: move_head
inline void move_head(char move) {
if (move == 'l')
pos -= 1;
else if (move == 'r')
pos += 1;
else
throw string("unknown state");
if (pos < 0) {
tape.insert(tape.begin(), init);
pos = 0;
}
if (pos >= tape.size()) {
tape.push_back(init);
}
moves++;
}