Commit Graph
54 Commits
Author SHA1 Message Date
Stephen Canon f6b0aeb607 Remove _mulAdd in favor of Relaxed.multiplyAdd. 2023-04-26 08:56:43 -04:00
Steve (Numerics) Canon 30c01a9fc5 Possible spelling: Relaxed.sum/product. 2023-04-26 08:56:43 -04:00
Stephen Canon b750c890b7 Don't use reassociate(on) on older clang toolchains. 2023-04-26 08:56:43 -04:00
Stephen Canon 0fff91683a Disable _Float16 shims for relaxed operations on Intel.
The C type isn't available yet in clang on i386 or x86_64; once the calling conventions are stabilized in clang, we can reenable this.
2023-04-26 08:56:43 -04:00
Stephen Canon 9c0332d570 Initial pass at "relaxed" multiply and add operations.
This commit adds the following to the RealFunctions protocol:

    static func _relaxedAdd(_:Self, _:Self) -> Self
    static func _relaxedMul(_:Self, _:Self) -> Self

These are equivalent to + and *, but have "relaxed semantics"; specifically, they license the compiler to reassociate them and to form FMA nodes, which are both significant optimizations that can easily make many common loops 8-10x faster. These transformation perturb results slightly, so they should not be enabled without care, but the results with the relaxed operations are--for most purposes--"just as good as" (and often better than) what strict operations produce. The main thing to beware of is that they are no longer portable; different compiler versions and different targets and optimization flags will result in different results.

They are underscored because they are not stable API. In particular:
- `RealFunctions` is not really the right protocol for these (and neither is `Real`). I need to do some thinking about where to attach them.
- Even if it were the right protocol, these are more like implementation hooks than the API I really want people to use (TBD).
- I like "relaxed" more than other commonly used idioms ("fast"), but I'm not sure it's the name I ultimately want.
2023-04-26 08:56:43 -04:00
Stephen Canon 2baff8fc30 Also fixup real edge cases for pow(0,0). 2022-09-15 16:10:17 -04:00
Stephen Canon 270972dd8a Minor documentation formatting cleanup. 2022-04-06 11:50:25 -04:00
Stephen Canon c4f8886a11 Move baseline supported tools version to 5.4. 2022-03-05 10:18:13 -05:00
Markus Winter 05366d7f4a Revert names of temporary variables 2021-10-27 08:48:54 +02:00
Markus WinterandXiaodi Wu 6ec74ec80e Fix source code formatting
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-10-27 08:28:25 +02:00
Markus Winter f6e5563514 Fix argument ordering in twoSum and add test cases 2021-10-26 15:57:30 +02:00
Markus Winter 8b05d1c8e0 Update comments on the difference of sum(_:_:) and sum(large:small:) 2021-10-21 10:55:24 +02:00
Markus Winter 1e724835bd Add twoSum to augmented arithmetic 2021-10-20 23:47:27 +02:00
Jeremy Saklad ae38370107 Fix typo in AlgebraicField documentation
“distributitve” should be spelled “distributive”.
2021-09-17 14:21:34 -05:00
Stephen CanonandXiaodi Wu 12148ffa66 Update Sources/RealModule/Real.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-08-20 09:06:44 -04:00
Stephen CanonandXiaodi Wu 3a5c73964b Update Sources/RealModule/Real.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-08-20 09:06:36 -04:00
Stephen CanonandXiaodi Wu 32f48e6b73 Update Sources/RealModule/Real.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-08-20 09:06:27 -04:00
Stephen CanonandXiaodi Wu 342d38eb3b Update Sources/RealModule/AlgebraicField.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-08-20 09:05:56 -04:00
Stephen Canon 10e75aa392 Further expand documentation of reciprocal with some example use. 2021-08-19 20:47:36 -04:00
Stephen Canon faf13772af Add some documentation for AlgebraicField ops, minor fix for Augmented. 2021-08-19 14:50:24 -04:00
Stephen Canon 702c6fc1d8 Document the Augmented enum in RealModule in advance of 1.0 2021-08-19 14:00:52 -04:00
Steve (Numerics) Canon 5827f9a943 80-column formatting for source doc comments
Tidying, plus a few small edits. This commit should not include any code changes.
2021-03-03 14:01:09 -05:00
Steve (Numerics) Canon 97852afaf5 Adjust Float16 availability for Swift 5.4 toolchains.
In older toolchains, Float16 is marked unavailable on all mac targets; starting with the 5.4 toolchain, it is available starting in macOS 11.0 when targeting Apple Silicon.
2021-02-19 15:53:15 -05:00
Saleem Abdulrasool 00c6183670 build: update file lists for RealModule and _TestSupport
Add new files to the list that were missed in the CMakeLists.txt
updates.
2020-11-09 11:23:48 -08:00
Stephen Canon 2b4c6701f2 log and log(onePlus:) implementations for Complex
These significantly improve on the state of the art for arguments close to the circle where the result vanishes, producing good componentwise relative accuracy as well as relative accuracy in the complex norm.

Also drops the argument parser dependency, which is desirable to avoid possible circular dependencies in the future with algorithms.
2020-11-05 15:14:25 -05:00
Stephen Canon e07b39453b Swap availability for #if check on Float16. 2020-09-18 16:01:51 -04:00
Stephen Canon 0f8ef268d0 Remove muladdf16 for now. 2020-08-24 20:31:40 -04:00
Stephen Canon cda1b5e6f4 Added mulAdd and cosMinusOne operations for Real.
These are _mostly_ implementation hooks for Complex, but are generally useful, so I've made them public. Experimental, subject to renaming, especially mulAdd.
2020-08-24 18:52:58 -04:00
Saleem Abdulrasool 7109a22972 build: add new source file to RealModule
`Float16+Real.swift` was added to the source tree, update the build
rules.
2020-08-05 10:28:19 -07:00
Stephen Canon d368762c95 Add swift version checks for Float16. 2020-08-04 08:30:25 -04:00
Stephen Canon 13b74ae5f4 Merge branch 'master' into swift-5.3 2020-07-27 09:42:16 -04:00
Stephen Canon e69f12617b Lift the most general isApproximatelyEqual(to:) to AdditiveArithmetic.
The most general version of the API is now defined on AA as:

  ```
  public func isApproximatelyEqual<Magnitude>(
    to other: Self,
    absoluteTolerance: Magnitude,
    relativeTolerance: Magnitude = 0,
    norm: (Self) -> Magnitude
  ) -> Bool where Magnitude: FloatingPoint {
  ```

Note that AA does not have the magnitude property, so we can't default the norm in this setting. Therefore the following is kept on Numeric:

  ```
  public func isApproximatelyEqual(
    to other: Self,
    absoluteTolerance: Magnitude,
    relativeTolerance: Magnitude = 0
  ) -> Bool {
    self.isApproximatelyEqual(
      to: other,
      absoluteTolerance: absoluteTolerance,
      relativeTolerance: relativeTolerance,
      norm: \.magnitude
    )
  }
  ```

to provide the operation with norm defaulted (note: it's not optional, because then this would call itself).
2020-07-16 14:35:21 -04:00
Stephen Canon 80522b2bee Apply suggestions from code review 2020-07-14 17:41:02 -04:00
Stephen CanonandKyle Macomber a7ef6cd74c Update Sources/RealModule/ApproximateEquality.swift
Co-authored-by: Kyle Macomber <kmacomber@apple.com>
2020-07-14 17:34:02 -04:00
Stephen Canon 06c17a9a0f Documentation formatting. 2020-07-14 13:43:43 -04:00
Stephen Canon 2327363b24 Keypaths, #yolo 2020-07-14 13:19:00 -04:00
Stephen Canon 8b73836979 Rebased, added CMakeLists changes. 2020-07-14 12:34:27 -04:00
Stephen Canon 1dcd7f314b Dropped default-less overload, added norm for ApproxEquality.
- Removed isApproximatelyEqual(to:), since that functionality already
exists via the default value of relativeTolerance.

- Added the ability to specify a norm to use in the expert-mode
operation, defaulting to using $0.magnitude.
2020-07-14 12:33:25 -04:00
Stephen Canon 30627f2d06 Added text for asserts. 2020-07-14 12:33:25 -04:00
Stephen Canon c07076e917 Documentation improvements. 2020-07-14 12:33:25 -04:00
Stephen Canon 968d004d54 Further refinement of approximate equality
- Respell as isApproximatelyEqual(to:), by analogy to isEqual(to:),
  isLess(than:), etc.

- Refactor to eliminate the need for the Tolerance<Magnitude> type.
  Now all we have is one overloaded function with three implementations.
  This could be futher trimmed down to two versions by taking an
  optional parameter instead, but that seems a little bit less clean.

I want to write some more documentation and examples here, but this is
enough to discuss and start review.
2020-07-14 12:33:25 -04:00
Stephen Canon cfeda4df2d s/positive/non-negative/ for minimumScale. 2020-07-14 12:33:25 -04:00
Stephen Canon f275f7df53 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.
2020-07-14 12:33:25 -04:00
Stephen Canon 91ecc8a3b6 First crack at dusting approximate comparisons back off. 2020-07-14 12:33:25 -04:00
Stephen Canon 40b5a03063 Merge pull request #105 from compnerd/cmake
build: add initial CMake based build system
2020-07-03 09:49:53 -04:00
Stephen Canon 93b8e9f0df Float16 is unavailable on macOS 11. 2020-06-29 14:50:37 -04:00
Saleem Abdulrasool f30f73ed10 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.
2020-06-25 09:46:54 -07:00
Stephen Canon 59444343c4 Somewhat better implementation of pow(x,n) for Float16. 2020-04-10 16:16:25 -04:00
Stephen Canon ee082efdaf 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.
2020-04-10 11:51:57 -04:00
Stephen Canon ff6a0ff2a5 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.
2020-04-10 11:46:22 -04:00