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

Hard crash when multiplying by empty matrix (process exits -1) #92

Closed
jdanbrown opened this issue Nov 30, 2018 · 3 comments
Closed

Hard crash when multiplying by empty matrix (process exits -1) #92

jdanbrown opened this issue Nov 30, 2018 · 3 comments

Comments

@jdanbrown
Copy link

jdanbrown commented Nov 30, 2018

import Surge

let X = Matrix<Float>([[1]])
let Y = Matrix<Float>([[]])

print("X")
print(X) // Ok
print("Y")
print(Y) // Ok
print("X*Y")
print(X*Y) // Hard crash

Output:

X
(       1.0     )

Y
(               )

X*Y
ldb must be >= MAX(N,1): ldb=0 N=0ldc must be >= MAX(N,1): ldc=0 N=0BLAS error: Parameter number 11 passed to cblas_sgemm had an invalid value

When run like swift <script>.swift, process prints that error msg and exits -1 (= 255), without printing a stacktrace. When run in Xcode, debugger doesn't activate.

Seems like Surge mul() needs to guard against the rows=0 / columns=0 cases and return an appropriate empty Matrix, instead of letting blas crash?

@jdanbrown jdanbrown changed the title Hard crash when multiplying by empty matrix (process exits 0) Hard crash when multiplying by empty matrix Nov 30, 2018
@jdanbrown jdanbrown changed the title Hard crash when multiplying by empty matrix Hard crash when multiplying by empty matrix (process exits -1) Nov 30, 2018
@alejandro-isaza
Copy link
Collaborator

Added a precondition check.

@jdanbrown
Copy link
Author

jdanbrown commented Nov 30, 2018

Thanks! But what do you think about returning an empty/zero matrix instead of treating it as an error? That seems less surprising mathematically, since empty matrices are valid objects. That's what e.g. numpy chooses to do:

>>> M = lambda r, c: np.random.rand(r, c)

>>> np.dot(M(1,2), M(2,0))
array([], shape=(1, 0), dtype=float64)

>>> np.dot(M(0,2), M(2,3))
array([], shape=(0, 3), dtype=float64)

>>> np.dot(M(1,0), M(0,3))
array([[0., 0., 0.]])

@alejandro-isaza
Copy link
Collaborator

Interesting, what about this: https://github.com/mattt/Surge/pull/93

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

No branches or pull requests

2 participants