Issue 46681 - ODFF: Repeat values of single array vector if used in second array dimension
Summary: ODFF: Repeat values of single array vector if used in second array dimension
Status: CLOSED FIXED
Alias: None
Product: Calc
Classification: Application
Component: programming (show other issues)
Version: 680m87
Hardware: All All
: P3 Trivial (vote)
Target Milestone: ---
Assignee: oc
QA Contact: issues@sc
URL:
Keywords:
: 27656 54581 54885 59973 63166 92402 95176 96682 (view as issue list)
Depends on:
Blocks: 72764
  Show dependency tree
 
Reported: 2005-04-05 09:44 UTC by daniel.rentz
Modified: 2013-08-07 15:14 UTC (History)
3 users (show)

See Also:
Issue Type: ENHANCEMENT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
more examples (13.50 KB, application/vnd.ms-excel)
2005-11-28 12:16 UTC, daniel.rentz
no flags Details
Changed a few functions, just for checking. (11.00 KB, text/plain)
2008-05-06 09:35 UTC, lvyue
no flags Details
patch 2. (17.06 KB, text/plain)
2008-06-03 08:50 UTC, lvyue
no flags Details
patch 3. (21.58 KB, text/plain)
2008-06-11 02:53 UTC, lvyue
no flags Details
patch4. Filled the regions that remain after copying. (22.04 KB, text/plain)
2008-06-12 03:37 UTC, lvyue
no flags Details
patch 5. :) (22.63 KB, text/plain)
2008-07-02 08:45 UTC, lvyue
no flags Details
patch 6, slightly changed from patch 5. (22.63 KB, text/plain)
2008-08-13 04:53 UTC, lvyue
no flags Details
fixes, enhancements and comments (31.42 KB, patch)
2008-08-27 14:03 UTC, ooo
no flags Details | Diff
TestCaseSpecification (6.36 KB, text/html)
2008-12-17 09:53 UTC, oc
no flags Details
Testdocuments for Test Case Specification (7.00 KB, application/vnd.ms-excel)
2008-12-17 09:55 UTC, oc
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description daniel.rentz 2005-04-05 09:44:33 UTC
Following test case:

A1: 1   B1: 1   C1: 2
A2: 2   B2: 1   C2: 2
A3: =SUM(IF(A1:A2<2;B1:C2;0))

Result is 1 (B1 only), but should be 3 (sum of B1:C1).
Comment 1 ooo 2005-04-05 12:06:13 UTC
Excel replicates a single column or row vector to cover further columns or rows
of a matrix in calculations. This is independent of conditional array
calculation and also done for ordinary operators and functions. The behavior is
currently not implemented in Calc.
Comment 2 ooo 2005-05-12 11:13:59 UTC
Need more time to investigate feasibility, retargeting to OOo2.0.2
Comment 3 ooo 2005-09-14 11:33:47 UTC
Adapting summary to reality.
Comment 4 ooo 2005-09-14 11:43:06 UTC
*** Issue 54581 has been marked as a duplicate of this issue. ***
Comment 5 ooo 2005-09-22 15:44:09 UTC
*** Issue 54885 has been marked as a duplicate of this issue. ***
Comment 6 daniel.rentz 2005-11-28 12:16:25 UTC
Created attachment 31857 [details]
more examples
Comment 7 ooo 2005-11-29 17:23:22 UTC
This will not be a small change and should not be done for OOo2.0.2.
Comment 8 frank 2006-02-01 14:30:13 UTC
*** Issue 59973 has been marked as a duplicate of this issue. ***
Comment 9 frank 2006-04-05 12:50:06 UTC
*** Issue 63166 has been marked as a duplicate of this issue. ***
Comment 10 drking 2008-03-02 19:54:33 UTC
In the ODFF draft 28Dec07 page 42 is:
2.2.3.2) If the argument data is 1 column wide the value in the corresponding 
row is used to evaluate all columns in the result matrix.
= {1|2} + {10;20|30;40}	=> {11;21|32;42}

whereas Calc returns {11|32}

Is this the same issue? Meaning it needs flagging for ODFF compliance?

Comment 11 ooo 2008-03-03 11:56:06 UTC
Yes, this is about that ;)  Adding ODFF to summary.
Comment 12 lvyue 2008-05-06 09:35:50 UTC
Created attachment 53407 [details]
Changed a few functions, just for checking.
Comment 13 lvyue 2008-05-09 12:55:58 UTC
Hi Eike,
I have a question about my system, but I'm not in office, so I can only ask you 
here. :)
I'm thinking about switching my operating system to Linux, and change the 
milestone together.
But there are so many Linux, I wonder which is better for our development, and 
which one are you using.
And about ODFF, which milestone should I use? 
I hope I didn't bring you many trouble. :P
Thank you! :)
Yue
Comment 14 ooo 2008-05-09 22:09:38 UTC
Strange request ;-)  anyway, replied per mail.
Comment 15 lvyue 2008-06-03 08:50:12 UTC
Created attachment 54198 [details]
patch 2.
Comment 16 lvyue 2008-06-03 08:59:53 UTC
Hi Eike,
In patch 2, I made some change for IF().
Applied the dynamic way to decide dimensions.
the biggest change is in class ScJumpMatrix, I don't know if 
such change is acceptable.
It works well in IF() now. :)
Please check this patch.
Thanks.
         Yue
Comment 17 ooo 2008-06-03 22:58:39 UTC
Hi Yue,

The approach looks viable in general. Some comments:

In real life (see remarks further down about copying methods), the
implementation of SetNewResMat() in the final version should not be in
the header file, but in a newly to be created jumpmatrix.cxx instead.
Header files should contain only relatively short inline methods. The
nested for() loops wouldn't necessarily be inlined by most compilers
anyway. The method is also quite rarely called, so we wouldn't gain
anything but increase compile time instead each time the header file is
parsed.


Instead of

    ScMatrix* pNewMat = new ScMatrix(...
    [...]
    ScMatrix* p = pMat;
    pMat = pNewMat;
    p->Delete();

use

    ScMatrixRef xNewMat = new ScMatrix(...
    [...]
    pMat = xNewMat;

Reason is that ScMatrixRef does refcount the ScMatrix, the pMat member
variable is also a ScMatrixRef, and by directly calling Delete() on the
pointer you interfere with the refcounting mechanism and may actually
doubly delete the matrix that was already released during the assignment
to pMat.


The copying code

    for (SCSIZE nC = 0; nC < nResMatCols; nC++)
        for (SCSIZE nR = 0; nR < nResMatRows; nR++)

is error prone; in case we added more type functionality to ScMatrix it
would had to be adapted and might easily get overlooked. It already
omits the IsEmptyPath() case ;-)

Better create a ScMatrix member method that copies the desired portion
similar to ScMatrix::MatCopy(), which would be faster as well. If you
also add a method ScMatrix::CloneAndExtend(nNewCols,nNewRows) or so,
similar to ScMatrix::Clone(), most code of ScJumpMatrix::SetNewResMat()
could be moved into these two methods, and SetNewResMat() could remain
inline in the header file.


Btw, last nitpick for now is a spelling error, Ajust should be written
with a 'd': Adjust ;)

Hope that helps.

  Eike
Comment 18 ooo 2008-06-04 10:01:20 UTC
This may need more time than available until QA for 3.0 code freeze, retargeting
to 3.1
Comment 19 lvyue 2008-06-11 02:53:45 UTC
Created attachment 54383 [details]
patch 3.
Comment 20 lvyue 2008-06-11 03:46:38 UTC
Hi Eike,
This is the third patch, including all the changes I made.
And, so far, I found these affected functions:
+, -, * , /, ^, &, =, <>, >, <, >=, <=, TRANSPOSE(), and IF().
Please check this patch.
Thanks.

PS: I have add 'd' to 'Ajust'. :P

  Yue
 
Comment 21 lvyue 2008-06-12 03:37:27 UTC
Created attachment 54412 [details]
patch4. Filled the regions that remain after copying.
Comment 22 lvyue 2008-07-02 08:45:14 UTC
Created attachment 54878 [details]
patch 5. :)
Comment 23 Regina Henschel 2008-08-02 15:37:54 UTC
*** Issue 92402 has been marked as a duplicate of this issue. ***
Comment 24 ooo 2008-08-04 12:40:05 UTC
Issue 92402 has another fine test case example attached,
http://www.openoffice.org/nonav/issues/showattachment.cgi/55506/Issue%2092402.ods
Comment 25 lvyue 2008-08-13 04:53:29 UTC
Created attachment 55731 [details]
patch 6, slightly changed from patch 5.
Comment 26 ooo 2008-08-27 14:01:45 UTC
@lvyue: I'll attach a patch created against CWS odff05 based on
DEV300_m29, please checkout CWS odff05 and continue further work based
on the new patch. As discussed on IRC, please investigate interpreter
methods whether special handling similar to MatAdd() and such is needed
for other functions as well.

Changes I did in the patch:

In ScInterpreter::JumpMatrix() the conditions to check for replication
were overcomplicated, at least in the case of svMatrix that was wrong
and lead to access of invalid matrix positions. Btw, this was caught by
an assertion about a matrix dimension error, I strongly suggest you use
a non-product build to get assertions displayed, please invoke configure
with --enable-dbgutil before a clean build from scratch.

I changed the condition, for example, to

    if ((nCols <= nC && nCols != 1) ||
        (nRows <= nR && nRows != 1))

to catch the case for NOTAVAILABLE, also changed errNoValue to
NOTAVAILABLE for these cases to be consistent with MatRef() and Excel.
Similar for svDoubleRef, also the original range must not be changed by
using
    ScAddress& rAdr = aRange.aStart;
    rAdr.SetCol(...);
see also the comments I added there.

Introduced ScMatrix::ValidColRowOrReplicated(nCol,nRow) to replace
    (ValidColRow(nCol,nRow) || ValidColRowReplicated(nCol,nRow))
for better readability and less typing effort ;-)

Simplified the conditionals in ValidColRowReplicated(), some checks were
done twice. Same in ScJumpMatrix::GetJump(), also added cleanup and an
assertion there for the case that invalid nCol/nRow was passed,
otherwise arbitrary memory could had been accessed in pJump[].

In interpr5.cxx introduced lcl_GetMinExtent() to not repeat all the
conditionals for nMinC=..., nMinR=... over and over again in MatAdd()
and the like.

Looking forward to your findings whether further changes are necessary
in other interpreter functions.

Thanks
  Eike
Comment 27 ooo 2008-08-27 14:03:14 UTC
Created attachment 56049 [details]
fixes, enhancements and comments
Comment 28 ooo 2008-08-27 14:07:23 UTC
@lvyue: forgot to mention that I also negated the logic in
ScInterpreter::ScMatRef() to simplify the condition for the PushNA().
Comment 29 lvyue 2008-09-09 09:52:26 UTC
Hi Eike,
I have checked all functions in ScInterpreter that call Put... and Get...
and I did not find a function that need to be changed.
Comment 30 ooo 2008-09-10 23:31:05 UTC
Hi Yue, great! I think I did not mention it explicitly, but did you also check
for places that use IsEmpty(), IsEmptyPath(), IsString(), IsValue() and such ,
without Get...() being near around?

Anyway, I applied the latest revision of the patch in cws odff05:

sc/inc/scmatrix.hxx  1.11.148.1
sc/source/core/inc/jumpmatrix.hxx  1.6.148.1
sc/source/core/tool/interpr1.cxx  1.60.54.1
sc/source/core/tool/interpr5.cxx  1.33.36.1
sc/source/core/tool/scmatrix.cxx  1.17.136.1

maybe this will need some further correction for new findings. Please cvs update
your cws odff05 and base new patches on the update.

Thanks
  Eike
Comment 31 lvyue 2008-09-11 02:47:41 UTC
Hi Eike,
yes, I checked those Is...().
since they are changed, I thought they should also be checked.
don't worry. :)

  Yue
Comment 32 ooo 2008-09-11 11:10:08 UTC
FYI: cleaned up naming, meaning and usage of ScMatrix::Is...Type(ScMatValType)

sc/inc/scmatrix.hxx  1.11.148.2
sc/source/core/data/validat.cxx  1.24.110.1
sc/source/core/tool/interpr1.cxx  1.60.54.2
sc/source/core/tool/interpr4.cxx  1.57.98.1
sc/source/core/tool/interpr5.cxx  1.33.36.2
sc/source/core/tool/scmatrix.cxx  1.17.136.2
sc/source/filter/excel/xehelper.cxx  1.31.148.1
sc/source/filter/xml/XMLExportDDELinks.cxx  1.18.148.1

Please cvs update your CWS.
Comment 33 ooo 2008-09-16 11:20:09 UTC
*** Issue 27656 has been marked as a duplicate of this issue. ***
Comment 35 ooo 2008-10-23 14:48:24 UTC
*** Issue 95176 has been marked as a duplicate of this issue. ***
Comment 37 lvyue 2008-10-24 02:29:47 UTC
Tested issue 95176, the result is right in the version with patch of i46681. :)
Comment 38 niklas.nebel 2008-11-28 11:19:46 UTC
*** Issue 96682 has been marked as a duplicate of this issue. ***
Comment 39 ooo 2008-12-09 13:53:38 UTC
Fixed in CWS odff05.
Comment 40 ooo 2008-12-11 14:22:57 UTC
Reassigning to QA for verification.
Comment 41 oc 2008-12-17 09:53:56 UTC
Created attachment 58880 [details]
TestCaseSpecification
Comment 42 oc 2008-12-17 09:55:08 UTC
Created attachment 58881 [details]
Testdocuments for Test Case Specification
Comment 43 oc 2008-12-17 09:55:46 UTC
verified in internal build cws_odff05
Comment 44 amy2008 2009-04-14 08:01:39 UTC
Verified in Ooo310m9 on WinXP and Fedora
Closing
Li Meiying