diff --git a/include/GooseFEM/assertions.h b/include/GooseFEM/assertions.h index 48b8d62..02e51af 100644 --- a/include/GooseFEM/assertions.h +++ b/include/GooseFEM/assertions.h @@ -1,28 +1,35 @@ /** \file \copyright Copyright 2017. Tom de Geus. All rights reserved. \license This project is released under the GNU Public License (GPLv3). */ #ifndef GOOSEFEM_ASSERTIONS_H #define GOOSEFEM_ASSERTIONS_H #include "config.h" namespace GooseFEM { /** Returns true is a list is unique (has not duplicate items). \param arg Array-like. \return `true` if `arg` is unique. */ template inline bool is_unique(const T& arg) { - array_type::tensor tmp = xt::ravel(arg); - return xt::all(xt::equal(xt::unique(tmp), xt::sort(tmp))); + array_type::tensor flat = xt::ravel(arg); + array_type::tensor unique = xt::unique(flat); + array_type::tensor sorted = xt::sort(flat); + + if (unique.size() != sorted.size()) { + return false; + } + + return xt::all(xt::equal(unique, sorted)); } } // namespace GooseFEM #endif