/usr/include/xtensor/xexception.hpp is in xtensor-dev 0.10.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | /***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XEXCEPTION_HPP
#define XEXCEPTION_HPP
#include <exception>
#include <iterator>
#include <sstream>
#include <string>
namespace xt
{
/*******************
* broadcast_error *
*******************/
class broadcast_error : public std::exception
{
public:
template <class S1, class S2>
broadcast_error(const S1& lhs, const S2& rhs);
virtual const char* what() const noexcept;
private:
std::string m_message;
};
/**********************************
* broadcast_error implementation *
**********************************/
template <class S1, class S2>
inline broadcast_error::broadcast_error(const S1& lhs, const S2& rhs)
{
std::ostringstream buf("Incompatible dimension of arrays:", std::ios_base::ate);
buf << "\n LHS shape = (";
using size_type1 = typename S1::value_type;
std::ostream_iterator<size_type1> iter1(buf, ", ");
std::copy(lhs.cbegin(), lhs.cend(), iter1);
buf << ")\n RHS shape = (";
using size_type2 = typename S2::value_type;
std::ostream_iterator<size_type2> iter2(buf, ", ");
std::copy(rhs.cbegin(), rhs.cend(), iter2);
buf << ")";
m_message = buf.str();
}
inline const char* broadcast_error::what() const noexcept
{
return m_message.c_str();
}
/*******************
* transpose_error *
*******************/
class transpose_error : public std::exception
{
public:
transpose_error(const std::string& msg);
virtual const char* what() const noexcept;
private:
std::string m_message;
};
/**********************************
* transpose_error implementation *
**********************************/
inline transpose_error::transpose_error(const std::string& msg)
: m_message(msg) {}
inline const char* transpose_error::what() const noexcept
{
return m_message.c_str();
}
/***************
* check_index *
***************/
template <class S, class... Args>
void check_index(const S& shape, Args... args);
template <class S, class It>
void check_element_index(const S& shape, It first, It last);
namespace detail
{
template <class S, std::size_t dim>
inline void check_index_impl(const S&)
{
}
template <class S, std::size_t dim, class... Args>
inline void check_index_impl(const S& shape, std::size_t arg, Args... args)
{
if (sizeof...(Args) + 1 > shape.size())
{
check_index_impl<S, dim>(shape, args...);
}
else
{
if (arg >= shape[dim] && shape[dim] != 1)
{
throw std::out_of_range("index " + std::to_string(arg) + " is out of bounds for axis "
+ std::to_string(dim) + " with size " + std::to_string(shape[dim]));
}
check_index_impl<S, dim + 1>(shape, args...);
}
}
}
template <class S, class... Args>
inline void check_index(const S& shape, Args... args)
{
detail::check_index_impl<S, 0>(shape, args...);
}
template <class S, class It>
inline void check_element_index(const S& shape, It first, It last)
{
auto dst = static_cast<typename S::size_type>(last - first);
It efirst = last - std::min(shape.size(), dst);
std::size_t axis = 0;
while (efirst != last)
{
if (*efirst >= shape[axis] && shape[axis] != 1)
{
throw std::out_of_range("index " + std::to_string(*efirst) + " is out of bounds for axis "
+ std::to_string(axis) + " with size " + std::to_string(shape[axis]));
}
++efirst, ++axis;
}
}
#ifdef XTENSOR_ENABLE_ASSERT
#define XTENSOR_ASSERT(expr) XTENSOR_ASSERT_IMPL(expr, __FILE__, __LINE__)
#define XTENSOR_ASSERT_IMPL(expr, file, line) \
try \
{ \
expr; \
} \
catch (std::exception & e) \
{ \
throw std::runtime_error(std::string(file) + ':' + std::to_string(line) \
+ ": check failed\n\t" + std::string(e.what())); \
}
#else
#define XTENSOR_ASSERT(expr)
#endif
}
#endif
|