Kotlin AVR Atmega8 [Experimental]

Submitted by Dickens A S on Mon, 12/02/2019 - 17:17

This is a small experiment for AVR Atmega8 

A simple swap function which is possibly re-used inside actual avr "C/C++" code as library

import platform.avr.*
import kotlinx.cinterop.internal.*
import kotlinx.cinterop.*

fun swap(a:uint8_tVar, b:uint8_tVar) = memScoped {
    var temp = a
    a.value = b.value
    b.value = temp.value
}

Still work in progress 

Source Code

End Of Article 

AVR
Atmega8
kotlin

GTK3 and Glade3 using Kotlin

Submitted by Dickens A S on Sat, 11/30/2019 - 14:13

GTK windows design using glade builder

This code explains how to use Kotlin to program GTK3 and Glade3 using Cygwin Glade designer

Install cygwin with below dependencies

mingw64-x86_64-gtk3    3.22.28-1 glade                                 3.20.3-1 xorg-server                       1.20.4-1 xinit                                   1.4.1-1

launch cygwin and export the PATH as

export PATH=$PATH:/usr/x86_64-w64-mingw32/sys-root/mingw/bin

The execute the gradle command to run the app, refer github for gradle command

GTK3
GLADE3
GTK+
GTK
GLADE
3.0
kotlin
Cygwin

Call OpenCL from Kotlin or embed OpenCL inside Kotlin

Submitted by Dickens A S on Fri, 11/29/2019 - 17:29

Embedded OpenCL inside Kotlin

OpenCL code which runs from kotlin

#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
__constant char hw[] = "Hello World";
__kernel void hello(__global char * A) {
    size_t tid = get_global_id(0);
    A[tid] = hw[tid];
}

 

Kotlin code which runs OpenCL

OpenCL
kotlin
Embed
Embed OpenCL

Call TCL from Kotlin or embed TCL inside Kotlin

Submitted by Dickens A S on Fri, 11/29/2019 - 08:37

Embedded TCL inside Kotlin

TCL code which runs from kotlin

puts "Hello, world!"

Kotlin code which run TCL

package plot

import kotlinx.cinterop.*
import tcl.*

fun main() 
{
    var tcli = Tcl_CreateInterp()
    if(Tcl_Eval(tcli, "set a 1")==TCL_OK) {
        Tcl_EvalFile(tcli, "hello.tcl")
    }
    Tcl_DeleteInterp(tcli)
}

You need to install MSYS2 and tcl using below command

TCL
Embed TCL
kotlin

Artificial Neural Network in Kotlin - FANN

Submitted by Dickens A S on Thu, 11/28/2019 - 13:53

FANN is an open source library 

which offers C based API which can be invoked from Kotlin

Below Kotlin example shows how it can be invoked

import fann.*

fun main() 
{

    var ann = fann_create_standard(4, 2, 8, 9, 1)
    
    fann_print_connections(ann)
    
    fann_destroy(ann)
}

Below is the sample output from MSYS2 terminal

FANN
ANN
Artificial Neural Network
kotlin

Call MATLAB function octave Mex from Kotlin

Submitted by Dickens A S on Thu, 11/28/2019 - 09:06

Is one of the popular Scientific Programming Language or platform

general MATLAB functions will work in Octave

This Article explains how to trigger Mex script from Kotlin using "mex.h" and "octave.h" C API in Kotlin

Octave 5.1.0 is installed in C:\octave with below structure and files

Note: Octave 6.x.x has C++ class will not support Kotlin, Please use Octave 5.1.0

Octave
kotlin
Embed Octave
MEX
Matlab
MATLAB
Embed MEX
Embed Matlab

Installing R using Cygwin

Submitted by Dickens A S on Wed, 11/27/2019 - 14:37

R is amazing platform which many numerical methods and analysis options available

This article explains how to use R in Windows using Cygwin

Reason for Cygwin, it has X11 and Cygwin-X with amazing setup selection tools and many libraries

Below are the installation steps

Step 1: Download and install Cygwin and dependencies

Double click the setup will launch  Press Next in all the windows  For Download Site choose http://mirrors.kernel.org

Pressing next will show software selection window as shown below

R
Cygwin
Install
Windows

Linear Algebra using Kotlin and LAPACK (OpenBLAS)

Submitted by Dickens A S on Mon, 11/25/2019 - 16:37

Kotlin Linear Algebra using LAPACKE C APIs

Code snippet to call the library method

    print_matrix_colmajor( "Entry Matrix A", m, n, a, lda )
    print_matrix_colmajor( "Right Hand Side b", n, nrhs, b, ldb )
    println( "\nLAPACKE_dgels (col-major, high-level) Example Program Results" );
    LAPACKE_dgels(LAPACK_COL_MAJOR,'N'.toInt().toByte(),m,n,nrhs,a,lda,b,ldb)
    println()
    print_matrix_colmajor( "Solution", n, nrhs, b, ldb );

You need to use MSYS2 and install OpenBLAS to make this work, please refer other articles for MSYS2

Linear Algebra
kotlin
LAPACK
LAPACKE
OpenBLAS