Update WriteTensor
tighter format
print decorated markers at tensor dim boundaries
fix bug printing 2-dim tensors
support up to 10-dim tensors
@@ -257,10 +257,11 @@ namespace Tensile
std::ostream& operator<<(std::ostream& stream, const TensorDescriptor& t);
+ // decorated will print brackets [] to indicate start/end of tensor dims
template <typename T>
- void WriteTensor(std::ostream & stream, T * data, TensorDescriptor const& desc)
+ void WriteTensor(std::ostream & stream, T * data, TensorDescriptor const& desc, bool decorated=true)
{
- const size_t maxDims=8;
+ const size_t maxDims=10;
if(desc.dimensions() > maxDims)
throw std::runtime_error("Fix this function to work with dimensions > 8");
// Use techniques from Reference.cpp with CoordCount to increase dimension support
@@ -276,25 +277,58 @@ namespace Tensile
stream << std::endl;
+ for(is[9] = 0; is[9] < sizes[9]; is[9]++)
+ for(is[8] = 0; is[8] < sizes[8]; is[8]++)
for(is[7] = 0; is[7] < sizes[7]; is[7]++)
for(is[6] = 0; is[6] < sizes[6]; is[6]++)
for(is[5] = 0; is[5] < sizes[5]; is[5]++)
for(is[4] = 0; is[4] < sizes[4]; is[4]++)
for(is[3] = 0; is[3] < sizes[3]; is[3]++)
- for(is[2] = 0; is[2] < desc.sizes()[2]; is[2]++)
+ for(is[2] = 0; is[2] < sizes[2]; is[2]++)
{
- stream << "[" << std::endl;
- for(is[0] = 0; is[0] < desc.sizes()[0]; is[0]++)
+ for(is[1] = 0; is[1] < sizes[1]; is[1]++)
{
- for(is[1] = 0; is[1] < desc.sizes()[1]; is[1]++)
+ int printBrackets=0;
+ if (decorated)
+ {
+ size_t i;
+ for (i=1;i<desc.dimensions();i++)
+ {
+ if (is[i]!=0)
+ break;
+ }
+ for (size_t bi=0;bi<desc.dimensions()-i;bi++)
+ stream << " ";
+ for (size_t bi=0;bi<i;bi++)
+ stream << "[";
+ }
+
+ for(is[0] = 0; is[0] < sizes[0]; is[0]++)
{
std::vector<size_t> validIs(is.begin(), is.begin()+desc.dimensions());
size_t idx = desc.index(validIs);
stream << data[idx] << " ";
}
- stream << std::endl;
+ if (decorated)
+ {
+ bool nl=false;
+ size_t i;
+ for (i=1;i<desc.dimensions();i++)
+ {
+ if (is[i]==sizes[i]-1)
+ {
+ nl = true;
+ stream << "]";
+ }
+ else
+ break;
}
stream << "]" << std::endl;
+ if (nl)
+ stream << std::endl;
+ }
+ }
+ //stream << "]" << std::endl;
}
}
