# systemml-dev mailing list archives

##### Site index · List index
Message view
Top
Subject Re: If a Vector is in Another Vector
Date Sun, 09 Jul 2017 22:57:17 GMT
```well, there are different flavors to this problem:

1) If you're only interested in integer values and in testing if all values
of A appear in B, you can do the following:

A = seq(3,4)
B = seq(2,11)
N = min(nrow(A),nrow(B))
M = min(max(A),max(B))
I1 = table(A,1,M,1)!=0;
I2 = table(B,1,M,1)!=0;
ret = sum(I1==I2) == N;
print(ret);

2) If you are interested in testing if the sequence of values in A appears
in B, then this is a classic sequence alignment problem and, if I remember
correctly, there are good dynamic programming algorithms for that. However,
in a semi-vectorized form in DML, you could still do the following (which
first determines the set of equal start values and subsequently probes only
matching candidate subsequences):

A = seq(3,4)
B = seq(2,11)
N = min(nrow(A),nrow(B))
I = (B == A[1,]) * seq(1,nrow(B));
S = removeEmpty(target=I, margin="rows");
ret = FALSE;
if( sum(S) > 0 ) {
for(i in 1:nrow(S)) {
start = as.scalar(S[i,]);
ret = ret | (sum(B[start:start+N-1,]==A)==N)
}
}
print(ret);

Regards,
Matthias

On Sun, Jul 9, 2017 at 3:08 AM, arijit chakraborty <akc14@hotmail.com>
wrote:

> Hi,
>
>
> Suppose I've 2 vectors as
>
>
> A = matrix("2 3", 2, 1)
>
>
> B = matrix(seq(1, 10), 10, 1)
>
>
> And I want to check if A is in B or not. I can use a for-loop to do so.
> But in my case that's not efficient. Is there a way to solve this problem.
>
>
> I tried "in" as we do in R, but it's not working.
>
>
> Thank you!
>
> Arijit
>

```
Mime
• Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message