Community Bonding – Report (3)

Hello there, this is my weekly report about my work. In this report, I will show what I did this past week. I will also show what I intend to do in the next week. let’s get started.

That’s what is done
  • I finished my experiments with RapidJSON. I also finished reading the documentation of the library. A small example I did is to make an Octave function (written in C++) that adds two JSON objects. JSON objects are a set of key-value pairs. This function accepts objects with numeric values only and adds these values if they have the same key. Else, the values remain the same. This small function serves as a good warm up before the coding period. I think this is a good warm up as it uses two important things for my project: Creating Octave functions that are written in C++ and using RapidJSON which I will use in the project. enough talking here is the code:
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/error/en.h"
#include <octave/oct.h>

using namespace rapidjson;

DEFUN_DLD (addJSON, args, , "adds two JSON objects.")
  int nargin = args.length ();

  if (args.length () != 2)
    print_usage ();

  if (! (args(0).is_string () && args(1).is_string ()))
    error ("parameters must be Character Strings");

  std::string first_json = args(0).string_value ();
  std::string second_json = args(1).string_value ();
  Document d1;
  Document d2;

  d1.Parse (first_json.c_str ());
  if (d1.HasParseError ())
    error("(offset %u): %s\n", 

  d2.Parse (second_json.c_str ());
  if (d2.HasParseError ())
    error("(offset %u): %s\n", 

  if(! (d1.IsObject () && d2.IsObject ()))
    error ("parameters must be JSON objects");

  // checking that the first json object has numeric values only
  for (Value::ConstMemberIterator itr = d1.MemberBegin ();
       itr != d1.MemberEnd () ; ++itr)
      if (! itr->value.IsNumber ())
        error ("values must be numbers");

  for (Value::ConstMemberIterator itr = d2.MemberBegin ();
       itr != d2.MemberEnd () ; ++itr)
      if (! itr->value.IsNumber ())
        error ("values must be numbers");
      if (d1.HasMember (itr->name.GetString ()))
          Value& s = d1[itr->name.GetString ()];
          if (s.IsDouble () || itr->value.IsDouble ())
            s.SetDouble(s.GetDouble() + itr->value.GetDouble ());
            s.SetInt(s.GetInt () + itr->value.GetInt ());
          Value key(itr->name.GetString (), d1.GetAllocator ());
          Value value (itr->value, d1.GetAllocator ());
          d1.AddMember (key, value, d1.GetAllocator ());
  StringBuffer buffer;
  Writer<StringBuffer> writer (buffer);
  d1.Accept (writer);

  return octave_value (buffer.GetString());
  • I discovered this cool Octave command __run_test_suite__. This command runs the complete test suite of Octave (the one that gets run at the end of make check.) This is very useful for regression testing.
  • I also prepared my check list for the test suite. My goal here is to make the test suite covers all the conversion cases that jsonencode and jsondecode cover in the official documentation of MATLAB (E.g. from boolean JSON data type to scalar logical) so my check list is simply the conversions listed at the end of the documentation of both functions (posting them here will overpopulate the post.)
Timeline and Milestones

Since the coding will start next week. This is a good time to show you my plan for the project. Those are my milestones:

  • 26/6: Deliver test suite (first evaluation period starts on 29/6)
  • 20/7: Deliver jsondecode (second evaluation period starts on 27/7)
  • 05/8: Deliver jsonencode (final week starts on 24/8)

Here is my timeline:

01/6 – 21/6* (final exams)20 daysPreparing the test suite7-10
21/6 – 03/712 daysFinalizing the test suite, running tests on the libraries and Creating reliable figures.40-45
03/7 – 06/73 daysAnalyzing results and taking design decisions with the mentors.40-45
06/7 – 18/712 daysImplementing jsondecode40-45
18/7 – 20/72 daysBuffering40-45
20/7 – 03/814 daysImplementing jsonencode40-45
03/8 – 07/84 daysBuffering & Documenting 40-45
07/8 – 12/85 daysConverting the test suite to Octave BIST40-45
12/8 – 17/85 daysCleaning the code and preparing the patch40-45
17/8 – 31/814 daysPerfecting the patch with the community feedback.40-45
My timeline
What I intend to do

That’s it for this week. See you next one.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with
Get started
%d bloggers like this: