//
// Created by Krad on 2023/4/6.
//

#include "Function.h"
#include <cstddef>

//必须在mkl.h和Eigen的头之前，<complex>之后
#define MKL_Complex8 std::complex<float>
#include "mkl.h"
#include <string.h>
#include <algorithm>

#include <Eigen/Core>
#include <Eigen/Eigen>
#include <Eigen/Dense>

#ifdef USE_CUDA
#include <cuda_runtime.h>
#endif

namespace Aurora {

    float *malloc(size_t size, bool complex) {
        if (!complex) return (float *) mkl_malloc(size * sizeof(float), 64);
        size_t complex_size = size * sizeof(std::complex<float>);
        return (float *) mkl_malloc(complex_size, 64);
    }

    void free(void* ptr){
        mkl_free(ptr);
    }
    float*  random(size_t length){
        VSLStreamStatePtr stream;
        vslNewStream(&stream, VSL_BRNG_MT19937, 1);
        float * ret =  new float[length];
        float low = -100.0;
        float high = 10000.0;
        vsRngUniform(VSL_RNG_METHOD_UNIFORM_STD, stream, length, ret, low, high);
        // 释放资源
        vslDeleteStream(&stream);
        return ret;
    }
#ifdef USE_CUDA
    void gpuFree(void* ptr)
    {
        cudaFree(ptr);
    }
#endif
}