Skip to content

Commit

Permalink
Issue with slicing solved.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarbajo committed Jan 13, 2018
1 parent c68fad6 commit f9aa1ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fda/FDataGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, data_matrix, sample_points=None,
else:
# Check that the dimension of the data matches the sample_points
# list
self.sample_points = numpy.asarray(sample_points)
self.sample_points = numpy.atleast_1d(sample_points)
if ((self.data_matrix.ndim == 2
and len(self.sample_points) != self.data_matrix.shape[1])
or (self.data_matrix.ndim > 2
Expand Down
37 changes: 30 additions & 7 deletions tests/test_FDataGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,47 @@ class TestFDataGrid(unittest.TestCase):

def test_init(self):
fd = FDataGrid([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6]])
numpy.testing.assert_array_equal(fd.data_matrix, numpy.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6]]))
numpy.testing.assert_array_equal(
fd.data_matrix,
numpy.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6]]))
self.assertSequenceEqual(fd.sample_range, (0, 1))
numpy.testing.assert_array_equal(fd.sample_points, numpy.array([0., 0.25, 0.5, 0.75, 1.]))
numpy.testing.assert_array_equal(
fd.sample_points, numpy.array([0., 0.25, 0.5, 0.75, 1.]))

def test_mean(self):
fd = FDataGrid([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6]])
mean = math_basic.mean(fd)
numpy.testing.assert_array_equal(mean.data_matrix[0], numpy.array([1.5, 2.5, 3.5, 4.5, 5.5]))
numpy.testing.assert_array_equal(
mean.data_matrix[0],
numpy.array([1.5, 2.5, 3.5, 4.5, 5.5]))
self.assertSequenceEqual(fd.sample_range, (0, 1))
numpy.testing.assert_array_equal(fd.sample_points, numpy.array([0., 0.25, 0.5, 0.75, 1.]))
numpy.testing.assert_array_equal(
fd.sample_points,
numpy.array([0., 0.25, 0.5, 0.75, 1.]))

def test_gmean(self):
fd = FDataGrid([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6]])
mean = math_basic.gmean(fd)
numpy.testing.assert_array_equal(mean.data_matrix[0],
scipy.stats.mstats.gmean(numpy.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6]])))
numpy.testing.assert_array_equal(
mean.data_matrix[0],
scipy.stats.mstats.gmean(
numpy.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6]])))
self.assertSequenceEqual(fd.sample_range, (0, 1))
numpy.testing.assert_array_equal(fd.sample_points, numpy.array([0., 0.25, 0.5, 0.75, 1.]))
numpy.testing.assert_array_equal(
fd.sample_points,
numpy.array([0., 0.25, 0.5, 0.75, 1.]))

def test_slice(self):
t = 10
fd = FDataGrid(data_matrix=numpy.ones(t))
fd = fd[:, 0]
numpy.testing.assert_array_equal(
fd.data_matrix,
numpy.array([[1]]))
numpy.testing.assert_array_equal(
fd.sample_points,
numpy.array([0]))


if __name__ == '__main__':
print()
Expand Down

0 comments on commit f9aa1ba

Please sign in to comment.