That will be fine until FriCAS allows inherent parellelism.
I don't think we have too many places where parellel execution of
commands will fail, but marking domain variables that are not "constant"
like here
https://github.com/fricas/fricas/blob/master/src/algebra/expr.spad#L1084
seems to me like a good idea.

In fact, is it really clear that FriCAS accesses tmp0 from outside the
function? If I'm not wrong, in Aldor you would have to declare

  free tmp0;

inside subtractIfCan.

Ralf

On 03/26/2018 02:05 PM, oldk1331 wrote:
> This change has been discussed long time ago,
> now I'm posting it again for review:
> 
> By using domain variables 'tmp0' and 'tmp1',
> this patch avoids allocation when computation
> fails.
> 
> diff --git a/src/algebra/vector.spad b/src/algebra/vector.spad
> index 6b6d7907..cb9e5b32 100644
> --- a/src/algebra/vector.spad
> +++ b/src/algebra/vector.spad
> @@ -437,24 +437,28 @@
>          u : % * v : % == map(_*, u, v)$Rep
> 
>        if R has CancellationAbelianMonoid then
> +        tmp0 := new(dim, 0)$Rep
> +
>          subtractIfCan(u:%, v:%):Union(%,"failed") ==
> -          w := new(dim, 0)$Vector(R)
> +          w := tmp0
>            for i in 1..dim repeat
>              (c := subtractIfCan(qelt(u, i)$Rep, qelt(v,i)$Rep)) case
> "failed" =>
>                      return "failed"
>              qsetelt!(w, i, c::R)$Rep
> -          w pretend %
> +          copy w
> 
>        if R has Monoid then
> 
>          1 == new(dim, 1)$Vector(R) pretend %
> 
> +        tmp1 := new(dim, 1)$Rep
> +
>          recip z ==
> -          w := new(dim, 1)$Vector(R)
> -          for i in minIndex w .. maxIndex w repeat
> +          w := tmp1
> +          for i in 1..dim repeat
>              (u := recip qelt(z, i)) case "failed" => return "failed"
>              qsetelt!(w, i, u::R)
> -          w pretend %
> +          copy w
> 
>        if R has AbelianMonoid and R has Monoid then
> 

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to