extracting a submatrix
Author Message extracting a submatrix

>Hello.  Suppose I have declared a two-dimensional array, call it M,
>like this:

>      parameter(maxn=10000,maxp=50)
>      double precision M(maxn,maxp)

>Then, I read a data file (into M) which has n rows and p columns.
>After reading the data file, I know the values of the integers n and
>p.  Here it is assumed that n <= maxn, and p <= maxp.  In particular,
>we are likely to have n < maxn and p < maxp.

>But, now I want to pass the n * p (sub)matrix to a subroutine (e.g.,
>least-squares routine [LAPACK]).  That is, I don't want to send the
>10000 by 50 matrix to the subroutine.  How can I do this?
>Intuitively, I'd like to be able to declare a new matrix *after*
>obtaining knowledge of n and p, but I don't think this is possible.

---Use adjustable dimensions makes this easy:

PROGRAM MAIN
. . . .
DOUBLE PRECISION M(maxn,maxp)

. . .
<<do NOT use array M>>
call intermediate (M, N, P)

end
subroutine intermediate (M, N, P) << Array M now appears as an N x P >>
DOUBLE PRECISION  M(N,P)
<<create array M of size M, N (e.g. read it in) >>
CALL LAPACK (M, N, P)
end
subroutine LAPACK (M, N, P)
DOUBLE PRECISION M (N, P)
<<use array M of size N x P >>
END

By using an intermediate subroutine, the array M appears to be
of the desired size in subroutines INTERMEDIATE and LAPACK.

Dynamic arrays is one area in which PL/I has been particularly good.
In this problem, a working space of 500,000 times 8 = 4Mb of storage
would be needed, even for the smallest pf problems.

In PL/I, only the amount of storage actually needed would be
used.

fortran 90 offers a comparable facility.

Mon, 27 Jul 1998 03:00:00 GMT  extracting a submatrix
As I remember, Algol 68 had something called a 'slice' that did this. Although
some Algol 68 features have been copied into other programming languages, this
wasn't one of them. I suspect that very few people used it.
--
---------------------------------------------------

http://www-comp.mpce.mq.edu.au/~martin/

Thu, 30 Jul 1998 03:00:00 GMT  extracting a submatrix

Quote:
>As I remember, Algol 68 had something called a 'slice' that did this. Although
>some Algol 68 features have been copied into other programming languages, this
>wasn't one of them. I suspect that very few people used it.

I remember using that feature of the ALGOL 68R compiler that Swinburne Tech. in
Melbourne had abit of 20 years ago. It was a really neat feature.

I have been wanting 'trimscripts' introduced into PL/I ever since. I think I have
even asked IBM Santa Teresa labs. about it. I hope it appears soon in an upcoming
release. [Perhaps Peter Elderon is lurking and will consider it.]

Regards

Dave
<Team PL/I>

Thu, 30 Jul 1998 03:00:00 GMT  extracting a submatrix

Quote:

>    >Hello.  Suppose I have declared a two-dimensional array, call it M,
>    >like this:

>    >      parameter(maxn=10000,maxp=50)
>    >      double precision M(maxn,maxp)

>    >Then, I read a data file (into M) which has n rows and p columns.
>    >After reading the data file, I know the values of the integers n and
>    >p.  Here it is assumed that n <= maxn, and p <= maxp.  In particular,
>    >we are likely to have n < maxn and p < maxp.

>    >But, now I want to pass the n * p (sub)matrix to a subroutine (e.g.,
>    >least-squares routine [LAPACK]).  That is, I don't want to send the
>    >10000 by 50 matrix to the subroutine.  How can I do this?
>    >Intuitively, I'd like to be able to declare a new matrix *after*
>    >obtaining knowledge of n and p, but I don't think this is possible.

> ---Use adjustable dimensions makes this easy:

> PROGRAM MAIN
>    . . . .
>    DOUBLE PRECISION M(maxn,maxp)

>    . . .
>    <<do NOT use array M>>
>    call intermediate (M, N, P)

> end
> subroutine intermediate (M, N, P) << Array M now appears as an N x P >>
>    DOUBLE PRECISION  M(N,P)
>    <<create array M of size M, N (e.g. read it in) >>
>    CALL LAPACK (M, N, P)
> end
> subroutine LAPACK (M, N, P)
>    DOUBLE PRECISION M (N, P)
>    <<use array M of size N x P >>
> END

> By using an intermediate subroutine, the array M appears to be
> of the desired size in subroutines INTERMEDIATE and LAPACK.

>    Dynamic arrays is one area in which PL/I has been particularly good.
> In this problem, a working space of 500,000 times 8 = 4Mb of storage
> would be needed, even for the smallest pf problems.

>    In PL/I, only the amount of storage actually needed would be
> used.

>    Fortran 90 offers a comparable facility.

The suggested solution is, in my opinion, about the worst way to solve this
"problem"; it is what I call "cheat mode", and full of pitfalls. I get the
impression that ++ robin believes that the whole maxn*maxp matrix is somehow
passed to subroutines. In fact, the address of M(1,1) is passed, along with
information from which the subroutine can find where any given element M(i,j)
is. The only clean and safe way to do this is to pass both the set (maxn, maxp)
AND the actually used dimensions, (n,p):

call SUB (M, maxn, maxp, n, p)
...
subroutine SUB (M, maxn, maxp, n, p)
integer maxn, maxp, n, p
double precision M(maxn, maxp)

etc. This gets tedious if you are passing several matrices, each of which
must be assumed to have its own maximum and actual dimensions. Even better
would be switching to F90 and using modules.

Fri, 31 Jul 1998 03:00:00 GMT  extracting a submatrix
I would like to have all the defining of the mainframe compiler also on OS/2
and AIX! For instance simple defining:

dcl M (4,4) float;
dcl N (3,3) float defined M;

In this way Matrix N is a submatrix of matrix N and Element M(2,3) is N(2,3)!
Or take the main diagonal of M:

dcl D (4) defined M(1sub, 1sub);

iSUB-defining is the thing in PL/I I like most!

Fri, 31 Jul 1998 03:00:00 GMT

 Page 1 of 1 [ 5 post ]

Relevant Pages