#pragma once #include #include // You can modify the data structure as you want struct Tensor { // Alloc memory Tensor(std::vector shape_) { ndim = shape_.size(); for (int i = 0; i < ndim; i++) { shape[i] = shape_[i]; } int n = num_elem(); buf = (float*)malloc(n * sizeof(float)); } // Alloc memory and copy Tensor(std::vector shape_, float *buf_) { ndim = shape_.size(); for (int i = 0; i < ndim; i++) { shape[i] = shape_[i]; } int n = num_elem(); buf = (float*)malloc(n * sizeof(float)); for (int i=0; i shape = {2, 3} int ndim = 0; int shape[4]; };