NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
types.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 <c10/util/ArrayRef.h>
28#include <c10/core/TensorOptions.h>
29
30namespace at
31{
32class Tensor;
33namespace indexing
34{
35struct Slice;
36struct TensorIndex;
37}
38} // namespace at
39
40namespace neml2
41{
42using ATensor = at::Tensor;
43
45// torch also provide unsigned integer types after version 2.2.1, but for backward compatibility
46// reasons we don't include them here
47constexpr auto kInt8 = c10::kChar;
48constexpr auto kInt16 = c10::kShort;
49constexpr auto kInt32 = c10::kInt;
50constexpr auto kInt64 = c10::kLong;
51constexpr auto kFloat16 = c10::kHalf;
52constexpr auto kFloat32 = c10::kFloat;
53constexpr auto kFloat64 = c10::kDouble;
54
55// Device types (mirroring the definition in <c10/core/DeviceType.h>)
56constexpr auto kCPU = c10::DeviceType::CPU;
57constexpr auto kCUDA = c10::DeviceType::CUDA;
58
59template <typename T, unsigned N>
60using SmallVector = c10::SmallVector<T, N>;
61template <typename T>
62using ArrayRef = c10::ArrayRef<T>;
63using TensorOptions = c10::TensorOptions;
64using Dtype = c10::ScalarType;
65using DeviceIndex = c10::DeviceIndex;
66using Device = c10::Device;
67
68using Real = double;
69using Size = int64_t;
70using Integer = int64_t;
71using TensorShape = c10::SmallVector<Size, 8>;
72using TensorShapeRef = c10::ArrayRef<Size>;
73
74namespace indexing
75{
76using namespace at::indexing;
77using TensorIndices = c10::SmallVector<TensorIndex, 8>;
78using TensorIndicesRef = c10::ArrayRef<TensorIndex>;
79} // namespace indexing
80
90enum class FType : int8_t
91{
92 NONE = 0,
93 INPUT = 1 << 0,
94 OUTPUT = 1 << 1,
95 PARAMETER = 1 << 2,
96 BUFFER = 1 << 3
97};
98std::ostream & operator<<(std::ostream & os, FType f);
99
101constexpr auto eps = std::numeric_limits<Real>::epsilon();
102constexpr Real sqrt2 = 1.4142135623730951;
103constexpr Real invsqrt2 = 0.7071067811865475;
105} // namespace neml2
Definition types.h:34
Definition types.h:31
Definition types.h:75
c10::ArrayRef< TensorIndex > TensorIndicesRef
Definition types.h:78
c10::SmallVector< TensorIndex, 8 > TensorIndices
Definition types.h:77
Definition DiagnosticsInterface.cxx:30
c10::Device Device
Definition types.h:66
constexpr auto kInt8
Fixed width dtypes (mirroring the definition in <torch/csrc/api/include/torch/types....
Definition types.h:47
c10::SmallVector< Size, 8 > TensorShape
Definition types.h:71
constexpr auto kFloat64
Definition types.h:53
int64_t Integer
Definition types.h:70
constexpr auto kInt16
Definition types.h:48
c10::SmallVector< T, N > SmallVector
Definition types.h:60
constexpr Real invsqrt2
Definition types.h:103
constexpr auto eps
Constants.
Definition types.h:101
at::Tensor ATensor
Definition types.h:42
double Real
Definition types.h:68
constexpr auto kInt32
Definition types.h:49
c10::ArrayRef< T > ArrayRef
Definition types.h:62
int64_t Size
Definition types.h:69
constexpr auto kInt64
Definition types.h:50
FType
Role in a function definition.
Definition types.h:91
@ BUFFER
Definition types.h:96
@ OUTPUT
Definition types.h:94
@ INPUT
Definition types.h:93
@ NONE
Definition types.h:92
@ PARAMETER
Definition types.h:95
c10::TensorOptions TensorOptions
Definition types.h:63
std::ostream & operator<<(std::ostream &os, const EnumSelection &es)
Definition EnumSelection.cxx:32
c10::ArrayRef< Size > TensorShapeRef
Definition types.h:72
constexpr auto kCPU
Definition types.h:56
constexpr Real sqrt2
Definition types.h:102
c10::ScalarType Dtype
Definition types.h:64
c10::DeviceIndex DeviceIndex
Definition types.h:65
constexpr auto kFloat16
Definition types.h:51
constexpr auto kFloat32
Definition types.h:52
constexpr auto kCUDA
Definition types.h:57