GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Multiprocessing returns Array, RawArray of wrong length python 3.10.4 · Issue #98447 · python/cpython

Multiprocessing returns Array, RawArray of wrong length python 3.10.4 #98447

New issue
Copy link
New issue
Copy link
Closed
Closed
Multiprocessing returns Array, RawArray of wrong length python 3.10.4#98447
Copy link
Labels
topic-multiprocessingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@tendermonster
tendermonster
opened on Oct 19, 2022
Issue body actions

Bug report

When initializing Array or RawArray of type int, wrong length of the arrays is returned

Reproducible example:

from multiprocessing import RawArray, RawValue, Array, Value
a = Array('d',12)
X = np.frombuffer(a.get_obj())
print(X) # [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

a = Array('i',12)
X = np.frombuffer(a.get_obj())
print(X) # [0. 0. 0. 0. 0. 0.]

a = RawArray('d',12)
X = np.frombuffer(a)
print(X) # [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]

a = RawArray('i',12)
X = np.frombuffer(a)
print(X) # [0. 0. 0. 0. 0. 0.]

Your environment

working with vscode
conda-forge python 3.10.4
using ubuntu uname-a: 5.11.0-46-generic #51~20.04.1-Ubuntu SMP Fri Jan 7 06:51:40 UTC 2022

  • CPython versions tested on: conda-forge python 3.10.4
  • Operating system and architecture: using ubuntu uname-a: 5.11.0-46-generic 51~20.04.1-Ubuntu

Activity

  1. tendermonster
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 19, 2022
  2. AlexWaygood
    added
    topic-multiprocessing
    on Oct 19, 2022
  3. AlexWaygood
    added this to Multiprocessing issueson Oct 19, 2022
  4. mdboom commented on Oct 19, 2022

    @mdboom
    mdboom
    on Oct 19, 2022
    Contributor
    More actions

    The buffer interface doesn't retain type information about the items in the array, so using np.frombuffer defaults to double (8 bytes per item), even when the type in the array is i (4 bytes per item) since converting to a buffer throws that information out.

    I think you want to use np.asarray(a) instead to get the behaviour you want -- it will correctly look at the type of the array (using the memoryview API), and it likewise avoids the memory copy.

  5. mdboom
    closed this as completedon Oct 19, 2022
  6. mdboom
    moved this to Done in Multiprocessing issueson Oct 19, 2022
  7. tendermonster commented on Oct 20, 2022

    @tendermonster
    tendermonster
    on Oct 20, 2022
    Author
    More actions

    Thanks for quick response

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

    topic-multiprocessingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Multiprocessing issues
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.