And, on that note, I have noticed ~. has sometimes been slow on
moderately large datasets (1e7 < #)

One tactic that might help for getting a small nub might be to sort
and then look for where it changes.

I hope this helps,

-- 
Raul


On Thu, Apr 5, 2018 at 4:38 AM, R.E. Boss <[email protected]> wrote:
> My strategy in efficiently converting a lot of dates: restrict to the nub. No 
> one has more than a few thousand dates.
> Just my 2c.
>
>
> R.E. Boss
>
>
>> -----Original Message-----
>> From: Programming <[email protected]> On
>> Behalf Of Jimmy Gauvin
>> Sent: donderdag 5 april 2018 04:40
>> To: [email protected]
>> Subject: Re: [Jprogramming] converting date number to iso 8601
>>
>> I played around with this a bit more and arrived at something much faster
>> than my initial approach which is in fact pretty slow.
>>
>> Raul :
>>
>> 6!:2 'daten28601 5e6 $ 20180102'
>> 1.40457
>>
>> My first take :
>>    6!:2 ' ff("0) 5e6 $ 20180102'
>> 87.6379
>>
>> My second take:
>>
>>
>> 6!:2 'fff("0) 5e6 $ 20181122'
>>
>> 5.19095
>>
>>
>>
>>    ff  =: 3 : '''-'' 4 7 } 1 1 1 1 2 1 2 1": 10#.inv y'
>>
>>    fff =: 3 : '''0123456789-''{~0 0 0 0 10 0 0 10 0 0+10 10 10 10 1 10 10
>> 1 10 10#: y'
>>
>>
>>
>>
>> A variant on Raul's method is to use expand rather than copy (expand is
>> slower though).
>>
>> b&#^:_1 where b is a boolean list is *Expand* (whose fill atom f can be
>> specified by *fit*, b&#^:_1!.f or #^:_1!.f )
>>
>>
>>    ]DYP=: -. (i.10)e.4 7
>> 1 1 1 1 0 1 1 0 1 1
>>    daten28602=: DYP #^:_1!.'-'"1 ":@,.
>>
>>
>>
>>
>> On Wed, Apr 4, 2018 at 7:08 PM, Joe Bogner <[email protected]> wrote:
>>
>> > Raul, that is great. I have used # thousands of times probably but
>> > never encountered this use
>> >
>> > "The complex left argument a j. b copies a items followed by b fills.
>> > The fit conjunction provides specified fills, as in #!.f ."
>> >
>> > http://www.jsoftware.com/help/dictionary/d400.htm
>> >
>> >
>> > I'm glad I asked because something simple like this uncovers new ways
>> > of thinking
>> >
>> > Jimmy - Same goes for yours too. Raul's approach is much speedier
>> > however yours highlighted an interesting technique for the future.
>> >
>> > Thank you both
>> >
>> > On Wed, Apr 4, 2018 at 6:18 PM, Jimmy Gauvin <[email protected]>
>> > wrote:
>> > > This might be fast :
>> > >
>> > > '-' 4 7 } 1 1 1 1 2 1 2 1 ": 10#.inv 20170209
>> > >
>> > > 2017-02-09
>> > >
>> > >
>> > > On Wed, Apr 4, 2018 at 6:04 PM, Raul Miller <[email protected]>
>> > wrote:
>> > >
>> > >> Here's one approach:
>> > >>
>> > >>
>> >
>> > DXP=: (8#1) j. (i.8)e.3 5
>> > >>
>> >
>> > daten28601=: DXP #!.'-'"1 ":@,.
>> > >>
>> > >>
>> >
>> > 6!:2 'daten28601 (5e6 1 $ 20180102)'
>> > >> 0.659381
>> > >>
>> > >> --
>> > >> Raul
>> > >>
>> > >> On Wed, Apr 4, 2018 at 5:56 PM, Joe Bogner <[email protected]>
>> wrote:
>> > >> > I'm curious if there is a speedier way to convert a date stored
>> > >> > as a number like 20180101 or 20170228 to the ISO 8601 equivalent:
>> > >> >
>> > >> > This does OK
>> > >> >
>> > >> >    datenumToISO =: 3 : 0
>> > >> > (4&{. , '-' , 2&{.@(4&}.) , '-' , _2&{.)"1 ": y
>> > >> > )
>> > >> >
>> > >> > datenumToISO 20180101
>> > >> > 2018-01-01
>> > >> >    datenumToISO 20180228
>> > >> > 2018-02-28
>> > >> >
>> > >> >
>> > >> > But is slower than I'd like ... no big deal but just curious
>> > >> >
>> > >> > 6!:2 'datenumToISO (5e6 1 $ 20180102)'
>> > >> > 4.29083
>> > >> >
>> > >> > sprintf is slow
>> > >> >
>> > >> > dateNumToISO2 =: 3 : 0
>> > >> > '%d-%02d-%02d' sprintf ,:(0 100 100 #: y)
>> > >> > )
>> > >> >
>> > >> >    (6!:2) 'dateNumToISO2 (1e5 # 20180102)'
>> > >> > 2.34002
>> > >> >    (6!:2) 'dateNumToISO2 (1e6 # 20180102)'
>> > >> > 25.4977
>> > >> >
>> > >> >
>> > >> > 8!:2 shows promise but I can't figure out the formatting string
>> > >> > to add a leading zero if it's possible
>> > >> >
>> > >> > (6!:2) '8!:2 (0 100 100 #: (5e6 # 20180102))'
>> > >> > 1.4853
>> > >> >
>> > >> > 'q<->,q<->,d' 8!:2 (0 100 100 #: (1 # 20180102))
>> > >> > 2018-1-2
>> > >> > ------------------------------------------------------------
>> > ----------
>> > >> > 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
>> > ----------------------------------------------------------------------
>> > 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to