@@ -464,7 +464,8 @@ julia> triu(a,-3)
464464 1.0  1.0  1.0  1.0 
465465``` 
466466""" 
467- function  triu (M:: AbstractMatrix , k:: Integer  =  0 )
467+ triu (M:: AbstractMatrix , k:: Integer  =  0 ) =  _triu (M, Val (haszero (eltype (M))), k)
468+ function  _triu (M:: AbstractMatrix , :: Val{true} , k:: Integer )
468469    d =  similar (M)
469470    A =  triu! (d,k)
470471    if  iszero (k)
@@ -477,6 +478,14 @@ function triu(M::AbstractMatrix, k::Integer = 0)
477478    end 
478479    return  A
479480end 
481+ function  _triu (M:: AbstractMatrix , :: Val{false} , k:: Integer )
482+     d =  similar (M)
483+     #  since the zero would need to be evaluated from the elements,
484+     #  we copy the array to avoid undefined references in triu!
485+     copy! (d, M)
486+     A =  triu! (d,k)
487+     return  A
488+ end 
480489
481490""" 
482491    tril(M, k::Integer = 0) 
@@ -507,7 +516,8 @@ julia> tril(a,-3)
507516 1.0  0.0  0.0  0.0 
508517``` 
509518""" 
510- function  tril (M:: AbstractMatrix ,k:: Integer = 0 )
519+ tril (M:: AbstractMatrix ,k:: Integer = 0 ) =  _tril (M, Val (haszero (eltype (M))), k)
520+ function  _tril (M:: AbstractMatrix , :: Val{true} , k:: Integer )
511521    d =  similar (M)
512522    A =  tril! (d,k)
513523    if  iszero (k)
@@ -520,6 +530,14 @@ function tril(M::AbstractMatrix,k::Integer=0)
520530    end 
521531    return  A
522532end 
533+ function  _tril (M:: AbstractMatrix , :: Val{false} , k:: Integer )
534+     d =  similar (M)
535+     #  since the zero would need to be evaluated from the elements,
536+     #  we copy the array to avoid undefined references in tril!
537+     copy! (d, M)
538+     A =  tril! (d,k)
539+     return  A
540+ end 
523541
524542""" 
525543    triu!(M) 
0 commit comments