Pergunta

I'm using a two-dimensional Matrix D to store distances over particles, so by definition
D(i,j) = D(j,i).

Consequently, I'm only storing values in the upper triangle of the array. But, when using maxval(D), I'm running intro troubles since half the array in un-initialized.

Is there a MASK that would allow me to only consider upper-triangle (i,j) tuples ?

! Pseudo-code above
max_distance = maxval(D, MASK = i in [1:size(D)] .and. j <= i)

Update

Of course, there is this version, but I would hate to write code that has a built-in way already :

function maxval_UpTriangle(D, d_size) result(max_val)
  implicit none
  real*8, dimension(1:d_size) :: D
  integer :: i, j, d_size
  real*8 :: max_val
  do i= 1, d_size
    do j= 1, i 
      if (D(j,i) >= max_val) D(j,i) = max_val
    end do
  end do
  return
end function function maxval_UpTriangle
Foi útil?

Solução

Fortran does not have "skew" sections, so I think what you are requesting is impossible. It's not difficult to write your own code to compute the maximum of the upper triangle of a matrix.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top