Skip to content

Add a feature that splits an array into arrays each not exceeding the given size. #7565

Closed

Activity

  1. added
    Issue-Enhancement
    WG-Language
    on Aug 18, 2018
  2. BrucePay commented on Aug 18, 2018

    @BrucePay
    Collaborator

    Oddly enough, I've been implementing just such a thing related to Task-based programming in PowerShell (see #6716):

    PSCore (1:191) >  (1..10).PartitionData(3).foreach{"$_"}
    1 2 3
    4 5 6
    7 8 9
    10

    This method creates ArraySegment[object] instances for each partition rather than actually building new arrays thus avoiding a lot of copying.

    Note that there are two ways to do partitioning:

    1. Number of items in a partition
    2. Total number of partitions.

    Total number of partitions is arguably better for parallel execution since you can number your partitions to match the number of cores on your machine e.g. on a 4-core machine:

    # count words in 'Way and Peace'
    [System.IO.File]::ReadAllLines("WarAndPeace.txt").
        PartitionData(4).
            foreachparallel{
                (-split $_).
                     Count}.
                          Sum()

    mazzy (@mazzy-ax) Is this your scenario? Or do you have other things in mind? If so, please share.

  3. mazzy-ax commented on Aug 18, 2018

    @mazzy-ax
    Author

    Bruce Payette (@BrucePay), yes, it's my scenario. And parallel processing too :)

    I've been implementing

    is it implemented in Powershell or LINQ?

    foreachparallel

    is it PLINQ?

    if it is a LINQ/PLINQ then what about a Restricted and Constained langage?
    I would like to have this basic feature in these modes too. not only for parallel jobs.

  4. BrucePay commented on Aug 19, 2018

    @BrucePay
    Collaborator

    mazzy (@mazzy-ax) It's a PowerShell "extension method" (i.e. built-in and implemented in C#) that uses PLINQ for its implementation. Note however, that once you have Task support, it can also be implemented as a script method:

    Update-TypeData -TypeName Object -Force -MemberType ScriptMethod -MemberName foreachparallel  -Value {
        param ([scriptblock] $body)
    
        $p = [linq.parallelenumerable]::AsParallel(@($this))
        [linq.parallelenumerable]::Select($p, [func[object,object]] $body)
    }

    foreachparallel wouldn't be available in Restricted language but it might be there in Constrained language as long as we can ensure there are no security holes (e.g. language mode would have to propagate into Tasks created by PLINQ)..

  5. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  8. added
    Resolution-No Activity
    on Nov 16, 2023
  9. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-No ActivityWG-Language

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions