3

I am looking for a faster way of calculating cosine similarity (because I have a large matrix of 2.8Gb).

I found a coop package where was written something about "A good BLAS library," so I started digging and found out that I should use openBLAS library to make it faster. I read the installation guide and many other articles.

How can I install and run it in R on macbook?

C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
  • I don't think there's an R API for that. Try writing your own cosine similarity function. See: https://stats.stackexchange.com/questions/31565/is-there-an-r-function-that-will-compute-the-cosine-dissimilarity-matrix – C8H10N4O2 Aug 10 '17 at 17:16
  • I don't think there's much improvement possible for this question, but I tried. – C8H10N4O2 Aug 10 '17 at 17:18

2 Answers2

2

osX has a great blas library already installed which you can use as an alternative. you only need to link it:

# use faster vecLib library
cd /Library/Frameworks/R.framework/Resources/lib
ln -sf  /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib libRblas.dylib

see here for source and details

dlampart
  • 81
  • 3
  • thanks! And is that everything I should do? Just write this 2 rows in terminal? – Martina Zapletalová Aug 10 '17 at 09:20
  • 2
    this workaround is not working with BigSur and above as they don't ship with the accelerate framework – blazej Oct 28 '21 at 16:17
  • 1
    @blazej R binaries on CRAN provides vecLib-based BLAS now. Can change to it by creating a symlink.https://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#Which-BLAS-is-used-and-how-can-it-be-changed_003f – Fred Dec 10 '21 at 03:38
0

Do not use OpenBLAS on osX. Apple already has a very optimized version of BLAS which is vecLib.

Pedro Rafael
  • 492
  • 4
  • 11