Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

IndexArray replacement in DotNET

I'm trying to use 100% managed code (no CWArray ActiveX control). The NationalInstruments math functions don't appear to have a replacement for IndexArray. I know about the Array.Copy method, but it isn't as good. The destination array must always have the same dimension as the source array. So if I want to extract a 1-D array from a 2-D array, I always get back a 2-D array. I could start using arrays of arrays, but this is not always possible. I don't want to resort to a for-next loop!
0 Kudos
Message 1 of 7
(4,476 Views)
Are you trying to extract a row or a column ?
If you are trying to extract a row, then you can use System.Buffer.BlockCopy (the rank of the two arrays here does not matter, but they must both be arrays if a primitive type)
You could do something like...
int numBytes = Marshal.SizeOf(typeof(double));
Buffer.BlockCopy(inputMatrix, rowIndex*numColumnsToCopy*numBytes,
destArray,0,numColumnsToCopy*numBytes);

If youre trying to extract a column, i don't know, yet, of any other way than iterating thru the aray..something like the following..
for (int rowIndex=0; rowIndex < numRows; ++rowIndex)
{
extractedArray[rowIndex] = matrix[rowIndex,colIndex];
}
where colIndex is the column that you want...

Hope this helps some...
Nandan Dharwadker
Staff Software Engineer
Measurement Studio Hardware Team
0 Kudos
Message 2 of 7
(4,475 Views)
Sorry,
Posted that a little earlier than i intended to.
We will also keep this suggestion in mind for our next release..
Nandan Dharwadker
Staff Software Engineer
Measurement Studio Hardware Team
0 Kudos
Message 3 of 7
(4,476 Views)
Is there a list of old math functions versus the new Measurement Studio .NET functions? I noticed a number of other functions that are gone. Maybe there are good reasons (for example, the Visual Studio .Net library contains the function natively). Or maybe there is no good reason at all, and I'll just have to deal with it. But in either case, I would like to know so I'm not searching for something that isn't there. Visual Studio has a list showing the differences and workarounds between VB6 and .NET controls. It was very useful during my transition to .Net.
0 Kudos
Message 4 of 7
(4,475 Views)
Hello,
We are in the process of creating a list that will be made externally available, I will post the link here , as soon as it is available.

When we implemented the analysis library for dotNET, we reevaluated existing APIs, and looked for methods that dotNET contained natively, or that let the user trivially (perhaps in one line) do the same themselves.
As it turns out, most of the methods that we chose not to implement were those that (when compared to the activeX control)are in the CniArray or in dotNET in the ArrayOperations class. Array arithmetic is arguably a lot simpler in dotNET, and most(though certainly not all) of the methods we chose not to include in our API, typically have trivial one line implementations in dotNET.
So there a
re no methods, say, for adding /subtracting 1D arrays, clearing or sorting them.
There are some array operations that may not be that easy, and some that, well, should be there just because they are very convenient. The extracting of a row/column from a matrix would fall into that category.
There may be others, so we do appreciate and certainly value, user feedback in this area.
Best Regards,
NandanD
Nandan Dharwadker
Staff Software Engineer
Measurement Studio Hardware Team
0 Kudos
Message 5 of 7
(4,476 Views)
Thanks for the info! I look forward to seeing the list... Most people buy Measurement Studio for the convience, so the more functions NI provides, the better it will be. Even if the .Net library has some obscure methods that could be used, I prefer the direct approach that NI provides.

As for the CWArray.IndexArray function, I used your example to create a simple function that replicates it for columns (assuming that the first dimension is the column). It only works on 2-D Double arrays, but that's all I need it for. I think this is a lot more efficient than a loop.

Public Function IndexArray(ByVal Data(,) As Double, ByVal Dimension As Int16) As Double()


ReDim IndexArray(Data.GetUpperBound(1))
Buffer.Block
Copy(CType(Data, Double(,)), Dimension * (IndexArray.GetUpperBound(0) + 1) * 8, IndexArray, 0, (IndexArray.GetUpperBound(0) + 1) * 😎


End Function
0 Kudos
Message 6 of 7
(4,475 Views)
By the way, if you're passing this information to the developers, here are some of the other functions I really miss:

Subset1D
ConcatenateArray
SumArray
MaxArray
MinArray

I know that MaxArray and MinArray are available in the MaxMin subroutine, but it�s nice to get a return value. I don�t have to create any temporary variables.

Thanks again,
Joe
0 Kudos
Message 7 of 7
(4,475 Views)