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

[fix] check for invalid axis in concat #16

Merged
merged 1 commit into from
Jan 5, 2025

Conversation

kchanqvq
Copy link
Contributor

Previously this is not checked and may silently give wrong result:

> (concat (list (asarray '(1 2 3))
                     (asarray '(4 5 6)))
               :axis 1)
#<STANDARD-DENSE-ARRAY :ROW-MAJOR 3 DOUBLE-FLOAT
    1.000
    4.000
    5.000
   {10042CB033}>

@digikar99
Copy link
Owner

Error checks should use (policy-cond:with-expectations (= 0 safety) ...) as in the following:

(policy-cond:with-expectations (cl:= 0 safety)
((assertion (let ((out-shape (out-shape-for-concat axis array-likes)))
(equal out-shape (narray-dimensions out)))
(out)))

This allows the checks to be skipped if the code is inline-compiled with (safety 0) optimization.

@kchanqvq
Copy link
Contributor Author

kchanqvq commented Jan 1, 2025

That's good to know! Although, is this necessary in this case? It is a single comparison which is very likely much cheaper than anything else in out-shape-for-concat. Moreover I take it that out-shape-for-concat is not intended to be used in high performance code anyway -- one use is inside policy-cond:with-expectations, the other is for allocating zeros array at runtime. Thoughts?

@digikar99
Copy link
Owner

That's a good argument :). But then I'd atleast like an assert with non-nil places, so users can recover from the error without unwinding the stack.

@kchanqvq
Copy link
Contributor Author

kchanqvq commented Jan 1, 2025

Good point about error recovering!

@digikar99
Copy link
Owner

Actually, this looks like a bad point for error recovery. The recovery through the change of values should happen in the polymorph itself, since those changes need to be visible to the rest of the algorithm. You can revert to the previous simple error and mention this error recovery as a TODO comment in the polymorph body. Later, someone could better the error recovery.

@digikar99 digikar99 merged commit c1f9b1f into digikar99:master Jan 5, 2025
2 of 4 checks passed
@digikar99
Copy link
Owner

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants