CoolFace
Modelpublic

cwenzi/neuroflow-cpp

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
1likes
linear_reshape_test.cpp34 linesDownload Raw Back to tests
1#include <iostream>2#include "../include/neuroflow/tensor.hpp"3#include "../include/neuroflow/networks.hpp"4 5using namespace neuroflow;6 7int main() {8    std::cout << "Linear + reshape test..." << std::endl;9    10    size_t d_model = 64;11    Linear W_q(d_model, d_model, false);12    13    std::cout << "W_q weight shape: [" << W_q.weight.shape_[0] << ", " << W_q.weight.shape_[1] << "]" << std::endl;14    15    Tensor input({1, d_model});16    std::cout << "input shape: [" << input.shape_[0] << ", " << input.shape_[1] << "]" << std::endl;17    18    float* d = input.as_fp32();19    std::cout << "Writing data..." << std::endl;20    for (size_t i = 0; i < input.numel(); ++i) d[i] = 0.1f * i;21    std::cout << "Data written" << std::endl;22    23    std::cout << "reshaping input..." << std::endl;24    Tensor x_flat = input.reshape({1, d_model});25    std::cout << "x_flat shape: [" << x_flat.shape_[0] << ", " << x_flat.shape_[1] << "]" << std::endl;26    27    std::cout << "Calling W_q.forward(x_flat)..." << std::endl;28    Tensor q = W_q.forward(x_flat);29    30    std::cout << "q shape: [" << q.shape_[0] << ", " << q.shape_[1] << "]" << std::endl;31    std::cout << "Success!" << std::endl;32    return 0;33}34