|
166 | 166 | end
|
167 | 167 | end
|
168 | 168 | end
|
| 169 | + |
| 170 | +# Test that concatenations of annotated sparse/special matrix types with other matrix |
| 171 | +# types yield sparse arrays, and that the code which effects that does not make concatenations |
| 172 | +# strictly involving un/annotated dense matrices yield sparse arrays |
| 173 | +# |
| 174 | +# TODO: As with the associated code, these tests should be moved to a more appropriate |
| 175 | +# location, particularly some future equivalent of base/linalg/special.jl dedicated to |
| 176 | +# intereactions between a broader set of matrix types |
| 177 | +let |
| 178 | + N = 4 |
| 179 | + # The tested annotation types |
| 180 | + utriannotations = (UpperTriangular, Base.LinAlg.UnitUpperTriangular) |
| 181 | + ltriannotations = (LowerTriangular, Base.LinAlg.UnitLowerTriangular) |
| 182 | + annotations = (utriannotations..., ltriannotations..., Symmetric, Hermitian) |
| 183 | + # Concatenations involving these types, un/annotated, should yield sparse arrays |
| 184 | + spvec = spzeros(N) |
| 185 | + spmat = speye(N) |
| 186 | + diagmat = Diagonal(ones(N)) |
| 187 | + bidiagmat = Bidiagonal(ones(N), ones(N-1), true) |
| 188 | + tridiagmat = Tridiagonal(ones(N-1), ones(N), ones(N-1)) |
| 189 | + symtridiagmat = SymTridiagonal(ones(N), ones(N-1)) |
| 190 | + sparseconcatmats = (spmat, diagmat, bidiagmat, tridiagmat, symtridiagmat) |
| 191 | + # Concatenations involving strictly these types, un/annotated, should yield dense arrays |
| 192 | + densevec = ones(N) |
| 193 | + densemat = ones(N, N) |
| 194 | + # Annotated collections |
| 195 | + annodmats = [annot(densemat) for annot in annotations] |
| 196 | + annospcmats = [annot(spcmat) for annot in annotations, spcmat in sparseconcatmats] |
| 197 | + # Test that concatenations of pairwise combinations of annotated sparse/special |
| 198 | + # yield sparse matrices |
| 199 | + for annospcmata in annospcmats, annospcmatb in annospcmats |
| 200 | + @test issparse(vcat(annospcmata, annospcmatb)) |
| 201 | + @test issparse(hcat(annospcmata, annospcmatb)) |
| 202 | + @test issparse(hvcat((2,), annospcmata, annospcmatb)) |
| 203 | + @test issparse(cat((1,2), annospcmata, annospcmatb)) |
| 204 | + end |
| 205 | + # Test that concatenations of pairwise combinations of annotated sparse/special |
| 206 | + # matrices and other matrix/vector types yield sparse matrices |
| 207 | + for annospcmat in annospcmats |
| 208 | + # --> Tests applicable to pairs including only matrices |
| 209 | + for othermat in (densemat, annodmats..., sparseconcatmats...) |
| 210 | + @test issparse(vcat(annospcmat, othermat)) |
| 211 | + @test issparse(vcat(othermat, annospcmat)) |
| 212 | + end |
| 213 | + # --> Tests applicable to pairs including other vectors or matrices |
| 214 | + for other in (spvec, densevec, densemat, annodmats..., sparseconcatmats...) |
| 215 | + @test issparse(hcat(annospcmat, other)) |
| 216 | + @test issparse(hcat(other, annospcmat)) |
| 217 | + @test issparse(hvcat((2,), annospcmat, other)) |
| 218 | + @test issparse(hvcat((2,), other, annospcmat)) |
| 219 | + @test issparse(cat((1,2), annospcmat, other)) |
| 220 | + @test issparse(cat((1,2), other, annospcmat)) |
| 221 | + end |
| 222 | + end |
| 223 | + # The preceding tests should cover multi-way combinations of those types, but for good |
| 224 | + # measure test a few multi-way combinations involving those types |
| 225 | + @test issparse(vcat(spmat, densemat, annospcmats[1], annodmats[2])) |
| 226 | + @test issparse(vcat(densemat, spmat, annodmats[1], annospcmats[2])) |
| 227 | + @test issparse(hcat(spvec, annodmats[3], annospcmats[3], densevec, diagmat)) |
| 228 | + @test issparse(hcat(annodmats[4], annospcmats[4], spvec, densevec, diagmat)) |
| 229 | + @test issparse(hvcat((5,), diagmat, densevec, spvec, annodmats[1], annospcmats[5])) |
| 230 | + @test issparse(hvcat((5,), spvec, annodmats[2], diagmat, densevec, annospcmats[6])) |
| 231 | + @test issparse(cat((1,2), annodmats[3], diagmat, annospcmats[7], densevec, spvec)) |
| 232 | + @test issparse(cat((1,2), spvec, diagmat, densevec, annospcmats[8], annodmats[4])) |
| 233 | + # Test that concatenations strictly involving un/annotated dense matrices/vectors |
| 234 | + # yield dense arrays |
| 235 | + for densemata in (densemat, annodmats...) |
| 236 | + # --> Tests applicable to pairs including only matrices |
| 237 | + for densematb in (densemat, annodmats...) |
| 238 | + @test !issparse(vcat(densemata, densematb)) |
| 239 | + @test !issparse(vcat(densematb, densemata)) |
| 240 | + end |
| 241 | + # --> Tests applicable to pairs including vectors or matrices |
| 242 | + for otherdense in (densevec, densemat, annodmats...) |
| 243 | + @test !issparse(hcat(densemata, otherdense)) |
| 244 | + @test !issparse(hcat(otherdense, densemata)) |
| 245 | + @test !issparse(hvcat((2,), densemata, otherdense)) |
| 246 | + @test !issparse(hvcat((2,), otherdense, densemata)) |
| 247 | + @test !issparse(cat((1,2), densemata, otherdense)) |
| 248 | + @test !issparse(cat((1,2), otherdense, densemata)) |
| 249 | + end |
| 250 | + end |
| 251 | +end |
0 commit comments