GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ITensor/SparseArraysBase.jl: Multidimensional sparse array library. SparseArraysBase.jl is supported by the Simons Foundation's Flatiron Institute.

BranchesTags
Open more actions menu

Latest commit

 

History

151 Commits
151 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
benchmark
benchmark
 
 
docs
docs
 
 
examples
examples
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.pre-commit-config.yaml
.pre-commit-config.yaml
 
 
LICENSE
LICENSE
 
 
Project.toml
Project.toml
 
 
README.md
README.md
 
 

Repository files navigation

SparseArraysBase.jl

Stable Dev Build Status Coverage Code Style Aqua

Support

Flatiron Center for Computational Quantum Physics logo.

SparseArraysBase.jl is supported by the Flatiron Institute, a division of the Simons Foundation.

Installation instructions

This package resides in the ITensor/ITensorRegistry local registry. In order to install, simply add that registry through your package manager. This step is only required once.

julia> using Pkg: Pkg

julia> Pkg.Registry.add(url="https://github.com/ITensor/ITensorRegistry")

or:

julia> Pkg.Registry.add(url="[email protected]:ITensor/ITensorRegistry.git")

if you want to use SSH credentials, which can make it so you don't have to enter your Github ursername and password when registering packages.

Then, the package can be added as usual through the package manager:

julia> Pkg.add("SparseArraysBase")

Examples

using SparseArraysBase: SparseArrayDOK, SparseMatrixDOK, SparseVectorDOK, eachstoredindex,
    getstoredindex, getunstoredindex, isstored, setstoredindex!, setunstoredindex!,
    storedlength, storedpairs, storedvalues, zero!
using Test: @test, @test_throws

a = SparseArrayDOK{Float64}(undef, 2, 2)

AbstractArray interface:

@test iszero(a)
@test iszero(sum(a))
@test iszero(storedlength(a))

a[1, 2] = 12
@test a == [0 12; 0 0]
@test a[1, 1] == 0
@test a[2, 1] == 0
@test a[1, 2] == 12
@test a[2, 2] == 0

SparseArraysBase interface:

using Dictionaries: IndexError
@test issetequal(eachstoredindex(a), [CartesianIndex(1, 2)])
@test getstoredindex(a, 1, 2) == 12
@test_throws IndexError getstoredindex(a, 1, 1)
@test getunstoredindex(a, 1, 1) == 0
@test getunstoredindex(a, 1, 2) == 0
@test !isstored(a, 1, 1)
@test isstored(a, 1, 2)
@test setstoredindex!(copy(a), 21, 1, 2) == [0 21; 0 0]
@test_throws IndexError setstoredindex!(copy(a), 21, 2, 1)
@test_throws IndexError setunstoredindex!(copy(a), 21, 1, 2) == [0 21; 0 0]
@test storedlength(a) == 1
@test issetequal(storedpairs(a), [CartesianIndex(1, 2) => 12])
@test issetequal(storedvalues(a), [12])
@test sum(a) == 12
@test isreal(a)
@test !iszero(a)
@test mapreduce(x -> 2x, +, a) == 24

AbstractArray functionality:

b = a .+ 2 .* a'
@test b isa SparseMatrixDOK{Float64}
@test b == [0 12; 24 0]
@test storedlength(b) == 2
@test sum(b) == 36
@test isreal(b)
@test !iszero(b)
@test mapreduce(x -> 2x, +, b) == 72

b = permutedims(a, (2, 1))
@test b isa SparseMatrixDOK{Float64}
@test b[1, 1] == a[1, 1]
@test b[2, 1] == a[1, 2]
@test b[1, 2] == a[2, 1]
@test b[2, 2] == a[2, 2]

b = a * a'
@test b isa SparseMatrixDOK{Float64}
@test b == [144 0; 0 0]
@test storedlength(b) == 1

Second column.

b = a[1:2, 2]
@test b isa SparseVectorDOK{Float64}
@test b == [12, 0]
@test storedlength(b) == 1

a = SparseArrayDOK{Float64}(undef, 2, 2)
a .= 2
for I in eachindex(a)
    @test a[I] == 2
end
@test storedlength(a) == length(a)

a = SparseArrayDOK{Float64}(undef, 2, 2)
fill!(a, 2)
for I in eachindex(a)
    @test a[I] == 2
end
@test storedlength(a) == length(a)

a = SparseArrayDOK{Float64}(undef, 2, 2)
fill!(a, 0)
@test iszero(a)
@test iszero(storedlength(a))

a = SparseArrayDOK{Float64}(undef, 2, 2)
a[1, 2] = 12
zero!(a)
@test iszero(a)
@test iszero(storedlength(a))

a = SparseArrayDOK{Float64}(undef, 2, 2)
a[1, 2] = 12
b = zero(a)
@test iszero(b)
@test iszero(storedlength(b))

This page was generated using Literate.jl.

About

Multidimensional sparse array library. SparseArraysBase.jl is supported by the Simons Foundation's Flatiron Institute.

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

1 star

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.