Code Monkey home page Code Monkey logo

Comments (4)

zoj613 avatar zoj613 commented on August 15, 2024

I was able to implement a temporary workaround to this issue by using element-wise set. Basically:

  1. Convert the slice to a list of coordinates of the target array.
  2. Use Owl.Dense.Ndarray.Generic.set and List.iter2 to iterate over the list of coordinates and values and set them one at a time
 List.iter2
  (fun coord val ->
	Owl.Dense.Ndarray.Generic.set coord val) coord_list value_list

I would like to add that this issue also affects the transpose function as well. The offending lines are:

let _ndarray_transpose
: type a b.
(a, b) kind
-> (a, b) owl_arr
-> (a, b) owl_arr
-> (int64, int64_elt) owl_arr
-> (int64, int64_elt) owl_arr
-> unit
= function
| Float32 -> owl_float32_ndarray_transpose
| Float64 -> owl_float64_ndarray_transpose
| Complex32 -> owl_complex32_ndarray_transpose
| Complex64 -> owl_complex64_ndarray_transpose
| _ -> failwith "_ndarray_transpose: unsupported operation"

Unfortunately, I haven't been able to find a workaround for this

from owl.

zoj613 avatar zoj613 commented on August 15, 2024

UPDATE: So I managed to find a workaround for computing the transpose of any kind using Owl functions. Essentially, this involves converting between .Any and .Generic representations of an array. The functions that seem to not work on .Generic happen to work on .Any arrays. Here is an implementation of transpose that works for any Bigarray kind:

module Ndarray = Owl.Dense.Ndarray.Generic
module Anyarray = Owl.Dense.Ndarray.Any

let transpose ?axis x =
  let shape = Ndarray.shape x in
  let y = Anyarray.init_nd shape @@ fun c -> Ndarray.get x c in
  let y' = Anyarray.transpose ?axis y in
  Ndarray.init_nd (Ndarray.kind x) (Anyarray.shape y') @@ fun c ->
    Anyarray.get y' c

I suppose this workaround can be generalized to any of the Generic functions that are limited to only 4 bigarray kinds?

Cc @jzstark

from owl.

mseri avatar mseri commented on August 15, 2024

Nice. The main downside is that this won't scale well since it involves copying everything twice, but at least would circumvent the current unnecessary limitation

from owl.

zoj613 avatar zoj613 commented on August 15, 2024

Nice. The main downside is that this won't scale well since it involves copying everything twice, but at least would circumvent the current unnecessary limitation

Perhaps it can be used only for the Bigarray kinds not currently supported by the Generic module, that's if correctness/usability is prioritized over performance.

I am very interested in getting Generic functions to work for any kind. What part of the codebase would I need to extend to support this functionality? Is it doable or too complicated for someone who doesn't have intimate knowledge of the codebase?

from owl.

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.