NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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{
39template <class... T>
40void neml_assert_broadcastable(const T &...);
41
49template <class... T>
51
59template <class... T>
61
69template <class... T>
71
79template <class... T>
81
89template <class... T>
91} // namespace neml2
92
94// Implementation
96
97namespace neml2
98{
99template <class... T>
100void
101neml_assert_broadcastable(const T &... tensors)
102{
103 neml_assert(broadcastable(tensors...),
104 "The ",
105 sizeof...(tensors),
106 " operands are not broadcastable. The batch shapes are ",
107 tensors.batch_sizes()...,
108 ", and the base shapes are ",
109 tensors.base_sizes()...);
110}
111
112template <class... T>
113void
114neml_assert_broadcastable_dbg([[maybe_unused]] const T &... tensors)
115{
117 "The ",
118 sizeof...(tensors),
119 " operands are not broadcastable. The batch shapes are ",
120 tensors.batch_sizes()...,
121 ", and the base shapes are ",
122 tensors.base_sizes()...);
123}
124
125template <class... T>
126void
128{
130 "The ",
131 sizeof...(tensors),
132 " operands are not batch-broadcastable. The batch shapes are ",
133 tensors.batch_sizes()...);
134}
135
136template <class... T>
137void
138neml_assert_batch_broadcastable_dbg([[maybe_unused]] const T &... tensors)
139{
141 "The ",
142 sizeof...(tensors),
143 " operands are not batch-broadcastable. The batch shapes are ",
144 tensors.batch_sizes()...);
145}
146
147template <class... T>
148void
150{
152 "The ",
153 sizeof...(tensors),
154 " operands are not base-broadcastable. The base shapes are ",
155 tensors.base_sizes()...);
156}
157
158template <class... T>
159void
160neml_assert_base_broadcastable_dbg([[maybe_unused]] const T &... tensors)
161{
163 "The ",
164 sizeof...(tensors),
165 " operands are not base-broadcastable. The base shapes are ",
166 tensors.base_sizes()...);
167}
168} // namespace neml2
bool batch_broadcastable(const T &... tensors)
Definition shape_utils.h:134
bool broadcastable(const T &... tensors)
Definition shape_utils.h:125
bool base_broadcastable(const T &... tensors)
Definition shape_utils.h:141
Definition DiagnosticsInterface.cxx:30
void neml_assert_dbg(bool assertion, Args &&... args)
Definition assertions.h:60
void neml_assert_batch_broadcastable(const T &...)
A helper function to assert that all tensors are batch-broadcastable.
void neml_assert_batch_broadcastable_dbg(const T &...)
A helper function to assert that (in Debug mode) all tensors are batch-broadcastable.
void neml_assert_broadcastable(const T &...)
A helper function to assert that all tensors are broadcastable.
void neml_assert_base_broadcastable_dbg(const T &...)
A helper function to assert that (in Debug mode) all tensors are base-broadcastable.
void neml_assert_broadcastable_dbg(const T &...)
A helper function to assert (in Debug mode) that all tensors are broadcastable.
void neml_assert_base_broadcastable(const T &...)
A helper function to assert that all tensors are base-broadcastable.
void neml_assert(bool assertion, Args &&... args)
Definition assertions.h:47