-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use new Enso Hash Codes and Comparable #6060
Changes from all commits
491a988
3840517
314b152
410cbdc
90489c9
9dc5ae0
ddba647
bf622c3
8b7e895
53e3471
7ff0f48
20abf27
dfbae3b
0b1402f
4c975ea
55c2b3a
52b6aac
45af32b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import project.Data.Numbers.Integer | ||
|
||
from project.Data.Ordering import all | ||
from project.Data.Boolean import Boolean, True, False | ||
|
||
|
||
polyglot java import java.time.DayOfWeek | ||
|
||
type Day_Of_Week | ||
|
@@ -34,8 +37,9 @@ type Day_Of_Week | |
Day_Of_Week.Friday -> 5 | ||
Day_Of_Week.Saturday -> 6 | ||
|
||
shifted = if first_day == Day_Of_Week.Sunday then day_number else | ||
(day_number + 7 - (first_day.to_integer start_at_zero=True)) % 7 | ||
shifted = case first_day of | ||
Day_Of_Week.Sunday -> day_number | ||
_ -> (day_number + 7 - (first_day.to_integer start_at_zero=True)) % 7 | ||
|
||
shifted + if start_at_zero then 0 else 1 | ||
|
||
|
@@ -49,3 +53,14 @@ type Day_Of_Week | |
Day_Of_Week.Thursday -> DayOfWeek.THURSDAY | ||
Day_Of_Week.Friday -> DayOfWeek.FRIDAY | ||
Day_Of_Week.Saturday -> DayOfWeek.SATURDAY | ||
|
||
## PRIVATE | ||
type Day_Of_Week_Comparator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks exactly as I have envisioned that when dreaming about |
||
compare x y = | ||
x_int = x.to_integer | ||
y_int = y.to_integer | ||
Comparable.from x_int . compare x_int y_int | ||
|
||
hash x = x.to_integer | ||
|
||
Comparable.from (_:Day_Of_Week) = Day_Of_Week_Comparator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
from Standard.Base import all | ||
import Standard.Base.Errors.File_Error.File_Error | ||
|
||
from Standard.Base.Data.Ordering import all | ||
|
||
import project.Read_Flag.Read_Flag | ||
import project.Write_Flag.Write_Flag | ||
import project.Data.Histogram.Histogram | ||
|
@@ -382,30 +384,6 @@ type Image | |
/ : (Number | Vector | Matrix) -> Image ! Matrix_Error | ||
/ self value = Panic.recover Any (core_op self.opencv_mat value (Java_Image.divide _ _ _)) . catch Any core_op_handler | ||
|
||
## UNSTABLE | ||
|
||
Check the equality of two images. | ||
|
||
Arguments: | ||
- that: the matrix to compare with. | ||
|
||
? Implementation Note | ||
Two images considered equal when they have the same number of rows, | ||
columns and channels, and have the same pixel values. | ||
|
||
The image represented internally as a byte array, and if two images | ||
have the same dimensions, equality checks that underlying byte arrays | ||
are equal as well. | ||
|
||
> Example | ||
Checking two images for equality. | ||
|
||
import Standard.Examples | ||
|
||
example_eq = Examples.image == Examples.image | ||
== : Image -> Boolean | ||
== self that = Java_Image.is_equals self.opencv_mat that.opencv_mat | ||
|
||
## UNSTABLE | ||
|
||
Convert the image to a vector. | ||
|
@@ -499,3 +477,13 @@ core_op_handler error = | |
case error of | ||
Matrix_Error.Dimensions_Not_Equal -> Error.throw error | ||
_ -> Panic.throw error | ||
|
||
## PRIVATE | ||
type Image_Comparator | ||
compare x y = | ||
if Java_Image.is_equals x.opencv_mat y.opencv_mat then Ordering.Equal else | ||
Nothing | ||
|
||
hash x = x.opencv_mat.hashCode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good. Delegating to Java |
||
|
||
Comparable.from (_:Image) = Image_Comparator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from Standard.Base import all | ||
import Standard.Base.Data.Array_Proxy.Array_Proxy | ||
import Standard.Base.Data.Ordering.Comparator | ||
import Standard.Base.Errors.Common.Index_Out_Of_Bounds | ||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument | ||
import Standard.Base.Errors.Illegal_State.Illegal_State | ||
|
@@ -1258,15 +1257,23 @@ type Column | |
my_compare a b = Ordering.compare a.abs b.abs | ||
Examples.decimal_column.sort by=my_compare | ||
sort : Sort_Direction -> Boolean -> (Any -> Any -> Ordering) | Nothing -> Column | ||
sort self order=Sort_Direction.Ascending missing_last=True by=Nothing = | ||
order_bool = case order of | ||
Sort_Direction.Ascending -> True | ||
Sort_Direction.Descending -> False | ||
java_cmp = Comparator.new by | ||
rule = OrderBuilder.OrderRule.new self.java_column java_cmp order_bool missing_last | ||
mask = OrderBuilder.buildOrderMask [rule].to_array | ||
new_col = self.java_column.applyMask mask | ||
Column.Value new_col | ||
sort self order=Sort_Direction.Ascending missing_last=True by=Nothing = case by of | ||
Nothing -> | ||
order_bool = case order of | ||
Sort_Direction.Ascending -> True | ||
Sort_Direction.Descending -> False | ||
rule = OrderBuilder.OrderRule.new self.java_column order_bool missing_last | ||
mask = OrderBuilder.buildOrderMask [rule].to_array | ||
new_col = self.java_column.applyMask mask | ||
Column.Value new_col | ||
_ -> | ||
wrapped a b = case a of | ||
Nothing -> if b.is_nothing then Ordering.Equal else if missing_last then Ordering.Greater else Ordering.Less | ||
_ -> case b of | ||
Nothing -> if missing_last then Ordering.Less else Ordering.Greater | ||
_ -> by a b | ||
Comment on lines
+1270
to
+1274
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels like it could be a separate method that will be useful in other places: |
||
sorted = self.to_vector.sort order by=wrapped | ||
Column.from_vector self.name sorted | ||
|
||
## Creates a new Column with the specified range of rows from the input | ||
Column. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw. won't just that work? I'm not sure if we have to special-case the Sunday given that we do
%
later anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stack overflow - to_integer would be called each time,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the culprit is #6065.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right! Okay then let's keep it.
I guess it would have worked if we did:
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This was only changed to avoid having
==
in it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was just wondering on a side if we could further simplify it, removing the possibility of the infinite loop altogether.