Back
comparator (clj)
(source)function
(comparator pred)
Returns an implementation of java.util.Comparator based upon pred.
Examples
mikera/core.matrix
(ns clojure.core.matrix.test-api
(:refer-clojure :exclude [vector?])
; (:use [clojure.core.matrix])
(:require [clojure.core.matrix.protocols :as mp]
[clojure.core.matrix.linear :as li]
; [clojure.core.matrix :refer [:all]]
[clojure.core.matrix.operators :as op]
[clojure.core.matrix :as m
:refer [abs abs! acos acos! add add! add-inner-product! add-outer-product! add-product add-product! add-row add-scaled add-scaled! add-scaled-product add-scaled-product! array array? as-vector asin asin! assign assign! assign-array! atan atan! block-diagonal-matrix broadcast broadcast-coerce broadcast-like cbrt cbrt! ceil ceil! clamp clone cmp coerce column-count column-matrix column-matrix? columns compute-matrix conforming? conjoin conjoin-along cos cos! cosh cosh! cross cross! current-implementation current-implementation-object dense density det diagonal diagonal-matrix diagonal? dimension-count dimensionality distance div div! dot e* e= e== ecount eif element-type emap emap! emap-indexed emap-indexed! emax emin emul emul! ensure-mutable eq equals ereduce eseq esum exp exp! fill fill! floor floor! ge get-column get-row gt identity-matrix identity-matrix? immutable index index-seq index-seq-for-shape index? inner-product inverse join join-along label label-index labels le length length-squared lerp lerp! log log! log10 log10! logistic logistic! lower-triangular? lt magnitude magnitude-squared main-diagonal matrix matrix? maximum mget minimum mmul mset mset! mul mul! multiply-row mutable mutable? native native? ne negate negate! new-array new-matrix new-scalar-array new-sparse-array new-vector non-zero-count non-zero-indices normalise normalise! numerical? order orthogonal? outer-product pack permutation-matrix pow pow! rank relu relu! reshape rotate round round! row-count row-matrix row-matrix? rows same-shape? scalar scalar-array scalar? scale scale! scale-add scale-add! select select-indices select-view set-column set-column! set-current-implementation set-indices set-indices! set-inner-product! set-row set-row! set-selection set-selection! shape shift signum signum! sin sin! sinh sinh! slice slice-count slice-map slice-view slice-views slices softmax softmax! softplus softplus! sparse sparse-array sparse-matrix sparse? sqrt sqrt! square square? sub sub! submatrix subvector supports-dimensionality? supports-shape? swap-rows symmetric? tan tan! tanh tanh! to-degrees to-degrees! to-double-array to-nested-vectors to-object-array to-radians to-radians! to-vector trace transform transform! transpose transpose! upper-triangular? vec? zero-array zero-count zero-dimensional? zero-matrix zero-matrix? zero-vector validate-shape]]
[clojure.core.matrix.implementations :as imp]
[clojure.core.matrix.utils :refer [broadcast-shape]]
#?@(:clj [[clojure.core.matrix.macros :refer [error doseq-indexed]]
[clojure.core.matrix.macros-clj :refer [error?]]
[clojure.test :refer [deftest is testing run-tests]]
[clojure.core.matrix.demo.examples]]
:cljs [[cljs.test :refer-macros [deftest is testing run-tests]]
[thinktopic.aljabr.core :as aljabr]
;[clojure.core.matrix :refer-macros [with-implementation]]
[clojure.core.matrix.macros :refer-macros [error]]
[clojure.core.matrix.macros-cljs :refer-macros [error?]]]))
#?(:clj (:import [java.io StringWriter])))
(comment
;;fails test
(deftest test-rank
(testing "default comparators"
(is (error? (rank 1)))
(is (= [0 2 1] (rank [10 30 20])))
(is (= [0 1 2] (sort (rank ["a" "a" "a"]))))
(is (= [[2 1 0] [0 1 2]] (rank [[:z :m :a] [-100 0.0 1000]]))))
(testing "custom comparators"
(is (error? (rank identity 1)))
(is (= [2 0 1] (rank > [10 30 20])))
(is (= [0 2 1] (rank #(< (count %1) (count %2)) ["a" "ccc" "bb"])))
(is (= [[0 1 2] [2 1 0]] (rank > [[8 7 6] [-1.0 1.0 3.0]]))))))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
#?(:cljs (do
(t/ann-protocol cljs.core/Fn)
(t/ann-protocol cljs.core/IFn)
(t/ann-protocol cljs.core/ICloneable
-clone [cljs.core/ICloneable :-> t/Any])
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IIterable
;; TODO
-iterator [(cljs.core/IIterable x) :-> t/Any #_Object])
(t/ann-protocol cljs.core/ICounted
-count [cljs.core/ICounted :-> t/Num])
(t/ann-protocol cljs.core/IEmptyableCollection
;; :/ TFn param on protocol?
-empty [cljs.core/IEmptyableCollection :-> t/Any])
(t/ann-protocol cljs.core/ICollection
-conj [cljs.core/ICollection t/Any :-> cljs.core/ICollection])
(t/ann-protocol [[x :variance :covariant]] cljs.core/IIndexed
-nth (t/All [y]
[(cljs.core/IIndexed x) t/JSnumber (t/? y) :-> (t/U x y)]))
(t/ann-protocol cljs.core/ASeq)
(t/ann-protocol [[x :variance :covariant
;;FIXME causes mystery error
;:< t/AnyNilableNonEmptySeq
]]
cljs.core/ISeqable)
(t/ann-protocol [[x :variance :covariant]] cljs.core/ISeq
-first [(cljs.core/ISeq x) :-> (t/Nilable x)]
-rest [(cljs.core/ISeq x) :-> (cljs.core/ISeq x)])
;cljs.core/INext [[x :variance :covariant]]
(t/ann-protocol [[v :variance :covariant]] cljs.core/ILookup)
(t/ann-protocol [[k :variance :covariant]
[v :variance :covariant]]
cljs.core/IAssociative
-contains-key [(cljs.core/IAssociative k v) t/Any :-> t/Bool]
-assoc (t/All [k1 v1] [(cljs.core/IAssociative k v) k1 v1 :->
(cljs.core/IAssociative (t/U k k1) (t/U v v1))]))
(t/ann-protocol cljs.core/IMap
-dissoc [cljs.core/IMap t/Any :-> cljs.core/IMap])
(t/ann-protocol [[k :variance :covariant]
[v :variance :covariant]]
cljs.core/IMapEntry
-key [(cljs.core/IMapEntry k v) :-> k]
-val [(cljs.core/IMapEntry k v) :-> v])
(t/ann-protocol cljs.core/ISet
-disjoin (t/All [s] [s t/Any :-> s]))
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IStack
-peek [(cljs.core/IStack x) :-> (t/U nil x)]
-pop [(cljs.core/IStack x) :-> (cljs.core/IStack x)])
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IVector
-assoc-n (t/All [x1] [(cljs.core/IVector x) t/Num x1
:-> (cljs.core/IVector (t/U x x1))]))
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IDeref
-deref [(cljs.core/IDeref x) :-> x])
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IDerefWithTimeout
-deref-with-timeout [(cljs.core/IDerefWithTimeout x) :-> x])
(t/ann-protocol cljs.core/IMeta
-meta [cljs.core/IMeta :-> (t/Nilable (t/Map t/Any t/Any))])
(t/ann-protocol cljs.core/IWithMeta
-with-meta [cljs.core/IWithMeta (t/Nilable (t/Map t/Any t/Any)) :-> cljs.core/IWithMeta])
;TODO
;cljs.core/IReduce [[]]
(t/ann-protocol cljs.core/IKVReduce ;;TODO
-kv-reduce [cljs.core/IKVReduce [t/Any t/Any t/Any :-> t/Any] :-> t/Any])
(t/ann-protocol cljs.core/IList)
(t/ann-protocol cljs.core/IEquiv
-equiv [cljs.core/IEquiv t/Any :-> t/Bool])
(t/ann-protocol cljs.core/IHash
-hash [cljs.core/IHash :-> t/Num])
(t/ann-protocol cljs.core/ISequential)
(t/ann-protocol cljs.core/IRecord)
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IReversible
-rseq [(cljs.core/IReversible x) :-> (t/NilableNonEmptySeq x)])
(t/ann-protocol [[k :variance :covariant]
[v :variance :covariant]] cljs.core/IFind
-find [(cljs.core/IFind k v) t/Any :-> (t/Nilable (cljs.core/IMapEntry k v))]
)
(t/ann-protocol [[x :variance :invariant]]
cljs.core/ISorted
-sorted-seq [(cljs.core/ISorted x) t/Bool :-> (t/Nilable (t/ASeq x))]
;; second arg => comparable?
-sorted-seq-from [(cljs.core/ISorted x) t/Any t/Bool :-> (t/Nilable (t/ASeq x))]
-entry-key [(cljs.core/ISorted x) t/Any :-> t/Any]
-comparator [(cljs.core/ISorted x) :-> [x x :-> t/Num]])
(t/ann-protocol cljs.core/IPending)
;cljs.core/IWriter [[]]
;cljs.core/IPrintWithWriter [[]]
; ;TODO
;;cljs.core/IWatchable [[]]
; ;cljs.core/IEditableCollection [[]]
; ;cljs.core/ITransientCollection [[]]
; ;cljs.core/ITransientAssociative [[]]
; ;cljs.core/ITransientMap [[]]
; ;cljs.core/ITransientVector [[]]
; ;cljs.core/ITransientSet [[]]
(t/ann-protocol [[x :variance :invariant]]
cljs.core/IComparable)
; ;cljs.core/IChunk [[]]
; ;cljs.core/IChunkedSeq [[]]
; ;cljs.core/IChunkedNext [[]]
(t/ann-protocol cljs.core/INamed
-named [cljs.core/INamed :-> t/Str]
-namespace [cljs.core/INamed :-> (t/Nilable t/Str)])
(t/ann-protocol [[x :variance :invariant]]
cljs.core/IVolatile
-vreset! (t/All [x] [(cljs.core/IVolatile x) x :-> x]))
cc/comparator (t/All [x y] [[x y :-> t/Any] :-> (t/I Comparator [x y :-> t/AnyInteger])])
camsaul/methodical
(ns methodical.impl.dispatcher.everything
(:refer-clojure :exclude [methods])
(:require
[clojure.core.protocols :as clojure.protocols]
[methodical.impl.dispatcher.common :as dispatcher.common]
[methodical.interface :as i]
[methodical.util.describe :as describe]
[pretty.core :as pretty])
(:import
(methodical.interface Dispatcher)))
(matching-primary-methods [_ method-table _]
(let [primary-methods (i/primary-methods method-table)
comparatorr (dispatcher.common/domination-comparator (deref hierarchy-var) prefs)]
(for [[dispatch-value method] (sort-by first comparatorr primary-methods)]
(vary-meta method assoc :dispatch-value dispatch-value))))
(matching-aux-methods [_ method-table _]
(let [aux-methods (i/aux-methods method-table)
comparatorr (dispatcher.common/domination-comparator (deref hierarchy-var) prefs)]
(into {} (for [[qualifier dispatch-value->methods] aux-methods]
[qualifier (for [[dispatch-value methods] (sort-by first comparatorr dispatch-value->methods)
method methods]
(vary-meta method assoc :dispatch-value dispatch-value))]))))
dco-dev/interval-tree
(ns com.dean.interval-tree.tree.interval-set
(:require [clojure.core.reducers :as r :refer [coll-fold]]
[clojure.set]
[com.dean.interval-tree.tree.interval :as interval]
[com.dean.interval-tree.tree.node :as node]
[com.dean.interval-tree.tree.order :as order]
[com.dean.interval-tree.tree.protocol :as proto]
[com.dean.interval-tree.tree.root]
[com.dean.interval-tree.tree.tree :as tree])
(:import [clojure.lang RT]
[com.dean.interval_tree.tree.protocol PExtensibleSet]
[com.dean.interval_tree.tree.root INodeCollection
IBalancedCollection
IOrderedCollection
IIntervalCollection]))
java.util.SortedSet
(comparator [_]
cmp)
(first [this]
(with-interval-set this
(node/-k (tree/node-least root))))
(last [this]
(with-interval-set this
(node/-k (tree/node-greatest root))))
dco-dev/interval-tree
(ns com.dean.interval-tree.tree.ordered-set
(:require [clojure.core.reducers :as r :refer [coll-fold]]
[clojure.set]
[com.dean.interval-tree.tree.node :as node]
[com.dean.interval-tree.tree.order :as order]
[com.dean.interval-tree.tree.protocol :as proto]
[com.dean.interval-tree.tree.root]
[com.dean.interval-tree.tree.tree :as tree])
(:import [clojure.lang RT]
[com.dean.interval_tree.tree.protocol PExtensibleSet]
[com.dean.interval_tree.tree.root INodeCollection
IBalancedCollection
IOrderedCollection]))
java.util.SortedSet
(comparator [_]
cmp)
(first [this]
(with-ordered-set this
(node/-k (tree/node-least root))))
(last [this]
(with-ordered-set this
(node/-k (tree/node-greatest root))))
(headSet [this x]
(with-ordered-set this
(new OrderedSet (tree/node-split-lesser root x) cmp alloc stitch {})))
(tailSet [this x]
(with-ordered-set this
(new OrderedSet (tree/node-split-greater root x) cmp alloc stitch {})))
(subSet [this from to]
(with-ordered-set this
(let [left (tree/node-split-greater root from)
right (tree/node-split-lesser root to)
result (tree/node-set-intersection left right)]
(new OrderedSet result cmp alloc stitch {}))))