-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5/N] Modernize FFX: approach namedtuple
- Loading branch information
Nate Kupp
committed
Dec 19, 2019
1 parent
1c7f07f
commit c9ccffb
Showing
8 changed files
with
56 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from collections import namedtuple | ||
|
||
|
||
class Approach(namedtuple('_Approach', 'use_inter use_denom use_expon use_nonlin use_thresh')): | ||
def __new__(cls, use_inter, use_denom, use_expon, use_nonlin, use_thresh): | ||
assert set([use_inter, use_denom, use_expon, use_nonlin, use_thresh]).issubset([0, 1]) | ||
return super(Approach, cls).__new__( | ||
cls, use_inter, use_denom, use_expon, use_nonlin, use_thresh | ||
) | ||
|
||
@property | ||
def num_feature_types(self): | ||
'''How many types of features does this approach consider? | ||
''' | ||
return sum(self._asdict().values()) | ||
|
||
def __repr__(self): | ||
return 'inter%d denom%d expon%d nonlin%d thresh%d' % ( | ||
self.use_inter, | ||
self.use_denom, | ||
self.use_expon, | ||
self.use_nonlin, | ||
self.use_thresh, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
|
||
from ffx.core.approach import Approach | ||
|
||
|
||
def test_approach(): | ||
a = Approach(use_inter=0, use_denom=0, use_expon=0, use_nonlin=0, use_thresh=0) | ||
assert str(a) == 'inter0 denom0 expon0 nonlin0 thresh0' | ||
assert a.num_feature_types == 0 | ||
|
||
b = Approach(use_inter=1, use_denom=1, use_expon=1, use_nonlin=1, use_thresh=1) | ||
assert str(b) == 'inter1 denom1 expon1 nonlin1 thresh1' | ||
assert b.num_feature_types == 5 | ||
|
||
with pytest.raises(AssertionError): | ||
Approach(use_inter='not an integer', use_denom=1, use_expon=1, use_nonlin=1, use_thresh=1) |
File renamed without changes.