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

dtype/alloc-zeros error #102

Open
benjamin-asdf opened this issue Jun 20, 2024 · 4 comments
Open

dtype/alloc-zeros error #102

benjamin-asdf opened this issue Jun 20, 2024 · 4 comments

Comments

@benjamin-asdf
Copy link

benjamin-asdf commented Jun 20, 2024

Hi, I suppose this is a bug:

cnuernber/dtype-next {:mvn/version "10.113"}
(require '[tech.v3.datatype :as dtype])

(dtype/alloc-zeros :boolean 20)
Error printing return value (ClassCastException) at tech.v3.datatype.native_buffer.ObjectNativeBuf/subBuffer (native_buffer.clj:483).
class java.lang.Long cannot be cast to class clojure.lang.IFn (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')

works with :int8.

More info:

  (let [v (dtype/alloc-zeros :boolean 2)]
    (dtt/->tensor v))
  
  ;; Execution error (NullPointerException) at tech.v3.datatype.copy/unsafe-copy-memory (copy.clj:70).
  ;; Cannot invoke "java.lang.Number.longValue()" because "x" is null
@benjamin-asdf benjamin-asdf changed the title dtype/alloc-zeros error dtype/alloc-zeros print error Jun 20, 2024
@benjamin-asdf benjamin-asdf changed the title dtype/alloc-zeros print error dtype/alloc-zeros error Jun 20, 2024
@cnuernber
Copy link
Owner

Yep definitely a bug

@cnuernber
Copy link
Owner

Looking into this - alloc-zeros is guaranteed to return a native buffer and native buffers in general do not support boolean types as those are logical types with either 1 bit or 8 bit representations depending on context. The dtype/functional namespace in general does treat 0 as false and anything else as true in keeping with the 'c' semantics.

So to make a long story a bit shorter I could alias allocating an int8 buffer with this and then return a custom reader or something like that - is this what you really want?

@benjamin-asdf
Copy link
Author

My suggestion, what would have helped me in the situation, would be to throw an error for :boolean in alloc zeros that explains this. Then the user can chose int8.
maybe: "alloc-zeros: native buffers do not support boolean types. You probably want to use int8 instead."

Yea I agree that the alias idea doesn't sound so great. It's nice that dtype is close to metal like this!

@cnuernber
Copy link
Owner

Better error messages - where have I heard that before?? ;-)

Good solution it makes great sense.

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