Skip to content

Commit

Permalink
Doc fix in argops and Fixes #120
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Oct 20, 2024
1 parent 6247a12 commit dca2f34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/tech/v3/datatype/argops.clj
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@
- `:storage-datatype` - `:int32`, `:int64, or `:bitmap`, defaults to whatever will fit
based on the element count of the reader.
- `:unordered?` - defaults to true, if true uses a slower algorithm that guarantees
- `:unordered?` - defaults to false, if true uses a slower algorithm that guarantees
the resulting index lists will be ordered. In the case where storage is
bitmap, unordered reductions are used as the bitmap forces the end results to be
ordered
Expand Down
66 changes: 23 additions & 43 deletions src/tech/v3/datatype_api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,10 @@


(defn ^:no-doc make-reader-fn
[datatype advertised-datatype n-elems read-fn]
[_datatype advertised-datatype n-elems read-fn]
(let [n-elems (long n-elems)]
(cond
(identical? :boolean datatype)
(reify BooleanReader
(elemwiseDatatype [rdr] advertised-datatype)
(lsize [rdr] n-elems)
(readObject [rdr idx]
(errors/check-idx idx n-elems)
(Casts/booleanCast (.invokePrim ^IFn$LO read-fn idx)))
(subBuffer [rdr sidx eidx]
(ChunkedList/sublistCheck sidx eidx n-elems)
(make-reader-fn datatype advertised-datatype (- eidx sidx)
(reify IFnDef$LO
(invokePrim [this idx]
(.invokePrim ^IFn$LO read-fn (+ sidx idx))))))
(reduce [rdr rfn init]
(loop [idx 0
acc init]
(if (and (< idx n-elems) (not (reduced? acc)))
(recur (unchecked-inc idx) (rfn acc
(Casts/booleanCast
(.invokePrim ^IFn$LO read-fn idx))))
(Reductions/unreduce acc)))))
(casting/integer-type? datatype)
(instance? IFn$LL read-fn)
(reify LongReader
(elemwiseDatatype [rdr] advertised-datatype)
(lsize [rdr#] n-elems)
Expand All @@ -171,7 +150,7 @@
(.invokePrim ^IFn$LL read-fn (+ sidx idx))))))
(reduce [rdr rfn init]
(Reductions/longSamplerReduction rfn init read-fn n-elems)))
(casting/float-type? datatype)
(instance? IFn$LD read-fn)
(reify DoubleReader
(elemwiseDatatype [rdr] advertised-datatype)
(lsize [rdr#] n-elems)
Expand All @@ -187,20 +166,22 @@
(reduce [rdr rfn acc]
(Reductions/doubleSamplerReduction rfn acc read-fn n-elems)))
:else
(reify ObjectReader
(elemwiseDatatype [rdr] advertised-datatype)
(lsize [rdr] n-elems)
(readObject [rdr idx]
(errors/check-idx idx n-elems)
(.invokePrim ^IFn$LO read-fn idx))
(subBuffer [rdr sidx eidx]
(ChunkedList/sublistCheck sidx eidx n-elems)
(make-reader-fn datatype advertised-datatype (- eidx sidx)
(reify IFnDef$LO
(invokePrim [this idx]
(.invokePrim ^IFn$LO read-fn (+ sidx idx))))))
(reduce [rdr rfn acc]
(Reductions/samplerReduction rfn acc read-fn n-elems))))))
(do
(assert (instance? IFn$LO read-fn))
(reify ObjectReader
(elemwiseDatatype [rdr] advertised-datatype)
(lsize [rdr] n-elems)
(readObject [rdr idx]
(errors/check-idx idx n-elems)
(.invokePrim ^IFn$LO read-fn idx))
(subBuffer [rdr sidx eidx]
(ChunkedList/sublistCheck sidx eidx n-elems)
(make-reader-fn advertised-datatype (- eidx sidx)
(reify IFnDef$LO
(invokePrim [this idx]
(.invokePrim ^IFn$LO read-fn (+ sidx idx))))))
(reduce [rdr rfn acc]
(Reductions/samplerReduction rfn acc read-fn n-elems)))))))


(defmacro make-reader
Expand Down Expand Up @@ -232,7 +213,7 @@ user> (dtype/make-reader :float32 5 (* idx 2))
(casting/ensure-valid-datatype ~reader-datatype)
(make-reader-fn
~reader-datatype ~advertised-datatype ~n-elems
~(cond
~(cond
(casting/integer-type? reader-datatype)
`(reify IFnDef$LL
(invokePrim [this# ~'idx] (Casts/longCast ~read-op)))
Expand Down Expand Up @@ -265,10 +246,9 @@ user> (dtype/make-reader :float32 5 (* idx 2))
(constantly (clojure.core/reverse item))
(fn [res-dt ^Buffer rdr]
(case (casting/simple-operation-space res-dt)
:int64 (make-reader res-dt rc (.readLong rdr (- drc idx)))
:float64 (make-reader res-dt rc (.readDouble rdr (- drc idx)))
:boolean (make-reader res-dt rc (.readBoolean rdr (- drc idx)))
(make-reader res-dt rc (.readObject rdr (- drc idx)))))
:int64 (make-reader :int64 rc (.readLong rdr (- drc idx)))
:float64 (make-reader :float64 rc (.readDouble rdr (- drc idx)))
(make-reader :object rc (.readObject rdr (- drc idx)))))
item))))


Expand Down

0 comments on commit dca2f34

Please sign in to comment.