NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
utils.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/types.h"
28#include "neml2/misc/errors.h"
29#include "neml2/jit/types.h"
30
31namespace neml2
32{
35
38
41
44
45namespace utils
46{
49TraceableTensorShape extract_batch_sizes(const ATensor & tensor, Size batch_dim);
50
51template <typename... S>
52TraceableTensorShape add_traceable_shapes(const S &... shape);
53
55std::shared_ptr<jit::Graph> last_executed_optimized_graph();
56
57namespace details
58{
59template <typename... S>
60TraceableTensorShape
61add_traceable_shapes_impl(TraceableTensorShape &, const TraceableTensorShape &, const S &...);
62} // namespace details
63} // namespace utils
64} // namespace neml2
65
67// Implementation
69
70namespace neml2::utils
71{
72template <typename... S>
73TraceableTensorShape
74add_traceable_shapes(const S &... shape)
75{
77 return details::add_traceable_shapes_impl(net, shape...);
78}
79
80namespace details
81{
82template <typename... S>
84add_traceable_shapes_impl(TraceableTensorShape & net,
85 const TraceableTensorShape & s,
86 const S &... rest)
87{
88 net.insert(net.end(), s.begin(), s.end());
89
90 if constexpr (sizeof...(rest) == 0)
91 return std::move(net);
92 else
93 return add_traceable_shapes_impl(net, rest...);
94}
95} // namespace details
96} // namespace neml2::utils
Definition Parser.cxx:35
TraceableTensorShape add_traceable_shapes(const S &... shape)
Definition utils.h:74
std::shared_ptr< jit::Graph > last_executed_optimized_graph()
Print last evaluated optimized graph.
Definition utils.cxx:78
TraceableTensorShape extract_batch_sizes(const ATensor &tensor, Size batch_dim)
Extract the batch shape of a tensor given batch dimension The extracted batch shape will be traceable...
Definition utils.cxx:62
Definition DiagnosticsInterface.cxx:30
void neml_assert_not_tracing_dbg()
Assert that we are currently NOT tracing (only effective in debug mode)
Definition utils.cxx:52
at::Tensor ATensor
Definition types.h:42
void neml_assert_tracing()
Assert that we are currently tracing.
Definition utils.cxx:32
void neml_assert_tracing_dbg()
Assert that we are currently tracing (only effective in debug mode)
Definition utils.cxx:44
int64_t Size
Definition types.h:69
void neml_assert_not_tracing()
Assert that we are currently NOT tracing.
Definition utils.cxx:38
Traceable tensor shape.
Definition TraceableTensorShape.h:38