Line data Source code
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 : #include "neml2/misc/defaults.h"
26 :
27 : namespace neml2
28 : {
29 : void
30 2 : set_default_dtype(Dtype dtype)
31 : {
32 2 : c10::set_default_dtype(scalarTypeToTypeMeta(dtype));
33 2 : }
34 :
35 : Dtype
36 0 : get_default_dtype()
37 : {
38 0 : return c10::get_default_dtype_as_scalartype();
39 : }
40 :
41 : TensorOptions
42 7296 : default_tensor_options()
43 : {
44 7296 : return TensorOptions().dtype(c10::get_default_dtype());
45 : }
46 :
47 : void
48 0 : set_default_integer_dtype(Dtype dtype)
49 : {
50 0 : details::default_integer_dtype() = dtype;
51 0 : }
52 :
53 : Dtype
54 822 : get_default_integer_dtype()
55 : {
56 822 : return details::default_integer_dtype();
57 : }
58 :
59 : TensorOptions
60 151 : default_integer_tensor_options()
61 : {
62 151 : return TensorOptions().dtype(get_default_integer_dtype());
63 : }
64 :
65 : namespace details
66 : {
67 : Dtype &
68 822 : default_integer_dtype()
69 : {
70 : static Dtype _default_integer_dtype = NEML2_DEFAULT_INTEGER_DTYPE_ENUM;
71 822 : return _default_integer_dtype;
72 : }
73 : } // namespace details
74 : } // namespace neml2
|