Many apologies for the rather chaotic state of AbstractArray and it's implementations. What we have now has grown rather organically and it shows. In the next iteration, we're going to clean all this stuff up and have a clearer hierarchy of array types and a much better separation of low-level indexing that you have to implement from high-level convenience indexing behaviors that are written in terms of those and should apply generically.
On Sun, Jan 26, 2014 at 1:02 PM, John Myles White <[email protected]>wrote: > There’s a lot of built-in functions for showing and displaying > AbstractArrays. Are you extending them? > > Right now AbstractArray implies a slightly underdocumented interface, > which you have to implement before inheriting from AbstractArray will work > right. I’m hopeful this interface will get documented after Julia > stabilizes, but for now I’ve used trial-and-error to figure out what needs > to be implemented. > > — John > > On Jan 26, 2014, at 9:50 AM, Jesse van den Kieboom <[email protected]> > wrote: > > On Sunday, January 26, 2014 5:59:03 PM UTC+1, John Myles White wrote: >> >> Right now this is a little tricky. It’s come up before and will probably >> have some kind of solution in the future. >> >> For now, you might find http://grollchristian.wordpress.com/2014/01/22/ >> julia-inheriting-behavior/ useful. >> > > Thanks, that was an interesting read which addresses exactly what I was > doing. I have a related question, that maybe you (or someone else) can > answer. I have the following type: > > type MotionVector <: AbstractArray{Float64} > v::Array{Float64} > > MotionVector() = (x = new(); x.v = zeros(6, 1); x) > MotionVector(v) = (x = new(); x.v = v; x) > end > > This seems to work, but when I do this, the display(MotionVector()) does > not work anymore, telling me: > > > ERROR: no method display(MotionVector) > > in display at multimedia.jl:158 > > > Without inheriting from AbstractArray{Float64}, this doesn't happen. > > >> >> — John >> >> On Jan 26, 2014, at 8:53 AM, Jesse van den Kieboom <[email protected]> >> wrote: >> >> > Hi all, >> > >> > I'm new to julia, so forgive me for maybe asking something obvious. >> What I would like to do is to create a new type which is basically an >> Array{Float64, 2}, but has some special operations defined as part of the >> vector space that it belongs to. >> > >> > What I currently do is to create a new composite type with one field >> containing the underlying array. This kind of works, but I need to proxy a >> lot of operators (*, -, +, etc) and methods (getindex, setindex!, convert, >> display, ndims, size), which do not need special behavior, to the >> underlying array. >> > >> > Initially, I tried to use a typealias instead of a composite type, but >> it seems the typealias type information is not retained and so I can't >> define new operations on it. Does anyone have a better way to implement >> this? >> >> >
