Fixed ComposeChannels and bugs with num_channels()

num_channels() is now a bit hacky, but necessary.  Also, the case where it is called without having an image generated first is very narrow and usually happens at most once, at initialization (when it's necessary to know, beforehand, the number of channels of the inputs, in order to construct the higher structures)

I don't think so, because the first time it's set is on loading, which
happens on _get_image().

The other possibility would be to "pre-load" the images in init(), which in
the *specific case* of FileImage is reasonable, as we're enforcing a strong
cache, but otherwise it would be expensive in computation and memory,
maybe?




On Sat, Jul 19, 2014 at 4:45 PM, James A. Bednar <notifications@github.com>
wrote:

> In imagen/patterngenerator.py:
>
> > @@ -375,9 +375,16 @@ def channels(self, **params_to_override):
> >          return res
> >
> >      def num_channels(self):
> > +        if( len(self._channel_data)==0 ):
> > +            import copy
> > +            c = copy.deepcopy(self)
> > +            return len(c.channels())-1
> > +
> > +
> >          return len(self._channel_data)
>
> Is there no way to make sure _channel_data is defined before this?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/ioam/imagen/pull/32/files#r15144284>.
>