Skip to content

Commit

Permalink
[FSharpMath] Add log2int
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Jul 10, 2024
1 parent 4d2a564 commit b7a0933
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Aardvark.Base.FSharp/Math/Math.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -230,6 +233,10 @@ module FSharpMath =
let inline log2 x =
log2Aux Unchecked.defaultof<Fun> x

/// Returns the base 2 logarithm of x rounded to the next integer towards negative infinity.
let inline log2int x =
log2intAux Unchecked.defaultof<Fun> x

/// Returns the inverse hyperbolic sine of x.
let inline asinh x =
asinhAux Unchecked.defaultof<Fun> x
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Aardvark.Base/AlgoDat/Meta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
150 changes: 150 additions & 0 deletions src/Aardvark.Base/Math/Vectors/Vector_auto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4091,6 +4091,16 @@ public static V2d Log2(this V2i x)
return new V2d(Log2(x.X), Log2(x.Y));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V2i Log2Int(this V2i x)
{
return new V2i(Log2Int(x.X), Log2Int(x.Y));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -8217,6 +8227,16 @@ public static V2d Log2(this V2ui x)
return new V2d(Log2(x.X), Log2(x.Y));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V2i Log2Int(this V2ui x)
{
return new V2i(Log2Int(x.X), Log2Int(x.Y));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -13402,6 +13422,16 @@ public static V2d Log2(this V2l x)
return new V2d(Log2(x.X), Log2(x.Y));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V2i Log2Int(this V2l x)
{
return new V2i(Log2Int(x.X), Log2Int(x.Y));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -19050,6 +19080,16 @@ public static V2f Log2(this V2f x)
return new V2f(Log2(x.X), Log2(x.Y));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V2i Log2Int(this V2f x)
{
return new V2i(Log2Int(x.X), Log2Int(x.Y));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -25287,6 +25327,16 @@ public static V2d Log2(this V2d x)
return new V2d(Log2(x.X), Log2(x.Y));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V2i Log2Int(this V2d x)
{
return new V2i(Log2Int(x.X), Log2Int(x.Y));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -33920,6 +33970,16 @@ public static V3d Log2(this V3i x)
return new V3d(Log2(x.X), Log2(x.Y), Log2(x.Z));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V3i Log2Int(this V3i x)
{
return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -39933,6 +39993,16 @@ public static V3d Log2(this V3ui x)
return new V3d(Log2(x.X), Log2(x.Y), Log2(x.Z));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V3i Log2Int(this V3ui x)
{
return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -48013,6 +48083,16 @@ public static V3d Log2(this V3l x)
return new V3d(Log2(x.X), Log2(x.Y), Log2(x.Z));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V3i Log2Int(this V3l x)
{
return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -56828,6 +56908,16 @@ public static V3f Log2(this V3f x)
return new V3f(Log2(x.X), Log2(x.Y), Log2(x.Z));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V3i Log2Int(this V3f x)
{
return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -66243,6 +66333,16 @@ public static V3d Log2(this V3d x)
return new V3d(Log2(x.X), Log2(x.Y), Log2(x.Z));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V3i Log2Int(this V3d x)
{
return new V3i(Log2Int(x.X), Log2Int(x.Y), Log2Int(x.Z));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -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));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[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));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -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));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[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));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -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));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[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));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -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));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[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));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down Expand Up @@ -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));
}

/// <summary>
/// Applies Fun.Log2Int to each element of the given vector(s).
/// </summary>
[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));
}

/// <summary>
/// Applies Fun.Log10 to each element of the given vector(s).
/// </summary>
Expand Down

0 comments on commit b7a0933

Please sign in to comment.