Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Support the '0 dimension case' for bigarrays#787

Merged
gasche merged 4 commits intoocaml:trunkfromLaurentMazare:trunk
Sep 1, 2016

Conversation

LaurentMazare
Copy link
Contributor

@LaurentMazareLaurentMazare commentedAug 30, 2016
edited
Loading

Handle the '0 dimension' case for bigarray in the same way other numerical libraries (e.g. numpy or tensorflow) do, which is that such a bigarray holds a scalar value.

It seems that relaxing the exceptions that currently prevent this case is enough to get this working.

Note that this PR doesn't include any support for the bigarray.{} syntax, not sure how worthy this is.
It also doesn't include a Bigarray.Array0 module but I'm happy to add one if there is any need for it.

To give some context I came along this when writing some tensorflow ocaml bindings and the current workaround is to have a wrapper around the bigarray module that handles this scalar case with a bigarray with one dimension of size one. However this isn't very neat as it requires the wrapper to store whether the embedded data is a scalar or not. It would be quite nicer to have this supported by the bigarray module directly.

Test reshaping.Also adapt the documentation.Also allow slice to produce arrays with 0 dimensions.Update Changes
@@ -1050,7 +1050,7 @@ CAMLprim value caml_ba_slice(value vb, value vind)

/* Check number of indices < number of dimensions of array */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should be<= now.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good catch, this is fixed now.

@alainfrisch
Copy link
Contributor

The request is well founded and the implementation rather straightforward and well tested. I'm in favor of merging if nobody is against.

@alainfrisch
Copy link
Contributor

@hcarty
Copy link
Member

Could something be added to the documentation so users realize this is available/possible?

@alainfrisch
Copy link
Contributor

alainfrisch commentedAug 30, 2016
edited
Loading

The ability to have dimension 0 is mentioned in bigarray.mli.

@hcarty
Copy link
Member

Ah, I missed those lines.

I would like an Array0 module and Array1.slice to go with this. I have had projects in the past which would have benefited from an Array0.

@LaurentMazare
Copy link
ContributorAuthor

I've added an Array0 module as well as Array1.slice. It makes the change larger so let me know if you think it's not worth it.

@hcarty
Copy link
Member

I think the addition of the module, slice function and genarray conversions make this PR much more useful. Thank you for adding them!

I looked over the code and like the change.

@gaschegasche merged commit079de96 intoocaml:trunkSep 1, 2016
@gasche
Copy link
Member

I merged, thanks to everyone for the comments, and for the nice pull request.

@LaurentMazare
Copy link
ContributorAuthor

That was pretty fast! Thanks all.

@gasche
Copy link
Member

gasche commentedSep 1, 2016
edited
Loading

Our internal continuous integration server just let me know that clang has a seemingly-legitimate complaint about the C code:

bigarray_stubs.c:205:16: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare]  if (num_dims < 0 || num_dims > CAML_BA_MAX_NUM_DIMS)      ~~~~~~~~ ^ ~bigarray_stubs.c:1302:16: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare]  if (num_dims < 0 || num_dims > CAML_BA_MAX_NUM_DIMS)      ~~~~~~~~ ^ ~2 errors generated.

@LaurentMazare
Copy link
ContributorAuthor

Indeed I didn't noticed that num_dims is unsigned, sorry about that. Should I create a new PR to fix this ? (removing the num_dims < 0 conditions)

@gasche
Copy link
Member

I will do the change, run the testsuite, and commit if it works.

@gasche
Copy link
Member

Should be fixed in014d941 .

camlspotter pushed a commit to camlspotter/ocaml that referenced this pull requestOct 17, 2017
Bigarray: support 0-dimension bigarrays (just a scalar value), with an Array0 module
ctk21 pushed a commit to ocaml-multicore/ocaml that referenced this pull requestDec 21, 2021
Address feedback on GC from async review
stedolan pushed a commit to stedolan/ocaml that referenced this pull requestSep 21, 2022
Co-authored-by: Malte Skarupke <mskarupke@janestreet.com>
sadiqj pushed a commit to sadiqj/ocaml that referenced this pull requestFeb 21, 2023
…l#787)Co-authored-by: Malte Skarupke <mskarupke@janestreet.com>
stedolan pushed a commit to stedolan/ocaml that referenced this pull requestMar 21, 2023
25188da flambda-backend: Missed comment from PR802 (ocaml#887)9469765 flambda-backend: Improve the semantics of asynchronous exceptions (new simpler version) (ocaml#802)d9e4dd0 flambda-backend: Fix `make runtest` on NixOS (ocaml#874)4bbde7a flambda-backend: Simpler symbols (ocaml#753)ef37262 flambda-backend: Add opaqueness to Obj.magic under Flambda 2 (ocaml#862)a9616e9 flambda-backend: Add build system hooks for ocaml-jst (ocaml#869)045ef67 flambda-backend: Allow the compiler to build with stock Dune (ocaml#868)3cac5be flambda-backend: Simplify Makefile logic for natdynlinkops (ocaml#866)c5b12bf flambda-backend: Remove unnecessary install lines (ocaml#860)ff12bbe flambda-backend: Fix unused variable warning in st_stubs.c (ocaml#861)c84976c flambda-backend: Static check for noalloc: attributes (ocaml#825)ca56052 flambda-backend: Build system refactoring for ocaml-jst (ocaml#857)39eb7f9 flambda-backend: Remove integer comparison involving nonconstant polymorphic variants (ocaml#854)c102688 flambda-backend: Fix soundness bug by using currying information from typing (ocaml#850)6a96b61 flambda-backend: Add a primitive to enable/disable the tick thread (ocaml#852)f64370b flambda-backend: Make Obj.dup use a new primitive, %obj_dup (ocaml#843)9b78eb2 flambda-backend: Add test forocaml#820 (include functor soundness bug) (ocaml#841)8f24346 flambda-backend: Add `-dtimings-precision` flag (ocaml#833)65c2f22 flambda-backend: Add test forocaml#829 (ocaml#831)7b27a49 flambda-backend: Follow-up PR#829 (comballoc fixes for locals) (ocaml#830)ad7ec10 flambda-backend: Use a custom condition variable implementation (ocaml#787)3ee650c flambda-backend: Fix soundness bug in include functor (ocaml#820)2f57378 flambda-backend: Static check noalloc (ocaml#778)aaad625 flambda-backend: Emit begin/end region only when stack allocation is enabled (ocaml#812)17c7173 flambda-backend: Fix .cmt for included signatures (ocaml#803)e119669 flambda-backend: Increase delays in tests/lib-threads/beat.ml (ocaml#800)ccc356d flambda-backend: Prevent dynamic loading of the same .cmxs twice in private mode, etc. (ocaml#784)14eb572 flambda-backend: Make local extension point equivalent to local_ expression (ocaml#790)487d11b flambda-backend: Fix tast_iterator and tast_mapper for include functor. (ocaml#795)a50a818 flambda-backend: Reduce closure allocation in List (ocaml#792)96c9c60 flambda-backend: Merge ocaml-jsta775b88 flambda-backend: Fix ocaml/otherlibs/unix 32-bit build (ocaml#767)f7c2679 flambda-backend: Create object files internally to avoid invoking GAS (ocaml#757)c7a46bb flambda-backend: Bugfix for Cmmgen.expr_size with locals (ocaml#756)b337cb6 flambda-backend: Fix build_upstream for PR749 (ocaml#750)8e7e81c flambda-backend: Differentiate is_int primitive between generic and variant-only versions (ocaml#749)git-subtree-dir: ocamlgit-subtree-split:25188da
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull requestJan 12, 2024
change self-referencing heading styles to not wrap title with an a tagCo-authored-by: Sabine Schmaltz <sabine@tarides.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@LaurentMazare@alainfrisch@hcarty@gasche

[8]ページ先頭

©2009-2025 Movatter.jp