local_context.cpp
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "local_context.h"
#include <cmath>
using namespace Poincare;
namespace Sequence {
template<typename T>
LocalContext<T>::LocalContext(Context * parentContext) :
VariableContext<T>('n', parentContext),
m_values{{Complex<T>::Float(NAN), Complex<T>::Float(NAN)},
{Complex<T>::Float(NAN), Complex<T>::Float(NAN)}}
{
}
template<typename T>
const Expression * LocalContext<T>::expressionForSymbol(const Symbol * symbol) {
if (symbol->name() == Symbol::SpecialSymbols::un || symbol->name() == Symbol::SpecialSymbols::un1 ||
symbol->name() == Symbol::SpecialSymbols::vn || symbol->name() == Symbol::SpecialSymbols::vn1 ||
symbol->name() == Symbol::SpecialSymbols::wn || symbol->name() == Symbol::SpecialSymbols::wn1) {
return &m_values[nameIndexForSymbol(symbol)][rankIndexForSymbol(symbol)];
}
return VariableContext<T>::expressionForSymbol(symbol);
}
template<typename T>
void LocalContext<T>::setValueForSequenceRank(T value, const char * sequenceName, int rank) {
for (int i = 0; i < SequenceStore::k_maxNumberOfSequences; i++) {
if (strcmp(sequenceName, SequenceStore::k_sequenceNames[i]) == 0) {
m_values[i][rank] = Complex<T>::Float(value);
}
}
}
template<typename T>
int LocalContext<T>::nameIndexForSymbol(const Poincare::Symbol * symbol) {
switch (symbol->name()) {
case Symbol::SpecialSymbols::un:
return 0;
case Symbol::SpecialSymbols::un1:
return 0;
case Symbol::SpecialSymbols::vn:
return 1;
case Symbol::SpecialSymbols::vn1:
return 1;
case Symbol::SpecialSymbols::wn:
return 2;
case Symbol::SpecialSymbols::wn1:
return 2;
default:
return 0;
}
}
template<typename T>
int LocalContext<T>::rankIndexForSymbol(const Poincare::Symbol * symbol) {
switch (symbol->name()) {
case Symbol::SpecialSymbols::un:
return 0;
case Symbol::SpecialSymbols::un1:
return 1;
case Symbol::SpecialSymbols::vn:
return 0;
case Symbol::SpecialSymbols::vn1:
return 1;
case Symbol::SpecialSymbols::wn:
return 0;
case Symbol::SpecialSymbols::wn1:
return 1;
default:
return 0;
}
}
template class LocalContext<float>;
template class LocalContext<double>;
}