Different results between torch.cdist and cdist

Tianming_Qu: <p>Hi all,</p>
<p>I am new to pytorch and I meet a problem that the result I got from cdist and torch.cdist is different. Part of the result in torch.cdist gives zeros but not in cdist, the rest part of the results are consistent between cdist and torch.cdist, why is this happened? following are part of the result:</p>
<p>cdist:</p>
<p>array([ 34.04802046,  31.41677035,  28.85756783,  26.39138085,<br>
24.0468448 ,  21.86313122,  19.89327195,  18.20681275,<br>
16.88886593,  16.03058185,  15.70749236,  15.95214964,<br>
16.73967861,  17.99896113,  19.63945935,  21.57438587,<br>
23.73183279,  26.05658553,  28.507743  ,  31.05538879,<br>
33.67763256,  36.35833738,  39.08547631,  41.84997277,<br>
44.64488753,  47.46484746,  50.3056409 ,  53.16392826,<br>
56.03703266,  58.92278669,  61.8194189 ,  64.72546883,<br>
67.63972263,  33.33915467,  30.64710421,  28.01768652,<br>
25.47030663,  23.03220098,  20.74193925,  18.65405601,<br>
16.84397719,  15.4099101 ,  14.46413119,  14.10520659,<br>
14.37715601,  15.2462578 ,  16.61908959,  18.38314175,<br>
20.43735948,  22.70311486,  25.12323996,  27.65724043,<br>
30.27653728,  32.96080205,  35.69538112,  38.46954634,<br>
41.27531656,  44.10666071,  46.95895315,  49.82859664,<br>
52.71275752,  55.609177  ,  58.5160348 ,  61.43184915,<br>
64.35540267,  67.28568655,  32.88967575,  30.15752863,<br>
27.4813081 ,  24.87906865,  22.37663555,  20.01148622,<br>
17.83831109,  15.93584338,  14.411692  ,  13.39561973,<br>
13.00724375,  13.30165974,  14.23656959,  15.69795132,<br>
17.55481237,  19.69561371,  22.03776216,  24.52363601,<br>
27.1137324 ,  29.78087048,  32.50609187,  35.27593756,<br>
38.08067138,  40.91311885,  43.76789984,  46.64091356,<br>
49.52898727,  52.42963229,  55.34087191,  58.26111796,<br>
61.18908095,  64.1237038 ,  67.06411224,  32.71027832,<br>
29.96177682,  27.26634981,  24.64142029,  22.1121088 ,<br>
19.71525088,  17.50533859,  15.56221839,  13.99744273,<br>
12.94890594,  12.5467098 ,  12.85168038,  13.81707098,<br>
15.31852514,  17.21635775,  19.39455429,  21.76911799,<br>
24.28250934,  26.89583651,  29.58262638,  32.32456567,<br>
35.10873549,  37.92583643,  40.76904256,  43.633251  ,<br>
46.51458217,  49.41004065,  52.31728088,  55.23444252,<br>
58.16003269,  61.09284053,  64.0318743 ,  66.97631438,<br>
32.80539353,  30.06558842,  27.38038292,  24.76754188,<br>
22.25257047,  19.87266098,  17.68243242,  15.76116043,<br>
14.21829596,  13.18733111,  12.79263318,  13.09187632,<br>
14.04076164,  15.52059114,  17.39639362,  19.5545461 ,<br>
21.91177845,  24.41048539,  27.01143385,  29.68776382,<br>
32.42081249,  35.19736985,  38.00790189,  40.84539592,<br>
43.70460079,  46.58151878,  49.47305988,  52.37680226,<br>
55.29082363,  58.21358037,  61.14381981,  64.08051547,<br>
67.02281869,  33.17266016,  30.46590133,  27.81936206,<br>
25.25198344,  22.79053377,  20.47325551,  18.3548346 ,<br>
16.51198701,  15.04631107,  14.076123  ,  13.70704201,<br>
13.98673523,  14.87866003,  16.28251474,  18.07943716,<br>
20.16461777,  22.45790666,  24.9018741 ,  27.45631249,<br>
30.09310315,  32.7923866 ,  35.53992658,  38.32534596,<br>
41.14095168,  43.98094663,  46.84089483,  49.71735301,<br>
52.60761306,  55.50951913,  58.4213358 ,  61.34165174,<br>
64.26930838,  67.20334636,  33.8032087 ,  31.15128698,<br>
28.56831186,  26.074781  ,  23.69894441,  21.47989125,<br>
19.47129913,  17.74478097,  16.38972281,  15.50383099,<br>
15.1695266 ,  15.42272023,  16.23594965,  17.53145239,<br>
19.21191258,  21.18592332,  23.37924525,  25.73586739,<br>
28.21490089,  30.78678928,  33.43010853,  36.12918374,<br>
38.87240255,  41.65104371,  44.45846605,  47.28954393,<br>
50.14027052,  53.00747579,  55.88862363,  58.78166392,<br>
61.6849234 ,  64.59702421,  67.51682234,  34.68268236,<br>
32.10349229,  29.60371563,  27.20525209,  24.93735156,<br>
22.83894185,  20.96098821,  19.36772544,  18.13434726,<br>
17.33782894,  17.03954443,  17.26533626,  17.99548827,<br>
19.17246358,  20.72025873,  22.56268786,  24.63372983,<br>
26.88059537,  29.26281205,  31.74992805,  34.3191447 ,<br>
36.95334159,  39.6395663 ,  42.36792394,  45.13077376,<br>
47.92215044,  50.73734585,  53.57260518,  56.42490397,<br>
59.29178316,  62.17122575,  65.06156372,  67.96140696,<br>
35.79273659,  33.29963595,  30.89678812,  28.60694458,<br>
26.45946031,  24.49181091,  22.75070468,  21.2917901 ,<br>
20.17637449,  19.46360319,  19.19837522,  19.39905598,<br>
20.05166165,  21.11432918,  22.52910692,  24.23440572,<br>
26.17350153,  28.29837353,  30.57030759,  32.95890575,<br>
35.44058732,  37.9971182 ,  40.61436634,  43.28131832,<br>
45.98932786,  48.73155076,  51.50252228,  54.29784124,<br>
57.11393284,  59.94786974,  62.79723599,  65.66002292,<br>
68.53454875,  37.1126869 ,  34.71451125,  32.41670947,<br>
30.24216948,  28.21940072,  26.38333449,  24.77551413,<br>
23.4429491 ,  22.43474146,  21.79594885,  21.55943292,<br>
21.73832813,  22.3226493 ,  23.28189068,  24.57218337,<br>
26.14455885,  27.9514529 ,  29.95045043,  32.10568864,<br>
34.38780314,  36.77317999,  39.24299337,  41.78227244,<br>
44.37909477,  47.0239281 ,  49.70910959,  52.42844016,<br>
55.17687106,  57.95026196,  60.74519424,  63.55882618,<br>
66.38878028,  69.23305503,  38.62101845,  36.32256637,<br>
34.13318898,  32.07522957,  30.17558804,  28.46597751,<br>
26.9825432 ,  25.76438238,  24.85053644,  24.27539748,<br>
24.06326422,  24.22367533,  24.74938804,  25.61792284,<br>
26.79596485,  28.24481358,  29.92516092,  31.80033047,<br>
33.83794881,  36.01045045,  38.29488613,  40.67239931,<br>
43.12759937,  45.64795274,  48.22324492,  50.8451287 ,<br>
53.50675541,  56.20247892,  58.92762   ,  61.67827949,<br>
64.45119023,  67.24359958,  70.05317585,  40.29658302,<br>
38.09934861,  36.01813608,  34.07421149,  32.29237759,<br>
30.7008699 ,  29.33068656,  28.21409109,  27.38212369,<br>
26.86124457,  26.66968732,  26.81451069,  27.29035994,<br>
28.08041145,  29.15913698,  30.49591827,  32.05849019,<br>
33.81556675,  35.7384711 ,  37.80190575,  39.98411985,<br>
42.2667198 ,  44.63430703,  47.07406001,  49.57532539,<br>
52.12924947,  54.72846071,  57.36680376,  60.03912004,<br>
62.74106867,  65.46898089,  68.21974216,  70.99069645,<br>
42.11942711,  40.0223925 ,  38.04651973,  36.21164765,<br>
34.54025459,  33.05714672,  31.78868841,  30.76144459,<br>
30.00020391,  29.5255482 ,  29.35138427,  29.48303784,<br>
29.91647176,  30.63888125,  31.63047274,  32.86689167,<br>
34.32168891,  35.96837627,  37.78187202,  39.73934594,<br>
41.82058557,  44.00803494,  46.28663847,  48.6435881 ,<br>
51.06803721,  53.55081873,  56.08418626,  58.66158633,<br>
61.277463  ,  63.92709312,  66.60644861,  69.31208234,<br>
72.04103358,  44.0712795 ,  42.07164649,  40.19663171,<br>
38.46446363,  36.89526696,  35.51065314,  34.33296154,<br>
33.38409816,  32.68399871,  32.24886872,  32.08948886,<br>
32.20995277,  32.60715902,  33.27119747,  34.18652283,<br>
35.33361154,  36.69073271,  38.23552835,  39.94623124,<br>
41.80247782,  43.78576155,  45.87961068,  48.06957913,<br>
50.34312465,  52.68942932,  55.09919894,  57.56446374,<br>
60.07839252,  62.635126  ,  65.22963108,  67.85757535,<br>
70.51522031,  73.19933098,  46.13576935,  44.22957128,<br>
42.44997924,  40.81355779,  39.33817816,  38.04258171,<br>
36.94568696,  36.06562833,  35.41857293,  35.01743952,<br>
34.87071597,  34.98160365,  35.34767823,  35.96114734,<br>
36.80964384,  37.87737638,  39.14640984,  40.59787144,<br>
42.21294739,  43.97361356,  45.86310555,  47.86616982,<br>
49.96915023,  52.15996297,  54.42800289,  56.76401378,<br>
59.15994441,  61.60880444,  64.10452828,  66.64185102,<br>
69.21619803,  71.82358827,  74.46055059,  48.29845495,<br>
46.4810339 ,  44.7909843 ,  43.24324266,  41.85359958,<br>
40.63827703,  39.61332253,  38.79382791,  38.1930209 ,<br>
37.82132477,  37.68551936,  37.78814802,  38.12728541,<br>
38.69671375,  39.48647131,  40.48366558,  41.67340807,<br>
43.03973399,  44.56640511,  46.23754131,  48.03806811,<br>
49.95399633,  51.97256499,  54.08228244,  56.27289788,<br>
58.53532948,  60.86156882,  63.24457543,  65.67817052,<br>
68.15693541,  70.67611765,  73.23154627,  75.81955638,<br>
50.5467337 ,  48.81309301,  47.20660771,  45.74067744,<br>
44.42921713,  43.28626915,  42.3254871 ,  41.55950698,<br>
40.99924856,  40.65321813,  40.52690348,  40.62235429,<br>
40.93801937,  41.46887015,  42.206788  ,  43.14114875,<br>
44.25951284,  45.54832861,  46.99357404,  48.58129026,<br>
50.29798728,  52.13092448,  54.06828135,  56.09924073,<br>
58.21400667,  60.40377748,  62.6606902 ,  64.97774894,<br>
67.34874624,  69.76818316,  72.23119232,  74.73346577,<br>
77.27118911,  52.8696872 ,  51.21473993,  49.68596731,<br>
48.29535288,  47.05514713,  45.97752313,  45.07414331,<br>
44.3556553 ,  43.83115238,  43.50765083,  43.38964672,<br>
43.47881329,  43.77388453,  44.27074348,  44.9627011 ,<br>
45.84092334,  46.89494657,  48.11321831,  49.48360878,<br>
50.99385551,  52.63192056,  54.38625583,  56.24598284,<br>
58.20099954,  60.24202942,  62.36062757,  64.54915672,<br>
66.80074397,  69.10922628,  71.46909065,  73.87541323,<br>
76.32379997,  78.81033057,  55.25789863,  53.6766348 ,<br>
52.21998549,  50.89865074,  49.72341912,  48.70486804,<br>
47.85300338,  47.17685549,  46.68405998,  46.3804616 ,<br>
46.26978474,  46.35341133,  46.63029598,  47.09703032,<br>
47.74804737,  48.57593838,  49.57184232,  50.72586434,<br>
52.02748384,  53.4659222 ,  55.03045156,  56.7106371 ,<br>
58.49651376,  60.3787039 ,  62.34848551,  64.39782145,<br>
66.51935936,  68.70641114,  70.95291885,  73.25341258,<br>
75.60296434,  77.99714084,  80.43195721,  57.70326592,<br>
56.19085922,  54.80108048,  53.54347937,  52.42756856,<br>
51.46256608,  50.65709693,  50.01886875,  49.55434383,<br>
49.26843568,  49.16426056,  49.24297187,  49.50369724,<br>
49.9435862 ,  50.55796242,  51.34056219,  52.28383199,<br>
53.37925486,  54.61767673,  55.98960951,  57.485495  ,<br>
59.09592116,  60.81178882,  62.6244315 ,  64.52569397,<br>
66.50797655,  68.5642524 ,  70.68806454,  72.87350843,<br>
75.1152048 ,  77.4082667 ,  79.7482634 ,  82.13118335,<br>
60.1988242 ,  58.75069529,  57.42290448,  56.22397816,<br>
55.16231941,  54.24598828,  53.48245512,  52.87833931,<br>
52.43915073,  52.16905492,  52.07068324,  52.14500758,<br>
52.39129295,  52.80713341,  53.38856714,  54.13025829,<br>
55.02572694,  56.0676055 ,  57.24790082,  58.55824374,<br>
59.99011312,  61.53502608,  63.18469115,  64.93112472,<br>
66.76673363,  68.68436854,  70.67735312,  72.73949412,<br>
74.86507709,  77.04885158,  79.28600943,  81.57215856,<br>
83.90329442,  62.73858439,  61.35043385,  60.08012563,<br>
58.93528024,  57.92333743,  57.05136967,  56.32587809,<br>
55.75258115,  55.33620936,  55.08032161,  54.98715841,<br>
55.05754582,  55.29085923,  55.68505074,  56.23673744,<br>
56.94134175,  57.7932709 ,  58.78612016,  59.91288413,<br>
61.1661626 ,  62.53834991,  64.02180075,  65.60896839,<br>
67.2925144 ,  69.06539116,  70.92089973,  72.85272665,<br>
74.85496338,  76.92211193,  79.04908011,  81.23116907,<br>
83.46405567,  85.7437715 ,  65.31739055,  63.98521134,<br>
62.7682486 ,  61.6733232 ,  60.70703877,  59.87562374,<br>
59.18476223,  58.63942225,  58.24369153,  58.00063246,<br>
57.91216735,  57.97900386,  58.20060696,  58.57522013,<br>
59.0999338 ,  59.77079501,  60.58294891,  61.53080091,<br>
62.60818814,  63.80854946,  65.12508538,  66.55090163,<br>
68.07913241,  69.70304177,  71.41610318,  73.21205881,<br>
75.08496066,  77.02919628,  79.03950178,  81.11096475,<br>
83.23901948,  85.41943647,  87.64830796,  67.930796  ,<br>
66.65087252,  65.48346791,  64.43469819,  63.51044082,<br>
62.7162009 ,  62.05697073,  61.53708945,  61.1601107 ,<br>
60.92868702,  60.84447932,  60.9080982 ,  61.11908203,<br>
61.47591357,  61.9760737 ,  62.6161279 ,  63.39183887,<br>
64.298297  ,  65.33006015,  66.48129452,  67.74590971,<br>
69.11768258,  70.59036624,  72.15778245,  73.81389659,<br>
75.55287613,  77.36913373,  79.25735686,  81.21252599,<br>
83.22992334,  85.30513409,  87.43404179,  89.61281954,<br>
70.57495719,  69.34385585,  68.22254837,  67.21652972,<br>
66.33104575,  65.5709798 ,  64.9407357 ,  64.44412243,<br>
64.08424672,  63.8634202 ,  63.78308711,  63.84377779,<br>
64.04509134,  64.38570871,  64.86343537,  65.47527022,<br>
66.21749597,  67.08578489,  68.07531341,  69.18087928,<br>
70.3970157 ,  71.71809801,  73.13843957,  74.65237508,<br>
76.25433015,  77.93887752,  79.70078037,  81.53502409,<br>
83.43683788,  85.40170769,  87.42538212,  89.50387254,<br>
91.63344893,  73.24654339,  72.06109825,  70.98272778,<br>
70.01637955,  69.166749  ,  68.43818326,  67.83458329,<br>
67.35930858,  67.01508945,  66.8039518 ,  66.72715892,<br>
66.78517425,  66.97764748,  67.30342505,  67.7605843 ,<br>
68.34648892,  69.05786204,  69.89087259,  70.84122975,<br>
71.90428078,  73.07510764,  74.34861881,  75.71963339,<br>
77.18295565,  78.73343892,  80.36603864,  82.07585472,<br>
83.85816412,  85.70844446,  87.62238991,  89.59592053,<br>
91.62518615,  93.70656593,  75.94266032,  74.799956  ,<br>
73.76163759,  72.83216969,  72.01576705,  71.31631276,<br>
70.73727608,  70.28163337,  69.95179591,  69.74954848,<br>
69.67600214,  69.73156413,  69.91592664,  70.2280753 ,<br>
70.66631674,  71.22832361,  71.91119416,  72.71152321,<br>
73.62548044,  74.64889237,  75.7773244 ,  77.00615985,<br>
78.33067354,  79.74609821,  81.24768268,  82.83074129,<br>
84.49069454,  86.22310147,  88.02368425,  89.88834602,<br>
91.81318267,  93.79448957,  95.82876414,  78.66078561,<br>
77.55813919,  76.55723817,  75.6621205 ,  74.87658005,<br>
74.20409694,  73.64776822,  73.21024195,  72.89365739,<br>
72.69959456,  72.6290356 ,  72.68234018,  72.85923644,<br>
73.15882788,  73.57961578,  74.11953603,  74.77600807,<br>
75.54599357,  76.4260617 ,  77.4124581 ,  78.50117471,<br>
79.68801787,  80.96867267,  82.33876193,  83.79389881,<br>
85.32973245,  86.94198641,  88.62649019,  90.37920405,<br>
92.19623792,  94.07386486,  96.00852989,  97.99685491]</p>
<p>torch.cdist:<br>
tensor([ 34.0480,  31.4167,  28.8575,  26.3913,  24.0468,  21.8631,  19.8932,<br>
18.2067,  16.8888,  16.0305,  15.7074,  15.9521,  16.7396,  17.9989,<br>
19.6394,  21.5743,  23.7318,  26.0566,  28.5077,  31.0554,  33.6776,<br>
36.3583,  39.0854,  41.8499,  44.6449,  47.4648,  50.3056,  53.1639,<br>
56.0370,  58.9228,  61.8194,  64.7254,  67.6397,  33.3391,  30.6471,<br>
28.0177,  25.4703,  23.0322,  20.7419,  18.6540,  16.8439,  15.4098,<br>
14.4641,  14.1051,  14.3771,  15.2462,  16.6190,  18.3831,  20.4373,<br>
22.7031,  25.1232,  27.6572,  30.2765,  32.9608,  35.6954,  38.4695,<br>
41.2753,  44.1066,  46.9589,  49.8286,  52.7127,  55.6092,  58.5160,<br>
61.4318,  64.3554,  67.2857,  32.8896,  30.1575,  27.4813,  24.8790,<br>
22.3766,  20.0115,  17.8383,  15.9358,  14.4116,  13.3956,  13.0072,<br>
13.3016,  14.2365,  15.6979,  17.5548,  19.6956,  22.0377,  24.5236,<br>
27.1137,  29.7808,  32.5061,  35.2759,  38.0807,  40.9131,  43.7679,<br>
46.6409,  49.5290,  52.4296,  55.3409,  58.2611,  61.1891,  64.1237,<br>
67.0641,  32.7102,  29.9617,  27.2663,  24.6414,  22.1121,  19.7152,<br>
17.5053,  15.5621,  13.9973,  12.9488,  12.5466,  12.8516,  13.8170,<br>
15.3185,  17.2163,  19.3945,  21.7691,  24.2825,  26.8958,  29.5826,<br>
32.3245,  35.1087,  37.9258,  40.7690,  43.6332,  46.5146,  49.4100,<br>
52.3173,  55.2344,  58.1600,  61.0928,  64.0318,  66.9763,  32.8054,<br>
30.0656,  27.3804,  24.7675,  22.2525,  19.8726,  17.6824,  15.7611,<br>
14.2182,  13.1873,  12.7926,  13.0918,  14.0407,  15.5206,  17.3964,<br>
19.5545,  21.9117,  24.4105,  27.0114,  29.6877,  32.4208,  35.1974,<br>
38.0079,  40.8454,  43.7046,  46.5815,  49.4730,  52.3768,  55.2908,<br>
58.2136,  61.1438,  64.0805,  67.0228,  33.1726,  30.4659,  27.8193,<br>
25.2520,  22.7905,  20.4732,  18.3548,  16.5119,  15.0463,  14.0761,<br>
13.7070,  13.9867,  14.8786,  16.2825,  18.0794,  20.1646,  22.4579,<br>
24.9019,  27.4563,  30.0931,  32.7924,  35.5399,  38.3253,  41.1409,<br>
43.9809,  46.8409,  49.7173,  52.6076,  55.5095,  58.4213,  61.3416,<br>
64.2693,  67.2033,  33.8032,  31.1513,  28.5683,  26.0748,  23.6989,<br>
21.4799,  19.4713,  17.7447,  16.3897,  15.5038,  15.1695,  15.4227,<br>
16.2359,  17.5314,  19.2119,  21.1859,  23.3792,  25.7359,  28.2149,<br>
30.7868,  33.4301,  36.1292,  38.8724,  41.6510,  44.4585,  47.2895,<br>
50.1403,  53.0075,  55.8886,  58.7816,  61.6849,  64.5970,  67.5168,<br>
34.6827,  32.1035,  29.6037,  27.2052,  24.9373,  22.8389,  20.9610,<br>
19.3677,  18.1343,  17.3378,  17.0395,  17.2653,  17.9955,  19.1724,<br>
20.7202,  22.5627,  24.6337,  26.8806,  29.2628,  31.7499,  34.3191,<br>
36.9533,  39.6396,  42.3679,  45.1308,  47.9221,  50.7373,  53.5726,<br>
56.4249,  59.2918,  62.1712,  65.0615,  67.9614,  35.7927,  33.2996,<br>
30.8968,  28.6069,  26.4594,  24.4918,  22.7507,  21.2918,  20.1763,<br>
19.4636,  19.1983,  19.3990,  20.0516,  21.1143,  22.5291,  24.2344,<br>
26.1735,  28.2984,  30.5703,  32.9589,  35.4406,  37.9971,  40.6143,<br>
43.2813,  45.9893,  48.7315,  51.5025,  54.2978,  57.1139,  59.9479,<br>
62.7972,  65.6600,  68.5345,  37.1127,  34.7145,  32.4167,  30.2421,<br>
28.2194,  26.3833,  24.7755,  23.4429,  22.4347,  21.7959,  21.5594,<br>
21.7383,  22.3226,  23.2819,  24.5722,  26.1445,  27.9514,  29.9504,<br>
32.1057,  34.3878,  36.7732,  39.2430,  41.7823,  44.3791,  47.0239,<br>
49.7091,  52.4284,  55.1769,  57.9502,  60.7452,  63.5588,  66.3888,<br>
69.2330,  38.6210,  36.3225,  34.1332,  32.0752,  30.1756,  28.4660,<br>
26.9825,  25.7644,  24.8505,  24.2754,  24.0632,  24.2237,  24.7494,<br>
25.6179,  26.7959,  28.2448,  29.9251,  31.8003,  33.8379,  36.0104,<br>
38.2949,  40.6724,  43.1276,  45.6479,  48.2232,  50.8451,  53.5068,<br>
56.2025,  58.9276,  61.6783,  64.4512,  67.2436,  70.0532,  40.2966,<br>
38.0993,  36.0181,  34.0742,  32.2924,  30.7009,  29.3307,  28.2141,<br>
27.3821,  26.8612,  26.6697,  26.8145,  27.2903,  28.0804,  29.1591,<br>
30.4959,  32.0585,  33.8156,  35.7385,  37.8019,  39.9841,  42.2667,<br>
44.6343,  47.0740,  49.5753,  52.1292,  54.7285,  57.3668,  60.0391,<br>
62.7411,  65.4690,  68.2197,  70.9907,  42.1194,  40.0224,  38.0465,<br>
36.2116,  34.5402,  33.0571,  31.7887,  30.7614,  30.0002,  29.5255,<br>
29.3514,  29.4830,  29.9165,  30.6389,  31.6305,  32.8669,  34.3217,<br>
35.9684,  37.7819,  39.7393,  41.8206,  44.0080,  46.2866,  48.6436,<br>
51.0680,  53.5508,  56.0842,  58.6616,  61.2774,  63.9271,  66.6064,<br>
69.3121,  72.0410,  44.0713,  42.0716,  40.1966,  38.4644,  36.8953,<br>
35.5106,  34.3329,  33.3841,  32.6840,  32.2489,  32.0895,  32.2099,<br>
32.6071,  33.2712,  34.1865,  35.3336,  36.6907,  38.2355,  39.9462,<br>
41.8025,  43.7858,  45.8796,  48.0696,  50.3431,  52.6894,  55.0992,<br>
57.5645,  60.0784,  62.6351,  65.2296,  67.8576,  70.5152,  73.1993,<br>
46.1358,  44.2295,  42.4500,  40.8135,  39.3382,  38.0426,  36.9457,<br>
36.0656,  35.4186,  35.0174,  34.8707,  34.9816,  35.3477,  35.9611,<br>
36.8096,  37.8774,  39.1464,  40.5979,  42.2129,  43.9736,  45.8631,<br>
47.8662,  49.9691,  52.1600,  54.4280,  56.7640,  59.1599,  61.6088,<br>
64.1045,  66.6418,  69.2162,  71.8236,  74.4605,  48.2984,  46.4810,<br>
44.7910,  43.2432,  41.8536,  40.6383,  39.6133,  38.7938,  38.1930,<br>
37.8213,  37.6855,  37.7881,  38.1273,  38.6967,  39.4865,  40.4837,<br>
41.6734,  43.0397,  44.5664,  46.2375,  48.0381,  49.9540,  51.9726,<br>
54.0823,  56.2729,  58.5353,  60.8616,  63.2446,  65.6782,  68.1569,<br>
70.6761,  73.2315,  75.8195,  50.5467,  48.8131,  47.2066,  45.7407,<br>
44.4292,  43.2863,  42.3255,  41.5595,  40.9992,  40.6532,  40.5269,<br>
40.6223,  40.9380,  41.4689,  42.2068,  43.1411,  44.2595,  45.5483,<br>
46.9936,  48.5813,  50.2980,  52.1309,  54.0683,  56.0992,  58.2140,<br>
60.4038,  62.6607,  64.9777,  67.3487,  69.7682,  72.2312,  74.7335,<br>
77.2712,  52.8697,  51.2147,  49.6860,  48.2953,  47.0551,  45.9775,<br>
45.0741,  44.3556,  43.8311,  43.5076,  43.3896,  43.4788,  43.7739,<br>
44.2707,  44.9627,  45.8409,  46.8949,  48.1132,  49.4836,  50.9939,<br>
52.6319,  54.3862,  56.2460,  58.2010,  60.2420,  62.3606,  64.5492,<br>
66.8007,  69.1092,  71.4691,  73.8754,  76.3238,  78.8103,  55.2579,<br>
53.6766,  52.2200,  50.8986,  49.7234,  48.7049,  47.8530,  47.1768,<br>
46.6840,  46.3805,  46.2698,  46.3534,  46.6303,  47.0970,  47.7480,<br>
48.5759,  49.5718,  50.7259,  52.0275,  53.4659,  55.0304,  56.7106,<br>
58.4965,  60.3787,  62.3485,  64.3978,  66.5193,  68.7064,  70.9529,<br>
73.2534,  75.6030,  77.9971,  80.4319,  57.7033,  56.1908,  54.8011,<br>
53.5435,  52.4276,  51.4626,  50.6571,  50.0189,  49.5543,  49.2684,<br>
49.1642,  49.2430,  49.5037,  49.9436,  50.5580,  51.3406,  52.2838,<br>
53.3792,  54.6177,  55.9896,  57.4855,  59.0959,  60.8118,  62.6244,<br>
64.5257,  66.5080,  68.5642,  70.6881,  72.8735,  75.1152,  77.4083,<br>
79.7483,  82.1312,  60.1988,  58.7507,  57.4229,  56.2240,  55.1623,<br>
54.2460,  53.4824,  52.8783,  52.4391,  52.1690,  52.0707,  52.1450,<br>
52.3913,  52.8071,  53.3886,  54.1303,  55.0257,  56.0676,  57.2479,<br>
58.5582,  59.9901,  61.5350,  63.1847,  64.9311,  66.7667,  68.6844,<br>
70.6773,  72.7395,  74.8651,  77.0488,  79.2860,  81.5722,  83.9033,<br>
62.7386,  61.3504,  60.0801,  58.9353,  57.9233,  57.0514,  56.3259,<br>
55.7526,  55.3362,  55.0803,  54.9871,  55.0575,  55.2909,  55.6850,<br>
56.2367,  56.9413,  57.7933,  58.7861,  59.9129,  61.1662,  62.5383,<br>
64.0218,  65.6090,  67.2925,  69.0654,  70.9209,  72.8527,  74.8550,<br>
76.9221,  79.0491,  81.2312,  83.4640,  85.7438,  65.3174,  63.9852,<br>
62.7682,  61.6733,  60.7070,  59.8756,  59.1847,  58.6394,  58.2437,<br>
58.0006,  57.9122,  57.9790,  58.2006,  58.5752,  59.0999,  59.7708,<br>
60.5829,  61.5308,  62.6082,  63.8085,  65.1251,  66.5509,  68.0791,<br>
69.7030,  71.4161,  73.2121,  75.0850,  77.0292,  79.0395,  81.1109,<br>
83.2390,  85.4194,  87.6483,  67.9308,  66.6509,  65.4835,  64.4347,<br>
63.5104,  62.7162,  62.0570,  61.5371,  61.1601,  60.9287,  60.8445,<br>
60.9081,  61.1191,  61.4759,  61.9761,  62.6161,  63.3918,  64.2983,<br>
65.3301,  66.4813,  67.7459,  69.1177,  70.5904,  72.1578,  73.8139,<br>
75.5529,  77.3691,  79.2573,  81.2125,  83.2299,  85.3051,  87.4340,<br>
89.6128,  70.5750,  69.3438,  68.2225,  67.2165,  66.3310,  65.5710,<br>
64.9407,  64.4441,  64.0842,  63.8634,  63.7831,  63.8438,  64.0451,<br>
64.3857,  64.8634,  65.4753,  66.2175,  67.0858,  68.0753,  69.1809,<br>
70.3970,  71.7181,  73.1384,  74.6524,  76.2543,  77.9389,  79.7008,<br>
81.5350,  83.4368,  85.4017,  87.4254,  89.5039,  91.6334,  73.2465,<br>
72.0611,  70.9827,  70.0164,  69.1667,  68.4382,  67.8346,  67.3593,<br>
67.0151,  66.8039,  66.7271,  66.7852,  66.9776,  67.3034,  67.7606,<br>
68.3465,  69.0579,  69.8909,  70.8412,  71.9043,  73.0751,  74.3486,<br>
75.7196,  77.1829,  78.7334,  80.3660,  82.0758,  83.8581,  85.7084,<br>
87.6224,  89.5959,  91.6252,  93.7066,  75.9426,  74.7999,  73.7616,<br>
72.8322,  72.0158,  71.3163,  70.7373,  70.2816,  69.9518,  69.7495,<br>
69.6760,  69.7316,  69.9159,  70.2281,  70.6663,  71.2283,  71.9112,<br>
72.7115,  73.6255,  74.6489,  75.7773,  77.0061,  78.3307,  79.7461,<br>
81.2477,  82.8307,  84.4907,  86.2231,  88.0237,  89.8883,  91.8132,<br>
93.7945,  95.8288,  78.6608,  77.5581,  76.5572,  75.6621,  74.8766,<br>
74.2041,  73.6478,  73.2102,  72.8937,  72.6996,  72.6290,  72.6823,<br>
72.8592,  73.1588,  73.5796,  74.1195,  74.7760,  75.5460,  76.4261,<br>
77.4125,  78.5012,  79.6880,  80.9687,  82.3388,  83.7939,  85.3297,<br>
86.9420,  88.6265,  90.3792,  92.1962,  94.0739,  96.0085,  97.9968,<br>
81.3987,  80.3336,  79.3678,  78.5047,  77.7479,  77.1004,  76.5652,<br>
76.1444,  75.8401,  75.6536,  75.5858,  75.6370,  75.8070,  76.0950,<br>
76.4996,  77.0191,  77.6510,  78.3928,  79.2412,  80.1930,  81.2445,<br>
82.3918,  83.6311,  84.9582,  86.3693,  87.8601,  89.4267,  91.0653,<br>
92.7719,  94.5430,  96.3749,  98.2643, 100.2079,  84.1545,  83.1248,<br>
82.1917,  81.3586,  80.6286,  80.0044,  79.4887,  79.0835,  78.7905,<br>
78.6110,  78.5458,  78.5951,  78.7587,  79.0359,  79.4256,  79.9260,<br>
80.5352,  81.2506,  82.0695,  82.9889,  84.0053,  85.1155,  86.3156,<br>
87.6021,  88.9712,  90.4192,  91.9422,  93.5367,  95.1991,  96.9258,<br>
98.7135, 100.5589, 102.4590,  86.9265,  85.9300,  85.0277,  84.2226,<br>
83.5176,  82.9153,  82.4177,  82.0270,  81.7446,  81.5716,  81.5087,<br>
81.5562,  81.7139,  81.9811,  82.3569,  82.8396,  83.4275,  84.1183,<br>
84.9096,  85.7985,  86.7821,  87.8571,  89.0203,  90.2683,  91.5975,<br>
93.0046,  94.4860,  96.0383,  97.6580,  99.3420, 101.0870, 102.8899,<br>
104.7477,  89.7131,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000,<br>
0.0000,   0.0000,   0.0000,   0.0000,   0.0000,   0.0000]</p>

ptrblck: <p>Could you describe how the other <code>cdist</code> call is used? I’m familiar with <code>torch.cdist</code>, but <code>cdist</code> should not be a tensor method so unsure how you are using it or where it’s defined.</p>

Tianming_Qu: <p>basically for cdist I have two np.ndarray A and B, and I simply do:<br>
cdist(A,B);</p>
<p>And then I convert A and B to pytorch.tensor using torch.from_numpy(), and I do:<br>
torch.cdist(A_torch, B_torch)</p>
<p>Thanks!</p>

Tianming_Qu: <p>I just solve the problem.</p>
<p>One more question, is there anyway I can avoid the “memory allocate problem” by using pytorch? The pytorch.cdist and other pytorch tensor really use a lot of memory.</p>
<p>Thanks!</p>

ptrblck: <aside class="quote no-group" data-username="Tianming_Qu" data-post="3" data-topic="162644">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tianming_qu/48/36947_2.png" class="avatar"> Tianming_Qu:</div>
<blockquote>
<p>basically for cdist I have two np.ndarray A and B, and I simply do:<br>
cdist(A,B);</p>
</blockquote>
</aside>
<p><code>cdist</code> is not a built-in Python method so I still don’t know where it’s coming from:</p>
<pre data-code-wrap="python"><code class="lang-python">cdist
NameError: name 'cdist' is not defined
</code></pre>
<aside class="quote no-group" data-username="Tianming_Qu" data-post="4" data-topic="162644">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tianming_qu/48/36947_2.png" class="avatar"> Tianming_Qu:</div>
<blockquote>
<p>The pytorch.cdist and other pytorch tensor really use a lot of memory.</p>
</blockquote>
</aside>
<p>You could try to reduce the tensor shapes to avoid running out of memory.</p>