profile
viewpoint

apple/swift 53945

The Swift Programming Language

apple/swift-package-manager 8009

The Package Manager for the Swift Programming Language

apple/swift-corelibs-foundation 4036

The Foundation Project, providing core utilities, internationalization, and OS independence

apple/swift-corelibs-libdispatch 1897

The libdispatch Project, (a.k.a. Grand Central Dispatch), for concurrency on multicore hardware

xwu/NumericAnnex 66

Numeric facilities for Swift

xwu/trait-o-matic 23

An open-source tool to find and classify phenotypic correlations for variations in whole genomes. (For deployment, use the production branch.)

xwu/xwu-swift-numerics 16

Notes on numerics in Swift

xwu/FlowKit 3

A library for analyzing flow cytometry data

xwu/FloatingPointAnnex 0

A standalone project to test new floating point initializers to be added to the Swift standard library

xwu/FloatingPointPerformanceRegression 0

Companion code for a Swift performance regression

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 extension Sequence where Element: Hashable {  extension Sequence {   /// Returns an array with the unique elements of this sequence (as determined-  /// by the given projection), in the order of the first occurence of each+  /// by the given projection), in the order of the first occurrence of each   /// unique element.+  ///+  ///     let animals = ["dog", "pig", "cat", "ox", "cow", "owl"]+  ///     let uniqued = animals.uniqued(on: {$0.first})+  ///     print(uniqued)+  ///     // Prints '["dog", "pig", "cat", "ox"]'+  ///+  /// - Parameter projection: A projecting closure. `projection` accepts an+  ///   element of this sequence as its parameter which is having the type of+  ///   projecting element and returns a projected value that may have the same+  ///   type having constraint `Hashable`.

@natecook1000 Do you have suggestions of how to approach describing this parameter?

Roshankumar350

comment created time in 15 hours

PullRequestReviewEvent

Pull request review commentapple/swift

[Concurrency] Don't lose name information from completion-handler arguments

  -(void)doSomethingConflicted:(NSString *)operation completionHandler:(void (^)(NSInteger))handler; -(NSInteger)doSomethingConflicted:(NSString *)operation;+-(void)server:(NSString *)name restartWithCompletionHandler:(void (^)(void))block;+-(void)server:(NSString *)name atPriority:(double)priority restartWithCompletionHandler:(void (^)(void))block;

Suggestion: I'm not sure what real-life APIs you're looking at, but at least rationalizing based on this example, it may make the most sense to translate these APIs by prepending the information to the base name at all times: await is really taking the place of the completion handler, and it lives on the opposite side of the expression as compared to a trailing closure.

   server:atPriority:restartWithCompletionHandler:
//                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trailing closures are ergonomic

   await server.server("localhost", atPriorityRestart: 0.8)
// ^^^^^                                      ^^^^^^^ await ... wait for it ... restart

If the Objective-C importer were to translate these names by first logically shuffling this information to the front, then it seems to me like it'd be a consistently better result:

// Original
thing:frobnicateWithCompletionHandler:

// Rearrange to pull name information next to `await` use site
frobnicateWithCompletionHandler:thing:

// Eliminate "WithCompletionHandler"
frobnicateThing:

When the design for async/await is eventually shared, I hope you'll devote some text to translation from legacy APIs for discussion and possible enhancement, just like the review process that the original Objective-C-to-Swift translation went through.

DougGregor

comment created time in 17 hours

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 extension Sequence {   /// by the given projection), in the order of the first occurrence of each   /// unique element.   ///-  ///     let animals = ["dog", "pig", "cat", "ox", "dog","cat"]-  ///     let uniqued = animals(on: { $0.first })+  ///     let animals = ["dog", "pig", "cat", "ox", "dog", "cat"]

This example doesn't really demonstrate the role of the 'projection' closure. If you want to stick to the projection $0.first, I'd suggest something like:

  ///     let animals = ["dog", "pig", "cat", "ox", "cow", "owl"]
Roshankumar350

comment created time in a day

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 extension Sequence {   /// by the given projection), in the order of the first occurrence of each   /// unique element.   ///-  ///     let animals = ["dog", "pig", "cat", "ox", "dog","cat"]-  ///     let uniqued = animals(on: { $0.first })+  ///     let animals = ["dog", "pig", "cat", "ox", "dog", "cat"]+  ///     let uniqued = animals.uniqued(on: {$0.first})   ///     print(uniqued)-  ///     // Prints "["dog", "pig","cat", "ox"]"+  ///     // Prints '["dog", "pig", "cat", "ox"]'   ///   /// - Parameter projection: A projecting closure. `projection` accepts an   ///   element of this sequence as its parameter and returns a projected-  ///   value of the same  type.+  ///   value of the same type having constraint `Hashable`.

This is not correct: the projected value does not need to be of the same type.

But moreover, even when corrected, this statement is still just describing the type of the parameter in words, which is not necessary and doesn't add anything. The challenge here is to teach the user why and how to use a projection function to determine uniqueness.

Roshankumar350

comment created time in a day

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentapple/swift

[DNM][TypeChecker] Implement Double <-> CGFloat implicit conversion

 if let realRoomName = roomName as! NSString { // expected-warning{{forced cast f  var pi = 3.14159265358979 var d: CGFloat = 2.0-var dpi:CGFloat = d*pi // expected-error@:21{{cannot convert value of type 'Double' to expected argument type 'CGFloat'}}+var dpi:CGFloat = d*pi // Ok (implicit conversion Float -> CGFloat)
var dpi:CGFloat = d*pi // Ok (implicit conversion Double -> CGFloat)
xedin

comment created time in a day

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentapple/swift

[SR-10011] [Lexer] Raw Strings escape character sequence resembling multiline delimiter

 _ = ##"""       """## // CHECK: "a raw string with \"\"\" in it" +// ===---------- False Multiline Delimiters --------===++/// Source code contains zero-width character in this format: `#"[U+200B]"[U+200B]"#`+/// The check contains zero-width character in this format: `"[U+200B]\"[U+200B]"`+/// Use this test when implementating `diagnoseZeroWidthMatchAndAdvance`.

I might be a little more specific, perhaps:

/// If this check fails after you implement `diagnoseZeroWidthMatchAndAdvance`,
/// then you may need to tweak how to test for single-line string literals that
/// resemble a multiline delimiter in `advanceIfMultilineDelimiter` so that it
/// passes again.
maustinstar

comment created time in a day

PullRequestReviewEvent

Pull request review commentapple/swift

[SR-10011] [Lexer] Raw Strings escape character sequence resembling multiline delimiter

 _ = ##"""       """## // CHECK: "a raw string with \"\"\" in it" +_ = #"""#+// CHECK: "\""

Here's a tricky situation that I want to make sure works in the future. Hopefully, this makes sense to you:

For now, diagnoseZeroWidthMatchAndAdvance doesn't actually diagnose zero-width spaces. It's meant to be clever so that eventually "[U+200B]"[U+200B]" (where [U+200B] is the zero-width space) is lexed as """ for the purposes of multiline string literals.

For your purposes here, even if that eventually becomes implemented, it's important that #"[U+200B]"[U+200B]"# is still lexed exactly as it is right now. That is, the string should be equal to "\u{200B}\"\u{200B}" and not just "\"". If we test for that now, it's trivial, but if someone implements diagnoseZeroWidthMatchAndAdvance in the future and it breaks this, then they will be alerted to that fact. We can even leave future people a note explaining this.

maustinstar

comment created time in a day

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 extension Sequence where Element: Hashable {  extension Sequence {   /// Returns an array with the unique elements of this sequence (as determined-  /// by the given projection), in the order of the first occurence of each+  /// by the given projection), in the order of the first occurrence of each   /// unique element.+  ///+  ///     let animals = ["dog", "pig", "cat", "ox", "dog","cat"]+  ///     let uniqued = animals(on: { $0.first })

This does not compile.

Roshankumar350

comment created time in 2 days

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 extension Sequence where Element: Hashable {  extension Sequence {   /// Returns an array with the unique elements of this sequence (as determined-  /// by the given projection), in the order of the first occurence of each+  /// by the given projection), in the order of the first occurrence of each   /// unique element.+  ///+  ///     let animals = ["dog", "pig", "cat", "ox", "dog","cat"]+  ///     let uniqued = animals(on: { $0.first })+  ///     print(uniqued)+  ///     // Prints "["dog", "pig","cat", "ox"]"+  ///+  /// - Parameter projection: A projecting closure. `projection` accepts an+  ///   element of this sequence as its parameter and returns a projected+  ///   value of the same  type.
  ///   value of the same type.

This description is true, but it’s also just describing the type signature in words. But what are the semantics expected of this closure? That should be documented here.

Roshankumar350

comment created time in 2 days

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 extension Sequence where Element: Hashable {  extension Sequence {   /// Returns an array with the unique elements of this sequence (as determined-  /// by the given projection), in the order of the first occurence of each+  /// by the given projection), in the order of the first occurrence of each   /// unique element.+  ///+  ///     let animals = ["dog", "pig", "cat", "ox", "dog","cat"]+  ///     let uniqued = animals(on: { $0.first })+  ///     print(uniqued)+  ///     // Prints "["dog", "pig","cat", "ox"]"
  ///     // Prints '["dog", "pig", "cat", "ox"]'

Although the output depends on what the projection chosen for this example is.

Roshankumar350

comment created time in 2 days

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 extension Sequence where Element: Hashable {  extension Sequence {   /// Returns an array with the unique elements of this sequence (as determined-  /// by the given projection), in the order of the first occurence of each+  /// by the given projection), in the order of the first occurrence of each   /// unique element.+  ///+  ///     let animals = ["dog", "pig", "cat", "ox", "dog","cat"]
  ///     let animals = ["dog", "pig", "cat", "ox", "dog", "cat"]
Roshankumar350

comment created time in 2 days

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 //===----------------------------------------------------------------------===//  extension Sequence where Element: Hashable {-  /// Returns an array with only the unique elements of this sequence, in the-  /// order of the first occurence of each unique element.+  /// Returns an array with only  unique elements of this sequence, in the+  /// order of the first occurrence of each unique element.+  ///+  ///     let animals = ["dog", "pig", "cat", "ox", "dog","cat"]+  ///     let uniqued = animals.uniqued()+  ///     print(uniqued)+  ///     // Prints "["dog", "pig","cat", "ox"]"
  ///     // Prints '["dog", "pig", "cat", "ox"]'
Roshankumar350

comment created time in 2 days

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 //===----------------------------------------------------------------------===//  extension Sequence where Element: Hashable {-  /// Returns an array with only the unique elements of this sequence, in the-  /// order of the first occurence of each unique element.+  /// Returns an array with only  unique elements of this sequence, in the+  /// order of the first occurrence of each unique element.+  ///+  ///     let animals = ["dog", "pig", "cat", "ox", "dog","cat"]
  ///     let animals = ["dog", "pig", "cat", "ox", "dog", "cat"]
Roshankumar350

comment created time in 2 days

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 //===----------------------------------------------------------------------===//  extension Sequence where Element: Hashable {-  /// Returns an array with only the unique elements of this sequence, in the-  /// order of the first occurence of each unique element.+  /// Returns an array with only  unique elements of this sequence, in the
  /// Returns an array with only the unique elements of this sequence, in the
Roshankumar350

comment created time in 2 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentapple/swift

[Docs] Clarifies `ObjectIdentifier` guarantees

  /// A unique identifier for a class instance or metatype. ///+/// And the unique identifier is only valid for comparisons during the lifetime
/// This unique identifier is only valid for comparisons during the lifetime
sunbohong

comment created time in 2 days

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

 //===----------------------------------------------------------------------===//  extension Sequence where Element: Hashable {-  /// Returns an array with only the unique elements of this sequence, in the-  /// order of the first occurence of each unique element.+  /// Returns an array with only  unique elements of this sequence, in the+  /// order of the first occurrence of each unique element.+  ///+  /// In this example, `uniqued()` is used to include only names which are+  /// unique

Thanks, the formatting is now mostly consistent. Make sure to include periods at the end of sentences, like here (also elsewhere.) There is still another closing brace that is incorrectly indented. There are also several places where you have two consecutive spaces in the comment or the code; please make sure to remove them. There are also places where there are missing spaces after punctuation: please make sure to add them.

A more general comment here: I don’t think it adds anything to describe the example here by saying that uniqued makes the array unique.

Roshankumar350

comment created time in 2 days

PullRequestReviewEvent

push eventapple/swift

Patrick Pijnappel

commit sha 87c177c4b6e22e2e7281328443d644326852f4a6

[stdlib] Change misleading comment

view details

Patrick Pijnappel

commit sha 8ecd884b626a98f7b84ececfc1cbe37dde8f5b59

[stdlib] Expand integer conversion comment

view details

Xiaodi Wu

commit sha 39cc4363880f82cbd6aa4ff2651d0160d6702ea9

Merge pull request #34347 from apple/PatrickPijnappel-float-comment [stdlib] Change misleading comment

view details

push time in 2 days

delete branch apple/swift

delete branch : PatrickPijnappel-float-comment

delete time in 2 days

PR merged apple/swift

[stdlib] Change misleading comment

<!-- What's in this pull request? --> The original comment suggests that RawSignificand.bitWidth would be the thing we'd want to use if it were available, however using this would be incorrect as this would include leading zero bits in the bit pattern. For example, for a Double this would always be 64 even though only the least significant 52 bits of this are used. Instead, 52 is the number we are after in our example.

<!-- Before merging this pull request, you must run the Swift continuous integration tests. For information about triggering CI builds via @swift-ci, see: https://github.com/apple/swift/blob/master/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift! -->

+4 -3

3 comments

1 changed file

PatrickPijnappel

pr closed time in 2 days

pull request commentapple/swift-algorithms

Added documentation and where clause for API `uniqued()`

Good catch on the typo!

I've followed the code style of the rest of the project

Note that the code style involves indentations with two spaces, and also wrapping to 80 columns on each line.

Roshankumar350

comment created time in 3 days

startedpwsacademy/swift-setup

started time in 3 days

Pull request review commentapple/swift

[Docs] Clarifies `ObjectIdentifier` guarantees

 /// /// In Swift, only class instances and metatypes have unique identities. There /// is no notion of identity for structs, enums, functions, or tuples.+///+/// `ObjectIdentifier` is only guaranteed to remain unique for the+/// lifetime of an object. When the instance gets deallocated, its object +/// identifier may be reused for a different object. (Internally, objects are+/// identified by their memory location.)

You're right, that result would be unexpected. However, I just ran your example, and on my machine it prints false, which is what I would expect.

Under what conditions are you getting true? I'm not sure I would understand how that comes about, and the parenthetical doesn't clarify for me.

sunbohong

comment created time in 3 days

PullRequestReviewEvent

Pull request review commentapple/swift

[Docs] Clarifies `ObjectIdentifier` guarantees

 /// /// In Swift, only class instances and metatypes have unique identities. There /// is no notion of identity for structs, enums, functions, or tuples.+///+/// `ObjectIdentifier` is only guaranteed to remain unique for the+/// lifetime of an object. When the instance gets deallocated, its object +/// identifier may be reused for a different object. (Internally, objects are+/// identified by their memory location.)

What does this parenthetical mean, and why is it important for users to know this?

sunbohong

comment created time in 3 days

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Add Stride for Collection

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// striding(by:)+//===----------------------------------------------------------------------===//++extension Collection {+  /// Returns a collection stepping through the elements every `step` starting+  /// at the first value. Any remainders of the stride will be trimmed.+  ///+  ///     (0...10).striding(by: 2) // == [0, 2, 4, 6, 8, 10]+  ///     (0...10).striding(by: 3) // == [0, 3, 6, 9]+  ///+  /// - Complexity: O(1). Access to successive values is O(1) if the+  /// collection conforms to `RandomAccessCollection`; otherwise,+  /// O(_k_), where _k_ is the striding `step`.+  ///+  /// - Parameter step: The amount to step with each iteration.+  /// - Returns: Returns a collection stepping through the elements by the+  /// specified amount.+  public func striding(by step: Int) -> Stride<Self> {+    Stride(base: self, stride: step)+  }+}++public struct Stride<Base: Collection> {+  +  public let base: Base

Sorry, the specific issue is the question of equality, which @natecook1000 mentioned above.

Two values are equal when they behave the same way for all salient operations. For this purpose, we say that iteration order isn’t salient for sets but is salient for arrays, that the sign of zero isn’t salient for floating-point numbers, etc.

It’s a judgment call about what is salient here, and reasonable people can disagree whether differing base elements would matter; by contrast, if base isn’t recoverable, then there is no ambiguity at all.

ollieatkinson

comment created time in 4 days

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Add Stride for Collection

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// striding(by:)+//===----------------------------------------------------------------------===//++extension Collection {+  /// Returns a collection stepping through the elements every `step` starting+  /// at the first value. Any remainders of the stride will be trimmed.+  ///+  ///     (0...10).striding(by: 2) // == [0, 2, 4, 6, 8, 10]+  ///     (0...10).striding(by: 3) // == [0, 3, 6, 9]+  ///+  /// - Complexity: O(1). Access to successive values is O(1) if the+  /// collection conforms to `RandomAccessCollection`; otherwise,+  /// O(_k_), where _k_ is the striding `step`.+  ///+  /// - Parameter step: The amount to step with each iteration.+  /// - Returns: Returns a collection stepping through the elements by the+  /// specified amount.+  public func striding(by step: Int) -> Stride<Self> {+    Stride(base: self, stride: step)+  }+}++public struct Stride<Base: Collection> {+  +  public let base: Base

To help simplify the issue, do we need to expose base at all?

ollieatkinson

comment created time in 4 days

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Add BidirectionalCollection.trimmed

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {++  /// Returns a `SubSequence` formed by discarding all elements at the start and end of the Collection
  /// Returns a `SubSequence` formed by discarding all elements at the start and end of the collection
karwa

comment created time in 5 days

Pull request review commentapple/swift-algorithms

Add BidirectionalCollection.trimmed

+# Trim++[[Source](https://github.com/apple/swift-algorithms/blob/main/Sources/Algorithms/Trim.swift) |+ [Tests](https://github.com/apple/swift-algorithms/blob/main/Tests/SwiftAlgorithmsTests/TrimTests.swift)]++Returns a `SubSequence` formed by discarding all elements at the start and end of the Collection+which satisfy the given predicate.++```swift+let results = [2, 10, 11, 15, 20, 21, 100].trimmed(where: { $0.isMultiple(of: 2) })+print(results) // [11, 15, 20, 21]++let myString = "   hello, world  "+print(myString.trimmed(where: \.isWhitespace)) // "hello, world"+```++Trimming is a common operation in computing. It is particularly for String processing, but also useful in
Trimming is a common operation in computing. It is particularly for string processing, but also useful in
karwa

comment created time in 5 days

Pull request review commentapple/swift-algorithms

Add BidirectionalCollection.trimmed

+# Trim++[[Source](https://github.com/apple/swift-algorithms/blob/main/Sources/Algorithms/Trim.swift) |+ [Tests](https://github.com/apple/swift-algorithms/blob/main/Tests/SwiftAlgorithmsTests/TrimTests.swift)]++Returns a `SubSequence` formed by discarding all elements at the start and end of the Collection

I think the prevailing style is to use code voice to refer to a Thing or otherwise to refer to the thing being modeled in lowercase. A Collection is a protocol for collections; a String models a string.

Returns a `SubSequence` formed by discarding all elements at the start and end of the collection
karwa

comment created time in 5 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Add BidirectionalCollection.trimmed

+# Trim++[[Source](https://github.com/apple/swift-algorithms/blob/main/Sources/Algorithms/Trim.swift) |+ [Tests](https://github.com/apple/swift-algorithms/blob/main/Tests/SwiftAlgorithmsTests/TrimTests.swift)]++Returns a `SubSequence` formed by discarding all elements at the start and end of the Collection+which satisfy the given predicate.++```swift+let results = [2, 10, 11, 15, 20, 21, 100].trimmed(where: { $0.isMultiple(of: 2) })

Just a teeny bit of bikeshedding. Because trailing closure syntax causes where: to be omitted, there can be a little bit of ambiguity as to whether the closure determine's what's included or what's excluded. It so happens that, in English, "trimming" can take a direct object, while "trimmed" cannot, such that [1, 2, 3].trimming { $0 == 1 } suggests that every element equal to one is being dropped a little more strongly than "trimmed" would.

karwa

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Add BidirectionalCollection.trimmed

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {++  /// Returns a `SubSequence` formed by discarding all elements at the start and end of the Collection

Nit: I think this project's style is to wrap to 80 columns.

karwa

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Add BidirectionalCollection.trimmed

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension BidirectionalCollection {++  /// Returns a `SubSequence` formed by discarding all elements at the start and end of the Collection+  /// which satisfy the given predicate.+  ///+  /// Trimming is a common operation in computing, often referring to removing leading and trailing whitespace+  /// from a string[1].+  ///+  ///  ```+  ///  let myString = "  hello, world  "+  ///  print(myString.trimmed(where: \.isWhitespace)) // "hello, world"+  ///  ```+  ///+  /// [1]: https://en.wikipedia.org/wiki/Trimming_(computer_programming)+  ///+  /// - parameters:+  ///    - predicate:  A closure which determines if the element should be omitted from the resulting slice.+  ///+  /// - complexity: `O(n)`, where `n` is the length of the Collection.+  ///+  @inlinable+  public func trimmed(where predicate: (Element) throws -> Bool) rethrows -> SubSequence {++    // Consume elements from the front.+    let sliceStart = try firstIndex(where: { try predicate($0) == false }) ?? endIndex+    // sliceEnd is the index _after_ the last index to match the predicate.+    var sliceEnd = endIndex+    while sliceStart != sliceEnd {+      let idxBeforeSliceEnd = index(before: sliceEnd)+      guard try predicate(self[idxBeforeSliceEnd]) else {+        return self[sliceStart..<sliceEnd]

Q: can these bounds be safely unchecked too?

karwa

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Add BidirectionalCollection.trimmed

+# Trim++[[Source](https://github.com/apple/swift-algorithms/blob/main/Sources/Algorithms/Trim.swift) |+ [Tests](https://github.com/apple/swift-algorithms/blob/main/Tests/SwiftAlgorithmsTests/TrimTests.swift)]++Returns a `SubSequence` formed by discarding all elements at the start and end of the Collection+which satisfy the given predicate.++```swift+let results = [2, 10, 11, 15, 20, 21, 100].trimmed(where: { $0.isMultiple(of: 2) })+print(results) // [11, 15, 20, 21]++let myString = "   hello, world  "+print(myString.trimmed(where: \.isWhitespace)) // "hello, world"+```++Trimming is a common operation in computing. It is particularly for String processing, but also useful in+other applications; for example, a signal processing library might want to trim leading and trailing `0` values+to "zoom in" on the window of data that contains useful values.++## Detailed Design++A new method is added to `BidirectionalCollection`:++```swift+extension BidirectionalCollection {++  public func trimmed(where predicate: (Element) throws -> Bool) rethrows -> SubSequence+}+```++This method requires `BidirectionalCollection` for an efficient implementation which visits as few elements as possible.++A less-efficient implementation is _possible_ for any `Collection`, which would involve always traversing the+entire collection. This implementation is not provided, as it would mean developers of generic algorithms who forget+to add the `BidirectionalCollection` constraint will recieve that inefficient implementation:++```swift+func myAlgorithm<Input>(input: Input) where Input: Collection {++  let trimmedInput = input.trimmed(where: { ... }) // Uses least-efficient implementation.+}++func myAlgorithm2<Input>(input: Input) where Input: BidirectionalCollection {++  let trimmedInput = input.trimmed(where: { ... }) // Uses most-efficient implementation.+}+```++Swift provides the `BidirectionalCollection` protocol for marking types which support reverse traversal,+and generic types and algorithms which want to make use of that should add it to their constraints.++### Complexity++Calling this methods is O(_n_).
Calling this method is O(_n_).
karwa

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Add BidirectionalCollection.trimmed

+# Trim++[[Source](https://github.com/apple/swift-algorithms/blob/main/Sources/Algorithms/Trim.swift) |+ [Tests](https://github.com/apple/swift-algorithms/blob/main/Tests/SwiftAlgorithmsTests/TrimTests.swift)]++Returns a `SubSequence` formed by discarding all elements at the start and end of the Collection+which satisfy the given predicate.++```swift+let results = [2, 10, 11, 15, 20, 21, 100].trimmed(where: { $0.isMultiple(of: 2) })+print(results) // [11, 15, 20, 21]++let myString = "   hello, world  "+print(myString.trimmed(where: \.isWhitespace)) // "hello, world"+```++Trimming is a common operation in computing. It is particularly for String processing, but also useful in+other applications; for example, a signal processing library might want to trim leading and trailing `0` values+to "zoom in" on the window of data that contains useful values.++## Detailed Design++A new method is added to `BidirectionalCollection`:++```swift+extension BidirectionalCollection {++  public func trimmed(where predicate: (Element) throws -> Bool) rethrows -> SubSequence+}+```++This method requires `BidirectionalCollection` for an efficient implementation which visits as few elements as possible.++A less-efficient implementation is _possible_ for any `Collection`, which would involve always traversing the+entire collection. This implementation is not provided, as it would mean developers of generic algorithms who forget+to add the `BidirectionalCollection` constraint will recieve that inefficient implementation:
to add the `BidirectionalCollection` constraint will receive that inefficient implementation:
karwa

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentapple/swift

[stdlib] Change misleading comment

 extension FixedWidthInteger {     let minBitWidth = source.significandWidth     let isExact = (minBitWidth <= exponent)     let bitPattern = source.significandBitPattern-    // `RawSignificand.bitWidth` is not available if `RawSignificand` does not-    // conform to `FixedWidthInteger`; we can compute this value as follows if-    // `source` is finite:+    // Determine the number of meaningful bits in the significand bit pattern.

Good catch. For whatever reason, I was actually intending to compute the bit width of RawSignificand, but that has since been reworked.

The "number of meaningful bits" would probably be interpreted by most to mean significandWidth (i.e., minBitWidth); let's use existing terminology here:

    // Determine the actual number of fractional significand bits.

You might then ask, why not use Source.significandBitCount? The answer (as I recall) is that it wouldn't be correct for a future extensible-width floating-point type, where that API is supposed to return Int.max instead of the actual significand bits, since the latter would vary from value to value. For the same reason, RawSignificand does not conform to FixedWidthInteger, and hence the comment here in the first place. This would be worth noting:

// `Source.significandBitCount` would not reflect the actual number of
// fractional significand bits if `Source` is not a fixed-width floating-point
// type; we can compute this value as follows if `source` is finite:
PatrickPijnappel

comment created time in 6 days

PullRequestReviewEvent

push eventxwu/swift-numerics

Xiaodi Wu

commit sha 775b898654b871ce8036098cb6e50ba60049b9c3

[BigInt] Change normalized representation of zero, simplify division, and restore a few stylistic choices.

view details

push time in 7 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 ConstraintSystem::simplifyDynamicCallableApplicableFnConstraint(       return SolutionKind::Error;      // The result types are equivalent.-    if (matchTypes(func1->getResult(),-                   func2->getResult(),-                   ConstraintKind::Bind,+    if (matchTypes(func1->getResult(), func2->getResult(), ConstraintKind::Bind,                    subflags,-                   locator.withPathElement(-                     ConstraintLocator::FunctionResult)).isFailure())+                   locator.withPathElement(ConstraintLocator::FunctionResult))+            .isFailure()) {+      if (locator.isForImplicitCallOfCallableValue()) {+        // This dynamicCall overload cannot be called to produce a value of the+        // expected type, so we fallback to record the actual mismatch.
        // expected type, so we fall back to record the actual mismatch.
LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 ConstraintLocator *ConstraintSystem::getCalleeLocator(       return getConstraintLocator(anchor, newPath);     }   }+  +  // We checkinng if it's possible to make a nominal callAsFunction callable value an
  // We checking if it's possible to make a nominal callAsFunction callable value an
LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 ConstraintSystem::simplifyApplicableFnConstraint(   // is not valid for operators though, where an inout parameter does not   // have an explicit inout argument.   if (type1.getPointer() == desugar2) {-    if (!isOperator || !hasInOut())+    if (!isOperator || !hasInOut()) {+      if (locator.isForImplicitCallOfCallableValue()) {+        // This overload can be trivially called to produce a value of expected+        // type record the insert explicit call fix.

Sorry, I don't understand this comment. Could you please reword?

LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 bool ConstraintSystem::repairFailures(     return false;   }; +  auto repairByInsertingExplicitCallOnCallableValue =+      [&](Type srcType, Type dstType) -> bool {+    if (dstType->isVoid())+      return false;++    if (!(srcType->hasDynamicCallableAttribute() ||+          srcType->isCallableNominalType(DC, /*ignoreAccessControl*/ false)))+      return false;++    auto *loc = getConstraintLocator(locator);+    auto *anchor = getAsExpr(simplifyLocatorToAnchor(loc));+    // In cases where we have an extension with @dynamicCallable or+    // callAsFunction on types that can be expressed as literal e.g. String,+    // Interger, etc. and the mismatches are let _: Int = "foo" let's prefer to
    // Integer) and the mismatches are of the form let _: Int = "foo" let's prefer to
LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 bool ConstraintSystem::repairFailures(     return false;   }; +  auto repairByInsertingExplicitCallOnCallableValue =+      [&](Type srcType, Type dstType) -> bool {+    if (dstType->isVoid())+      return false;++    if (!(srcType->hasDynamicCallableAttribute() ||+          srcType->isCallableNominalType(DC, /*ignoreAccessControl*/ false)))+      return false;++    auto *loc = getConstraintLocator(locator);+    auto *anchor = getAsExpr(simplifyLocatorToAnchor(loc));+    // In cases where we have an extension with @dynamicCallable or+    // callAsFunction on types that can be expressed as literal e.g. String,+    // Interger, etc. and the mismatches are let _: Int = "foo" let's prefer to+    // still produce a conversion mismatch diagnostic.+    if (anchor && isa<LiteralExpr>(anchor))+      return false;++    // Let's attempt to see if the callable value can be explicit called to
    // Let's attempt to see if the callable value can be explicitly called to
LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 bool ConstraintSystem::repairFailures(     return false;   }; +  auto repairByInsertingExplicitCallOnCallableValue =+      [&](Type srcType, Type dstType) -> bool {+    if (dstType->isVoid())+      return false;++    if (!(srcType->hasDynamicCallableAttribute() ||+          srcType->isCallableNominalType(DC, /*ignoreAccessControl*/ false)))+      return false;++    auto *loc = getConstraintLocator(locator);+    auto *anchor = getAsExpr(simplifyLocatorToAnchor(loc));+    // In cases where we have an extension with @dynamicCallable or+    // callAsFunction on types that can be expressed as literal e.g. String,
    // callAsFunction on types that can be expressed by a literal (e.g., String or
LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 Optional<ConstraintSystem::ArgumentInfo> ConstraintSystem::getArgumentInfo(ConstraintLocator *locator) {   if (!locator)     return None;+  // Since we are only attempting to check if it's possible to insert an+  // explicit call in an anchor expr it doesn't explicitly have an argument
  // explicit call in an anchor expr, it doesn't explicitly have an argument
LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 class NonOptionalUnwrapFailure final : public FailureDiagnostic { };  class MissingCallFailure final : public FailureDiagnostic {+  Type ResultType;+ public:-  MissingCallFailure(const Solution &solution, ConstraintLocator *locator)-      : FailureDiagnostic(solution, locator) {}+  MissingCallFailure(const Solution &solution, Type resultType,+                     ConstraintLocator *locator)+      : FailureDiagnostic(solution, locator), ResultType(resultType) {}    ASTNode getAnchor() const override;    bool diagnoseAsError() override;++  /// Tailored diagnose insert an explicit call to a value of a type that
  /// Tailored diagnostic to insert an explicit call to a value of a type that
LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 ConstraintSystem::simplifyApplicableFnConstraint(     }      // The result types are equivalent.-    if (matchTypes(func1->getResult(),-                   func2->getResult(),-                   ConstraintKind::Bind,+    if (matchTypes(func1->getResult(), func2->getResult(), ConstraintKind::Bind,                    subflags,-                   locator.withPathElement(-                     ConstraintLocator::FunctionResult)).isFailure())+                   locator.withPathElement(ConstraintLocator::FunctionResult))+            .isFailure()) {+      if (locator.isForImplicitCallOfCallableValue()) {+        // This means overload cannot be called to produce a value of the+        // expected type, so we fallback to record the actual mismatch.
        // expected type, so we fall back to record the actual mismatch.
LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 class ConstraintLocatorBuilder {     return (getSummaryFlags() & ConstraintLocator::IsNonEphemeralParam);   } +  /// Checks whether this locator is describing an anchor that produces a value of a+  /// callable type that could be implicit called using "()" either by defining
  /// callable type that could be called using "()" either by defining

If one writes (), that's just a call, not an implicit call, right?

LucianoPAlmeida

comment created time in 8 days

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 CUSTOM_LOCATOR_PATH_ELT(ArgumentAttribute) /// The result of a chain of member accesses off an UnresolvedMemberExpr SIMPLE_LOCATOR_PATH_ELT(UnresolvedMemberChainResult) +/// A reference or expression that results in value of a callable type either @dynamicCallable

Nit: wrap to 80 columns.

LucianoPAlmeida

comment created time in 8 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 class ConstraintLocatorBuilder {   }    /// Checks whether this locator is describing an anchor that produces a value of a-  /// callable type that could be implicit called using "()" either by defining+  /// callable type that could be explicit called using "()" either by defining

Is this terminology, “explicit call” and “implicitly callable,” used anywhere? It seems confusing to me: I don’t understand what’s explicit or implicit about this. My understanding is that this is all about calling things that are callable.

LucianoPAlmeida

comment created time in 9 days

PullRequestReviewEvent

Pull request review commentapple/swift

[SR-13503] [Sema] Special InsertExplicitCall for nominal callable types

 class ConstraintLocatorBuilder {   }    /// Checks whether this locator is describing an anchor that produces a value of a-  /// callable type that could be implicit called using "()" either by defining+  /// callable type that could be explicit called using "()" either by defining

?

LucianoPAlmeida

comment created time in 9 days

PullRequestReviewEvent

Pull request review commentapple/swift

stdlib: remove `swiftMSVCRT`, replace with `swiftCRT` on Windows

 public let DBL_MIN = Double.leastNormalMagnitude  @available(swift, deprecated: 3.0, message: "Please use 'Double.leastNonzeroMagnitude' or '.leastNonzeroMagnitude'.") public let DBL_TRUE_MIN = Double.leastNonzeroMagnitude--public let M_LN2 = ucrt.M_LN2-public let M_LOG10E = ucrt.M_LOG10E-public let M_2_SQRTPI = ucrt.M_2_SQRTPI

Q: Would it make sense to just hardcode these (i.e., public let M_LN2 = 0.69314718055994529), for compatibility instead of deleting them?

compnerd

comment created time in 10 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentapple/swift-algorithms

Add Stride for Collection

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// stride(by:)+//===----------------------------------------------------------------------===//++extension Collection {+  /// - Complexity: O(_1_) and access to the next value in the stride+  /// is O(_1_) if the collection conforms to `RandomAccessCollection`,+  /// otherwise O(_k_) where `k` is the stride `step`.+  ///+  /// - Parameter step: The amount to step with each iteration.+  /// - Returns: Returns a collection stepping through the elements by the+  /// specified amount.+  public func stride(by step: Int) -> Stride<Self> {

I wonder if this would best be striding to fit the ed/ing rule for naming nonmutating members. That said, I also worry about ambiguity with the existing StrideTo/StrideThrough types: are there other terms that are often used for this operation?

ollieatkinson

comment created time in 10 days

pull request commentapple/swift-algorithms

Add sliding windows algorithm

In a general-purpose language that now has Windows support, I would be wary of a general-purpose API vending a type named Windows. I do think SlidingWindows would be more apt here.

ollieatkinson

comment created time in 11 days

issue commentapple/swift-algorithms

Add `indexBeforeFirst(where:)` and `indexAfterLast(where:)`

In fact, the “firstness” and “lastness” of these APIs are kind of inconsequential, and even potentially misinterpretable. The index before the first x is actually the last index before x.

By contrast, the “beforeness” and “afterness” of these APIs is very clear. It’s also worth reflecting that the index before the first x is also the index before any x. Perhaps, if we wanted to reflect the relationship between these APIs, we might invoke existing naming precedent and say: indexBefore(anySatisfying:) and indexAfter(allSatisfying:).

kylemacomber

comment created time in 11 days

push eventxwu/swift-numerics

Xiaodi Wu

commit sha 4102a08c80d762285f5c3781f9210315925f2e60

[BigInt] Fix example in documentation.

view details

push time in 13 days

pull request commentapple/swift-algorithms

Removes unnecessary shuffle from randomSample method of Collection and Sequence

Now all the numbers have the probability of 3/4 to be picked

This doesn't address the problem that is at discussion here, which is that not all the numbers have equal probability of being picked first. See the README for more details.

iSame7

comment created time in 13 days

push eventxwu/swift-numerics

Xiaodi Wu

commit sha 8364081ed47a7f0ceeeeb865e38322017cebaabd

[BigInt] Simplify implementation by always normalizing newly created values and adding '_isZero'.

view details

Xiaodi Wu

commit sha f0e257110cd704db7ec182d10f6201adcc55934d

[BigInt] Excise obsolete attempt at inline storage of lowest word.

view details

Xiaodi Wu

commit sha 713734f7885d3ed3f97cbec3db2b97478f1ebff6

[BigInt] Remove custom 'BigInt._Significand(_:_:)' initializer.

view details

push time in 14 days

pull request commentapple/swift-algorithms

Removes unnecessary shuffle from randomSample method of Collection and Sequence

Whether the shuffle is unnecessary or not is a mathematical question. I'm not sure I understand how you arrived at the conclusion that "there is no need to do that" based on your description here, although perhaps it is straightforward. Can you show a proof as to why each element of the original element is equally likely to found at any particular position of the result even without this shuffle?

iSame7

comment created time in 14 days

push eventxwu/swift-numerics

Xiaodi Wu

commit sha 7ed3ddf71008d6ff02aa1a923121f5a73b7c40f4

[BigInt] Fix a bug in the implementation of 'RandomNumberGenerator._next'.

view details

push time in 15 days

Pull request review commentapple/swift

Fix-it for missing let/var in pattern when identifier is unbound

 default: }  switch (1, 2) {-case (var a, a): // expected-error {{cannot find 'a' in scope}}+case (var a, a): // expected-error {{cannot find 'a' in scope}} expected-note {{add 'let' or 'var' keyword to bind 'a' in a pattern}}

Unless I'm mistaken, applying the suggestion here just leads to code that's broken in other ways.

In this case, as in the case of case none, it would be better if a non-working or likely unintended suggestion isn't made. It's fine if this PR doesn't include the fix-it to change the latter case to case .none, but I think it is important that this PR not suggest something in these cases.

kavon

comment created time in 16 days

PullRequestReviewEvent

pull request commentapple/swift-numerics

BigInt

As you can tell, I haven't been focusing on this much. You're absolutely right; will fix that think-o tonight. Thanks for exercising this code, and keep these coming!

xwu

comment created time in 16 days

pull request commentapple/swift-numerics

BigInt

As you've noted, that's a standard library bug :)

xwu

comment created time in 16 days

push eventxwu/swift-numerics

Stephen Canon

commit sha a35f5ba889a6a0e40292fcabf9072673225c2a77

Add Real conformance for Float16.

view details

Stephen Canon

commit sha 29d25b62c51caee06da1c3f0ed160ee6f1541a62

Merge pull request #106 from stephentyrone/Float16-support Add Real conformance for Float16.

view details

Stephen Canon

commit sha 9e1645a49510122887897943c295e3f591dbef87

Additional test coverage for pow with integer exponents. These cases expose a bug in the current implementation; because the split of the exponent into high and low parts may produce numbers with different signs, if both parts overflow or underflow, we can end up with 0 * infinity = NaN, when the result should actually be either zero or infinity.

view details

Stephen Canon

commit sha 75e4116989cd7e9480b7c11a39fe9f21f509c5fd

Additional test coverage for Float16 power with integer exponents.

view details

Stephen Canon

commit sha ee082efdaf1e2aa15b113ffdd51010af0dc152a5

Fix bug for very large exponents pow(Float/Double, Int). Just-added tests expose this issue, where the split of n into high/low parts could produce parts with different signs. If both x**high and x**low then overflow and underflow, the resulting computation would be 0*inf (or inf*0) and produce NaN instead of either zero or infinity.

view details

Stephen Canon

commit sha 59444343c4cbdc5573931d0bf3a6871b1e8b3ea2

Somewhat better implementation of pow(x,n) for Float16.

view details

Stephen Canon

commit sha 8978159f21ce026f6e4894985fc90d46187f2a7a

Merge pull request #108 from stephentyrone/better-pown-float16 Somewhat better implementation of pow(x,n) for Float16.

view details

Stephen Canon

commit sha a5cc950a86d005946b8d33a1995ecfcd0150c7fe

Merge pull request #111 from rxwei/complex-derivatives Make 'Complex' differentiable.

view details

Dan Zheng

commit sha 86f0b33c65c4efc77fe71fe31eaa160d777b5a55

Define `Complex.zeroTangentVectorInitializer`. The `Differentiable.zeroTangentVectorInitializer` protocol requirement is a closure producing a zero tangent vector, capturing minimal information from `self`. Fixes the `Complex: Differentiable` conformance for master toolchains.

view details

Stephen Canon

commit sha c634b5ddcea8445244b7cde1e5deddb8adf58e37

Merge pull request #121 from dan-zheng/complex-differentiable Define `Complex.zeroTangentVectorInitializer`.

view details

Saleem Abdulrasool

commit sha f30f73ed10000712c1758e5f6456aa3e420baca8

build: add initial CMake based build system This adds a CMake based build, which enables the build of swift-numerics on Windows. This currently does not add the test suite to the build as there are still some issues to work out in building the full test suite which require additional math operations to fully build.

view details

Saleem Abdulrasool

commit sha 697e9351e82fd150fe178bc6e94fc247331163d7

build: support the test suite on Windows

view details

Stephen Canon

commit sha 93b8e9f0dfc860e8536d84c798b64c64970ac1a6

Float16 is unavailable on macOS 11.

view details

Stephen Canon

commit sha e97070e36cdc378c9ba9dd6a97ba6975a43b268f

file -> filePath, too.

view details

Stephen Canon

commit sha 085f6dab2e7149b54392ba4c82ab9413972341bf

Merge branch 'master' into swift-5.3

view details

Stephen Canon

commit sha 110beefe0b9a4af05b09f2d33faf52740d9229a7

Merge pull request #105 from compnerd/cmake build: add initial CMake based build system

view details

Stephen Canon

commit sha 40b5a03063e690ec413e46e0df41a9d2c96c4677

Merge pull request #105 from compnerd/cmake build: add initial CMake based build system

view details

Stephen Canon

commit sha 91ecc8a3b62f661958e8768b86f7bc7b8b4a367f

First crack at dusting approximate comparisons back off.

view details

Stephen Canon

commit sha 7c0eb30664e864f4d9c8f3b1876dceda63dc7a20

Update complex test dependencies.

view details

Stephen Canon

commit sha f275f7df53eccad949fd234b808a122c67cff9aa

Wrote some rough documentation Also removed the default absolute tolerance, because in writing the documentation I realized that I couldn't reasonably justify having one.

view details

push time in 16 days

create barnchxwu/swift-numerics

branch : main

created branch time in 16 days

push eventxwu/swift-numerics

Stephen Canon

commit sha a35f5ba889a6a0e40292fcabf9072673225c2a77

Add Real conformance for Float16.

view details

Stephen Canon

commit sha 29d25b62c51caee06da1c3f0ed160ee6f1541a62

Merge pull request #106 from stephentyrone/Float16-support Add Real conformance for Float16.

view details

Stephen Canon

commit sha 9e1645a49510122887897943c295e3f591dbef87

Additional test coverage for pow with integer exponents. These cases expose a bug in the current implementation; because the split of the exponent into high and low parts may produce numbers with different signs, if both parts overflow or underflow, we can end up with 0 * infinity = NaN, when the result should actually be either zero or infinity.

view details

Stephen Canon

commit sha 75e4116989cd7e9480b7c11a39fe9f21f509c5fd

Additional test coverage for Float16 power with integer exponents.

view details

Stephen Canon

commit sha ee082efdaf1e2aa15b113ffdd51010af0dc152a5

Fix bug for very large exponents pow(Float/Double, Int). Just-added tests expose this issue, where the split of n into high/low parts could produce parts with different signs. If both x**high and x**low then overflow and underflow, the resulting computation would be 0*inf (or inf*0) and produce NaN instead of either zero or infinity.

view details

Stephen Canon

commit sha 59444343c4cbdc5573931d0bf3a6871b1e8b3ea2

Somewhat better implementation of pow(x,n) for Float16.

view details

Stephen Canon

commit sha 8978159f21ce026f6e4894985fc90d46187f2a7a

Merge pull request #108 from stephentyrone/better-pown-float16 Somewhat better implementation of pow(x,n) for Float16.

view details

Stephen Canon

commit sha a5cc950a86d005946b8d33a1995ecfcd0150c7fe

Merge pull request #111 from rxwei/complex-derivatives Make 'Complex' differentiable.

view details

Dan Zheng

commit sha 86f0b33c65c4efc77fe71fe31eaa160d777b5a55

Define `Complex.zeroTangentVectorInitializer`. The `Differentiable.zeroTangentVectorInitializer` protocol requirement is a closure producing a zero tangent vector, capturing minimal information from `self`. Fixes the `Complex: Differentiable` conformance for master toolchains.

view details

Stephen Canon

commit sha c634b5ddcea8445244b7cde1e5deddb8adf58e37

Merge pull request #121 from dan-zheng/complex-differentiable Define `Complex.zeroTangentVectorInitializer`.

view details

Saleem Abdulrasool

commit sha f30f73ed10000712c1758e5f6456aa3e420baca8

build: add initial CMake based build system This adds a CMake based build, which enables the build of swift-numerics on Windows. This currently does not add the test suite to the build as there are still some issues to work out in building the full test suite which require additional math operations to fully build.

view details

Saleem Abdulrasool

commit sha 697e9351e82fd150fe178bc6e94fc247331163d7

build: support the test suite on Windows

view details

Stephen Canon

commit sha 93b8e9f0dfc860e8536d84c798b64c64970ac1a6

Float16 is unavailable on macOS 11.

view details

Stephen Canon

commit sha e97070e36cdc378c9ba9dd6a97ba6975a43b268f

file -> filePath, too.

view details

Stephen Canon

commit sha 085f6dab2e7149b54392ba4c82ab9413972341bf

Merge branch 'master' into swift-5.3

view details

Stephen Canon

commit sha 110beefe0b9a4af05b09f2d33faf52740d9229a7

Merge pull request #105 from compnerd/cmake build: add initial CMake based build system

view details

Stephen Canon

commit sha 40b5a03063e690ec413e46e0df41a9d2c96c4677

Merge pull request #105 from compnerd/cmake build: add initial CMake based build system

view details

Stephen Canon

commit sha 91ecc8a3b62f661958e8768b86f7bc7b8b4a367f

First crack at dusting approximate comparisons back off.

view details

Stephen Canon

commit sha 7c0eb30664e864f4d9c8f3b1876dceda63dc7a20

Update complex test dependencies.

view details

Stephen Canon

commit sha f275f7df53eccad949fd234b808a122c67cff9aa

Wrote some rough documentation Also removed the default absolute tolerance, because in writing the documentation I realized that I couldn't reasonably justify having one.

view details

push time in 16 days

push eventxwu/swift-numerics

Xiaodi Wu

commit sha 86e72f942fa6569f599537ad3eb1a8c3e45dcf0d

[BigInt] Fix a bug in the implementation of Knuth's Algorithm D.

view details

push time in 16 days

pull request commentapple/swift-numerics

BigInt

@swanysteve Yikes, I'll have to look into that.

xwu

comment created time in 16 days

Pull request review commentapple/swift-algorithms

Adds "isSorted", "isSorted(by: )" and "allEqual" to Comparable Sequence

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2020 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++//===----------------------------------------------------------------------===//+// isSorted()+//===----------------------------------------------------------------------===//+++extension Sequence where Element: Comparable {+    public func isSorted() -> Bool {+        /// Returns Bool, indicating whether a sequence is sorted+        /// into non-descending order.+        ///+        /// - Complexity: O(*n*), where *n* is the length of the sequence.+        +        isSorted(by: <)+    }+    +    public func isSorted(by areInIncreasingOrder: (Element, Element) -> Bool) -> Bool {+        /// Returns Bool, indicating whether a sequence is sorted using+        /// the given predicate as the comparison between elements.+        ///+        /// - Complexity: O(*n*), where *n* is the length of the sequence.+        +        var prev: Element?+        for element in self {+            if let p = prev, !areInIncreasingOrder(p, element) {+                return false+            }+            prev = element+        }+        return true+    }+    +    public func allEqual() -> Bool {

This name is confusing to me, as it reads like it could be related to elementsEqual. It also seems like it's straightforward enough that we don't necessarily need to provide it in a library if the building blocks are there.

mcekr

comment created time in 17 days

PullRequestReviewEvent

startedapple/swift-algorithms

started time in 17 days

pull request commentapple/swift

Make Unicode.Scalar.Properties added after ICU 55 available on Linux

Will this break Windows?

MrLotU

comment created time in 19 days

more