We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 53dcc22 commit 274300bCopy full SHA for 274300b
Orange/data/util.py
@@ -99,12 +99,16 @@ def array_equal(a1, a2):
99
"""array_equal that supports sparse and dense arrays with missing values"""
100
if a1.shape != a2.shape:
101
return False
102
- i1, j1, v1 = sp.find(a1)
103
- i2, j2, v2 = sp.find(a2)
104
- a1 = v1 if sp.issparse(a1) else a1[i2, j2]
105
- a2 = v2 if sp.issparse(a2) else a2[i1, j1]
106
- index_equal = set(zip(i1, j1)) == set(zip(i2, j2))
107
- return index_equal and np.allclose(a1, a2, equal_nan=True)
+
+ if not (sp.issparse(a1) or sp.issparse(a2)): # Both dense: just compare
+ return np.allclose(a1, a2, equal_nan=True)
+ v1 = np.vstack(sp.find(a1)).T
+ v2 = np.vstack(sp.find(a2)).T
108
+ if not (sp.issparse(a1) and sp.issparse(a2)): # Any dense: order indices
109
+ v1.sort(axis=0)
110
+ v2.sort(axis=0)
111
+ return np.allclose(v1, v2, equal_nan=True)
112
113
114
def assure_array_dense(a):
Orange/tests/test_util.py
@@ -144,3 +144,17 @@ def test_csc_array_equal(self):
144
a2 = sp.csc_matrix(([5, 1, 4], ([1, 0, 0], [2, 0, 2])), shape=(2, 3))
145
a2[0, 1] = 0 # explicitly setting to 0
146
self.assertTrue(array_equal(a1, a2))
147
148
+ def test_csc_scr_equal(self):
149
+ a1 = sp.csc_matrix(([1, 4, 5], ([0, 0, 1], [0, 2, 2])), shape=(2, 3))
150
+ a2 = sp.csr_matrix(([5, 1, 4], ([1, 0, 0], [2, 0, 2])), shape=(2, 3))
151
+ self.assertTrue(array_equal(a1, a2))
152
153
154
+ a2 = sp.csr_matrix(([1, 4, 5], ([0, 0, 1], [0, 2, 2])), shape=(2, 3))
155
156
157
+ def test_csc_unordered_array_equal(self):
158
+ a1 = sp.csc_matrix(([1, 4, 5], [0, 0, 1], [0, 1, 1, 3]), shape=(2, 3))
159
+ a2 = sp.csc_matrix(([1, 5, 4], [0, 1, 0], [0, 1, 1, 3]), shape=(2, 3))
160
0 commit comments