fml  0.1-0
Fused Matrix Library
copy.hh
1 // This file is part of fml which is released under the Boost Software
2 // License, Version 1.0. See accompanying file LICENSE or copy at
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #ifndef FML_CPU_COPY_H
6 #define FML_CPU_COPY_H
7 #pragma once
8 
9 
10 #include <stdexcept>
11 
12 #include "../_internals/arraytools/src/arraytools.hpp"
13 
14 #include "cpumat.hh"
15 #include "cpuvec.hh"
16 
17 
18 namespace fml
19 {
21 namespace copy
22 {
39  template <typename REAL_IN, typename REAL_OUT>
40  void cpu2cpu(const cpuvec<REAL_IN> &cpu_in, cpuvec<REAL_OUT> &cpu_out)
41  {
42  cpu_out.resize(cpu_in.size());
43 
44  arraytools::copy(cpu_in.size(), cpu_in.data_ptr(), cpu_out.data_ptr());
45  }
46 
48  template <typename REAL>
50  {
51  cpuvec<REAL> cpu_out;
52  cpu2cpu(cpu_in, cpu_out);
53 
54  return cpu_out;
55  }
56 
58  template <typename REAL_IN, typename REAL_OUT>
59  void cpu2cpu(const cpumat<REAL_IN> &cpu_in, cpumat<REAL_OUT> &cpu_out)
60  {
61  cpu_out.resize(cpu_in.nrows(), cpu_in.ncols());
62 
63  size_t len = (size_t) cpu_in.nrows() * cpu_in.ncols();
64  arraytools::copy(len, cpu_in.data_ptr(), cpu_out.data_ptr());
65  }
66 
68  template <typename REAL>
70  {
71  cpumat<REAL> cpu_out;
72  cpu2cpu(cpu_in, cpu_out);
73 
74  return cpu_out;
75  }
76 }
77 }
78 
79 
80 #endif
fml::cpumat
Matrix class for data held on a single CPU.
Definition: cpumat.hh:36
fml::copy::cpu2cpu
void cpu2cpu(const cpuvec< REAL_IN > &cpu_in, cpuvec< REAL_OUT > &cpu_out)
Copy data from a CPU object to another.
Definition: copy.hh:40
fml::univec::data_ptr
T * data_ptr()
Pointer to the internal array.
Definition: univec.hh:28
fml::unimat::nrows
len_t nrows() const
Number of rows.
Definition: unimat.hh:36
fml::cpuvec::resize
void resize(len_t size)
Resize the internal object storage.
Definition: cpuvec.hh:210
fml::cpumat::resize
void resize(len_t nrows, len_t ncols)
Resize the internal object storage.
Definition: cpumat.hh:233
fml::cpuvec
Vector class for data held on a single CPU.
Definition: cpuvec.hh:31
fml::unimat::ncols
len_t ncols() const
Number of columns.
Definition: unimat.hh:38
fml::unimat::data_ptr
REAL * data_ptr()
Pointer to the internal array.
Definition: unimat.hh:40
fml
Core namespace.
Definition: dimops.hh:10
fml::univec::size
len_t size() const
Number of elements in the vector.
Definition: univec.hh:26