[bug #68035] [Statistics] pdist2 memory requirement and speed

Liang Tang <[email protected]>
Newsgroups gmane.comp.gnu.octave.bugs
Message-ID <[email protected]>
Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only notification stream.  Info posted to this mailing list address won't appear in the tracker database where it is most useful.

URL:
  <https://savannah.gnu.org/bugs/?68035>

                 Summary: [Statistics] pdist2 memory requirement and speed
                   Group: GNU Octave
               Submitter: lt1234
               Submitted: Mon 09 Feb 2026 03:57:59 PM UTC
                Category: Octave Package
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Performance
                  Status: None
             Assigned to: None
         Originator Name: lt1234
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Unlocked
                 Release: 10.3.0
        Operating System: Microsoft Windows
           Fixed Release: None
         Planned Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Mon 09 Feb 2026 03:57:59 PM UTC By: Liang Tang <lt1234>
I believe that this item must have been considered in the past.

My recommendation is to modify the existing code just  to handle the default
'euclidean' only.  The required changes would not have a major impact to the
current code structure.  Thanks.  

From an example in
https://stackoverflow.com/questions/7696734/pdist2-equivalent-in-matlab-version-7

A = rand(4754,1024);
B = rand(6800,1024);

tic; D = pdist2(A,B,'euclidean'); toc

We have an error message: 

>> tic; D = pdist2(A,B,'euclidean'); toc
error: out of memory or dimension too large for Octave's index type
error: called from
    pdist2 at line 188 column 9

>> tic; DD = sqrt( bsxfun(@plus,sum(A.^2,2),sum(B.^2,2)') - 2*(A*B') ); toc
Elapsed time is 0.81075 seconds.    
    
    
After the dimension of the example problem is reduced to 

A = rand(1024,512);
B = rand(1024,512);

tic; D = pdist2(A,B,'euclidean'); toc
tic; DD = sqrt( bsxfun(@plus,sum(A.^2,2),sum(B.^2,2)') - 2*(A*B') ); toc

Elapsed time is 5.70096 seconds.
Elapsed time is 0.0249472 seconds.

A = rand(1024,1024);
B = rand(1024,1024);

Elapsed time is 12.458 seconds.
Elapsed time is 0.032671 seconds.

The same formulation can also be found in pdollar's vision toolbox.  










    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?68035>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCaYoECwAKCRCqLAuaBUf3
TiN1AQCF97wV3Yj0Xpy13O+okbl4hFMtV8upM101hZH3PzAXqgD9H0X2s89HaQyH
2vq7zMxCR1MgGGxEkE6YiLoFiKJYRAA=
=Vm8k
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.