@@ -446,7 +446,8 @@ julia> triu(a,-3)
446
446
1.0 1.0 1.0 1.0
447
447
```
448
448
"""
449
- function triu (M:: AbstractMatrix , k:: Integer = 0 )
449
+ triu (M:: AbstractMatrix , k:: Integer = 0 ) = _triu (M, Val (haszero (eltype (M))), k)
450
+ function _triu (M:: AbstractMatrix , :: Val{true} , k:: Integer )
450
451
d = similar (M)
451
452
A = triu! (d,k)
452
453
if iszero (k)
@@ -459,6 +460,14 @@ function triu(M::AbstractMatrix, k::Integer = 0)
459
460
end
460
461
return A
461
462
end
463
+ function _triu (M:: AbstractMatrix , :: Val{false} , k:: Integer )
464
+ d = similar (M)
465
+ # since the zero would need to be evaluated from the elements,
466
+ # we copy the array to avoid undefined references in triu!
467
+ copy! (d, M)
468
+ A = triu! (d,k)
469
+ return A
470
+ end
462
471
463
472
"""
464
473
tril(M, k::Integer = 0)
@@ -489,7 +498,8 @@ julia> tril(a,-3)
489
498
1.0 0.0 0.0 0.0
490
499
```
491
500
"""
492
- function tril (M:: AbstractMatrix ,k:: Integer = 0 )
501
+ tril (M:: AbstractMatrix ,k:: Integer = 0 ) = _tril (M, Val (haszero (eltype (M))), k)
502
+ function _tril (M:: AbstractMatrix , :: Val{true} , k:: Integer )
493
503
d = similar (M)
494
504
A = tril! (d,k)
495
505
if iszero (k)
@@ -502,6 +512,14 @@ function tril(M::AbstractMatrix,k::Integer=0)
502
512
end
503
513
return A
504
514
end
515
+ function _tril (M:: AbstractMatrix , :: Val{false} , k:: Integer )
516
+ d = similar (M)
517
+ # since the zero would need to be evaluated from the elements,
518
+ # we copy the array to avoid undefined references in tril!
519
+ copy! (d, M)
520
+ A = tril! (d,k)
521
+ return A
522
+ end
505
523
506
524
"""
507
525
triu!(M)
0 commit comments