MCPcopy Create free account
hub / github.com/ai-techsystems/deepC / to_string

Method to_string

include/core/tensor.h:316–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314#endif
315
316 std::string to_string(const size_t max_el = DNNC_TENSOR_MAX_EL) const {
317 std::string str = this->name().size() ? this->name() + "=" : "";
318 if (this->rank() == 0) {
319 str += "null tensor";
320 } else if (this->rank() == 1 && this->length() == 1) {
321 str += std::to_string(_mem_layout[0]);
322 } else if (this->rank() == 1) {
323 str += "[";
324 size_t i = 0;
325 for (i = 0; i < this->length() && i < max_el; i++)
326 str += (i ? " " : "") + std::to_string(_mem_layout[i]);
327 str += i == max_el ? "...]" : "]";
328 } else if (this->rank() == 2) {
329 str += "[";
330 size_t i = 0;
331 for (i = 0; i < this->shape()[0] && i < max_el; i++) {
332 str += i ? "\n [" : "[";
333 size_t j = 0;
334 for (j = 0; j < this->shape()[1] && j < max_el; j++) {
335 size_t index = i * this->shape()[1] + j;
336 str += (j ? " " : "") + std::to_string(_mem_layout[index]);
337 }
338 str += (j == max_el ? "...]" : "]");
339 }
340 str += i == max_el ? "...]" : "]";
341 } else if (this->rank() == 3) {
342 str += "[";
343 size_t i = 0;
344 for (i = 0; i < this->shape()[0] && i < max_el; i++) {
345 str += i ? "\n [" : "[";
346 size_t j = 0;
347 for (j = 0; j < this->shape()[1] && j < max_el; j++) {
348 str += j ? "\n [" : "[";
349 size_t k = 0;
350 for (k = 0; k < this->shape()[2] && k < max_el; k++) {
351 size_t index = i * this->shape()[1] * this->shape()[2] +
352 j * this->shape()[2] + k;
353 str += (k ? " " : "") + std::to_string(_mem_layout[index]);
354 }
355 str += k == max_el ? "...]" : "]";
356 }
357 str += j == max_el ? "...]" : "]";
358 }
359 str += i == max_el ? "...]" : "]";
360 } else if (this->rank() == 4) {
361 str += "[";
362 size_t i = 0;
363 for (i = 0; i < this->shape()[0] && i < max_el; i++) {
364 str += i ? "\n [" : "[";
365 size_t j = 0;
366 for (j = 0; j < this->shape()[1] && j < max_el; j++) {
367 str += j ? "\n [" : "[";
368 size_t k = 0;
369 for (k = 0; k < this->shape()[2] && k < max_el; k++) {
370 str += k ? "\n [" : "[";
371 size_t l = 0;
372 for (l = 0; l < this->shape()[3] && l < max_el; l++) {
373 size_t index =

Callers 1

tensorClass · 0.45

Calls 5

sizeMethod · 0.45
nameMethod · 0.45
rankMethod · 0.45
lengthMethod · 0.45
shapeMethod · 0.45

Tested by

no test coverage detected