GithubHelp home page GithubHelp logo

Comments (10)

kasterma avatar kasterma commented on August 23, 2024

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.

mikera avatar mikera commented on August 23, 2024

@kasterma: good suggestion, though I think that is worth a separate issue. I'll create one.

from core.matrix.

mikera avatar mikera commented on August 23, 2024

#40

from core.matrix.

si14 avatar si14 commented on August 23, 2024

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.

mikera avatar mikera commented on August 23, 2024

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.

alexott avatar alexott commented on August 23, 2024

I've also thought already about implementing 2 APIs for Incanter - mutable & immutable.

from core.matrix.

mikera avatar mikera commented on August 23, 2024

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.

si14 avatar si14 commented on August 23, 2024

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.

mikera avatar mikera commented on August 23, 2024

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.

mikera avatar mikera commented on August 23, 2024

Row setting implemented in this commit:
95993ea

Still not sure of how to handle the more general strategy....

from core.matrix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.