| 243 | |
| 244 | template<af_op_t op> |
| 245 | static af_err af_arith_sparse_dense(af_array *out, const af_array lhs, |
| 246 | const af_array rhs, |
| 247 | const bool reverse = false) { |
| 248 | try { |
| 249 | const SparseArrayBase linfo = getSparseArrayBase(lhs); |
| 250 | if (linfo.ndims() > 2) { |
| 251 | AF_ERROR( |
| 252 | "Sparse-Dense arithmetic operations cannot be used in batch " |
| 253 | "mode", |
| 254 | AF_ERR_BATCH); |
| 255 | } |
| 256 | const ArrayInfo &rinfo = getInfo(rhs); |
| 257 | |
| 258 | const af_dtype otype = implicit(linfo.getType(), rinfo.getType()); |
| 259 | af_array res; |
| 260 | switch (otype) { |
| 261 | case f32: |
| 262 | res = arithSparseDenseOp<float, op>(lhs, rhs, reverse); |
| 263 | break; |
| 264 | case f64: |
| 265 | res = arithSparseDenseOp<double, op>(lhs, rhs, reverse); |
| 266 | break; |
| 267 | case c32: |
| 268 | res = arithSparseDenseOp<cfloat, op>(lhs, rhs, reverse); |
| 269 | break; |
| 270 | case c64: |
| 271 | res = arithSparseDenseOp<cdouble, op>(lhs, rhs, reverse); |
| 272 | break; |
| 273 | default: TYPE_ERROR(0, otype); |
| 274 | } |
| 275 | |
| 276 | std::swap(*out, res); |
| 277 | } |
| 278 | CATCHALL; |
| 279 | return AF_SUCCESS; |
| 280 | } |
| 281 | |
| 282 | af_err af_add(af_array *out, const af_array lhs, const af_array rhs, |
| 283 | const bool batchMode) { |