Interesting.  Don't have access to a J interpreter right now, but could we 
express this along the lines of

    At=: ((,'@') <@; <)@,"0

   conv2 =:  +//. At ($:"_1 _`(*/))@.(1...@$@[)

Even if it's this simple, I'm surprised we require the recursion, given J's 
native array capabilities.

-Dan



Please excuse typos; composed on a handheld device.

-----Original Message-----
From: "R.E. Boss" <[email protected]>
Date: Wed, 3 Mar 2010 16:05:24 
To: 'Programming forum'<[email protected]>
Subject: Re: [Jprogramming] convolution

> Van: [email protected] [mailto:programming-
> [email protected]] Namens Aai
(...)
> 
> Not a general solution, but the 3 convolutions can be computed as follows.
> 
> pp=: +//.@(*/)       NB. 1D
> 
> ppp=: +//.@(pp"1/)   NB. 2D
> 
> pppp=: +//.@(ppp"2/) NB. 3D
> 
> 
> 1D
>    h (conv-:pp) f
> 1
> 
> 2D
>    h (conv-:ppp) f
> 1
> 
> 3D
>    h (conv-:pppp) h
> 1


Nice solution.

conv1=: 4 : 0
if. 1 = #$x do. x +//.@(*/) y return. end.
t=.<:#$x
x +//.@ (conv1 "t/) y
)

   g1-:h1 conv1 f1
1

   g2-:h2 conv1 f2
1

   g3-:h3 conv1 f3
1

see below for hi, fi, gi


R.E. Boss


h1=: _8 2 _9 _2 9 _8 _2
f1=: 6 _9 _7 _5
g1=: _48 84 _16 95 125 _70 7 29 54 10

h2=:".;._2]0 :0
 _8  1 _7 _2 _9  4
  4  5 _5  2  7 _1
 _6 _3 _3 _6  9  5
)

f2=:".;._2]0 :0
 _5  2 _2 _6 _7
  9  7 _6  5 _7
  1 _1  9  2 _7
  5  9 _9  2 _5
 _8  5 _2  8  5
)
g2=:".;._2]0 :0
  40  _21  53   42  105    1  87   60   39 _28
 _92  _64  19 _167  _71  _47 128 _109   40 _21
  58   85 _93   37  101  _14   5   37  _76 _56
 _90 _135  60 _125   68   53 223    4  _36 _48
  78   16   7 _199  156 _162  29   28 _103 _10
 _62  _89  69  _61   66  193 _61   71   _8 _30
  48   _6  21   _9 _150  _22 _56   32   85  25
)

h3=:_3[\".;._2]0 :0
_6 _8 _5  9
_7  9 _6 _8
 2 _7  9  8
 7  4  4 _6
 9  9  4 _4
_3  7 _2 _3
)
f3=: _2[\".;._2]0 :0
_9  5 _8
 3  5  1
_1 _7  2
_5 _6  6
 8  5  8
_2 _6 _4
)
g3=: _4[\".;._2]0 :0
 54   42   53  _42   85  _72
 45 _170   94  _36   48   73
_39   65 _112  _16  _78  _72
  6  _11   _6   62   49    8
_57   49  _23   52 _135   66
_23  127  _58   _5 _118   64
 87  _16  121   23  _41  _12
_19   29   35 _148  _11   45
_55 _147 _146  _31   55   60
_88  _45  _28   46  _26 _144
_12 _107  _34  150  249   66
 11  _15  _34   27  _78  _50
 56   67  108    4    2  _48
 58   67   89   32   32   _8
_42  _31 _103  _30  _23   _8
  6    4  _26  _10   26   12
)


> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to