Skip to content
This repository was archived by the owner on Mar 4, 2022. It is now read-only.

Commit 1c719c6

Browse files
author
Antonio Vilches
authored
Fix bug when doing get_data from an Array with one element. (shapelets#50)
* Fix bug when doing get_data from an Array with one element.
1 parent 1027f66 commit 1c719c6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

khiva/array.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ def _get_data(self):
213213
KhivaLibrary().c_khiva_library.get_data(ctypes.pointer(self.arr_reference), ctypes.pointer(c_result_array))
214214

215215
dims = self.get_dims()
216-
dims = dims[dims > 1]
216+
if dims[dims > 1].size > 0:
217+
dims = dims[dims > 1]
218+
else:
219+
dims = np.array([1])
220+
217221
a = np.array(c_result_array)
218222

219223
if self._is_complex():

tests/unit_tests/array_unit_tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ def testNonZero(self):
394394
a = Array([1, 2, 3, 4])
395395
self.assertTrue(a)
396396

397+
def testGetData1(self):
398+
a = Array([1])
399+
np.testing.assert_array_equal(a._get_data(), np.array([1]))
400+
401+
def testToList1(self):
402+
a = Array([1])
403+
self.assertIs(type(a.to_list()), list)
404+
self.assertEqual(a.to_list()[0], 1)
405+
397406

398407
if __name__ == '__main__':
399408
suite = unittest.TestLoader().loadTestsFromTestCase(ArrayTest)

0 commit comments

Comments
 (0)