bayes.h 883 Bytes
Newer Older
1
2
3
#ifndef _SPEL_MARKER_OBS_BAYES_H_
#define _SPEL_MARKER_OBS_BAYES_H_

Damien Leroux's avatar
Damien Leroux committed
4
#include "error.h"
5
#include "generation_rs_fwd.h"
Damien Leroux's avatar
Damien Leroux committed
6
/*#include "bayes/graph.h"*/
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

static inline
size_t idx_to_ofs(const std::vector<size_t>& dim, const std::vector<size_t>& idx)
{
    size_t accum = 0;
    size_t stride = 1;
    if (dim.size() != idx.size()) { throw 0; }
    for (int i = dim.size() - 1; i >= 0; --i) {
        if (idx[i] >= dim[i]) { throw 1; }
        accum += stride * idx[i];
        stride *= dim[i];
    }
#if 0
    std::cout << "idx_to_ofs";
    for (int i = 0; i < dim.size(); ++i) {
        std::cout << ' ' << idx[i] << "[" << dim[i] << ']';
    }
    std::cout << " => " << accum << std::endl;
#endif
    return accum;
}


static inline
size_t size(const std::vector<size_t>& dim) {
    size_t stride = 1;
    for (auto d: dim) {
        stride *= d;
    }
    return stride;
}


#endif