Before you head out, which bit of this (for `long-stats`) would get  the `singular?` treatment?


```clojure
  (let [time-step (utils/idx ts)
        X (if (empty? cofactors)
            (i/matrix time-step)
            (apply i/bind-columns time-step cofactors))
        output (try (map second (trend-characteristics ts X))
                    (catch Throwable e
                      (error (str "TIMESERIES ISSUES: " ts ", "
                                  cofactors) e)))]
    (if (string? output)
      [nil nil]
      (vec output))))
```
On Aug 3, 2012, at 10:33 AM, Dan <reply@reply.github.com> wrote:

>> -            focsum-mat (i/mmult focsum (i/trans focsum))]
>> -        (-> (i/solve (i/mult foc-mat (i/nrow ts-mat)))
>> -            (i/mmult focsum-mat)
>> -            (i/trace)))
>> -      (catch Exception e))))
>> +        foc-mat (i/mmult foc (i/trans foc))
>> +        output (try
>> +                 (let [focsum (map i/cumulative-sum foc)
>> +                       focsum-mat (i/mmult focsum (i/trans focsum))]
>> +                   (-> (i/solve (i/mult foc-mat (i/nrow ts-mat)))
>> +                       (i/mmult focsum-mat)
>> +                       (i/trace)))
>> +                 (catch Exception e))]
>> +    (if (string? output)
>> +      nil
>> +      [output])))
> 
> I'm on my way out.  There is a function called `singular?` in the
> `forma.matrix.utils` namespace.  I can work on this in a few hours; but
> can't right now.  It's pretty simple, I think:
> 
> ```clojure
> 
> (if (singular? focsum-mat)
>   [nil nil]
>   ...)
> 
> ```
> 
> On Fri, Aug 3, 2012 at 10:30 AM, Robin Kraft <
> reply@reply.github.com
>> wrote:
> 
>>> -            focsum-mat (i/mmult focsum (i/trans focsum))]
>>> -        (-> (i/solve (i/mult foc-mat (i/nrow ts-mat)))
>>> -            (i/mmult focsum-mat)
>>> -            (i/trace)))
>>> -      (catch Exception e))))
>>> +        foc-mat (i/mmult foc (i/trans foc))
>>> +        output (try
>>> +                 (let [focsum (map i/cumulative-sum foc)
>>> +                       focsum-mat (i/mmult focsum (i/trans focsum))]
>>> +                   (-> (i/solve (i/mult foc-mat (i/nrow ts-mat)))
>>> +                       (i/mmult focsum-mat)
>>> +                       (i/trace)))
>>> +                 (catch Exception e))]
>>> +    (if (string? output)
>>> +      nil
>>> +      [output])))
>> 
>> The occasional singular matrix that should really just be ignored. I'm not
>> sure what the best way to do it is, but these changes are hacks to get
>> around the problem - I'm trying to minimize downtime for this huge cluster
>> processing trends. If the solution is to return to `singular?`, let's do
>> it! I don't remember when/why this changed.
>> 
>> 
>> On Aug 3, 2012, at 10:25 AM, Dan <reply@reply.github.com> wrote:
>> 
>>>> -            focsum-mat (i/mmult focsum (i/trans focsum))]
>>>> -        (-> (i/solve (i/mult foc-mat (i/nrow ts-mat)))
>>>> -            (i/mmult focsum-mat)
>>>> -            (i/trace)))
>>>> -      (catch Exception e))))
>>>> +        foc-mat (i/mmult foc (i/trans foc))
>>>> +        output (try
>>>> +                 (let [focsum (map i/cumulative-sum foc)
>>>> +                       focsum-mat (i/mmult focsum (i/trans focsum))]
>>>> +                   (-> (i/solve (i/mult foc-mat (i/nrow ts-mat)))
>>>> +                       (i/mmult focsum-mat)
>>>> +                       (i/trace)))
>>>> +                 (catch Exception e))]
>>>> +    (if (string? output)
>>>> +      nil
>>>> +      [output])))
>>> 
>>> Wait.  All this is incorrect.  We shouldn't be checking to see if the
>> output is a string -- that distracts from the point of the conditional in
>> the first place.  There are much better ways to do this, given that we know
>> exactly what sort of issue will arise at this step.  We can revert back to
>> the old code with the `singular?` function, and then return two `nil`
>> values.  This need not check for general errors.
>>> 
>>> ---
>>> Reply to this email directly or view it on GitHub:
>>> https://github.com/reddmetrics/forma-clj/pull/193/files#r1303649
>> 
>> ---
>> Reply to this email directly or view it on GitHub:
>> https://github.com/reddmetrics/forma-clj/pull/193/files#r1303682
>> 
> 
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/reddmetrics/forma-clj/pull/193/files#r1303717