update on distribshape function

distribshape =: (] [`(i:&_@])`]}~ ( :: [) [ % _ */@:-.~ ])~

does not need to cover multiple _ s with 1s.  If caller wants 1s in shape 
somewhere, he can include them in pattern.  If they call it with multiple _ s, 
just fill rightmost one, rather than "question it" 

1 6 _ distribshape 24

1 6 4

1 _ _ 6 2 distribshape 24

1 _ 2 6 2





On Tuesday, August 18, 2020, 08:35:45 p.m. EDT, 'Pascal Jasmin' via Programming 
<[email protected]> wrote: 





the part of the proposal that produces an error if the provided shape is not 
divisible in item count is not obvious compared to filling.

A function that distributes a "product" over a template with _ to fill in:

distribshape =: (] [`(i:&_@])`]}~ ( :: [) [ % _ */@:-.~ ])(^:_)


   2 _ 6 distribshape 24

2 2 6

 _ 6 _ distribshape 24

1 6 4

_ 2 _ 6 distribshape 25

1 2 2.08333 6


can be refined to remove 1s, or either round up to next integer or let $ return 
an error if you attempt to use it with floating value.

I think this function is more useful as a "core" shape generator than hard 
coding what to do in edge cases of the proposal.


On Tuesday, August 18, 2020, 07:51:03 p.m. EDT, Henry Rich 
<[email protected]> wrote: 





This is a proposed change only to dyad and $ , is that right?

What problem does this solve?

Henry Rich

On 8/18/2020 6:18 PM, David Lambert wrote:
> Proposal to allow a single infinity in the shape.  This model doesn't
> consider empty arrays or other issues I'm unaware of.  If infinity is in
> the shape, the product of the defined ranks must be a factor of the tally
> of y .
>
> reshape=: dyad define
>  shape=. x
>  if. _ -.@e. shape do.
>    shape $ y
>    return.
>  end.
>  error=. 13!:8
>  valueError=. 21
>  vector=. , y  NB. or <"_1 followed by unboxing
>  if. 1 < +/ _ = shape do.
>    'at most one replacement' error valueError
>  end.
>  f=. (# vector) % (*/ shape -. _)
>  if. (~: <.) f do.  NB. f must be integral
>    'shape mismatch' error valueError
>  end.
>  shape =. f (shape i. _)} shape
>  shape $ vector
> )
>    _ 4 reshape i. 6
> |shape mismatch: error
> |  'shape mismatch'    error 21
>
>    _ _ 2 reshape 'abcd'
> |at most one replacement: error
> |  'at most one replacement'    error 21
>
>    2 _ reshape i. 6
> 0 1 2
> 3 4 5
>
>    _ 2 reshape i. 6    NB.    _2 [\ i. 6
> 0 1
> 2 3
> 4 5
>
>    _ 2 $ i.6
> |domain error
> |  _ 2    $i.6
>
>    NB. while we're at it, permit negative shape values akin to integers
> (i.).
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm


-- 
This email has been checked for viruses by AVG.
https://www.avg.com



----------------------------------------------------------------------
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