23 #if ! defined (octave_Sparse_diag_op_defs_h) 24 #define octave_Sparse_diag_op_defs_h 1 26 #include "octave-config.h" 32 template <
typename RT,
typename DM,
typename SM>
44 RT r (nr,
a_nc,
a.nnz ());
56 r.xdata (l) =
d.dgelem (
i) *
a.data (
k);
64 r.maybe_compress (
true);
68 template <
typename RT,
typename SM,
typename DM>
81 RT r (
a_nr, nc,
a.cidx (mnc));
85 const typename DM::element_type
s =
d.dgelem (j);
87 r.xcidx (j) =
a.cidx (j);
90 r.xdata (
k) =
s *
a.data (
k);
91 r.xridx (
k) =
a.ridx (
k);
95 r.xcidx (j) =
a.cidx (mnc);
97 r.maybe_compress (
true);
102 template <
typename T>
104 :
public std::unary_function <T, T>
111 template <
typename RT,
typename SM,
typename DM,
typename OpA,
typename OpD>
133 for (k_split = k_src; k_split < colend; k_split++)
134 if (
a.ridx (k_split) >= j)
137 for (; k_src < k_split; k_src++,
k++)
139 r.xridx (
k) =
a.ridx (k_src);
140 r.xdata (
k) = opa (
a.data (k_src));
143 if (k_src < colend &&
a.ridx (k_src) == j)
146 r.xdata (
k) = opa (
a.data (k_src)) + opd (
d.dgelem (j));
152 r.xdata (
k) = opd (
d.dgelem (j));
156 for (; k_src < colend; k_src++,
k++)
158 r.xridx (
k) =
a.ridx (k_src);
159 r.xdata (
k) = opa (
a.data (k_src));
165 r.maybe_compress (
true);
169 template <
typename RT,
typename DM,
typename SM>
173 return inner_do_add_sm_dm<RT> (
a,
d,
178 template <
typename RT,
typename DM,
typename SM>
181 if (
a.rows () !=
d.rows () ||
a.cols () !=
d.cols ())
183 d.rows (),
d.cols (),
a.rows (),
a.cols ());
185 return do_commutative_add_dm_sm<RT> (
d,
a);
188 template <
typename RT,
typename DM,
typename SM>
191 if (
a.rows () !=
d.rows () ||
a.cols () !=
d.cols ())
193 d.rows (),
d.cols (),
a.rows (),
a.cols ());
195 return inner_do_add_sm_dm<RT> (
a,
d,
196 std::negate<typename SM::element_type> (),
200 template <
typename RT,
typename SM,
typename DM>
203 if (
a.rows () !=
d.rows () ||
a.cols () !=
d.cols ())
205 a.rows (),
a.cols (),
d.rows (),
d.cols ());
207 return do_commutative_add_dm_sm<RT> (
d,
a);
210 template <
typename RT,
typename SM,
typename DM>
213 if (
a.rows () !=
d.rows () ||
a.cols () !=
d.cols ())
215 a.rows (),
a.cols (),
d.rows (),
d.cols ());
217 return inner_do_add_sm_dm<RT> (
a,
d,
219 std::negate<typename DM::element_type> ());
RT do_commutative_add_dm_sm(const DM &d, const SM &a)
RT do_mul_sm_dm(const SM &a, const DM &d)
RT do_add_dm_sm(const DM &d, const SM &a)
RT do_sub_dm_sm(const DM &d, const SM &a)
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
RT do_add_sm_dm(const SM &a, const DM &d)
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
RT inner_do_add_sm_dm(const SM &a, const DM &d, OpA opa, OpD opd)
RT do_sub_sm_dm(const SM &a, const DM &d)
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
charNDArray min(char d, const charNDArray &m)
RT do_mul_dm_sm(const DM &d, const SM &a)