Moved fix parameter to constrainable

This commit is contained in:
Alan Saul 2014-02-10 15:39:54 +00:00
parent d2a0e4a265
commit c6d466e72d
2 changed files with 21 additions and 17 deletions

View file

@ -158,23 +158,6 @@ class Param(ObservableArray, Constrainable):
def _collect_gradient(self, target): def _collect_gradient(self, target):
target[:] = self.gradient.flat target[:] = self.gradient.flat
#=========================================================================== #===========================================================================
# Fixing Parameters:
#===========================================================================
def constrain_fixed(self, warning=True):
"""
Constrain this paramter to be fixed to the current value it carries.
:param warning: print a warning for overwriting constraints.
"""
self._highest_parent_._fix(self,warning)
fix = constrain_fixed
def unconstrain_fixed(self):
"""
This parameter will no longer be fixed.
"""
self._highest_parent_._unfix(self)
unfix = unconstrain_fixed
#===========================================================================
# Tying operations -> bugged, TODO # Tying operations -> bugged, TODO
#=========================================================================== #===========================================================================
def tie_to(self, param): def tie_to(self, param):

View file

@ -76,6 +76,27 @@ class Nameable(Parentable):
class Constrainable(Nameable): class Constrainable(Nameable):
def __init__(self, name): def __init__(self, name):
super(Constrainable,self).__init__(name) super(Constrainable,self).__init__(name)
#===========================================================================
# Fixing Parameters:
#===========================================================================
def constrain_fixed(self, value=None, warning=True):
"""
Constrain this paramter to be fixed to the current value it carries.
:param warning: print a warning for overwriting constraints.
"""
if value is not None:
self[:] = value
self._highest_parent_._fix(self,warning)
fix = constrain_fixed
def unconstrain_fixed(self):
"""
This parameter will no longer be fixed.
"""
self._highest_parent_._unfix(self)
unfix = unconstrain_fixed
#=========================================================================== #===========================================================================
# Constrain operations -> done # Constrain operations -> done
#=========================================================================== #===========================================================================