Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:04:30+00:00 2026-05-28T04:04:30+00:00

I have not used PackedArray before, but just started looking at using them from

  • 0

I have not used PackedArray before, but just started looking at using them from reading some discussion on them here today.

What I have is lots of large size 1D and 2D matrices of all reals, and no symbolic (it is a finite difference PDE solver), and so I thought that I should take advantage of using PackedArray.

I have an initialization function where I allocate all the data/grids needed. So I went and used ToPackedArray on them. It seems a bit faster, but I need to do more performance testing to better compare speed before and after and also compare RAM usage.

But while I was looking at this, I noticed that some operations in M automatically return lists in PackedArray already, and some do not.

For example, this does not return packed array

a = Table[RandomReal[], {5}, {5}];
Developer`PackedArrayQ[a]

But this does

a = RandomReal[1, {5, 5}];
Developer`PackedArrayQ[a]

and this does

a = Table[0, {5}, {5}];
b = ListConvolve[ {{0, 1, 0}, {1, 4, 1}, {0, 1, 1}}, a, 1];
Developer`PackedArrayQ[b]

and also matrix multiplication does return result in packed array

a = Table[0, {5}, {5}];
b = a.a;
Developer`PackedArrayQ[b]

But element wise multiplication does not

b = a*a;
Developer`PackedArrayQ[b]

My question : Is there a list somewhere which documents which M commands return PackedArray vs. not? (assuming data meets the requirements, such as Real, not mixed, no symbolic, etc..)

Also, a minor question, do you think it will be better to check first if a list/matrix created is already packed before calling calling ToPackedArray on it? I would think calling ToPackedArray on list already packed will not cost anything, as the call will return right away.

thanks,

update (1)

Just wanted to mention, that just found that PackedArray symbols not allowed in a demo CDF as I got an error uploading one with one. So, had to remove all my packing code out. Since I mainly write demos, now this topic is just of an academic interest for me. But wanted to thank everyone for time and good answers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:04:31+00:00Added an answer on May 28, 2026 at 4:04 am

    There isn’t a comprehensive list. To point out a few things:

    • Basic operations with packed arrays will tend to remain packed:
     
        In[66]:= a = RandomReal[1, {5, 5}];
    
        In[67]:= Developer`PackedArrayQ /@ {a, a.a, a*a}
    
        Out[67]= {True, True, True}
    
    • Note above that that my version (8.0.4) doesn’t unpack for element-wise multiplication.

    • Whether a Table will result in a packed array depends on the number of elements:

     
        In[71]:= Developer`PackedArrayQ[Table[RandomReal[], {24}, {10}]]
    
        Out[71]= False
    
        In[72]:= Developer`PackedArrayQ[Table[RandomReal[], {24}, {11}]]
    
        Out[72]= True
    
        In[73]:= Developer`PackedArrayQ[Table[RandomReal[], {25}, {10}]]
    
        Out[73]= True
    
    • On["Packing"] will turn on messages to let you know when things unpack:
     
        In[77]:= On["Packing"]
    
        In[78]:= a = RandomReal[1, 10];
    
        In[79]:= Developer`PackedArrayQ[a]
    
        Out[79]= True
    
        In[80]:= a[[1]] = 0 (* force unpacking due to type mismatch *)
    
           Developer`FromPackedArray::punpack1: Unpacking array with dimensions {10}. >>
    
        Out[80]= 0
    
    • Operations that do per-element inspection will usually unpack the array,
        In[81]:= a = RandomReal[1, 10];
    
        In[82]:= Position[a, Max[a]]
    
           Developer`FromPackedArray::unpack: Unpacking array in call to Position. >>
    
        Out[82]= {{4}}
    
    • There penalty for calling ToPackedArray on an already packed list is small enough that I wouldn’t worry about it too much:
    
        In[90]:= a = RandomReal[1, 10^7];
    
        In[91]:= Timing[Do[Identity[a], {10^5}];]
    
        Out[91]= {0.028089, Null}
    
        In[92]:= Timing[Do[Developer`ToPackedArray[a], {10^5}];]
    
        Out[92]= {0.043788, Null}
    
    
    • The frontend prefers packed to unpacked arrays, which can show up when dealing with Dynamic and Manipulate:
        In[97]:= Developer`PackedArrayQ[{1}]
    
        Out[97]= False
    
        In[98]:= Dynamic[Developer`PackedArrayQ[{1}]]
    
        Out[98]= True
    
    • When looking into performance, focus on cases where large lists are getting unpacked, rather than the small ones. Unless the small ones are in big loops.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You'll have to forgive my ignorance, but I'm not used to using wide character
I have not used MAC OSX before, but I wanted to buy one for
I have not used a UIScrollView before, and I just wanted to know how
I have not used phing before, but would like to use it to automate
I have not used many lambda expressions before and I ran into a case
Disclaimer: I have not used RoR, and I have not generated tests. But, I
In the past, I have not really used namespaces, but in this project I
I have not used Junit before and have not done unit testing automatically. Scenario:
I am long time user of LINQ2SQL, but have not used the Entity Framework
I have been developing for some time now, and I have not used pointers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.