Skip to content

Commit

Permalink
8.039
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Oct 26, 2021
1 parent d112a95 commit 8a31258
Show file tree
Hide file tree
Showing 44 changed files with 97 additions and 68 deletions.
2 changes: 1 addition & 1 deletion docs/buffered-image.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/cheatsheet.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/datatype-to-dtype-next.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/dimensions-bytecode-gen.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/overview.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.argops.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.bitmap.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.convolve.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.datetime.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.errors.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.ffi.clang.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.ffi.graalvm.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.ffi.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.functional.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.gradient.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/tech.v3.datatype.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.jna.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.jvm-map.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.list.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.locker.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.mmap-writer.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.mmap.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tech.v3.datatype.native-buffer.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.nippy.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.packing.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.reductions.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.rolling.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.sampling.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.struct.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.datatype.wavelet.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.libs.buffered-image.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.libs.neanderthal.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.parallel.for.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.tensor.color-gradients.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/tech.v3.tensor.dimensions.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/tech.v3.tensor.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject cnuernber/dtype-next "8.039-SNAPSHOT"
(defproject cnuernber/dtype-next "8.039"
:description "A Clojure library designed to aid in the implementation of high performance algorithms and systems."
:url "http://github.com/cnuernber/dtype-next"
:license {:name "EPL-2.0"
Expand Down
4 changes: 2 additions & 2 deletions src/tech/v3/datatype/array_buffer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
;;For integer types, everything implements readlong.
;;They also implement readX where X maps to exactly the datatype.
;;For example byte arrays implement readLong and readByte.
(casting/integer-type? cast-dtype)
(or (= cast-dtype :char) (casting/integer-type? cast-dtype))
(concat
[`(readLong [rdr# ~'idx]
(casting/datatype->unchecked-cast-fn
Expand Down Expand Up @@ -129,7 +129,7 @@
(= :boolean cast-dtype)
[`(writeBoolean [wtr# idx# val#]
(ArrayHelpers/aset ~'java-ary (pmath/+ ~offset idx#) val#))]
(casting/integer-type? cast-dtype)
(or (= :char cast-dtype) (casting/integer-type? cast-dtype))
(concat
[`(writeLong [rdr# ~'idx ~'value]
(ArrayHelpers/aset ~'java-ary (pmath/+ ~offset ~'idx)
Expand Down
23 changes: 14 additions & 9 deletions src/tech/v3/datatype/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -689,21 +689,26 @@ tech.v3.tensor.integration-test> (dtype/set-value! (dtype/clone test-tens) [:all
(fn [op-dtype item]
(dispatch/typed-map-1 cast-fn new-dtype item))
(fn [op-dtype item]
(case (casting/simple-operation-space new-dtype
(elemwise-datatype item))
:int64
(let [src-rdr (dtype-proto/elemwise-reader-cast item :int64)]
(let [ewise-dtype (dtype-proto/operational-elemwise-datatype item)
^Buffer src-rdr (dtype-proto/elemwise-reader-cast
item
ewise-dtype)
number? (casting/numeric-type? ewise-dtype)
simp-op-space (casting/simple-operation-space new-dtype)]
(cond
(and number? (identical? simp-op-space :int64))
(reify LongReader
(elemwiseDatatype [rdr] new-dtype)
(lsize [rdr] (.lsize src-rdr))
(readLong [rdr idx] (.readLong src-rdr idx))))
:float64
(let [src-rdr (dtype-proto/elemwise-reader-cast item :float64)]
;;We have to call cast-fn here in order to correctly cache out-of-range
;;issues with types like uint8
(readLong [rdr idx] (cast-fn (.readLong src-rdr idx))))
(and number? (identical? simp-op-space :float64))
(reify DoubleReader
(elemwiseDatatype [rdr] new-dtype)
(lsize [rdr] (.lsize src-rdr))
(readDouble [rdr idx] (.readDouble src-rdr idx))))
(let [src-rdr (->reader item)]
(readDouble [rdr idx] (.readDouble src-rdr idx)))
:else
(reify ObjectReader
(elemwiseDatatype [rdr] new-dtype)
(lsize [rdr] (.lsize src-rdr))
Expand Down
9 changes: 6 additions & 3 deletions src/tech/v3/datatype/casting.clj
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@

(def float-types #{:float32 :float64})

(def int-types (set (concat (flatten (seq signed-unsigned)) [:char])))
(def int-types (set (concat (flatten (seq signed-unsigned)))))

(def signed-int-types (set (keys signed-unsigned)))

(def unsigned-int-types (set (vals signed-unsigned)))

(def host-numeric-types (set (concat signed-int-types float-types)))

(def numeric-types (set (concat host-numeric-types unsigned-int-types [:char])))
(def numeric-types (set (concat host-numeric-types unsigned-int-types)))


(defonce valid-datatype-set (atom nil))
Expand All @@ -98,7 +98,7 @@
(->> (concat (keys datatype->class-map)
(keys aliased-datatypes)
numeric-types
[:object :boolean])
[:object :boolean :char])
(->hash-set))))


Expand Down Expand Up @@ -167,6 +167,9 @@
(quot (int-width dtype) 8)
(float-types dtype)
(quot (float-width dtype) 8)
;;char is a shitty uint16
(identical? dtype :char)
(int-width :uint16)
:else
(throw (ex-info (format "datatype is not numeric: %s" dtype)
{:datatype dtype}))))))
Expand Down
11 changes: 7 additions & 4 deletions src/tech/v3/datatype/native_buffer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
:int64 ['.putLong '.getLong]
:float32 ['.putFloat '.getFloat]
:float64 ['.putDouble '.getDouble])
accum-type (if (casting/integer-type? datatype)
accum-type (if (or (= :char datatype)
(casting/integer-type? datatype))
:int64
:float64)]
`(do
Expand Down Expand Up @@ -267,7 +268,8 @@
;;For integer types, everything implements readlong.
;;They also implement readX where X maps to exactly the datatype.
;;For example byte arrays implement readLong and readByte.
(casting/integer-type? datatype)
(or (= :char datatype)
(casting/integer-type? datatype))
(concat
[`(readLong [rdr# ~'idx]
(casting/datatype->unchecked-cast-fn
Expand Down Expand Up @@ -320,7 +322,8 @@
(= :boolean datatype)
[`(writeBoolean [wtr# idx# ~'value]
(write-value ~address ~swap? ~datatype ~byte-width ~n-elems))]
(casting/integer-type? datatype)
(or (= :char datatype (casting/integer-type? datatype))
(casting/integer-type? datatype))
(concat
[`(writeLong [rdr# ~'idx ~'value]
(write-value ~address ~swap? ~datatype ~byte-width ~n-elems))]
Expand Down Expand Up @@ -354,7 +357,7 @@
`(writeFloat [rdr# ~'idx ~'value]
(write-value ~address ~swap? ~datatype ~byte-width ~n-elems))]
:else
[`(writeObject [wtr# idx# val#]
[`(writeObject [wtr# ~'idx ~'value]
;;Writing values is always checked, no options.
(write-value ~address ~swap? ~datatype ~byte-width ~n-elems))])))))

Expand Down
6 changes: 3 additions & 3 deletions src/tech/v3/datatype/typecast.clj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
:boolean 'tech.v3.datatype.BooleanReader
:int8 'tech.v3.datatype.LongReader
:int16 'tech.v3.datatype.LongReader
:char 'tech.v3.datatype.LongReader
:char 'tech.v3.datatype.ObjectReader
:int32 'tech.v3.datatype.LongReader
:int64 'tech.v3.datatype.LongReader
:float32 'tech.v3.datatype.DoubleReader
Expand All @@ -82,8 +82,8 @@
(case (casting/safe-flatten dtype)
:boolean 'tech.v3.datatype.BooleanWriter
:int8 'tech.v3.datatype.LongWriter
:int16 'tech.v3.datatype.LongtWriter
:char 'tech.v3.datatype.LongWriter
:int16 'tech.v3.datatype.LongWriter
:char 'tech.v3.datatype.ObjectWriter
:int32 'tech.v3.datatype.LongWriter
:int64 'tech.v3.datatype.LongWriter
:float32 'tech.v3.datatype.DoubleWriter
Expand Down
18 changes: 18 additions & 0 deletions test/tech/v3/datatype_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -747,3 +747,21 @@
(is (thrown? Throwable (nth data -11)))
(is (= :a (nth data -11 :a)))
(is (= 0 (nth data -10 :a)))))


(deftest elemwise-cast-container
(let [c (dtype/make-container :float64 [1.2])
ic (dtype/elemwise-cast c :int32)]
(is (= 1 (ic 0))))
(let [c (dtype/make-container :float64 [155])
ic (dtype/elemwise-cast c :int8)]
(is (thrown? Throwable (ic 0))))
(let [c (dtype/make-container :float64 [155])
ic (dtype/elemwise-cast c :uint8)]
(is (= 155 (ic 0))))
;;This one is tricky because the JVM is too stupid to cast
;;an char, which is an unsigned short, to any numeric type without
;;more magic.
(let [c (dtype/make-container :char [155])
ic (dtype/elemwise-cast c :uint8)]
(is (= 155 (ic 0)))))

0 comments on commit 8a31258

Please sign in to comment.