Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I discovered several strange results and inconsistencies while trying to understand what undocumented RawArray and ArrayObject really are:

image = ImageResize[Import["http://wolfram.com/favicon.ico"][[1]], 1];

rawArray = ToBoxes[image][[1, 1, 1]]
(* RawArray[Byte, <1,1,4>] *)

rawArray // Head
(* RawArray *)

rawArray // Length
(* 2 *)

rawArray // InputForm
(* RawArray["Byte", {{{237, 153, 142, 255}}}] *)

Hold[RawArray]["Byte", {{{237, 153, 142, 255}}}] // Depth
(* 5 *)

rawArray // Depth
(* 2 *)

rawArray[[0]]
(* Part::partd: Part specification RawArray[Byte,<1,1,4>][[0]] is longer than depth of object. >> *)
(* RawArray *)

rawArray[[1]]
(* Part::partd: Part specification RawArray[Byte,<1,1,4>][[1]] is longer than depth of object. >> *)
(* "Byte" *)

arrayObject = rawArray[[2]]
(* Part::partd: Part specification RawArray[Byte,<1,1,4>][[2]] is longer than depth of object. >> *)
(* ArrayObject[Byte, <4>] *)

arrayObject // Head
(* Language`ArrayObject *)

arrayObject // AtomQ
(* True *)

wdx = ExportString[arrayObject, "WDX"];

ImportString[wdx, "WDX"]
(* {{{237, 153, 142, 255}}} *)

% // Head
(* List *)

Uncompress[Compress[arrayObject]]
(* {{{237, 153, 142, 255}}} *)

arrayObject // FullForm
(* List[List[List[237, 153, 142, 255]]] *)

arrayObject // InputForm
(* Raw[Language`ArrayObject, "78c4801b00000000"] *)

inputFormStr = ToString[arrayObject, InputForm]
(* "Raw[Language`ArrayObject, \"78c4801b00000000\"]" *)

heldArrayObject = ToExpression[inputFormStr, InputForm, Hold]
(* Hold[Raw[Language`ArrayObject, "78c4801b00000000"]] *)

heldArrayObject[[1, 0]]
(* Raw *)

heldArrayObject[[1, 1]]
(* Language`ArrayObject *)

heldArrayObject[[1, 2]]
(* "78c4801b00000000" *)

arrayObject2 = ReleaseHold[heldArrayObject]
(* 0 *)

arrayObject2 == 0
(* 0 == 0 *)

% // FullForm
(* Equal[1, 0] *)

ToBoxes[arrayObject2]
(* 0 *)

% // Head
(* Integer *)

arrayObject2 // Head
(* Language`ArrayObject *)

arrayObject2 // AtomQ
(* True *)

wdx = ExportString[arrayObject2, "WDX"];

reimported = ImportString[wdx, "WDX"]

(* Raw::string: String expected at position 2 in Raw[Language`ArrayObject,78 c4801b00000000]. >> *)
(* Raw[Language`ArrayObject, 78 c4801b00000000] *)

reimported // FullForm
(* Raw[Language`ArrayObject, Times[78, c4801b00000000]] *)

reimported // AtomQ
(* False *)

reimported // Depth
(* 3 *)

Uncompress[Compress[arrayObject2]]
(* "<---RAW DATA--->" *)

% // Head
(* String *)

Note that Part reports errors when invoked on a RawArray, but still is able to extract parts. ArrayObject has completely different representation in InputForm and FullForm, and turns into a List when reimported.

Is this behavior normal? Or there are some bugs? Is it because these parts were not supposed to ever be seen by humans?

Are there situations when one needs to explicitly construct or manipulate by RawArray or ArrayObject expressions? What is their real meaning?

share|improve this question
    
An image in Mathematica is already indivisible! Try AtomQ[image] on your favicon. I assume the user is not supposed to use/see/care-about RawArray's. –  halirutan Jun 24 '13 at 11:00
    
Can you make your question specific, rather than simply asking for comments? –  m_goldberg Jun 24 '13 at 13:08
    
@m_goldberg Sorry, I was so surprised by results, that forget the rules. I formulated explicit questions that I'm interested in. Thanks! –  Vladimir Reshetnikov Jun 24 '13 at 17:19
1  
I believe that this is not supposed to be used because Image (and the underlying arrays) are highly optimized for speed. Otherwise there would clearly be any documentation and someone would have used it in all the packages which come with Mathematica. Anyway, have you seen image[[1, 2]] //Language`FromArrayObject and Language`NewArrayObject["Byte", {1, 2, 3, 4, 5, 5}]? –  halirutan Jun 24 '13 at 18:40
1  
I'm fairly sure that an ArrayObject is literally just a thin wrapper around a C array that records its type and dimensions so that these can be passed around between the different image processing functions. AFAIK, there aren't any functions provided in the top-level language for manipulation of the RawArray type. –  Oleksandr R. Jun 24 '13 at 19:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.