Skip to content

Commit 4c2bc30

Browse files
committed
chol: Reduce code duplication
* chol.cc: Replace special case if-else for complex types with unconditional call to math::conj instead of std::conj. The math::conj function already does the right thing for this use case.
1 parent 82c9fef commit 4c2bc30

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

liboctave/numeric/chol.cc

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,14 @@ chol2inv_internal (const T& r, bool is_upper = true)
104104
{
105105
// If someone thinks of a more graceful way of doing this
106106
// (or faster for that matter :-)), please let me know!
107-
if constexpr (std::is_same<T, ComplexMatrix>::value
108-
|| std::is_same<T, FloatComplexMatrix>::value)
109-
{
110-
if (is_upper)
111-
for (octave_idx_type j = 0; j < nc; j++)
112-
for (octave_idx_type i = j+1; i < nr; i++)
113-
retval.xelem (i, j) = std::conj (retval.xelem (j, i));
114-
else
115-
for (octave_idx_type j = 0; j < nc; j++)
116-
for (octave_idx_type i = j+1; i < nr; i++)
117-
retval.xelem (j, i) = std::conj (retval.xelem (i, j));
118-
}
119-
else // not complex type ==> don't need std::conj.
120-
{
121-
if (is_upper)
122-
for (octave_idx_type j = 0; j < nc; j++)
123-
for (octave_idx_type i = j+1; i < nr; i++)
124-
retval.xelem (i, j) = retval.xelem (j, i);
125-
else
126-
for (octave_idx_type j = 0; j < nc; j++)
127-
for (octave_idx_type i = j+1; i < nr; i++)
128-
retval.xelem (j, i) = retval.xelem (i, j);
129-
}
107+
if (is_upper)
108+
for (octave_idx_type j = 0; j < nc; j++)
109+
for (octave_idx_type i = j+1; i < nr; i++)
110+
retval.xelem (i, j) = math::conj (retval.xelem (j, i));
111+
else
112+
for (octave_idx_type j = 0; j < nc; j++)
113+
for (octave_idx_type i = j+1; i < nr; i++)
114+
retval.xelem (j, i) = math::conj (retval.xelem (i, j));
130115
}
131116

132117
return retval;

0 commit comments

Comments
 (0)