Skip to content

Commit

Permalink
Document dfr/reduce-+ & dfr/reduce-* (#104)
Browse files Browse the repository at this point in the history
* add docsctrings for the methods dfr/reduce-+ & dfr/reduce-*

* finish documenting all the functions named like reduce-
  • Loading branch information
shellandbull authored Sep 9, 2024
1 parent a9d05cd commit 9de4bfe
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/tech/v3/datatype/functional.clj
Original file line number Diff line number Diff line change
Expand Up @@ -715,21 +715,61 @@ tech.v3.datatype.functional> (meta regressor)


(defn reduce-*
"Invokes a reduce operation with the operand * to multiply items together.
Examples:
```clojure
user> (dfn/reduce-* [1 2 3 4])
24
user> (dfn/reduce-* [-1 1.1 4])
-4.4
```"
([x]
(tech.v3.datatype.functional-api/reduce-* x)))


(defn reduce-+
"Invokes a reduce operation with the operand + to add items together.
Examples:
```clojure
user> (dfn/reduce-+ [1 2 3 4])
10
user> (dfn/reduce-+ [-1 1.1 4])
4.1
```"
([x]
(tech.v3.datatype.functional-api/reduce-+ x)))


(defn reduce-max
"Invokes a reduce operation with the operand max find the maximum item of a list.
Examples:
```clojure
user> (dfn/reduce-max [1 2 3 4])
4
user> (dfn/reduce-max [10 -10 20 100 -1])
100
```"
([x]
(tech.v3.datatype.functional-api/reduce-max x)))


(defn reduce-min
"Invokes a reduce operation with the operand min find the minimum item of a list.
Examples:
```clojure
user> (dfn/reduce-min [1 2 3 4])
1
user> (dfn/reduce-min [10 -10 20 100 -1])
-10
```"
([x]
(tech.v3.datatype.functional-api/reduce-min x)))

Expand Down
40 changes: 40 additions & 0 deletions src/tech/v3/datatype/functional_api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,65 @@

;;Implement only reductions that we know we will use.
(defn reduce-+
"Invokes a reduce operation with the operand + to add items together.
Examples:
```clojure
user> (dfn/reduce-+ [1 2 3 4])
10
user> (dfn/reduce-+ [-1 1.1 4])
4.1
```"
[x]
;;There is a fast path specifically for summations
(dtype-reductions/commutative-binary-reduce
(:tech.numerics/+ binary-op/builtin-ops) x))


(defn reduce-*
"Invokes a reduce operation with the operand * to multiply items together.
Examples:
```clojure
user> (dfn/reduce-* [1 2 3 4])
24
user> (dfn/reduce-* [-1 1.1 4])
-4.4
```"
[x]
(dtype-reductions/commutative-binary-reduce
(:tech.numerics/* binary-op/builtin-ops) x))


(defn reduce-max
"Invokes a reduce operation with the operand max find the maximum item of a list.
Examples:
```clojure
user> (dfn/reduce-max [1 2 3 4])
4
user> (dfn/reduce-max [10 -10 20 100 -1])
100
```"
[x]
(dtype-reductions/commutative-binary-reduce
(:tech.numerics/max binary-op/builtin-ops) x))


(defn reduce-min
"Invokes a reduce operation with the operand min find the minimum item of a list.
Examples:
```clojure
user> (dfn/reduce-min [1 2 3 4])
1
user> (dfn/reduce-min [10 -10 20 100 -1])
-10
```"
[x]
(dtype-reductions/commutative-binary-reduce
(:tech.numerics/min binary-op/builtin-ops) x))
Expand Down

0 comments on commit 9de4bfe

Please sign in to comment.