FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
diffpy.srreal/src/extensions/wrap_PDFBaseline.cpp at main · diffpy/diffpy.srreal · GitHub
diffpy
diffpy.srreal
Repository navigation
Code
Issues
13
(13)
Pull requests
5
(5)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
diffpy.srreal
/
src
/
extensions
/
wrap_PDFBaseline.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
196 lines (151 loc) · 5.54 KB
Breadcrumbs
diffpy.srreal
/
src
/
extensions
/
wrap_PDFBaseline.cpp
Copy path
File metadata and controls
196 lines (151 loc) · 5.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
****************************************************************************
*
* diffpy.srreal by DANSE Diffraction group
* Simon J. L. Billinge
* (c) 2010 The Trustees of Columbia University
* in the City of New York. All rights reserved.
*
* File coded by: Pavol Juhas
*
* See AUTHORS.txt for a list of people who contributed.
* See LICENSE_DANSE.txt for license information.
*
******************************************************************************
*
* Bindings to the PDFBaseline class. The business methods can be overloaded
* from Python to create custom PDF baseline functions.
*
****************************************************************************
*/
#
include
<
nanobind/nanobind.h
>
#
include
"
srreal_trampoline.hpp
"
#
include
<
diffpy/srreal/PDFBaseline.hpp
>
#
include
<
diffpy/srreal/ZeroBaseline.hpp
>
#
include
<
diffpy/srreal/LinearBaseline.hpp
>
#
include
"
srreal_converters.hpp
"
#
include
"
srreal_pickling.hpp
"
#
include
"
srreal_legacy.hpp
"
#
include
"
srreal_registry.hpp
"
namespace
nb
=
nanobind;
namespace
srrealmodule
{
namespace
nswrap_PDFBaseline
{
using
namespace
diffpy
::srreal
;
//
docstrings ----------------------------------------------------------------
const
char
* doc_PDFBaseline =
"
\
Base class and registry for functions that calculate PDF baseline.
\n
\
"
;
const
char
* doc_PDFBaseline___call__ =
"
\
Calculate PDF baseline at the specified r.
\n
\
\n
\
r -- atom distance in Angstroms where the baseline is calculated.
\n
\
Float or NumPy array.
\n
\
\n
\
Return float or NumPy array.
\n
\
"
;
const
char
* doc_ZeroBaseline =
"
\
Trivial baseline function that is always zero, no baseline.
\n
\
"
;
const
char
* doc_LinearBaseline =
"
\
PDF baseline function equal to (slope * r).
\n
\
"
;
//
wrappers ------------------------------------------------------------------
//
Helper class allows overload of the PDFBaseline methods from Python.
class
PDFBaselineWrap
:
public PDFBaseline,
public PythonTrampolineTag
{
public:
NB_TRAMPOLINE
(PDFBaseline);
//
HasClassRegistry methods
PDFBaselinePtr
create
()
const
{
nb::gil_scoped_acquire gil;
OverrideTicket
ticket
(nb_trampoline,
"
create
"
,
true
);
if
(!ticket.
key
.
is_valid
())
{
throw
nb::type_error
(
"
pure virtual method PDFBaseline.create() called
"
);
}
nb::object rv = nb_trampoline.
base
().
attr
(ticket.
key
)();
return
mconfigurator.
fetch
(rv);
}
PDFBaselinePtr
clone
()
const
{
NB_OVERRIDE_PURE
(clone);
}
const
std::string&
type
()
const
{
nb::gil_scoped_acquire gil;
OverrideTicket
ticket
(nb_trampoline,
"
type
"
,
true
);
if
(!ticket.
key
.
is_valid
())
{
throw
nb::type_error
(
"
pure virtual method PDFBaseline.type() called
"
);
}
nb::object tp = nb_trampoline.
base
().
attr
(ticket.
key
)();
mtype = nb::cast<std::string>(tp);
return
mtype;
}
//
own methods
double
operator
()(
const
double
& x)
const
{
NB_OVERRIDE_PURE_NAME
(
"
__call__
"
,
operator
(), x);
}
protected:
//
HasClassRegistry method
void
setupRegisteredObject
(PDFBaselinePtr p)
const
{
mconfigurator.
setup
(p);
}
private:
mutable
std::string mtype;
wrapper_registry_configurator<PDFBaseline> mconfigurator;
};
//
class PDFBaselineWrap
nb::object
callnparray
(
const
PDFBaseline* obj, nb::object& x)
{
//
Return a float for Python scalars and an array for array-like inputs.
if
(nb::isinstance<nb::float_>(x) || nb::isinstance<nb::int_>(x))
return
nb::float_
((*obj)(
extractdouble
(x)));
NumPyDoubleInput xx =
extractNumPyDoubleArray
(x);
auto
yy =
createNumPyDoubleArrayLike
(xx);
const
double
* src = xx.
data
();
const
double
* last = src + xx.
size
();
double
* dst = yy.
array
.
data
();
for
(; src != last; ++src, ++dst) *dst = (*obj)(*src);
return
yy.
object
;
}
}
//
namespace nswrap_PDFBaseline
//
Wrapper definition --------------------------------------------------------
void
wrap_PDFBaseline
(nb::module_& m)
{
using
namespace
nswrap_PDFBaseline
;
using
diffpy::Attributes;
nb::class_<PDFBaseline, Attributes, PDFBaselineWrap>
pdfbaseline
(m,
"
PDFBaseline
"
,
nb::dynamic_attr
(), doc_PDFBaseline);
wrap_registry_methods
(pdfbaseline)
.
def
(nb::init<>())
.
def
(
"
__call__
"
, callnparray,
nb::arg
(
"
r_array
"
))
.
def
(
"
__call__
"
, &
PDFBaseline::operator
(),
nb::arg
(
"
r
"
), doc_PDFBaseline___call__)
;
SerializationPickleSuite<
PDFBaseline,
DICT_PICKLE
>::
bind
(pdfbaseline);
nb::class_<ZeroBaseline, PDFBaseline>
zerobaseline
(m,
"
ZeroBaseline
"
, doc_ZeroBaseline);
zerobaseline
.
def
(nb::init<>());
SerializationPickleSuite<ZeroBaseline,
DICT_GUARD
>::
bind
(zerobaseline);
nb::class_<LinearBaseline, PDFBaseline>
linearbaseline
(m,
"
LinearBaseline
"
, doc_LinearBaseline);
linearbaseline
.
def
(nb::init<>());
SerializationPickleSuite<LinearBaseline,
DICT_GUARD
>::
bind
(linearbaseline);
}
}
//
namespace srrealmodule
//
Serialization -------------------------------------------------------------
BOOST_CLASS_EXPORT_GUID
(srrealmodule::LegacyComponent<diffpy::srreal::PDFBaseline>,
"
srrealmodule::nswrap_PDFBaseline::PDFBaselineWrap
"
)
//
End of file
Back
|
FazBrowse Home
|
New Git URL