Re: vector difference
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Wed, 06 Aug 2008 12:31:19 -0800
Gordon Sande wrote:
On 2008-08-06 15:36:01 -0300, nospam@xxxxxxxxxxxxx (Richard Maine) said:
utab <umut.tabak@xxxxxxxxx> wrote:
(snip)real :: a(4) = (/1.,2.,3.,4./)
real :: b(1) = (/2., 3./)
result is to be
res = (/1., 4./)
I wondered if there is a quick way to accomplish
this through intrinsic functions?
(snip of actual code using PACK and ANY)I'd say that "pack" and "any" are your friends. I'd probably do
something like
As well as being hard to read they have the
disadvantage that the algorithms
being suggested are quadratic for a well/over researched problem that has
linear (and a bit) solutions. Perfectly acceptable for toy problems but
prone to create bottlenecks if the size grows at some later time. Having
the inputs sorted and using that fact lowers the cost markedly. Establishing
and maintaining a sorted order has it own costs.
In addition, the OP didn't specify the results in the case
that there are repeats in either list. The PACK/ANY method
will remove all copies of any matching element. That may or
may not be the desired result.
With linear traversal through two sorted lists one can
choose to remove all matching element, or only one in
list A for each match to list B.
-- glen
.
- Follow-Ups:
- Re: vector difference
- From: e p chandler
- Re: vector difference
- From: utab
- Re: vector difference
- References:
- vector difference
- From: utab
- Re: vector difference
- From: Richard Maine
- Re: vector difference
- From: Gordon Sande
- vector difference
- Prev by Date: Re: vector difference
- Next by Date: Re: cray pointer declaration issue with gfortran
- Previous by thread: Re: vector difference
- Next by thread: Re: vector difference
- Index(es):
Relevant Pages
|
|