Skip to content

Commit

Permalink
Unexpected Output from delete from array (#700)
Browse files Browse the repository at this point in the history
Changed how the non-flat array gets copied from the CopySubarray function. The changes are done for non-flat type arrays and for flat type it's still the same. I have used what we have for elementType->CopyData so that a proper copy(deep copy) happens.
  • Loading branch information
amehra-ni authored Jun 16, 2022
1 parent 265b8c9 commit f3d254c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 12 deletions.
40 changes: 28 additions & 12 deletions source/core/Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,15 +1201,31 @@ VIREO_FUNCTION_SIGNATURET(ArrayMaxMinInternal, FindArrayMaxMinInstruction)
}
// NOLINT(runtime/references)
static void CopySubArray(AQBlock1* &sourcePtr, AQBlock1* &destinationPtr, // NOLINT(runtime/references)
const UInt32 elementSize, const size_t elementsToCopy)
const size_t elementsToCopy, TypedArrayCoreRef arraySource, TypedArrayCoreRef arrayDest)
{
if (elementsToCopy) {
size_t bytesToCopy = elementsToCopy * elementSize;
if (destinationPtr) {
memmove(destinationPtr, sourcePtr, bytesToCopy);
sourcePtr += bytesToCopy, destinationPtr += bytesToCopy;
} else {
sourcePtr += bytesToCopy;
NIError err = kNIError_Success;
TypeRef elementType = arraySource->ElementType();
if (elementType->IsFlat()) {
if (elementsToCopy) {
size_t bytesToCopy = elementsToCopy * elementType->TopAQSize();
if (destinationPtr) {
memmove(destinationPtr, sourcePtr, bytesToCopy);
sourcePtr += bytesToCopy, destinationPtr += bytesToCopy;
} else {
sourcePtr += bytesToCopy;
}
}
} else {
IntIndex stride = elementType->TopAQSize();
IntIndex count = elementsToCopy;
for (Int32 i = 0; i < count; i++) {
err = elementType->CopyData(sourcePtr, destinationPtr);
if (err != kNIError_Success) {
arrayDest->Resize1D(0);
break;
}
sourcePtr += stride;
destinationPtr += stride;
}
}
}
Expand Down Expand Up @@ -1316,11 +1332,11 @@ VIREO_FUNCTION_SIGNATURE7(ArrayDeleteND, TypedArrayCoreRef, StaticType, void,
size_t numberOfElementsToBeDeleted = deletedPortionLength * numberOfElementsInDeletedDimension;
size_t numberOfElementsAfterDeleted = (dimensionSize[dimensionToDelete]
- (startIndex + deletedPortionLength)) * numberOfElementsInDeletedDimension;
Int32 currentDimension;
Int32 currentDimension;
do {
CopySubArray(inputArrayPtr, outputArrayPtr, elementSize, numberOfElementsBeforeDeleted);
CopySubArray(inputArrayPtr, deletedArrayPtr, elementSize, numberOfElementsToBeDeleted);
CopySubArray(inputArrayPtr, outputArrayPtr, elementSize, numberOfElementsAfterDeleted);
CopySubArray(inputArrayPtr, outputArrayPtr, numberOfElementsBeforeDeleted, arrayIn, arrayOut);
CopySubArray(inputArrayPtr, deletedArrayPtr, numberOfElementsToBeDeleted, arrayIn, deletedArray);
CopySubArray(inputArrayPtr, outputArrayPtr, numberOfElementsAfterDeleted, arrayIn, arrayOut);
currentDimension = dimensionToDelete;
while (--currentDimension >= 0 && ++index[currentDimension] >= dimensionSize[currentDimension])
index[currentDimension] = 0;
Expand Down
21 changes: 21 additions & 0 deletions test-it/ExpectedResults/ArrayDeleteMultiDimensionString.vtr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Loop no - 1
Input 4D Array of String
(((('a1' 'a2' 'a3' 'a4') ('b1' 'b2' 'b3' 'b4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
Deleted Array
((('b1' 'b2' 'b3' 'b4')))
Output Array
(((('a1' 'a2' 'a3' 'a4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
Loop no - 2
Input 4D Array of String
(((('a1' 'a2' 'a3' 'a4') ('b1' 'b2' 'b3' 'b4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
Deleted Array
((('b1' 'b2' 'b3' 'b4')))
Output Array
(((('a1' 'a2' 'a3' 'a4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
Loop no - 3
Input 4D Array of String
(((('a1' 'a2' 'a3' 'a4') ('b1' 'b2' 'b3' 'b4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
Deleted Array
((('b1' 'b2' 'b3' 'b4')))
Output Array
(((('a1' 'a2' 'a3' 'a4') ('c1' 'c2' 'c3' 'c4') ('d1' 'd2' 'd3' 'd4') ('e1' 'e2' 'e3' 'e4') ('f1' 'f2' 'f3' 'f4') ('g1' 'g2' 'g3' 'g4'))))
60 changes: 60 additions & 0 deletions test-it/ViaTests/ArrayDeleteMultiDimensionString.via
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
define (WebApp%3A%3Aindex%2Egviweb dv(.VirtualInstrument (
Locals: c( // Data Space
e(dv(.String 'WebApp::index.gviweb')local0)
ce(dv(.Int32 3)c1)
ce(dv(.Int32 0)c2)
e(.Int32 local3)
e(.Int32 local4)
ce(dv(.Int32 10)c5)
e(.UInt32 local6)
ce(dv(.Int32 1)c7)
ce(dv(a(.String * * * *) (((('a1' 'a2' 'a3' 'a4' )('b1' 'b2' 'b3' 'b4' )('c1' 'c2' 'c3' 'c4' )('d1' 'd2' 'd3' 'd4' )('e1' 'e2' 'e3' 'e4' )('f1' 'f2' 'f3' 'f4' )('g1' 'g2' 'g3' 'g4' )))))c8)
e(a(.String * * * *) local9)
e(a(.String * * *) local10)
de(a(.String * * *) dataItem_DeletedPortion)
e(a(.String * * *) local12)
de(a(.String * * * *) dataItem_ArrayWithSubsetDeleted)
e(a(.String * * * *) local14)
e(.UInt32 local15)
e(.Boolean local16)
ce(dv(.Int32 0)c17)
e(dv(.Int32 2)local18)
)
clump(1
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#12##WebApp;}" c1)
IsGE(c2 c1 local16)
BranchIfTrue(1 local16)
Branch(2)
Perch(2)
Copy(c17 local3)
Copy(c1 local4)
Perch(3)
Convert(c5 local6)
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#23d77726c0714674bcf64c1054667ee4##WebApp;}" c5 c7 c8)
ArrayDelete(local9 local10 c8 * c7 local18 )
Copy(local10 dataItem_DeletedPortion)
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#110262b5adda4912928eedd243f5bf67##WebApp;}" local9 local10)
Copy(local9 dataItem_ArrayWithSubsetDeleted)
WaitMilliseconds(local6 * )
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#58099fec38a94a8297cf980d7e70ae5a##WebApp;}" )
Increment(local3 local3 )
Printf("Loop no - ")
Printf("%d\n" local3)
Println("Input 4D Array of String")
Println(c8)
Println("Deleted Array")
Println(dataItem_DeletedPortion)
Println("Output Array")
Println(dataItem_ArrayWithSubsetDeleted)
BranchIfGE(4 local3 local4)
Branch(3)
Perch(4)
Branch(0)
Perch(1)
Branch(0)
Perch(0)
DebugPoint("1;{::VireoDevSystem::Interactive::WebApp::index.gviweb::#e9c42849feb046fabc82ca61e2684d21##WebApp;}" )
/* Clump Ended. */ )
)))
enqueue (WebApp%3A%3Aindex%2Egviweb)
//Finished!! :D
1 change: 1 addition & 0 deletions test-it/testList.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"ArrayDelete.via",
"ArrayDeleteFail.via",
"ArrayDeleteFail2.via",
"ArrayDeleteMultiDimensionString.via",
"ArrayDemo.via",
"ArrayFillNDV.via",
"ArrayFillNDVFail.via",
Expand Down

0 comments on commit f3d254c

Please sign in to comment.