Rank: 185 based on 301 downloads (last 30 days) and 25 files submitted
photo

James Tursa

E-mail
Lat/Long
47.68167, -122.2075

Personal Profile:

Interested in external applications, mex & engine applications with Fortran, C, C++, etc.

Professional Interests:

 

Watch this Author's files

 

Files Posted by James View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
11 Dec 2011 Screenshot Fortran 95 Interface to MATLAB API with extras! This is the one you have been waiting for, a clean interface using assumed shape Fortran pointers. Author: James Tursa fortran 95, fortran, 95, mex, engine, api 16 28
  • 5.0
5.0 | 4 ratings
09 May 2011 Screenshot UNINIT - Create an uninitialized variable (like ZEROS but faster) UNINIT is similar to ZEROS, except UNINIT returns uninitialized values instead of zero values. Author: James Tursa uninit, zeros, ones, allocate, preallocate 2 1
20 Mar 2011 Screenshot typecast and typecastx C-mex functions typecast and typecastx are mex functions that mimic the MATLAB typecast function with extensions Author: James Tursa external interface, typecast, cast, mex, external code interfa... 17 3
  • 5.0
5.0 | 1 rating
08 Mar 2011 mxGetPropertyPtr C-mex function Fast memory efficient alternative to the API function mxGetProperty. Author: James Tursa mxgetpropertyptr, object, mxgetproperty, classdef 5 1
  • 4.5
4.5 | 2 ratings
23 Feb 2011 Screenshot MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa mtimes, multiply, speed, blas, bsxfun, as the code is pretty... 91 69
  • 4.9375
4.9 | 19 ratings
Comments and Ratings by James View all
Updated File Comments Rating
08 Feb 2012 MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa

@ Jonathan: Yes, weird indeed. For slices 100x100 in size, MTIMESX will always use BLAS dgemm calls regardless of the method setting (you can verify this by using the 'DEBUG' setting). That is, the exact same code path gets executed ragardless of whether 'MATLAB', 'SPEED', or 'SPEEDOMP' is set. That setting should have had no effect on this particular outcome. Also, I have been unable to reproduce this error on a 32-bit WinXP system. Can you provide me some specifics on your MATLAB version, machine OS, compiler used, etc? Does it crash if you restart MATLAB and immediatly try the example?

08 Feb 2012 MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa

@ Jonathan Sullivan: Your first example without repmat should have worked. Looks like I introduced a bug in the latest release. I will look into this right away ...

19 Oct 2011 MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa

@ Michael Völker: FYI, another way to use the DSDOT routine is to use this submission:

http://www.mathworks.com/matlabcentral/fileexchange/16777-lapack

Not sure if it works on 64-bit systems, but you might give it a try.

19 Oct 2011 MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa

@ Michael Völker: Thanks for the comments. I will look into your request. There is a BLAS routine called DSDOT that does what you request. I will look into how easily I can incorporate this into MTIMESX for BLAS specific results. For the SPEED modes MTIMESX sometimes uses custom code to calculate the dot product (e.g., see function RealKindDotProduct), and in fact the accumulation is done in double precision regardless of input type (calculations themselves are single for single inputs), so it might not be too difficult to adapt this to return the double precision output if requested instead of always converting back to single for single inputs. Thanks for the suggestion.

08 Sep 2011 swapping swapping of two numbers in matlab Author: sumit verma

This is an un-commented script rather than a function. This does "cute" numerical operations to do the swap, but the method suffers from cancellation error and completely breaks down if the values are too widely separated (e.g., 1e20 and 1). In short, this is useless code and should be removed from the FEX.

Comments and Ratings on James' Files View all
Updated File Comment by Comments Rating
08 Feb 2012 MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa Sullivan, Jonathan

@ James
The array sizes I'm working with are much larger what I posted. The size of A is 100x33x3. The size of B is 33x1x3x5000x5. That might be why you had trouble recreating it. I'm running on Windows 7, 64 bit, MATLAB 2011b, compiler is cl. If it makes a difference, some of the values in the first matrix are -inf.

08 Feb 2012 MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa Tursa, James

@ Jonathan: Yes, weird indeed. For slices 100x100 in size, MTIMESX will always use BLAS dgemm calls regardless of the method setting (you can verify this by using the 'DEBUG' setting). That is, the exact same code path gets executed ragardless of whether 'MATLAB', 'SPEED', or 'SPEEDOMP' is set. That setting should have had no effect on this particular outcome. Also, I have been unable to reproduce this error on a 32-bit WinXP system. Can you provide me some specifics on your MATLAB version, machine OS, compiler used, etc? Does it crash if you restart MATLAB and immediatly try the example?

08 Feb 2012 MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa Sullivan, Jonathan

@ James
So the problem, at least in part, is caused by using the 'SPEEDOMP' flag. I removed the flag, and now it works. Weird, huh?

08 Feb 2012 MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa Tursa, James

@ Jonathan Sullivan: Your first example without repmat should have worked. Looks like I introduced a bug in the latest release. I will look into this right away ...

08 Feb 2012 MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa Sullivan, Jonathan

James,

Fantastic code. It has come in handy. It is well documented, incredibly fast, and extremely useful, especially for N-D arrays.

For the N-D case, this code would be even more powerful if the singleton dimension capability were expanded. Currently, all the dimensions from 3:end must be either the same size (A to B), or must all be singleton for one of the variables.

For example
A = rand(100,100,3);
B = rand(100,100,3,5);
C = mtimesx(A,B); % Does not work. Crashes MATLAB.

You can get around this by using repmat:
A = rand(100,100,3);
B = rand(100,100,3,5);
C = mtimesx(repmat(A,[1 1 1 5]),B); % Works, but slow

Unfortunately, explicitly expanding out large arrays has overhead which is more than I'd like.

Overall code. A+.

Top Tags Applied by James
external interface, mex, fortran, precision, engine
Files Tagged by James View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
11 Dec 2011 Screenshot Fortran 95 Interface to MATLAB API with extras! This is the one you have been waiting for, a clean interface using assumed shape Fortran pointers. Author: James Tursa fortran 95, fortran, 95, mex, engine, api 16 28
  • 5.0
5.0 | 4 ratings
09 May 2011 Screenshot UNINIT - Create an uninitialized variable (like ZEROS but faster) UNINIT is similar to ZEROS, except UNINIT returns uninitialized values instead of zero values. Author: James Tursa uninit, zeros, ones, allocate, preallocate 2 1
20 Mar 2011 Screenshot typecast and typecastx C-mex functions typecast and typecastx are mex functions that mimic the MATLAB typecast function with extensions Author: James Tursa external interface, typecast, cast, mex, external code interfa... 17 3
  • 5.0
5.0 | 1 rating
08 Mar 2011 mxGetPropertyPtr C-mex function Fast memory efficient alternative to the API function mxGetProperty. Author: James Tursa mxgetpropertyptr, object, mxgetproperty, classdef 5 1
  • 4.5
4.5 | 2 ratings
23 Feb 2011 Screenshot MTIMESX - Fast Matrix Multiply with Multi-Dimensional Support Beats MATLAB 300% - 400% in some cases ... really! Author: James Tursa mtimes, multiply, speed, blas, bsxfun, as the code is pretty... 91 69
  • 4.9375
4.9 | 19 ratings

Contact us at files@mathworks.com