MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / printContext

Function printContext

test/arrayfire_test.cpp:1560–1662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1558
1559template<typename T>
1560std::string printContext(const std::vector<T> &hGold, std::string goldName,
1561 const std::vector<T> &hOut, std::string outName,
1562 af::dim4 arrDims, af::dim4 arrStrides, dim_t idx) {
1563 std::ostringstream os;
1564
1565 af::dim4 coords = unravelIdx(idx, arrDims, arrStrides);
1566 dim_t ctxWidth = 5;
1567
1568 // Coordinates that span dim0
1569 af::dim4 coordsMinBound = coords;
1570 coordsMinBound[0] = 0;
1571 af::dim4 coordsMaxBound = coords;
1572 coordsMaxBound[0] = arrDims[0] - 1;
1573
1574 // dim0 positions that can be displayed
1575 dim_t dim0Start = std::max<dim_t>(0LL, coords[0] - ctxWidth);
1576 dim_t dim0End = std::min<dim_t>(coords[0] + ctxWidth + 1LL, arrDims[0]);
1577
1578 // Linearized indices of values in vectors that can be displayed
1579 dim_t vecStartIdx =
1580 std::max<dim_t>(ravelIdx(coordsMinBound, arrStrides), idx - ctxWidth);
1581
1582 // Display as minimal coordinates as needed
1583 // First value is the range of dim0 positions that will be displayed
1584 os << "Viewing slice (" << dim0Start << ":" << dim0End - 1;
1585 if (arrDims[1] > 1 || arrDims[2] > 1 || arrDims[3] > 1)
1586 os << ", " << coords[1];
1587 if (arrDims[2] > 1 || arrDims[3] > 1) os << ", " << coords[2];
1588 if (arrDims[3] > 1) os << ", " << coords[3];
1589 os << "), dims are (" << arrDims << ") strides: (" << arrStrides << ")\n";
1590
1591 dim_t ctxElems = dim0End - dim0Start;
1592 std::vector<int> valFieldWidths(ctxElems);
1593 std::vector<std::string> ctxDim0(ctxElems);
1594 std::vector<std::string> ctxOutVals(ctxElems);
1595 std::vector<std::string> ctxGoldVals(ctxElems);
1596
1597 // Get dim0 positions and out/reference values for the context window
1598 //
1599 // Also get the max string length between the position and out/ref
1600 // values per item so that it can be used later as the field width for
1601 // displaying each item in the context window
1602 for (dim_t i = 0; i < ctxElems; ++i) {
1603 std::ostringstream tmpOs;
1604
1605 dim_t dim0 = dim0Start + i;
1606 if (dim0 == coords[0])
1607 tmpOs << "[" << dim0 << "]";
1608 else
1609 tmpOs << dim0;
1610 ctxDim0[i] = tmpOs.str();
1611 size_t dim0Len = tmpOs.str().length();
1612 tmpOs.str(std::string());
1613
1614 dim_t valIdx = vecStartIdx + i;
1615
1616 if (valIdx == idx) {
1617 tmpOs << "[" << +hOut[valIdx] << "]";

Callers 1

elemWiseEqFunction · 0.85

Calls 2

unravelIdxFunction · 0.85
ravelIdxFunction · 0.85

Tested by

no test coverage detected