NEML2 2.1.0
Loading...
Searching...
No Matches
assertions.h
1// Copyright 2024, UChicago Argonne, LLC
2// All Rights Reserved
3// Software Name: NEML2 -- the New Engineering material Model Library, version 2
4// By: Argonne National Laboratory
5// OPEN SOURCE LICENSE (MIT)
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23// THE SOFTWARE.
24
25#pragma once
26
27#include "neml2/misc/assertions.h"
28#include "neml2/tensors/shape_utils.h"
29
30namespace neml2
31{
34template <class... T>
35void neml_assert_broadcastable(const T &...);
36
37#ifndef NDEBUG
38#define neml_assert_broadcastable_dbg(...) ::neml2::neml_assert_broadcastable(__VA_ARGS__)
39#else
40#define neml_assert_broadcastable_dbg(...) ((void)0)
41#endif
43
46template <class... T>
48
49#ifndef NDEBUG
50#define neml_assert_dynamic_broadcastable_dbg(...) \
51 ::neml2::neml_assert_dynamic_broadcastable(__VA_ARGS__)
52#else
53#define neml_assert_dynamic_broadcastable_dbg(...) ((void)0)
54#endif
56
59template <class... T>
61
62#ifndef NDEBUG
63#define neml_assert_intmd_broadcastable_dbg(...) \
64 ::neml2::neml_assert_intmd_broadcastable(__VA_ARGS__)
65#else
66#define neml_assert_intmd_broadcastable_dbg(...) ((void)0)
67#endif
69
72template <class... T>
74
75#ifndef NDEBUG
76#define neml_assert_batch_broadcastable_dbg(...) \
77 ::neml2::neml_assert_batch_broadcastable(__VA_ARGS__)
78#else
79#define neml_assert_batch_broadcastable_dbg(...) ((void)0)
80#endif
82
85template <class... T>
87
88#ifndef NDEBUG
89#define neml_assert_base_broadcastable_dbg(...) ::neml2::neml_assert_base_broadcastable(__VA_ARGS__)
90#else
91#define neml_assert_base_broadcastable_dbg(...) ((void)0)
92#endif
94
97template <class... T>
99
100#ifndef NDEBUG
101#define neml_assert_static_broadcastable_dbg(...) \
102 ::neml2::neml_assert_static_broadcastable(__VA_ARGS__)
103#else
104#define neml_assert_static_broadcastable_dbg(...) ((void)0)
105#endif
107} // namespace neml2
108
110// Implementation
112
113namespace neml2
114{
115template <class... T>
116void
117neml_assert_broadcastable(const T &... tensors)
118{
120 "The ",
121 sizeof...(tensors),
122 " operands are not broadcastable. The dynamic shapes are ",
123 tensors.dynamic_sizes()...,
124 ", the intermediate shapes are ",
125 tensors.intmd_sizes()...,
126 ", and the base shapes are ",
127 tensors.base_sizes()...);
128}
129
130template <class... T>
131void
133{
135 "The ",
136 sizeof...(tensors),
137 " operands are not dynamic-broadcastable. The dynamic shapes are ",
138 tensors.dynamic_sizes()...);
139}
140
141template <class... T>
142void
144{
146 "The ",
147 sizeof...(tensors),
148 " operands are not intermediate-broadcastable. The intermediate shapes are ",
149 tensors.intmd_sizes()...);
150}
151
152template <class... T>
153void
155{
157 "The ",
158 sizeof...(tensors),
159 " operands are not batch-broadcastable. The dynamic shapes are ",
160 tensors.dynamic_sizes()...,
161 ", and the intermediate shapes are ",
162 tensors.intmd_sizes()...);
163}
164
165template <class... T>
166void
168{
170 "The ",
171 sizeof...(tensors),
172 " operands are not base-broadcastable. The base shapes are ",
173 tensors.base_sizes()...);
174}
175
176template <class... T>
177void
179{
181 "The ",
182 sizeof...(tensors),
183 " operands are not static-broadcastable. The intermediate shapes are ",
184 tensors.intmd_sizes()...,
185 ", and the base shapes are ",
186 tensors.base_sizes()...);
187}
188} // namespace neml2
bool intmd_broadcastable(const T &... tensors)
Definition shape_utils.h:242
bool dynamic_broadcastable(const T &... tensors)
Definition shape_utils.h:235
bool broadcastable(const T &... tensors)
Definition shape_utils.h:227
bool base_broadcastable(const T &... tensors)
Definition shape_utils.h:249
Definition DiagnosticsInterface.h:31
void neml_assert_batch_broadcastable(const T &...)
void neml_assert_dynamic_broadcastable(const T &...)
void neml_assert_broadcastable(const T &...)
void neml_assert_intmd_broadcastable(const T &...)
void neml_assert_static_broadcastable(const T &...)
void neml_assert_base_broadcastable(const T &...)
void neml_assert(bool assertion, Args &&... args)
Definition assertions.h:47