Skip to content

Commit

Permalink
Move math to std.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnwpark committed Oct 7, 2024
1 parent e57ef8b commit dc3230d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 54 deletions.
80 changes: 40 additions & 40 deletions edb/lib/math.edgeql
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# limitations under the License.
#

CREATE MODULE math;
CREATE MODULE std::math;


CREATE FUNCTION
math::abs(x: std::anyreal) -> std::anyreal
std::math::abs(x: std::anyreal) -> std::anyreal
{
CREATE ANNOTATION std::description :=
'Return the absolute value of the input *x*.';
Expand All @@ -30,7 +30,7 @@ math::abs(x: std::anyreal) -> std::anyreal


CREATE FUNCTION
math::ceil(x: std::int64) -> std::int64
std::math::ceil(x: std::int64) -> std::int64
{
CREATE ANNOTATION std::description := 'Round up to the nearest integer.';
SET volatility := 'Immutable';
Expand All @@ -39,7 +39,7 @@ math::ceil(x: std::int64) -> std::int64


CREATE FUNCTION
math::ceil(x: std::float64) -> std::float64
std::math::ceil(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description := 'Round up to the nearest integer.';
SET volatility := 'Immutable';
Expand All @@ -48,7 +48,7 @@ math::ceil(x: std::float64) -> std::float64


CREATE FUNCTION
math::ceil(x: std::bigint) -> std::bigint
std::math::ceil(x: std::bigint) -> std::bigint
{
CREATE ANNOTATION std::description := 'Round up to the nearest integer.';
SET volatility := 'Immutable';
Expand All @@ -57,7 +57,7 @@ math::ceil(x: std::bigint) -> std::bigint


CREATE FUNCTION
math::ceil(x: std::decimal) -> std::decimal
std::math::ceil(x: std::decimal) -> std::decimal
{
CREATE ANNOTATION std::description := 'Round up to the nearest integer.';
SET volatility := 'Immutable';
Expand All @@ -66,7 +66,7 @@ math::ceil(x: std::decimal) -> std::decimal


CREATE FUNCTION
math::floor(x: std::int64) -> std::int64
std::math::floor(x: std::int64) -> std::int64
{
CREATE ANNOTATION std::description := 'Round down to the nearest integer.';
SET volatility := 'Immutable';
Expand All @@ -75,7 +75,7 @@ math::floor(x: std::int64) -> std::int64


CREATE FUNCTION
math::floor(x: std::float64) -> std::float64
std::math::floor(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description := 'Round down to the nearest integer.';
SET volatility := 'Immutable';
Expand All @@ -84,7 +84,7 @@ math::floor(x: std::float64) -> std::float64


CREATE FUNCTION
math::floor(x: std::bigint) -> std::bigint
std::math::floor(x: std::bigint) -> std::bigint
{
CREATE ANNOTATION std::description := 'Round down to the nearest integer.';
SET volatility := 'Immutable';
Expand All @@ -93,7 +93,7 @@ math::floor(x: std::bigint) -> std::bigint


CREATE FUNCTION
math::floor(x: std::decimal) -> std::decimal
std::math::floor(x: std::decimal) -> std::decimal
{
CREATE ANNOTATION std::description := 'Round down to the nearest integer.';
SET volatility := 'Immutable';
Expand All @@ -102,7 +102,7 @@ math::floor(x: std::decimal) -> std::decimal


CREATE FUNCTION
math::ln(x: std::int64) -> std::float64
std::math::ln(x: std::int64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the natural logarithm of the input value.';
Expand All @@ -112,7 +112,7 @@ math::ln(x: std::int64) -> std::float64


CREATE FUNCTION
math::ln(x: std::float64) -> std::float64
std::math::ln(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the natural logarithm of the input value.';
Expand All @@ -122,7 +122,7 @@ math::ln(x: std::float64) -> std::float64


CREATE FUNCTION
math::ln(x: std::decimal) -> std::decimal
std::math::ln(x: std::decimal) -> std::decimal
{
CREATE ANNOTATION std::description :=
'Return the natural logarithm of the input value.';
Expand All @@ -132,7 +132,7 @@ math::ln(x: std::decimal) -> std::decimal


CREATE FUNCTION
math::lg(x: std::int64) -> std::float64
std::math::lg(x: std::int64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the base 10 logarithm of the input value.';
Expand All @@ -142,7 +142,7 @@ math::lg(x: std::int64) -> std::float64


CREATE FUNCTION
math::lg(x: std::float64) -> std::float64
std::math::lg(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the base 10 logarithm of the input value.';
Expand All @@ -152,7 +152,7 @@ math::lg(x: std::float64) -> std::float64


CREATE FUNCTION
math::lg(x: std::decimal) -> std::decimal
std::math::lg(x: std::decimal) -> std::decimal
{
CREATE ANNOTATION std::description :=
'Return the base 10 logarithm of the input value.';
Expand All @@ -162,7 +162,7 @@ math::lg(x: std::decimal) -> std::decimal


CREATE FUNCTION
math::log(x: std::decimal, NAMED ONLY base: std::decimal) -> std::decimal
std::math::log(x: std::decimal, NAMED ONLY base: std::decimal) -> std::decimal
{
CREATE ANNOTATION std::description :=
'Return the logarithm of the input value in the specified *base*.';
Expand All @@ -174,7 +174,7 @@ math::log(x: std::decimal, NAMED ONLY base: std::decimal) -> std::decimal


CREATE FUNCTION
math::sqrt(x: std::int64) -> std::float64
std::math::sqrt(x: std::int64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the square root of the input value.';
Expand All @@ -184,7 +184,7 @@ math::sqrt(x: std::int64) -> std::float64


CREATE FUNCTION
math::sqrt(x: std::float64) -> std::float64
std::math::sqrt(x: std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the square root of the input value.';
Expand All @@ -194,20 +194,20 @@ math::sqrt(x: std::float64) -> std::float64


CREATE FUNCTION
math::sqrt(x: std::decimal) -> std::decimal
std::math::sqrt(x: std::decimal) -> std::decimal
{
CREATE ANNOTATION std::description :=
'Return the square root of the input value.';
SET volatility := 'Immutable';
USING SQL FUNCTION 'sqrt';
};

# math::mean
# std::math::mean
# -----------
# The mean function returns an empty set if the input is empty set. On
# all other inputs it returns the mean for that input set.
CREATE FUNCTION
math::mean(vals: SET OF std::decimal) -> std::decimal
std::math::mean(vals: SET OF std::decimal) -> std::decimal
{
CREATE ANNOTATION std::description :=
'Return the arithmetic mean of the input set.';
Expand All @@ -219,7 +219,7 @@ math::mean(vals: SET OF std::decimal) -> std::decimal


CREATE FUNCTION
math::mean(vals: SET OF std::int64) -> std::float64
std::math::mean(vals: SET OF std::int64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the arithmetic mean of the input set.';
Expand All @@ -233,7 +233,7 @@ math::mean(vals: SET OF std::int64) -> std::float64


CREATE FUNCTION
math::mean(vals: SET OF std::float64) -> std::float64
std::math::mean(vals: SET OF std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the arithmetic mean of the input set.';
Expand All @@ -244,10 +244,10 @@ math::mean(vals: SET OF std::float64) -> std::float64
};


# math::stddev
# std::math::stddev
# ------------
CREATE FUNCTION
math::stddev(vals: SET OF std::decimal) -> std::decimal
std::math::stddev(vals: SET OF std::decimal) -> std::decimal
{
CREATE ANNOTATION std::description :=
'Return the sample standard deviation of the input set.';
Expand All @@ -259,7 +259,7 @@ math::stddev(vals: SET OF std::decimal) -> std::decimal


CREATE FUNCTION
math::stddev(vals: SET OF std::int64) -> std::float64
std::math::stddev(vals: SET OF std::int64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the sample standard deviation of the input set.';
Expand All @@ -273,7 +273,7 @@ math::stddev(vals: SET OF std::int64) -> std::float64


CREATE FUNCTION
math::stddev(vals: SET OF std::float64) -> std::float64
std::math::stddev(vals: SET OF std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the sample standard deviation of the input set.';
Expand All @@ -284,10 +284,10 @@ math::stddev(vals: SET OF std::float64) -> std::float64
};


# math::stddev_pop
# std::math::stddev_pop
# ----------------
CREATE FUNCTION
math::stddev_pop(vals: SET OF std::decimal) -> std::decimal
std::math::stddev_pop(vals: SET OF std::decimal) -> std::decimal
{
CREATE ANNOTATION std::description :=
'Return the population standard deviation of the input set.';
Expand All @@ -299,7 +299,7 @@ math::stddev_pop(vals: SET OF std::decimal) -> std::decimal


CREATE FUNCTION
math::stddev_pop(vals: SET OF std::int64) -> std::float64
std::math::stddev_pop(vals: SET OF std::int64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the population standard deviation of the input set.';
Expand All @@ -313,7 +313,7 @@ math::stddev_pop(vals: SET OF std::int64) -> std::float64


CREATE FUNCTION
math::stddev_pop(vals: SET OF std::float64) -> std::float64
std::math::stddev_pop(vals: SET OF std::float64) -> std::float64
{
CREATE ANNOTATION std::description :=
'Return the population standard deviation of the input set.';
Expand All @@ -324,10 +324,10 @@ math::stddev_pop(vals: SET OF std::float64) -> std::float64
};


# math::var
# std::math::var
# --------------
CREATE FUNCTION
math::var(vals: SET OF std::decimal) -> OPTIONAL std::decimal
std::math::var(vals: SET OF std::decimal) -> OPTIONAL std::decimal
{
CREATE ANNOTATION std::description :=
'Return the sample variance of the input set.';
Expand All @@ -339,7 +339,7 @@ math::var(vals: SET OF std::decimal) -> OPTIONAL std::decimal


CREATE FUNCTION
math::var(vals: SET OF std::int64) -> OPTIONAL std::float64
std::math::var(vals: SET OF std::int64) -> OPTIONAL std::float64
{
CREATE ANNOTATION std::description :=
'Return the sample variance of the input set.';
Expand All @@ -353,7 +353,7 @@ math::var(vals: SET OF std::int64) -> OPTIONAL std::float64


CREATE FUNCTION
math::var(vals: SET OF std::float64) -> OPTIONAL std::float64
std::math::var(vals: SET OF std::float64) -> OPTIONAL std::float64
{
CREATE ANNOTATION std::description :=
'Return the sample variance of the input set.';
Expand All @@ -364,10 +364,10 @@ math::var(vals: SET OF std::float64) -> OPTIONAL std::float64
};


# math::var_pop
# std::math::var_pop
# -------------
CREATE FUNCTION
math::var_pop(vals: SET OF std::decimal) -> OPTIONAL std::decimal
std::math::var_pop(vals: SET OF std::decimal) -> OPTIONAL std::decimal
{
CREATE ANNOTATION std::description :=
'Return the population variance of the input set.';
Expand All @@ -379,7 +379,7 @@ math::var_pop(vals: SET OF std::decimal) -> OPTIONAL std::decimal


CREATE FUNCTION
math::var_pop(vals: SET OF std::int64) -> OPTIONAL std::float64
std::math::var_pop(vals: SET OF std::int64) -> OPTIONAL std::float64
{
CREATE ANNOTATION std::description :=
'Return the population variance of the input set.';
Expand All @@ -393,7 +393,7 @@ math::var_pop(vals: SET OF std::int64) -> OPTIONAL std::float64


CREATE FUNCTION
math::var_pop(vals: SET OF std::float64) -> OPTIONAL std::float64
std::math::var_pop(vals: SET OF std::float64) -> OPTIONAL std::float64
{
CREATE ANNOTATION std::description :=
'Return the population variance of the input set.';
Expand Down
2 changes: 1 addition & 1 deletion edb/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
STD_MODULES = (
sn.UnqualName('std'),
sn.UnqualName('schema'),
sn.UnqualName('math'),
sn.UnqualName('std::math'),
sn.UnqualName('sys'),
sn.UnqualName('cfg'),
sn.UnqualName('cal'),
Expand Down
2 changes: 1 addition & 1 deletion edb/tools/experimental_interpreter/basis/server_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def default_impl(arg: Sequence[Sequence[e.Val]]) -> Sequence[e.Val]:
return all_server_cal_funcs[name.names[1]]
else:
return default_impl
case "math":
case "std::math":
if name.names[1] in all_server_math_funcs:
return all_server_math_funcs[name.names[1]]
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dump_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def _ensure_schema_data_integrity(self, include_secrets):
r'''
with x := range_unpack(range(1, 1000))
select all(
L2.vec in <v3>[x % 10, math::ln(x), x / 7 % 13]
L2.vec in <v3>[x % 10, std::math::ln(x), x / 7 % 13]
)
''',
[
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dump_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def _ensure_data_integrity(self):
r'''
with x := range_unpack(range(1, 1000))
select all(
L2.vec in <v3>[x % 10, math::ln(x), x / 7 % 13]
L2.vec in <v3>[x % 10, std::math::ln(x), x / 7 % 13]
)
''',
[
Expand Down
Loading

0 comments on commit dc3230d

Please sign in to comment.