From 8f3e8a6ca7744c4e29a3f65915fe0c48eb8b3fb9 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 11 Jun 2016 21:15:36 -0400 Subject: [PATCH] Made mat() work on empty tensors. --- dlib/dnn/tensor.h | 14 ++++++-------- dlib/dnn/tensor_abstract.h | 11 ++++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/dlib/dnn/tensor.h b/dlib/dnn/tensor.h index 95603a861..4f37c5582 100644 --- a/dlib/dnn/tensor.h +++ b/dlib/dnn/tensor.h @@ -192,9 +192,9 @@ namespace dlib long nc ) { - DLIB_ASSERT(nr > 0 && nc > 0 , + DLIB_ASSERT(nr >= 0 && nc >= 0 , "\tconst matrix_exp mat(tensor, nr, nc)" - << "\n\t nr and nc must be bigger than 0" + << "\n\t nr and nc must be >= 0" << "\n\t nr: " << nr << "\n\t nc: " << nc ); @@ -212,12 +212,10 @@ namespace dlib const tensor& t ) { - DLIB_ASSERT(t.size() != 0, - "\tconst matrix_exp mat(tensor)" - << "\n\t The tensor can't be empty." - ); - - return mat(t, t.num_samples(), t.size()/t.num_samples()); + if (t.size() != 0) + return mat(t, t.num_samples(), t.size()/t.num_samples()); + else + return mat((float*)0,0,0); } inline const matrix_op > image_plane ( diff --git a/dlib/dnn/tensor_abstract.h b/dlib/dnn/tensor_abstract.h index d4ef8ec45..f8cfcf469 100644 --- a/dlib/dnn/tensor_abstract.h +++ b/dlib/dnn/tensor_abstract.h @@ -333,8 +333,8 @@ namespace dlib ); /*! requires - - nr > 0 - - nc > 0 + - nr >= 0 + - nc >= 0 - nr*nc == t.size() ensures - returns a matrix M such that: @@ -350,10 +350,11 @@ namespace dlib const tensor& t ); /*! - requires - - t.size() != 0 ensures - - returns mat(t, t.num_samples(), t.size()/t.num_samples()) + - if (t.size() != 0) then + - returns mat(t, t.num_samples(), t.size()/t.num_samples()) + - else + - returns an empty matrix. !*/ const matrix_exp image_plane (