deepjavalibrary / djl

An Engine-Agnostic Deep Learning Framework in Java
https://djl.ai
Apache License 2.0
4.07k stars 648 forks source link

the operator pairwise_distance #1280

Closed mengpengfei closed 2 years ago

mengpengfei commented 2 years ago

I have to implement the siamese network,but i can not find the operator pairwise_distance in djl. I would like to use the operator pairwise_distance,but it is not implemented in djl.please help me.

hongyaohongyao commented 2 years ago

you can implement it with other operators

mengpengfei commented 2 years ago

you can implement it with other operators

can you tell me how to implement.please help me,thanks very much.

zachgk commented 2 years ago

Wouldn't it be:

public NDArray pairwiseDistance(NDArray A, NDArray B) {
    return A.sub(B).square().sum(new int[]{0}).sqrt();
}