uncomplicate / neanderthal

Fast Clojure Matrix Library
http://neanderthal.uncomplicate.org
Eclipse Public License 1.0
1.06k stars 56 forks source link

ClassCastException with dge/mv in DLFP book #82

Closed djjolicoeur closed 4 years ago

djjolicoeur commented 4 years ago

Not sure if this belongs here, but I just picked up the DLFP book and ran into an issue w/ the first exercise. Intel MKL installed and appears to be working. I actually ran into this in my own code and concluded I must be doing something wrong, so I pulled down the book code and tried to run it there as well (captured below) with the same results. It is entirely possible that I still managed to mess it up somehow, so any nudge in the right direction would be appreciated!

java version

➜  dlfp java --version 
java --version 
java 10.0.2 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
➜  dlfp

project.clj

(defproject deep-learning-for-programmers "0.12.0"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.10.1"]
                 [uncomplicate/neanderthal "0.26.1"]
                 [criterium/criterium "0.4.5"]
                 [org.clojure/data.csv "0.1.4"]]
  :plugins [[lein-with-env-vars "0.1.0"]]
  :env-vars {:DYLD_LIBRARY_PATH "/opt/intel/mkl/lib:/opt/intel/lib"}
  :jvm-opts ["--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED"]
  :resource-paths ["data"]
  :global-vars {*warn-on-reflection* true
                *assert* false
                *unchecked-math* :warn-on-boxed
                *print-length* 128})

code and output

(ns dragan.rocks.dlfp.part-2.representing-layers-and-connections
  (:require [uncomplicate.commons.core :refer [with-release]]
            [uncomplicate.neanderthal
             [native :refer [dv dge]]
             [core :refer [mv mv!]]]))

(def x (dv 0.3 0.9))

(def w1 (dge 4 2 [0.3 0.6
                  0.1 2.0
                  0.9 3.7
                  0.0 1.0]
             {:layout :row}))

(def h1 (dv 4))

(mv w1 x h1)

;; Execution error (ClassCastException) at uncomplicate.neanderthal.core/mv (core.clj:1314).
;; uncomplicate.neanderthal.internal.host.buffer_block.RealBlockVector cannot be cast to
;; uncomplicate.neanderthal.internal.api.Matrix
blueberry commented 4 years ago

Hi @djjolicoeur

I’m on my iPad, so I cannot run that code, but I’m pretty sure that the problem is caused by the mismatched use of mv/mv!

In particular case that you’ve posted, the function should be mv! (note the !)

The immutable version should be (mv w1 x), and it is used only to introduc the reader to the simplest possible layer propagation.

Please check whether the same error is in the book code. If it is, I must have introduced by error, and will change this asap.

djjolicoeur commented 4 years ago

@blueberry it is (mv w1 x h1) in the 0.12.0 book code and book as well. Well, at least I'm less confused about why we need h1 there!