Fork me on GitHub
#uncomplicate
<
2023-04-13
>
Mandimby Raveloarinjaka02:04:00

Hello, is there a way to sort the columns of a matrix according to the value of a given row? I was checking the reference of dlasrt2 and of it was available I think it would be a combination of the result of a call on the row and permute-cols

Mandimby Raveloarinjaka10:04:21

Actually I guess I can switch back to a combination of map-indexed and sort-by to get the permutation index I need

jsa-aerial20:04:52

An alternative approach is to use tech.ml.dataset which has the ability to map Neanderthal native matrices in place and then apply all the data frame functionality provided. You can go in both directions which I use a lot. Very nice.

Mandimby Raveloarinjaka13:04:44

Hello, if I pass a matrix to a function, even if I use destructive methods inside, the parameter is unchanged when the function return: everything is passed by value in clojure functions. What can I do if I want to pass a reference ?

Mandimby Raveloarinjaka13:04:43

The sample code

(defn ->min-xy-m
    [points]
    (let [n (ucore/ncols points)
          xs (ucore/row points 0)
          ys (ucore/row points 1)
          min-ix (ucore/imin xs)
          min-iy (ucore/imin ys)
          min-x (ucore/entry xs min-ix)
          min-y (ucore/entry ys min-iy)]
      (native/dge 2 n (cycle [min-x min-y]))))

  (defn ->to-origin!
    [points]
    (let [min-xy-m (->min-xy-m points)]
      (ucore/axpby! 1 points -1 min-xy-m)))
calling ->to-origin! on a matrix leaves it unchanged but return the correct result

Mandimby Raveloarinjaka00:04:31

my bad, I did not read the doc properly. axpby! modifies y and it works as expected.

2
👆 2