cwenzi/neuroflow-cpp
1
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 << "LayerNorm class test..." << std::endl;9 10 // Create LayerNorm11 std::cout << "Creating LayerNorm(32)..." << std::endl;12 LayerNorm norm(32);13 14 std::cout << "weight shape size: " << norm.weight.shape_.size() << std::endl;15 std::cout << "weight shape[0]: " << norm.weight.shape_[0] << std::endl;16 std::cout << "weight numel: " << norm.weight.numel() << std::endl;17 std::cout << "weight data_size: " << norm.weight.data_size_ << std::endl;18 19 std::cout << "bias shape size: " << norm.bias.shape_.size() << std::endl;20 std::cout << "bias shape[0]: " << norm.bias.shape_[0] << std::endl;21 std::cout << "bias numel: " << norm.bias.numel() << std::endl;22 std::cout << "bias data_size: " << norm.bias.data_size_ << std::endl;23 24 // Create input25 Tensor input({2, 32});26 float* id = input.as_fp32();27 for (size_t i = 0; i < input.numel(); ++i) id[i] = 0.1f * i;28 29 std::cout << "Calling norm.forward(input)..." << std::endl;30 Tensor output = norm.forward(input);31 32 std::cout << "output shape: [" << output.shape_[0] << ", " << output.shape_[1] << "]" << std::endl;33 34 std::cout << "Success!" << std::endl;35 return 0;36}37 