mirror of
https://github.com/JuliaFEM/JuliaFEM.jl.git
synced 2026-08-06 04:21:33 +00:00
SparseVectorCOO
This commit is contained in:
+1
-1
@@ -60,7 +60,7 @@ include("integrate.jl") # default integration points for elements
|
||||
export get_integration_points
|
||||
|
||||
include("sparse.jl")
|
||||
export add!, SparseMatrixCOO, get_nonzero_rows, get_nonzero_columns
|
||||
export add!, SparseMatrixCOO, SparseVectorCOO, get_nonzero_rows, get_nonzero_columns
|
||||
|
||||
include("problems.jl") # common problem routines
|
||||
export Problem, AbstractProblem, FieldProblem, BoundaryProblem,
|
||||
|
||||
+16
-2
@@ -10,8 +10,14 @@ type SparseMatrixCOO{T<:Real}
|
||||
V :: Vector{T}
|
||||
end
|
||||
|
||||
typealias SparseVectorCOO SparseMatrixCOO
|
||||
|
||||
function SparseMatrixCOO()
|
||||
SparseMatrixCOO{Float64}([], [], [])
|
||||
return SparseMatrixCOO{Float64}([], [], [])
|
||||
end
|
||||
|
||||
function SparseVectorCOO(I::Vector, V::Vector)
|
||||
return SparseVectorCOO(I, ones(I), V)
|
||||
end
|
||||
|
||||
function convert(::Type{SparseMatrixCOO}, A::SparseMatrixCSC)
|
||||
@@ -132,7 +138,15 @@ function add!(A::SparseMatrixCOO, dofs::Vector{Int}, data::Array{Float64}, dim::
|
||||
append!(A.V, vec(data))
|
||||
end
|
||||
|
||||
""" Combine (I,J,V) values is possible to reduce memory usage. """
|
||||
""" Add SparseVector to SparseVectorCOO. """
|
||||
function add!(a::SparseVectorCOO, b::SparseVector)
|
||||
I, V = findnz(b)
|
||||
c = SparseVectorCOO(I, V)
|
||||
append!(a, c)
|
||||
return
|
||||
end
|
||||
|
||||
""" Combine (I,J,V) values if possible to reduce memory usage. """
|
||||
function optimize!(A::SparseMatrixCOO)
|
||||
I, J, V = findnz(sparse(A))
|
||||
A.I = I
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
# This file is a part of JuliaFEM.
|
||||
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
||||
|
||||
module InterfaceTests
|
||||
|
||||
using JuliaFEM.Testing
|
||||
|
||||
function test_foo()
|
||||
@test 1+2 == 3
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
# This file is a part of JuliaFEM.
|
||||
# License is MIT: see https://github.com/JuliaFEM/JuliaFEM.jl/blob/master/LICENSE.md
|
||||
|
||||
using JuliaFEM
|
||||
using JuliaFEM.Testing
|
||||
|
||||
@testset "Add to SparseMatrixCOO" begin
|
||||
A = SparseMatrixCOO()
|
||||
A2 = reshape(collect(1:9), 3, 3)
|
||||
add!(A, sparse(A2))
|
||||
@test isapprox(full(A), full(A2))
|
||||
end
|
||||
|
||||
@testset "Add to SparseVectorCOO" begin
|
||||
b = SparseVectorCOO()
|
||||
b2 = collect(1:3)
|
||||
add!(b, sparse(b2))
|
||||
@test isapprox(full(b), full(b2))
|
||||
end
|
||||
Reference in New Issue
Block a user