MCPcopy Create free account
hub / github.com/davisking/dlib / to_tensor

Method to_tensor

dlib/dnn/input.h:1096–1133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1094
1095 template<typename forward_iterator>
1096 void to_tensor(
1097 forward_iterator ibegin,
1098 forward_iterator iend,
1099 resizable_tensor& data
1100 ) const
1101 {
1102 DLIB_CASSERT(std::distance(ibegin, iend) > 0);
1103 const auto k = ibegin->k();
1104 const auto nr = ibegin->nr();
1105 const auto nc = ibegin->nc();
1106 // make sure all the input tensors have the same dimensions
1107 for (auto i = ibegin; i != iend; ++i)
1108 {
1109 DLIB_CASSERT(i->k() == k && i->nr() == nr && i->nc() == nc,
1110 "\t input_tensor::to_tensor()"
1111 << "\n\t All tensor objects given to to_tensor() must have the same dimensions."
1112 << "\n\t k: " << k
1113 << "\n\t nr: " << nr
1114 << "\n\t nc: " << nc
1115 << "\n\t i->k(): " << i->k()
1116 << "\n\t i->nr(): " << i->nr()
1117 << "\n\t i->nc(): " << i->nc()
1118 );
1119 }
1120
1121 const auto num_samples = count_samples(ibegin, iend);
1122 // initialize data to the right size to contain the stuff in the iterator range.
1123 data.set_size(num_samples, k, nr, nc);
1124
1125 const size_t stride = k * nr * nc;
1126 size_t offset = 0;
1127 for (auto i = ibegin; i != iend; ++i)
1128 {
1129 alias_tensor slice(i->num_samples(), k, nr, nc);
1130 memcpy(slice(data, offset), *i);
1131 offset += slice.num_samples() * stride;
1132 }
1133 }
1134
1135 friend void serialize(const input_tensor&, std::ostream& out)
1136 {

Callers

nothing calls this directly

Calls 8

sliceClass · 0.85
distanceFunction · 0.50
memcpyFunction · 0.50
kMethod · 0.45
nrMethod · 0.45
ncMethod · 0.45
set_sizeMethod · 0.45
num_samplesMethod · 0.45

Tested by

no test coverage detected