@@ -53,10 +53,10 @@ void destroy(Tensor* t);
5353// -----------------------------------------------------------------------------
5454
5555template <TDtype src, TDtype des>
56- Tensor cast_to (void * data, size_t len) {
56+ Tensor cast_to (const void * data, size_t len) {
5757 using d_src = to_device_t <src>;
5858 using d_des = to_device_t <des>;
59- auto c_data = reinterpret_cast <d_src*>(data);
59+ auto c_data = reinterpret_cast <const d_src*>(data);
6060 auto out = cpu::init<des>(len);
6161 auto c_out = reinterpret_cast <d_des*>(out.data );
6262 auto caster = cast_value<to_device_t <src>, to_device_t <des>>();
@@ -71,13 +71,13 @@ Tensor cast_to(const Tensor& t, TDtype des);
7171// -----------------------------------------------------------------------------
7272
7373template <TDtype dtype>
74- std::string to_string (void * data, size_t dim, bool simplify = false ) {
74+ std::string to_string (const void * data, size_t dim, bool simplify = false ) {
7575 std::string out = " " ;
7676 if (!simplify) {
7777 out = " array(dtype: " + dtype_to_string (dtype) + " , device: " + device_to_string (TDevice::CPU) + " , data: [" ;
7878 }
7979 using calc_t = to_device_t <dtype>;
80- calc_t * data_ = reinterpret_cast <calc_t *>(data);
80+ const calc_t * data_ = reinterpret_cast <const calc_t *>(data);
8181 for (size_t i = 0 ; i < dim; i++) {
8282 if constexpr (is_complex_v<calc_t >) {
8383 out += " (" + std::to_string (data_[i].real ()) + " , " + std::to_string (data_[i].imag ()) + " )" ;
@@ -118,7 +118,7 @@ Tensor init_with_vector(const std::vector<T>& a) {
118118// -----------------------------------------------------------------------------
119119
120120template <TDtype dtype>
121- Tensor copy (void * data, size_t len) {
121+ Tensor copy (const void * data, size_t len) {
122122 using calc_t = to_device_t <dtype>;
123123 auto out = init<dtype>(len);
124124 mindquantum::safe_copy (out.data , sizeof (calc_t ) * len, data, sizeof (calc_t ) * len);
@@ -128,7 +128,7 @@ Tensor copy(void* data, size_t len) {
128128Tensor copy (const Tensor& t);
129129
130130template <TDtype dtype>
131- void * copy_mem (void * data, size_t len) {
131+ void * copy_mem (const void * data, size_t len) {
132132 using calc_t = to_device_t <dtype>;
133133 auto res = reinterpret_cast <void *>(malloc (sizeof (calc_t ) * len));
134134 if (res == nullptr ) {
@@ -137,7 +137,7 @@ void* copy_mem(void* data, size_t len) {
137137 mindquantum::safe_copy (res, sizeof (calc_t ) * len, data, sizeof (calc_t ) * len);
138138 return res;
139139}
140- void * copy_mem (void * data, TDtype dtype, size_t len);
140+ void * copy_mem (const void * data, TDtype dtype, size_t len);
141141
142142// -----------------------------------------------------------------------------
143143template <typename src, typename T>
@@ -185,8 +185,8 @@ Tensor get(const Tensor& t, size_t idx);
185185// -----------------------------------------------------------------------------
186186
187187template <TDtype src_dtype>
188- std::vector<to_device_t <src_dtype>> to_vector (void * data, size_t len) {
189- auto c_data = reinterpret_cast <to_device_t <src_dtype>*>(data);
188+ std::vector<to_device_t <src_dtype>> to_vector (const void * data, size_t len) {
189+ auto c_data = reinterpret_cast <const to_device_t <src_dtype>*>(data);
190190 std::vector<to_device_t <src_dtype>> out;
191191 for (size_t i = 0 ; i < len; i++) {
192192 out.push_back (c_data[i]);
@@ -204,8 +204,8 @@ std::vector<T> to_vector(const Tensor& ori) {
204204}
205205
206206template <TDtype src_dtype>
207- std::vector<std::vector<to_device_t <src_dtype>>> to_vector (void * data, size_t n_row, size_t n_col) {
208- auto c_data = reinterpret_cast <to_device_t <src_dtype>*>(data);
207+ std::vector<std::vector<to_device_t <src_dtype>>> to_vector (const void * data, size_t n_row, size_t n_col) {
208+ auto c_data = reinterpret_cast <const to_device_t <src_dtype>*>(data);
209209 std::vector<std::vector<to_device_t <src_dtype>>> out;
210210 for (size_t i = 0 ; i < n_row; i++) {
211211 std::vector<to_device_t <src_dtype>> tmp;
0 commit comments