sparse-array

Sparse O(1) array with indices being consecutive products

余生颓废 提交于 2020-01-23 12:49:28
问题 I'd like to pre-calculate an array of values of some unary function f . I know that I'll only need the values for f(x) where x is of the form of a*b , where both a and b are integers in range 0..N . The obvious time-optimized choice is just to make an array of size N*N and just pre-calculate just the elements which I'm going to read later. For f(a*b) , I'd just check and set tab[a*b] . This is the fastest method possible - however, this is going to take a lot of space as there are lots of

How to use SparseArray as a source for Adapter?

此生再无相见时 提交于 2020-01-14 09:35:08
问题 I have a sparse array of values which I want to populate in a Spinner, and when the item is selected, I want to get the id (which is the key from the sparse array). What is the preferred way of creating an adapter from a SparseArray? Is it possible to subclass an existing Adapter like BaseAdapter or ListAdapter So that the items will have a key from the SparseArray as item id? Not knowing how to achieve the above, I am thinking of creating a simple ArrayAdapter instance and giving it values

How to wrap Eigen::SparseMatrix over preexistant 3-standard compress row/colum arrays

佐手、 提交于 2020-01-02 16:30:27
问题 NOTE: I allready asked this question, but it was closed because of "too broad" without much explanation. I can't see how this question could be more specific (it deals with a specific class of a specific library for a specific usage...), so I assume that it was something like a "moderator's mistake" and ask it again... I would like to perfom sparse matrix/matrix multiplication using Eigen on sparse matrices. These matrices are already defined in the code I am working on in standard 3-arrays

how to implement a sparse_vector class

*爱你&永不变心* 提交于 2020-01-02 07:51:12
问题 I am implementing a templated sparse_vector class. It's like a vector, but it only stores elements that are different from their default constructed value. So, sparse_vector would store the lazily-sorted index-value pairs for all indices whose value is not T(). I am basing my implementation on existing sparse vectors in numeric libraries-- though mine will handle non-numeric types T as well. I looked at boost::numeric::ublas::coordinate_vector and eigen::SparseVector . Both store: size_t*

Automated sparse matricies in Fortran

♀尐吖头ヾ 提交于 2019-12-25 05:32:14
问题 I know that Intel Fortran has libraries with functions and subroutines for working with sparse matricies, but I'm wondering if there is also some sort of data type or automated method for creating the sparse matricies in the first place. BACKGROUND: I have a program that uses some 3 & 4 dimensional arrays that can be very large in the first 2 dimensions (~10k to ~100k elements in each dimension, maybe more). In the first 2 dimensions, each array is mostly (95% or so) populated w/ zeroes. To

Local maxima in a point cloud

旧巷老猫 提交于 2019-12-21 02:56:12
问题 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

Sparse array compression using SIMD (AVX2)

时光怂恿深爱的人放手 提交于 2019-12-18 04:55:18
问题 I have a sparse array a (mostly zeroes): unsigned char a[1000000]; and I would like to create an array b of indexes to non-zero elements of a using SIMD instructions on Intel x64 architecture with AVX2. I'm looking for tips how to do it efficiently. Specifically, are there SIMD instruction(s) to get positions of consecutive non-zero elements in SIMD register, arranged contiguously? 回答1: Five methods to compute the indices of the nonzeros are: Semi vectorized loop: Load a SIMD vector with

Condensing a sparse array in Javascript?

拟墨画扇 提交于 2019-12-17 21:07:49
问题 I have an array of elements where the entries are sparse. How can I easily condense the sparse array into a dense array so that I don't have to keep checking for null and undefined values every time I loop through the data? Here is some example data: var sparse = []; sparse[1] = undefined; sparse[5] = 3; sparse[10] = null; var dense = sparseToDenseArray(sparse); // dense should be [3] 回答1: In vanilla JS, works on all browsers: function filt(a) { var b = []; for(var i = 0;i < a.length;i++) {

Memory-efficient sparse array in Java

我的未来我决定 提交于 2019-12-17 06:50:20
问题 (There are some questions about time-efficient sparse arrays but I am looking for memory efficiency.) I need the equivalent of a List<T> or Map<Integer,T> which Can grow on demand just by setting a key larger than any encountered before. (Can assume keys are nonnegative.) Is about as memory-efficient as an ArrayList<T> in the case that most of the indices are not null , i.e. when the actual data is not very sparse. When the indices are sparse, consumes space proportional to the number of non-

writeSparseArray support SparseArray<int[]>?

和自甴很熟 提交于 2019-12-11 18:41:46
问题 I have a param in SparseArray<int[]> , and want to serialize it. But the writeSparseArray(Object) for Parcelable seems not support int[] . Is there any other way to serialize the SparseArray<int[]> ,Or only change int[] to Object? 回答1: I checked Parcel.writeSparseArray() method and in my opinion there is some issue because this method should be generic like writeList(). It looks like: public final void writeSparseArray(SparseArray<Object> val) and should be public final void writeSparseArray