
Ndimensional sparse arrays 1.0 File ID: 84017 


 Ndimensional sparse arrays 1.0 License: Shareware File Size: 20.5 KB Downloads: 0
Submit Rating: 



Ndimensional sparse arrays 1.0 Description 

Description: The class ndSparse defined in this submission will give a lot of the functionality of Ndimensional sparse arrays for N possibly greater than 2. However, it should really be thought of as a way of starting with an ordinary MATLAB sparse matrix and reshaping it to have N dimensions. In other words, the sparse data must first be able to exist as an ordinary 2D MATLAB sparse matrix before being made Ndimensional. In fact, if the intended array has dimensions MxNxP...YxZ, then the class will store it internally as an ordinary 2D sparse array of dimensions (M*N*P*...*Y)xZ. This leads to certain performance limitations, but I still find that it has a reasonable range of use. USAGE: S=ndSparse(X) where X is an ordinary MATLAB sparse matrix converts X into an ndSparse object. S can be reshaped into an Ndimensional sparse array using its RESHAPE method, for arbitrary N. S=ndSparse(X,[M,N,P,...]) is equivalent to reshape(ndSparse(X),[M,N,P,...]). The class also has a variety of static methods that can be used to construct instances of the class. For example,
S=ndSparse.build(Coordinates,Values,[m,n,p,...],nzmax)
lets you generate an Ndimensional sparse array from a table of explicit entries. This is a generalization to N dimensions of S=sparse(i,j,s,m,n,nzmax).
Other such methods include:
ndSparse.accumarray ndSparse.sprand ndSparse.sprandn ndSparse.spalloc
EXAMPLES: >> A=ndSparse.build( [1 1 1; 2 1 1;2 2 2] , [50,60 70]) %Builds a 2x2x2 sparse array from table
A(:,:,1) =
(1,1) 50 (2,1) 60
A(:,:,2) =
(2,2) 70
Many of the same manipulations common to ordinary multidimensional MATLAB full arrays can be performed on the sparse 3D array A generated above. It can be permuted, summed, concatentated, and so forth e.g.,
>> B=sum( permute([A,A+10], [3,2,1]) ,2)
B(:,:,1) =
(1,1) 120 (2,1) 20
B(:,:,2) =
(1,1) 140 (2,1) 160
Other overloaded methods include BSXFUN, REPMAT, CIRCSHIFT, CONVN, FLIPDIMS, SQUEEZE, SHIFTDIM and many more. Type "methods ndSparse" for a full list and use "help ndSparse.methodname" to get details of usage.
When browsing the list of methods, note that certain common operations have different implementations, optimized for different situations. Specifically, SUM, ANY,ALL, MIN, MAX... have alternative implementations SUMML, ANYML, ALLML, MINML, MAXML which are optimized for "lowdimensional" ndSparse objects OBJ. Here, lowdimensional means that a normal Ncolumn MATLAB sparse matrix won't consume too much memory on your platform for N=MAX(NUMEL(OBJ)./SIZE(OBJ)).
Another feature of the class is that bioperand operations are allowed between ndSparse objects and MATLAB objects of any numeric type (single, uint16, etc...). This is not true of ordinary MATLAB sparse matrices, as of R2010b. >> C=eye(2,'single')*B(:,:,2)
C =
(1,1) 140 (2,1) 160
>> whos A B C
Name Size Bytes Class Attributes
A 2x2x2 136 ndSparse B 2x1x2 140 ndSparse C 2x1 104 ndSparse To convert back to an ordinary nD full array, use the class' overloaded FULL method. To convert to a normal 2D sparse matrix, use the methods SPARSE or SPARSE2D. For example, SPARSE2D will convert an MxNxPx...xQ ndSparse array to the two dimensional (M*N*P*...)xQ sparse matrix in native MATLAB form.
License: Shareware Related: Details, Usage, Browsing, ndsparsemethodname, shiftdim, flipdims, squeeze, operations, anyall O/S:BSD, Linux, Solaris, Mac OS X File Size: 20.5 KB Downloads: 0


More Similar Code 

I have looked far and wide for code for fast sorting of n dimensional arrays by the first element, for example if I had the array: ray = [[1,2,3,7,5][10,11,12,13,14]]
I would want it to come out as ray = [[1,2,3,5,7][10,11,12,14,13]]
There are several ways to do this. One is zipped = zip(ray) zipped.sort() ray = zip(zipped)
but this is extremely slow. Numpy has...
Three ways to calculate a distance matrix out of a list of ndimensional points using scipy.
This function is an implementation of Ndimensional convolution for the special case when the convolution kernel is separable.
A continuous function f(x1, x2, ... xN) is considered separable if there exist N functions f1, f2, ... fN...
Code to generate ndimensional memorymapped arrays for efficiently accessing large array datasets Memorymapped arrays reside within binary files, but are mapped to MATLAB's working memory. They are particularly useful when handling large...
HISTCND Histogram count for n dimensional data. N = HISTCND(X,EDGES), for row vectors X, counts the number of values in X that fall between the grid defined by the cell array of EDGES, each of whose element is a vector that...
MAJLE (Weak) Majorization check S = MAJLE(X,Y) checks if the real part of X is (weakly) majorized by the real part of Y, where X and Y must be numeric (full or sparse) arrays. It returns S=0, if there is no weak majorization of X by Y, S=1,...
This program computes the projection of any ndimensional vector y onto the canonical simplex Dn defined by Dn:={x: x ndimensional vector, 0
Many image processing applications require an extensive usage of FFT2 routine (or, in the most general case, a Ndimensional FFT) of matrices having the same dimensions. In these cases MATLAB FFT2 can result extremely inefficient. In general the...
This builds a navigation GUI for navigating ndimensional convex Pareto surfaces interactively. It requires linprog from the optimization toolbox, but can probably be replaced easily with a free version. The linear programs solved during...
function [i,i_] = fgridmin(y) % Search an Ndimensional array y for points that may be proximate to a global minimum % of the interpolated array; return the proximate points' ND subscripts (i) in y. Also % optionally return the... 
User Review for Ndimensional sparse arrays 
