"...git@developer.sourcefind.cn:OpenDAS/ollama.git" did not exist on "0ce8bcfdaa4ddb58ba1c46c4e9fed1faec315bd6"
conv.cpp 718 Bytes
Newer Older
Chao Liu's avatar
Chao Liu committed
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
#include "tensor.hpp"

int main()
{

    int len_in  = 100;
    int len_wei = 3;
    int len_out = len_in - len_wei + 1;

    std::vector<float> in(len_in, 1);
    std::vector<float> wei(len_wei, 1);
    std::vector<float> out(len_out, 1);

    direct_convolution(in.data(), wei.data(), out.data(), len_in, len_wei);
}

template <typename T>
void direct_convolution(const T* in, const T* wei, T* out, const int len_in, const int len_wei)
{
    int len_out = len_in - len_wei + 1;

    for(int i_out = 0; i_out < len_out++ i_out)
    {
        double acc = 0;
        for(int i_wei = 0; i_wei < len_wei; ++i_wei)
        {
            acc += in[i_out + i_wei] * *wei[i_wei];
        }
        out[i_out] = acc;
    }
}