{"id":13688153,"url":"https://github.com/tminka/lightspeed","last_synced_at":"2026-03-11T10:10:57.599Z","repository":{"id":90879584,"uuid":"77951273","full_name":"tminka/lightspeed","owner":"tminka","description":"lightspeed matlab toolbox","archived":false,"fork":false,"pushed_at":"2021-06-07T17:12:24.000Z","size":112,"stargazers_count":128,"open_issues_count":1,"forks_count":36,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-11-12T11:40:25.546Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"MATLAB","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tminka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-01-03T20:35:21.000Z","updated_at":"2024-09-28T03:54:36.000Z","dependencies_parsed_at":"2024-01-14T18:09:28.518Z","dependency_job_id":null,"html_url":"https://github.com/tminka/lightspeed","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tminka%2Flightspeed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tminka%2Flightspeed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tminka%2Flightspeed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tminka%2Flightspeed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tminka","download_url":"https://codeload.github.com/tminka/lightspeed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251906714,"owners_count":21663150,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T15:01:07.871Z","updated_at":"2026-03-11T10:10:57.514Z","avatar_url":"https://github.com/tminka.png","language":"MATLAB","funding_links":[],"categories":["MATLAB","Dirichlet hyperparameter optimization techniques"],"sub_categories":["Embedding based Topic Models"],"readme":"Lightspeed matlab toolbox\n=========================\n\nThis library provides:\n\n* highly optimized versions of mathematical functions such as `normcdf`, set intersection, and `gammaln`\n* efficient random number generators\n* evaluation of common probability densities\n* routines for counting floating-point\noperations (FLOPS), useful for benchmarking algorithms.\n* utilities such as filename globbing and parsing of variable-length argument lists.\n* graphics functions such as `axis_pct` and `mobile_text` (in the graphics subdirectory).\n\nSee Contents.m for a table of contents.\n\nAlso see my general tips on [accelerating matlab](http://tminka.github.io/software/matlab/).\n\nFlop counting\n=============\n\nMatlab is frequently used for research, so I have included routines\nthat faciliate research.\nIn particular, Lightspeed features a set of routines for accurate\nfloating-point operation (flop) counting.  These flop counts allow\nmachine-independent and programmer-independent comparison of numerical\nalgorithms, because they represent the minimal number of operations that\nthe algorithm needs.  Consequently, you can compare algorithms based on\ntheir Matlab implementations alone, without having to code them efficiently\nin C and report their run time on a particular processor.\nHopefully these routines will allow more informative algorithm \ncomparisons in research papers.\n\nThe flop count routines in lightspeed are significantly more accurate than\nthe `flops` function which was included in Matlab up to version 5.\nFor example, according to Matlab 5, `inv(3)` requires more flops\nthan `1/3`.  Matlab 5 also returned slightly\nincorrect flop counts for matrix multiplies and overly pessimistic flop\ncounts for solving linear systems.  Lightspeed always returns the minimal\nnumber of flops for matrix operations, as though the best possible\nalgorithm was used, no matter what method you are actually using.\n\nPerhaps the biggest difference between flop counting in lightspeed versus\nMatlab 5 is the handling of special functions like `exp` and\n`sqrt`.  Matlab 5 counted these as one flop, which is much too low.\nA more accurate count for `exp`, based on the\nPentium 4 processor, is 40 flops.  Similarly, `sqrt` is 8 flops.\nInterestingly, the run time in Matlab 6 for `sqrt` is\nsignificantly longer than `exp`, and even longer than the time\nfor `x^(0.51)` (raising to an arbitrary power other than 0.5).\nThis emphasizes the importance of measuring the `idealized' run time,\nrepresented by flops, rather than the actual run time, which is subject to\nodd inefficiencies in Matlab (or any programming language). \n\nFlop counting in lightspeed is a more manual process than in Matlab 5.  In Matlab 5, the flop counter is incremented automatically after every operation.  Lightspeed does not increment the flop counter automatically.  Instead, you must specify which operations should have their flops counted.  For example, after performing a matrix multiply you should call `addflops(flops_mul(...))`, and after every Cholesky decomposition you should call `addflops(flops_chol(...))`.  Some operations do not have a dedicated flops routine.  For these you should consult the help for `flops`.\n\nManual flop counting has two advantages.  First, it can be different from the operation that you actually performed, allowing you to count the flops for an `idealized' algorithm rather than the one you implemented.  Second, since only the operations that you explicitly count get added to the flop counter, unrelated operations (such as debugging code) will not interfere with the result.  \n\nIncrementing the flop counter on every operation can cause your code to run slower.  To avoid this, you can batch up the count for many operations.  For example, to get the flop count for a loop, you can save time by computing the flops for one iteration of the loop and then multiply by the number of iterations.  For examples, see [fastfit/dirichlet_fit_newton.m](https://github.com/tminka/fastfit/blob/master/dirichlet_fit_newton.m) or [logreg/train_cg.m](https://github.com/tminka/logreg/blob/master/train_cg.m).\n\nInstallation\n============\n\nThe toolbox has been tested on all versions of Matlab from 6.5 to 8.4 with\nWindows XP, Vista, 7, and 8.  It has been tested on 32-bit and 64-bit machines, with Microsoft Visual Studio 2008-2013 (Professional and Express Editions).  It should work on Macs and Linux as well.  Most (but not all) functions work with Matlab 6.1 and 5. \n\nYou can place the lightspeed directory anywhere.\nTo make sure lightspeed is always in your path, create a startup.m\nfile in your matlab directory, if you don't already have one, and add\na line like this:\n\n    addpath(genpath('c:\\matlab\\lightspeed'))\n\nReplace 'c:\\matlab\\lightspeed' with the location of the lightspeed directory.\n\nThere are some Matlab Extension (MEX) files that need to be compiled.\nThis can be done in matlab via:\n\n    cd c:\\matlab\\lightspeed\n    install_lightspeed\n\nI recommend using Microsoft Visual C++ as the mex compiler, though this is not required.  You can set the mex compiler by typing 'mex -setup' in matlab.\n\nYou can find timing tests in the tests/ subdirectory.  \nThe test_lightspeed.m script will run all tests, and is a good way to check \nthat lightspeed installed properly.\n\nTroubleshooting\n===============\n\nIf you are having problems compiling the mex files, check your matlab installation by compiling one of the examples that comes with matlab, such as:\n    mex([matlabroot '/extern/examples/mex/explore.c'])\nIf this does not work, then contact MathWorks for help.  You can find some common fixes below.\n\nTo use Microsoft Visual C++ 2013 with Matlab 8.1 (R2013a), you will need to download this patch:\nhttp://www.mathworks.com/matlabcentral/fileexchange/45878-setting-microsoft-visual-c++-2013-as-default-mex-compiler\n\nTo use Microsoft Visual C++ 2010 with Matlab 7.10 (R2010a), you will need to download this patch:\nhttp://www.mathworks.com/support/solutions/en/data/1-D5W493/?solution=1-D5W493\n\nTo use Microsoft Visual C++ 2008 on Windows 64-bit, you will need to follow the instructions at:\nhttp://www.mathworks.com/matlabcentral/answers/98351-how-can-i-set-up-microsoft-visual-studio-2008-express-edition-for-use-with-matlab-7-7-r2008b-on-64\n\nTo use Microsoft Visual C++ with Matlab 7.0 (R14), you will need to download \nR14 service pack 2, as described here:\nhttp://www.mathworks.com/support/solutions/en/data/1-UMEKK/?solution=1-UMEKK\n\nTo compile mex files on a Snow Leopard upgrade, prior to Matlab R2014a:\n\n1. Go to mexopts.sh in your $HOME/.matlab/ directory, and change the line SDKROOT='/Developer/SDKs/MacOSX10.5.sdk' to SDKROOT='/Developer/SDKs/MacOSX10.6.sdk'. That line is not updated during updating mac OSX, so you need to do manually. This file also exists in the standard matlab bin, so if you run mex with the -v option it will tell you which mexopts.sh file it's looking at.\n\n2. You may also need to change some lines in install_lightspeed.m.  By default, install_lightspeed.m is set up for 64-bit MacOSX 10.6 with gcc-4.0.  If you are using some other version of MacOSX or some other compiler, then you need to edit a few lines (see the comments in that file).\n\nChangelist\n==========\n\n### 2.8\nChanged to MIT license.  intersect_sorted provides multiple outputs, for compatibility with intersect.  Added support for different number types to randbinom and int_hist.  Added graphics/draw_loess.  Fixes to install_lightspeed, flops_solve, hhist, cut_quantile.\n\n### 2.7\nAdded the hist2 function.\nUpdated the installer to handle Matlab versions up to R2014b.  In version R2014a and later, installation on Mac is now much easier.  In version R2013b and later, lightspeed does not replace Matlab's built-in repmat, because the built-in is now faster.  Congratulations to MathWorks---it only took them 11 years to catch up with lightspeed's repmat.  Perhaps now they can try making sum(x,2) run as fast as lightspeed's row_sum.\n\n### 2.6\n\nUpdated the installer to handle MacOSX 10.6 and older versions of matlab (all the way back to 7.0.1).\n\n### 2.5\n\nUpdated the installer to handle Microsoft Visual Studio 2010 Express with Windows SDK 7.1.  All mex files now use -largeArrayDims.  Fixed a bug in multivariate `gammaln` (used by `wishpdf`).\n\n### 2.4\n\nLightspeed's normpdf is now called mvnormpdf, for compatibility with the statistics toolbox.  Added invnormcdf.  Updated the installer.\n\n### 2.3\n\nSupport for Matlab R2009a and 64-bit architectures.\n`install_lightspeed` is more robust to different matlab versions and platforms (pc, mac, unix).\n`setnonzeros` and `sparse_nocheck` are new functions for quickly filling in a sparse matrix.  \nFlop counting is more accurate in some cases.  Added `flops_lu` and `flops_abs`.\nFixed a bug in `union_rows_sorted`.\nAdded the `tetragamma` function.\n\n### 2.2\n\nThe installer now supports Matlab 7.5.\n`randomseed` is a new function that allows you to set the seed for lightspeed's random number generator.\n`cholproj` is a new function that provides an approximate cholesky decomposition even when a matrix is not exactly positive definite, for example due to roundoff errors.\nThe tests have been moved to a subdirectory.\nMore bug-fixes, thanks to people who have sent in bug reports.\n\n### 2.1\n\n`graphics/hhist` has been greatly improved, and now has the same\ninterface as `hist`.  You'll never have to use `hist` again!\n`normcdflogit` is a new function that provides accurate \nevaluation of the normal CDF in the tails.\nA variety of bug-fixes, thanks to people who have sent in bug reports.\n\n### 2.0\n\nMany new functions have been added, including sorted-set functions and\nmutation.  Graphics functions have been moved to a\nsubdirectory.  The formulas for flop counting have been changed, to better\nreflect the Pentium 4 architecture.  In particular, note the addition of\n`flops_div` (division is 8 flops on a Pentium 4),\n`flops_sqrt`, and `flops_log`.\n\n### 1.3\n\nThe main change from version 1.2 is that tri_inv_times has been renamed to\nsolve_triu and solve_tril, and made more efficient.\nThe tricky part is that these have to be linked against Matlab's\ninternal BLAS library.\n\nThe mex files have also been changed to use the Matlab 5 API.\n\n\n\nTom Minka\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftminka%2Flightspeed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftminka%2Flightspeed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftminka%2Flightspeed/lists"}