Re: Arrays Intersection
- From: Arjen Markus <arjen.markus@xxxxxxxxxx>
- Date: Fri, 30 May 2008 07:38:35 -0700 (PDT)
On 30 mei, 16:34, Paul van Delst <Paul.vanDe...@xxxxxxxx> wrote:
On 30 mei, 16:08, Gordon Sande <g.sa...@xxxxxxxxxxxxxxxx> wrote:On 30 mei, 13:34, Infinity77 <andrea.gav...@xxxxxxxxx> wrote:On 2008-05-30 09:53:27 -0300, Arjen Markus <arjen.mar...@xxxxxxxxxx> said:
Hi All,
I have received so many nice answers in this newsgroup that I
thought I could ask one more question. I am trying to find the
intersection of 2 one-dimensional integer arrays, where "intersection"
means the common elements in both arrays, i.e.:
a = [1,2,3,4,5,6]
b = [5, 6, 7]
intersection(a, b) ==> [5, 6]
You might use:
pack( array1, (/ (any(array1(i) == array2), i=1,size(array1)) /) )
And allows for demonstration of arcane usage of litle used (by many)
fetures that would make an APLer proud. If the following programmers
can not follow the code it is a disservice.
If the OP had to ask it is a fair bet that arcane responses are not the
most helpful. If the OP were into serious obscure algorithms of import
to a larger code then there probably would not have been a question.
There is a well know quote on pricing of yachts that seems suited to
these situations after trivial modification.
FWIW, I don't think the code above is arcane at all. Yes, it uses two new f90/95
intrinsics, PACK and ALL, but once you know what they do, it seems quite clear.
Comparing to current scripting languages like python and ruby, the above code snippet is
positively crystal like in it's clarity. I doubt coding one's own versions of PACK and ALL
would be quite as readable.
We (for some suitable definition of "we") need to stop thinking that we must write code
that can be understood by both our grand-children and -parents. We've got to assume the
person reading the code in the future has some capability for analytical thought when they
come across something they don't immediately grok.
And, besides, isn't reading other's codes and trying to understand them how we all learned
Fortran? :o)
cheers,
paulv- Tekst uit oorspronkelijk bericht niet weergeven -
- Tekst uit oorspronkelijk bericht weergeven -
Hear, hear :)
No, seriously, I think you are right - that is one of the
reasons I wrote the article about array operations and a
"functional" style of programming that appeared in the
Fortran Forum last month.
Well, the one-liner was a bit tough, but splitting it
up a bit makes it very digestible in my opinion and
easier to check than a version with explicit do-loops
(two of them!).
Regards,
Arjen
.
- References:
- Arrays Intersection
- From: Infinity77
- Re: Arrays Intersection
- From: Arjen Markus
- Re: Arrays Intersection
- From: Gordon Sande
- Re: Arrays Intersection
- From: Arjen Markus
- Re: Arrays Intersection
- From: Gordon Sande
- Re: Arrays Intersection
- From: Arjen Markus
- Re: Arrays Intersection
- From: Paul van Delst
- Arrays Intersection
- Prev by Date: Re: Arrays Intersection
- Next by Date: Re: .true. help
- Previous by thread: Re: Arrays Intersection
- Next by thread: Re: Arrays Intersection
- Index(es):
Relevant Pages
|
|