2 void copy(
const Tensor_Base<Xpr>& rv) {
3 static_assert(ExpressionTemplate::tensor_iterator_dim <= 1,
"copy only accepts continuous");
4 static_assert(Xpr::tensor_iterator_dim <= 1,
"copy only accepts continuous");
6 if (this->size() != rv.size()) {
7 bc::printerr(
"Attempting to copy two different size tensors (ERROR)");
13 using same_system = std::is_same<system_tag, typename Xpr::system_tag>;
14 if (std::is_same<system_tag, typename Xpr::system_tag>::value) {
16 bc::traits::constexpr_if<same_system::value>(
20 }
else if (std::is_same<system_tag, device_tag>::value) {
21 copy_impl::HostToDevice(this->data(),
25 copy_impl::DeviceToHost(this->data(),
37 bool sparse=
false)
const 39 using traits = exprs::expression_traits<ExpressionTemplate>;
40 using is_host = std::is_same<bc::host_tag, system_tag>;
43 using allocator_type = std::conditional_t<
48 using allocator_type = bc::Allocator<value_type, system_tag>;
50 using tensor_type = Tensor_Base<exprs::Array<
55 using host_tensor_type = Tensor_Base<exprs::Array<
56 bc::Shape<tensor_dim>,
63 constexpr
bool is_array = traits::is_array::value;
64 constexpr
bool no_copy_required =
65 is_host::value && is_array;
67 static constexpr
bool is_continuous = traits::is_continuous::value;
69 return bc::traits::constexpr_if<no_copy_required>(
74 bc::traits::constexpr_else_if<is_continuous && is_array>(
77 host_tensor_type tensor(der.get_shape());
84 tensor_type
copy(der);
92 return this->
to_string(precision,
false,
false);
95 void print(
int precision=8,
bool pretty=
true,
bool sparse=
false)
const {
96 std::cout << this->
to_string(precision, pretty, sparse) << std::endl;
100 std::cout << this->
to_string(precision, pretty,
true) << std::endl;
103 void raw_print(
int precision=0,
bool sparse=
false)
const {
104 std::cout << this->
to_string(precision,
false, sparse) << std::endl;
108 for (
int i = 0; i < tensor_dim; ++i) {
109 std::cout <<
"[" << this->
dim(i) <<
"]";
111 std::cout << std::endl;
115 for (
int i = 0; i < tensor_dim; ++i) {
116 std::cout <<
"[" << this->leading_dim(i) <<
"]";
118 std::cout << std::endl;
123 const Tensor_Base&
self) {
124 return os <<
self.to_string();
friend std::ostream & operator<<(std::ostream &os, const Tensor_Base &self)
Definition: tensor_utility.h:121
Bind< Function, Args &&... > bind(Function function, Args &&... args)
Definition: bind.h:105
void print_sparse(int precision=8, bool pretty=true) const
Definition: tensor_utility.h:99
std::string to_raw_string(int precision=8) const
Definition: tensor_utility.h:91
Definition: constexpr_int.h:14
auto constexpr_else(Function function)
Definition: constexpr_if.h:61
std::string to_string(const Tensor &tensor, features f, bc::traits::Integer< 2 >)
Definition: print.h:78
void device_sync()
Definition: stream_synchronization.h:20
BCINLINE auto dim(const Integers &... ints)
Definition: dim.h:336
std::string to_string(int precision=8, bool pretty=true, bool sparse=false) const
Definition: tensor_utility.h:34
void print(int precision=8, bool pretty=true, bool sparse=false) const
Definition: tensor_utility.h:95
void print_leading_dims() const
Definition: tensor_utility.h:114
Definition: filesystem.h:11
Definition: allocators.h:20
void print_dims() const
Definition: tensor_utility.h:107
void printerr(const Ts &... args)
Definition: common.h:170
void raw_print(int precision=0, bool sparse=false) const
Definition: tensor_utility.h:103
void copy(const Tensor_Base< Xpr > &rv)
Definition: tensor_utility.h:2
Definition: basic_allocators.h:104