Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph Slice node (resolves #483) #517

Merged
merged 3 commits into from
Apr 16, 2020
Merged

Graph Slice node (resolves #483) #517

merged 3 commits into from
Apr 16, 2020

Conversation

mreppen
Copy link
Contributor

@mreppen mreppen commented Apr 14, 2020

A node producing a get_slice on its input.

Most code that is not boilerplate is for computing the output dimension. The calculation itself is pretty much the same as in _enumerate_slice_def (https://github.com/owlbarn/owl/blob/master/src/base/dense/owl_base_dense_ndarray_generic.ml#L99). The assert is a bit more aggressive (checks bounds) to avoid Assert_failure ("src/base/core/owl_base_slicing.ml", 90, 10). when running.

I am aware of special cases like that "later" axes do not need to be specified, and handle that. Are there others that I might have missed?

There is one potential extra feature: A bool flag to set whether trivial dimensions (those with length 1) should be remove, i.e., reshaped away. Is this too niche/specialized?

There is still a TODO for prettier (more detailed) printing.

Example:

# let nn = Neural.D.Graph.(input [| 5; 2 |] |> slice [[1; -1; 3]] |> get_network);;
val nn : Owl_neural.D.Graph.network =
  42878

[ Node input_0 ]:
    Input : in/out:[*,3,2]
    prev:[] next:[slice_1]

[ Node slice_1 ]:
    Slice : in:[*,3,2] out:[*,2,2]
    prev:[input_0] next:[]

# Neural.D.Graph.model nn (Arr.sequential [| 1; 5; 2 |]);;
- : Owl_algodiff_primal_ops.D.arr =

       C0 C1
R[0,0]  2  3
R[0,1]  8  9
# Arr.(sequential [|5;2|] |> get_slice [[1;-1;3]]);;
- : Arr.arr =
   C0 C1
R0  2  3
R1  8  9

@ryanrhymes ryanrhymes added enhancement R&D Core research and development labels Apr 14, 2020
@mreppen
Copy link
Contributor Author

mreppen commented Apr 15, 2020

I added more detailed printing:

# ... slice [[1; -1; 3]; []; [0]] ...
...
[ Node slice_1 ]:
    Slice : in:[*,5,2,10] out:[*,2,2,1]
    Axes  : 0:[1; -1; 3] 1:[] 2:[0]
    prev:[input_0] next:[]

@jzstark
Copy link
Collaborator

jzstark commented Apr 15, 2020

Cool! Thanks for this PR! Looks good to me. I'm just wondering if we can put the slicing shape inference routine to the owl_utils_infer_shape.ml file.

@mreppen
Copy link
Contributor Author

mreppen commented Apr 15, 2020

@jzstark I was not aware of that file, but that looks very appropriate. Latest commit moves it.

@ryanrhymes ryanrhymes merged commit c103674 into owlbarn:master Apr 16, 2020
mseri added a commit to mseri/opam-repository that referenced this pull request Oct 4, 2020
CHANGES:

* various documentation improvements (thanks @pveber, @UnixJunkie, @Fourchaux)
* Fix use of access operators (owlbarn/owl#543)
* Upgrade to ocamlformat 0.15.0 (thanks @gpetiot owlbarn/owl#535)
* keep_dims option (owlbarn/owl#531)
* stats: fix infinite loop in ecdf
* Use Fun.protect to ensure all file descriptors are being closed
* owl_ndarray_maths: improve user experience in case of errors
* owl_io: close file descriptors also in case of errors
* owl_dense_ndarray_generic: fix error on printing 0-ary arrays
* fixed bug in sub forward mode (owlbarn/owl#533)
* Add stack to Algodiff (owlbarn/owl#528)
* added log_sum_exp to Ndarray and Algodiff (owlbarn/owl#527)
* added single-precision and double-precision Bessel functions to Ndarray  (owlbarn/owl#526)
* Fixes owlbarn/owl#518 by introducing another `/` to resolve data directory (@jotterbach owlbarn/owl#519)
* Graph Slice node (resolves owlbarn/owl#483) (@mreppen owlbarn/owl#517)
* Graph subnetwork: Multiple outputs (@mreppen owlbarn/owl#515)
* Added kron and swap to Algodiff operations (owlbarn/owl#512)
* various other small fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement R&D Core research and development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants