Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better tests for shapes #3808

Closed
odow opened this issue Aug 22, 2024 · 4 comments · Fixed by #3816
Closed

Add better tests for shapes #3808

odow opened this issue Aug 22, 2024 · 4 comments · Fixed by #3816

Comments

@odow
Copy link
Member

odow commented Aug 22, 2024

We could test that the dot product before and after reshaping is the same.

This would catch issues like #3797

@odow
Copy link
Member Author

odow commented Aug 27, 2024

@blegat: could you sketch what you had in mind here? Adding some default tests for the shapes doesn't help us show that we use the appropriate shape for a constraint? (Which was the issue here.)

@blegat
Copy link
Member

blegat commented Aug 27, 2024

I think it can just be something like

function test_shape(primal, dual, shape)
    vec_primal = vectorize(primal, shape)
    vec_dual = vectorize(dual, dual_shape(shape))
    @test primal = reshape(vec_primal, shape)
    @test dual == reshape(vec_dual, dual_shape(shape))
    @test dot(primal, dual) == dot(vec_primal, vec_dual)
end

@odow
Copy link
Member Author

odow commented Aug 27, 2024

Sure. But this doesn't really help us catch the fact that the solver might return a "different" value to the one we expected (if we didn't think clearly) for the dual. That would just tell us that Symmetric works. But it would't help tell us we needed the adjoint? (Unless we know good values for primal and dual to test?)

@blegat
Copy link
Member

blegat commented Aug 27, 2024

You're right, then we can do something like:
I think it can just be something like

function test_shape(primal, dual, con::VectorConstraint)
    vec_primal = vectorize(primal, con.shape)
    vec_dual = vectorize(dual, dual_shape(con.shape))
    @test primal = reshape(vec_primal, con.shape)
    @test dual == reshape(vec_dual, dual_shape(con.shape))
    @test dot(primal, dual) == MOI.Utilities.set_dot(vec_primal, vec_dual, con.set)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants