You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find myself in the need of preallocated matrix operations, like add, mul, map and so. For this the _to methods taking a &mut out argument are great, however they are increasing the verbosity quite a lot. For two reasons:
2x more arguments (but we cannot avoid it)
split expressions across many lines (and we can do something about it)
I suggest these functions could return the &mut out reference so we could chain these operations when needed.
The following example shows the concept on u32 operations
pubtraitMulTo<Rhs,Rst>{fnmul_to(&self,right:Rhs,result:Rst) -> Rst;}implMulTo<u32,&mutu32>foru32{fnmul_to<'r>(&self,right:u32,result:&'r mutu32) -> &'r mutu32{*result = self* right;
result
}}fnmain(){let a = 2;let b = 3;let c = 4;letmut tmp1 = 0;letmut tmp2 = 0;// and now without dynamic allocations (if it were matrices)// result = a*b + clet result = a.mul_to(b,&mut tmp1).add_to(c,&mut tmp2);// result is a &mut u32 pointing into our tmp2 variable, so it can live as long as we do not need tmp2 again}
On a diffferent topic, I suggest creating traits AddTo, SubTo, MulTo to generalize this to third-party types
The text was updated successfully, but these errors were encountered:
BLAS kernels could certainly be used in this example but this is not the point.
BLAS kernels do not return a reference to their out: &mut either, so they do not help reducing verbosity and increasing readability.
My point is simply: it would be more convenient to have *_to methods return their out reference so we can chain them in an expression
Hello again dear maintainers
I find myself in the need of preallocated matrix operations, like
add
,mul
,map
and so. For this the_to
methods taking a&mut out
argument are great, however they are increasing the verbosity quite a lot. For two reasons:I suggest these functions could return the
&mut out
reference so we could chain these operations when needed.The following example shows the concept on
u32
operationsOn a diffferent topic, I suggest creating traits
AddTo
,SubTo
,MulTo
to generalize this to third-party typesThe text was updated successfully, but these errors were encountered: