Skip to content

Commit

Permalink
Add support for universal contiguous? function.
Browse files Browse the repository at this point in the history
  • Loading branch information
blueberry committed Jul 28, 2019
1 parent 667412d commit 3df9563
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 5 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*assert* false
*unchecked-math* :warn-on-boxed
*print-length* 128}
:dependencies [[midje "1.9.8"]]}}
:dependencies [[midje "1.9.9"]]}}

:javac-options ["-target" "1.8" "-source" "1.8" "-Xlint:-options"]
:source-paths ["src/clojure" "src/device"]
Expand Down
4 changes: 2 additions & 2 deletions src/clojure/uncomplicate/neanderthal/block.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
(defn row? [a]
(.isRowMajor (api/navigator a)))

(defn gapless? [a]
(.isGapless (api/storage a)))
(defn contiguous? [^Block x]
(.isContiguous x))

(defn wrap-prim [^DataAccessor accessor ^double v]
(.wrapPrim accessor v))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@
ofst)
(stride [_]
strd)
(isContiguous [_]
(= 1 strd))
(dim [_]
n)
(boxedEntry [x i]
Expand Down Expand Up @@ -478,6 +480,8 @@
ofst)
(stride [_]
(.ld stor))
(isContiguous [_]
(.isGapless stor))
(dim [_]
(* m n))
(mrows [_]
Expand Down Expand Up @@ -697,6 +701,8 @@
ofst)
(stride [_]
(.ld stor))
(isContiguous [_]
false)
(dim [_]
(* n n))
(mrows [_]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@
ofst)
(stride [_]
strd)
(isContiguous [_]
(= 1 strd))
(dim [_]
n)
(boxedEntry [x i]
Expand Down Expand Up @@ -518,6 +520,8 @@
ofst)
(stride [_]
(.ld stor))
(isContiguous [_]
(.isGapless stor))
(dim [_]
(* m n))
(mrows [_]
Expand Down Expand Up @@ -705,6 +709,8 @@
ofst)
(stride [_]
(.ld stor))
(isContiguous [_]
false)
(dim [_]
(* n n))
(mrows [_]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@
ofst)
(stride [_]
strd)
(isContiguous [_]
(= 1 strd))
(dim [_]
n)
(entry [_ i]
Expand Down Expand Up @@ -671,6 +673,8 @@
ofst)
(stride [_]
strd)
(isContiguous [_]
(= 1 strd))
(dim [_]
n)
(entry [_ i]
Expand Down Expand Up @@ -930,6 +934,8 @@
ofst)
(stride [_]
(.ld stor))
(isContiguous [_]
(.isGapless stor))
(dim [_]
(* m n))
(mrows [_]
Expand Down Expand Up @@ -1183,6 +1189,8 @@
ofst)
(stride [_]
(.ld stor))
(isContiguous [_]
false)
(dim [_]
(* n n))
(mrows [_]
Expand Down Expand Up @@ -1489,6 +1497,8 @@
ofst)
(stride [_]
(.ld stor))
(isContiguous [_]
(.isGapless stor))
(dim [_]
(* m n))
(mrows [_]
Expand Down Expand Up @@ -2069,6 +2079,8 @@
ofst)
(stride [_]
1)
(isContiguous [_]
true)
(dim [_]
(* n n))
(mrows [_]
Expand Down
1 change: 1 addition & 0 deletions src/java/uncomplicate/neanderthal/internal/api/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public interface Block {

long stride ();

boolean isContiguous ();
}
34 changes: 32 additions & 2 deletions test/uncomplicate/neanderthal/block_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[test :refer :all]]
[uncomplicate.neanderthal
[core :refer :all]
[block :refer [buffer]]])
[block :refer [buffer contiguous?]]])
(:import [clojure.lang IFn$LLD IFn$LD IFn$DD ExceptionInfo]))

(defn test-create [factory]
Expand Down Expand Up @@ -129,6 +129,32 @@
(transfer! b1 a0) => a2
(transfer! a2 b0) => b2)))

(defn test-vctr-contiguous [factory]
(let [x (vctr factory 4)
a (ge factory 4 4 (range 16))]
(facts
"Vector contiguous tests."
(contiguous? x) => true
(contiguous? (row a 0)) => false
(contiguous? (row a 1)) => false
(contiguous? (col a 0)) => true
(contiguous? (col a 1)) => true)))

(defn test-ge-contiguous [factory]
(let [a (ge factory 4 4 (range 16))]
(facts
"GE contiguous tests."
(contiguous? a) => true
(contiguous? (submatrix a 0 0 4 2)) => true
(contiguous? (submatrix a 0 1 4 2)) => true
(contiguous? (submatrix a 0 1 3 2)) => false)))

(defn test-uplo-contiguous [factory uplo]
(let [a (uplo factory 4 (range 16))]
(facts
"Uplo contiguous tests."
(contiguous? a) => false)))

;; ================= Vector ========================================

(defn test-vctr-ifn [factory]
Expand Down Expand Up @@ -444,14 +470,18 @@
(test-equality factory)
(test-release factory)
(test-vctr-op factory)
(test-ge-op factory))
(test-ge-op factory)
(test-vctr-contiguous factory)
(test-ge-contiguous factory)
(test-uplo-contiguous factory tr))

(defn test-both-factories [factory0 factory1]
(test-vctr-transfer factory0 factory1)
(test-ge-transfer factory0 factory1)
(test-tr-transfer factory0 factory1))

(defn test-host [factory]
(test-uplo-contiguous factory sy)
(test-vctr-ifn factory)
(test-vctr-functor factory)
(test-vctr-fold factory)
Expand Down

0 comments on commit 3df9563

Please sign in to comment.