CoolFace
Modelpublic

cwenzi/neuroflow-cpp

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
1likes
norm_test.cpp31 linesDownload Raw Back to tests
1#include <iostream>2#include "../include/neuroflow/tensor.hpp"3 4using namespace neuroflow;5 6int main() {7    std::cout << "LayerNorm test..." << std::endl;8    9    Tensor x({2, 32});10    Tensor weight({32});11    Tensor bias({32});12    13    float* xd = x.as_fp32();14    float* wd = weight.as_fp32();15    float* bd = bias.as_fp32();16    17    for (size_t i = 0; i < x.numel(); ++i) xd[i] = 0.1f * i;18    for (size_t i = 0; i < 32; ++i) wd[i] = 1.0f;19    for (size_t i = 0; i < 32; ++i) bd[i] = 0.0f;20    21    std::cout << "x shape: [" << x.shape_[0] << ", " << x.shape_[1] << "]" << std::endl;22    std::cout << "x numel: " << x.numel() << std::endl;23    std::cout << "x data_size: " << x.data_size_ << std::endl;24    25    std::cout << "Calling layer_norm..." << std::endl;26    TensorOps::layer_norm(x, weight, bias);27    28    std::cout << "Success!" << std::endl;29    return 0;30}31