Seth, I've attached two files:
The first has the java code for the matrix:map procedure, the second the full error messages and traces. When I try to add another catch to the try/catch block with any NetLogo type exception, such as LogoException or EngineException, NetBeans tells me that those exceptions aren't thrown by anything in the try block. My goal was simply to provide an intelligible error message in this situation, but if that's not possible, so be it. (Note that I do get a "2" as part of the exception message. I'm assuming that it is part of the expected 3 inputs and got 2 error, but not sure I should build a message on that!) BTW, run-time errors such as division by zero or the square root of a negative number are caught and reported just fine. I did look to see if I could turn off the NetBeans complaint, but it seems to be an error rather than a warning. Let me know if you need anything else. Best, Charles On Monday, February 24, 2014 7:04:04 PM UTC-5, Seth Tisue wrote: > > > P.S. re: the surprising, even wrong-seeming wording of the error > message, it's a known problem; see > https://github.com/NetLogo/NetLogo/issues/419 > > -- > Seth Tisue | Northwestern University | http://tisue.net > developer, NetLogo: http://ccl.northwestern.edu/netlogo/ > > -- You received this message because you are subscribed to the Google Groups "netlogo-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-devel+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
public static class MapElements extends DefaultReporter { @Override public Syntax getSyntax() { return Syntax.reporterSyntax(new int[]{Syntax.ReporterTaskType(), Syntax.WildcardType() | Syntax.RepeatableType()}, Syntax.WildcardType(), 2); } @Override public Object report(Argument args[], Context context) throws ExtensionException, LogoException { // Get reporter task and the LogoMatrix or matrices from the arguments // and put the LogoMatrices in an ArrayList. ReporterTask mapFnctn = args[0].getReporterTask(); ArrayList<LogoMatrix> lmats = new ArrayList<LogoMatrix>(); for (int i = 1; i < args.length; i++) { lmats.add(getMatrixFromArgument(args[i])); } // Now get the underlying double[][] matrices and put them in an // ArrayList. ArrayList<double[][]> dmats = new ArrayList<double[][]>(); for (LogoMatrix lmat : lmats) { dmats.add(lmat.matrix.getArray()); } int nmats = dmats.size(); // make sure all the underlying matrices have the same dimensions. int nrows = dmats.get(0).length; int ncols = dmats.get(0)[0].length; for (double[][] mat : dmats) { if (mat.length != nrows || mat[0].length != ncols) { throw new org.nlogo.api.ExtensionException("All matrices must have the same dimmensions."); } } // create the destination array and an array for the task arguments. double[][] destmat = new double[nrows][ncols]; Object[] taskArgs = new Object[nmats]; // iterate through the elements of the arrays, mapping them to the // destination array. try { for (int i = 0; i < nrows; i++) { for (int j = 0; j < ncols; j++) { for (int n = 0; n < nmats; n++) { taskArgs[n] = dmats.get(n)[i][j]; } destmat[i][j] = (Double) mapFnctn.report(context, taskArgs); } } // return the destination array as a new LogoMatrix. return new LogoMatrix(new Jama.Matrix(destmat)); } catch (RuntimeException ex) { throw new ExtensionException(ex); } } }
This NetLogo code generates the first exception below. let m8 matrix:from-row-list [[1 2 3] [4 5 6] [7 8 9]] let m9 matrix:from-row-list [[9 8 7] [6 5 4] [3 2 1]] output-print matrix:to-row-list (matrix:map (task [?1 * ?3]) m8 m9) Extension exception: 2 error while observer running MATRIX:MAP called by procedure SETUP called by Button 'setup' org.nlogo.nvm.EngineException: Extension exception: 2 at org.nlogo.nvm.Task$class.bindArgs(Task.scala:27) at org.nlogo.nvm.ReporterTask.bindArgs(Task.scala:42) at org.nlogo.nvm.ReporterTask.report(Task.scala:52) at org.nlogo.nvm.ReporterTask.report(Task.scala:46) at org.nlogo.extensions.matrix.MatrixExtension$MapElements.report(MatrixExtension.java:868) at org.nlogo.prim._externreport.report(_externreport.java:50) at org.nlogo.nvm.Argument.get(Argument.java:27) at org.nlogo.extensions.matrix.MatrixExtension.getMatrixFromArgument(MatrixExtension.java:370) at org.nlogo.extensions.matrix.MatrixExtension.access$300(MatrixExtension.java:17) at org.nlogo.extensions.matrix.MatrixExtension$ToRowList.report(MatrixExtension.java:615) at org.nlogo.prim._externreport.report(_externreport.java:50) at org.nlogo.prim.etc._outputprint.perform(_outputprint.scala:13) at org.nlogo.nvm.Context.stepConcurrent(Context.java:91) at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.java:82) at org.nlogo.job.JobThread.org$nlogo$job$JobThread$$runPrimaryJobs(JobThread.scala:143) at org.nlogo.job.JobThread$$anonfun$run$1.apply$mcV$sp(JobThread.scala:78) at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76) at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76) at scala.util.control.Exception$Catch.apply(Exception.scala:88) at org.nlogo.util.Exceptions$.handling(Exceptions.scala:41) at org.nlogo.job.JobThread.run(JobThread.scala:75) NetLogo 5.0.5 main: org.nlogo.app.AppFrame thread: JobThread Java HotSpot(TM) Server VM 1.6.0_45 (Sun Microsystems Inc.; 1.6.0_45-b06) operating system: Windows 7 6.1 (x86 processor) Scala version 2.9.2 JOGL: (3D View not initialized) OpenGL Graphics: (3D View not initialized) model: MatrixExample 07:53:41.537 SwitchedTabsEvent (org.nlogo.app.Tabs) AWT-EventQueue-0 07:53:41.534 RuntimeErrorEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:53:41.530 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:53:41.526 OutputEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:53:41.521 OutputEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:53:41.516 OutputEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:53:41.511 OutputEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:53:41.507 OutputEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:53:41.501 OutputEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:53:41.497 OutputEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 ------------------------------------------------------------------------------------------------------ A similar use of the standard map primitive in NetLogo using lists generates the following: task expected 3 inputs, but only got 2 error while observer running MAP called by procedure GO called by Command Center org.nlogo.nvm.EngineException: task expected 3 inputs, but only got 2 at org.nlogo.nvm.EngineException.fillInStackTrace(EngineException.java:81) at java.lang.Throwable.<init>(Throwable.java:218) at java.lang.Exception.<init>(Exception.java:59) at org.nlogo.api.LogoException.<init>(LogoException.scala:15) at org.nlogo.nvm.EngineException.<init>(EngineException.java:20) at org.nlogo.prim.etc._map.report(_map.scala:25) at org.nlogo.prim.etc._map.report(_map.scala:8) at org.nlogo.prim.etc._show.perform(_show.scala:13) at org.nlogo.nvm.Context.stepConcurrent(Context.java:91) at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.java:82) at org.nlogo.job.JobThread.org$nlogo$job$JobThread$$runPrimaryJobs(JobThread.scala:143) at org.nlogo.job.JobThread$$anonfun$run$1.apply$mcV$sp(JobThread.scala:78) at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76) at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76) at scala.util.control.Exception$Catch.apply(Exception.scala:88) at org.nlogo.util.Exceptions$.handling(Exceptions.scala:41) at org.nlogo.job.JobThread.run(JobThread.scala:75) NetLogo 5.0.5 main: org.nlogo.app.AppFrame thread: JobThread Java HotSpot(TM) Server VM 1.6.0_45 (Sun Microsystems Inc.; 1.6.0_45-b06) operating system: Windows 7 6.1 (x86 processor) Scala version 2.9.2 JOGL: (3D View not initialized) OpenGL Graphics: (3D View not initialized) model: Untitled 07:56:08.057 SwitchedTabsEvent (org.nlogo.app.Tabs) AWT-EventQueue-0 07:56:08.051 RuntimeErrorEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:56:08.051 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:56:08.043 AddJobEvent (org.nlogo.app.CommandLine) AWT-EventQueue-0 07:56:08.040 OutputEvent (org.nlogo.app.CommandLine) AWT-EventQueue-0 07:56:08.039 CompiledEvent (org.nlogo.window.CompilerManager) AWT-EventQueue-0 07:56:08.026 CompileMoreSourceEvent (org.nlogo.app.CommandLine) AWT-EventQueue-0 07:56:07.885 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:56:07.685 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 07:56:07.485 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 --------------------------------------------------------------------------------------------------------------