forked from diffpy/diffpy.srfit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargument.py
More file actions
84 lines (68 loc) · 2.2 KB
/
argument.py
File metadata and controls
84 lines (68 loc) · 2.2 KB
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
#!/usr/bin/env python
##############################################################################
#
# diffpy.srfit by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2008 The Trustees of Columbia University
# in the City of New York. All rights reserved.
#
# File coded by: Chris Farrow
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE_DANSE.txt for license information.
#
##############################################################################
"""Argument class.
Arguments are the leaves of an equation tree, in essence a variable or a
constant.
"""
__all__ = ["Argument"]
from numpy import array_equal, ndarray
from diffpy.srfit.equation.literals.abcs import ArgumentABC
from diffpy.srfit.equation.literals.literal import Literal
class Argument(Literal, ArgumentABC):
"""Argument class.
Attributes
----------
name
A name for this Argument.
const
A flag indicating whether this is considered a constant.
Constants may be given special treatment by the Visitors.
_value
The value of the Argument. Modified with 'set_value'.
value
Property for 'getValue' and 'set_value'.
"""
const = None
def __init__(self, name=None, value=None, const=False):
"""Initialization."""
Literal.__init__(self, name)
self.const = const
self.value = value
return
def identify(self, visitor):
"""Identify self to a visitor."""
return visitor.onArgument(self)
def getValue(self):
"""Get the value of this Literal."""
return self._value
def set_value(self, val):
"""Set the value of the Literal.
Parameters
----------
val
The value to assign
"""
if isinstance(self._value, ndarray) or isinstance(val, ndarray):
notequiv = not array_equal(self._value, val)
else:
notequiv = self._value != val
if notequiv:
self._value = val
self.notify()
return
value = property(
lambda self: self.getValue(), lambda self, val: self.set_value(val)
)
# End of file