473,667 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fast copy from double[] to double[,]

I use a simple double[] array plus a variable to store the row size to
represent two dimensional data. I need to quickly copy this data to a
two dimensional array: double[,].

Currently I iterate through the double[], one by one and place it into
the preallocated double[,]. The arrays are large, and I'm doing a lot
of these. Thus it has become a significant bottleneck.

Can anyone suggest a faster way to convert a double[] + row size info
to a double[,]. I'm hoping there is some way to use one of the
Array.Copy() methods to copy at least a whole row at a time.

Thanks,

Mitch

Oct 2 '07 #1
2 4011
Buffer.Copy is the fastest method I know for matrix transformation.

A snippet how I use it:

private static double[,] DoubleArrayMatr ix(double[] arrSrc,int
rowLength)
{
double[,] arrDst = new double[arrSrc.Length/rowLength,
rowLength];
Buffer.BlockCop y(arrSrc, 0, arrDst, 0, arrSrc.Length *
sizeof(double)) ;
return arrDst;
}

<ba*****@yahoo. comha scritto nel messaggio
news:11******** **************@ w3g2000hsg.goog legroups.com...
>I use a simple double[] array plus a variable to store the row size to
represent two dimensional data. I need to quickly copy this data to a
two dimensional array: double[,].

Currently I iterate through the double[], one by one and place it into
the preallocated double[,]. The arrays are large, and I'm doing a lot
of these. Thus it has become a significant bottleneck.

Can anyone suggest a faster way to convert a double[] + row size info
to a double[,]. I'm hoping there is some way to use one of the
Array.Copy() methods to copy at least a whole row at a time.

Thanks,

Mitch
Oct 3 '07 #2
That's great..

Buffer.BlockCop y is about 5x faster than copying each value
individually. (My test was on a array size of 2000x5000 row x col)

Thanks Laura.

Oct 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
731
by: Michele Simionato | last post by:
I posted this few weeks ago (remember the C Sharp thread?) but it went unnoticed on the large mass of posts, so let me retry. Here I get Python+ Psyco twice as fast as optimized C, so I would like to now if something is wrong on my old laptop and if anybody can reproduce my results. Here are I my numbers for calling the error function a million times (Python 2.3, Psyco 1.0, Red Hat Linux 7.3, Pentium II 366 MHz): $ time p23 erf.py real ...
30
13726
by: franky.backeljauw | last post by:
Hello, I am wondering which of these two methods is the fastest: std::copy, which is included in the standard library, or a manually written pointer copy? Do any of you have any experience with this? I would think that the library function std::copy would perform optimally, as it is a library function, and therefore the writers of this function would know best how to optimize it ... but some tests seem to indicate that my pointer copy...
2
2017
by: Birt | last post by:
My understanding about defining your own copy and assignment constructors is whenever there is a member of pointer type. Is this true or is there any exception to this"rule"? How about when you define a class which doesn't have a pointer type variable as member and this class could be derived, and a new member of pointer type could be added in the future? Does this mean that all classes that will be inherited in the future should be...
45
9407
by: OcelotIguana | last post by:
Hello, Does anyone have any suggestions for where to find a good sincos routine (i.e. a routine that calculates both the sin and cos of a given argument) written in c? Thanks, OcelotIguana@yahoo.com
7
7403
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For example, the manner in which I update element 1 depends on several other (randomly numbered) elements in the array. So, I can't change an element until I've figured out how every element changes.
4
3600
by: Alexis Gallagher | last post by:
(I tried to post this yesterday but I think my ISP ate it. Apologies if this is a double-post.) Is it possible to do very fast string processing in python? My bioinformatics application needs to scan very large ASCII files (80GB+), compare adjacent lines, and conditionally do some further processing. I believe the disk i/o is the main bottleneck so for now that's what I'm optimizing. What I have now is roughly as follows (on python...
11
5530
by: moleskyca1 | last post by:
Hi, I know if you call erase when you iterate through map you will crash. Ex: map<int,doublem; // insert something for ( map<int, double>::iterator i = m.begin(); i != m.end(); i++ ) if ( i->second < 0 ) m.erase(i);
1
4585
emaghero
by: emaghero | last post by:
Does anybody know an algorithm for the fast multiplication of three n-x-n symmetric matrices? I have an algorithm, which I'm not too pleased with, that does the job. Does anybody know a faster method, or even how to improve my algorithm? My algorithm takes three n-x-n symmetric matrices, A, B, C It multiplies the first two in the usual way to give a matrix D = A*B.
13
2462
by: Jeroen | last post by:
Hi all, I'm trying to implement a certain class but I have problems regarding the copy ctor. I'll try to explain this as good as possible and show what I tried thusfar. Because it's not about a certain code syntax but more a 'code architecture' thing , I'll use simple example classes (which are certainly not complete or working...) just to illustrate the idea (and I may make some mistakes because I'm not that experienced...). The...
0
8366
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8565
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7391
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.