{"id":15066394,"url":"https://github.com/simphotonics/stride","last_synced_at":"2026-02-21T09:01:57.176Z","repository":{"id":59149813,"uuid":"374307413","full_name":"simphotonics/stride","owner":"simphotonics","description":"Extension method for iterating Dart Lists and Iterables using a custom start index and step size (stride).","archived":false,"fork":false,"pushed_at":"2025-10-10T09:10:27.000Z","size":231,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-24T11:50:06.764Z","etag":null,"topics":["array","column-major","dart","iterable","iterator","multi-dimensional-array","numerical-computation","row-major","stride"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/stride","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simphotonics.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-06-06T08:29:43.000Z","updated_at":"2025-10-10T09:10:31.000Z","dependencies_parsed_at":"2022-09-13T11:00:27.906Z","dependency_job_id":null,"html_url":"https://github.com/simphotonics/stride","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/simphotonics/stride","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fstride","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fstride/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fstride/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fstride/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simphotonics","download_url":"https://codeload.github.com/simphotonics/stride/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fstride/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29677881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T06:23:40.028Z","status":"ssl_error","status_checked_at":"2026-02-21T06:23:39.222Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["array","column-major","dart","iterable","iterator","multi-dimensional-array","numerical-computation","row-major","stride"],"created_at":"2024-09-25T01:07:06.948Z","updated_at":"2026-02-21T09:01:57.149Z","avatar_url":"https://github.com/simphotonics.png","language":"Dart","readme":"# Dart Stride Iterators\n[![Dart](https://github.com/simphotonics/stride/actions/workflows/dart.yml/badge.svg)](https://github.com/simphotonics/stride/actions/workflows/dart.yml)\n\n## Introduction\n\nThe package [stride][stride] provides **stride iterators** and extension\nmethods that make it possible to iterate data structures of type `List` and\n`Iterable` using a custom start point and step size. For negative step sizes\na reverse iterator is used.\n\n## Multi-Dimensional Arrays\n\nIn Dart, a multi-dimensional array can be\nrepresented as a list of lists.\nHowever, in the context of\n[numerical computation](https://dart.dev/articles/archive/numeric-computation)\nit is often useful to store multi-dimensional arrays as a flat list\nto speed up arithmetical operations and minimize memory usage.\nThe example below shows how the elements of a 2-dimensional array can\nbe stored as a 1-dimensional array (a Dart list).\n\n![2D-Array](https://github.com/simphotonics/stride/raw/main/images/array.svg?sanitize=true)\n\nIn order to access the elements of the column with index 1\n(highlighted using a grey rectangle), we\nneed to start the iteration at index 1. To move to the next element\nwe have to use a step size, or **stride**, that is equal to the\nnumber of columns in the 2D-array. For more\ninfo, see the section on [storage layout](#storage-layout) below.\n\n\n## Usage\n\nTo use this package, include [stride] as a dependency in your `pubspec.yaml` file.\nThe program below demonstrates how to use the\nextension method [`stride`][stride-method] to iterate lists using a custom step size\nand start index. Note that the iteration step size must not be zero. A negative step\nsize and suitable start index may be used to iterate in reverse direction.\n\nTip: When iterating *fixed* size lists, immutable lists views, or typed lists\nit makes perfect sense to omit concurrent modification\nchecks by using the method [`fastStride`][fastStride-method].\nThe slight performance improvement\nis evident when iterating very long lists.\n\n```Dart\nimport 'dart:typed_data';\n\nimport 'package:stride/stride.dart';\n\nmain(List\u003cString\u003e args) {\n  // 3x3 matrix.\n  final array2D = \u003cList\u003cString\u003e\u003e[\n    ['e00', 'e01', 'e02'],\n    ['e10', 'e11', 'e12'],\n    ['e20', 'e21', 'e22'],\n  ];\n\n  /// Elements of 3x3 matrix in row major layout.\n  final list = ['e00', 'e01', 'e02', 'e10', 'e11', 'e12', 'e20', 'e21', 'e22'];\n\n  final stepSize = 3;\n  final startIndex = 1;\n  final strideIt0 = list.stride(stepSize, startIndex);\n\n  print('2D array:');\n  print(array2D[0]);\n  print(array2D[1]);\n  print(array2D[2]);\n  print('');\n\n  print('Column 1:');\n  print(strideIt0);\n  print('');\n\n  // Typed list (with fixed length).\n  final numericalList =\n      Float64List.fromList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);\n\n  // Omitting concurrent modification checks:\n  final strideIt1 = numericalList.fastStride(\n    stepSize,\n    startIndex\n  );\n\n  print('Numerical list:');\n  print(numericalList);\n  print('');\n\n  print('start index: 1 and step-size: 3:');\n  print(strideIt1);\n  print('');\n\n  print('start index: 9 and step-size: -3:');\n  final reverseStrideIt1 = numericalList.stride(-3, 9);\n  print(reverseStrideIt1);\n}\n\n```\nRunning the program above produces the following console output:\n\n```Console\n$ dart example/bin/example.dart\n2D array:\n[e00, e01, e02]\n[e10, e11, e12]\n[e20, e21, e22]\n\nColumn 1:\n(e01, e11, e21)\n\nNumerical list:\n[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]\n\nstart index: 1 and step-size: 3:\n(1.0, 4.0, 7.0, 10.0)\n\nstart index: 9 and step-size: -3:\n(9.0, 6.0, 3.0, 0.0)\n```\n\n## Storage Layout\n\nLet **A** be an n-dimensional array with length d\u003csub\u003ei\u003c/sub\u003e along dimension i,\nwhere i \u0026in; \\[0, n-1\\].\n\nLet **L** be a Dart list containing all the elements of **A**. Then the length of **L** will be d\u003csub\u003e0\u003c/sub\u003e \u0026times; d\u003csub\u003e1\u003c/sub\u003e \u0026times; \u0026hellip; \u0026times; d\u003csub\u003en-1\u003c/sub\u003e .\n\nLet the element **A**\\[ i\u003csub\u003e0\u003c/sub\u003e \\]\\[ i\u003csub\u003e1\u003c/sub\u003e \\]\u0026hellip;\\[ i\u003csub\u003en\u0026#x2011;1\u003c/sub\u003e \\] be stored at location **L**\\[s\u003csub\u003e0\u003c/sub\u003e\u0026times;i\u003csub\u003e0\u003c/sub\u003e\u0026nbsp;+\u0026nbsp;\u0026hellip;\u0026nbsp;+\u0026nbsp;s\u003csub\u003en-1\u003c/sub\u003e\u0026times;i\u003csub\u003en-1\u003c/sub\u003e\\].\nThen the iteration step sizes, s\u003csub\u003ei\u003c/sub\u003e depend on the storage order\nas shown below. \n\n### Row Major Layout\n\nFor a *row major* storage order the step sizes are given by:\n\ns\u003csub\u003e0\u003c/sub\u003e = d\u003csub\u003e1\u003c/sub\u003e \u0026middot; d\u003csub\u003e2\u003c/sub\u003e \u0026middot; \u0026nbsp; \u0026hellip; \u0026nbsp; \u0026middot; d\u003csub\u003en-1\u003c/sub\u003e\n\ns\u003csub\u003e1\u003c/sub\u003e = d\u003csub\u003e2\u003c/sub\u003e \u0026middot; d\u003csub\u003e3\u003c/sub\u003e \u0026middot;  \u0026nbsp; \u0026hellip;  \u0026nbsp; \u0026middot; d\u003csub\u003en-1\u003c/sub\u003e\n\n\u0026nbsp; \u0026nbsp; \u0026vellip;\n\ns\u003csub\u003en-2\u003c/sub\u003e = d\u003csub\u003en-1\u003c/sub\u003e\n\ns\u003csub\u003en-1\u003c/sub\u003e = 1.\n\n\n### Column Major Layout\nFor a *column major* storage order the step sizes are given by:\n\ns\u003csub\u003e0\u003c/sub\u003e = 1\n\ns\u003csub\u003e1\u003c/sub\u003e = d\u003csub\u003e0\u003c/sub\u003e\n\ns\u003csub\u003e2\u003c/sub\u003e = d\u003csub\u003e0\u003c/sub\u003e \u0026middot; d\u003csub\u003e1\u003c/sub\u003e\n\n\n\u0026nbsp; \u0026nbsp; \u0026vellip;\n\ns\u003csub\u003en-2\u003c/sub\u003e = d\u003csub\u003e0\u003c/sub\u003e \u0026middot; d\u003csub\u003e1\u003c/sub\u003e \u0026middot;  \u0026nbsp; \u0026hellip;  \u0026nbsp; \u0026middot; d\u003csub\u003en-3\u003c/sub\u003e\n\ns\u003csub\u003en-1\u003c/sub\u003e = d\u003csub\u003e0\u003c/sub\u003e \u0026middot; d\u003csub\u003e1\u003c/sub\u003e \u0026middot;  \u0026nbsp; \u0026hellip;  \u0026nbsp; \u0026middot; d\u003csub\u003en-2\u003c/sub\u003e\n\n\nFor more information see [Row- and column-major order](https://en.wikipedia.org/wiki/Row-_and_column-major_order).\n\n\n## Examples\n\nA copy of the program shown in the section above can be found in the folder [example].\n\n\n## Features and bugs\n\nPlease file feature requests and bugs at the [issue tracker].\n\n[issue tracker]: https://github.com/simphotonics/stride/issues\n\n[example]: https://github.com/simphotonics/stride/tree/main/example\n\n[stride]: https://pub.dev/packages/stride\n\n[Stride]: https://pub.dev/documentation/stride/latest/stride/Stride.html\n\n[stride-method]: https://pub.dev/documentation/stride/latest/stride/Stride/stride.html\n\n[fastStride-method]: https://pub.dev/documentation/stride/latest/stride/FastStride/fastStride.html\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimphotonics%2Fstride","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimphotonics%2Fstride","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimphotonics%2Fstride/lists"}