123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103# 1 "src/owl/core/owl_slicing_fancy.ml"(*
* OWL - an OCaml numerical library for scientific computing
* Copyright (c) 2016-2018 Liang Wang <liang.wang@cl.cam.ac.uk>
*)openBigarrayopenOwl_typesopenOwl_core_types(* Interface to the native c functions *)externalowl_float32_ndarray_get_fancy:('a,'b)owl_arr->('a,'b)owl_arr->(int64,'c)owl_arr->(int64,'c)owl_arr->unit="stub_float32_ndarray_get_fancy"externalowl_float64_ndarray_get_fancy:('a,'b)owl_arr->('a,'b)owl_arr->(int64,'c)owl_arr->(int64,'c)owl_arr->unit="stub_float64_ndarray_get_fancy"externalowl_complex32_ndarray_get_fancy:('a,'b)owl_arr->('a,'b)owl_arr->(int64,'c)owl_arr->(int64,'c)owl_arr->unit="stub_complex32_ndarray_get_fancy"externalowl_complex64_ndarray_get_fancy:('a,'b)owl_arr->('a,'b)owl_arr->(int64,'c)owl_arr->(int64,'c)owl_arr->unit="stub_complex64_ndarray_get_fancy"let_ndarray_get_fancy:typeabc.(a,b)kind->(a,b)owl_arr->(a,b)owl_arr->(int64,c)owl_arr->(int64,c)owl_arr->unit=function|Float32->owl_float32_ndarray_get_fancy|Float64->owl_float64_ndarray_get_fancy|Complex32->owl_complex32_ndarray_get_fancy|Complex64->owl_complex64_ndarray_get_fancy|_->failwith"_ndarray_get_fancy: unsupported operation"externalowl_float32_ndarray_set_fancy:('a,'b)owl_arr->('a,'b)owl_arr->(int64,'c)owl_arr->(int64,'c)owl_arr->unit="stub_float32_ndarray_set_fancy"externalowl_float64_ndarray_set_fancy:('a,'b)owl_arr->('a,'b)owl_arr->(int64,'c)owl_arr->(int64,'c)owl_arr->unit="stub_float64_ndarray_set_fancy"externalowl_complex32_ndarray_set_fancy:('a,'b)owl_arr->('a,'b)owl_arr->(int64,'c)owl_arr->(int64,'c)owl_arr->unit="stub_complex32_ndarray_set_fancy"externalowl_complex64_ndarray_set_fancy:('a,'b)owl_arr->('a,'b)owl_arr->(int64,'c)owl_arr->(int64,'c)owl_arr->unit="stub_complex64_ndarray_set_fancy"let_ndarray_set_fancy:typeabc.(a,b)kind->(a,b)owl_arr->(a,b)owl_arr->(int64,c)owl_arr->(int64,c)owl_arr->unit=function|Float32->owl_float32_ndarray_set_fancy|Float64->owl_float64_ndarray_set_fancy|Complex32->owl_complex32_ndarray_set_fancy|Complex64->owl_complex64_ndarray_set_fancy|_->failwith"_ndarray_set_fancy: unsupported operation"(* Core functions for fancy slicing *)let_calc_total_list_lenaxis=Array.fold_left(funax->matchxwith|L_x->a+Array.lengthx|_->a)0axis(* This function encodes the slice definition into the slice and index two
fields in fancy pair c data strcture. The slice definition needs to be
normalised by [check_slice_definition] function first.
Refer to owl_slicing.h file for fancy pare structure.
*)letencode_slice_definitionaxis=letn0=3*Array.lengthaxisinletn1=_calc_total_list_lenaxisinletslice=Genarray.createInt64C_layout[|3*n0|]inletindex=Genarray.createInt64C_layout[|n1|]inletk=ref0inArray.iteri(funia->letj=3*iinmatchawith|L_x->(letl=Array.lengthxinGenarray.setslice[|j|](Int64.of_int(-1));Genarray.setslice[|j+1|](Int64.of_int!k);Genarray.setslice[|j+2|](Int64.of_int(!k+l-1));Array.iteri(funoy->Genarray.setindex[|!k+o|](Int64.of_inty))x;k:=!k+l;)|R_x->(Genarray.setslice[|j|](Int64.of_intx.(0));Genarray.setslice[|j+1|](Int64.of_intx.(1));Genarray.setslice[|j+2|](Int64.of_intx.(2));)|_->failwith"owl_slicing_fancy:encode_slice_definition")axis;slice,indexletgetkindaxisxy=letslice,index=encode_slice_definitionaxisin_ndarray_get_fancykindxysliceindexletsetkindaxisxy=letslice,index=encode_slice_definitionaxisin_ndarray_set_fancykindxysliceindex(* ends here *)