/*
 *  test_reg_mask_grid_anchor_05.sli
 *
 *  This file is part of NEST.
 *
 *  Copyright (C) 2004 The NEST Initiative
 *
 *  NEST is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  NEST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NEST.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

% to be run by run_test.sli

% expectation:
%   /anchor << /row 5 /column 5 >> 
%   The fictional point (5,5) measured from the top-left corner of the mask towards
%   the bottom right is aligned with each source, i.e., the top left corner of the mask
%   displaced by (-5,-5) relative to the source node, measured in grid coordinates.
%   With a grid origin at (0,0), the "last" node in the 5x5 grid is at (4,4). For
%   connections from this node, the box upper left corner of the 2x3 mask is placed
%   at (-1,-1) and spans to (0,1), i.e., it contains nodes only at (0,0) and (0,1).
%
%    Sources                      Targets
%     2  7 12 17 22    	          28 33 38 43 48
%     3  8 13 18 23		  29 34	39 44 49
%     4	 9 14 19 24		  30 35	40 45 50
%     5	10 15 20 25		  31 36	41 46 51
%     6	11 16 21 26		  32 37	42 47 52
%
%    All connections:
%      21 -> 28
%      26 -> 28 33

/layer << /rows 5
          /columns 5
          /extent [1.25 1.25]
          /center [0. 0.]
          /edge_wrap false
          /elements /iaf_psc_alpha
        >> def

/src_layer layer def
/tgt_layer layer def

/conns << /connection_type (divergent)
          /mask << /grid << /rows 2 /columns 3 >> /anchor << /row 5 /column 5 >> >>
       >> def

/source_layer_ref
[
 [2 -0.5 0.5]
 [3 -0.5 0.25]
 [4 -0.5 0]
 [5 -0.5 -0.25]
 [6 -0.5 -0.5]
 [7 -0.25 0.5]
 [8 -0.25 0.25]
 [9 -0.25 0]
 [10 -0.25 -0.25]
 [11 -0.25 -0.5]
 [12 0 0.5]
 [13 0 0.25]
 [14 0 0]
 [15 0 -0.25]
 [16 0 -0.5]
 [17 0.25 0.5]
 [18 0.25 0.25]
 [19 0.25 0]
 [20 0.25 -0.25]
 [21 0.25 -0.5]
 [22 0.5 0.5]
 [23 0.5 0.25]
 [24 0.5 0]
 [25 0.5 -0.25]
 [26 0.5 -0.5]
]
def

/target_layer_ref
[
 [28 -0.5 0.5]
 [29 -0.5 0.25]
 [30 -0.5 0]
 [31 -0.5 -0.25]
 [32 -0.5 -0.5]
 [33 -0.25 0.5]
 [34 -0.25 0.25]
 [35 -0.25 0]
 [36 -0.25 -0.25]
 [37 -0.25 -0.5]
 [38 0 0.5]
 [39 0 0.25]
 [40 0 0]
 [41 0 -0.25]
 [42 0 -0.5]
 [43 0.25 0.5]
 [44 0.25 0.25]
 [45 0.25 0]
 [46 0.25 -0.25]
 [47 0.25 -0.5]
 [48 0.5 0.5]
 [49 0.5 0.25]
 [50 0.5 0]
 [51 0.5 -0.25]
 [52 0.5 -0.5]
]
def

/conn_ref
[
 [21 28 1 1 -0.75 1]
 [26 28 1 1 -1 1]
 [26 33 1 1 -0.75 1]
]
def

(unittest) run
/unittest using

ResetKernel



/sources src_layer CreateLayer def
/targets tgt_layer CreateLayer def

sources targets conns ConnectLayers

/sources_oss osstream ; def
/targets_oss osstream ; def
/sources_conns_oss osstream ; def

sources_oss sources DumpLayerNodes ;
targets_oss targets DumpLayerNodes ;
sources_conns_oss sources /static_synapse DumpLayerConnections ;

/source_layer_result sources_oss str cst 3 Partition def
/target_layer_result targets_oss str cst 3 Partition def
/conn_result sources_conns_oss str cst 6 Partition def

{
  source_layer_ref source_layer_result eq
} assert_or_die

{
  target_layer_ref target_layer_result eq
} assert_or_die

{
  conn_ref conn_result eq
} assert_or_die

