From b7a0933e08f73ccbc255fbac847c8b0d5b0282a4 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 10 Jul 2024 11:17:05 +0200 Subject: [PATCH] [FSharpMath] Add log2int --- src/Aardvark.Base.FSharp/Math/Math.fs | 18 +++ src/Aardvark.Base/AlgoDat/Meta.cs | 1 + src/Aardvark.Base/Math/Vectors/Vector_auto.cs | 150 ++++++++++++++++++ 3 files changed, 169 insertions(+) diff --git a/src/Aardvark.Base.FSharp/Math/Math.fs b/src/Aardvark.Base.FSharp/Math/Math.fs index 470310ed..4a5d1383 100644 --- a/src/Aardvark.Base.FSharp/Math/Math.fs +++ b/src/Aardvark.Base.FSharp/Math/Math.fs @@ -123,6 +123,9 @@ module FSharpMath = let inline log2Aux (_ : ^Z) (x : ^T) = ((^Z or ^T) : (static member Log2 : ^T -> ^T) x) + let inline log2intAux (_ : ^Z) (x : ^T) = + ((^Z or ^T) : (static member Log2Int : ^T -> ^U) x) + let inline asinhAux (_ : ^Z) (x : ^T) = ((^Z or ^T) : (static member Asinh : ^T -> ^T) x) @@ -230,6 +233,10 @@ module FSharpMath = let inline log2 x = log2Aux Unchecked.defaultof x + /// Returns the base 2 logarithm of x rounded to the next integer towards negative infinity. + let inline log2int x = + log2intAux Unchecked.defaultof x + /// Returns the inverse hyperbolic sine of x. let inline asinh x = asinhAux Unchecked.defaultof x @@ -338,6 +345,7 @@ module FSharpMath = static member Log(h : MyCustomNumericTypeExtensionTestTypeForInternalTesting) = h static member Log2(h : MyCustomNumericTypeExtensionTestTypeForInternalTesting) = h + static member Log2Int(h : MyCustomNumericTypeExtensionTestTypeForInternalTesting) = 0 static member Acosh(h : MyCustomNumericTypeExtensionTestTypeForInternalTesting) = h static member Asinh(h : MyCustomNumericTypeExtensionTestTypeForInternalTesting) = h @@ -598,6 +606,16 @@ module FSharpMath = let a : MyCustomNumericTypeExtensionTestTypeForInternalTesting = indirectLog2 (MyCustomNumericTypeExtensionTestTypeForInternalTesting()) () + let inline indirectLog2int (x : ^T) = + log2int x + + let log2intWorking() = + let a : int = log2int 10.0 + let a : V2i = log2int V2d.II + let a : int = log2int (MyCustomNumericTypeExtensionTestTypeForInternalTesting()) + let a : int = indirectLog2int (MyCustomNumericTypeExtensionTestTypeForInternalTesting()) + () + let acoshWorking() = let a : float = acosh 1.0 let a : float32 = acosh 1.0f diff --git a/src/Aardvark.Base/AlgoDat/Meta.cs b/src/Aardvark.Base/AlgoDat/Meta.cs index dded17db..a23f2886 100644 --- a/src/Aardvark.Base/AlgoDat/Meta.cs +++ b/src/Aardvark.Base/AlgoDat/Meta.cs @@ -1219,6 +1219,7 @@ SimpleType[] OnlySigned() Method("Log", DoubleType, NotReal(), Tensor("x")), Method("Log2", RealTypes, Tensor("x")), Method("Log2", DoubleType, NotReal(), Tensor("x")), + Method("Log2Int", IntType, Tensor("x")), Method("Log10", RealTypes, Tensor("x")), Method("Log10", DoubleType, NotReal(), Tensor("x")), Method("Log", RealTypes, Tensor("x"), Scalar("basis")), diff --git a/src/Aardvark.Base/Math/Vectors/Vector_auto.cs b/src/Aardvark.Base/Math/Vectors/Vector_auto.cs index c34267fe..24ac88ae 100644 --- a/src/Aardvark.Base/Math/Vectors/Vector_auto.cs +++ b/src/Aardvark.Base/Math/Vectors/Vector_auto.cs @@ -4091,6 +4091,16 @@ public static V2d Log2(this V2i x) return new V2d(Log2(x.X), Log2(x.Y)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V2i Log2Int(this V2i x) + { + return new V2i(Log2Int(x.X), Log2Int(x.Y)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -8217,6 +8227,16 @@ public static V2d Log2(this V2ui x) return new V2d(Log2(x.X), Log2(x.Y)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V2i Log2Int(this V2ui x) + { + return new V2i(Log2Int(x.X), Log2Int(x.Y)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -13402,6 +13422,16 @@ public static V2d Log2(this V2l x) return new V2d(Log2(x.X), Log2(x.Y)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V2i Log2Int(this V2l x) + { + return new V2i(Log2Int(x.X), Log2Int(x.Y)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -19050,6 +19080,16 @@ public static V2f Log2(this V2f x) return new V2f(Log2(x.X), Log2(x.Y)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V2i Log2Int(this V2f x) + { + return new V2i(Log2Int(x.X), Log2Int(x.Y)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -25287,6 +25327,16 @@ public static V2d Log2(this V2d x) return new V2d(Log2(x.X), Log2(x.Y)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V2i Log2Int(this V2d x) + { + return new V2i(Log2Int(x.X), Log2Int(x.Y)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -33920,6 +33970,16 @@ public static V3d Log2(this V3i x) return new V3d(Log2(x.X), Log2(x.Y), Log2(x.Z)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V3i Log2Int(this V3i x) + { + return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -39933,6 +39993,16 @@ public static V3d Log2(this V3ui x) return new V3d(Log2(x.X), Log2(x.Y), Log2(x.Z)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V3i Log2Int(this V3ui x) + { + return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -48013,6 +48083,16 @@ public static V3d Log2(this V3l x) return new V3d(Log2(x.X), Log2(x.Y), Log2(x.Z)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V3i Log2Int(this V3l x) + { + return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -56828,6 +56908,16 @@ public static V3f Log2(this V3f x) return new V3f(Log2(x.X), Log2(x.Y), Log2(x.Z)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V3i Log2Int(this V3f x) + { + return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -66243,6 +66333,16 @@ public static V3d Log2(this V3d x) return new V3d(Log2(x.X), Log2(x.Y), Log2(x.Z)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V3i Log2Int(this V3d x) + { + return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -79527,6 +79627,16 @@ public static V4d Log2(this V4i x) return new V4d(Log2(x.X), Log2(x.Y), Log2(x.Z), Log2(x.W)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V4i Log2Int(this V4i x) + { + return new V4i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z), Log2Int(x.W)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -88559,6 +88669,16 @@ public static V4d Log2(this V4ui x) return new V4d(Log2(x.X), Log2(x.Y), Log2(x.Z), Log2(x.W)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V4i Log2Int(this V4ui x) + { + return new V4i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z), Log2Int(x.W)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -101233,6 +101353,16 @@ public static V4d Log2(this V4l x) return new V4d(Log2(x.X), Log2(x.Y), Log2(x.Z), Log2(x.W)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V4i Log2Int(this V4l x) + { + return new V4i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z), Log2Int(x.W)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -114510,6 +114640,16 @@ public static V4f Log2(this V4f x) return new V4f(Log2(x.X), Log2(x.Y), Log2(x.Z), Log2(x.W)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V4i Log2Int(this V4f x) + { + return new V4i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z), Log2Int(x.W)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). /// @@ -128259,6 +128399,16 @@ public static V4d Log2(this V4d x) return new V4d(Log2(x.X), Log2(x.Y), Log2(x.Z), Log2(x.W)); } + /// + /// Applies Fun.Log2Int to each element of the given vector(s). + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static V4i Log2Int(this V4d x) + { + return new V4i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z), Log2Int(x.W)); + } + /// /// Applies Fun.Log10 to each element of the given vector(s). ///