@@ -464,7 +464,8 @@ julia> triu(a,-3)
464
464
1.0 1.0 1.0 1.0
465
465
```
466
466
"""
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 )
468
469
d = similar (M)
469
470
A = triu! (d,k)
470
471
if iszero (k)
@@ -477,6 +478,14 @@ function triu(M::AbstractMatrix, k::Integer = 0)
477
478
end
478
479
return A
479
480
end
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
480
489
481
490
"""
482
491
tril(M, k::Integer = 0)
@@ -507,7 +516,8 @@ julia> tril(a,-3)
507
516
1.0 0.0 0.0 0.0
508
517
```
509
518
"""
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 )
511
521
d = similar (M)
512
522
A = tril! (d,k)
513
523
if iszero (k)
@@ -520,6 +530,14 @@ function tril(M::AbstractMatrix,k::Integer=0)
520
530
end
521
531
return A
522
532
end
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
523
541
524
542
"""
525
543
triu!(M)
0 commit comments