From 0df0a9f8df27b95d52a7afd7ba9fe96018e74c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E7=A7=80=E7=85=8C?= Date: Thu, 14 Aug 2025 11:09:53 +0800 Subject: [PATCH 1/4] math4 --- math4/_demo/go.mod | 10 ++ math4/_demo/go.sum | 2 + math4/_demo/main.go | 29 ++++ math4/go.mod | 5 + math4/llpkg.cfg | 16 +++ math4/llpyg.cfg | 123 ++++++++++++++++ math4/math.go | 280 +++++++++++++++++++++++++++++++++++++ math4/math_autogen_link.go | 5 + 8 files changed, 470 insertions(+) create mode 100644 math4/_demo/go.mod create mode 100644 math4/_demo/go.sum create mode 100644 math4/_demo/main.go create mode 100644 math4/go.mod create mode 100644 math4/llpkg.cfg create mode 100644 math4/llpyg.cfg create mode 100644 math4/math.go create mode 100644 math4/math_autogen_link.go diff --git a/math4/_demo/go.mod b/math4/_demo/go.mod new file mode 100644 index 00000000..46f5f92f --- /dev/null +++ b/math4/_demo/go.mod @@ -0,0 +1,10 @@ +module test_math3 + +go 1.24.5 + +replace github.com/goplus/llpkg/math => ../ + +require ( + github.com/goplus/lib v0.2.0 + github.com/goplus/llpkg/math v0.0.0-00010101000000-000000000000 +) diff --git a/math4/_demo/go.sum b/math4/_demo/go.sum new file mode 100644 index 00000000..512980a5 --- /dev/null +++ b/math4/_demo/go.sum @@ -0,0 +1,2 @@ +github.com/goplus/lib v0.2.0 h1:AjqkN1XK5H23wZMMlpaUYAMCDAdSBQ2NMFrLtSh7W4g= +github.com/goplus/lib v0.2.0/go.mod h1:SgJv3oPqLLHCu0gcL46ejOP3x7/2ry2Jtxu7ta32kp0= diff --git a/math4/_demo/main.go b/math4/_demo/main.go new file mode 100644 index 00000000..023355a1 --- /dev/null +++ b/math4/_demo/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "github.com/goplus/lib/py" + "github.com/goplus/lib/py/std" + "github.com/goplus/llpkg/math" +) + +func main() { + // 初始化 Python + py.Initialize() + defer py.Finalize() + + // 测试 math.Sqrt + result1 := math.Sqrt(py.Float(4.0)) + std.Print(py.Str("sqrt(4) = "), result1) + + // 测试 math.Cos + result2 := math.Cos(py.Float(0.0)) + std.Print(py.Str("cos(0) = "), result2) + + // 测试 math.Pow + result3 := math.Pow(py.Float(2.0), py.Float(3.0)) + std.Print(py.Str("2^3 = "), result3) + + // 测试 math.Sin + result4 := math.Sin(py.Float(1.57)) // 接近 pi/2 + std.Print(py.Str("sin(1.57) = "), result4) +} diff --git a/math4/go.mod b/math4/go.mod new file mode 100644 index 00000000..7d6e6402 --- /dev/null +++ b/math4/go.mod @@ -0,0 +1,5 @@ +module github.com/goplus/llpkg/math + +go 1.23 + +require github.com/goplus/lib v0.2.0 diff --git a/math4/llpkg.cfg b/math4/llpkg.cfg new file mode 100644 index 00000000..dd565d41 --- /dev/null +++ b/math4/llpkg.cfg @@ -0,0 +1,16 @@ +{ + "type": "python", + "upstream": { + "installer": { + "name": "pip", + "config": { + "python_version": "3.12", + "index_url": "https://pypi.org/simple/" + } + }, + "package": { + "name": "math", + "version": "builtin" + } + } +} \ No newline at end of file diff --git a/math4/llpyg.cfg b/math4/llpyg.cfg new file mode 100644 index 00000000..94275e92 --- /dev/null +++ b/math4/llpyg.cfg @@ -0,0 +1,123 @@ +{ + "name": "math", + "module": "math", + "python": true, + "symMap": { + "abs": "Abs", + "acos": "Acos", + "acosh": "Acosh", + "all": "All", + "any": "Any", + "asin": "Asin", + "asinh": "Asinh", + "atan": "Atan", + "atan2": "Atan2", + "atanh": "Atanh", + "bin": "Bin", + "bool": "Bool", + "cbrt": "Cbrt", + "ceil": "Ceil", + "chr": "Chr", + "comb": "Comb", + "copysign": "Copysign", + "cos": "Cos", + "cosh": "Cosh", + "degrees": "Degrees", + "dict": "Dict", + "dir": "Dir", + "dist": "Dist", + "enumerate": "Enumerate", + "erf": "Erf", + "erfc": "Erfc", + "exp": "Exp", + "exp2": "Exp2", + "expm1": "Expm1", + "fabs": "Fabs", + "factorial": "Factorial", + "filter": "Filter", + "float": "Float", + "floor": "Floor", + "fmod": "Fmod", + "format": "Format", + "frexp": "Frexp", + "frozenset": "FrozenSet", + "fsum": "Fsum", + "gamma": "Gamma", + "gcd": "Gcd", + "getattr": "GetAttr", + "hasattr": "HasAttr", + "hash": "Hash", + "help": "Help", + "hex": "Hex", + "id": "ID", + "input": "Input", + "int": "Int", + "isinstance": "IsInstance", + "issubclass": "IsSubclass", + "iter": "Iter", + "len": "Len", + "list": "List", + "locals": "Locals", + "log10": "Log10", + "log2": "Log2", + "map": "Map", + "max": "Max", + "min": "Min", + "modf": "Modf", + "next": "Next", + "nextafter": "Nextafter", + "oct": "Oct", + "open": "Open", + "ord": "Ord", + "perm": "Perm", + "pow": "Pow", + "print": "Print", + "prod": "Prod", + "radians": "Radians", + "range": "Range", + "remainder": "Remainder", + "repr": "Repr", + "reversed": "Reversed", + "round": "Round", + "set": "Set", + "setattr": "SetAttr", + "sin": "Sin", + "sinh": "Sinh", + "sorted": "Sorted", + "sqrt": "Sqrt", + "str": "Str", + "sum": "Sum", + "sumprod": "Sumprod", + "tan": "Tan", + "tanh": "Tanh", + "trunc": "Trunc", + "tuple": "Tuple", + "type": "Type", + "ulp": "Ulp", + "vars": "Vars", + "zip": "Zip" + }, + "deps": [ + "py" + ], + "include": [ + "math" + ], + "exclude": [ + "__builtins__", + "__cached__", + "__doc__", + "__file__", + "__loader__", + "__name__", + "__package__", + "__spec__" + ], + "constants": { + "e": "E", + "inf": "Inf", + "nan": "NaN", + "pi": "Pi", + "tau": "Tau" + } +} \ No newline at end of file diff --git a/math4/math.go b/math4/math.go new file mode 100644 index 00000000..e497df6e --- /dev/null +++ b/math4/math.go @@ -0,0 +1,280 @@ +package math + +import ( + "github.com/goplus/lib/py" + _ "unsafe" +) + +const LLGoPackage = "py.math" +// Return the arc cosine (measured in radians) of x. +// +// The result is between 0 and pi. +// +//go:linkname Acos py.acos +func Acos(x *py.Object) *py.Object +// Return the inverse hyperbolic cosine of x. +// +//go:linkname Acosh py.acosh +func Acosh(x *py.Object) *py.Object +// Return the arc sine (measured in radians) of x. +// +// The result is between -pi/2 and pi/2. +// +//go:linkname Asin py.asin +func Asin(x *py.Object) *py.Object +// Return the inverse hyperbolic sine of x. +// +//go:linkname Asinh py.asinh +func Asinh(x *py.Object) *py.Object +// Return the arc tangent (measured in radians) of x. +// +// The result is between -pi/2 and pi/2. +// +//go:linkname Atan py.atan +func Atan(x *py.Object) *py.Object +// Return the arc tangent (measured in radians) of y/x. +// +// Unlike atan(y/x), the signs of both x and y are considered. +// +//go:linkname Atan2 py.atan2 +func Atan2(y *py.Object, x *py.Object) *py.Object +// Return the inverse hyperbolic tangent of x. +// +//go:linkname Atanh py.atanh +func Atanh(x *py.Object) *py.Object +// Return the cube root of x. +// +//go:linkname Cbrt py.cbrt +func Cbrt(x *py.Object) *py.Object +// Return the ceiling of x as an Integral. +// +// This is the smallest integer >= x. +// +//go:linkname Ceil py.ceil +func Ceil(x *py.Object) *py.Object +// Return a float with the magnitude (absolute value) of x but the sign of y. +// +// On platforms that support signed zeros, copysign(1.0, -0.0) +// returns -1.0. +// +// +//go:linkname Copysign py.copysign +func Copysign(x *py.Object, y *py.Object) *py.Object +// Return the cosine of x (measured in radians). +// +//go:linkname Cos py.cos +func Cos(x *py.Object) *py.Object +// Return the hyperbolic cosine of x. +// +//go:linkname Cosh py.cosh +func Cosh(x *py.Object) *py.Object +// Convert angle x from radians to degrees. +// +//go:linkname Degrees py.degrees +func Degrees(x *py.Object) *py.Object +// Return the Euclidean distance between two points p and q. +// +// The points should be specified as sequences (or iterables) of +// coordinates. Both inputs must have the same dimension. +// +// Roughly equivalent to: +// sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q))) +// +//go:linkname Dist py.dist +func Dist(p *py.Object, q *py.Object) *py.Object +// Error function at x. +// +//go:linkname Erf py.erf +func Erf(x *py.Object) *py.Object +// Complementary error function at x. +// +//go:linkname Erfc py.erfc +func Erfc(x *py.Object) *py.Object +// Return e raised to the power of x. +// +//go:linkname Exp py.exp +func Exp(x *py.Object) *py.Object +// Return 2 raised to the power of x. +// +//go:linkname Exp2 py.exp2 +func Exp2(x *py.Object) *py.Object +// Return exp(x)-1. +// +// This function avoids the loss of precision involved in the direct evaluation of exp(x)-1 for small x. +// +//go:linkname Expm1 py.expm1 +func Expm1(x *py.Object) *py.Object +// Return the absolute value of the float x. +// +//go:linkname Fabs py.fabs +func Fabs(x *py.Object) *py.Object +// Find n!. +// +// Raise a ValueError if x is negative or non-integral. +// +//go:linkname Factorial py.factorial +func Factorial(n *py.Object) *py.Object +// Return the floor of x as an Integral. +// +// This is the largest integer <= x. +// +//go:linkname Floor py.floor +func Floor(x *py.Object) *py.Object +// Return fmod(x, y), according to platform C. +// +// x % y may differ. +// +//go:linkname Fmod py.fmod +func Fmod(x *py.Object, y *py.Object) *py.Object +// Return the mantissa and exponent of x, as pair (m, e). +// +// m is a float and e is an int, such that x = m * 2.**e. +// If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0. +// +//go:linkname Frexp py.frexp +func Frexp(x *py.Object) *py.Object +// Return an accurate floating-point sum of values in the iterable seq. +// +// Assumes IEEE-754 floating-point arithmetic. +// +//go:linkname Fsum py.fsum +func Fsum(seq *py.Object) *py.Object +// Gamma function at x. +// +//go:linkname Gamma py.gamma +func Gamma(x *py.Object) *py.Object +// Greatest Common Divisor. +// +//go:linkname Gcd py.gcd +func Gcd(__llgo_va_list ...interface{}) *py.Object +// Return the integer part of the square root of the input. +// +//go:linkname Isqrt py.isqrt +func Isqrt(n *py.Object) *py.Object +// Least Common Multiple. +// +//go:linkname Lcm py.lcm +func Lcm(__llgo_va_list ...interface{}) *py.Object +// Return x * (2**i). +// +// This is essentially the inverse of frexp(). +// +//go:linkname Ldexp py.ldexp +func Ldexp(x *py.Object, i *py.Object) *py.Object +// Natural logarithm of absolute value of Gamma function at x. +// +//go:linkname Lgamma py.lgamma +func Lgamma(x *py.Object) *py.Object +// Return the base 2 logarithm of x. +// +//go:linkname Log2 py.log2 +func Log2(x *py.Object) *py.Object +// Return the fractional and integer parts of x. +// +// Both results carry the sign of x and are floats. +// +//go:linkname Modf py.modf +func Modf(x *py.Object) *py.Object +// Return x**y (x to the power of y). +// +//go:linkname Pow py.pow +func Pow(x *py.Object, y *py.Object) *py.Object +// Convert angle x from degrees to radians. +// +//go:linkname Radians py.radians +func Radians(x *py.Object) *py.Object +// Difference between x and the closest integer multiple of y. +// +// Return x - n*y where n*y is the closest integer multiple of y. +// In the case where x is exactly halfway between two multiples of +// y, the nearest even value of n is used. The result is always exact. +// +//go:linkname Remainder py.remainder +func Remainder(x *py.Object, y *py.Object) *py.Object +// Return the sine of x (measured in radians). +// +//go:linkname Sin py.sin +func Sin(x *py.Object) *py.Object +// Return the hyperbolic sine of x. +// +//go:linkname Sinh py.sinh +func Sinh(x *py.Object) *py.Object +// Return the square root of x. +// +//go:linkname Sqrt py.sqrt +func Sqrt(x *py.Object) *py.Object +// Return the tangent of x (measured in radians). +// +//go:linkname Tan py.tan +func Tan(x *py.Object) *py.Object +// Return the hyperbolic tangent of x. +// +//go:linkname Tanh py.tanh +func Tanh(x *py.Object) *py.Object +// Return the sum of products of values from two iterables p and q. +// +// Roughly equivalent to: +// +// sum(itertools.starmap(operator.mul, zip(p, q, strict=True))) +// +// For float and mixed int/float inputs, the intermediate products +// and sums are computed with extended precision. +// +//go:linkname Sumprod py.sumprod +func Sumprod(p *py.Object, q *py.Object) *py.Object +// Truncates the Real x to the nearest Integral toward 0. +// +// Uses the __trunc__ magic method. +// +//go:linkname Trunc py.trunc +func Trunc(x *py.Object) *py.Object +// Calculate the product of all the elements in the input iterable. +// +// The default start value for the product is 1. +// +// When the iterable is empty, return the start value. This function is +// intended specifically for use with numeric values and may reject +// non-numeric types. +// +//go:linkname Prod py.prod +func Prod(iterable *py.Object) *py.Object +// Number of ways to choose k items from n items without repetition and with order. +// +// Evaluates to n! / (n - k)! when k <= n and evaluates +// to zero when k > n. +// +// If k is not specified or is None, then k defaults to n +// and the function returns n!. +// +// Raises TypeError if either of the arguments are not integers. +// Raises ValueError if either of the arguments are negative. +// +//go:linkname Perm py.perm +func Perm(n *py.Object, k *py.Object) *py.Object +// Number of ways to choose k items from n items without repetition and without order. +// +// Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates +// to zero when k > n. +// +// Also called the binomial coefficient because it is equivalent +// to the coefficient of k-th term in polynomial expansion of the +// expression (1 + x)**n. +// +// Raises TypeError if either of the arguments are not integers. +// Raises ValueError if either of the arguments are negative. +// +//go:linkname Comb py.comb +func Comb(n *py.Object, k *py.Object) *py.Object +// Return the floating-point value the given number of steps after x towards y. +// +// If steps is not specified or is None, it defaults to 1. +// +// Raises a TypeError, if x or y is not a double, or if steps is not an integer. +// Raises ValueError if steps is negative. +// +//go:linkname Nextafter py.nextafter +func Nextafter(x *py.Object, y *py.Object) *py.Object +// Return the value of the least significant bit of the float x. +// +//go:linkname Ulp py.ulp +func Ulp(x *py.Object) *py.Object diff --git a/math4/math_autogen_link.go b/math4/math_autogen_link.go new file mode 100644 index 00000000..1f657e14 --- /dev/null +++ b/math4/math_autogen_link.go @@ -0,0 +1,5 @@ +package math + +import _ "github.com/goplus/lib/py" + +// LLGoPackage is defined in the main binding file From 0511864d410baaa4246901146615fcfcb48dde68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E7=A7=80=E7=85=8C?= Date: Thu, 14 Aug 2025 12:01:53 +0800 Subject: [PATCH 2/4] math3 --- .DS_Store | Bin 0 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..59f99ee8aa6f5f1d7326b2a03473eb0fbe623fa7 GIT binary patch literal 6148 zcmeH~O-{ow5QU#hs}>Mamu!%7f=a*z($X#}0SkHo`hyB6G|(1=SY^*0xB};61#iX{ zBx$=v2+c_LOPn{h^C^jA0Iu^mIRu&j8Z4sK9ad{Xu1i^oN@&@mI_=}ApQPhal8#oq z)?fsTz~3Vv?`{nvyx<1+$iKhxNocdQJ~edeKhERan=a1x73Ua3%rV8H=yV5boVQpY z#jNCfEjjB*ILi^1^rlEk?vD-bXWTKbbZ3?6M)!j5WwCGN@Rs9H$0_9IcHm&ZsT+I4O>*T=RX^$@D>qEpb&I z*$LacyUHg(>6UsGs(BwzE&d4sd9E0ZU9VOf0V7}pz6r?pAz~4YgJxd!)4@u&0Msg* zHFzw)1CkR3je}-hd4=J8D%GdDu*Gmbo$XQZ#X&Q#J{>M>K3o{tg&m61(b<2bcDUH9 z)keSw6bWqk)26Kdz0LdoVv?O10VD9Q2)Jr@(CzS+!rHoWbF$V(ESD@2;>)~h3ahXj g>wzrA`z#u~7RdoM4w`vo3&VZ{6oXYp;8zKJ0mS8~00000 literal 0 HcmV?d00001 From dcbc62d40e61fac74a09bbdf63f680b259d5e888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E7=A7=80=E7=85=8C?= Date: Thu, 14 Aug 2025 13:44:45 +0800 Subject: [PATCH 3/4] ver1 --- .github/workflows/verification.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index 6ce255da..cef9e496 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -82,12 +82,13 @@ jobs: run: | sudo apt install -y python3 python3-pip python3 -m pip install --upgrade pip - python3 -m pip install conan pydump pysigfetch + python3 -m pip install conan pydump + go install github.com/goplus/hdq/chore/pysigfetch@v0.8.1 - name: Pre setup Python and Conan if: startsWith(matrix.os, 'macos') run: | - python3 -m pip install --upgrade pip --break-system-packages - python3 -m pip install conan pydump pysigfetch --break-system-packages + python3 -m pip install conan pydump --break-system-packages + go install github.com/goplus/hdq/chore/pysigfetch@v0.8.1 - name: Set up Conan run: | conan profile detect From 7ac4a7046310078cb49d42749cc5b3f3f3ecbebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E7=A7=80=E7=85=8C?= Date: Thu, 14 Aug 2025 13:56:24 +0800 Subject: [PATCH 4/4] verif --- .github/workflows/verification.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index cef9e496..42691884 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -139,4 +139,4 @@ jobs: - name: Run demotest process env: LLPKG_PATH: ${{ env.LLPKG_PATH }} - run: llpkgstore demotest \ No newline at end of file + run: llpkgstore demotest