{"id":15038459,"url":"https://github.com/openalloc/swiftseriesresampler","last_synced_at":"2026-03-15T18:15:14.228Z","repository":{"id":63919504,"uuid":"430535462","full_name":"openalloc/SwiftSeriesResampler","owner":"openalloc","description":"Transform a series of coordinate values into a new series with uniform intervals","archived":false,"fork":false,"pushed_at":"2023-05-01T23:59:24.000Z","size":192,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-13T13:14:07.662Z","etag":null,"topics":["chart","charting-library","linear-interpolation","resampling","swift-generics","swift-lang","swift-language","swift-library"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openalloc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-22T02:19:38.000Z","updated_at":"2024-11-02T04:33:12.000Z","dependencies_parsed_at":"2024-10-12T14:42:03.817Z","dependency_job_id":"810ba0e7-853f-4677-ba63-00a48508ad63","html_url":"https://github.com/openalloc/SwiftSeriesResampler","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"3668047f4058504b9a12172f79c8d767288e0eae"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftSeriesResampler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftSeriesResampler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftSeriesResampler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftSeriesResampler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openalloc","download_url":"https://codeload.github.com/openalloc/SwiftSeriesResampler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243410446,"owners_count":20286396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chart","charting-library","linear-interpolation","resampling","swift-generics","swift-lang","swift-language","swift-library"],"created_at":"2024-09-24T20:38:35.344Z","updated_at":"2025-12-25T18:39:25.383Z","avatar_url":"https://github.com/openalloc.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftSeriesResampler\n\nTransform a series of coordinate values into a new series with uniform intervals.\n\nWhy _SwiftSeriesResampler_? A typical use is to prepare a set of coordinates for plotting in a chart, where that chart requires uniform intervals along the x-axis, such as in a time series.\n\nAvailable as an open source Swift library to be incorporated in other apps.\n\n_SwiftSeriesResampler_ is part of the [OpenAlloc](https://github.com/openalloc) family of open source Swift software tools.\n\n## SeriesResampler\n\nThis example shows the resampling of market value data in a time series from 5 *non-uniform* intervals to 8 *uniform intervals* in the target, as depicted in the charts.\n\n\u003cimg src=\"https://github.com/openalloc/SwiftSeriesResampler/blob/main/Images/example.png\" width=\"1149\" height=\"397\"/\u003e\n\n```swift\nlet df = ISO8601DateFormatter()\nlet d1 = df.date(from: \"2020-06-01T10:00:00Z\")!\nlet d2 = df.date(from: \"2020-06-20T08:00:00Z\")!\nlet d3 = df.date(from: \"2020-06-28T09:00:00Z\")!\nlet d4 = df.date(from: \"2020-07-18T11:00:00Z\")!\nlet d5 = df.date(from: \"2020-07-30T13:00:00Z\")!\n\nlet intervals = [d1, d2, d3, d4, d5].map { $0.timeIntervalSinceReferenceDate }\nlet marketValues = [1300.0, 1600.0, 1200.0, 800.0, 1500.0]\n\nlet s = LerpResampler(intervals, targetCount: 8)!\nlet targetMVs = s.resample(marketValues)\n\nfor pair in zip(s.targetVals, targetMVs) {\n    let d = Date(timeIntervalSinceReferenceDate: pair.0)\n    print(String(format: \"%@: $%5.0f\", df.string(from: d), pair.1))\n}\n\n=\u003e\n \"2020-06-01T10:00:00Z: $ 1300\"\n \"2020-06-09T20:42:51Z: $ 1434\"\n \"2020-06-18T07:25:42Z: $ 1568\"\n \"2020-06-26T18:08:34Z: $ 1281\"\n \"2020-07-05T04:51:25Z: $ 1064\"\n \"2020-07-13T15:34:17Z: $  896\"\n \"2020-07-22T02:17:08Z: $ 1011\"\n \"2020-07-30T13:00:00Z: $ 1500\"\n```\n\nCode for the `AccelLerpResamplerD` isn't shown, but is easily reproduced by replacing `LerpResampler` with it.\n\n## Resamplers\n\nTwo resamplers are currently offered, both based on linear interpolation technique.\n\nAs depicted above, the behavior between the two resamplers differs, as they handle the interpolation differently.\n\n### LerpResampler\n\nA basic resampler that employs a pure-Swift linear interpolator (aka lerp).\n\n### AccelLerpResampler\n\nActually two resamplers that employ a linear interpolator from Apple's Accelerate framework.\n\nThe single-precision version, `AccelLerpResamplerS`, is for use with `Float` and similar data types.\n\nThe double-precision version, `AccelLerpResamplerD`, is for use with `Double` and similar data types. Notably with `TimeInterval` which is handy for charting time series.\n\n## Base Instance Properties and Methods\n\nAll resamplers are derived from the `BaseResampler` class, which offers the following public properties and methods. \n\nDerived resamplers may offer additional public properties and methods.\n\n#### Initializer\n\n- `init?(_ xVals: [T], targetCount: Int)` - create a new resampler instance\n\nWhere `T` is your `BinaryFloatingPoint` data type. Note that some resamplers have fixed types.\n\nInitialization is conditional, returning `nil` if the parameters are nonsensical, such as if the `xVals` are not in ascending order.\n\nThe initialization values are also available as properties:\n\n- `let xVals: [T]` - the original coordinates along the x-axis. They do not need to be uniform in spacing.\n\n- `let targetCount: Int` - the number of uniformly-spaced coordinates along the x-axis to target in the resampling.\n\n#### Instance Properties\n\nComputed properties are lazy, meaning that they are only calculated when first needed.\n\n- `var horizontalExtent: T` - The distance separating the first and last `xVal`.\n\n- `var relativeDistances: [T]` - `xVal` distances from first `xVal`. The first is `0`. The last is equal to `horizontalExtent`.\n\n- `var targetInterval: T` - The width of each interval between the resampled coordinates.\n\n- `var targetStride: [T]` - The resampled x-axis coordinates, as a stride object. They are uniformly-spaced.\n\n- `var targetVals: [T]` - The resampled x-axis coordinates, as an array object. They are uniformly-spaced.\n\n#### Instance Methods\n\n- `func resample(yVals: [T]) -\u003e [T]` - Resample the specified array of y-coordinate values for the original `xVals` provided when initializing the resampler. Returns `targetCount` resampled y-coordinate values.\n\n## See Also\n\nThis library is a member of the _OpenAlloc Project_.\n\n* [_OpenAlloc_](https://openalloc.github.io) - product website for all the _OpenAlloc_ apps and libraries\n* [_OpenAlloc Project_](https://github.com/openalloc) - Github site for the development project, including full source code\n\n## License\n\nCopyright 2021, 2022 OpenAlloc LLC\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\n## Contributing\n\nOther contributions are welcome too. You are encouraged to submit pull requests to fix bugs, improve documentation, or offer new features.\n\nThe pull request need not be a production-ready feature or fix. It can be a draft of proposed changes, or simply a test to show that expected behavior is buggy. Discussion on the pull request can proceed from there.\n\nContributions should ultimately have adequate test coverage. See tests for current entities to see what coverage is expected.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenalloc%2Fswiftseriesresampler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenalloc%2Fswiftseriesresampler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenalloc%2Fswiftseriesresampler/lists"}