Skip to content

Commit

Permalink
Updated consumers and enabled a simple printing pathway for one line …
Browse files Browse the repository at this point in the history
…printing of array buffers.
  • Loading branch information
cnuernber committed Mar 26, 2021
1 parent 7812fd4 commit 2bcefac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
15 changes: 15 additions & 0 deletions java/tech/v3/datatype/Consumers.java
Expand Up @@ -4,12 +4,27 @@
import java.util.function.DoubleConsumer;
import java.util.function.LongConsumer;
import java.util.function.IntConsumer;
import java.util.function.Consumer;
import java.util.function.DoublePredicate;
import java.util.List;
import clojure.lang.IDeref;


public class Consumers {
public interface CombinedConsumer extends DoubleConsumer,
LongConsumer,
IntConsumer,
Consumer
{
public default void accept(double val) { acceptDouble(val); }
public default void accept(long val) { acceptLong(val); }
public default void accept(int val) { acceptInt(val); }
public default void accept(Object val) { acceptObject(val); }
public void acceptDouble(double val);
public void acceptLong(long val);
public void acceptInt(int val);
public void acceptObject(Object val);
}
//Consumers are created per in thread-independent contexts at each stage of
//the reduction.
public interface StagedConsumer extends IDeref
Expand Down
3 changes: 1 addition & 2 deletions src/tech/v3/datatype/array_buffer.clj
Expand Up @@ -36,8 +36,7 @@
(-> (dtype-proto/sub-buffer ~buffer offset# length#)
(dtype-proto/->reader)))
dtype-proto/PDatatype
(datatype [this#]
(dtype-proto/datatype ~buffer))
(datatype [this#] :object)
dtype-proto/PElemwiseReaderCast
(elemwise-reader-cast [this# new-dtype#] this#)
~(typecast/datatype->io-type (casting/safe-flatten cast-dtype))
Expand Down
26 changes: 16 additions & 10 deletions src/tech/v3/datatype/pprint.clj
Expand Up @@ -39,16 +39,22 @@
(defn buffer->string
(^String [buffer typename]
(let [n-items (dtype-proto/ecount buffer)
datatype (dtype-proto/elemwise-datatype buffer)
format-str (if (> n-items 20)
"#%s<%s>%s\n[%s...]"
"#%s<%s>%s\n[%s]")]
(format format-str
typename
(name datatype)
[n-items]
(-> (dtype-proto/sub-buffer buffer 0 (min 20 n-items))
(print-reader-data)))))
simple-print? (:simple-print? (meta buffer))
reader-data (-> (dtype-proto/sub-buffer buffer 0 (min 20 n-items))
(print-reader-data))
datatype (dtype-proto/elemwise-datatype buffer)]
(if simple-print?
(format (if (> n-items 20)
"[%s...]"
"[%s]")
reader-data)
(format (if (> n-items 20)
"#%s<%s>%s\n[%s...]"
"#%s<%s>%s\n[%s]")
typename
(name datatype)
[n-items]
reader-data))))
(^String [buffer]
(buffer->string buffer (.getCanonicalName (.getClass ^Object buffer)))))

Expand Down

0 comments on commit 2bcefac

Please sign in to comment.