• JonB

    UIApplication.sharedApplication().keyWindow().rootViewController().showAccessoryWithAnimationDuration_(1)

    Is the equivalent of show_console. It certainly works with editor or panel, but very well might not work with fullscreen or sheet.

    What could work would be to find the view that contains the fullscreen view (by walking up the heirarchy in objc), and just shift the frame so it is partially off the screen, enough to get to underlying console. You may need to go up a few levels, as there may be some "shield" views. Basically, find the common ancestor to the console view and the presented fullscreen view, then resize the child leg that contains the presented view.

    I could be totally wrong.. it might be some kind of modal view controller that will prevent any other interaction.

    I usually use panel for this sort of thing -- you get the extra titlebar stuff, but you can easily go back and forth to console.

    posted in Pythonista read more
  • JonB

    Take a look at (here](https://github.com/dgelessus/pythonista_startup/blob/master/_preflight_hook_experiment.py)
    And also
    Here
    at line 39
    The first let's you register hooks that get called very early in preflight. I suppose you could check for your UI, and if present, raise an Exception, thus killing preflight. (I'm not 100% sure that's work).

    Option 2 uses the DirAllTheGlobals trick to patch pythonista_startup's dir to return everything in main -- since preflight checks if each variable is in pythonista_startup.

    I'd think you could also create a custom importer, that forced all imports into pythonista_startup where it would be safe, or maybe have a system to "register" required imports/globals associated with an app, that can be cleared when app closes

    posted in Pythonista read more
  • JonB

    Iirc, @dgelessus figured out a way to bypass the preflight altogether. I can't find that thread right now, I think it involved hijacking a call that happened within preflight.. this might be an option in his pythonista_startup.

    You probably know all this, but from another thread, here are some methods to avoid module and or variables getting cleared:

    ##ways to keep modules from clearing:

    1. for modules, delete file
      e.g
       import mymodule
       del mymodule.__file__
    

    now mymodule is not removed from sys.modules

    1. create name staring with dunder__
    import mymodule
    sys.modules['__mymodule']=sys.modules['mymodule']
    
    1. set file access to nonwritable
    chmod(mymodule.__file__,0xo444)
    
    1. place module in site-packages

    ##ways to keep global vars from being cleared
    1.start variable with __
    __myglobalvar=4
    2.add to pythonista_startup
    myglobalvar=4
    import pythonista_startup

    pythonista_startup.myglobalvar=myglobalvar

    1. for things like ui.Views, threads, which needs to reference itself, but does not need to be refernced externally, etc it is sufficient to simply add the var to an existing builtin module

      try:
      ui.mysavedviews.append(myview)
      except NameError:
      ui.mysavedviews=[myview]

    retain_global is another way.

    other thoughts

    For modules getting cleared out from under you, the only practical solution iirc is that every function must import what it needs. That's what stash does, and it can survive anything (I think including pythonista://). It is really tedious-- basically anything that can get called after your initial launch cannot rely on modules being imported at the file/module level. Instead, each def must import modules it uses. There is not a great way to check that you remembered everything.

    posted in Pythonista read more
  • JonB

    Ok, the other problem.. it seems to me that you are doing a (5,784) dotted with a 784,1, for the first loop. Dot should broadcast on its own (if training data is (N,784,1), I think, though perhaps you might need tensordot.

    But then second iteration, you try to multiply a 10,5 by the 784,1...

    Instead you need to store the current result as a separate variable.

    Maybe

    def predict (self,a):
       layer_output=a
       for [w,b] in zip(self.weights,self.biases)
          layer_output=self.activation(
                                 np.dot(w,layer_output)+b)
       return layer_output
    

    Which I think should give an out sized (N,10) if a is sized (N,784)

    Or perhaps

    def predict (self,a):
       output=np.array([])
       for data in a:
          layer_output=data
          for [w,b] in zip(self.weights,self.biases)
             layer_output=self.activation(
                                 np.dot(w,layer_output)+b)
          output.append(layer_output)
    

    in case broadcasting doesn't work(but it should, and will be loads faster than a loop)

    posted in Pythonista read more
  • JonB

    Is

    for a in a:
    a = self.activation(np.dot(w, a))+b

    valid? I'd think you would want another variable name or two, to be unambiguous. Might work, just looks suspect, and depends on perhaps some arcane scoping rules if it does. You are using a as the input variable (a list of 784,1 arrays), then as a single iterator (a 784,1) then assigning a value to that same variable name... Use three different names!

    Have you tried printing the shape of a? Is training_images an array of (784,1) ndarrays?

    posted in Pythonista read more
  • JonB

    Actually on second look, matmul was introduced in 1.10.0, but current pythonista has 1.8.0.

    https://github.com/omz/Pythonista-Issues/issues/533

    posted in Pythonista read more
  • JonB

    Make sure you are using python3 interpreter -- I think the @ operator was introduced in 3.5. are you getting a syjtax erro with @?

    In any case, @/matmul should be th same as .dot, so if none of these work, that suggests you have other problems, like incorrectly sized arrays. Check .shape -- if first matrix is (n,m), second should be (m, p).

    Are you using numpy arrays or matrix? You could also convert to matrix (.asmatrix()) then use regular *.

    It would be helpful if you copy/paste the code and error you are getting.

    posted in Pythonista read more
  • JonB

    A primative turtle module comes built into pythonista, just import turtle and start playing.

    See also
    https://forum.omz-software.com/topic/5014/shape-method-for-turtle-py

    posted in General Discussion read more
  • JonB

    It might be a good idea to compile it once, copy it to a regular location, then delete the tmp file. That's what Apple recommends

    If you run the code that does a fresh compile every time, you will quickly fill up the tmp storage. I'm not how reliable the cleaning of tmp files is.

    posted in Pythonista read more
  • JonB

    https://alexsosn.github.io/ml/2017/06/09/Core-ML-will-not-Work-for-Your-App.html

    This mentions that complex models can turn into several GB on the device. You might also try backing up after, and looking at what files get created and where. Possibly, I'm thinking if you put your file into a folder starting with a period, that keeps pythonista from showing /indexing it.

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!