-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,43 @@ | ||
(ns tech.v3.neanderthal) | ||
(ns tech.v3.neanderthal | ||
(:require [uncomplicate.neanderthal.native :as n-native] | ||
[tech.v3.datatype.errors :as errors] | ||
[tech.v3.tensor :as dtt] | ||
[tech.v3.datatype.copy-make-container :as dt-cmc] | ||
[tech.v3.datatype.base :as dtype-base] | ||
[clojure.tools.logging :as log])) | ||
|
||
|
||
(def ^:private impl | ||
{:tensor->matrix (requiring-resolve 'tech.v3.libs.neanderthal-pre-48/tensor->matrix) | ||
:dtype->native-factory (requiring-resolve 'tech.v3.libs.neanderthal-pre-48/datatype->native-factory)}) | ||
(try | ||
;;test for uncomplicate javacpp support | ||
(require '[uncomplicate.clojure-cpp]) | ||
(require '[tech.v3.libs.neanderthal-post-48]) | ||
(catch Exception e | ||
(require '[tech.v3.libs.neanderthal-pre-48]))) | ||
|
||
|
||
(defn tensor->matrix | ||
([tens] ((get impl :tensor->matrix) tens)) | ||
([tens layout datatype] | ||
((get impl :tensor->matrix) tens layout datatype))) | ||
(let [tshape (dtype-base/shape tens) | ||
_ (errors/when-not-errorf (== 2 (count tshape)) | ||
"Only 2D tensors can transform to neanderthal matrix") | ||
[n-rows n-cols] tshape | ||
layout (or layout :column) | ||
nmat (case (or datatype (dtype-base/elemwise-datatype tens)) | ||
:float64 | ||
(n-native/dge n-rows n-cols {:layout layout}) | ||
:float32 | ||
(n-native/fge n-rows n-cols {:layout layout})) | ||
ntens (dtt/as-tensor nmat)] | ||
(dt-cmc/copy! tens ntens) | ||
nmat)) | ||
([tens] | ||
(tensor->matrix tens nil nil))) | ||
|
||
|
||
(defn datatype->native-factory | ||
[dtype] | ||
((get impl :datatype->native-factory) dtype)) | ||
(case dtype | ||
:float64 | ||
(n-native/factory-by-type Double/TYPE) | ||
:float32 | ||
(n-native/factory-by-type Float/TYPE))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters