Skip to content

Commit 84b6d62

Browse files
committed
moved .size() method from Array class to Potential class
1 parent 8b2a69c commit 84b6d62

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

brml/array.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,6 @@ class is not implemented.
3434
# TODO: See if LogArray class is needed or this is enough.
3535
return Array(variables=self.variables, table=np.log(self.table))
3636

37-
def size(self):
38-
"""
39-
Finds the number of states of the Array potential.
40-
At the moment this method calculates the number of states as follows:
41-
1. Table 1D (vector) -> length of vector
42-
2. Table 2D but one dimension has length 1 (e.g. (1, 2)) -> max
43-
of both dimensions (e.g. max(1, 2) = 2)
44-
3. Table multidimensional but actually a vector - length vector
45-
4. Table multidimensional -> return shape of table
46-
TODO: Consider moving this method to Potential superclass.
47-
TODO: Consider adding a __len__ method.
48-
Notice that it returns a numpy array even if table is a 1D vector.
49-
:return: Number of states in the table for each variable.
50-
:rtype: numpy.array
51-
"""
52-
if isvector(self.table):
53-
return np.array([len(self.table)]).astype(np.int8)
54-
else:
55-
return np.array(self.table.shape).astype(np.int8)
56-
5737
def sum(self, variables):
5838
"""
5939
This method sums the probability table over provided variables. It is

brml/potential.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,25 @@ def set_table(self, table):
169169
"""
170170
self.table = self._check_table(table)
171171

172+
def size(self):
173+
"""
174+
Finds the number of states of the Array potential.
175+
At the moment this method calculates the number of states as follows:
176+
1. Table 1D (vector) -> length of vector
177+
2. Table 2D but one dimension has length 1 (e.g. (1, 2)) -> max
178+
of both dimensions (e.g. max(1, 2) = 2)
179+
3. Table multidimensional but actually a vector - length vector
180+
4. Table multidimensional -> return shape of table
181+
TODO: Consider adding a __len__ method.
182+
Notice that it returns a numpy array even if table is a 1D vector.
183+
:return: Number of states in the table for each variable.
184+
:rtype: numpy.array
185+
"""
186+
if isvector(self.table):
187+
return np.array([len(self.table)]).astype(np.int8)
188+
else:
189+
return np.array(self.table.shape).astype(np.int8)
190+
172191

173192
if __name__ == "__main__":
174193
VARIABLES = 1

0 commit comments

Comments
 (0)