Source file owl_numdiff_generic_sig.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 1 "src/base/optimise/owl_numdiff_generic_sig.ml"
(*
 * OWL - OCaml Scientific Computing
 * Copyright (c) 2016-2022 Liang Wang <liang@ocaml.xyz>
 *)

(** Numdiff: numerical differentiation module *)

open Owl_types

(** The functor used to generate Numdiff module of various precisions. *)

(* TODO: unit test *)

module type Sig = sig
  (** {5 Type definition} *)

  type arr
  (** General ndarray type *)

  type elt
  (** Scalar type *)

  (** {5 Basic functions} *)

  val diff : (elt -> elt) -> elt -> elt
  (** derivative of [f : scalar -> scalar]. *)

  val diff' : (elt -> elt) -> elt -> elt * elt
  (** derivative of [f : scalar -> scalar], return both [f x] and [f' x]. *)

  val diff2 : (elt -> elt) -> elt -> elt
  (** second order derivative of [f : float -> float]. *)

  val diff2' : (elt -> elt) -> elt -> elt * elt
  (** second order derivative of [f : float -> float], return [f x] and [f' x]. *)

  val grad : (arr -> elt) -> arr -> arr
  (** gradient of [f : vector -> scalar]. *)

  val grad' : (arr -> elt) -> arr -> arr * arr
  (** gradient of [f : vector -> scalar], return [f x] and [g x]. *)

  val jacobian : (arr -> arr) -> arr -> arr
  (** jacobian of [f : vector -> vector]. *)

  val jacobian' : (arr -> arr) -> arr -> arr * arr
  (** jacobian of [f : vector -> vector], return [f x] and [j x]. *)

  val jacobianT : (arr -> arr) -> arr -> arr
  (** transposed jacobian of [f : vector -> vector]. *)

  val jacobianT' : (arr -> arr) -> arr -> arr * arr
  (** transposed jacobian of [f : vector -> vector], return [f x] and [j x]. *)
end

(* This is a dumb module for checking the module signature. *)

module Impl (A : Ndarray_Numdiff with type elt = float) : Sig =
  Owl_numdiff_generic.Make (A)