Comments (3)
It doesn't allocate for nonzero values. It still has to allocate for the SparseMatrixCSC data structure, roughly 1 int per column.
from sparsearrays.jl.
spzeros
does not create aSparseMatrixCSC
, but aSparseVector
. I guess thatspzeros
allocates because it contains 2 vectors (one for dims and one for values). Even if they're initialized as empty, Julia allocates for empty vectors. See code below- In any case, I think the reason why it allocates is not important. What is important is that the documentation says that it does not allocate, and it does. This means that it's misleading when optimized code is required, since the documentation seems to imply that using it and pushing data might have the same performance as setting the data directly through other SparseVector constructors.
function f(n)
for i in 1:n
a= Int[]
resize!(a,1)
end
end
f (generic function with 1 method)
julia> @allocations f(10)
20
from sparsearrays.jl.
That is right, the empty vectors will be allocated. You are right - the documentation could be improved to not give the wrong impression. If you could make a PR that would be great.
from sparsearrays.jl.
Related Issues (20)
- Elementwise multiplication by a view of a dense matrix gives a dense matrix
- `findmin(A; dims=1)` is much slower than manually looping over. HOT 1
- Sparse array of string types HOT 17
- Memory Mapped SparseArrays HOT 3
- Extra allocations when using generalized `mul!` operation
- Attempting to run sparse `qr` produces StackOverflow when run on a sparse matrix of `ForwardDiff.Dual`. HOT 6
- Inconsistent addition between sparse and dense HOT 1
- `ldiv` of `LUFactorization` can throw `SingluarException` HOT 1
- Thread-safe dropstored! HOT 1
- Merge SparseMatricesCSR.jl in HOT 2
- Support zero-based indices HOT 3
- Windows threading tests fail in GitHub Actions CI but pass in Buildkite CI
- Problem when running old benchmarks in Oceananigans HOT 6
- Sparse matrix format interfaces HOT 9
- Clarify Cholmod version incompatibility message at build time and run time HOT 8
- Row-wise and column-wise scaling of a sparse matrix runs out of memory HOT 1
- CHOLMOD default ordering options: METIS vs AMD HOT 28
- Add solver docs to the main SparseArrays docs
- Dividing sparse matrix by vector produces fill in HOT 2
- BLAS/LAPACK not being loaded for sparse matrix operations HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sparsearrays.jl.