File size: 1,201 Bytes
26d5b81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include <iostream>
#include "../include/neuroflow/tensor.hpp"
#include "../include/neuroflow/networks.hpp"

using namespace neuroflow;

int main() {
    std::cout << "Linear + reshape test..." << std::endl;
    
    size_t d_model = 64;
    Linear W_q(d_model, d_model, false);
    
    std::cout << "W_q weight shape: [" << W_q.weight.shape_[0] << ", " << W_q.weight.shape_[1] << "]" << std::endl;
    
    Tensor input({1, d_model});
    std::cout << "input shape: [" << input.shape_[0] << ", " << input.shape_[1] << "]" << std::endl;
    
    float* d = input.as_fp32();
    std::cout << "Writing data..." << std::endl;
    for (size_t i = 0; i < input.numel(); ++i) d[i] = 0.1f * i;
    std::cout << "Data written" << std::endl;
    
    std::cout << "reshaping input..." << std::endl;
    Tensor x_flat = input.reshape({1, d_model});
    std::cout << "x_flat shape: [" << x_flat.shape_[0] << ", " << x_flat.shape_[1] << "]" << std::endl;
    
    std::cout << "Calling W_q.forward(x_flat)..." << std::endl;
    Tensor q = W_q.forward(x_flat);
    
    std::cout << "q shape: [" << q.shape_[0] << ", " << q.shape_[1] << "]" << std::endl;
    std::cout << "Success!" << std::endl;
    return 0;
}