diff options
Diffstat (limited to 'otherlibs/bigarray')
| -rw-r--r-- | otherlibs/bigarray/.cvsignore | 3 | ||||
| -rw-r--r-- | otherlibs/bigarray/.depend | 17 | ||||
| -rw-r--r-- | otherlibs/bigarray/Makefile | 74 | ||||
| -rw-r--r-- | otherlibs/bigarray/Makefile.Mac | 53 | ||||
| -rw-r--r-- | otherlibs/bigarray/Makefile.Mac.depend | 42 | ||||
| -rw-r--r-- | otherlibs/bigarray/Makefile.nt | 84 | ||||
| -rw-r--r-- | otherlibs/bigarray/bigarray.h | 81 | ||||
| -rw-r--r-- | otherlibs/bigarray/bigarray.ml | 226 | ||||
| -rw-r--r-- | otherlibs/bigarray/bigarray.mli | 756 | ||||
| -rw-r--r-- | otherlibs/bigarray/bigarray_stubs.c | 1073 | ||||
| -rw-r--r-- | otherlibs/bigarray/mmap_unix.c | 117 | ||||
| -rw-r--r-- | otherlibs/bigarray/mmap_win32.c | 116 |
12 files changed, 0 insertions, 2642 deletions
diff --git a/otherlibs/bigarray/.cvsignore b/otherlibs/bigarray/.cvsignore deleted file mode 100644 index c54b3a3580..0000000000 --- a/otherlibs/bigarray/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -*.x -so_locations diff --git a/otherlibs/bigarray/.depend b/otherlibs/bigarray/.depend deleted file mode 100644 index 7c4e124ea6..0000000000 --- a/otherlibs/bigarray/.depend +++ /dev/null @@ -1,17 +0,0 @@ -bigarray_stubs.o: bigarray_stubs.c ../../byterun/alloc.h \ - ../../byterun/misc.h ../../byterun/config.h ../../config/m.h \ - ../../config/s.h ../../byterun/mlvalues.h bigarray.h \ - ../../byterun/custom.h ../../byterun/fail.h ../../byterun/intext.h \ - ../../byterun/io.h ../../byterun/fix_code.h ../../byterun/memory.h \ - ../../byterun/gc.h ../../byterun/major_gc.h ../../byterun/freelist.h \ - ../../byterun/minor_gc.h -mmap_unix.o: mmap_unix.c bigarray.h ../../byterun/mlvalues.h \ - ../../byterun/config.h ../../config/m.h ../../config/s.h \ - ../../byterun/misc.h ../../byterun/custom.h ../../byterun/fail.h \ - ../../byterun/sys.h -mmap_win32.o: mmap_win32.c bigarray.h ../../byterun/mlvalues.h \ - ../../byterun/config.h ../../config/m.h ../../config/s.h \ - ../../byterun/misc.h ../../byterun/alloc.h ../../byterun/custom.h \ - ../../byterun/fail.h ../../byterun/sys.h ../unix/unixsupport.h -bigarray.cmo: bigarray.cmi -bigarray.cmx: bigarray.cmi diff --git a/otherlibs/bigarray/Makefile b/otherlibs/bigarray/Makefile deleted file mode 100644 index 715428fca6..0000000000 --- a/otherlibs/bigarray/Makefile +++ /dev/null @@ -1,74 +0,0 @@ -######################################################################### -# # -# Objective Caml # -# # -# Xavier Leroy, projet Cristal, INRIA Rocquencourt # -# # -# Copyright 1999 Institut National de Recherche en Informatique et # -# en Automatique. All rights reserved. This file is distributed # -# under the terms of the GNU Library General Public License, with # -# the special exception on linking described in file ../../LICENSE. # -# # -######################################################################### - -# $Id$ - -include ../../config/Makefile - -CC=$(BYTECC) -CFLAGS=-I../../byterun -g -O $(BYTECCCOMPOPTS) $(SHAREDCCCOMPOPTS) -CAMLC=../../ocamlcomp.sh -I ../unix -CAMLOPT=../../ocamlcompopt.sh -I ../unix -MKLIB=../../boot/ocamlrun ../../tools/ocamlmklib -COMPFLAGS=-warn-error A - -C_OBJS=bigarray_stubs.o mmap_unix.o - -CAML_OBJS=bigarray.cmo - -all: libbigarray.a bigarray.cma - -allopt: libbigarray.a bigarray.cmxa - -libbigarray.a: $(C_OBJS) - $(MKLIB) -o bigarray $(C_OBJS) - -bigarray.cma: $(CAML_OBJS) - $(MKLIB) -ocamlc '$(CAMLC)' -linkall -o bigarray $(CAML_OBJS) - -bigarray.cmxa: $(CAML_OBJS:.cmo=.cmx) - $(MKLIB) -ocamlopt '$(CAMLOPT)' -linkall -o bigarray \ - $(CAML_OBJS:.cmo=.cmx) - -install: - if test -f dllbigarray.so; then cp dllbigarray.so $(STUBLIBDIR)/dllbigarray.so; fi - cp bigarray.cmi bigarray.mli libbigarray.a bigarray.cma $(LIBDIR) - cd $(LIBDIR); $(RANLIB) libbigarray.a - cp bigarray.h $(LIBDIR)/caml/bigarray.h - -installopt: - cp bigarray.a $(CAML_OBJS:.cmo=.cmx) bigarray.cmxa $(LIBDIR) - cd $(LIBDIR); $(RANLIB) bigarray.a - -partialclean: - rm -f *.cm* - -clean: partialclean - rm -f libbigarray.* *.o bigarray.a *.so - -.SUFFIXES: .ml .mli .cmo .cmi .cmx - -.mli.cmi: - $(CAMLC) -c $(COMPFLAGS) $< - -.ml.cmo: - $(CAMLC) -c $(COMPFLAGS) $< - -.ml.cmx: - $(CAMLOPT) -c $(COMPFLAGS) $< - -depend: - gcc -MM -I../../byterun -I../unix *.c > .depend - ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend - -include .depend diff --git a/otherlibs/bigarray/Makefile.Mac b/otherlibs/bigarray/Makefile.Mac deleted file mode 100644 index 7f449f9974..0000000000 --- a/otherlibs/bigarray/Makefile.Mac +++ /dev/null @@ -1,53 +0,0 @@ -######################################################################### -# # -# Objective Caml # -# # -# Damien Doligez, projet Moscova, INRIA Rocquencourt # -# # -# Copyright 2000 Institut National de Recherche en Informatique et # -# en Automatique. All rights reserved. This file is distributed # -# under the terms of the GNU Library General Public License, with # -# the special exception on linking described in file ../../LICENSE. # -# # -######################################################################### - -# $Id$ - -PPCC = mrc -PPCCOptions = -i :::byterun:,:::config: -w 35 {cdbgflag} - -CAMLC = :::boot:ocamlrun :::ocamlc -I :::stdlib: -I ::unix: - -PPCC_OBJS = bigarray_stubs.c.x mmap_unix.c.x - -CAML_OBJS = bigarray.cmo - -all Ä libbigarray.x bigarray.cma - -libbigarray.x Ä {PPCC_OBJS} - ppclink {ldbgflag} -xm library -o libbigarray.x {PPCC_OBJS} - -bigarray.cma Ä {CAML_OBJS} - {CAMLC} -a -linkall -o bigarray.cma {CAML_OBJS} - -install Ä - duplicate -y bigarray.cmi bigarray.mli libbigarray.x ¶ - bigarray.cma "{LIBDIR}" - -partialclean Ä - delete -y Å.cmÅ || set status 0 - -clean Ä partialclean - delete -i Å.x || set status 0 - -.cmi Ä .mli - {CAMLC} -c {COMPFLAGS} {depdir}{default}.mli - -.cmo Ä .ml - {CAMLC} -c {COMPFLAGS} {depdir}{default}.ml - -depend Ä - begin - MakeDepend -w -objext .x Å.c - :::boot:ocamlrun :::tools:ocamldep -I :::stdlib: -I ::unix: Å.mli Å.ml - end | streamedit -e "/¶t/ replace // ' ' -c °" > Makefile.Mac.depend diff --git a/otherlibs/bigarray/Makefile.Mac.depend b/otherlibs/bigarray/Makefile.Mac.depend deleted file mode 100644 index b2608cbede..0000000000 --- a/otherlibs/bigarray/Makefile.Mac.depend +++ /dev/null @@ -1,42 +0,0 @@ -#*** Dependencies: Cut here *** -# These dependencies were produced at 20:33:17 on Tue, Aug 21, 2001 by MakeDepend - -:bigarray_stubs.c.x Ä ¶ - :bigarray_stubs.c ¶ - "{CIncludes}"stddef.h ¶ - "{CIncludes}"stdarg.h ¶ - "{CIncludes}"string.h ¶ - :bigarray.h ¶ - "{CIncludes}"memory.h ¶ - "{CIncludes}"NullDef.h ¶ - "{CIncludes}"SizeTDef.h ¶ - "{CIncludes}"WCharTDef.h ¶ - "{CIncludes}"VaListTDef.h ¶ - "{CIncludes}"ConditionalMacros.h ¶ - "{CIncludes}"MacMemory.h ¶ - "{CIncludes}"MacTypes.h ¶ - "{CIncludes}"MixedMode.h - -:mmap_unix.c.x Ä ¶ - :mmap_unix.c ¶ - "{CIncludes}"stddef.h ¶ - "{CIncludes}"string.h ¶ - :bigarray.h ¶ - "{CIncludes}"NullDef.h ¶ - "{CIncludes}"SizeTDef.h ¶ - "{CIncludes}"WCharTDef.h - -:mmap_win32.c.x Ä ¶ - :mmap_win32.c ¶ - "{CIncludes}"stddef.h ¶ - "{CIncludes}"string.h ¶ - :bigarray.h ¶ - "{CIncludes}"NullDef.h ¶ - "{CIncludes}"SizeTDef.h ¶ - "{CIncludes}"WCharTDef.h - -bigarray.cmiÄ ::unix:unix.cmi -bigarray.cmoÄ :::stdlib:array.cmi :::stdlib:obj.cmi ::unix:unix.cmi ¶ - bigarray.cmi -bigarray.cmxÄ :::stdlib:array.cmx :::stdlib:obj.cmx ::unix:unix.cmx ¶ - bigarray.cmi diff --git a/otherlibs/bigarray/Makefile.nt b/otherlibs/bigarray/Makefile.nt deleted file mode 100644 index b4a8dc3058..0000000000 --- a/otherlibs/bigarray/Makefile.nt +++ /dev/null @@ -1,84 +0,0 @@ -######################################################################### -# # -# Objective Caml # -# # -# Xavier Leroy, projet Cristal, INRIA Rocquencourt # -# # -# Copyright 1999 Institut National de Recherche en Informatique et # -# en Automatique. All rights reserved. This file is distributed # -# under the terms of the GNU Library General Public License, with # -# the special exception on linking described in file ../../LICENSE. # -# # -######################################################################### - -# $Id$ - -include ../../config/Makefile - -CC=$(BYTECC) -CFLAGS=-I../../byterun -I../win32unix -DIN_OCAML_BIGARRAY -CAMLC=../../boot/ocamlrun ../../ocamlc -I ../../stdlib -I ../win32unix -CAMLOPT=../../boot/ocamlrun ../../ocamlopt -I ../../stdlib -I ../win32unix - -C_OBJS=bigarray_stubs.obj mmap_win32.obj - -CAML_OBJS=bigarray.cmo - -all: dllbigarray.dll libbigarray.$(A) bigarray.cma - -allopt: libbigarray.$(A) bigarray.cmxa - -dllbigarray.dll: $(C_OBJS:.obj=.$(DO)) - $(call MKDLL,dllbigarray.dll,dllbigarray.$(A),\ - $(C_OBJS:.obj=.$(DO)) ../../byterun/ocamlrun.$(A)) - -libbigarray.$(A): $(C_OBJS:.obj=.$(SO)) - $(call MKLIB,libbigarray.$(A),$(C_OBJS:.obj=.$(SO))) - -bigarray.cma: $(CAML_OBJS) - $(CAMLC) -a -linkall -o bigarray.cma $(CAML_OBJS) \ - -dllib -lbigarray -cclib -lbigarray - -bigarray.cmxa: $(CAML_OBJS:.cmo=.cmx) - $(CAMLOPT) -a -linkall -o bigarray.cmxa \ - $(CAML_OBJS:.cmo=.cmx) -cclib -lbigarray - -install: - cp dllbigarray.dll $(STUBLIBDIR) - cp libbigarray.$(A) dllbigarray.$(A) $(LIBDIR) - cp bigarray.cmi bigarray.mli bigarray.cma $(LIBDIR) - cp bigarray.h $(LIBDIR)/caml/bigarray.h - -installopt: - cp bigarray.$(A) $(CAML_OBJS:.cmo=.cmx) bigarray.cmxa $(LIBDIR) - -partialclean: - rm -f *.cm* - -clean: partialclean - rm -f *.dll *.$(A) *.$(O) - -.SUFFIXES: .ml .mli .cmo .cmi .cmx .$(DO) .$(SO) - -.mli.cmi: - $(CAMLC) -c $(COMPFLAGS) $< - -.ml.cmo: - $(CAMLC) -c $(COMPFLAGS) $< - -.ml.cmx: - $(CAMLOPT) -c $(COMPFLAGS) $< - -.c.$(DO): - $(BYTECC) $(DLLCCCOMPOPTS) $(CFLAGS) -c $< - mv $*.$(O) $*.$(DO) - -.c.$(SO): - $(BYTECC) $(BYTECCCOMPOPTS) $(CFLAGS) -c $< - mv $*.$(O) $*.$(SO) - -depend: - gcc -MM $(CFLAGS) *.c > .depend - ../../boot/ocamlrun ../../tools/ocamldep *.mli *.ml >> .depend - -include .depend diff --git a/otherlibs/bigarray/bigarray.h b/otherlibs/bigarray/bigarray.h deleted file mode 100644 index 17b2dfe430..0000000000 --- a/otherlibs/bigarray/bigarray.h +++ /dev/null @@ -1,81 +0,0 @@ -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ -/* */ -/* Copyright 2000 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id$ */ - -#ifndef _bigarray_ -#define _bigarray_ - - -#include "mlvalues.h" - -#define MAX_NUM_DIMS 16 - -enum caml_bigarray_kind { - BIGARRAY_FLOAT32, /* Single-precision floats */ - BIGARRAY_FLOAT64, /* Double-precision floats */ - BIGARRAY_SINT8, /* Signed 8-bit integers */ - BIGARRAY_UINT8, /* Unsigned 8-bit integers */ - BIGARRAY_SINT16, /* Signed 16-bit integers */ - BIGARRAY_UINT16, /* Unsigned 16-bit integers */ - BIGARRAY_INT32, /* Signed 32-bit integers */ - BIGARRAY_INT64, /* Signed 64-bit integers */ - BIGARRAY_CAML_INT, /* Caml-style integers (signed 31 or 63 bits) */ - BIGARRAY_NATIVE_INT, /* Platform-native long integers (32 or 64 bits) */ - BIGARRAY_COMPLEX32, /* Single-precision complex */ - BIGARRAY_COMPLEX64, /* Double-precision complex */ - BIGARRAY_KIND_MASK = 0xFF /* Mask for kind in flags field */ -}; - -enum caml_bigarray_layout { - BIGARRAY_C_LAYOUT = 0, /* Row major, indices start at 0 */ - BIGARRAY_FORTRAN_LAYOUT = 0x100, /* Column major, indices start at 1 */ - BIGARRAY_LAYOUT_MASK = 0x100 /* Mask for layout in flags field */ -}; - -enum caml_bigarray_managed { - BIGARRAY_EXTERNAL = 0, /* Data is not allocated by Caml */ - BIGARRAY_MANAGED = 0x200, /* Data is allocated by Caml */ - BIGARRAY_MAPPED_FILE = 0x400, /* Data is a memory mapped file */ - BIGARRAY_MANAGED_MASK = 0x600 /* Mask for "managed" bits in flags field */ -}; - -struct caml_bigarray_proxy { - long refcount; /* Reference count */ - void * data; /* Pointer to base of actual data */ - unsigned long size; /* Size of data in bytes (if mapped file) */ -}; - -struct caml_bigarray { - void * data; /* Pointer to raw data */ - long num_dims; /* Number of dimensions */ - long flags; /* Kind of element array + memory layout + allocation status */ - struct caml_bigarray_proxy * proxy; /* The proxy for sub-arrays, or NULL */ - long dim[1] /*[num_dims]*/; /* Size in each dimension */ -}; - -#define Bigarray_val(v) ((struct caml_bigarray *) Data_custom_val(v)) - -#define Data_bigarray_val(v) (Bigarray_val(v)->data) - -#if defined(IN_OCAML_BIGARRAY) -#define CAMLBAextern CAMLexport -#else -#define CAMLBAextern CAMLextern -#endif - -CAMLBAextern value alloc_bigarray(int flags, int num_dims, void * data, long * dim); -CAMLBAextern value alloc_bigarray_dims(int flags, int num_dims, void * data, - ... /*dimensions, with type long */); - -#endif diff --git a/otherlibs/bigarray/bigarray.ml b/otherlibs/bigarray/bigarray.ml deleted file mode 100644 index adfb5847b2..0000000000 --- a/otherlibs/bigarray/bigarray.ml +++ /dev/null @@ -1,226 +0,0 @@ -(***********************************************************************) -(* *) -(* Objective Caml *) -(* *) -(* Manuel Serrano et Xavier Leroy, INRIA Rocquencourt *) -(* *) -(* Copyright 2000 Institut National de Recherche en Informatique et *) -(* en Automatique. All rights reserved. This file is distributed *) -(* under the terms of the GNU Library General Public License, with *) -(* the special exception on linking described in file ../../LICENSE. *) -(* *) -(***********************************************************************) - -(* $Id$ *) - -(* Module [Bigarray]: large, multi-dimensional, numerical arrays *) - -external init : unit -> unit = "bigarray_init" - -let _ = init() - -type ('a, 'b) kind = int - -type int8_signed_elt -type int8_unsigned_elt -type int16_signed_elt -type int16_unsigned_elt -type int_elt -type int32_elt -type int64_elt -type nativeint_elt -type float32_elt -type float64_elt -type complex32_elt -type complex64_elt - -(* Keep those constants in sync with the caml_bigarray_kind enumeration - in bigarray.h *) - -let float32 = 0 -let float64 = 1 -let int8_signed = 2 -let int8_unsigned = 3 -let int16_signed = 4 -let int16_unsigned = 5 -let int32 = 6 -let int64 = 7 -let int = 8 -let nativeint = 9 -let char = int8_unsigned -let complex32 = 10 -let complex64 = 11 - -type 'a layout = int - -type c_layout -type fortran_layout - -(* Keep those constants in sync with the caml_bigarray_layout enumeration - in bigarray.h *) - -let c_layout = 0 -let fortran_layout = 0x100 - -module Genarray = struct - type ('a, 'b, 'c) t - external create: ('a, 'b) kind -> 'c layout -> int array -> ('a, 'b, 'c) t - = "bigarray_create" - external get: ('a, 'b, 'c) t -> int array -> 'a - = "bigarray_get_generic" - external set: ('a, 'b, 'c) t -> int array -> 'a -> unit - = "bigarray_set_generic" - external num_dims: ('a, 'b, 'c) t -> int = "bigarray_num_dims" - external nth_dim: ('a, 'b, 'c) t -> int -> int = "bigarray_dim" - let dims a = - let n = num_dims a in - let d = Array.make n 0 in - for i = 0 to n-1 do d.(i) <- nth_dim a i done; - d - external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "bigarray_kind" - external layout: ('a, 'b, 'c) t -> 'c layout = "bigarray_layout" - - external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t - = "bigarray_sub" - external sub_right: ('a, 'b, fortran_layout) t -> int -> int -> - ('a, 'b, fortran_layout) t - = "bigarray_sub" - external slice_left: ('a, 'b, c_layout) t -> int array -> - ('a, 'b, c_layout) t - = "bigarray_slice" - external slice_right: ('a, 'b, fortran_layout) t -> int array -> - ('a, 'b, fortran_layout) t - = "bigarray_slice" - external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit - = "bigarray_blit" - external fill: ('a, 'b, 'c) t -> 'a -> unit = "bigarray_fill" - external map_file: Unix.file_descr -> ('a, 'b) kind -> 'c layout -> - bool -> int array -> ('a, 'b, 'c) t - = "bigarray_map_file" -end - -module Array1 = struct - type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t - let create kind layout dim = - Genarray.create kind layout [|dim|] - external get: ('a, 'b, 'c) t -> int -> 'a = "%bigarray_ref_1" - external set: ('a, 'b, 'c) t -> int -> 'a -> unit = "%bigarray_set_1" - let dim a = Genarray.nth_dim a 0 - external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "bigarray_kind" - external layout: ('a, 'b, 'c) t -> 'c layout = "bigarray_layout" - external sub: ('a, 'b, 'c) t -> int -> int -> ('a, 'b, 'c) t = "bigarray_sub" - external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "bigarray_blit" - external fill: ('a, 'b, 'c) t -> 'a -> unit = "bigarray_fill" - let of_array kind layout data = - let ba = create kind layout (Array.length data) in - let ofs = if (Obj.magic layout : 'a layout) = c_layout then 0 else 1 in - for i = 0 to Array.length data - 1 do set ba (i + ofs) data.(i) done; - ba - let map_file fd kind layout shared dim = - Genarray.map_file fd kind layout shared [|dim|] -end - -module Array2 = struct - type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t - let create kind layout dim1 dim2 = - Genarray.create kind layout [|dim1; dim2|] - external get: ('a, 'b, 'c) t -> int -> int -> 'a = "%bigarray_ref_2" - external set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit = "%bigarray_set_2" - let dim1 a = Genarray.nth_dim a 0 - let dim2 a = Genarray.nth_dim a 1 - external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "bigarray_kind" - external layout: ('a, 'b, 'c) t -> 'c layout = "bigarray_layout" - external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t = "bigarray_sub" - external sub_right: ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t = "bigarray_sub" - let slice_left a n = Genarray.slice_left a [|n|] - let slice_right a n = Genarray.slice_right a [|n|] - external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "bigarray_blit" - external fill: ('a, 'b, 'c) t -> 'a -> unit = "bigarray_fill" - let of_array kind layout data = - let dim1 = Array.length data in - let dim2 = if dim1 = 0 then 0 else Array.length data.(0) in - let ba = create kind layout dim1 dim2 in - let ofs = if (Obj.magic layout : 'a layout) = c_layout then 0 else 1 in - for i = 0 to dim1 - 1 do - let row = data.(i) in - if Array.length row <> dim2 then - invalid_arg("Bigarray.Array2.of_array: non-rectangular data"); - for j = 0 to dim2 - 1 do - set ba (i + ofs) (j + ofs) row.(j) - done - done; - ba - let map_file fd kind layout shared dim1 dim2 = - Genarray.map_file fd kind layout shared [|dim1;dim2|] -end - -module Array3 = struct - type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t - let create kind layout dim1 dim2 dim3 = - Genarray.create kind layout [|dim1; dim2; dim3|] - external get: ('a, 'b, 'c) t -> int -> int -> int -> 'a = "%bigarray_ref_3" - external set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit = "%bigarray_set_3" - let dim1 a = Genarray.nth_dim a 0 - let dim2 a = Genarray.nth_dim a 1 - let dim3 a = Genarray.nth_dim a 2 - external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "bigarray_kind" - external layout: ('a, 'b, 'c) t -> 'c layout = "bigarray_layout" - external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t = "bigarray_sub" - external sub_right: ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t = "bigarray_sub" - let slice_left_1 a n m = Genarray.slice_left a [|n; m|] - let slice_right_1 a n m = Genarray.slice_right a [|n; m|] - let slice_left_2 a n = Genarray.slice_left a [|n|] - let slice_right_2 a n = Genarray.slice_right a [|n|] - external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "bigarray_blit" - external fill: ('a, 'b, 'c) t -> 'a -> unit = "bigarray_fill" - let of_array kind layout data = - let dim1 = Array.length data in - let dim2 = if dim1 = 0 then 0 else Array.length data.(0) in - let dim3 = if dim2 = 0 then 0 else Array.length data.(0).(0) in - let ba = create kind layout dim1 dim2 dim3 in - let ofs = if (Obj.magic layout : 'a layout) = c_layout then 0 else 1 in - for i = 0 to dim1 - 1 do - let row = data.(i) in - if Array.length row <> dim2 then - invalid_arg("Bigarray.Array3.of_array: non-cubic data"); - for j = 0 to dim2 - 1 do - let col = row.(j) in - if Array.length col <> dim3 then - invalid_arg("Bigarray.Array3.of_array: non-cubic data"); - for k = 0 to dim3 - 1 do - set ba (i + ofs) (j + ofs) (k + ofs) col.(j) - done - done - done; - ba - let map_file fd kind layout shared dim1 dim2 dim3 = - Genarray.map_file fd kind layout shared [|dim1;dim2;dim3|] -end - -external genarray_of_array1: ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t = "%identity" -external genarray_of_array2: ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t = "%identity" -external genarray_of_array3: ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t = "%identity" -let array1_of_genarray a = - if Genarray.num_dims a = 1 then a else invalid_arg "Bigarray.array1_of_genarray" -let array2_of_genarray a = - if Genarray.num_dims a = 2 then a else invalid_arg "Bigarray.array2_of_genarray" -let array3_of_genarray a = - if Genarray.num_dims a = 3 then a else invalid_arg "Bigarray.array3_of_genarray" - -external reshape: - ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t - = "bigarray_reshape" -let reshape_1 a dim1 = reshape a [|dim1|] -let reshape_2 a dim1 dim2 = reshape a [|dim1;dim2|] -let reshape_3 a dim1 dim2 dim3 = reshape a [|dim1;dim2;dim3|] - -(* Force bigarray_get_{1,2,3,N} to be linked in, since we don't refer - to those primitives directly in this file *) - -let _ = - let getN = Genarray.get in - let get1 = Array1.get in - let get2 = Array2.get in - let get3 = Array3.get in - () - diff --git a/otherlibs/bigarray/bigarray.mli b/otherlibs/bigarray/bigarray.mli deleted file mode 100644 index e2ce03de67..0000000000 --- a/otherlibs/bigarray/bigarray.mli +++ /dev/null @@ -1,756 +0,0 @@ -(***********************************************************************) -(* *) -(* Objective Caml *) -(* *) -(* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt *) -(* *) -(* Copyright 2000 Institut National de Recherche en Informatique et *) -(* en Automatique. All rights reserved. This file is distributed *) -(* under the terms of the GNU Library General Public License, with *) -(* the special exception on linking described in file ../../LICENSE. *) -(* *) -(***********************************************************************) - -(* $Id$ *) - -(** Large, multi-dimensional, numerical arrays. - - This module implements multi-dimensional arrays of integers and - floating-point numbers, thereafter referred to as ``big arrays''. - The implementation allows efficient sharing of large numerical - arrays between Caml code and C or Fortran numerical libraries. - - Concerning the naming conventions, users of this module are encouraged - to do [open Bigarray] in their source, then refer to array types and - operations via short dot notation, e.g. [Array1.t] or [Array2.sub]. - - Big arrays support all the Caml ad-hoc polymorphic operations: - - comparisons ([=], [<>], [<=], etc, as well as {!Pervasives.compare}); - - hashing (module [Hash]); - - and structured input-output ({!Pervasives.output_value} - and {!Pervasives.input_value}, as well as the functions from the - {!Marshal} module). -*) - -(** {6 Element kinds} *) - -(** Big arrays can contain elements of the following kinds: -- IEEE single precision (32 bits) floating-point numbers - ({!Bigarray.float32_elt}), -- IEEE double precision (64 bits) floating-point numbers - ({!Bigarray.float64_elt}), -- IEEE single precision (2 * 32 bits) floating-point complex numbers - ({!Bigarray.complex32_elt}), -- IEEE double precision (2 * 64 bits) floating-point complex numbers - ({!Bigarray.complex64_elt}), -- 8-bit integers (signed or unsigned) - ({!Bigarray.int8_signed_elt} or {!Bigarray.int8_unsigned_elt}), -- 16-bit integers (signed or unsigned) - ({!Bigarray.int16_signed_elt} or {!Bigarray.int16_unsigned_elt}), -- Caml integers (signed, 31 bits on 32-bit architectures, - 63 bits on 64-bit architectures) ({!Bigarray.int_elt}), -- 32-bit signed integer ({!Bigarray.int32_elt}), -- 64-bit signed integers ({!Bigarray.int64_elt}), -- platform-native signed integers (32 bits on 32-bit architectures, - 64 bits on 64-bit architectures) ({!Bigarray.nativeint_elt}). - - Each element kind is represented at the type level by one - of the abstract types defined below. -*) - -type float32_elt -type float64_elt -type complex32_elt -type complex64_elt -type int8_signed_elt -type int8_unsigned_elt -type int16_signed_elt -type int16_unsigned_elt -type int_elt -type int32_elt -type int64_elt -type nativeint_elt - -type ('a, 'b) kind -(** To each element kind is associated a Caml type, which is - the type of Caml values that can be stored in the big array - or read back from it. This type is not necessarily the same - as the type of the array elements proper: for instance, - a big array whose elements are of kind [float32_elt] contains - 32-bit single precision floats, but reading or writing one of - its elements from Caml uses the Caml type [float], which is - 64-bit double precision floats. - - The abstract type [('a, 'b) kind] captures this association - of a Caml type ['a] for values read or written in the big array, - and of an element kind ['b] which represents the actual contents - of the big array. The following predefined values of type - [kind] list all possible associations of Caml types with - element kinds: *) - -val float32 : (float, float32_elt) kind -(** See {!Bigarray.char}. *) - -val float64 : (float, float64_elt) kind -(** See {!Bigarray.char}. *) - -val complex32 : (Complex.t, complex32_elt) kind -(** See {!Bigarray.char}. *) - -val complex64 : (Complex.t, complex64_elt) kind -(** See {!Bigarray.char}. *) - -val int8_signed : (int, int8_signed_elt) kind -(** See {!Bigarray.char}. *) - -val int8_unsigned : (int, int8_unsigned_elt) kind -(** See {!Bigarray.char}. *) - -val int16_signed : (int, int16_signed_elt) kind -(** See {!Bigarray.char}. *) - -val int16_unsigned : (int, int16_unsigned_elt) kind -(** See {!Bigarray.char}. *) - -val int : (int, int_elt) kind -(** See {!Bigarray.char}. *) - -val int32 : (int32, int32_elt) kind -(** See {!Bigarray.char}. *) - -val int64 : (int64, int64_elt) kind -(** See {!Bigarray.char}. *) - -val nativeint : (nativeint, nativeint_elt) kind -(** See {!Bigarray.char}. *) - -val char : (char, int8_unsigned_elt) kind -(** As shown by the types of the values above, - big arrays of kind [float32_elt] and [float64_elt] are - accessed using the Caml type [float]. Big arrays of complex kinds - [complex32_elt], [complex64_elt] are accessed with the Caml type - {!Complex.t}. Big arrays of - integer kinds are accessed using the smallest Caml integer - type large enough to represent the array elements: - [int] for 8- and 16-bit integer bigarrays, as well as Caml-integer - bigarrays; [int32] for 32-bit integer bigarrays; [int64] - for 64-bit integer bigarrays; and [nativeint] for - platform-native integer bigarrays. Finally, big arrays of - kind [int8_unsigned_elt] can also be accessed as arrays of - characters instead of arrays of small integers, by using - the kind value [char] instead of [int8_unsigned]. *) - -(** {6 Array layouts} *) - -type c_layout -(** See {!Bigarray.fortran_layout}.*) - -type fortran_layout -(** To facilitate interoperability with existing C and Fortran code, - this library supports two different memory layouts for big arrays, - one compatible with the C conventions, - the other compatible with the Fortran conventions. - - In the C-style layout, array indices start at 0, and - multi-dimensional arrays are laid out in row-major format. - That is, for a two-dimensional array, all elements of - row 0 are contiguous in memory, followed by all elements of - row 1, etc. In other terms, the array elements at [(x,y)] - and [(x, y+1)] are adjacent in memory. - - In the Fortran-style layout, array indices start at 1, and - multi-dimensional arrays are laid out in column-major format. - That is, for a two-dimensional array, all elements of - column 0 are contiguous in memory, followed by all elements of - column 1, etc. In other terms, the array elements at [(x,y)] - and [(x+1, y)] are adjacent in memory. - - Each layout style is identified at the type level by the - abstract types {!Bigarray.c_layout} and [fortran_layout] respectively. *) - -type 'a layout -(** The type ['a layout] represents one of the two supported - memory layouts: C-style if ['a] is {!Bigarray.c_layout}, Fortran-style - if ['a] is {!Bigarray.fortran_layout}. *) - - -(** {7 Supported layouts} - - The abstract values [c_layout] and [fortran_layout] represent - the two supported layouts at the level of values. -*) - -val c_layout : c_layout layout -val fortran_layout : fortran_layout layout - - -(** {6 Generic arrays (of arbitrarily many dimensions)} *) - -module Genarray : - sig - type ('a, 'b, 'c) t - (** The type [Genarray.t] is the type of big arrays with variable - numbers of dimensions. Any number of dimensions between 1 and 16 - is supported. - - The three type parameters to [Genarray.t] identify the array element - kind and layout, as follows: - - the first parameter, ['a], is the Caml type for accessing array - elements ([float], [int], [int32], [int64], [nativeint]); - - the second parameter, ['b], is the actual kind of array elements - ([float32_elt], [float64_elt], [int8_signed_elt], [int8_unsigned_elt], - etc); - - the third parameter, ['c], identifies the array layout - ([c_layout] or [fortran_layout]). - - For instance, [(float, float32_elt, fortran_layout) Genarray.t] - is the type of generic big arrays containing 32-bit floats - in Fortran layout; reads and writes in this array use the - Caml type [float]. *) - - external create: ('a, 'b) kind -> 'c layout -> int array -> ('a, 'b, 'c) t - = "bigarray_create" - (** [Genarray.create kind layout dimensions] returns a new big array - whose element kind is determined by the parameter [kind] (one of - [float32], [float64], [int8_signed], etc) and whose layout is - determined by the parameter [layout] (one of [c_layout] or - [fortran_layout]). The [dimensions] parameter is an array of - integers that indicate the size of the big array in each dimension. - The length of [dimensions] determines the number of dimensions - of the bigarray. - - For instance, [Genarray.create int32 c_layout [|4;6;8|]] - returns a fresh big array of 32-bit integers, in C layout, - having three dimensions, the three dimensions being 4, 6 and 8 - respectively. - - Big arrays returned by [Genarray.create] are not initialized: - the initial values of array elements is unspecified. - - [Genarray.create] raises [Invalid_arg] if the number of dimensions - is not in the range 1 to 16 inclusive, or if one of the dimensions - is negative. *) - - external num_dims: ('a, 'b, 'c) t -> int = "bigarray_num_dims" - (** Return the number of dimensions of the given big array. *) - - val dims : ('a, 'b, 'c) t -> int array - (** [Genarray.dims a] returns all dimensions of the big array [a], - as an array of integers of length [Genarray.num_dims a]. *) - - external nth_dim: ('a, 'b, 'c) t -> int -> int = "bigarray_dim" - (** [Genarray.nth_dim a n] returns the [n]-th dimension of the - big array [a]. The first dimension corresponds to [n = 0]; - the second dimension corresponds to [n = 1]; the last dimension, - to [n = Genarray.num_dims a - 1]. - Raise [Invalid_arg] if [n] is less than 0 or greater or equal than - [Genarray.num_dims a]. *) - - external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "bigarray_kind" - (** Return the kind of the given big array. *) - - external layout: ('a, 'b, 'c) t -> 'c layout = "bigarray_layout" - (** Return the layout of the given big array. *) - - external get: ('a, 'b, 'c) t -> int array -> 'a = "bigarray_get_generic" - (** Read an element of a generic big array. - [Genarray.get a [|i1; ...; iN|]] returns the element of [a] - whose coordinates are [i1] in the first dimension, [i2] in - the second dimension, ..., [iN] in the [N]-th dimension. - - If [a] has C layout, the coordinates must be greater or equal than 0 - and strictly less than the corresponding dimensions of [a]. - If [a] has Fortran layout, the coordinates must be greater or equal - than 1 and less or equal than the corresponding dimensions of [a]. - Raise [Invalid_arg] if the array [a] does not have exactly [N] - dimensions, or if the coordinates are outside the array bounds. - - If [N > 3], alternate syntax is provided: you can write - [a.{i1, i2, ..., iN}] instead of [Genarray.get a [|i1; ...; iN|]]. - (The syntax [a.{...}] with one, two or three coordinates is - reserved for accessing one-, two- and three-dimensional arrays - as described below.) *) - - external set: ('a, 'b, 'c) t -> int array -> 'a -> unit - = "bigarray_set_generic" - (** Assign an element of a generic big array. - [Genarray.set a [|i1; ...; iN|] v] stores the value [v] in the - element of [a] whose coordinates are [i1] in the first dimension, - [i2] in the second dimension, ..., [iN] in the [N]-th dimension. - - The array [a] must have exactly [N] dimensions, and all coordinates - must lie inside the array bounds, as described for [Genarray.get]; - otherwise, [Invalid_arg] is raised. - - If [N > 3], alternate syntax is provided: you can write - [a.{i1, i2, ..., iN} <- v] instead of - [Genarray.set a [|i1; ...; iN|] v]. - (The syntax [a.{...} <- v] with one, two or three coordinates is - reserved for updating one-, two- and three-dimensional arrays - as described below.) *) - - external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t - = "bigarray_sub" - (** Extract a sub-array of the given big array by restricting the - first (left-most) dimension. [Genarray.sub_left a ofs len] - returns a big array with the same number of dimensions as [a], - and the same dimensions as [a], except the first dimension, - which corresponds to the interval [[ofs ... ofs + len - 1]] - of the first dimension of [a]. No copying of elements is - involved: the sub-array and the original array share the same - storage space. In other terms, the element at coordinates - [[|i1; ...; iN|]] of the sub-array is identical to the - element at coordinates [[|i1+ofs; ...; iN|]] of the original - array [a]. - - [Genarray.sub_left] applies only to big arrays in C layout. - Raise [Invalid_arg] if [ofs] and [len] do not designate - a valid sub-array of [a], that is, if [ofs < 0], or [len < 0], - or [ofs + len > Genarray.nth_dim a 0]. *) - - external sub_right: - ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t - = "bigarray_sub" - (** Extract a sub-array of the given big array by restricting the - last (right-most) dimension. [Genarray.sub_right a ofs len] - returns a big array with the same number of dimensions as [a], - and the same dimensions as [a], except the last dimension, - which corresponds to the interval [[ofs ... ofs + len - 1]] - of the last dimension of [a]. No copying of elements is - involved: the sub-array and the original array share the same - storage space. In other terms, the element at coordinates - [[|i1; ...; iN|]] of the sub-array is identical to the - element at coordinates [[|i1; ...; iN+ofs|]] of the original - array [a]. - - [Genarray.sub_right] applies only to big arrays in Fortran layout. - Raise [Invalid_arg] if [ofs] and [len] do not designate - a valid sub-array of [a], that is, if [ofs < 1], or [len < 0], - or [ofs + len > Genarray.nth_dim a (Genarray.num_dims a - 1)]. *) - - external slice_left: - ('a, 'b, c_layout) t -> int array -> ('a, 'b, c_layout) t - = "bigarray_slice" - (** Extract a sub-array of lower dimension from the given big array - by fixing one or several of the first (left-most) coordinates. - [Genarray.slice_left a [|i1; ... ; iM|]] returns the ``slice'' - of [a] obtained by setting the first [M] coordinates to - [i1], ..., [iM]. If [a] has [N] dimensions, the slice has - dimension [N - M], and the element at coordinates - [[|j1; ...; j(N-M)|]] in the slice is identical to the element - at coordinates [[|i1; ...; iM; j1; ...; j(N-M)|]] in the original - array [a]. No copying of elements is involved: the slice and - the original array share the same storage space. - - [Genarray.slice_left] applies only to big arrays in C layout. - Raise [Invalid_arg] if [M >= N], or if [[|i1; ... ; iM|]] - is outside the bounds of [a]. *) - - external slice_right: - ('a, 'b, fortran_layout) t -> int array -> ('a, 'b, fortran_layout) t - = "bigarray_slice" - (** Extract a sub-array of lower dimension from the given big array - by fixing one or several of the last (right-most) coordinates. - [Genarray.slice_right a [|i1; ... ; iM|]] returns the ``slice'' - of [a] obtained by setting the last [M] coordinates to - [i1], ..., [iM]. If [a] has [N] dimensions, the slice has - dimension [N - M], and the element at coordinates - [[|j1; ...; j(N-M)|]] in the slice is identical to the element - at coordinates [[|j1; ...; j(N-M); i1; ...; iM|]] in the original - array [a]. No copying of elements is involved: the slice and - the original array share the same storage space. - - [Genarray.slice_right] applies only to big arrays in Fortran layout. - Raise [Invalid_arg] if [M >= N], or if [[|i1; ... ; iM|]] - is outside the bounds of [a]. *) - - external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit - = "bigarray_blit" - (** Copy all elements of a big array in another big array. - [Genarray.blit src dst] copies all elements of [src] into - [dst]. Both arrays [src] and [dst] must have the same number of - dimensions and equal dimensions. Copying a sub-array of [src] - to a sub-array of [dst] can be achieved by applying [Genarray.blit] - to sub-array or slices of [src] and [dst]. *) - - external fill: ('a, 'b, 'c) t -> 'a -> unit = "bigarray_fill" - (** Set all elements of a big array to a given value. - [Genarray.fill a v] stores the value [v] in all elements of - the big array [a]. Setting only some elements of [a] to [v] - can be achieved by applying [Genarray.fill] to a sub-array - or a slice of [a]. *) - - external map_file: - Unix.file_descr -> ('a, 'b) kind -> 'c layout -> - bool -> int array -> ('a, 'b, 'c) t = "bigarray_map_file" - (** Memory mapping of a file as a big array. - [Genarray.map_file fd kind layout shared dims] - returns a big array of kind [kind], layout [layout], - and dimensions as specified in [dims]. The data contained in - this big array are the contents of the file referred to by - the file descriptor [fd] (as opened previously with - [Unix.openfile], for example). If [shared] is [true], - all modifications performed on the array are reflected in - the file. This requires that [fd] be opened with write permissions. - If [shared] is [false], modifications performed on the array - are done in memory only, using copy-on-write of the modified - pages; the underlying file is not affected. - - [Genarray.map_file] is much more efficient than reading - the whole file in a big array, modifying that big array, - and writing it afterwards. - - To adjust automatically the dimensions of the big array to - the actual size of the file, the major dimension (that is, - the first dimension for an array with C layout, and the last - dimension for an array with Fortran layout) can be given as - [-1]. [Genarray.map_file] then determines the major dimension - from the size of the file. The file must contain an integral - number of sub-arrays as determined by the non-major dimensions, - otherwise [Failure] is raised. - - If all dimensions of the big array are given, the file size is - matched against the size of the big array. If the file is larger - than the big array, only the initial portion of the file is - mapped to the big array. If the file is smaller than the big - array, the file is automatically grown to the size of the big array. - This requires write permissions on [fd]. *) - - end - -(** {6 One-dimensional arrays} *) - -(** One-dimensional arrays. The [Array1] structure provides operations similar to those of - {!Bigarray.Genarray}, but specialized to the case of one-dimensional arrays. - (The [Array2] and [Array3] structures below provide operations - specialized for two- and three-dimensional arrays.) - Statically knowing the number of dimensions of the array allows - faster operations, and more precise static type-checking. *) -module Array1 : sig - type ('a, 'b, 'c) t - (** The type of one-dimensional big arrays whose elements have - Caml type ['a], representation kind ['b], and memory layout ['c]. *) - - val create: ('a, 'b) kind -> 'c layout -> int -> ('a, 'b, 'c) t - (** [Array1.create kind layout dim] returns a new bigarray of - one dimension, whose size is [dim]. [kind] and [layout] - determine the array element kind and the array layout - as described for [Genarray.create]. *) - - val dim: ('a, 'b, 'c) t -> int - (** Return the size (dimension) of the given one-dimensional - big array. *) - - external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "bigarray_kind" - (** Return the kind of the given big array. *) - - external layout: ('a, 'b, 'c) t -> 'c layout = "bigarray_layout" - (** Return the layout of the given big array. *) - - external get: ('a, 'b, 'c) t -> int -> 'a = "%bigarray_ref_1" - (** [Array1.get a x], or alternatively [a.{x}], - returns the element of [a] at index [x]. - [x] must be greater or equal than [0] and strictly less than - [Array1.dim a] if [a] has C layout. If [a] has Fortran layout, - [x] must be greater or equal than [1] and less or equal than - [Array1.dim a]. Otherwise, [Invalid_arg] is raised. *) - - external set: ('a, 'b, 'c) t -> int -> 'a -> unit = "%bigarray_set_1" - (** [Array1.set a x v], also written [a.{x} <- v], - stores the value [v] at index [x] in [a]. - [x] must be inside the bounds of [a] as described in - {!Bigarray.Array1.get}; - otherwise, [Invalid_arg] is raised. *) - - external sub: ('a, 'b, 'c) t -> int -> int -> ('a, 'b, 'c) t - = "bigarray_sub" - (** Extract a sub-array of the given one-dimensional big array. - See [Genarray.sub_left] for more details. *) - - external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit - = "bigarray_blit" - (** Copy the first big array to the second big array. - See [Genarray.blit] for more details. *) - - external fill: ('a, 'b, 'c) t -> 'a -> unit = "bigarray_fill" - (** Fill the given big array with the given value. - See [Genarray.fill] for more details. *) - - val of_array: ('a, 'b) kind -> 'c layout -> 'a array -> ('a, 'b, 'c) t - (** Build a one-dimensional big array initialized from the - given array. *) - - val map_file: Unix.file_descr -> ('a, 'b) kind -> 'c layout -> - bool -> int -> ('a, 'b, 'c) t - (** Memory mapping of a file as a one-dimensional big array. - See {!Bigarray.Genarray.map_file} for more details. *) -end - - -(** {6 Two-dimensional arrays} *) - -(** Two-dimensional arrays. The [Array2] structure provides operations similar to those of - {!Bigarray.Genarray}, but specialized to the case of two-dimensional arrays. *) -module Array2 : - sig - type ('a, 'b, 'c) t - (** The type of two-dimensional big arrays whose elements have - Caml type ['a], representation kind ['b], and memory layout ['c]. *) - - val create: ('a, 'b) kind -> 'c layout -> int -> int -> ('a, 'b, 'c) t - (** [Array2.create kind layout dim1 dim2] returns a new bigarray of - two dimension, whose size is [dim1] in the first dimension - and [dim2] in the second dimension. [kind] and [layout] - determine the array element kind and the array layout - as described for {!Bigarray.Genarray.create}. *) - - val dim1: ('a, 'b, 'c) t -> int - (** Return the first dimension of the given two-dimensional big array. *) - - val dim2: ('a, 'b, 'c) t -> int - (** Return the second dimension of the given two-dimensional big array. *) - - external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "bigarray_kind" - (** Return the kind of the given big array. *) - - external layout: ('a, 'b, 'c) t -> 'c layout = "bigarray_layout" - (** Return the layout of the given big array. *) - - external get: ('a, 'b, 'c) t -> int -> int -> 'a = "%bigarray_ref_2" - (** [Array2.get a x y], also written [a.{x,y}], - returns the element of [a] at coordinates ([x], [y]). - [x] and [y] must be within the bounds - of [a], as described for {!Bigarray.Genarray.get}; - otherwise, [Invalid_arg] is raised. *) - - external set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit = "%bigarray_set_2" - (** [Array2.set a x y v], or alternatively [a.{x,y} <- v], - stores the value [v] at coordinates ([x], [y]) in [a]. - [x] and [y] must be within the bounds of [a], - as described for {!Bigarray.Genarray.set}; - otherwise, [Invalid_arg] is raised. *) - - external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t - = "bigarray_sub" - (** Extract a two-dimensional sub-array of the given two-dimensional - big array by restricting the first dimension. - See {!Bigarray.Genarray.sub_left} for more details. - [Array2.sub_left] applies only to arrays with C layout. *) - - external sub_right: - ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t - = "bigarray_sub" - (** Extract a two-dimensional sub-array of the given two-dimensional - big array by restricting the second dimension. - See {!Bigarray.Genarray.sub_right} for more details. - [Array2.sub_right] applies only to arrays with Fortran layout. *) - - val slice_left: ('a, 'b, c_layout) t -> int -> ('a, 'b, c_layout) Array1.t - (** Extract a row (one-dimensional slice) of the given two-dimensional - big array. The integer parameter is the index of the row to - extract. See {!Bigarray.Genarray.slice_left} for more details. - [Array2.slice_left] applies only to arrays with C layout. *) - - val slice_right: - ('a, 'b, fortran_layout) t -> int -> ('a, 'b, fortran_layout) Array1.t - (** Extract a column (one-dimensional slice) of the given - two-dimensional big array. The integer parameter is the - index of the column to extract. See {!Bigarray.Genarray.slice_right} - for more details. [Array2.slice_right] applies only to arrays - with Fortran layout. *) - - external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit - = "bigarray_blit" - (** Copy the first big array to the second big array. - See {!Bigarray.Genarray.blit} for more details. *) - - external fill: ('a, 'b, 'c) t -> 'a -> unit = "bigarray_fill" - (** Fill the given big array with the given value. - See {!Bigarray.Genarray.fill} for more details. *) - - val of_array: ('a, 'b) kind -> 'c layout -> 'a array array -> ('a, 'b, 'c) t - (** Build a two-dimensional big array initialized from the - given array of arrays. *) - - val map_file: Unix.file_descr -> ('a, 'b) kind -> 'c layout -> - bool -> int -> int -> ('a, 'b, 'c) t - (** Memory mapping of a file as a two-dimensional big array. - See {!Bigarray.Genarray.map_file} for more details. *) - - end - -(** {6 Three-dimensional arrays} *) - -(** Three-dimensional arrays. The [Array3] structure provides operations similar to those of - {!Bigarray.Genarray}, but specialized to the case of three-dimensional arrays. *) -module Array3 : - sig - type ('a, 'b, 'c) t - (** The type of three-dimensional big arrays whose elements have - Caml type ['a], representation kind ['b], and memory layout ['c]. *) - - val create: ('a, 'b) kind -> 'c layout -> int -> int -> int -> ('a, 'b, 'c) t - (** [Array3.create kind layout dim1 dim2 dim3] returns a new bigarray of - three dimension, whose size is [dim1] in the first dimension, - [dim2] in the second dimension, and [dim3] in the third. - [kind] and [layout] determine the array element kind and - the array layout as described for {!Bigarray.Genarray.create}. *) - - val dim1: ('a, 'b, 'c) t -> int - (** Return the first dimension of the given three-dimensional big array. *) - - val dim2: ('a, 'b, 'c) t -> int - (** Return the second dimension of the given three-dimensional big array. *) - - val dim3: ('a, 'b, 'c) t -> int - (** Return the third dimension of the given three-dimensional big array. *) - - external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "bigarray_kind" - (** Return the kind of the given big array. *) - - external layout: ('a, 'b, 'c) t -> 'c layout = "bigarray_layout" - (** Return the layout of the given big array. *) - - external get: ('a, 'b, 'c) t -> int -> int -> int -> 'a = "%bigarray_ref_3" - (** [Array3.get a x y z], also written [a.{x,y,z}], - returns the element of [a] at coordinates ([x], [y], [z]). - [x], [y] and [z] must be within the bounds of [a], - as described for {!Bigarray.Genarray.get}; - otherwise, [Invalid_arg] is raised. *) - - external set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit - = "%bigarray_set_3" - (** [Array3.set a x y v], or alternatively [a.{x,y,z} <- v], - stores the value [v] at coordinates ([x], [y], [z]) in [a]. - [x], [y] and [z] must be within the bounds of [a], - as described for {!Bigarray.Genarray.set}; - otherwise, [Invalid_arg] is raised. *) - - external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t - = "bigarray_sub" - (** Extract a three-dimensional sub-array of the given - three-dimensional big array by restricting the first dimension. - See {!Bigarray.Genarray.sub_left} for more details. [Array3.sub_left] - applies only to arrays with C layout. *) - - external sub_right: - ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t - = "bigarray_sub" - (** Extract a three-dimensional sub-array of the given - three-dimensional big array by restricting the second dimension. - See {!Bigarray.Genarray.sub_right} for more details. [Array3.sub_right] - applies only to arrays with Fortran layout. *) - - val slice_left_1: - ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) Array1.t - (** Extract a one-dimensional slice of the given three-dimensional - big array by fixing the first two coordinates. - The integer parameters are the coordinates of the slice to - extract. See {!Bigarray.Genarray.slice_left} for more details. - [Array3.slice_left_1] applies only to arrays with C layout. *) - - val slice_right_1: - ('a, 'b, fortran_layout) t -> - int -> int -> ('a, 'b, fortran_layout) Array1.t - (** Extract a one-dimensional slice of the given three-dimensional - big array by fixing the last two coordinates. - The integer parameters are the coordinates of the slice to - extract. See {!Bigarray.Genarray.slice_right} for more details. - [Array3.slice_right_1] applies only to arrays with Fortran - layout. *) - - val slice_left_2: ('a, 'b, c_layout) t -> int -> ('a, 'b, c_layout) Array2.t - (** Extract a two-dimensional slice of the given three-dimensional - big array by fixing the first coordinate. - The integer parameter is the first coordinate of the slice to - extract. See {!Bigarray.Genarray.slice_left} for more details. - [Array3.slice_left_2] applies only to arrays with C layout. *) - - val slice_right_2: - ('a, 'b, fortran_layout) t -> int -> ('a, 'b, fortran_layout) Array2.t - (** Extract a two-dimensional slice of the given - three-dimensional big array by fixing the last coordinate. - The integer parameter is the coordinate of the slice - to extract. See {!Bigarray.Genarray.slice_right} for more details. - [Array3.slice_right_2] applies only to arrays with Fortran - layout. *) - - external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit - = "bigarray_blit" - (** Copy the first big array to the second big array. - See {!Bigarray.Genarray.blit} for more details. *) - - external fill: ('a, 'b, 'c) t -> 'a -> unit = "bigarray_fill" - (** Fill the given big array with the given value. - See {!Bigarray.Genarray.fill} for more details. *) - - val of_array: - ('a, 'b) kind -> 'c layout -> 'a array array array -> ('a, 'b, 'c) t - (** Build a three-dimensional big array initialized from the - given array of arrays of arrays. *) - - val map_file: Unix.file_descr -> ('a, 'b) kind -> 'c layout -> - bool -> int -> int -> int -> ('a, 'b, 'c) t - (** Memory mapping of a file as a three-dimensional big array. - See {!Bigarray.Genarray.map_file} for more details. *) - - end - -(** {6 Coercions between generic big arrays and fixed-dimension big arrays} *) - -external genarray_of_array1 : - ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t = "%identity" -(** Return the generic big array corresponding to the given one-dimensional big array. *) - -external genarray_of_array2 : - ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t = "%identity" -(** Return the generic big array corresponding to the given two-dimensional big array. *) - -external genarray_of_array3 : - ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t = "%identity" -(** Return the generic big array corresponding to the given three-dimensional big array. *) - -val array1_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array1.t -(** Return the one-dimensional big array corresponding to the given - generic big array. Raise [Invalid_arg] if the generic big array - does not have exactly one dimension. *) - -val array2_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array2.t -(** Return the two-dimensional big array corresponding to the given - generic big array. Raise [Invalid_arg] if the generic big array - does not have exactly two dimensions. *) - -val array3_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array3.t -(** Return the three-dimensional big array corresponding to the given - generic big array. Raise [Invalid_arg] if the generic big array - does not have exactly three dimensions. *) - - -(** {6 Re-shaping big arrays} *) - -val reshape : ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t -(** [reshape b [|d1;...;dN|]] converts the big array [b] to a - [N]-dimensional array of dimensions [d1]...[dN]. The returned - array and the original array [b] share their data - and have the same layout. For instance, assuming that [b] - is a one-dimensional array of dimension 12, [reshape b [|3;4|]] - returns a two-dimensional array [b'] of dimensions 3 and 4. - If [b] has C layout, the element [(x,y)] of [b'] corresponds - to the element [x * 3 + y] of [b]. If [b] has Fortran layout, - the element [(x,y)] of [b'] corresponds to the element - [x + (y - 1) * 4] of [b]. - The returned big array must have exactly the same number of - elements as the original big array [b]. That is, the product - of the dimensions of [b] must be equal to [i1 * ... * iN]. - Otherwise, [Invalid_arg] is raised. *) - -val reshape_1 : ('a, 'b, 'c) Genarray.t -> int -> ('a, 'b, 'c) Array1.t -(** Specialized version of {!Bigarray.reshape} for reshaping to one-dimensional arrays. *) - -val reshape_2 : ('a, 'b, 'c) Genarray.t -> int -> int -> ('a, 'b, 'c) Array2.t -(** Specialized version of {!Bigarray.reshape} for reshaping to two-dimensional arrays. *) - -val reshape_3 : - ('a, 'b, 'c) Genarray.t -> int -> int -> int -> ('a, 'b, 'c) Array3.t -(** Specialized version of {!Bigarray.reshape} for reshaping to three-dimensional arrays. *) - diff --git a/otherlibs/bigarray/bigarray_stubs.c b/otherlibs/bigarray/bigarray_stubs.c deleted file mode 100644 index 969c111b12..0000000000 --- a/otherlibs/bigarray/bigarray_stubs.c +++ /dev/null @@ -1,1073 +0,0 @@ -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ -/* */ -/* Copyright 2000 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id$ */ - -#include <stddef.h> -#include <stdarg.h> -#include <string.h> -#include "alloc.h" -#include "bigarray.h" -#include "custom.h" -#include "fail.h" -#include "intext.h" -#include "memory.h" -#include "mlvalues.h" - -CAMLextern int compare_unordered; /* from byterun/compare.c */ - -extern void bigarray_unmap_file(void * addr, unsigned long len); - /* from mmap_xxx.c */ - -/* Compute the number of elements of a big array */ - -static unsigned long bigarray_num_elts(struct caml_bigarray * b) -{ - unsigned long num_elts; - int i; - num_elts = 1; - for (i = 0; i < b->num_dims; i++) num_elts = num_elts * b->dim[i]; - return num_elts; -} - -/* Size in bytes of a bigarray element, indexed by bigarray kind */ - -int bigarray_element_size[] = -{ 4 /*FLOAT32*/, 8 /*FLOAT64*/, - 1 /*SINT8*/, 1 /*UINT8*/, - 2 /*SINT16*/, 2 /*UINT16*/, - 4 /*INT32*/, 8 /*INT64*/, - sizeof(value) /*CAML_INT*/, sizeof(value) /*NATIVE_INT*/, - 8 /*COMPLEX32*/, 16 /*COMPLEX64*/ -}; - -/* Compute the number of bytes for the elements of a big array */ - -unsigned long bigarray_byte_size(struct caml_bigarray * b) -{ - return bigarray_num_elts(b) - * bigarray_element_size[b->flags & BIGARRAY_KIND_MASK]; -} - -/* Operation table for bigarrays */ - -static void bigarray_finalize(value v); -static int bigarray_compare(value v1, value v2); -static long bigarray_hash(value v); -static void bigarray_serialize(value, unsigned long *, unsigned long *); -unsigned long bigarray_deserialize(void * dst); -static struct custom_operations bigarray_ops = { - "_bigarray", - bigarray_finalize, - bigarray_compare, - bigarray_hash, - bigarray_serialize, - bigarray_deserialize -}; - -/* Multiplication of unsigned longs with overflow detection */ - -static unsigned long -bigarray_multov(unsigned long a, unsigned long b, int * overflow) -{ -#define HALF_SIZE (sizeof(unsigned long) * 4) -#define LOW_HALF(x) ((x) & ((1UL << HALF_SIZE) - 1)) -#define HIGH_HALF(x) ((x) >> HALF_SIZE) - /* Cut in half words */ - unsigned long al = LOW_HALF(a); - unsigned long ah = HIGH_HALF(a); - unsigned long bl = LOW_HALF(b); - unsigned long bh = HIGH_HALF(b); - /* Exact product is: - al * bl - + ah * bl << HALF_SIZE - + al * bh << HALF_SIZE - + ah * bh << 2*HALF_SIZE - Overflow occurs if: - ah * bh is not 0, i.e. ah != 0 and bh != 0 - OR ah * bl has high half != 0 - OR ah * bl has high half != 0 - OR the sum al * bl + LOW_HALF(ah * bl) << HALF_SIZE - + LOW_HALF(al * bh) << HALF_SIZE overflows. - This sum is equal to p = (a * b) modulo word size. */ - unsigned long p1 = al * bh; - unsigned long p2 = ah * bl; - unsigned long p = a * b; - if (ah != 0 && bh != 0) *overflow = 1; - if (p1 >= (1UL << HALF_SIZE) || p2 >= (1UL << HALF_SIZE)) *overflow = 1; - p1 <<= HALF_SIZE; - p2 <<= HALF_SIZE; - p1 += p2; - if (p < p1 || p1 < p2) *overflow = 1; /* overflow in sums */ - return p; -#undef HALF_SIZE -#undef LOW_HALF -#undef HIGH_HALF -} - -/* Allocation of a big array */ - -#define MAX_BIGARRAY_MEMORY 256*1024*1024 -/* 256 Mb -- after allocating that much, it's probably worth speeding - up the major GC */ - -/* [alloc_bigarray] will allocate a new bigarray object in the heap. - If [data] is NULL, the memory for the contents is also allocated - (with [malloc]) by [alloc_bigarray]. - [data] cannot point into the Caml heap. - [dim] may point into an object in the Caml heap. -*/ -CAMLexport value -alloc_bigarray(int flags, int num_dims, void * data, long * dim) -{ - unsigned long num_elts, size; - int overflow, i; - value res; - struct caml_bigarray * b; - long dimcopy[MAX_NUM_DIMS]; - - Assert(num_dims >= 1 && num_dims <= MAX_NUM_DIMS); - Assert((flags & BIGARRAY_KIND_MASK) <= BIGARRAY_COMPLEX64); - for (i = 0; i < num_dims; i++) dimcopy[i] = dim[i]; - size = 0; - if (data == NULL) { - overflow = 0; - num_elts = 1; - for (i = 0; i < num_dims; i++) { - num_elts = bigarray_multov(num_elts, dimcopy[i], &overflow); - } - size = bigarray_multov(num_elts, - bigarray_element_size[flags & BIGARRAY_KIND_MASK], - &overflow); - if (overflow) raise_out_of_memory(); - data = malloc(size); - if (data == NULL && size != 0) raise_out_of_memory(); - flags |= BIGARRAY_MANAGED; - } - res = alloc_custom(&bigarray_ops, - sizeof(struct caml_bigarray) - + (num_dims - 1) * sizeof(long), - size, MAX_BIGARRAY_MEMORY); - b = Bigarray_val(res); - b->data = data; - b->num_dims = num_dims; - b->flags = flags; - b->proxy = NULL; - for (i = 0; i < num_dims; i++) b->dim[i] = dimcopy[i]; - return res; -} - -/* Same as alloc_bigarray, but dimensions are passed as a list of - arguments */ - -CAMLexport value alloc_bigarray_dims(int flags, int num_dims, void * data, ...) -{ - va_list ap; - long dim[MAX_NUM_DIMS]; - int i; - value res; - - va_start(ap, data); - for (i = 0; i < num_dims; i++) dim[i] = va_arg(ap, long); - va_end(ap); - res = alloc_bigarray(flags, num_dims, data, dim); - return res; -} - -/* Allocate a bigarray from Caml */ - -CAMLprim value bigarray_create(value vkind, value vlayout, value vdim) -{ - long dim[MAX_NUM_DIMS]; - mlsize_t num_dims; - int i, flags; - - num_dims = Wosize_val(vdim); - if (num_dims < 1 || num_dims > MAX_NUM_DIMS) - invalid_argument("Bigarray.create: bad number of dimensions"); - for (i = 0; i < num_dims; i++) { - dim[i] = Long_val(Field(vdim, i)); - if (dim[i] < 0 || dim[i] > 0x7FFFFFFFL) - invalid_argument("Bigarray.create: negative dimension"); - } - flags = Int_val(vkind) | Int_val(vlayout); - return alloc_bigarray(flags, num_dims, NULL, dim); -} - -/* Given a big array and a vector of indices, check that the indices - are within the bounds and return the offset of the corresponding - array element in the data part of the array. */ - -static long bigarray_offset(struct caml_bigarray * b, long * index) -{ - long offset; - int i; - - offset = 0; - if ((b->flags & BIGARRAY_LAYOUT_MASK) == BIGARRAY_C_LAYOUT) { - /* C-style layout: row major, indices start at 0 */ - for (i = 0; i < b->num_dims; i++) { - if ((unsigned long) index[i] >= (unsigned long) b->dim[i]) - array_bound_error(); - offset = offset * b->dim[i] + index[i]; - } - } else { - /* Fortran-style layout: column major, indices start at 1 */ - for (i = b->num_dims - 1; i >= 0; i--) { - if ((unsigned long) (index[i] - 1) >= (unsigned long) b->dim[i]) - array_bound_error(); - offset = offset * b->dim[i] + (index[i] - 1); - } - } - return offset; -} - -/* Helper function to allocate a record of two double floats */ - -static value copy_two_doubles(double d0, double d1) -{ - value res = alloc_small(2 * Double_wosize, Double_array_tag); - Store_double_field(res, 0, d0); - Store_double_field(res, 1, d1); - return res; -} - -/* Generic code to read from a big array */ - -value bigarray_get_N(value vb, value * vind, int nind) -{ - struct caml_bigarray * b = Bigarray_val(vb); - long index[MAX_NUM_DIMS]; - int i; - long offset; - - /* Check number of indices = number of dimensions of array - (maybe not necessary if ML typing guarantees this) */ - if (nind != b->num_dims) - invalid_argument("Bigarray.get: wrong number of indices"); - /* Compute offset and check bounds */ - for (i = 0; i < b->num_dims; i++) index[i] = Long_val(vind[i]); - offset = bigarray_offset(b, index); - /* Perform read */ - switch ((b->flags) & BIGARRAY_KIND_MASK) { - default: - Assert(0); - case BIGARRAY_FLOAT32: - return copy_double(((float *) b->data)[offset]); - case BIGARRAY_FLOAT64: - return copy_double(((double *) b->data)[offset]); - case BIGARRAY_SINT8: - return Val_int(((schar *) b->data)[offset]); - case BIGARRAY_UINT8: - return Val_int(((unsigned char *) b->data)[offset]); - case BIGARRAY_SINT16: - return Val_int(((int16 *) b->data)[offset]); - case BIGARRAY_UINT16: - return Val_int(((uint16 *) b->data)[offset]); - case BIGARRAY_INT32: - return copy_int32(((int32 *) b->data)[offset]); - case BIGARRAY_INT64: - return copy_int64(((int64 *) b->data)[offset]); - case BIGARRAY_NATIVE_INT: - return copy_nativeint(((long *) b->data)[offset]); - case BIGARRAY_CAML_INT: - return Val_long(((long *) b->data)[offset]); - case BIGARRAY_COMPLEX32: - { float * p = ((float *) b->data) + offset * 2; - return copy_two_doubles(p[0], p[1]); } - case BIGARRAY_COMPLEX64: - { double * p = ((double *) b->data) + offset * 2; - return copy_two_doubles(p[0], p[1]); } - } -} - -CAMLprim value bigarray_get_1(value vb, value vind1) -{ - return bigarray_get_N(vb, &vind1, 1); -} - -CAMLprim value bigarray_get_2(value vb, value vind1, value vind2) -{ - value vind[2]; - vind[0] = vind1; vind[1] = vind2; - return bigarray_get_N(vb, vind, 2); -} - -CAMLprim value bigarray_get_3(value vb, value vind1, value vind2, value vind3) -{ - value vind[3]; - vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; - return bigarray_get_N(vb, vind, 3); -} - -#if 0 -CAMLprim value bigarray_get_4(value vb, value vind1, value vind2, - value vind3, value vind4) -{ - value vind[4]; - vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; vind[3] = vind4; - return bigarray_get_N(vb, vind, 4); -} - -CAMLprim value bigarray_get_5(value vb, value vind1, value vind2, - value vind3, value vind4, value vind5) -{ - value vind[5]; - vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; - vind[3] = vind4; vind[4] = vind5; - return bigarray_get_N(vb, vind, 5); -} - -CAMLprim value bigarray_get_6(value vb, value vind1, value vind2, - value vind3, value vind4, value vind5, value vind6) -{ - value vind[6]; - vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; - vind[3] = vind4; vind[4] = vind5; vind[5] = vind6; - return bigarray_get_N(vb, vind, 6); -} -#endif - -CAMLprim value bigarray_get_generic(value vb, value vind) -{ - return bigarray_get_N(vb, &Field(vind, 0), Wosize_val(vind)); -} - -/* Generic write to a big array */ - -static value bigarray_set_aux(value vb, value * vind, long nind, value newval) -{ - struct caml_bigarray * b = Bigarray_val(vb); - long index[MAX_NUM_DIMS]; - int i; - long offset; - - /* Check number of indices = number of dimensions of array - (maybe not necessary if ML typing guarantees this) */ - if (nind != b->num_dims) - invalid_argument("Bigarray.set: wrong number of indices"); - /* Compute offset and check bounds */ - for (i = 0; i < b->num_dims; i++) index[i] = Long_val(vind[i]); - offset = bigarray_offset(b, index); - /* Perform write */ - switch (b->flags & BIGARRAY_KIND_MASK) { - default: - Assert(0); - case BIGARRAY_FLOAT32: - ((float *) b->data)[offset] = Double_val(newval); break; - case BIGARRAY_FLOAT64: - ((double *) b->data)[offset] = Double_val(newval); break; - case BIGARRAY_SINT8: - case BIGARRAY_UINT8: - ((schar *) b->data)[offset] = Int_val(newval); break; - case BIGARRAY_SINT16: - case BIGARRAY_UINT16: - ((int16 *) b->data)[offset] = Int_val(newval); break; - case BIGARRAY_INT32: - ((int32 *) b->data)[offset] = Int32_val(newval); break; - case BIGARRAY_INT64: - ((int64 *) b->data)[offset] = Int64_val(newval); break; - case BIGARRAY_NATIVE_INT: - ((long *) b->data)[offset] = Nativeint_val(newval); break; - case BIGARRAY_CAML_INT: - ((long *) b->data)[offset] = Long_val(newval); break; - case BIGARRAY_COMPLEX32: - { float * p = ((float *) b->data) + offset * 2; - p[0] = Double_field(newval, 0); - p[1] = Double_field(newval, 1); - break; } - case BIGARRAY_COMPLEX64: - { double * p = ((double *) b->data) + offset * 2; - p[0] = Double_field(newval, 0); - p[1] = Double_field(newval, 1); - break; } - } - return Val_unit; -} - -CAMLprim value bigarray_set_1(value vb, value vind1, value newval) -{ - return bigarray_set_aux(vb, &vind1, 1, newval); -} - -CAMLprim value bigarray_set_2(value vb, value vind1, value vind2, value newval) -{ - value vind[2]; - vind[0] = vind1; vind[1] = vind2; - return bigarray_set_aux(vb, vind, 2, newval); -} - -CAMLprim value bigarray_set_3(value vb, value vind1, value vind2, value vind3, - value newval) -{ - value vind[3]; - vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; - return bigarray_set_aux(vb, vind, 3, newval); -} - -#if 0 -CAMLprim value bigarray_set_4(value vb, value vind1, value vind2, - value vind3, value vind4, value newval) -{ - value vind[4]; - vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; vind[3] = vind4; - return bigarray_set_aux(vb, vind, 4, newval); -} - -CAMLprim value bigarray_set_5(value vb, value vind1, value vind2, - value vind3, value vind4, value vind5, value newval) -{ - value vind[5]; - vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; - vind[3] = vind4; vind[4] = vind5; - return bigarray_set_aux(vb, vind, 5, newval); -} - -CAMLprim value bigarray_set_6(value vb, value vind1, value vind2, - value vind3, value vind4, value vind5, - value vind6, value newval) -{ - value vind[6]; - vind[0] = vind1; vind[1] = vind2; vind[2] = vind3; - vind[3] = vind4; vind[4] = vind5; vind[5] = vind6; - return bigarray_set_aux(vb, vind, 6, newval); -} - -value bigarray_set_N(value vb, value * vind, int nargs) -{ - return bigarray_set_aux(vb, vind, nargs - 1, vind[nargs - 1]); -} -#endif - -CAMLprim value bigarray_set_generic(value vb, value vind, value newval) -{ - return bigarray_set_aux(vb, &Field(vind, 0), Wosize_val(vind), newval); -} - -/* Return the number of dimensions of a big array */ - -CAMLprim value bigarray_num_dims(value vb) -{ - struct caml_bigarray * b = Bigarray_val(vb); - return Val_long(b->num_dims); -} - -/* Return the n-th dimension of a big array */ - -CAMLprim value bigarray_dim(value vb, value vn) -{ - struct caml_bigarray * b = Bigarray_val(vb); - long n = Long_val(vn); - if (n >= b->num_dims) invalid_argument("Bigarray.dim"); - return Val_long(b->dim[n]); -} - -/* Return the kind of a big array */ - -CAMLprim value bigarray_kind(value vb) -{ - return Val_int(Bigarray_val(vb)->flags & BIGARRAY_KIND_MASK); -} - -/* Return the layout of a big array */ - -CAMLprim value bigarray_layout(value vb) -{ - return Val_int(Bigarray_val(vb)->flags & BIGARRAY_LAYOUT_MASK); -} - -/* Finalization of a big array */ - -static void bigarray_finalize(value v) -{ - struct caml_bigarray * b = Bigarray_val(v); - - switch (b->flags & BIGARRAY_MANAGED_MASK) { - case BIGARRAY_EXTERNAL: - break; - case BIGARRAY_MANAGED: - if (b->proxy == NULL) { - free(b->data); - } else { - if (-- b->proxy->refcount == 0) { - free(b->proxy->data); - stat_free(b->proxy); - } - } - break; - case BIGARRAY_MAPPED_FILE: - if (b->proxy == NULL) { - bigarray_unmap_file(b->data, bigarray_byte_size(b)); - } else { - if (-- b->proxy->refcount == 0) { - bigarray_unmap_file(b->proxy->data, b->proxy->size); - stat_free(b->proxy); - } - } - break; - } -} - -/* Comparison of two big arrays */ - -static int bigarray_compare(value v1, value v2) -{ - struct caml_bigarray * b1 = Bigarray_val(v1); - struct caml_bigarray * b2 = Bigarray_val(v2); - unsigned long n, num_elts; - int i; - - /* Compare number of dimensions */ - if (b1->num_dims != b2->num_dims) return b2->num_dims - b1->num_dims; - /* Same number of dimensions: compare dimensions lexicographically */ - for (i = 0; i < b1->num_dims; i++) { - long d1 = b1->dim[i]; - long d2 = b2->dim[i]; - if (d1 != d2) return d1 < d2 ? -1 : 1; - } - /* Same dimensions: compare contents lexicographically */ - num_elts = bigarray_num_elts(b1); - -#define DO_INTEGER_COMPARISON(type) \ - { type * p1 = b1->data; type * p2 = b2->data; \ - for (n = 0; n < num_elts; n++) { \ - type e1 = *p1++; type e2 = *p2++; \ - if (e1 < e2) return -1; \ - if (e1 > e2) return 1; \ - } \ - return 0; \ - } -#define DO_FLOAT_COMPARISON(type) \ - { type * p1 = b1->data; type * p2 = b2->data; \ - for (n = 0; n < num_elts; n++) { \ - type e1 = *p1++; type e2 = *p2++; \ - if (e1 < e2) return -1; \ - if (e1 > e2) return 1; \ - if (e1 != e2) { \ - compare_unordered = 1; \ - if (e1 == e1) return 1; \ - if (e2 == e2) return -1; \ - } \ - } \ - return 0; \ - } - - switch (b1->flags & BIGARRAY_KIND_MASK) { - case BIGARRAY_COMPLEX32: - num_elts *= 2; /*fallthrough*/ - case BIGARRAY_FLOAT32: - DO_FLOAT_COMPARISON(float); - case BIGARRAY_COMPLEX64: - num_elts *= 2; /*fallthrough*/ - case BIGARRAY_FLOAT64: - DO_FLOAT_COMPARISON(double); - case BIGARRAY_SINT8: - DO_INTEGER_COMPARISON(schar); - case BIGARRAY_UINT8: - DO_INTEGER_COMPARISON(unsigned char); - case BIGARRAY_SINT16: - DO_INTEGER_COMPARISON(int16); - case BIGARRAY_UINT16: - DO_INTEGER_COMPARISON(uint16); - case BIGARRAY_INT32: - DO_INTEGER_COMPARISON(int32); - case BIGARRAY_INT64: -#ifdef ARCH_INT64_TYPE - DO_INTEGER_COMPARISON(int64); -#else - { int64 * p1 = b1->data; int64 * p2 = b2->data; - for (n = 0; n < num_elts; n++) { - int64 e1 = *p1++; int64 e2 = *p2++; - if ((int32)e1.h > (int32)e2.h) return 1; - if ((int32)e1.h < (int32)e2.h) return -1; - if (e1.l > e2.l) return 1; - if (e1.l < e2.l) return -1; - } - return 0; - } -#endif - case BIGARRAY_CAML_INT: - case BIGARRAY_NATIVE_INT: - DO_INTEGER_COMPARISON(long); - default: - Assert(0); - return 0; /* should not happen */ - } -#undef DO_INTEGER_COMPARISON -#undef DO_FLOAT_COMPARISON -} - -/* Hashing of a bigarray */ - -static long bigarray_hash(value v) -{ - struct caml_bigarray * b = Bigarray_val(v); - long num_elts, n, h; - int i; - - num_elts = 1; - for (i = 0; i < b->num_dims; i++) num_elts = num_elts * b->dim[i]; - if (num_elts >= 50) num_elts = 50; - h = 0; - -#define COMBINE(h,v) ((h << 4) + h + (v)) - - switch (b->flags & BIGARRAY_KIND_MASK) { - case BIGARRAY_SINT8: - case BIGARRAY_UINT8: { - unsigned char * p = b->data; - for (n = 0; n < num_elts; n++) h = COMBINE(h, *p++); - break; - } - case BIGARRAY_SINT16: - case BIGARRAY_UINT16: { - unsigned short * p = b->data; - for (n = 0; n < num_elts; n++) h = COMBINE(h, *p++); - break; - } - case BIGARRAY_FLOAT32: - case BIGARRAY_COMPLEX32: - case BIGARRAY_INT32: -#ifndef ARCH_SIXTYFOUR - case BIGARRAY_CAML_INT: - case BIGARRAY_NATIVE_INT: -#endif - { - uint32 * p = b->data; - for (n = 0; n < num_elts; n++) h = COMBINE(h, *p++); - break; - } - case BIGARRAY_FLOAT64: - case BIGARRAY_COMPLEX64: - case BIGARRAY_INT64: -#ifdef ARCH_SIXTYFOUR - case BIGARRAY_CAML_INT: - case BIGARRAY_NATIVE_INT: -#endif -#ifdef ARCH_SIXTYFOUR - { - unsigned long * p = b->data; - for (n = 0; n < num_elts; n++) h = COMBINE(h, *p++); - break; - } -#else - { - uint32 * p = b->data; - for (n = 0; n < num_elts; n++) { -#ifdef ARCH_BIG_ENDIAN - h = COMBINE(h, p[1]); h = COMBINE(h, p[0]); p += 2; -#else - h = COMBINE(h, p[0]); h = COMBINE(h, p[1]); p += 2; -#endif - } - break; - } -#endif - } -#undef COMBINE - return h; -} - -static void bigarray_serialize_longarray(void * data, - long num_elts, - long min_val, long max_val) -{ -#ifdef ARCH_SIXTYFOUR - int overflow_32 = 0; - long * p, n; - for (n = 0, p = data; n < num_elts; n++, p++) { - if (*p < min_val || *p > max_val) { overflow_32 = 1; break; } - } - if (overflow_32) { - serialize_int_1(1); - serialize_block_8(data, num_elts); - } else { - serialize_int_1(0); - for (n = 0, p = data; n < num_elts; n++, p++) serialize_int_4((int32) *p); - } -#else - serialize_int_1(0); - serialize_block_4(data, num_elts); -#endif -} - -static void bigarray_serialize(value v, - unsigned long * wsize_32, - unsigned long * wsize_64) -{ - struct caml_bigarray * b = Bigarray_val(v); - long num_elts; - int i; - - /* Serialize header information */ - serialize_int_4(b->num_dims); - serialize_int_4(b->flags & (BIGARRAY_KIND_MASK | BIGARRAY_LAYOUT_MASK)); - for (i = 0; i < b->num_dims; i++) serialize_int_4(b->dim[i]); - /* Compute total number of elements */ - num_elts = 1; - for (i = 0; i < b->num_dims; i++) num_elts = num_elts * b->dim[i]; - /* Serialize elements */ - switch (b->flags & BIGARRAY_KIND_MASK) { - case BIGARRAY_SINT8: - case BIGARRAY_UINT8: - serialize_block_1(b->data, num_elts); break; - case BIGARRAY_SINT16: - case BIGARRAY_UINT16: - serialize_block_2(b->data, num_elts); break; - case BIGARRAY_FLOAT32: - case BIGARRAY_INT32: - serialize_block_4(b->data, num_elts); break; - case BIGARRAY_COMPLEX32: - serialize_block_4(b->data, num_elts * 2); break; - case BIGARRAY_FLOAT64: - case BIGARRAY_INT64: - serialize_block_8(b->data, num_elts); break; - case BIGARRAY_COMPLEX64: - serialize_block_8(b->data, num_elts * 2); break; - case BIGARRAY_CAML_INT: - bigarray_serialize_longarray(b->data, num_elts, -0x40000000, 0x3FFFFFFF); - break; - case BIGARRAY_NATIVE_INT: - bigarray_serialize_longarray(b->data, num_elts, -0x80000000, 0x7FFFFFFF); - break; - } - /* Compute required size in Caml heap. Assumes struct caml_bigarray - is exactly 4 + num_dims words */ - Assert(sizeof(struct caml_bigarray) == 5 * sizeof(value)); - *wsize_32 = (4 + b->num_dims) * 4; - *wsize_64 = (4 + b->num_dims) * 8; -} - -static void bigarray_deserialize_longarray(void * dest, long num_elts) -{ - int sixty = deserialize_uint_1(); -#ifdef ARCH_SIXTYFOUR - if (sixty) { - deserialize_block_8(dest, num_elts); - } else { - long * p, n; - for (n = 0, p = dest; n < num_elts; n++, p++) *p = deserialize_sint_4(); - } -#else - if (sixty) - deserialize_error("input_value: cannot read bigarray " - "with 64-bit Caml ints"); - deserialize_block_4(dest, num_elts); -#endif -} - -unsigned long bigarray_deserialize(void * dst) -{ - struct caml_bigarray * b = dst; - int i, elt_size; - unsigned long num_elts; - - /* Read back header information */ - b->num_dims = deserialize_uint_4(); - b->flags = deserialize_uint_4() | BIGARRAY_MANAGED; - b->proxy = NULL; - for (i = 0; i < b->num_dims; i++) b->dim[i] = deserialize_uint_4(); - /* Compute total number of elements */ - num_elts = bigarray_num_elts(b); - /* Determine element size in bytes */ - if ((b->flags & BIGARRAY_KIND_MASK) > BIGARRAY_COMPLEX64) - deserialize_error("input_value: bad bigarray kind"); - elt_size = bigarray_element_size[b->flags & BIGARRAY_KIND_MASK]; - /* Allocate room for data */ - b->data = malloc(elt_size * num_elts); - if (b->data == NULL) - deserialize_error("input_value: out of memory for bigarray"); - /* Read data */ - switch (b->flags & BIGARRAY_KIND_MASK) { - case BIGARRAY_SINT8: - case BIGARRAY_UINT8: - deserialize_block_1(b->data, num_elts); break; - case BIGARRAY_SINT16: - case BIGARRAY_UINT16: - deserialize_block_2(b->data, num_elts); break; - case BIGARRAY_FLOAT32: - case BIGARRAY_INT32: - deserialize_block_4(b->data, num_elts); break; - case BIGARRAY_COMPLEX32: - deserialize_block_4(b->data, num_elts * 2); break; - case BIGARRAY_FLOAT64: - case BIGARRAY_INT64: - deserialize_block_8(b->data, num_elts); break; - case BIGARRAY_COMPLEX64: - deserialize_block_8(b->data, num_elts * 2); break; - case BIGARRAY_CAML_INT: - case BIGARRAY_NATIVE_INT: - bigarray_deserialize_longarray(b->data, num_elts); break; - } - return sizeof(struct caml_bigarray) + (b->num_dims - 1) * sizeof(long); -} - -/* Create / update proxy to indicate that b2 is a sub-array of b1 */ - -static void bigarray_update_proxy(struct caml_bigarray * b1, - struct caml_bigarray * b2) -{ - struct caml_bigarray_proxy * proxy; - /* Nothing to do for un-managed arrays */ - if ((b1->flags & BIGARRAY_MANAGED_MASK) == BIGARRAY_EXTERNAL) return; - if (b1->proxy != NULL) { - /* If b1 is already a proxy for a larger array, increment refcount of - proxy */ - b2->proxy = b1->proxy; - ++ b1->proxy->refcount; - } else { - /* Otherwise, create proxy and attach it to both b1 and b2 */ - proxy = stat_alloc(sizeof(struct caml_bigarray_proxy)); - proxy->refcount = 2; /* original array + sub array */ - proxy->data = b1->data; - proxy->size = - b1->flags & BIGARRAY_MAPPED_FILE ? bigarray_byte_size(b1) : 0; - b1->proxy = proxy; - b2->proxy = proxy; - } -} - -/* Slicing */ - -CAMLprim value bigarray_slice(value vb, value vind) -{ - CAMLparam2 (vb, vind); - #define b ((struct caml_bigarray *) Bigarray_val(vb)) - CAMLlocal1 (res); - long index[MAX_NUM_DIMS]; - int num_inds, i; - long offset; - long * sub_dims; - char * sub_data; - - /* Check number of indices < number of dimensions of array */ - num_inds = Wosize_val(vind); - if (num_inds >= b->num_dims) - invalid_argument("Bigarray.slice: too many indices"); - /* Compute offset and check bounds */ - if ((b->flags & BIGARRAY_LAYOUT_MASK) == BIGARRAY_C_LAYOUT) { - /* We slice from the left */ - for (i = 0; i < num_inds; i++) index[i] = Long_val(Field(vind, i)); - for (/*nothing*/; i < b->num_dims; i++) index[i] = 0; - offset = bigarray_offset(b, index); - sub_dims = b->dim + num_inds; - } else { - /* We slice from the right */ - for (i = 0; i < num_inds; i++) - index[b->num_dims - num_inds + i] = Long_val(Field(vind, i)); - for (i = 0; i < b->num_dims - num_inds; i++) index[i] = 1; - offset = bigarray_offset(b, index); - sub_dims = b->dim; - } - sub_data = - (char *) b->data + - offset * bigarray_element_size[b->flags & BIGARRAY_KIND_MASK]; - /* Allocate a Caml bigarray to hold the result */ - res = alloc_bigarray(b->flags, b->num_dims - num_inds, sub_data, sub_dims); - /* Create or update proxy in case of managed bigarray */ - bigarray_update_proxy(b, Bigarray_val(res)); - /* Return result */ - CAMLreturn (res); - - #undef b -} - -/* Extracting a sub-array of same number of dimensions */ - -CAMLprim value bigarray_sub(value vb, value vofs, value vlen) -{ - CAMLparam3 (vb, vofs, vlen); - CAMLlocal1 (res); - #define b ((struct caml_bigarray *) Bigarray_val(vb)) - long ofs = Long_val(vofs); - long len = Long_val(vlen); - int i, changed_dim; - long mul; - char * sub_data; - - /* Compute offset and check bounds */ - if ((b->flags & BIGARRAY_LAYOUT_MASK) == BIGARRAY_C_LAYOUT) { - /* We reduce the first dimension */ - mul = 1; - for (i = 1; i < b->num_dims; i++) mul *= b->dim[i]; - changed_dim = 0; - } else { - /* We reduce the last dimension */ - mul = 1; - for (i = 0; i < b->num_dims - 1; i++) mul *= b->dim[i]; - changed_dim = b->num_dims - 1; - ofs--; /* Fortran arrays start at 1 */ - } - if (ofs < 0 || len < 0 || ofs + len > b->dim[changed_dim]) - invalid_argument("Bigarray.sub: bad sub-array"); - sub_data = - (char *) b->data + - ofs * mul * bigarray_element_size[b->flags & BIGARRAY_KIND_MASK]; - /* Allocate a Caml bigarray to hold the result */ - res = alloc_bigarray(b->flags, b->num_dims, sub_data, b->dim); - /* Doctor the changed dimension */ - Bigarray_val(res)->dim[changed_dim] = len; - /* Create or update proxy in case of managed bigarray */ - bigarray_update_proxy(b, Bigarray_val(res)); - /* Return result */ - CAMLreturn (res); - - #undef b -} - -/* Copying a big array into another one */ - -CAMLprim value bigarray_blit(value vsrc, value vdst) -{ - struct caml_bigarray * src = Bigarray_val(vsrc); - struct caml_bigarray * dst = Bigarray_val(vdst); - int i; - long num_bytes; - - /* Check same numbers of dimensions and same dimensions */ - if (src->num_dims != dst->num_dims) goto blit_error; - for (i = 0; i < src->num_dims; i++) - if (src->dim[i] != dst->dim[i]) goto blit_error; - /* Compute number of bytes in array data */ - num_bytes = - bigarray_num_elts(src) - * bigarray_element_size[src->flags & BIGARRAY_KIND_MASK]; - /* Do the copying */ - memmove (dst->data, src->data, num_bytes); - return Val_unit; - blit_error: - invalid_argument("Bigarray.blit: dimension mismatch"); - return Val_unit; /* not reached */ -} - -/* Filling a big array with a given value */ - -CAMLprim value bigarray_fill(value vb, value vinit) -{ - struct caml_bigarray * b = Bigarray_val(vb); - long num_elts = bigarray_num_elts(b); - - switch (b->flags & BIGARRAY_KIND_MASK) { - default: - Assert(0); - case BIGARRAY_FLOAT32: { - float init = Double_val(vinit); - float * p; - for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; - break; - } - case BIGARRAY_FLOAT64: { - double init = Double_val(vinit); - double * p; - for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; - break; - } - case BIGARRAY_SINT8: - case BIGARRAY_UINT8: { - int init = Int_val(vinit); - char * p; - for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; - break; - } - case BIGARRAY_SINT16: - case BIGARRAY_UINT16: { - int init = Int_val(vinit); - short * p; - for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; - break; - } - case BIGARRAY_INT32: { - int32 init = Int32_val(vinit); - int32 * p; - for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; - break; - } - case BIGARRAY_INT64: { - int64 init = Int64_val(vinit); - int64 * p; - for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; - break; - } - case BIGARRAY_NATIVE_INT: { - long init = Nativeint_val(vinit); - long * p; - for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; - break; - } - case BIGARRAY_CAML_INT: { - long init = Long_val(vinit); - long * p; - for (p = b->data; num_elts > 0; p++, num_elts--) *p = init; - break; - } - case BIGARRAY_COMPLEX32: { - float init0 = Double_field(vinit, 0); - float init1 = Double_field(vinit, 1); - float * p; - for (p = b->data; num_elts > 0; num_elts--) { *p++ = init0; *p++ = init1; } - break; - } - case BIGARRAY_COMPLEX64: { - double init0 = Double_field(vinit, 0); - double init1 = Double_field(vinit, 1); - double * p; - for (p = b->data; num_elts > 0; num_elts--) { *p++ = init0; *p++ = init1; } - break; - } - } - return Val_unit; -} - -/* Reshape an array: change dimensions and number of dimensions, preserving - array contents */ - -CAMLprim value bigarray_reshape(value vb, value vdim) -{ - CAMLparam2 (vb, vdim); - CAMLlocal1 (res); - #define b ((struct caml_bigarray *) Bigarray_val(vb)) - long dim[MAX_NUM_DIMS]; - mlsize_t num_dims; - unsigned long num_elts; - int i; - - num_dims = Wosize_val(vdim); - if (num_dims < 1 || num_dims > MAX_NUM_DIMS) - invalid_argument("Bigarray.reshape: bad number of dimensions"); - num_elts = 1; - for (i = 0; i < num_dims; i++) { - dim[i] = Long_val(Field(vdim, i)); - if (dim[i] < 0 || dim[i] > 0x7FFFFFFFL) - invalid_argument("Bigarray.reshape: negative dimension"); - num_elts *= dim[i]; - } - /* Check that sizes agree */ - if (num_elts != bigarray_num_elts(b)) - invalid_argument("Bigarray.reshape: size mismatch"); - /* Create bigarray with same data and new dimensions */ - res = alloc_bigarray(b->flags, num_dims, b->data, dim); - /* Create or update proxy in case of managed bigarray */ - bigarray_update_proxy(b, Bigarray_val(res)); - /* Return result */ - CAMLreturn (res); - - #undef b -} - -/* Initialization */ - -CAMLprim value bigarray_init(value unit) -{ - register_custom_operations(&bigarray_ops); - return Val_unit; -} diff --git a/otherlibs/bigarray/mmap_unix.c b/otherlibs/bigarray/mmap_unix.c deleted file mode 100644 index e0f649f920..0000000000 --- a/otherlibs/bigarray/mmap_unix.c +++ /dev/null @@ -1,117 +0,0 @@ -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ -/* */ -/* Copyright 2000 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id$ */ - -#include <stddef.h> -#include <string.h> -#include "bigarray.h" -#include "custom.h" -#include "fail.h" -#include "mlvalues.h" -#include "sys.h" - -extern int bigarray_element_size[]; /* from bigarray_stubs.c */ - -#ifdef HAS_UNISTD -#include <unistd.h> -#endif -#ifdef HAS_MMAP -#include <sys/types.h> -#include <sys/mman.h> -#endif - -#if defined(HAS_MMAP) - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *) -1) -#endif - -CAMLprim value bigarray_map_file(value vfd, value vkind, value vlayout, - value vshared, value vdim) -{ - int fd, flags, major_dim, shared; - long num_dims, i; - long dim[MAX_NUM_DIMS]; - long currpos, file_size; - unsigned long array_size; - char c; - void * addr; - - fd = Int_val(vfd); - flags = Int_val(vkind) | Int_val(vlayout); - num_dims = Wosize_val(vdim); - major_dim = flags & BIGARRAY_FORTRAN_LAYOUT ? num_dims - 1 : 0; - /* Extract dimensions from Caml array */ - num_dims = Wosize_val(vdim); - if (num_dims < 1 || num_dims > MAX_NUM_DIMS) - invalid_argument("Bigarray.mmap: bad number of dimensions"); - for (i = 0; i < num_dims; i++) { - dim[i] = Long_val(Field(vdim, i)); - if (dim[i] == -1 && i == major_dim) continue; - if (dim[i] < 0 || dim[i] > 0x7FFFFFFFL) - invalid_argument("Bigarray.create: negative dimension"); - } - /* Determine file size */ - currpos = lseek(fd, 0, SEEK_CUR); - if (currpos == -1) sys_error(NO_ARG); - file_size = lseek(fd, 0, SEEK_END); - if (file_size == -1) sys_error(NO_ARG); - /* Determine array size in bytes (or size of array without the major - dimension if that dimension wasn't specified) */ - array_size = bigarray_element_size[flags & BIGARRAY_KIND_MASK]; - for (i = 0; i < num_dims; i++) - if (dim[i] != -1) array_size *= dim[i]; - /* Check if the first/last dimension is unknown */ - if (dim[major_dim] == -1) { - /* Determine first/last dimension from file size */ - if ((unsigned long) file_size % array_size != 0) - failwith("Bigarray.mmap: file size doesn't match array dimensions"); - dim[major_dim] = (unsigned long) file_size / array_size; - array_size = file_size; - } else { - /* Check that file is large enough, and grow it otherwise */ - if (file_size < array_size) { - if (lseek(fd, array_size - 1, SEEK_SET) == -1) sys_error(NO_ARG); - c = 0; - if (write(fd, &c, 1) != 1) sys_error(NO_ARG); - } - } - /* Restore original file position */ - lseek(fd, currpos, SEEK_SET); - /* Do the mmap */ - shared = Bool_val(vshared) ? MAP_SHARED : MAP_PRIVATE; - addr = mmap(NULL, array_size, PROT_READ | PROT_WRITE, shared, fd, 0); - if (addr == (void *) MAP_FAILED) sys_error(NO_ARG); - /* Build and return the Caml bigarray */ - return alloc_bigarray(flags | BIGARRAY_MAPPED_FILE, num_dims, addr, dim); -} - -#else - -value bigarray_map_file(value vfd, value vkind, value vlayout, - value vshared, value vdim) -{ - invalid_argument("Bigarray.map_file: not supported"); - return Val_unit; -} - -#endif - - -void bigarray_unmap_file(void * addr, unsigned long len) -{ -#if defined(HAS_MMAP) - munmap(addr, len); -#endif -} diff --git a/otherlibs/bigarray/mmap_win32.c b/otherlibs/bigarray/mmap_win32.c deleted file mode 100644 index a3701611d7..0000000000 --- a/otherlibs/bigarray/mmap_win32.c +++ /dev/null @@ -1,116 +0,0 @@ -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt */ -/* */ -/* Copyright 2000 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id$ */ - -#include <stddef.h> -#include <stdio.h> -#include <string.h> -#include "bigarray.h" -#include "alloc.h" -#include "custom.h" -#include "fail.h" -#include "mlvalues.h" -#include "sys.h" -#include "unixsupport.h" - -extern int bigarray_element_size[]; /* from bigarray_stubs.c */ - -static void bigarray_sys_error(void); - -CAMLprim value bigarray_map_file(value vfd, value vkind, value vlayout, - value vshared, value vdim) -{ - HANDLE fd, fmap; - int flags, major_dim, mode, perm; - long num_dims, i; - long dim[MAX_NUM_DIMS]; - long currpos, file_size; - unsigned long array_size; - char c; - void * addr; - - fd = Handle_val(vfd); - flags = Int_val(vkind) | Int_val(vlayout); - num_dims = Wosize_val(vdim); - major_dim = flags & BIGARRAY_FORTRAN_LAYOUT ? num_dims - 1 : 0; - /* Extract dimensions from Caml array */ - num_dims = Wosize_val(vdim); - if (num_dims < 1 || num_dims > MAX_NUM_DIMS) - invalid_argument("Bigarray.mmap: bad number of dimensions"); - for (i = 0; i < num_dims; i++) { - dim[i] = Long_val(Field(vdim, i)); - if (dim[i] == -1 && i == major_dim) continue; - if (dim[i] < 0 || dim[i] > 0x7FFFFFFFL) - invalid_argument("Bigarray.create: negative dimension"); - } - /* Determine file size */ - currpos = SetFilePointer(fd, 0, NULL, FILE_CURRENT); - if (currpos == -1) bigarray_sys_error(); - file_size = SetFilePointer(fd, 0, NULL, FILE_END); - if (file_size == -1) bigarray_sys_error(); - /* Determine array size in bytes (or size of array without the major - dimension if that dimension wasn't specified) */ - array_size = bigarray_element_size[flags & BIGARRAY_KIND_MASK]; - for (i = 0; i < num_dims; i++) - if (dim[i] != -1) array_size *= dim[i]; - /* Check if the first/last dimension is unknown */ - if (dim[major_dim] == -1) { - /* Determine first/last dimension from file size */ - if ((unsigned long) file_size % array_size != 0) - failwith("Bigarray.mmap: file size doesn't match array dimensions"); - dim[major_dim] = (unsigned long) file_size / array_size; - array_size = file_size; - } - /* Restore original file position */ - SetFilePointer(fd, currpos, NULL, FILE_BEGIN); - /* Create the file mapping */ - if (Bool_val(vshared)) { - perm = PAGE_READWRITE; - mode = FILE_MAP_WRITE; - } else { - perm = PAGE_READONLY; /* doesn't work under Win98 */ - mode = FILE_MAP_COPY; - } - fmap = CreateFileMapping(fd, NULL, perm, 0, array_size, NULL); - if (fmap == NULL) bigarray_sys_error(); - /* Map the mapping in memory */ - addr = MapViewOfFile(fmap, mode, 0, 0, array_size); - if (addr == NULL) bigarray_sys_error(); - /* Close the file mapping */ - CloseHandle(fmap); - /* Build and return the Caml bigarray */ - return alloc_bigarray(flags | BIGARRAY_MAPPED_FILE, num_dims, addr, dim); -} - -void bigarray_unmap_file(void * addr, unsigned long len) -{ - UnmapViewOfFile(addr); -} - -static void bigarray_sys_error(void) -{ - char buffer[512]; - unsigned long errnum; - - errnum = GetLastError(); - if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - errnum, - 0, - buffer, - sizeof(buffer), - NULL)) - sprintf(buffer, "Unknown error %ld\n", errnum); - raise_sys_error(copy_string(buffer)); -} |
