linops: optimize linop_plus if one of the arguments is linop_null
@@ -531,6 +531,19 @@ static void plus_free(const linop_data_t* _data)
struct linop_s* linop_plus(const struct linop_s* a, const struct linop_s* b)
{
+
+#if 1
+ // detect null operations and just clone
+
+ if (operator_zero_or_null_p(a->forward)) {
+
+ return (struct linop_s*) linop_clone(b);
+ } else if (operator_zero_or_null_p(b->forward)) {
+
+ return (struct linop_s*) linop_clone(a);
+ }
+#endif
+
auto bdo = linop_domain(b);
assert(CFL_SIZE == bdo->size);
iovec_check(linop_domain(a), bdo->N, bdo->dims, bdo->strs);
@@ -542,8 +555,6 @@ struct linop_s* linop_plus(const struct linop_s* a, const struct linop_s* b)
PTR_ALLOC(struct plus_data_s, data);
SET_TYPEID(plus_data_s, data);
- // maybe detect null operations and just clone
-
data->a = linop_clone(a);
data->b = linop_clone(b);
