sparse-array

Data structure for representing sparse tensor?

假装没事ソ 提交于 2019-12-05 17:31:35
What is an appropriate data structure to represent a sparse tesnor in C++? The first option that comes to mind is a boost::unordered_map since it allows operations like fast setting and retrieval of an an element like below: A(i,j,k,l) = 5 However, I would also like to be able to do contractions over a single index, which would involve summation over one of the indices C(i,j,k,m) = A(i,j,k,l)*B(l,m) How easy would it be to implement this operator with a boost::unordered_map ? Is there a more appropriate data structure? There are tensor libraries available, like: http://www.codeproject.com/KB

How to store sparsearray in bundle

爷,独闯天下 提交于 2019-12-05 10:29:31
I have a SparseArray<myObject> and want to store it in bundle in onSaveInstanceState method in my activity and restore it in oncreate . I found putSparseParcelableArray method for put SparseArray in bundle and did this in onSaveInstanceState method: bundle.putSparseParcelableArray("mySparseArray", mySparseArray); But eclips shows this error: The method putSparseParcelableArray(String, SparseArray<? extends Parcelable>) in the type Bundle is not applicable for the arguments (String, SparseArray<myObject>) And the quick fix is casting argument mySparsArray to SparseArray<? extends Parcelable> ,

Loading Matlab sparse matrix saved with -v7.3 (HDF5) into Python and operating on it

喜夏-厌秋 提交于 2019-12-04 23:41:41
问题 I'm new to python, coming from matlab. I have a large sparse matrix saved in matlab v7.3 (HDF5) format. I've so far found two ways of loading in the file, using h5py and tables . However operating on the matrix seems to be extremely slow after either. For example, in matlab: >> whos Name Size Bytes Class Attributes M 11337x133338 77124408 double sparse >> tic, sum(M(:)); toc Elapsed time is 0.086233 seconds. Using tables: t = time.time() sum(f.root.M.data) elapsed = time.time() - t print

How to quickly compact a sparse array with CUDA C?

人走茶凉 提交于 2019-12-04 11:04:07
Summary Array [A - B - - - C] in device memory but want [A B C] - what's the quickest way with CUDA C? Context I have an array A of integers on device (GPU) memory. At each iteration, I randomly choose a few elements that are larger than 0 and subtract 1 from them. I maintain a sorted lookup array L of those elements that are equal to 0: Array A: @ iteration i: [0 1 0 3 3 2 0 1 2 3] @ iteration i + 1: [0 0 0 3 2 2 0 1 2 3] Lookup for 0-elements L: @ iteration i: [0 - 2 - - - 6 - - -] -> want compacted form: [0 2 6] @ iteration i + 1: [0 1 2 - - - 6 - - -] -> want compacted form: [0 1 2 6] (

Efficient alternative to Outer on sparse arrays in Mathematica?

空扰寡人 提交于 2019-12-04 10:53:01
问题 Suppose I have two very large lists {a1, a2, …} and {b1, b2, …} where all ai and bj are large sparse arrays. For the sake of memory efficiency I store each list as one comprehensive sparse array. Now I would like to compute some function f on all possible pairs of ai and bj where each result f[ai, bj] is a sparse array again. All these sparse arrays have the same dimensions, by the way. While Flatten[Outer[f, {a1, a2, ...}, {b1, b2, ...}, 1], 1] returns the desired result (in principle) it

Matlab: First Non-zero element of each row or column

≯℡__Kan透↙ 提交于 2019-12-04 03:12:33
For example, A = [ -1 0 -2 0 0 2 8 0 1 0 0 0 3 0 -2 0 -3 2 0 0 1 2 0 0 -4]; how can I get a vector of the first nonzero elements of each row? You can use max : >> [sel, c] = max( A ~=0, [], 2 ); Rows for which sel equalse zero - are all zeros and the corresponding column in c should be ignored. Result: >> [sel c]= max( A~=0, [], 2 ) sel = 1 1 1 1 1 c = 1 1 3 2 1 In order to find the first non-zero row index (for each column) you just need to apply max on the first dimension: >> [sel r] = max( A~=0, [], 1 ); Here is a solution based on accumarray that will work even if a row is all zeros. A = [

Local maxima in a point cloud

我怕爱的太早我们不能终老 提交于 2019-12-03 08:58:25
I have a point cloud C, where each point has an associated value. Lets say the points are in 2-d space, so each point can be represented with the triplet (x, y, v). I'd like to find the subset of points which are local maxima. That is, for some radius R, I would like to find the subset of points S in C such that for any point Pi (with value vi) in S, there is no point Pj in C within R distance of Pi whose value vj is greater that vi. I see how I could do this in O(N^2) time, but that seems wasteful. Is there an efficient way to do this? Side Notes: The source of this problem is that I'm trying

Efficient alternative to Outer on sparse arrays in Mathematica?

两盒软妹~` 提交于 2019-12-03 06:48:01
Suppose I have two very large lists {a1, a2, …} and {b1, b2, …} where all ai and bj are large sparse arrays. For the sake of memory efficiency I store each list as one comprehensive sparse array. Now I would like to compute some function f on all possible pairs of ai and bj where each result f[ai, bj] is a sparse array again. All these sparse arrays have the same dimensions, by the way. While Flatten[Outer[f, {a1, a2, ...}, {b1, b2, ...}, 1], 1] returns the desired result (in principle) it appears to consume excessive amounts of memory. Not the least because the return value is a list of

javascript sort sparse array keep indexes

巧了我就是萌 提交于 2019-12-03 06:32:34
问题 What is the best method to sort a sparse array and keep the elements on the same indexes? For example: a[0] = 3, a[1] = 2, a[2] = 6, a[7] = 4, a[8] = 5, I would like after the sort to have a[0] = 2, a[1] = 3, a[2] = 4, a[7] = 5, a[8] = 6. 回答1: Here's one approach. It copies the defined array elements to a new array and saves their indexes. It sorts the new array and then puts the sorted results back into the indexes that were previously used. var a = []; a[0] = 3; a[1] = 2; a[2] = 6; a[7] = 4

javascript sort sparse array keep indexes

流过昼夜 提交于 2019-12-02 20:11:51
What is the best method to sort a sparse array and keep the elements on the same indexes? For example: a[0] = 3, a[1] = 2, a[2] = 6, a[7] = 4, a[8] = 5, I would like after the sort to have a[0] = 2, a[1] = 3, a[2] = 4, a[7] = 5, a[8] = 6. Here's one approach. It copies the defined array elements to a new array and saves their indexes. It sorts the new array and then puts the sorted results back into the indexes that were previously used. var a = []; a[0] = 3; a[1] = 2; a[2] = 6; a[7] = 4; a[8] = 5; // sortFn is optional array sort callback function, // defaults to numeric sort if not passed