Comments (10)
If I understand the suggestion correctly, I would expand and suggest to add the elementary row operations. (switching, multiplication, and row addition; see http://en.wikipedia.org/wiki/Elementary_matrix).
Not sure what the semantics of the last function (set-submatrix-at) is supposed to be.
from core.matrix.
@kasterma: good suggestion, though I think that is worth a separate issue. I'll create one.
from core.matrix.
from core.matrix.
If I'm right it can be done using mutable "views" into original array (or at least can pretend to be done this way if underlying matrix representation doesn't support mutation).
from core.matrix.
Well we probably ultimately want two versions (immutable and mutable) of each: set-row
and set-row!
for example.
The mutable versions could certainly be implemented with an mutable view.
The immutable version would need to construct a new matrix. However structural sharing is possible, so parts of the new matrix could be shared with the original matrix - possibly via a view.
from core.matrix.
I've also thought already about implementing 2 APIs for Incanter - mutable & immutable.
from core.matrix.
We'll get mutable + immutable versions of most operations for free if we complete the Incanter / core.matrix integration.
Most core.matrix functions already have immutable and mutable versions where it makes sense, e.g. add
and add!
, where the !
versions generally mutate their first argument.
from core.matrix.
I'm sorry for not being clear enough.
I meant something like this MATLAB/Octave code:
octave:1> a = eye(3)
a =
Diagonal Matrix
1 0 0
0 1 0
0 0 1
octave:2> a(2,1:2) = [2,2]
a =
1 0 0
2 2 0
0 0 1
The thing here is that we already need a powerful tool to take slices of array. Why don't reuse it to assign values as well, as it is done in MATLAB/Octave? From the point of API, I can imagine "slicing schemes" as first-class objects:
(def s (slicing-scheme [2 1 :to 2]))
(sub (eye 3) s) ; returns a slice
(set (eye 3) s) ; returns new matrix
(set! (eye 3) s) ; mutates in place
DSL for slicing is another issue, of course.
from core.matrix.
slicing schemes as first class objects is an interesting idea, I'd be interested to see an implementation that demonstrates that it can be done efficiently and in a general way.
But do note that core.matrix already includes an NDWrapper type that can wrap an arbitrary subset of a matrix. See clojure.core.matrix.impl.wrappers
namespace and the submatrix
function.
Use example:
(def A (array :ndarray [[1 2 3] [4 5 6] [7 8 9]]))
(def S (submatrix A [[1 1] [0 2]]))
S
=> #<NDWrapper [[4 5]]>
Currently NDWrapper doesn't support mutation, but it could easily be upgraded to do so. In which case, we would be able to do stuff that alters the original matrix like:
(assign! S 0)
S
=> #<NDWrapper [[0 0]]>
A
=> #<NDArray [[1 2 3] [0 0 6] [7 8 9]]>
Overall the NDWrapper is quite flexible and good for simple use cases. The problem is that it adds quite a lot of index lookup overhead for each element (Dmitry: we wouldn't need your shiny new NDArray if the NDWrapper was ultra-fast!)
from core.matrix.
Row setting implemented in this commit:
95993ea
Still not sure of how to handle the more general strategy....
from core.matrix.
Related Issues (20)
- index-max HOT 3
- `fill` does not preserve type
- Exception when `mmul`ing `fill`ed ndarrays
- Numeric types are unexpectedly coerced HOT 1
- TODO: Not yet implemented: for class clojure.lang.PersistentVector HOT 2
- Why is there no mmul! function ? HOT 2
- API documentation is out of date HOT 4
- Uninitialized object exists on backward branch 108 in clojurescript HOT 11
- Typo in persistent_vector.cljc (vector-dot)? HOT 2
- `pm` (pretty print) undefined in clojurescript HOT 1
- what is the purpose of 'unimplemented' function in utils HOT 2
- Matrix element wise multiplication by column vector HOT 1
- where is react native API document? HOT 1
- Warnings of clashes with Clojure 1.11.0 abs. HOT 6
- apache-commons-matrix not playing well with core.matrix? HOT 1
- New release HOT 2
- pm, get-shape are confused by cells containing sequences in NDArray
- Max size of ndarray matrices? HOT 2
- element-wise equality comparison for non-numbers HOT 2
- Feature request: reverse and rotate functions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.matrix.