[GSoC Neural network] Updates and question about classdef

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

[GSoC Neural network] Updates and question about classdef

Enrico Bertino
Hi everybody,

In this first period of GSoC I have been working on two sides: making the basic structure of the package in Octave and familiarizing with Tensorflow. You can find the posts on my blog [1]. 

Regarding the first part, I implemented the package classes with classdef and I don't know if I went in the right direction. It would be great if you can give me a feedback about it!

My goal was creating an object by the concatenation of other objects. For example let Class1 be a class with a property foo, doing

  A = class1() 
  B = class1() 
  C = [A B] 

could create a class2 object and I would be able to do

  C(1)        to access A,
  C(2)        to access B,
  C(1).foo    to access A.foo .

For doing the concatenation, I overloaded the horzcat, vertcat, cat methods of class1 in which I simply call the constructor of class2.

    function obj = horzcat (obj1, varargin)
        obj = class2(obj1, varargin{:});

In class2 I store the class1 objects in a struct property (let's call it bar). So I had to overload subsref, replacing the '()' access to the obejct with the '{}' access to bar in order enable commands like C(1).foo .

This is the way I thought about implementing class2:

classdef class2 < handle
    properties (Access = private)
        bar = {};
    methods (Hidden, Access = {?class1})
        function this = class2 (varargin)
            this.bar = cell(1, nargin);
            for i = 1:nargin
                this.bar{i} = varargin{i};
        function obj = subsref(this, idx)
            switch idx(1).type
                case '()'
                    idx(1).type = '{}';
                    obj = builtin('subsref', this.bar, idx);
                case '{}'
                    error('{} indexing not supported');
                case '.'
                    error('. indexing not supported');

Is this the right way to do it?

The problem is that when I try to access more than one property, it does not work:

C(1:2) gives me the same result of C(1) 

Have you any suggestion for fixing it?

Thank you,