|
1 | 1 | using Test, LinearAlgebra, LazyArrays, FillArrays, ArrayLayouts, SparseArrays |
2 | 2 | using StaticArrays |
3 | | -import LazyArrays: CachedArray, colsupport, rowsupport, LazyArrayStyle, broadcasted, |
| 3 | +import LazyArrays: CachedArray, colsupport, rowsupport, LazyArrayStyle, broadcasted, resizedata!, |
4 | 4 | ApplyLayout, BroadcastLayout, AddArray, LazyLayout, PaddedLayout, PaddedRows, PaddedColumns |
5 | 5 | import ArrayLayouts: OnesLayout |
6 | 6 |
|
|
379 | 379 | @test a[end] ≈ prod(1 .+ (1:10_000_000).^(-2.0)) |
380 | 380 | @test LazyArrays.AccumulateAbstractVector(*, 1:5) == Accumulate(*, 1:5) |
381 | 381 | @test LazyArrays.AccumulateAbstractVector(*, 1:5) isa LazyArrays.AccumulateAbstractVector |
| 382 | + |
| 383 | + @testset "Broadcasted Cached" begin |
| 384 | + a = Accumulate(*, 1:5) |
| 385 | + b = BroadcastVector(*, 2, a); |
| 386 | + |
| 387 | + dest = Vector{Int}(undef, 3) |
| 388 | + copyto!(dest, view(b,1:3)) |
| 389 | + |
| 390 | + # lets step through the copyto! to reduce to MWE |
| 391 | + bc = LazyArrays._broadcastarray2broadcasted(view(b,1:3)) |
| 392 | + # this is equivalent to |
| 393 | + v = view(a,1:3) |
| 394 | + bc = broadcasted(*, 2, v) |
| 395 | + |
| 396 | + copyto!(dest, bc) |
| 397 | + |
| 398 | + |
| 399 | + # what we want: |
| 400 | + resizedata!(v, length(dest)) |
| 401 | + copyto!(dest, broadcasted(*, 2, LazyArrays.cacheddata(v))) |
| 402 | + end |
382 | 403 | end |
383 | 404 | end |
384 | 405 |
|
|
441 | 462 | @test tril(A,1) isa ApplyMatrix{Float64,typeof(tril)} |
442 | 463 | end |
443 | 464 |
|
444 | | -@testset "BroadcastArray" begin |
445 | | - bc = broadcasted(exp,[1,2,3]) |
446 | | - v = BroadcastArray(exp, [1,2,3]) |
447 | | - @test BroadcastArray(bc) == BroadcastVector(bc) == BroadcastVector{Float64,typeof(exp),typeof(bc.args)}(bc) == |
448 | | - v == BroadcastVector(exp, [1,2,3]) == exp.([1,2,3]) |
449 | | - |
450 | | - Base.IndexStyle(typeof(BroadcastVector(exp, [1,2,3]))) == IndexLinear() |
451 | | - |
452 | | - bc = broadcasted(exp,[1 2; 3 4]) |
453 | | - M = BroadcastArray(exp, [1 2; 3 4]) |
454 | | - @test BroadcastArray(bc) == BroadcastMatrix(bc) == BroadcastMatrix{Float64,typeof(exp),typeof(bc.args)}(bc) == |
455 | | - M == BroadcastMatrix(BroadcastMatrix(bc)) == BroadcastMatrix(exp,[1 2; 3 4]) == exp.([1 2; 3 4]) |
456 | | - |
457 | | - @test exp.(v') isa Adjoint{<:Any,<:BroadcastVector} |
458 | | - @test exp.(transpose(v)) isa Transpose{<:Any,<:BroadcastVector} |
459 | | - @test exp.(M') isa Adjoint{<:Any,<:BroadcastMatrix} |
460 | | - @test exp.(transpose(M)) isa Transpose{<:Any,<:BroadcastMatrix} |
461 | | - |
462 | | - bc = BroadcastArray(broadcasted(+, 1:10, broadcasted(sin, 1:10))) |
463 | | - @test bc[1:10] == (1:10) .+ sin.(1:10) |
464 | | - |
465 | | - bc = BroadcastArray(broadcasted(+,1:10,broadcasted(+,1,2))) |
466 | | - @test bc.args[2] == 3 |
467 | | - |
468 | | - @testset "_vec_mul_arguments method" begin |
469 | | - @test_throws "MethodError: no method matching _vec_mul_arguments" LazyArrays._vec_mul_arguments(2, []) |
470 | | - end |
471 | | -end |
472 | 465 |
|
473 | 466 | include("blocktests.jl") |
474 | 467 | include("bandedtests.jl") |
|
0 commit comments