MCPcopy Index your code
hub / github.com/tensorflow/tfjs / subTensorToString

Function subTensorToString

tfjs-core/src/tensor_format.ts:90–188  ·  view source on GitHub ↗
(
    vals: TypedArray|string[], shape: number[], dtype: DataType,
    strides: number[], padPerCol: number[], isLast = true)

Source from the content-addressed store, hash-verified

88}
89
90function subTensorToString(
91 vals: TypedArray|string[], shape: number[], dtype: DataType,
92 strides: number[], padPerCol: number[], isLast = true): string[] {
93 const storagePerElement = dtype === 'complex64' ? 2 : 1;
94
95 const size = shape[0];
96 const rank = shape.length;
97 if (rank === 0) {
98 if (dtype === 'complex64') {
99 const complexTuple = createComplexTuples(vals);
100 return [valToString(complexTuple[0], 0, dtype)];
101 }
102 if (dtype === 'bool') {
103 return [boolNumToString(vals[0] as number)];
104 }
105 return [vals[0].toString()];
106 }
107
108 if (rank === 1) {
109 if (size > FORMAT_LIMIT_NUM_VALS) {
110 const firstValsSize = FORMAT_NUM_FIRST_LAST_VALS * storagePerElement;
111
112 let firstVals = Array.from<number|string|[number, number]>(
113 vals.slice(0, firstValsSize));
114 let lastVals = Array.from<number|string|[number, number]>(vals.slice(
115 (size - FORMAT_NUM_FIRST_LAST_VALS) * storagePerElement,
116 size * storagePerElement));
117 if (dtype === 'complex64') {
118 firstVals = createComplexTuples(firstVals);
119 lastVals = createComplexTuples(lastVals);
120 }
121 return [
122 '[' +
123 firstVals.map((x, i) => valToString(x, padPerCol[i], dtype))
124 .join(', ') +
125 ', ..., ' +
126 lastVals
127 .map(
128 (x, i) => valToString(
129 x, padPerCol[size - FORMAT_NUM_FIRST_LAST_VALS + i], dtype))
130 .join(', ') +
131 ']'
132 ];
133 }
134 const displayVals: Array<number|string|[number, number]> =
135 dtype === 'complex64' ? createComplexTuples(vals) :
136 Array.from<number|string>(vals);
137
138 return [
139 '[' +
140 displayVals.map((x, i) => valToString(x, padPerCol[i], dtype))
141 .join(', ') +
142 ']'
143 ];
144 }
145
146 // The array is rank 2 or more.
147 const subshape = shape.slice(1);

Callers 1

tensorToStringFunction · 0.85

Calls 7

createComplexTuplesFunction · 0.85
valToStringFunction · 0.85
boolNumToStringFunction · 0.85
toStringMethod · 0.80
joinMethod · 0.80
sliceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…