asciimat() should be moved into [m2sci] module. It wrongly manages empty strings and hypermatrices of ascii codes
@sgougeon)
Reported by Samuel GOUGEON (BUG DESCRIPTION:
----------------
asciimat() is a pure internal Matlab conversion function. There is no asciimat() function neither
in Matlab nor in Octave.
Almost all its calls in Scilab are from functions of the M2SCI converter,
mainly from convert2double() that is called by almost all sci_functions.
The very few remaining calls outside [m2sci] are artificial and can be replaced by trivial
ascii() equivalent calls.
This is why asciimat() should be moved into SCI/modules/m2sci/macros/kernel, and its page to
SCI/modules/m2sci/help.
A true distinct Scilab asciiMat() could be implemented for Scilab string objects of distinct lengths
and without horizontal concatenation, if it is required.
asciimat() is aimed to comput an equivalence of the Matlab/Octave +/- operations between char strings
-- not texts -- and numbers, as in
>> ['abc';'def']+0
ans =
97 98 99
100 101 102
But to this respect, the present asciimat() implementation is bugged:
1) The empty char '' is wrongly managed:
--> asciimat(['abc';'';'def']) // yields a transposed result
ans =
97. 98.
99. 100.
101. 102.
while with Matlab as with Octave:
>> ['abc';'';'def']+0
ans =
97 98 99
100 101 102
2) When converting an hypermatrix of ascii codes to strings, the dim#2 of the result is wrongly squeezed:
--> t = cat(3,['abc' 'd';'e' 'fgh'],['ij' 'kl';'mno' 'p'])
t =
(:,:,1)
"abc" "d"
"e" "fgh"
(:,:,2)
"ij" "kl"
"mno" "p"
--> c = asciimat(t) // OK
ans =
(:,:,1)
97. 98. 99. 100.
101. 102. 103. 104.
(:,:,2)
105. 106. 107. 108.
109. 110. 111. 112.
--> asciimat(c) // KO
ans =
"abcd" "ijkl"
"efgh" "mnop"
// Expected:
ans =
(:,:,1)
"abcd"
"efgh"
(:,:,2)
"ijkl"
"mnop"
as with Matlab and Octave:
>> t = cat(3,['abc' 'd';'e' 'fgh'],['ij' 'kl';'mno' 'p']);
>> c = t+0
c =
ans(:,:,1) =
97 98 99 100
101 102 103 104
ans(:,:,2) =
105 106 107 108
109 110 111 112
>> char(c)
ans =
ans(:,:,1) =
abcd
efgh
ans(:,:,2) =
ijkl
mnop
ERROR LOG:
----------
None. Wrong results
HOW TO REPRODUCE THE BUG:
-------------------------
// 1) The empty char '' is wrongly managed:
r = asciimat(['abc';'';'def']) // yields a transposed result
and(r==[97 98 99 ; 100 101 102])
// 2) When converting an hypermatrix of ascii codes to strings, the dim#2 of the result is wrongly squeezed:
t = cat(3,['abc' 'd';'e' 'fgh'],['ij' 'kl';'mno' 'p']);
c = asciimat(t)
r = asciimat(c)
and(size(r) == [2 1 2])
OTHER INFORMATION:
------------------
See also the bug 16438 about supporting UTF-8 characters and input strings of distinct lengths.
Edited by Samuel GOUGEON