Skip to content

Commit b595d7e

Browse files
committed
TYP: Typing improvements
1 parent 4e9543d commit b595d7e

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

linearmodels/panel/utility.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,24 @@ def preconditioner(
9797
klass = None
9898
if not isinstance(d, sp.csc_matrix):
9999
klass = d.__class__
100-
d = sp.csc_matrix(d)
100+
d_csc = sp.csc_matrix(d)
101101
elif copy:
102-
d = d.copy()
102+
assert isinstance(d, sp.csc_matrix)
103+
d_csc = d.copy()
103104

104-
cond = cast(linearmodels.typing.data.Float64Array, np.sqrt(d.multiply(d).sum(0)).A1)
105-
locs = np.zeros_like(d.indices)
106-
locs[d.indptr[1:-1]] = 1
105+
cond = cast(
106+
linearmodels.typing.data.Float64Array, np.sqrt(d_csc.multiply(d_csc).sum(0)).A1
107+
)
108+
locs = np.zeros_like(d_csc.indices)
109+
locs[d_csc.indptr[1:-1]] = 1
107110
locs = np.cumsum(locs)
108-
d.data /= np.take(cond, locs)
111+
d_csc.data /= np.take(cond, locs)
109112
if klass is not None:
110-
d = klass(d)
113+
d_out = klass(d_csc)
114+
else:
115+
d_out = d_csc
111116

112-
return d, cond
117+
return d_out, cond
113118

114119

115120
def dummy_matrix(

0 commit comments

Comments
 (0)