14
14
15
15
namespace k2 {
16
16
17
-
18
17
/*
19
- We will use e.g. StridedPtr<int32_t, T> when the stride is not 1, and otherwise
20
- just T* (which presumably be faster).
18
+ We will use e.g. StridedPtr<int32_t, T> when the stride is not 1, and
19
+ otherwise just T* (which presumably be faster).
21
20
*/
22
21
template <typename I, typename T>
23
- class StridedPtr {
22
+ struct StridedPtr {
24
23
T *data;
25
24
I stride;
26
- T &operator [] (I i) { return data[i]; }
27
- StridedPtr (T *data, I stride): data(data), stride(stride) { }
25
+ T &operator [] (I i) { return data[i]; }
26
+ StridedPtr (T *data, I stride) : data(data), stride(stride) {}
28
27
};
29
28
30
-
31
-
32
29
/* MIGHT NOT NEED THIS */
33
30
template <typename I, typename Ptr >
34
31
struct Array1 {
@@ -37,23 +34,20 @@ struct Array1 {
37
34
using IndexT = I;
38
35
using PtrT = Ptr ;
39
36
40
-
41
37
// 'begin' and 'end' are the first and one-past-the-last indexes into `data`
42
38
// that we are allowed to use.
43
39
IndexT begin;
44
40
IndexT end;
45
41
46
42
PtrT data;
47
-
48
-
49
43
};
50
44
51
-
52
45
/*
53
46
This struct stores the size of an Array2 object; it will generally be used as
54
47
an output argument by functions that work out this size.
55
48
*/
56
- template <typename I> struct Array2Size {
49
+ template <typename I>
50
+ struct Array2Size {
57
51
using IndexT = I;
58
52
// `size1` is the top-level size of the array, equal to the object's .size
59
53
// element
@@ -62,8 +56,7 @@ template <typename I> struct Array2Size {
62
56
// o->indexes[o->size] - o->indexes[0] (if the Array2 object o is
63
57
// initialized).
64
58
I size2;
65
- }
66
-
59
+ };
67
60
68
61
template <typename I, typename Ptr >
69
62
struct Array2 {
@@ -79,113 +72,50 @@ struct Array2 {
79
72
// not required that indexes[0] == 0, it may be
80
73
// greater than 0.
81
74
82
- PtrT data; // `data` might be an actual pointer, or might be some object
83
- // supporting operator []. data[indexes[0]] through
84
- // data[indexes[size] - 1] must be accessible through this
85
- // object.
75
+ PtrT data; // `data` might be an actual pointer, or might be some object
76
+ // supporting operator []. data[indexes[0]] through
77
+ // data[indexes[size] - 1] must be accessible through this
78
+ // object.
86
79
87
80
/* initialized definition:
88
81
89
82
An Array2 object is initialized if its `size` member is set and its
90
83
`indexes` and `data` pointer allocated, and the values of its `indexes`
91
84
array are set for indexes[0] and indexes[size].
92
85
*/
93
-
94
86
};
95
87
96
-
97
88
template <typename I, typename Ptr >
98
89
struct Array3 {
99
- using IndexT = I;
100
- using PtrT = Ptr ;
101
-
102
- // Irregular three dimensional array of something, like vector<vector<vetor<X> > >
103
- // where Ptr is or behaves like X*.
90
+ // Irregular three dimensional array of something, like vector<vector<vetor<X>
91
+ // > > where Ptr is or behaves like X*.
104
92
using IndexT = I;
105
93
using PtrT = Ptr ;
106
94
107
95
IndexT size;
108
- const IndexT *indexes1; // indexes1[0,1,...size] should be defined; note, this
109
- // means the array must be of at least size+1. We
110
- // require that indexes[i] <= indexes[i+1], but it is
111
- // not required that indexes[0] == 0, it may be
96
+ const IndexT *indexes1; // indexes1[0,1,...size] should be defined; note,
97
+ // this means the array must be of at least size+1.
98
+ // We require that indexes[i] <= indexes[i+1], but it
99
+ // is not required that indexes[0] == 0, it may be
112
100
// greater than 0.
113
101
114
102
const IndexT *indexes2; // indexes2[indexes1[0]]
115
103
// .. indexes2[indexes1[size]-1] should be defined.
116
104
117
- Ptr data; // `data` might be an actual pointer, or might be some object
118
- // supporting operator []. data[indexes[0]] through
119
- // data[indexes[size] - 1] must be accessible through this
120
- // object.
121
-
105
+ Ptr data; // `data` might be an actual pointer, or might be some object
106
+ // supporting operator []. data[indexes[0]] through
107
+ // data[indexes[size] - 1] must be accessible through this
108
+ // object.
122
109
123
- Array2 operator [] (I i) {
124
- // ...
110
+ Array2<I, Ptr > operator [](I i) {
111
+ // TODO(haowen): fill real data here
112
+ Array2<I, Ptr > array;
113
+ return array;
125
114
}
126
-
127
- };
128
-
129
-
130
-
131
-
132
-
133
-
134
- // we'd put the following in fsa.h
135
- using Cfsa = Array2<int32_t , Arc>;
136
- using CfsaVec = Array3<int32_t , Arc>;
137
-
138
-
139
-
140
-
141
- class FstInverter {
142
- /* Constructor. Lightweight. */
143
- FstInverter (const Fsa &fsa_in, const AuxLabels &labels_in);
144
-
145
- /*
146
- Do enough work that know now much memory will be needed, and output
147
- that information
148
- @param [out] fsa_size The num-states and num-arcs of the FSA
149
- will be written to here
150
- @param [out] aux_size The number of lists in the AuxLabels
151
- output (==num-arcs) and the number of
152
- elements will be written to here.
153
- */
154
- void GetSizes (Array2Size<int32_t > *fsa_size,
155
- Array2Size<int32_t > *aux_size);
156
-
157
- /*
158
- Finish the operation and output inverted FSA to `fsa_out` and
159
- auxiliary labels to `labels_out`.
160
- @param [out] fsa_out The inverted FSA will be written to
161
- here. Must be initialized; search for
162
- 'initialized definition' in class Array2
163
- in array.h for meaning.
164
- @param [out] labels_out The auxiliary labels will be written to
165
- here. Must be initialized; search for
166
- 'initialized definition' in class Array2
167
- in array.h for meaning.
168
- */
169
- void GetOutput (Fsa *fsa_out,
170
- AuxLabels *labels_out);
171
- private:
172
- // ...
173
115
};
174
116
175
117
// Note: we can create Array4 later if we need it.
176
118
177
-
178
- void InvertFst (const Fsa &fsa_in, const AuxLabels &labels_in, Fsa *fsa_out,
179
- AuxLabels *aux_labels_out) {
180
-
181
-
182
- /*
183
- void RmEpsilonsPrunedMax(const WfsaWithFbWeights &a, float beam, Fsa *b,
184
- std::vector<std::vector<int32_t>> *arc_derivs);
185
- */
186
-
187
-
188
-
189
119
} // namespace k2
190
120
191
121
#endif // K2_CSRC_ARRAY_H_
0 commit comments