|
1 | 1 | <!DOCTYPE html> |
2 | 2 | <html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Home · SparseArraysBase.jl</title><meta name="title" content="Home · SparseArraysBase.jl"/><meta property="og:title" content="Home · SparseArraysBase.jl"/><meta property="twitter:title" content="Home · SparseArraysBase.jl"/><meta name="description" content="Documentation for SparseArraysBase.jl."/><meta property="og:description" content="Documentation for SparseArraysBase.jl."/><meta property="twitter:description" content="Documentation for SparseArraysBase.jl."/><meta property="og:url" content="https://ITensor.github.io/SparseArraysBase.jl/"/><meta property="twitter:url" content="https://ITensor.github.io/SparseArraysBase.jl/"/><link rel="canonical" href="https://ITensor.github.io/SparseArraysBase.jl/"/><script data-outdated-warner src="assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL="."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="assets/documenter.js"></script><script src="search_index.js"></script><script src="siteinfo.js"></script><script src="../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/catppuccin-mocha.css" data-theme-name="catppuccin-mocha"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/catppuccin-macchiato.css" data-theme-name="catppuccin-macchiato"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/catppuccin-frappe.css" data-theme-name="catppuccin-frappe"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/catppuccin-latte.css" data-theme-name="catppuccin-latte"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href>SparseArraysBase.jl</a></span></div><button class="docs-search-query input is-rounded is-small is-clickable my-2 mx-auto py-1 px-2" id="documenter-search-query">Search docs (Ctrl + /)</button><ul class="docs-menu"><li class="is-active"><a class="tocitem" href>Home</a><ul class="internal"><li><a class="tocitem" href="#Installation-instructions"><span>Installation instructions</span></a></li><li><a class="tocitem" href="#Examples"><span>Examples</span></a></li></ul></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><a class="docs-sidebar-button docs-navbar-link fa-solid fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Home</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Home</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/ITensor/SparseArraysBase.jl" title="View the repository on GitHub"><span class="docs-icon fa-brands"></span><span class="docs-label is-hidden-touch">GitHub</span></a><a class="docs-navbar-link" href="https://github.com/ITensor/SparseArraysBase.jl/blob/main/examples/README.jl" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-article-toggle-button fa-solid fa-chevron-up" id="documenter-article-toggle-button" href="javascript:;" title="Collapse all docstrings"></a></div></header><article class="content" id="documenter-page"><h1 id="SparseArraysBase.jl"><a class="docs-heading-anchor" href="#SparseArraysBase.jl">SparseArraysBase.jl</a><a id="SparseArraysBase.jl-1"></a><a class="docs-heading-anchor-permalink" href="#SparseArraysBase.jl" title="Permalink"></a></h1><p><a href="https://ITensor.github.io/SparseArraysBase.jl/stable/"><img src="https://img.shields.io/badge/docs-stable-blue.svg" alt="Stable"/></a> <a href="https://ITensor.github.io/SparseArraysBase.jl/dev/"><img src="https://img.shields.io/badge/docs-dev-blue.svg" alt="Dev"/></a> <a href="https://github.com/ITensor/SparseArraysBase.jl/actions/workflows/Tests.yml?query=branch%3Amain"><img src="https://github.com/ITensor/SparseArraysBase.jl/actions/workflows/Tests.yml/badge.svg?branch=main" alt="Build Status"/></a> <a href="https://codecov.io/gh/ITensor/SparseArraysBase.jl"><img src="https://codecov.io/gh/ITensor/SparseArraysBase.jl/branch/main/graph/badge.svg" alt="Coverage"/></a> <a href="https://github.com/invenia/BlueStyle"><img src="https://img.shields.io/badge/code%20style-blue-4495d1.svg" alt="Code Style: Blue"/></a> <a href="https://github.com/JuliaTesting/Aqua.jl"><img src="https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg" alt="Aqua"/></a></p><h2 id="Installation-instructions"><a class="docs-heading-anchor" href="#Installation-instructions">Installation instructions</a><a id="Installation-instructions-1"></a><a class="docs-heading-anchor-permalink" href="#Installation-instructions" title="Permalink"></a></h2><p>This package resides in the <code>ITensor/ITensorRegistry</code> local registry. In order to install, simply add that registry through your package manager. This step is only required once.</p><pre><code class="language-julia hljs">julia> using Pkg: Pkg |
3 | 3 |
|
4 | | -julia> Pkg.Registry.add(url="https://github.com/ITensor/ITensorRegistry") </code></pre><p>or: </p><pre><code class=" language-julia hljs" >julia> Pkg.Registry.add(url=" [email protected]:ITensor/ITensorRegistry.git") </code></pre><p>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. </p><p>Then, the package can be added as usual through the package manager: </p><pre><code class=" language-julia hljs" >julia> Pkg.add("SparseArraysBase") </code></pre><h2 id=" Examples" ><a class=" docs-heading-anchor" href=" #Examples" >Examples </a><a id=" Examples-1" ></a><a class=" docs-heading-anchor-permalink" href=" #Examples" title=" Permalink" ></a></h2><pre><code class=" language-julia hljs" >using SparseArraysBase: SparseArraysBase </code></pre><p>Examples go here. </p><hr/><p><em>This page was generated using <a href=" https://github.com/fredrikekre/Literate.jl" >Literate.jl </a>. </em></p></article><nav class=" docs-footer" ><p class=" footer-message" >Powered by <a href=" https://github.com/JuliaDocs/Documenter.jl" >Documenter.jl </a> and the <a href=" https://julialang.org/" >Julia Programming Language </a>. </p></nav></div><div class=" modal" id=" documenter-settings" ><div class=" modal-background" ></div><div class=" modal-card" ><header class=" modal-card-head" ><p class=" modal-card-title" >Settings </p><button class=" delete" ></button></header><section class=" modal-card-body" ><p><label class=" label" >Theme </label><div class=" select" ><select id=" documenter-themepicker" ><option value=" auto" >Automatic (OS) </option><option value=" documenter-light" >documenter-light </option><option value=" documenter-dark" >documenter-dark </option><option value=" catppuccin-latte" >catppuccin-latte </option><option value=" catppuccin-frappe" >catppuccin-frappe </option><option value=" catppuccin-macchiato" >catppuccin-macchiato </option><option value=" catppuccin-mocha" >catppuccin-mocha </option></select></div></p><hr/><p>This document was generated with <a href=" https://github.com/JuliaDocs/Documenter.jl" >Documenter.jl </a> version 1.8.0 on <span class=" colophon-date" title=" Thursday 12 December 2024 06:06" >Thursday 12 December 2024 </span>. Using Julia version 1.11.2. </p></section><footer class=" modal-card-foot" ></footer></div></div></div></body></html> |
| 4 | +julia> Pkg.Registry.add(url="https://github.com/ITensor/ITensorRegistry") </code></pre><p>or: </p><pre><code class=" language-julia hljs" >julia> Pkg.Registry.add(url=" [email protected]:ITensor/ITensorRegistry.git") </code></pre><p>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. </p><p>Then, the package can be added as usual through the package manager: </p><pre><code class=" language-julia hljs" >julia> Pkg.add("SparseArraysBase") </code></pre><h2 id=" Examples" ><a class=" docs-heading-anchor" href=" #Examples" >Examples </a><a id=" Examples-1" ></a><a class=" docs-heading-anchor-permalink" href=" #Examples" title=" Permalink" ></a></h2><pre><code class=" language-julia hljs" >using SparseArraysBase: |
| 5 | + SparseArrayDOK, |
| 6 | + SparseMatrixDOK, |
| 7 | + SparseVectorDOK, |
| 8 | + eachstoredindex, |
| 9 | + getstoredindex, |
| 10 | + getunstoredindex, |
| 11 | + isstored, |
| 12 | + setstoredindex!, |
| 13 | + setunstoredindex!, |
| 14 | + storedlength, |
| 15 | + storedpairs, |
| 16 | + storedvalues, |
| 17 | + zero! |
| 18 | +using Test: @test, @test_throws |
| 19 | + |
| 20 | +a = SparseArrayDOK{Float64}(2, 2)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">2×2 SparseArraysBase.SparseArrayDOK{Float64, 2, typeof(SparseArraysBase.default_getunstoredindex)}: |
| 21 | + 0.0 0.0 |
| 22 | + 0.0 0.0</code></pre><p>AbstractArray interface:</p><pre><code class="language-julia hljs">@test iszero(a) |
| 23 | +@test iszero(sum(a)) |
| 24 | +@test iszero(storedlength(a)) |
| 25 | + |
| 26 | +a[1, 2] = 12 |
| 27 | +@test a == [0 12; 0 0] |
| 28 | +@test a[1, 1] == 0 |
| 29 | +@test a[2, 1] == 0 |
| 30 | +@test a[1, 2] == 12 |
| 31 | +@test a[2, 2] == 0</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi"><span class="sgr32"><span class="sgr1">Test Passed</span></span></code></pre><p>SparseArraysBase interface:</p><pre><code class="language-julia hljs">using Dictionaries: IndexError |
| 32 | +@test issetequal(eachstoredindex(a), [CartesianIndex(1, 2)]) |
| 33 | +@test getstoredindex(a, 1, 2) == 12 |
| 34 | +@test_throws IndexError getstoredindex(a, 1, 1) |
| 35 | +@test getunstoredindex(a, 1, 1) == 0 |
| 36 | +@test getunstoredindex(a, 1, 2) == 0 |
| 37 | +@test !isstored(a, 1, 1) |
| 38 | +@test isstored(a, 1, 2) |
| 39 | +@test setstoredindex!(copy(a), 21, 1, 2) == [0 21; 0 0] |
| 40 | +@test_throws IndexError setstoredindex!(copy(a), 21, 2, 1) |
| 41 | +@test setunstoredindex!(copy(a), 21, 1, 2) == [0 21; 0 0] |
| 42 | +@test storedlength(a) == 1 |
| 43 | +@test issetequal(storedpairs(a), [CartesianIndex(1, 2) => 12]) |
| 44 | +@test issetequal(storedvalues(a), [12]) |
| 45 | +@test sum(a) == 12 |
| 46 | +@test isreal(a) |
| 47 | +@test !iszero(a) |
| 48 | +@test mapreduce(x -> 2x, +, a) == 24</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi"><span class="sgr32"><span class="sgr1">Test Passed</span></span></code></pre><p>AbstractArray functionality:</p><pre><code class="language-julia hljs">b = a .+ 2 .* a' |
| 49 | +@test b isa SparseMatrixDOK{Float64} |
| 50 | +@test b == [0 12; 24 0] |
| 51 | +@test storedlength(b) == 2 |
| 52 | +@test sum(b) == 36 |
| 53 | +@test isreal(b) |
| 54 | +@test !iszero(b) |
| 55 | +@test mapreduce(x -> 2x, +, b) == 72 |
| 56 | + |
| 57 | +b = permutedims(a, (2, 1)) |
| 58 | +@test b isa SparseMatrixDOK{Float64} |
| 59 | +@test b[1, 1] == a[1, 1] |
| 60 | +@test b[2, 1] == a[1, 2] |
| 61 | +@test b[1, 2] == a[2, 1] |
| 62 | +@test b[2, 2] == a[2, 2] |
| 63 | + |
| 64 | +b = a * a' |
| 65 | +@test b isa SparseMatrixDOK{Float64} |
| 66 | +@test b == [144 0; 0 0] |
| 67 | +@test storedlength(b) == 1</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi"><span class="sgr32"><span class="sgr1">Test Passed</span></span></code></pre><p>Second column.</p><pre><code class="language-julia hljs">b = a[1:2, 2] |
| 68 | +@test b isa SparseVectorDOK{Float64} |
| 69 | +@test b == [12, 0] |
| 70 | +@test storedlength(b) == 1 |
| 71 | + |
| 72 | +a = SparseArrayDOK{Float64}(2, 2) |
| 73 | +a .= 2 |
| 74 | +for I in eachindex(a) |
| 75 | + @test a[I] == 2 |
| 76 | +end |
| 77 | +@test storedlength(a) == length(a) |
| 78 | + |
| 79 | +a = SparseArrayDOK{Float64}(2, 2) |
| 80 | +fill!(a, 2) |
| 81 | +for I in eachindex(a) |
| 82 | + @test a[I] == 2 |
| 83 | +end |
| 84 | +@test storedlength(a) == length(a) |
| 85 | + |
| 86 | +a = SparseArrayDOK{Float64}(2, 2) |
| 87 | +fill!(a, 0) |
| 88 | +@test iszero(a) |
| 89 | +@test iszero(storedlength(a)) |
| 90 | + |
| 91 | +a = SparseArrayDOK{Float64}(2, 2) |
| 92 | +a[1, 2] = 12 |
| 93 | +zero!(a) |
| 94 | +@test iszero(a) |
| 95 | +@test iszero(storedlength(a)) |
| 96 | + |
| 97 | +a = SparseArrayDOK{Float64}(2, 2) |
| 98 | +a[1, 2] = 12 |
| 99 | +b = zero(a) |
| 100 | +@test iszero(b) |
| 101 | +@test iszero(storedlength(b))</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi"><span class="sgr32"><span class="sgr1">Test Passed</span></span></code></pre><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.8.0 on <span class="colophon-date" title="Monday 16 December 2024 01:41">Monday 16 December 2024</span>. Using Julia version 1.11.2.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
0 commit comments