Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/mikera/core.matrix.git into
Browse files Browse the repository at this point in the history
develop

Conflicts:
	src/test/clojure/clojure/core/matrix/test_double_array.clj
  • Loading branch information
mikera committed Sep 27, 2017
2 parents 305dc7c + 8939cf6 commit 801c55e
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 257 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/.settings
/classes
/doc

/out
.DS_Store
.html
bench
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: java
jdk:
- oraclejdk8
- oraclejdk7
- openjdk7
sudo: false
sudo: true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file, as of core.matrix 0.50.0
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.61.0] - 2017-...
### Added
- add-emap! and set-emap! API functions

## [0.60.3] - 2017-05-18
### Fixed
- New upload to Clojars attempting to resolve deployment issue (see: https://github.com/clojars/clojars-web/issues/640)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>core.matrix</artifactId>
<description>N-dimensional array programming API for Clojure</description>
<version>0.60.4-SNAPSHOT</version>
<version>0.61.1-SNAPSHOT</version>
<packaging>jar</packaging>

<url>https://github.com/mikera/core.matrix</url>
Expand Down
46 changes: 21 additions & 25 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,36 @@

:cljs
{:dependencies [[org.clojure/clojurescript "1.7.228"]
[thinktopic/aljabr "0.1.0-SNAPSHOT" :exclusions [net.mikera/core.matrix]]]
[thinktopic/aljabr "0.1.0-SNAPSHOT" :exclusions [net.mikera/core.matrix]]
]

:plugins [[lein-figwheel "0.5.0-6"]
[lein-cljsbuild "1.1.2"]]
[lein-doo "0.1.7"]
[lein-cljsbuild "1.1.7"]
]

:cljsbuild {:builds
[{:id :dev
:figwheel true
:source-paths ["src/main/clojure" "src/test/cljs" "src/test/clojure"]
:compiler {:output-to "resources/public/js/core.matrix.js"
:asset-path "js/out"
:optimizations :none
:parallel-build true
:pretty-print true}}
{:id :test
:source-paths ["src/main/clojure" "src/test/cljs" "src/test/clojure"]
:compiler {:output-to "resources/public/js/unit-test.js"
:asset-path "js/out"
;:main "clojure.core.matrix.test-basics"
:optimizations :advanced
:parallel-build true
:pretty-print false}}]
{:dev {:figwheel true
:source-paths ["src/main/clojure" "src/test/cljs" "src/test/clojure"]
:compiler {:output-to "resources/public/js/core.matrix.js"
:asset-path "js/out"
:optimizations :none
:parallel-build true
:pretty-print true}}
:test {:source-paths ["src/main/clojure" "src/test/cljs" "src/test/clojure"]
:compiler {:output-to "resources/public/js/unit-test.js"
:asset-path "out/"
:main clojure.core.matrix.cljs-runner
:optimizations :none
:parallel-build true
:pretty-print false}}}

;:test-commands {"unit" ["phantomjs" "resources/public/js/unit-test.js"]}
:figwheel {:load-warninged-code true :css-dirs ["resources/public/css"] :server-port 8765}
}

:figwheel {:load-warninged-code true
:css-dirs ["resources/public/css"]
:server-port 8765}}
}
}}

:marginalia {:javascript ["http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"]}


:codox {:namespaces [clojure.core.matrix
clojure.core.matrix.dataset
clojure.core.matrix.io
Expand Down
93 changes: 43 additions & 50 deletions src/main/clojure/clojure/core/matrix.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,9 @@ elements not-equal to the argument are 0.
(defn mul
"Performs element-wise multiplication with scalars and numerical arrays.
Examples:
(mul [1 2] [3 4]) ;=> [3 8]
Behaves like clojure.core/* for scalar values."
([] 1.0)
([a] a)
Expand All @@ -1483,10 +1486,7 @@ elements not-equal to the argument are 0.
(defn mmul
"Performs matrix multiplication on matrices or vectors.
Equivalent to inner-product when applied to vectors. Will treat a 1D vector roughly as a
1xN matrix (row vector) when it's the first argument, or as an Nx1 matrix
(column vector) when it's the second argument--except that the dimensionality
of the result will be different from what it would be with matrix arguments."
Equivalent to inner-product, but may be more efficient for matrices."
([] 1.0)
([a] a)
([a b]
Expand Down Expand Up @@ -1581,7 +1581,9 @@ elements not-equal to the argument are 0.
v))

(defn add
"Performs element-wise addition on one or more numerical arrays."
"Performs element-wise addition on one or more numerical arrays.
Will broadcast to the smallest shape compatible will addition of all input arrays."
([] 0.0)
([a] a)
([a b]
Expand Down Expand Up @@ -1610,12 +1612,15 @@ elements not-equal to the argument are 0.

(defn add-product
"Adds the element-wise product of two numerical arrays to the first array.
Arrays should be the same shape."
Arrays should be the same shape, some implementations may support broadcasting."
([m a b]
(mp/add-product m a b)))

(defn add-product!
"Adds the product of two numerical arrays to the first array. Returns the mutated array."
"Adds the product of two numerical arrays to the first array. Returns the mutated array.
Arrays should be the same shape, some implementations may support broadcasting."
([m a b]
(mp/add-product! m a b)
m))
Expand Down Expand Up @@ -1717,46 +1722,6 @@ elements not-equal to the argument are 0.
(mp/set-inner-product! m a b factor)
m))

(defn op
"Computes the specified operation on the array a and returns a new array.
The operation is implementation specific. Throws an error if the operator is not recognised by the implementation of a, or
if the operation is invalid for the given parameters."
([operation a]
(TODO))
([operation a & args]
(TODO)))

(defn op!
"Computes the specified operation on the array a and mutates the array a.
The operation is implementation specific. Throws an error if the operator is not recognised by the implementation of a, or
if the operation is invalid for the given parameters."
([operation a]
(TODO))
([operation a & args]
(TODO)))

(defn set-op!
"Computes the specified operation on the array a and stores the result in the destination array, which must be mutable.
The operation is implementation specific. Throws an error if the operator is not recognised by the implementation of a, or
if the operation is invalid for the given parameters."
([operation dest a]
(TODO))
([operation dest a & args]
(TODO)))

(defn add-op!
"Computes the specified operation on the array a and adds the result to the destination array, which must be mutable.
The operation is implementation specific. Throws an error if the operator is not recognised by the implementation of a, or
if the operation is invalid for the given parameters."
([operation dest a]
(TODO))
([operation dest a & args]
(TODO)))

(defn sub
"Performs element-wise subtraction on one or more numerical arrays.
Expand Down Expand Up @@ -1815,7 +1780,9 @@ elements not-equal to the argument are 0.
(mp/square m)))

(defn normalise
"Normalises a numerical vector (scales to unit length). Returns a new normalised vector.
"Normalises a numerical vector (scales to unit length, i.e. the L2 norm).
Returns a new normalised vector.
The result is undefined if the initial length of the vector is zero (it is possible the
implementation may return NaNs or zeros). If this is a concern, it is recommended to check
Expand All @@ -1832,7 +1799,7 @@ elements not-equal to the argument are 0.

(defn dot
"Efficiently computes the scalar dot product (1Dx1D inner product) of two numerical vectors. Prefer this API
function if you are performing a dot product on 1D vectors and want a scalar result.
function if you are performing a dot product on 1D vectors and require a scalar result.
If either argument is not a vector, will compute and return a higher dimensional inner-product."
([a b]
Expand Down Expand Up @@ -2153,6 +2120,9 @@ elements not-equal to the argument are 0.
(emap (fn [x] (str x)) (double-array [1 2 3])) ;; Throws an error
(emap (fn [x] (str x)) (coerce [] (double-array [1 2 3]))) ;; OK!
Implemenations may *optionally* support custom function types. If this is the case, the
parameter m must be a valid array from the given implementation.
Returns a new array of the same element-type and shape as the array m."
([f m]
(mp/element-map m f))
Expand All @@ -2162,7 +2132,8 @@ elements not-equal to the argument are 0.
(mp/element-map m f a more)))

(defn emap-indexed
"Element-wise map-indexed over all elements of one or more arrays.
"Element-wise map-indexed over all elements of one or more arrays. Like
emap, but provides an index as the second argument to the mapping function.
f must accept as first argument the index vector of the current element,
and return a result compatible with the element-type of the array m
Expand Down Expand Up @@ -2242,6 +2213,28 @@ elements not-equal to the argument are 0.
([f m a & more]
(mp/element-map! m f a more) m))

(defn add-emap!
"Adds the result of emap to a destination array.
dest must be a mutable numerical array. Returns dest."
([dest f a]
(mp/add-emap! dest f a) dest)
([dest f a b]
(mp/add-emap! dest f a b) dest)
([dest f a b & more]
(mp/add-emap! dest f a b more) dest))

(defn set-emap!
"Sets the destination array to the result of an emap operation.
dest must be a mutable array. Returns dest."
([dest f a]
(mp/set-emap! dest f a) dest)
([dest f a b]
(mp/set-emap! dest f a b) dest)
([dest f a b & more]
(mp/set-emap! dest f a b more) dest))

(defn emap-indexed!
"Element-wise map-indexed over all elements of one or more arrays.
Expand Down
20 changes: 20 additions & 0 deletions src/main/clojure/clojure/core/matrix/impl/defaults.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,26 @@
;; check for no slices, in which case we must return nil
(if (seq slcs) slcs nil))))

(extend-protocol mp/PAddEmap
#?(:clj Object :cljs object)
(add-emap!
([dest f a]
(mp/matrix-add! dest (mp/element-map a f)))
([dest f a b]
(mp/matrix-add! dest (mp/element-map a f b)))
([dest f a b more]
(mp/matrix-add! dest (mp/element-map a f b more)))))

(extend-protocol mp/PSetEmap
#?(:clj Object :cljs object)
(set-emap!
([dest f a]
(mp/assign! dest (mp/element-map a f)))
([dest f a b]
(mp/assign! dest (mp/element-map a f b)))
([dest f a b more]
(mp/assign! dest (mp/element-map a f b more)))))

;; functional operations
(extend-protocol mp/PFunctionalOperations
#?(:clj Number :cljs number)
Expand Down
27 changes: 25 additions & 2 deletions src/main/clojure/clojure/core/matrix/protocols.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1051,14 +1051,14 @@ would often be a numeric base type)."
[m f]
[m f a]
[m f a more]
"Maps f over all elements of m (and optionally other matrices), returning a new matrix.
"Maps f over all elements of m (and optionally other arrays), returning a new matrix.
f is expected to produce elements of a type supported by the implementation of m - failure
to do so may cause an error.")
(element-map!
[m f]
[m f a]
[m f a more]
"Maps f over all elements of m (and optionally other matrices), mutating the elements of m in place.
"Maps f over all elements of m (and optionally other arrays), mutating the elements of m in place.
Must throw an exception if m is not mutable.
f is expected to produce elements of a type supported by the implementation of m - failure
to do so may cause an error.")
Expand All @@ -1068,6 +1068,29 @@ would often be a numeric base type)."
"Reduces with the function f over all elements of m.
Implementations do not need to support clojure.core/reduced"))

(defprotocol PAddEmap
"Protocol to support the add-emap! API function."
(add-emap!
[dest f a]
[dest f a b]
[dest f a b more]
"Maps f over all elements of a (and optionally other arrays), adding the result to dest.
Must throw an exception if dest is not mutable.
f is expected to produce elements of a type supported by the implementation of dest - failure
to do so may cause an error."))

(defprotocol PSetEmap
"Protocol to support the set-emap! API function."
(set-emap!
[dest f a]
[dest f a b]
[dest f a b more]
"Maps f over all elements of a (and optionally other arrays), storing the result in dest.
Must throw an exception if dest is not mutable.
f is expected to produce elements of a type supported by the implementation of dest - failure
to do so may cause an error."))


(defprotocol PMapIndexed
"Protocol for map-indexed operation on matrices"
;; This protocol is created instead of adding element-map-indexed to PFunctionalOperations to
Expand Down
5 changes: 5 additions & 0 deletions src/test/cljs/clojure/core/matrix/cljs_runner.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns clojure.core.matrix.cljs-runner
(:require [doo.runner :refer-macros [doo-tests]]
[clojure.core.matrix.test-api]))

(doo-tests 'clojure.core.matrix.test-api)
Loading

0 comments on commit 801c55e

Please sign in to comment.