Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing unused usages of clojure.reflect in order to remove this dependency #351

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM clojure:openjdk-11-lein-buster

RUN apt-get update -qq
RUN apt-get install libquadmath0 -qq
RUN apt-get install libquadmath0 maven -qq
WORKDIR /tmp
RUN wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-6/gcc-6-base_6.4.0-17ubuntu1_amd64.deb
RUN wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-6/libgfortran3_6.4.0-17ubuntu1_amd64.deb
Expand Down
18 changes: 18 additions & 0 deletions docker/Dockerfile.jdk8
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM clojure:openjdk-8-lein-buster

RUN apt-get update -qq
RUN apt-get install libquadmath0 maven -qq
WORKDIR /tmp
RUN wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-6/gcc-6-base_6.4.0-17ubuntu1_amd64.deb
RUN wget http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-6/libgfortran3_6.4.0-17ubuntu1_amd64.deb
RUN dpkg -i gcc-6-base_6.4.0-17ubuntu1_amd64.deb
RUN dpkg -i libgfortran3_6.4.0-17ubuntu1_amd64.deb

WORKDIR /usr/src/core.matrix

# Dependencies
COPY project.clj .
RUN lein deps

COPY . .
CMD ["/usr/local/bin/lein", "test"]
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,3 @@
[:div.pure-g
[:div.pure-u-1 header]
[:div.pure-u-1 table]]]))

(defn generate
[]
(let [impl-objs (c/get-impl-objs)
protos (c/extract-implementations (u/extract-protocols) impl-objs)
git-hash (c/get-git-hash)
header (render-header git-hash)
table (render-table impl-objs protos git-hash)]
(render-page header table)))
16 changes: 0 additions & 16 deletions src/main/clojure/clojure/core/matrix/impl/common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@

#?(:clj (do

(defn find-implementers
"Returns a set of implementation names of implementations that
support provided protocol"
[protocol impl-objs]
(->> impl-objs
(filter #(->> % :obj class (u/extends-deep? protocol)))
(map :name)
(into #{})))

(defn extract-implementations
"Returns a a sequence of protocol maps augmented with :implemented-by key
that contains a set of names of supporting implementations"
[protocols impl-objs]
(for [proto protocols]
(assoc proto :implemented-by (find-implementers proto impl-objs))))

(defn get-git-hash
"Returns current revision's git hash"
[]
Expand Down
32 changes: 1 addition & 31 deletions src/main/clojure/clojure/core/matrix/utils.cljc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(ns clojure.core.matrix.utils
"Namespace for core.matrix utilities. Intended mainly for library and tool writers."
(:refer-clojure :exclude [update])
#?@(:clj [(:require [clojure.reflect :as r])
(:import [java.util Arrays]
#?@(:clj [(:import [java.util Arrays]
[clojure.lang IPersistentVector])])
#?(:clj (:require [clojure.core.matrix.macros :refer [TODO is-long-array?]])
:cljs (:require-macros [clojure.core.matrix.macros :refer [TODO]]
Expand Down Expand Up @@ -226,26 +225,6 @@

;; utilities for protocol introspection

#?(:clj
(defn extends-deep?
"This functions differs from ordinary `extends?` by using `extends?`
on all ancestors of given type instead of just type itself. It also
skips `java.lang.Object` that serves as a default implementation
for all protocols"
[proto cls]
;; Here we need a special case to avoid reflecting on primitive type
;; (it will cause an exception)
(if (= (Class/forName "[D") cls)
(extends? proto cls)
(let [bases (-> cls (r/type-reflect :ancestors true) :ancestors)]
(->> bases
(filter (complement #{'Object 'java.lang.Object}))
(map resolve)
(cons cls)
(map (partial extends? proto))
(some true?)))))
)

(defn protocol?
"Returns true if an argument is a protocol'"
[p]
Expand All @@ -271,15 +250,6 @@
(map enhance-protocol-kv)
(sort-by :line))))

(defn unimplemented
"Identifies which protocols are unimplemented for a given array object.

Unimplemented protocols will fall back to the default implementation (for java.lang.Object) which
is likely to be slower than a specialised implementation."
[m]
(let [protocols (extract-protocols)
m (if (class? m) m (class m))]
(map :name (filter #(not (#?(:clj extends-deep? :cljs satisfies?) % m)) protocols))))
))

(defn update-indexed [xs idxs f]
Expand Down
6 changes: 1 addition & 5 deletions src/test/clojure/clojure/core/matrix/test_utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:refer-clojure :exclude [vector?])
(:require [clojure.core.matrix.protocols :as mp]
[clojure.core.matrix :refer :all]
[clojure.core.matrix.utils :refer [extends-deep? extract-protocols]]
[clojure.core.matrix.utils :refer [extract-protocols]]
[clojure.test :refer :all])
(:import [clojure.lang PersistentVector]
[mikera.vectorz Vector]))
Expand All @@ -13,10 +13,6 @@
(is (= (type (long-array 0)) (type (long-array nil))))
(is (= (count (long-array 0)) (count (long-array nil)))))

(deftest test-protocol-extension
(is (extends-deep? mp/PImplementation PersistentVector))
(is (extends-deep? mp/PImplementation Vector)))

;; this tests that all protocols have a default implementation for java.lang.Object
;; (except for specified known exceptions
(deftest test-default-implementations
Expand Down