@@ -15,6 +15,7 @@ limitations under the License.
1515
1616#include " tensorflow/core/framework/tensor_shape.h"
1717
18+ #include " tensorflow/core/kernels/bounds_check.h"
1819#include " tensorflow/core/lib/core/errors.h"
1920#include " tensorflow/core/lib/strings/str_util.h"
2021#include " tensorflow/core/lib/strings/strcat.h"
@@ -327,4 +328,38 @@ bool TensorShapeUtils::StartsWith(const TensorShape& shape,
327328 return true ;
328329}
329330
331+ template <typename T>
332+ static inline Status MakeShapeHelper (const T* dims, int n, TensorShape* out) {
333+ *out = TensorShape ();
334+ for (int i = 0 ; i < n; ++i) {
335+ const T dim = internal::SubtleMustCopy (dims[i]);
336+ if (dim >= 0 ) {
337+ out->AddDim (dim);
338+ } else {
339+ return errors::InvalidArgument (" Dimension " , dim, " must be >= 0" );
340+ }
341+ }
342+ return Status::OK ();
343+ }
344+
345+ #define MAKE_SHAPE (T ) \
346+ Status TensorShapeUtils::MakeShape (const T* dims, int n, TensorShape* out) { \
347+ return MakeShapeHelper (dims, n, out); \
348+ }
349+ MAKE_SHAPE (int32)
350+ MAKE_SHAPE (int64)
351+ #undef MAKE_SHAPE
352+
353+ string TensorShapeUtils::ShapeListString (
354+ const gtl::ArraySlice<TensorShape>& shapes) {
355+ string result = " [" ;
356+ bool first = true ;
357+ for (const TensorShape& shape : shapes) {
358+ strings::StrAppend (&result, (first ? " " : " , " ), shape.DebugString ());
359+ first = false ;
360+ }
361+ strings::StrAppend (&result, " ]" );
362+ return result;
363+ }
364+
330365} // namespace tensorflow
0 commit comments